) {
- for domain in &["a", "b", "c"] {
+async fn create_dummy_users(db: &mut Database) {
+ db.create_user(User {
+ username: "admin".to_string(),
+ domain: None,
+ password: "adminadmin".to_string(),
+ // TODO: what should we put here?
+ mail: "admin".to_string(),
+ role: Role::Admin,
+ })
+ .await
+ .unwrap()
+ .unwrap();
+ for letter in &["a", "b", "c"] {
+ let domain = format!("{letter}.localhost");
+ db.create_domain(&domain).await.unwrap().unwrap();
db.create_user(User {
- username: domain.to_string(),
- domain: format!("{domain}.localhost"),
+ username: letter.to_string(),
+ domain: Some(domain.clone()),
password: "adminadmin".to_string(),
- mail: format!("{domain}@{domain}.localhost"),
+ mail: format!("{letter}@{domain}"),
+ role: Role::DomainAdmin(domain.clone()),
+ })
+ .await
+ .unwrap()
+ .unwrap();
+ db.create_user(User {
+ username: format!("user{letter}"),
+ domain: Some(domain.clone()),
+ password: "adminadmin".to_string(),
+ mail: format!("user{letter}@{domain}"),
+ role: Role::User,
})
.await
.unwrap()
@@ -39,13 +67,28 @@ 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()
+ };
create_dummy_users(&mut db).await;
- let ldap_db = db.clone();
- tokio::spawn(ldap_listen(listener, ldap_db));
+ #[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) = ldap_listener.accept_ldap().await? {
+ let db = db.clone();
+ tokio::spawn(ldap_handler(stream, db));
+ }
Ok(())
}
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..11ae59a
--- /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 %}
+