Skip to content

Commit

Permalink
🔨 Configure Adguard port/protocol dynamically on startup (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairpaul authored May 29, 2020
1 parent 56e8e28 commit edd538a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
8 changes: 8 additions & 0 deletions adguard/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ authentication on the AdGuard Home by setting it to `true`.
**Note**: _We STRONGLY suggest, not to use this, even if this add-on is
only exposed to your internal network. USE AT YOUR OWN RISK!_

## Encryption Settings (Advanced Usage)

Adguard allows the configuration of running DNS-over-HTTPS and DNS-over-
TLS locally. If you configure these options please ensure to restart the
addon afterwards. Also to use DNS-over-HTTPS correctly please ensure to
configure SSL on the addon as well as in Adguard itself. Also consider
that the addon and Adguard cannot use the same port for SSL.

## Changelog & Releases

This repository keeps a change log using [GitHub's releases][releases]
Expand Down
11 changes: 11 additions & 0 deletions adguard/rootfs/etc/cont-init.d/nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
# Home Assistant Community Add-on: AdGuard Home
# Configures NGINX for use with the AdGuard Home server
# ==============================================================================
declare adguard_port=45158
declare adguard_protocol=http
declare admin_port
declare certfile
declare dns_host
declare ingress_interface
declare ingress_port
declare keyfile

if bashio::var.true "$(yq read /data/adguard/AdGuardHome.yaml tls.enabled)"; then
adguard_port=$(yq read /data/adguard/AdGuardHome.yaml tls.port_https)

This comment has been minimized.

Copy link
@hastarin

hastarin May 31, 2020

This is NOT safe. If the admin interface has left this blank (you can have TLS without HTTPS support) things crash on startup.

[11:39:22] INFO: Starting NGinx...
nginx: [emerg] invalid port in upstream "127.0.0.1:0" in /etc/nginx/includes/upstream.conf:2

This comment has been minimized.

Copy link
@frenck

frenck May 31, 2020

Member

Please do not comment on commits. It is annoying, and not trackable.
Instead use issues (which you did), which is sufficient.

adguard_protocol=https
fi

sed -i "s#%%port%%#${adguard_port}#g" /etc/nginx/includes/upstream.conf
sed -i "s#%%protocol%%#${adguard_protocol}#g" /etc/nginx/servers/ingress.conf

admin_port=$(bashio::addon.port 80)
if bashio::var.has_value "${admin_port}"; then
bashio::config.require.ssl
Expand All @@ -27,6 +37,7 @@ if bashio::var.has_value "${admin_port}"; then
fi

sed -i "s/%%port%%/${admin_port}/g" /etc/nginx/servers/direct.conf
sed -i "s#%%protocol%%#${adguard_protocol}#g" /etc/nginx/servers/direct.conf
fi

ingress_port=$(bashio::addon.ingress_port)
Expand Down
2 changes: 1 addition & 1 deletion adguard/rootfs/etc/nginx/includes/upstream.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
upstream backend {
server 127.0.0.1:45158;
server 127.0.0.1:%%port%%;
}
7 changes: 6 additions & 1 deletion adguard/rootfs/etc/nginx/servers/direct-ssl.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ server {

location / {
access_by_lua_file /etc/nginx/lua/ha-auth.lua;
proxy_pass http://backend;
proxy_pass %%protocol%%://backend;
}

location /dns-query {
proxy_pass %%protocol%%://backend;
}

}
2 changes: 1 addition & 1 deletion adguard/rootfs/etc/nginx/servers/direct.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ server {

location / {
access_by_lua_file /etc/nginx/lua/ha-auth.lua;
proxy_pass http://backend;
proxy_pass %%protocol%%://backend;
}
}
2 changes: 1 addition & 1 deletion adguard/rootfs/etc/nginx/servers/ingress.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ server {
allow 172.30.32.2;
deny all;

proxy_pass http://backend;
proxy_pass %%protocol%%://backend;
}
}

0 comments on commit edd538a

Please sign in to comment.