From bd6684ea2a09ff2afcd1b477f538f681d25eefd8 Mon Sep 17 00:00:00 2001
From: Brian Picciano
Date: Fri, 4 Aug 2023 18:48:04 +0200
Subject: [PATCH] Even more polish of the web experience
---
config.yml.tpl | 2 +-
src/service/http.rs | 64 ++++++++++++++++++++++-----
src/service/http/tpl/domain_init.html | 13 +++---
src/service/http/tpl/domain_sync.html | 26 ++++++++++-
src/service/http/tpl/domains.html | 2 +-
src/service/http/util.rs | 2 +-
6 files changed, 89 insertions(+), 20 deletions(-)
diff --git a/config.yml.tpl b/config.yml.tpl
index ba58274..5fcb262 100644
--- a/config.yml.tpl
+++ b/config.yml.tpl
@@ -4,7 +4,7 @@ origin:
store_dir_path: /tmp/domani_dev_env/origin
domain:
store_dir_path: /tmp/domani_dev_env/domain
- builtins:
+ builtin_domains:
domani-test.localhost:
kind: git
url: https://code.betamike.com/micropelago/domani.git
diff --git a/src/service/http.rs b/src/service/http.rs
index 7923596..4bd7f25 100644
--- a/src/service/http.rs
+++ b/src/service/http.rs
@@ -19,6 +19,7 @@ use crate::{domain, service, task_stack};
struct BasePresenter<'a, T> {
page_name: &'a str,
form_method: &'a str,
+ http_scheme: &'a str,
data: T,
}
@@ -123,6 +124,13 @@ impl Service {
self.serve(status_code, name, rendered.into())
}
+ fn presenter_http_scheme(&self) -> &str {
+ if self.config.http.https_addr.is_some() {
+ return "https";
+ }
+ return "http";
+ }
+
fn render_error_page(&self, status_code: u16, e: &str) -> Response {
#[derive(Serialize)]
struct Response<'a> {
@@ -135,6 +143,7 @@ impl Service {
BasePresenter {
page_name: "/error.html",
form_method: self.config.http.form_method.as_str(),
+ http_scheme: self.presenter_http_scheme(),
data: &Response { error_msg: e },
},
)
@@ -158,6 +167,7 @@ impl Service {
BasePresenter {
page_name: name,
form_method: self.config.http.form_method.as_str(),
+ http_scheme: self.presenter_http_scheme(),
data,
},
)
@@ -304,7 +314,7 @@ impl Service {
return self.render_error_page(401, "Incorrect passphrase");
}
- let settings: domain::Settings = match args.url_encoded_domain_settings.try_into() {
+ let settings: domain::Settings = match args.url_encoded_domain_settings.clone().try_into() {
Ok(settings) => settings,
Err(e) => {
return self
@@ -320,25 +330,59 @@ impl Service {
#[derive(Serialize)]
struct Data {
domain: domain::Name,
+ url_encoded_domain_settings: util::UrlEncodedDomainSettings,
+ passphrase: String,
+
error_msg: Option,
+ retryable: bool,
}
- let error_msg = match sync_result {
- Ok(_) => None,
- Err(domain::manager::SyncWithSettingsError::NotModifiable) => Some("This domain is not able to be configured, please contact the server administrator.".to_string()),
- Err(domain::manager::SyncWithSettingsError::InvalidURL) => Some("Fetching the git repository failed, please double check that you input the correct URL.".to_string()),
- Err(domain::manager::SyncWithSettingsError::InvalidBranchName) => Some("The git repository does not have a branch of the given name, please double check that you input the correct name.".to_string()),
- Err(domain::manager::SyncWithSettingsError::AlreadyInProgress) => Some("The configuration of your domain is still in progress, please refresh in a few minutes.".to_string()),
- Err(domain::manager::SyncWithSettingsError::ServiceDNSRecordsNotSet) => Some("None of the expected service DNS records were set on the domain. Please double check that you put the correct value on the record. If the value is correct, then most likely the updated records have not yet propagated. In this case you can refresh in a few minutes to try again.".to_string()),
- Err(domain::manager::SyncWithSettingsError::ChallengeTokenNotSet) => Some("The TXT record is not set correctly on the domain. Please double check that you put the correct value on the record. If the value is correct, then most likely the updated records have not yet propagated. In this case you can refresh in a few minutes to try again.".to_string()),
- Err(domain::manager::SyncWithSettingsError::Unexpected(e)) => Some(format!("An unexpected error occurred: {e}")),
+ let (error_msg, retryable) = match sync_result {
+ Ok(_) => (None, false),
+
+ Err(domain::manager::SyncWithSettingsError::NotModifiable) => {
+ (Some("This domain is not allowed to be configured.".to_string()), false)
+ }
+
+ Err(domain::manager::SyncWithSettingsError::InvalidURL) => (Some(
+ "Fetching the git repository failed, please double check that you input the correct
+ URL."
+ .to_string(),
+ ), false),
+
+ Err(domain::manager::SyncWithSettingsError::InvalidBranchName) => (Some(
+ "The git repository does not have a branch of the given name, please double check
+ that you input the correct name."
+ .to_string(),
+ ), false),
+
+ Err(domain::manager::SyncWithSettingsError::AlreadyInProgress) => {
+ (Some("The configuration of your domain is still in progress.".to_string()), true)
+ }
+
+ Err(domain::manager::SyncWithSettingsError::ServiceDNSRecordsNotSet) => (Some(
+ "No routing record (A, AAAA, CNAME, etc...) was present on the nameserver."
+ .to_string(),
+ ), true),
+
+ Err(domain::manager::SyncWithSettingsError::ChallengeTokenNotSet) => (Some(
+ "The challenge record (TXT) was not present on the nameserver."
+ .to_string(),
+ ), true),
+
+ Err(domain::manager::SyncWithSettingsError::Unexpected(e)) => {
+ (Some(format!("An unexpected error occurred: {e}")), false)
+ }
};
self.render_page(
"/domain_sync.html",
Data {
domain: args.domain,
+ url_encoded_domain_settings: args.url_encoded_domain_settings,
+ passphrase: args.passphrase,
error_msg,
+ retryable,
},
)
}
diff --git a/src/service/http/tpl/domain_init.html b/src/service/http/tpl/domain_init.html
index 0a114a7..aaa66f9 100644
--- a/src/service/http/tpl/domain_init.html
+++ b/src/service/http/tpl/domain_init.html
@@ -1,4 +1,4 @@
-
Configure DNS
+
Configure Your Nameserver
This step requires a passphrase that has been given to you by the
administrator of the Domani server:
@@ -18,7 +18,7 @@ administrator of the Domani server:
-
Next you will need to configure your DNS server to point to Domani. There are
+
Next you will need to configure your nameserver to point to Domani. There are
two entries you will need to add. The first entry tells the Domani server that
it is allowed to serve this domain with your given configuration:
@@ -59,12 +59,13 @@ query for your domain name. It can be one or more of:
{{ #if data.dns_records_have_cname }}
-
(Please note that not all DNS providers support putting a CNAME at the zone
-apex, while others support it via an alternative record type like ALIAS or
-ANAME.)
+
(Please note that not all nameserver support using a CNAME in all cases,
+while others support it via an alternative record type like ALIAS or ANAME. If
+one of those are available they can be used instead.)
{{ /if }}
Once both entries are installed, you can hit the following button to check
-your configuration and set up your domain.
+your configuration and set up your domain. Note that this step may take a long
+time to complete, so if nothing happens immediately please don't panic.
diff --git a/src/service/http/tpl/domain_sync.html b/src/service/http/tpl/domain_sync.html
index 2d9aef1..c938d44 100644
--- a/src/service/http/tpl/domain_sync.html
+++ b/src/service/http/tpl/domain_sync.html
@@ -3,11 +3,35 @@
Your domain is not yet set up.
{{ data.error_msg }}
+{{#if data.retryable}}
+
+It's very possible that you have input your nameserver records correctly, but
+that the changes haven't yet propagated to Domani. Propagation of nameserver
+changes can take up to a couple of hours. You can use the button below to retry.
+
+
+
+{{/if}}
+
{{ else }}
Congratulations! Your domain has been successfully configured. You can visit
it at: