From eeccb19b35e078a33ba68b1be3830e699dec941d Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 29 Jul 2020 15:52:31 +0100 Subject: [PATCH 1/5] WIP: enable bind-addr control --- includes/system.php | 21 ++++++++++++++--- installers/configport.sh | 14 ++++++++--- locale/en_US/LC_MESSAGES/messages.po | 6 +++++ templates/system/advanced.php | 35 +++++++++++++++++----------- 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/includes/system.php b/includes/system.php index e8e340f8..4919b5ff 100755 --- a/includes/system.php +++ b/includes/system.php @@ -77,7 +77,8 @@ function DisplaySystem() } if (!RASPI_MONITOR_ENABLED) { - if (isset($_POST['SaveServerPort'])) { + if (isset($_POST['SaveServerSettings'])) { + // Save server port if (isset($_POST['serverPort'])) { if (strlen($_POST['serverPort']) > 4 || !is_numeric($_POST['serverPort'])) { $status->addMessage('Invalid value for port number', 'danger'); @@ -89,6 +90,19 @@ function DisplaySystem() } } } + // Save server bind address + if (isset($_POST['serverBind'])) { + if (!filter_var($_POST['serverBind'], FILTER_VALIDATE_IP)) { + $status->addMessage('Invalid value for bind address', 'danger'); + } else { + $serverBind = escapeshellarg($_POST['serverBind']); + //exec("sudo /etc/raspap/lighttpd/configport.sh $serverPort " .RASPI_LIGHTTPD_CONFIG. " ".$_SERVER['SERVER_NAME'], $return); + //foreach ($return as $line) { + // $status->addMessage($line, 'info'); + //} + } + } + } if (isset($_POST['system_reboot'])) { $status->addMessage("System Rebooting Now!", "warning", false); @@ -106,7 +120,8 @@ function DisplaySystem() } exec('cat '. RASPI_LIGHTTPD_CONFIG, $return); $conf = ParseConfig($return); - $ServerPort = $conf['server.port']; + $serverPort = $conf['server.port']; + $serverBind = str_replace('"', '',$conf['server.bind']); // define locales $arrLocales = array( @@ -132,5 +147,5 @@ function DisplaySystem() 'vi_VN.UTF-8' => 'Tiếng Việt (Vietnamese)' ); - echo renderTemplate("system", compact("arrLocales", "status", "ServerPort")); + echo renderTemplate("system", compact("arrLocales", "status", "serverPort", "serverBind")); } diff --git a/installers/configport.sh b/installers/configport.sh index 999726ce..a1350875 100755 --- a/installers/configport.sh +++ b/installers/configport.sh @@ -1,12 +1,20 @@ #!/bin/bash # -# Updates lighttpd server.port and restarts the service +# Updates lighttpd config settings and restarts the service # @author billz # license: GNU General Public License v3.0 +# Exit on error +set -o errexit +# Exit on error inside functions +set -o errtrace +# Turn on traces, disabled by default +#set -o xtrace + server_port=$1 -lighttpd_conf=$2 -host=$3 +server_bind=$2 +lighttpd_conf=$3 +host=$4 restart_service=0 while :; do diff --git a/locale/en_US/LC_MESSAGES/messages.po b/locale/en_US/LC_MESSAGES/messages.po index cf6dc3c9..39a7dd54 100644 --- a/locale/en_US/LC_MESSAGES/messages.po +++ b/locale/en_US/LC_MESSAGES/messages.po @@ -533,6 +533,12 @@ msgstr "System Rebooting Now!" msgid "System Shutting Down Now!" msgstr "System Shutting Down Now!" +msgid "Web server port" +msgstr "Web server port" + +msgid "Web server bind address" +msgstr "Web server bind address" + #: includes/themes.php msgid "Theme settings" msgstr "Theme settings" diff --git a/templates/system/advanced.php b/templates/system/advanced.php index bf81af2c..62303200 100644 --- a/templates/system/advanced.php +++ b/templates/system/advanced.php @@ -1,18 +1,25 @@ -
-

-
-
- -
- - - - +
+

+ + + +
+
+ + +
-
- " /> - " /> -
+
+
+ + +
+
+ " /> + " /> + + +
From b0ebd7bf00eb9f25be8d6c85f69e2fd959100dc1 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 5 Aug 2020 18:57:42 +0100 Subject: [PATCH 2/5] Add validate serverBind, save settings --- includes/system.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/includes/system.php b/includes/system.php index 4919b5ff..a66ec9e0 100755 --- a/includes/system.php +++ b/includes/system.php @@ -78,32 +78,35 @@ function DisplaySystem() if (!RASPI_MONITOR_ENABLED) { if (isset($_POST['SaveServerSettings'])) { - // Save server port + $good_input = true; + // Validate server port if (isset($_POST['serverPort'])) { if (strlen($_POST['serverPort']) > 4 || !is_numeric($_POST['serverPort'])) { $status->addMessage('Invalid value for port number', 'danger'); + $good_input = false; } else { $serverPort = escapeshellarg($_POST['serverPort']); - exec("sudo /etc/raspap/lighttpd/configport.sh $serverPort " .RASPI_LIGHTTPD_CONFIG. " ".$_SERVER['SERVER_NAME'], $return); - foreach ($return as $line) { - $status->addMessage($line, 'info'); - } - } + } } - // Save server bind address - if (isset($_POST['serverBind'])) { + // Validate server bind address + $serverBind = escapeshellarg(''); + if ($_POST['serverBind'] && $_POST['serverBind'] !== null ) { if (!filter_var($_POST['serverBind'], FILTER_VALIDATE_IP)) { $status->addMessage('Invalid value for bind address', 'danger'); + $good_input = false; } else { $serverBind = escapeshellarg($_POST['serverBind']); - //exec("sudo /etc/raspap/lighttpd/configport.sh $serverPort " .RASPI_LIGHTTPD_CONFIG. " ".$_SERVER['SERVER_NAME'], $return); - //foreach ($return as $line) { - // $status->addMessage($line, 'info'); - //} } } - + // Save settings + if ($good_input) { + exec("sudo /etc/raspap/lighttpd/configport.sh $serverPort $serverBind " .RASPI_LIGHTTPD_CONFIG. " ".$_SERVER['SERVER_NAME'], $return); + foreach ($return as $line) { + $status->addMessage($line, 'info'); + } + } } + if (isset($_POST['system_reboot'])) { $status->addMessage("System Rebooting Now!", "warning", false); $result = shell_exec("sudo /sbin/reboot"); From 08011100cd5329c3dcbb349772f98185069b3154 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 5 Aug 2020 18:58:29 +0100 Subject: [PATCH 3/5] Add/update save server.bind option --- installers/configport.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/installers/configport.sh b/installers/configport.sh index a1350875..27182159 100755 --- a/installers/configport.sh +++ b/installers/configport.sh @@ -33,11 +33,20 @@ if [ "$restart_service" = 1 ]; then echo "Restarting lighttpd in 3 seconds..." sleep 3 systemctl restart lighttpd.service -else - echo "Changing lighttpd server.port to $server_port..." +fi +if [ -n "$server_port" ]; then + echo "Changing lighttpd server.port to $server_port ..." sed -i "s/^\(server\.port *= *\)[0-9]*/\1$server_port/g" "$lighttpd_conf" - echo "RaspAP will now be available at $host:$server_port" echo "Restart lighttpd for new setting to take effect" fi +if [ -n "$server_bind" ]; then + echo "Changing lighttpd server.bind to $server_bind ..." + grep -q 'server.bind' "$lighttpd_conf" && \ + sed -i "s/^\(server\.bind.*= \)\".*\"*/\1\"$server_bind\"/g" "$lighttpd_conf" || \ + printf "server.bind \t\t\t\t = \"$server_bind\"" >> "$lighttpd_conf" + echo "RaspAP will now be available at $server_bind" + echo "Restart lighttpd for new setting to take effect" +fi + From 83ff3198aabb1084e4eff772fb453e38959b86d5 Mon Sep 17 00:00:00 2001 From: billz Date: Wed, 5 Aug 2020 23:07:55 +0100 Subject: [PATCH 4/5] Modify return message --- installers/configport.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/installers/configport.sh b/installers/configport.sh index 27182159..ee78080d 100755 --- a/installers/configport.sh +++ b/installers/configport.sh @@ -37,16 +37,18 @@ fi if [ -n "$server_port" ]; then echo "Changing lighttpd server.port to $server_port ..." sed -i "s/^\(server\.port *= *\)[0-9]*/\1$server_port/g" "$lighttpd_conf" - echo "RaspAP will now be available at $host:$server_port" - echo "Restart lighttpd for new setting to take effect" + echo "RaspAP will now be available at port $server_port" + conf_change=1 fi if [ -n "$server_bind" ]; then echo "Changing lighttpd server.bind to $server_bind ..." grep -q 'server.bind' "$lighttpd_conf" && \ sed -i "s/^\(server\.bind.*= \)\".*\"*/\1\"$server_bind\"/g" "$lighttpd_conf" || \ printf "server.bind \t\t\t\t = \"$server_bind\"" >> "$lighttpd_conf" - echo "RaspAP will now be available at $server_bind" - echo "Restart lighttpd for new setting to take effect" + echo "RaspAP will now be available at address $server_bind" + conf_change=1 +fi +if [ "$conf_change" == 1 ]; then + echo "Restart lighttpd for new settings to take effect" fi - From cfd26ae2bd28c03e1c810b503b63c095a14f2947 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 6 Aug 2020 08:34:14 +0100 Subject: [PATCH 5/5] Add newline --- installers/configport.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installers/configport.sh b/installers/configport.sh index ee78080d..b4f44e33 100755 --- a/installers/configport.sh +++ b/installers/configport.sh @@ -44,7 +44,7 @@ if [ -n "$server_bind" ]; then echo "Changing lighttpd server.bind to $server_bind ..." grep -q 'server.bind' "$lighttpd_conf" && \ sed -i "s/^\(server\.bind.*= \)\".*\"*/\1\"$server_bind\"/g" "$lighttpd_conf" || \ - printf "server.bind \t\t\t\t = \"$server_bind\"" >> "$lighttpd_conf" + printf "server.bind \t\t\t\t = \"$server_bind\"\n" >> "$lighttpd_conf" echo "RaspAP will now be available at address $server_bind" conf_change=1 fi