|
|
@ -23,7 +23,7 @@ pub struct Service<'svc> { |
|
|
|
handlebars: handlebars::Handlebars<'svc>, |
|
|
|
handlebars: handlebars::Handlebars<'svc>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn new<'svc, 'mgr>( |
|
|
|
pub fn new<'svc>( |
|
|
|
domain_manager: sync::Arc<dyn domain::manager::Manager>, |
|
|
|
domain_manager: sync::Arc<dyn domain::manager::Manager>, |
|
|
|
target_a: net::Ipv4Addr, |
|
|
|
target_a: net::Ipv4Addr, |
|
|
|
passphrase: String, |
|
|
|
passphrase: String, |
|
|
@ -34,7 +34,7 @@ pub fn new<'svc, 'mgr>( |
|
|
|
target_a, |
|
|
|
target_a, |
|
|
|
passphrase, |
|
|
|
passphrase, |
|
|
|
http_domain, |
|
|
|
http_domain, |
|
|
|
handlebars: self::http_tpl::get().expect("Retrieved Handlebars templates"), |
|
|
|
handlebars: self::http_tpl::get(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -104,7 +104,7 @@ impl<'svc> Service<'svc> { |
|
|
|
self.render( |
|
|
|
self.render( |
|
|
|
status_code, |
|
|
|
status_code, |
|
|
|
"/base.html", |
|
|
|
"/base.html", |
|
|
|
&BasePresenter { |
|
|
|
BasePresenter { |
|
|
|
page_name: "/error.html", |
|
|
|
page_name: "/error.html", |
|
|
|
data: &Response { error_msg: e }, |
|
|
|
data: &Response { error_msg: e }, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -128,7 +128,7 @@ impl<'svc> Service<'svc> { |
|
|
|
fn serve_origin(&self, domain: domain::Name, path: &'_ str) -> SvcResponse { |
|
|
|
fn serve_origin(&self, domain: domain::Name, path: &'_ str) -> SvcResponse { |
|
|
|
let mut path_owned; |
|
|
|
let mut path_owned; |
|
|
|
|
|
|
|
|
|
|
|
let path = match path.ends_with("/") { |
|
|
|
let path = match path.ends_with('/') { |
|
|
|
true => { |
|
|
|
true => { |
|
|
|
path_owned = String::from(path); |
|
|
|
path_owned = String::from(path); |
|
|
|
path_owned.push_str("index.html"); |
|
|
|
path_owned.push_str("index.html"); |
|
|
@ -148,8 +148,8 @@ impl<'svc> Service<'svc> { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let mut buf = Vec::<u8>::new(); |
|
|
|
let mut buf = Vec::<u8>::new(); |
|
|
|
match origin.read_file_into(&path, &mut buf) { |
|
|
|
match origin.read_file_into(path, &mut buf) { |
|
|
|
Ok(_) => self.serve_string(200, &path, buf), |
|
|
|
Ok(_) => self.serve_string(200, path, buf), |
|
|
|
Err(origin::ReadFileIntoError::FileNotFound) => { |
|
|
|
Err(origin::ReadFileIntoError::FileNotFound) => { |
|
|
|
self.render_error_page(404, "File not found") |
|
|
|
self.render_error_page(404, "File not found") |
|
|
|
} |
|
|
|
} |
|
|
@ -190,9 +190,9 @@ impl<'svc> Service<'svc> { |
|
|
|
|
|
|
|
|
|
|
|
self.render_page( |
|
|
|
self.render_page( |
|
|
|
"/domain.html", |
|
|
|
"/domain.html", |
|
|
|
&Response { |
|
|
|
Response { |
|
|
|
domain: args.domain, |
|
|
|
domain: args.domain, |
|
|
|
config: config, |
|
|
|
config, |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
@ -222,15 +222,15 @@ impl<'svc> Service<'svc> { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return self.render_page( |
|
|
|
self.render_page( |
|
|
|
"/domain_init.html", |
|
|
|
"/domain_init.html", |
|
|
|
&Response { |
|
|
|
Response { |
|
|
|
domain: args.domain, |
|
|
|
domain: args.domain, |
|
|
|
flat_config: config.into(), |
|
|
|
flat_config: config.into(), |
|
|
|
target_a: self.target_a, |
|
|
|
target_a: self.target_a, |
|
|
|
challenge_token: config_hash, |
|
|
|
challenge_token: config_hash, |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async fn domain_sync( |
|
|
|
async fn domain_sync( |
|
|
@ -276,12 +276,12 @@ impl<'svc> Service<'svc> { |
|
|
|
error_msg, |
|
|
|
error_msg, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return self.render_page("/domain_sync.html", response); |
|
|
|
self.render_page("/domain_sync.html", response) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub async fn handle_request<'svc>( |
|
|
|
pub async fn handle_request( |
|
|
|
svc: sync::Arc<Service<'svc>>, |
|
|
|
svc: sync::Arc<Service<'_>>, |
|
|
|
req: Request<Body>, |
|
|
|
req: Request<Body>, |
|
|
|
) -> Result<Response<Body>, Infallible> { |
|
|
|
) -> Result<Response<Body>, Infallible> { |
|
|
|
match handle_request_inner(svc, req).await { |
|
|
|
match handle_request_inner(svc, req).await { |
|
|
@ -291,16 +291,13 @@ pub async fn handle_request<'svc>( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn strip_port(host: &str) -> &str { |
|
|
|
fn strip_port(host: &str) -> &str { |
|
|
|
match host.rfind(":") { |
|
|
|
match host.rfind(':') { |
|
|
|
None => host, |
|
|
|
None => host, |
|
|
|
Some(i) => &host[..i], |
|
|
|
Some(i) => &host[..i], |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub async fn handle_request_inner<'svc>( |
|
|
|
pub async fn handle_request_inner(svc: sync::Arc<Service<'_>>, req: Request<Body>) -> SvcResponse { |
|
|
|
svc: sync::Arc<Service<'svc>>, |
|
|
|
|
|
|
|
req: Request<Body>, |
|
|
|
|
|
|
|
) -> SvcResponse { |
|
|
|
|
|
|
|
let maybe_host = match ( |
|
|
|
let maybe_host = match ( |
|
|
|
req.headers() |
|
|
|
req.headers() |
|
|
|
.get("Host") |
|
|
|
.get("Host") |
|
|
@ -321,7 +318,7 @@ pub async fn handle_request_inner<'svc>( |
|
|
|
let method = req.method(); |
|
|
|
let method = req.method(); |
|
|
|
let path = req.uri().path(); |
|
|
|
let path = req.uri().path(); |
|
|
|
|
|
|
|
|
|
|
|
if method == &Method::GET && path.starts_with("/static/") { |
|
|
|
if method == Method::GET && path.starts_with("/static/") { |
|
|
|
return svc.render(200, path, ()); |
|
|
|
return svc.render(200, path, ()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|