From 4ef7802fc01724334ef6cfce9d43796928a9eb9f Mon Sep 17 00:00:00 2001 From: undef-i Date: Sun, 30 Apr 2023 19:24:45 +0800 Subject: [PATCH] Fix existing issues --- Cargo.lock | 2 +- Cargo.toml | 2 +- config.toml | 6 +--- src/main.rs | 2 +- src/route/bird.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 74 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95d9c01..a3a19bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,7 +368,7 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bird-looking-glass-proxy" -version = "0.0.2" +version = "0.0.3" dependencies = [ "actix-web", "birdc", diff --git a/Cargo.toml b/Cargo.toml index 67517a5..b1c78da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bird-looking-glass-proxy" -version = "0.0.2" +version = "0.0.3" edition = "2021" [dependencies] diff --git a/config.toml b/config.toml index ad71787..e97557e 100644 --- a/config.toml +++ b/config.toml @@ -1,14 +1,10 @@ bind_ip = "0.0.0.0" -bind_port = 5000 +bind_port = 8000 # Used to restrict access to bird-looking-glass-proxy based on source IP address. # Empty list = any IP is allowed to run queries. access_list = ["127.0.0.1"] -# Used to restrict access to bird-looking-glass-proxy based on a shared secret (must also be configured in lg.cfg) -# Empty string or unset = no shared secret is required to run queries. -shared_secret="ThisTokenIsNotSecret" - # Used as source address when running traceroute ipv4_source="198.51.100.42" ipv6_source="2001:db8:42::1" diff --git a/src/main.rs b/src/main.rs index 42fea24..e1ac303 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ lazy_static! { .arg_from_usage("-e, --example 'Export sample config file'") .get_matches(); if matches.is_present("example") { - println!("bind_ip = \"0.0.0.0\"\nbind_port = 5000\n\n# Used to restrict access to bird-looking-glass-proxy based on source IP address.\n# Empty list = any IP is allowed to run queries.\naccess_list = [\"127.0.0.1\"]\n\n# Used to restrict access to bird-looking-glass-proxy based on a shared secret (must also be configured in lg.cfg)\n# Empty string or unset = no shared secret is required to run queries.\nshared_secret=\"ThisTokenIsNotSecret\"\n\n# Used as source address when running traceroute\nipv4_source=\"198.51.100.42\"\nipv6_source=\"2001:db8:42::1\"\n\nbird_socket=\"/var/run/bird/bird.ctl\"\nbird6_socket=\"/var/run/bird/bird6.ctl\""); + println!("bind_ip = \"0.0.0.0\"\nbind_port = 5000\n\n# Used to restrict access to bird-looking-glass-proxy based on source IP address.\n# Empty list = any IP is allowed to run queries.\naccess_list = [\"127.0.0.1\"]\n\n# Used as source address when running traceroute\nipv4_source=\"198.51.100.42\"\nipv6_source=\"2001:db8:42::1\"\n\nbird_socket=\"/var/run/bird/bird.ctl\"\nbird6_socket=\"/var/run/bird/bird6.ctl\""); std::process::exit(0); } config::Config::new(matches.value_of("config").unwrap_or("config.toml")) diff --git a/src/route/bird.rs b/src/route/bird.rs index 0abb4ca..36ccafe 100644 --- a/src/route/bird.rs +++ b/src/route/bird.rs @@ -16,7 +16,76 @@ pub async fn bird(_param: web::Query, _req: HttpRequest, mode: i8) -> Res }); let mut connection = block_on(client.connect())?; let messages = block_on(connection.send_request(&_param.q))?; - return Ok(messages.iter().map(|message |format!("{:?}",message)).collect::()); + return Ok(messages.iter().map(|message | match message { + Message::Welcome(s) | + Message::ReadingConfiguration(s) | + Message::Reconfigured(s) | + Message::ReconfigurationInProgress(s) | + Message::ReconfigurationQueued(s) | + Message::ReconfigurationIgnoredShutdown(s) | + Message::ShutdownOrdered(s) | + Message::AlreadyDisable(s) | + Message::Disabled(s) | + Message::AlreadyEnabled(s) | + Message::Enabled(s) | + Message::Restarted(s) | + Message::StatusReport(s) | + Message::RouteCount(s) | + Message::Reloading(s) | + Message::AccessRestricted(s) | + Message::ReconfigurationUnQueued(s) | + Message::ReconfigurationConfirmed(s) | + Message::NothingToDo(s) | + Message::ConfigurationOk(s) | + Message::UndoRequested(s) | + Message::UndoScheduled(s) | + Message::EvaluatingExpression(s) | + Message::GracefulRestartStatus(s) | + Message::BirdVersion(s) | + Message::InterfaceList(s) | + Message::ProtocolList(s) | + Message::InterfaceAddress(s) | + Message::InterfaceFlags(s) | + Message::InterfaceSummary(s) | + Message::ProtocolDetails(s) | + Message::RouteList(s) | + Message::RouteDetails(s) | + Message::StaticRouteList(s) | + Message::SymbolList(s) | + Message::Uptime(s) | + Message::RouteExtendedAttributeList(s) | + Message::OspfNeighbors(s) | + Message::Ospf(s) | + Message::OspfInterface(s) | + Message::OspfState(s) | + Message::OspfLsadb(s) | + Message::Memory(s) | + Message::RoaList(s) | + Message::BfdSessions(s) | + Message::RipInterfaces(s) | + Message::RipNeighbors(s) | + Message::BabelInterfaces(s) | + Message::BabelNeighbors(s) | + Message::BabelEntries(s) | + Message::ProtocolListHeader(s) | + Message::InterfaceSummaryHeader(s) | + Message::TableHeader(_, s) | + Message::ReplyTooLong(s) | + Message::RouteNotFound(s) | + Message::ConfigurationFileError(s) | + Message::NoProtocolsMatch(s) | + Message::StoppedDueToReconfiguration(s) | + Message::ProtocolDown(s) | + Message::ReloadFailed(s) | + Message::AccessDenied(s) | + Message::RuntimeError(_, s) | + Message::CommandTooLong(s) | + Message::ParseError(s) | + Message::InvalidSymbol(s) | + Message::ClientError(_, s) | + Message::Unknown(_, s) => s.to_string(), + _ => "".to_string(), + }).collect::>().join("\n")); } pub async fn bird4(_param: web::Query, _req: HttpRequest) -> impl Responder {