peach-dyndns-server/src/http.rs

44 lines
1.4 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 crate::generate_zone::{check_domain_available, generate_zone};
use rocket_contrib::json::{Json, JsonValue};
2021-04-30 11:18:44 +00:00
use serde::Deserialize;
2021-05-15 06:57:32 +00:00
use std::thread;
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 is_domain_available = check_domain_available(&data.domain);
if !is_domain_available{
"can't register domain that already exists"
2021-05-15 06:57:32 +00:00
} else {
let result = generate_zone(&data.domain);
match result {
Ok(key_file_text) => {
// TODO: figure out how to return key_file_text
"successfully created zone"
}
Err(err) => {
"there was an error registering the domain"
}
}
2021-04-30 11:18:44 +00:00
}
}