From 2b95d3b75fad20586e4bae6f4bfbcc1d4ab17afe Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 31 May 2023 21:21:34 +0100 Subject: [PATCH 1/3] Enables https use of protocol (#7) --- src/main.rs | 4 +++- src/welcome.rs | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8ab7e23..ccc2caf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,9 +24,11 @@ async fn run() -> anyhow::Result<()> { // AdGuard instance details, from env vars (verified in welcome.rs) let ip = env::var("ADGUARD_IP")?; let port = env::var("ADGUARD_PORT")?; - let hostname = format!("http://{}:{}", ip, port); + let protocol = env::var("ADGUARD_PROTOCOL").unwrap_or("http".to_string()); + let hostname = format!("{}://{}:{}", protocol, ip, port); let username = env::var("ADGUARD_USERNAME")?; let password = env::var("ADGUARD_PASSWORD")?; + // Fetch data that doesn't require updates let filters = fetch_adguard_filter_list(&client, &hostname, &username, &password).await?; diff --git a/src/welcome.rs b/src/welcome.rs index 098afd4..79e5750 100644 --- a/src/welcome.rs +++ b/src/welcome.rs @@ -62,6 +62,7 @@ async fn verify_connection( client: &Client, ip: String, port: String, + protocol: String, username: String, password: String, ) -> Result<(), Box> { @@ -72,7 +73,7 @@ async fn verify_connection( let mut headers = reqwest::header::HeaderMap::new(); headers.insert("Authorization", auth_header_value.parse()?); - let url = format!("http://{}:{}/control/status", ip, port); + let url = format!("{}://{}:{}/control/status", protocol, ip, port); match client .get(&url) @@ -105,6 +106,9 @@ pub async fn welcome() -> Result<(), Box> { ("--adguard-password", "ADGUARD_PASSWORD"), ]; + let protocol: String = env::var("ADGUARD_PROTOCOL").unwrap_or_else(|_| "http".into()).parse()?; + env::set_var("ADGUARD_PROTOCOL", protocol); + // Parse command line arguments let mut args = std::env::args().peekable(); while let Some(arg) = args.next() { @@ -136,8 +140,9 @@ pub async fn welcome() -> Result<(), Box> { let ip = get_env("ADGUARD_IP")?; let port = get_env("ADGUARD_PORT")?; + let protocol = get_env("ADGUARD_PROTOCOL")?; let username = get_env("ADGUARD_USERNAME")?; let password = get_env("ADGUARD_PASSWORD")?; - - verify_connection(&client, ip, port, username, password).await + + verify_connection(&client, ip, port, protocol, username, password).await } From 20f9d735bd5de9fe131d957c0ad9d97a0c5ea706 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 31 May 2023 21:24:28 +0100 Subject: [PATCH 2/3] Updates docs to include https options (#7) --- .github/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/README.md b/.github/README.md index c467ea4..80814e8 100644 --- a/.github/README.md +++ b/.github/README.md @@ -136,6 +136,11 @@ The following params are accepted: - `ADGUARD_USERNAME` / `--adguard-username` - An AdGuard Home username - `ADGUARD_PASSWORD` / `--adguard-password` - An AdGuard Home password +There's also some additional optional environment variables that you may set: + +- `ADGUARD_PROTOCOL` - The protocol to use when connecting to AdGuard (defaults to `http`) +- `ADGUARD_UPDATE_INTERVAL` - The rate at which to refresh the UI in seconds (defaults to `2`) +
Examples From 9dae69e66e3a9b50d541b038707fa71562e345e2 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 31 May 2023 21:33:33 +0100 Subject: [PATCH 3/3] Bumps version, and updates changelog --- .github/CHANGELOG.md | 3 +-- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 2257405..afb7071 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1,2 +1 @@ -Catch error caused by unknown AdGuard field, last_updated (#5) -Add support for ARMv7 and ARM_64 binaries (#4) +Enables support for HTTPS, via optional user-defined protocol (#7) diff --git a/Cargo.lock b/Cargo.lock index d0a4d0f..7891d76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "adguardian" -version = "1.2.0" +version = "1.3.0" dependencies = [ "anyhow", "base64 0.13.1", diff --git a/Cargo.toml b/Cargo.toml index 917ca20..39070b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adguardian" -version = "1.2.0" +version = "1.3.0" edition = "2021" authors = ["Alicia Sykes"] description = "Terminal-based, real-time traffic monitoring and statistics for your AdGuard Home instance "