Merge pull request #132 from bergware/6.4-wip

Added GUI access mode
This commit is contained in:
tom mortensen
2017-06-23 03:43:01 -07:00
committed by GitHub
4 changed files with 114 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
Menu="WebGui"
Title="GUI Access"
---
<?PHP
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$emhttp = preg_split('/\s+/',exec("grep '/usr/local/sbin/emhttp' /boot/config/go"));
while ($emhttp[0] != '/usr/local/sbin/emhttp') $emhttp = array_shift($emhttp);
list($cmd,$options,$ports,$spare) = $emhttp;
if ($ports[0] == '-') {
$options .= substr($ports,1);
$ports = $spare;
}
list($http,$https) = explode(',',$ports);
switch ($options) {
case '' :
case '&' : $protocol = 'http'; $options = ''; break;
case '-p' : $protocol = $http ? 'http' : 'https'; break;
case '-rp':
case '-pr': $protocol = 'redirect'; break;
default: $protocol = 'http';
}
?>
<script>
function showPorts(form) {
var http = $(form).find('div#http');
var https = $(form).find('div#https');
switch (form.protocol.value) {
case 'http' : http.show(); https.hide(); break;
case 'https' : http.hide(); https.show(); break;
case 'redirect': http.show(); https.show(); break;
}
}
function setGUI(form) {
switch (form.protocol.value) {
case 'http':
if (form.http.value=='' || form.http.value=='80') {
$('input[name="#arg[1]"]').val('');
$('input[name="#arg[2]"]').val('');
} else {
$('input[name="#arg[1]"]').val('-p');
$('input[name="#arg[2]"]').val(form.http.value);
}
break;
case 'https':
$('input[name="#arg[1]"]').val('-p');
if (form.https.value=='') {
$('input[name="#arg[2]"]').val(',443');
} else {
$('input[name="#arg[2]"]').val(','+form.https.value);
}
break;
case 'redirect':
$('input[name="#arg[1]"]').val('-rp');
$('input[name="#arg[2]"]').val((form.http.value||'80')+','+(form.https.value||'443'));
break;
}
}
$(function() {
showPorts(document.access_mode);
});
</script>
<form markdown="1" name="access_mode" method="POST" action="/update.php" target="progressFrame" onsubmit="setGUI(this)">
<input type="hidden" name="#command" value="/webGui/scripts/accessmode">
<input type="hidden" name="#arg[1]" value="<?=$options?>">
<input type="hidden" name="#arg[2]" value="<?=$ports?>">
GUI protocol:
: <select name="protocol" size="1" onchange="showPorts(this.form)">
<?=mk_option($protocol, "http", "HTTP")?>
<?=mk_option($protocol, "https", "HTTPS")?>
<?=mk_option($protocol, "redirect", "REDIRECT")?>
</select>
<div markdown="1" id="http" style="display:none">
HTTP port:
: <input type="text" name="http" maxlength="" value="<?=$http ?: '80'?>" class="narrow">
</div>
<div markdown="1" id="https" style="display:none">
HTTPS port:
: <input type="text" name="https" maxlength="" value="<?=$https ?: '443'?>" class="narrow">
</div>
&nbsp;
: <input type="submit" value="Apply"><input type="button" value="Done" onclick="done()">
</form>

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

View File

@@ -0,0 +1,10 @@
#!/bin/bash
# usage: accessmode [-r] [-p http [,https]]
[[ -n $1 ]] && options="$1" || options=
[[ -n $2 ]] && options="$1 $2"
[[ -n $options ]] && options="$options \&" || options="\&"
sed -ri "s|^(.*/usr/local/sbin/emhttp).*|\1 $options|" /boot/config/go
# We need to restart the GUI in a separate process to prevent it from hanging
at -M -f /usr/local/emhttp/webGui/scripts/restart_gui now 2>/dev/null

View File

@@ -0,0 +1,8 @@
#!/bin/bash
# read go file settings and restart GUI
# called from accessmode script
/usr/local/sbin/emhttp stop >/dev/null
/usr/local/sbin/emhttp $(grep -Po '^.*/usr/local/sbin/emhttp \K[^&]*' /boot/config/go) >/dev/null
/etc/rc.d/rc.php-fpm start >/dev/null
/etc/rc.d/rc.nginx start >/dev/null