peach-dyndns-server/src/http.rs

39 lines
1.3 KiB
Rust
Raw Normal View History

2021-04-30 11:18:44 +00:00
/*
*
* /register-user (sends an email verification to create a new account)
* /verify (for clicking the link in the email)
* /register-domain (add a new domain and get back the secret for subsequent updating)
* /update-domain (update the IP for the domain, passing the associated secret)
*
*/
use rocket_contrib::json::Json;
use serde::Deserialize;
2021-05-15 06:57:32 +00:00
use std::thread;
use crate::client::check_domain_available;
2019-05-07 11:13:10 +00:00
2021-04-30 11:18:44 +00:00
#[get("/")]
2021-05-15 06:57:32 +00:00
pub fn index() -> &'static str {
2021-04-30 11:18:44 +00:00
"This is the peach-dyn-dns server."
}
2021-04-28 11:08:12 +00:00
2021-04-30 11:18:44 +00:00
#[derive(Deserialize, Debug)]
2021-05-15 06:57:32 +00:00
pub struct RegisterDomainPost {
2021-04-30 11:18:44 +00:00
domain: String,
2019-05-07 11:13:10 +00:00
}
2021-04-30 11:18:44 +00:00
#[post("/register-domain", data = "<data>")]
2021-05-15 06:57:32 +00:00
pub async fn register_domain(data: Json<RegisterDomainPost>) -> &'static str {
2021-04-30 11:18:44 +00:00
info!("++ post request to register new domain: {:?}", data);
2021-05-15 06:57:32 +00:00
// TODO: first confirm domain is in the right format ("*.dyn.peachcloud.org")
let handle = thread::spawn(move || {
let domain_already_exists = check_domain_available(&data.domain);
domain_already_exists
});
let domain_already_exists = handle.join().unwrap();
if domain_already_exists {
"can't register domain already exists"
} else {
// TODO: use bash to generate a tsig key, update bind config, and then return the secret
"New domain registered"
2021-04-30 11:18:44 +00:00
}
2021-05-15 06:57:32 +00:00
}