Skip to content
Snippets Groups Projects
Commit 9338c968 authored by Paul's avatar Paul :turtle:
Browse files

add config

parent 04d77a50
No related branches found
No related tags found
No related merge requests found
Pipeline #3420 failed
use serde::{Serialize, Deserialize};
use serde;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
pub domain: Vec<Domain>,
pub master: String,
pub rname: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Domain {
/// the domain suffix. eg. for a dynamic domain
/// mydomain.ddns.org the name here is ddns.org
pub name: String,
/// a short description for a domain
pub description: String,
/// a list of networks, which a subdomain from this
/// domain is allowed to updated to
pub nets: Vec<String>,
/// duration in days before a subdomain gets 'released' wgen not updated
pub registration_time: usize,
}
......@@ -2,6 +2,7 @@
mod db;
mod web;
mod config;
use chrono::DateTime;
use chrono::Utc;
......@@ -18,17 +19,78 @@ use rocket::request::Outcome;
use std::fmt::{self, Display};
use std::net::IpAddr;
use rand;
use toml;
use lazy_static::lazy_static;
use config::Config;
use std::fs;
use std::path;
use std::io::Read;
use log::{debug, info, error};
use std::process::exit;
const CONFIG_DIRS: &[&str] = &[
"./ffdyndns.toml",
"/etc/ffdyndns.toml",
"/var/lib/ffdyndns/ffdyndns.toml",
];
lazy_static! {
pub static ref CONFIG: Config = {
let file = CONFIG_DIRS.iter()
.map(|x| path::Path::new(x))
.find(|p| p.exists() && p.is_file());
match file {
Some(f) => {
debug!("loading config: {}", f.to_str().unwrap());
let mut f = fs::File::open(f).unwrap();
let mut toml_str = String::new();
f.read_to_string(&mut toml_str).expect("can't read config file");
match toml::from_str::<Config>(&toml_str) {
Err(e) => {
eprintln!("configuration error: {}", e);
exit(1);
}
Ok(r) => r
}
}
None => {
eprintln!("could not find config file");
exit(1);
},
}
};
}
// for p in CONFIG_DIRS.iter().map(|x| path::Path::new(x)) {
// if !p.exists() || !p.is_file() {
// continue;
// }
// debug!("loading config: {}", p.to_str().unwrap());
// let mut f = fs::File::open(p).unwrap();
// let mut toml_str = String::new();
// f.read_to_string(&mut toml_str).expect("can't read config file");
// config = toml::from_str::<Config>(&toml_str).unwrap()
// };
// return config;
#[derive(Debug, Clone)]
pub struct DomainUpdate {
domain: String,
ip: IpAddr
domain: String,
ip: IpAddr
}
fn main() {
let db = db::Database::new("./ffddns.sqlite".into());
web::start_web(db);
println!("{:?}", CONFIG.domain);
let db = db::Database::new("./ffddns.sqlite".into());
web::start_web(db);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment