diff --git a/home-panel/config.json b/home-panel/config.json index 1e4cfb2..0bd74c6 100644 --- a/home-panel/config.json +++ b/home-panel/config.json @@ -4,7 +4,7 @@ "slug": "home-panel", "description": "A touch-compatible web frontend for controlling the home.", "url": "https://github.com/hassio-addons/addon-home-panel", - "webui": "[PROTO:ssl]://[HOST]:[PORT:8234]", + "webui": "[PROTO:ssl]://[HOST]:[PORT:80]", "startup": "application", "arch": [ "aarch64", @@ -17,16 +17,19 @@ "hassio_role": "default", "hassio_api": true, "homeassistant_api": true, + "ingress": true, + "ingress_port": 1337, + "panel_icon": "mdi:home", + "homeassistant": "0.92.0b2", "ports": { - "3234/tcp": 3234, - "8234/tcp": 8234 + "80/tcp": null, + "3234/tcp": 3234 }, - "ports_descriptions": { - "3234/tcp": "Home Panel web interface", - "8234/tcp": "Home Panel API" + "ports_description": { + "80/tcp": "Web UI (Not required for Hass.io Ingress)", + "3234/tcp": "API" }, "map": [ - "config:rw", "ssl" ], "options": { diff --git a/home-panel/rootfs/etc/cont-init.d/10-requirements.sh b/home-panel/rootfs/etc/cont-init.d/10-requirements.sh deleted file mode 100644 index 0455f33..0000000 --- a/home-panel/rootfs/etc/cont-init.d/10-requirements.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/with-contenv bashio -# ============================================================================== -# Community Hass.io Add-ons: Home Panel -# This checks if all user configuration requirements are met -# ============================================================================== -# Check SSL settings -bashio::config.require.ssl diff --git a/home-panel/rootfs/etc/cont-init.d/40-nginx.sh b/home-panel/rootfs/etc/cont-init.d/40-nginx.sh deleted file mode 100644 index 2e727d2..0000000 --- a/home-panel/rootfs/etc/cont-init.d/40-nginx.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/with-contenv bashio -# ============================================================================== -# Community Hass.io Add-ons: Home Panel -# Configures NGINX for use with Home Panel -# ============================================================================== -declare certfile -declare keyfile - -# Enable SSL -if bashio::config.true 'ssl'; then - certfile=$(bashio::config 'certfile') - keyfile=$(bashio::config 'keyfile') - - sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx-ssl.conf - sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx-ssl.conf -fi diff --git a/home-panel/rootfs/etc/cont-init.d/nginx.sh b/home-panel/rootfs/etc/cont-init.d/nginx.sh new file mode 100644 index 0000000..a53a162 --- /dev/null +++ b/home-panel/rootfs/etc/cont-init.d/nginx.sh @@ -0,0 +1,32 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Matrix +# Configures NGINX for use with Riot +# ============================================================================== +declare port +declare certfile +declare ingress_interface +declare ingress_port +declare keyfile + +port=$(bashio::addon.port 80) +if bashio::var.has_value "${port}"; then + bashio::config.require.ssl + + if bashio::config.true 'ssl'; then + certfile=$(bashio::config 'certfile') + keyfile=$(bashio::config 'keyfile') + + mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf + sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf + sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf + + else + mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf + fi +fi + +ingress_port=$(bashio::addon.ingress_port) +ingress_interface=$(bashio::addon.ip_address) +sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf +sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf diff --git a/home-panel/rootfs/etc/cont-init.d/20-secrets.sh b/home-panel/rootfs/etc/cont-init.d/secrets.sh similarity index 100% rename from home-panel/rootfs/etc/cont-init.d/20-secrets.sh rename to home-panel/rootfs/etc/cont-init.d/secrets.sh diff --git a/home-panel/rootfs/etc/nginx/includes/mime.types b/home-panel/rootfs/etc/nginx/includes/mime.types new file mode 100644 index 0000000..7c7cdef --- /dev/null +++ b/home-panel/rootfs/etc/nginx/includes/mime.types @@ -0,0 +1,96 @@ +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/home-panel/rootfs/etc/nginx/includes/resolver.conf b/home-panel/rootfs/etc/nginx/includes/resolver.conf new file mode 100644 index 0000000..758ca69 --- /dev/null +++ b/home-panel/rootfs/etc/nginx/includes/resolver.conf @@ -0,0 +1 @@ +resolver 172.30.32.2; diff --git a/home-panel/rootfs/etc/nginx/includes/server_params.conf b/home-panel/rootfs/etc/nginx/includes/server_params.conf new file mode 100644 index 0000000..f90db57 --- /dev/null +++ b/home-panel/rootfs/etc/nginx/includes/server_params.conf @@ -0,0 +1,6 @@ +root /opt/panel; +server_name $hostname; + +add_header X-Content-Type-Options nosniff; +add_header X-XSS-Protection "1; mode=block"; +add_header X-Robots-Tag none; diff --git a/home-panel/rootfs/etc/nginx/includes/ssl_params.conf b/home-panel/rootfs/etc/nginx/includes/ssl_params.conf new file mode 100644 index 0000000..6f15005 --- /dev/null +++ b/home-panel/rootfs/etc/nginx/includes/ssl_params.conf @@ -0,0 +1,9 @@ +ssl_protocols TLSv1.2; +ssl_prefer_server_ciphers on; +ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA; +ssl_ecdh_curve secp384r1; +ssl_session_timeout 10m; +ssl_session_cache shared:SSL:10m; +ssl_session_tickets off; +ssl_stapling on; +ssl_stapling_verify on; diff --git a/home-panel/rootfs/etc/nginx/modules/ndk_http.conf b/home-panel/rootfs/etc/nginx/modules/ndk_http.conf new file mode 100644 index 0000000..2663122 --- /dev/null +++ b/home-panel/rootfs/etc/nginx/modules/ndk_http.conf @@ -0,0 +1 @@ +load_module "/usr/lib/nginx/modules/ndk_http_module.so"; diff --git a/home-panel/rootfs/etc/nginx/nginx-ssl.conf b/home-panel/rootfs/etc/nginx/nginx-ssl.conf deleted file mode 100644 index e586e4f..0000000 --- a/home-panel/rootfs/etc/nginx/nginx-ssl.conf +++ /dev/null @@ -1,36 +0,0 @@ -worker_processes 1; -pid /var/run/nginx.pid; -error_log /dev/stdout info; -daemon off; - -events { - worker_connections 1024; -} - -http { - include mime.types; - server { - listen 8234 default_server ssl; - - server_name home-panel; - access_log /dev/stdout combined; - - client_max_body_size 4G; - keepalive_timeout 5; - - root /opt/panel; - - ssl on; - ssl_certificate /ssl/%%certfile%%; - ssl_certificate_key /ssl/%%keyfile%%; - ssl_protocols TLSv1.2; - ssl_prefer_server_ciphers on; - ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA; - ssl_ecdh_curve secp384r1; - ssl_session_timeout 10m; - ssl_session_cache shared:SSL:10m; - ssl_session_tickets off; - ssl_stapling on; - ssl_stapling_verify on; - } -} diff --git a/home-panel/rootfs/etc/nginx/nginx.conf b/home-panel/rootfs/etc/nginx/nginx.conf index b5ca927..e0e2e26 100644 --- a/home-panel/rootfs/etc/nginx/nginx.conf +++ b/home-panel/rootfs/etc/nginx/nginx.conf @@ -1,23 +1,53 @@ -worker_processes 1; -pid /var/run/nginx.pid; -error_log /dev/stdout info; +# Run nginx in foreground. daemon off; +# This is run inside Docker. +user root; + +# Pid storage location. +pid /var/run/nginx.pid; + +# Set number of worker processes. +worker_processes 1; + +# Enables the use of JIT for regular expressions to speed-up their processing. +pcre_jit on; + +# Write error log to Hass.io add-on log. +error_log /proc/1/fd/1 error; + +# Load allowed environment vars +env HASSIO_TOKEN; +env DISABLE_HA_AUTHENTICATION; + +# Max num of simultaneous connections by a worker process. events { - worker_connections 1024; + worker_connections 512; } http { - include mime.types; - server { - listen 8234 default_server; + include /etc/nginx/includes/mime.types; - server_name home-panel; - access_log /dev/stdout combined; + log_format hassio '[$time_local] $status ' + '$http_x_forwarded_for($remote_addr) ' + '$request ($http_user_agent)'; - client_max_body_size 4G; - keepalive_timeout 5; + access_log /proc/1/fd/1 hassio; + client_max_body_size 4G; + default_type application/octet-stream; + gzip on; + keepalive_timeout 65; + sendfile on; + server_tokens off; + tcp_nodelay on; + tcp_nopush on; - root /opt/panel; + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; } + + include /etc/nginx/includes/resolver.conf; + + include /etc/nginx/servers/*.conf; } diff --git a/home-panel/rootfs/etc/nginx/servers/direct-ssl.disabled b/home-panel/rootfs/etc/nginx/servers/direct-ssl.disabled new file mode 100644 index 0000000..f09b758 --- /dev/null +++ b/home-panel/rootfs/etc/nginx/servers/direct-ssl.disabled @@ -0,0 +1,10 @@ +server { + listen 80 default_server ssl http2; + + include /etc/nginx/includes/server_params.conf; + include /etc/nginx/includes/ssl_params.conf; + + ssl on; + ssl_certificate /ssl/%%certfile%%; + ssl_certificate_key /ssl/%%keyfile%%; +} diff --git a/home-panel/rootfs/etc/nginx/servers/direct.disabled b/home-panel/rootfs/etc/nginx/servers/direct.disabled new file mode 100644 index 0000000..b332dff --- /dev/null +++ b/home-panel/rootfs/etc/nginx/servers/direct.disabled @@ -0,0 +1,5 @@ +server { + listen 80 default_server; + + include /etc/nginx/includes/server_params.conf; +} diff --git a/home-panel/rootfs/etc/nginx/servers/ingress.conf b/home-panel/rootfs/etc/nginx/servers/ingress.conf new file mode 100644 index 0000000..2f6839f --- /dev/null +++ b/home-panel/rootfs/etc/nginx/servers/ingress.conf @@ -0,0 +1,8 @@ +server { + listen %%interface%%:%%port%% default_server; + + include /etc/nginx/includes/server_params.conf; + + allow 172.30.32.2; + deny all; +} diff --git a/home-panel/rootfs/etc/services.d/nginx/run b/home-panel/rootfs/etc/services.d/nginx/run index 005946e..5f7e5ec 100644 --- a/home-panel/rootfs/etc/services.d/nginx/run +++ b/home-panel/rootfs/etc/services.d/nginx/run @@ -3,12 +3,13 @@ # Community Hass.io Add-ons: Home Panel # Runs the NGINX daemon # ============================================================================== -bashio::log.info "Starting NGINX..." +# Wait for the API to start +bashio::net.wait_for 3234 -if bashio::config.true 'ssl'; then - options='/etc/nginx/nginx-ssl.conf' -else - options='/etc/nginx/nginx.conf' +# Disable HA Authentication if front door is open +if bashio::config.true 'leave_front_door_open'; then + export DISABLE_HA_AUTHENTICATION=true fi -exec nginx -c "$options" +bashio::log.info "Starting NGINX..." +exec nginx