) {
- for domain in &["a", "b", "c"] {
+async fn create_dummy_users(db: &mut Database) {
+ // TODO: customize admin password
+ if db.list_all_users().await.unwrap().is_empty() {
+ tracing::info!("Creating admin account with default `adminadmin` password");
db.create_user(User {
- username: domain.to_string(),
- domain: format!("{domain}.localhost"),
+ username: "admin".to_string(),
+ domain: None,
password: "adminadmin".to_string(),
- mail: format!("{domain}@{domain}.localhost"),
+ // TODO: what should we put here?
+ mail: "admin".to_string(),
+ role: Role::Admin,
})
.await
.unwrap()
@@ -39,14 +47,26 @@ async fn main() -> Result<(), GlobalError> {
// .init();
// tracing::subscriber::set_global_default(subscriber)?;
- let listener = ListenerPath::new(&cli.listen)?.listener().await?;
+ let ldap_listener = ListenerPath::new(&cli.listen_ldap)?.listener().await?;
- let mut db = MemoryDatabase::new();
+ let mut db = if let Some(db_path) = &cli.db {
+ FilesystemDatabase::from_path(db_path).await.unwrap()
+ } else {
+ MemoryDatabase::new()
+ };
+ tracing::info!("Database loaded successfully");
create_dummy_users(&mut db).await;
+ #[cfg(feature = "http")]
+ {
+ let http_listener = ListenerPath::new(&cli.listen_http)?.listener().await?;
+ let http_db = db.clone();
+ tokio::spawn(http_listen(http_listener, http_db));
+ }
+
// If the connection is None, it's because the client aborted early
// so there's nothing to do about it.
- while let Some(stream) = listener.accept_ldap().await? {
+ while let Some(stream) = ldap_listener.accept_ldap().await? {
let db = db.clone();
tokio::spawn(ldap_handler(stream, db));
}
diff --git a/templates/base.html b/templates/base.html
new file mode 100644
index 0000000..b92b6da
--- /dev/null
+++ b/templates/base.html
@@ -0,0 +1,11 @@
+
+
+
+ LLLDAP
+
+
+
+{% block main %}
+{% endblock %}
+
+
diff --git a/templates/domain.html b/templates/domain.html
new file mode 100644
index 0000000..758ad65
--- /dev/null
+++ b/templates/domain.html
@@ -0,0 +1,30 @@
+{% extends 'base.html' %}
+{% block main %}
+
+
+ You are logged in as {{ user.username }}
+
+ {% if can_create_user %}
+
+
Create user
+
+
+ {% endif %}
+
+
Users on {{ domain.name }}
+
+ {% for user in users %}
+ - {{ user.mail }}
+ {% endfor %}
+
+
+
+{% endblock %}
+
diff --git a/templates/home.html b/templates/home.html
new file mode 100644
index 0000000..d1f71b2
--- /dev/null
+++ b/templates/home.html
@@ -0,0 +1,38 @@
+{% extends 'base.html' %}
+{% block main %}
+
+
+ You are logged in as {{ user.username }}
+
+ {% if can_create_domain %}
+
+
Create domain
+
+
+ {% endif %}
+
+
Active domains you can see
+
+
+ {% if other_users %}
+
+
Other users you have permission to see on your own domain
+
+ {% for user in other_users %}
+ - {{ user.mail }}
+ {% endfor %}
+
+
+ {% endif %}
+
+{% endblock %}
+
diff --git a/templates/login.html b/templates/login.html
new file mode 100644
index 0000000..82ef600
--- /dev/null
+++ b/templates/login.html
@@ -0,0 +1,29 @@
+{% extends 'base.html' %}
+{% block main %}
+
+
+ {% if login_error == "InvalidCredentials" %}
+
+ {% elif login_error == "SessionInvalidated" %}
+
+ {% endif %}
+
+
+{% endblock %}
+