Merge pull request #648 from billz/feature/bind-addr

Feature: Add server.bind address option to System UI
This commit is contained in:
Bill Zimmerman 2020-08-06 09:44:52 +02:00 committed by GitHub
commit b2b3d58afd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 29 deletions

View file

@ -77,19 +77,36 @@ function DisplaySystem()
}
if (!RASPI_MONITOR_ENABLED) {
if (isset($_POST['SaveServerPort'])) {
if (isset($_POST['SaveServerSettings'])) {
$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');
}
}
}
// 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']);
}
}
// 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");
@ -106,7 +123,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 +150,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"));
}

View file

@ -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
@ -25,11 +33,22 @@ 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"
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\"\n" >> "$lighttpd_conf"
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

View file

@ -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"

View file

@ -1,18 +1,25 @@
<!-- advanced tab -->
<div role="tabpanel" class="tab-pane" id="advanced">
<h4 class="mt-3"><?php echo _("Advanced settings") ;?></h4>
<div class="row">
<div class="form-group col-md-6">
<label for="code"><?php echo _("Web server port") ;?></label>
<form action="?page=system_info" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<input type="text" class="form-control" name="serverPort" value="<?php echo htmlspecialchars($ServerPort, ENT_QUOTES); ?>" />
<?php endif ?>
<div role="tabpanel" class="tab-pane" id="advanced">
<h4 class="mt-3"><?php echo _("Advanced settings") ;?></h4>
<?php if (!RASPI_MONITOR_ENABLED) : ?>
<form action="?page=system_info" method="POST">
<?php echo CSRFTokenFieldTag() ?>
<div class="row">
<div class="form-group col-md-6">
<label for="code"><?php echo _("Web server port") ;?></label>
<input type="text" class="form-control" name="serverPort" value="<?php echo htmlspecialchars($serverPort, ENT_QUOTES); ?>" />
</div>
</div>
</div>
<input type="submit" class="btn btn-outline btn-primary" name="SaveServerPort" value="<?php echo _("Save settings"); ?>" />
<input type="submit" class="btn btn-warning" name="RestartLighttpd" value="<?php echo _("Restart lighttpd"); ?>" />
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="code"><?php echo _("Web server bind address") ;?></label>
<input type="text" class="form-control" name="serverBind" value="<?php echo htmlspecialchars($serverBind, ENT_QUOTES); ?>" />
</div>
</div>
<input type="submit" class="btn btn-outline btn-primary" name="SaveServerSettings" value="<?php echo _("Save settings"); ?>" />
<input type="submit" class="btn btn-warning" name="RestartLighttpd" value="<?php echo _("Restart lighttpd"); ?>" />
</form>
<?php endif ?>
</div>