A cloudflare backed DDNS service written in Rust
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5 KiB

  1. #[macro_use]
  2. extern crate serde_derive;
  3. #[macro_use]
  4. extern crate log;
  5. extern crate actix_web;
  6. extern crate bytes;
  7. extern crate clap;
  8. extern crate env_logger;
  9. extern crate futures;
  10. extern crate num_cpus;
  11. extern crate serde;
  12. use clap::{App, Arg};
  13. mod server;
  14. const VERSION: &'static str = env!("CARGO_PKG_VERSION");
  15. fn main() {
  16. match std::env::var("RUST_LOG") {
  17. Ok(_) => (),
  18. Err(_) => std::env::set_var("RUST_LOG", "actix_web=info"),
  19. }
  20. env_logger::init();
  21. let args = App::new("Dynamic DNS Server")
  22. .version(VERSION)
  23. .author("Drew Short <warrick@sothr.com>")
  24. .about("Recieve DDNS requests and update cloudflare subdomains")
  25. .args(&[
  26. Arg::with_name("config")
  27. .short("c")
  28. .long("config")
  29. .value_name("PATH")
  30. .default_value("/etc/rsddns/rsddns.yml")
  31. .help("Set a custom configuration file path.")
  32. .takes_value(true),
  33. Arg::with_name("host")
  34. .short("h")
  35. .long("host")
  36. .value_name("HOST")
  37. .default_value("localhost")
  38. .help("The address the server listens on.")
  39. .takes_value(true),
  40. Arg::with_name("port")
  41. .short("p")
  42. .long("port")
  43. .value_name("PORT")
  44. .default_value("8080")
  45. .help("The port to run the server on.")
  46. .takes_value(true),
  47. Arg::with_name("workers")
  48. .short("w")
  49. .long("workers")
  50. .value_name("NUMBER")
  51. .help("The number of workers to serve requests with.")
  52. .takes_value(true),
  53. ])
  54. .get_matches();
  55. let config: &str = args.value_of("config").unwrap_or("/etc/rsddns/rsddns.yml");
  56. let host: &str = args.value_of("host").unwrap_or("localhost");
  57. let port: i32 = args
  58. .value_of("port")
  59. .unwrap()
  60. .parse::<i32>()
  61. .unwrap_or(8080);
  62. let workers: usize = match args.value_of("workers") {
  63. Some(count) => count.parse::<usize>().unwrap_or(num_cpus::get()),
  64. None => num_cpus::get(),
  65. };
  66. info!(
  67. "Starting server on {}:{} with workers={} and config {}",
  68. host, port, workers, config
  69. );
  70. actix_web::server::new(|| server::router::create())
  71. .workers(workers)
  72. .bind(format!("{}:{}", host, port))
  73. .unwrap()
  74. .run();
  75. }