Skip to content

Commit dcc21be

Browse files
authored
Merge pull request #9 from Lissy93/FEAT/support-for-https
[Feature] Support for HTTPS / User-defined protocol Fixes #7
2 parents 52a4cbf + 9dae69e commit dcc21be

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

.github/CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Catch error caused by unknown AdGuard field, last_updated (#5)
2-
Add support for ARMv7 and ARM_64 binaries (#4)
1+
Enables support for HTTPS, via optional user-defined protocol (#7)

.github/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ The following params are accepted:
136136
- `ADGUARD_USERNAME` / `--adguard-username` - An AdGuard Home username
137137
- `ADGUARD_PASSWORD` / `--adguard-password` - An AdGuard Home password
138138

139+
There's also some additional optional environment variables that you may set:
140+
141+
- `ADGUARD_PROTOCOL` - The protocol to use when connecting to AdGuard (defaults to `http`)
142+
- `ADGUARD_UPDATE_INTERVAL` - The rate at which to refresh the UI in seconds (defaults to `2`)
143+
139144
<details>
140145
<summary>Examples</summary>
141146

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "adguardian"
3-
version = "1.2.0"
3+
version = "1.3.0"
44
edition = "2021"
55
authors = ["Alicia Sykes"]
66
description = "Terminal-based, real-time traffic monitoring and statistics for your AdGuard Home instance "

src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ async fn run() -> anyhow::Result<()> {
2424
// AdGuard instance details, from env vars (verified in welcome.rs)
2525
let ip = env::var("ADGUARD_IP")?;
2626
let port = env::var("ADGUARD_PORT")?;
27-
let hostname = format!("http://{}:{}", ip, port);
27+
let protocol = env::var("ADGUARD_PROTOCOL").unwrap_or("http".to_string());
28+
let hostname = format!("{}://{}:{}", protocol, ip, port);
2829
let username = env::var("ADGUARD_USERNAME")?;
2930
let password = env::var("ADGUARD_PASSWORD")?;
31+
3032

3133
// Fetch data that doesn't require updates
3234
let filters = fetch_adguard_filter_list(&client, &hostname, &username, &password).await?;

src/welcome.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async fn verify_connection(
6262
client: &Client,
6363
ip: String,
6464
port: String,
65+
protocol: String,
6566
username: String,
6667
password: String,
6768
) -> Result<(), Box<dyn std::error::Error>> {
@@ -72,7 +73,7 @@ async fn verify_connection(
7273
let mut headers = reqwest::header::HeaderMap::new();
7374
headers.insert("Authorization", auth_header_value.parse()?);
7475

75-
let url = format!("http://{}:{}/control/status", ip, port);
76+
let url = format!("{}://{}:{}/control/status", protocol, ip, port);
7677

7778
match client
7879
.get(&url)
@@ -105,6 +106,9 @@ pub async fn welcome() -> Result<(), Box<dyn std::error::Error>> {
105106
("--adguard-password", "ADGUARD_PASSWORD"),
106107
];
107108

109+
let protocol: String = env::var("ADGUARD_PROTOCOL").unwrap_or_else(|_| "http".into()).parse()?;
110+
env::set_var("ADGUARD_PROTOCOL", protocol);
111+
108112
// Parse command line arguments
109113
let mut args = std::env::args().peekable();
110114
while let Some(arg) = args.next() {
@@ -136,8 +140,9 @@ pub async fn welcome() -> Result<(), Box<dyn std::error::Error>> {
136140

137141
let ip = get_env("ADGUARD_IP")?;
138142
let port = get_env("ADGUARD_PORT")?;
143+
let protocol = get_env("ADGUARD_PROTOCOL")?;
139144
let username = get_env("ADGUARD_USERNAME")?;
140145
let password = get_env("ADGUARD_PASSWORD")?;
141-
142-
verify_connection(&client, ip, port, username, password).await
146+
147+
verify_connection(&client, ip, port, protocol, username, password).await
143148
}

0 commit comments

Comments
 (0)