Skip to content

Commit

Permalink
Merge pull request #9 from Lissy93/FEAT/support-for-https
Browse files Browse the repository at this point in the history
[Feature] Support for HTTPS / User-defined protocol
Fixes #7
  • Loading branch information
Lissy93 authored May 31, 2023
2 parents 52a4cbf + 9dae69e commit dcc21be
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

<details>
<summary>Examples</summary>

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 "
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
11 changes: 8 additions & 3 deletions src/welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async fn verify_connection(
client: &Client,
ip: String,
port: String,
protocol: String,
username: String,
password: String,
) -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -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)
Expand Down Expand Up @@ -105,6 +106,9 @@ pub async fn welcome() -> Result<(), Box<dyn std::error::Error>> {
("--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() {
Expand Down Expand Up @@ -136,8 +140,9 @@ pub async fn welcome() -> Result<(), Box<dyn std::error::Error>> {

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
}

0 comments on commit dcc21be

Please sign in to comment.