feat: add logging, check
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -9,6 +9,7 @@ mod network;
|
||||
// mod simple_thread_pool;
|
||||
|
||||
use std::env;
|
||||
use std::thread;
|
||||
use rust_util::XResult;
|
||||
use acme_lib::Directory;
|
||||
use acme_lib::{create_p384_key, create_p256_key, create_rsa_key};
|
||||
@@ -197,6 +198,10 @@ async fn main() -> tide::Result<()> {
|
||||
let cert_config = matches.value_of("config");
|
||||
match cert_config {
|
||||
None => { // cert config is not assigned
|
||||
if check {
|
||||
failure!("Bad argument `--check`");
|
||||
exit(1);
|
||||
}
|
||||
let domains_val = matches.values_of("domain").unwrap_or_else(|| {
|
||||
failure!("Domains is not assigned.");
|
||||
exit(1);
|
||||
@@ -388,12 +393,16 @@ fn startup_http_server(s: Sender<i32>, port: u16) {
|
||||
task::spawn(async move {
|
||||
information!("Listen at 0.0.0.0:{}", port);
|
||||
let mut app = tide::new();
|
||||
app.at("/").get(|_req: Request<()>| async move {
|
||||
information!("Request / received");
|
||||
Ok("acme-client\n")
|
||||
});
|
||||
app.at("/.well-known/acme-challenge/:token").get(|req: Request<()>| async move {
|
||||
let token = match req.param("token") {
|
||||
Ok(token) => token,
|
||||
Err(e) => {
|
||||
warning!("Cannot get token from url, query: {:?}, error: {}", req.url().query(), e);
|
||||
return Ok("400 - bad request".to_string());
|
||||
return Ok("400 - bad request\n".to_string());
|
||||
}
|
||||
};
|
||||
let peer = req.peer_addr().unwrap_or("none");
|
||||
@@ -405,10 +414,14 @@ fn startup_http_server(s: Sender<i32>, port: u16) {
|
||||
}
|
||||
None => {
|
||||
warning!("Request acme challenge not found: {}, peer: {:?}", token, peer);
|
||||
Ok("404 - not found".to_string())
|
||||
Ok("404 - not found\n".to_string())
|
||||
}
|
||||
}
|
||||
});
|
||||
app.at("/*").get(|req: Request<()>| async move {
|
||||
warning!("Request /* received: {}", req.url());
|
||||
Ok("acme-client *\n")
|
||||
});
|
||||
s.send(1).await.ok();
|
||||
if let Err(e) = app.listen(&format!("0.0.0.0:{}", port)).await {
|
||||
failure!("Failed to listen 0.0.0.0:{}, program will exit, error: {}", port, e);
|
||||
|
||||
Reference in New Issue
Block a user