hbbr.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. use clap::App;
  2. mod common;
  3. mod relay_server;
  4. use flexi_logger::*;
  5. use hbb_common::{config::RELAY_PORT, ResultType};
  6. use relay_server::*;
  7. mod version;
  8. fn main() -> ResultType<()> {
  9. let _logger = Logger::try_with_env_or_str("info")?
  10. .log_to_stdout()
  11. .format(opt_format)
  12. .write_mode(WriteMode::Async)
  13. .start()?;
  14. let args = format!(
  15. "-p, --port=[NUMBER(default={RELAY_PORT})] 'Sets the listening port'
  16. -k, --key=[KEY] 'Only allow the client with the same key'
  17. ",
  18. );
  19. let matches = App::new("hbbr")
  20. .version(version::VERSION)
  21. .author("Purslane Ltd. <info@rustdesk.com>")
  22. .about("RustDesk Relay Server")
  23. .args_from_usage(&args)
  24. .get_matches();
  25. if let Ok(v) = ini::Ini::load_from_file(".env") {
  26. if let Some(section) = v.section(None::<String>) {
  27. section.iter().for_each(|(k, v)| std::env::set_var(k, v));
  28. }
  29. }
  30. let mut port = RELAY_PORT;
  31. if let Ok(v) = std::env::var("PORT") {
  32. let v: i32 = v.parse().unwrap_or_default();
  33. if v > 0 {
  34. port = v + 1;
  35. }
  36. }
  37. start(
  38. matches.value_of("port").unwrap_or(&port.to_string()),
  39. matches
  40. .value_of("key")
  41. .unwrap_or(&std::env::var("KEY").unwrap_or_default()),
  42. )?;
  43. Ok(())
  44. }