mirror of
https://github.com/YunoHost-Apps/hotspot_ynh.git
synced 2024-09-03 19:25:53 +02:00
Add service status on the web admin
This commit is contained in:
parent
dbf4697ff2
commit
f61bcb410f
11 changed files with 164 additions and 32 deletions
|
@ -181,6 +181,19 @@ moulinette_get() {
|
||||||
echo "${value}"
|
echo "${value}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moulinette_vpnclient_get() {
|
||||||
|
var=${1}
|
||||||
|
|
||||||
|
value=$(yunohost app setting vpnclient "${var}")
|
||||||
|
|
||||||
|
if [[ "${value}" =~ "An instance is already running" ]]; then
|
||||||
|
echo "${value}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${value}"
|
||||||
|
}
|
||||||
|
|
||||||
moulinette_set() {
|
moulinette_set() {
|
||||||
var=${1}
|
var=${1}
|
||||||
value=${2}
|
value=${2}
|
||||||
|
@ -193,6 +206,12 @@ moulinette_set() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Restart php5-fpm at the first start (it needs to be restarted after the slapd start)
|
||||||
|
if [ ! -e /tmp/.ynh-hotspot-boot ]; then
|
||||||
|
touch /tmp/.ynh-hotspot-boot
|
||||||
|
service php5-fpm restart
|
||||||
|
fi
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
||||||
echo -n "Retrieving Yunohost settings... "
|
echo -n "Retrieving Yunohost settings... "
|
||||||
|
@ -221,6 +240,21 @@ fi
|
||||||
|
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
|
||||||
|
# Check IPv6 delegated prefix from vpnclient
|
||||||
|
if [ "${ynh_ip6_net}" == none ]; then
|
||||||
|
ynh_ip6_net=$(moulinette_vpnclient_get ip6_net)
|
||||||
|
ynh_ip6_addr=$(moulinette_vpnclient_get ip6_addr)
|
||||||
|
|
||||||
|
moulinette_set ip6_net "${ynh_ip6_net}"
|
||||||
|
moulinette_set ip6_addr "${ynh_ip6_addr}"
|
||||||
|
else
|
||||||
|
vpnclient_ip6_net=$(moulinette_vpnclient_get ip6_net)
|
||||||
|
|
||||||
|
if [ "${ynh_ip6_net}" != "${vpnclient_ip6_net}" ]; then
|
||||||
|
echo "[WARN] The IPv6 delegated prefix is different from the vpnclient one"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Script
|
# Script
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
@ -298,12 +332,6 @@ case "$1" in
|
||||||
# Update dynamic settings
|
# Update dynamic settings
|
||||||
moulinette_set internet_device "${new_internet_device}"
|
moulinette_set internet_device "${new_internet_device}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Restart php5-fpm at the first start (it needs to be restarted after the slapd start)
|
|
||||||
if [ ! -e /tmp/.ynh-hotspot-boot ]; then
|
|
||||||
touch /tmp/.ynh-hotspot-boot
|
|
||||||
service php5-fpm restart
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
echo "[hotspot] Stopping..."
|
echo "[hotspot] Stopping..."
|
||||||
|
@ -357,62 +385,64 @@ case "$1" in
|
||||||
exitcode=0
|
exitcode=0
|
||||||
|
|
||||||
if has_ip6delegatedprefix; then
|
if has_ip6delegatedprefix; then
|
||||||
|
echo "[INFO] IPv6 delegated prefix found"
|
||||||
|
|
||||||
if is_ndproxy_set; then
|
if is_ndproxy_set; then
|
||||||
echo "NDP proxy is correctly set"
|
echo "[OK] NDP proxy set"
|
||||||
else
|
else
|
||||||
echo "NDP proxy is NOT set"
|
echo "[ERR] No NDP proxy set"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_ip6addr_set; then
|
if is_ip6addr_set; then
|
||||||
echo "IPv6 address is correctly set"
|
echo "[OK] IPv6 address set"
|
||||||
else
|
else
|
||||||
echo "IPv6 address is NOT set"
|
echo "[ERR] No IPv6 address set"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_radvd_running; then
|
if is_radvd_running; then
|
||||||
echo "Radvd is running"
|
echo "[OK] Radvd is running"
|
||||||
else
|
else
|
||||||
echo "Radvd is NOT running"
|
echo "[ERR] Radvd is not running"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "No IPv6 delegated prefix"
|
echo "[INFO] No IPv6 delegated prefix found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_nat_set "${new_internet_device}"; then
|
if is_nat_set "${new_internet_device}"; then
|
||||||
echo "NAT is correctly set"
|
echo "[OK] IPv4 NAT set"
|
||||||
else
|
else
|
||||||
echo "NAT is NOT set"
|
echo "[ERR] No IPv4 NAT set"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_ip4nataddr_set; then
|
if is_ip4nataddr_set; then
|
||||||
echo "IPv4 NAT address is correctly set"
|
echo "[OK] IPv4 NAT address set"
|
||||||
else
|
else
|
||||||
echo "IPv4 NAT address is NOT set"
|
echo "[ERR] No IPv4 NAT address set"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_forwarding_set; then
|
if is_forwarding_set; then
|
||||||
echo "Forwarding is correctly set"
|
echo "[OK] IPv6/IPv4 forwarding set"
|
||||||
else
|
else
|
||||||
echo "Forwarding is NOT set"
|
echo "[ERR] No IPv6/IPv4 forwarding set"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_hostapd_running; then
|
if is_hostapd_running; then
|
||||||
echo "Hostapd is running"
|
echo "[OK] Hostapd is running"
|
||||||
else
|
else
|
||||||
echo "Hostapd is NOT running"
|
echo "[ERR] Hostapd is not running"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_dhcpd_running; then
|
if is_dhcpd_running; then
|
||||||
echo "Dhcpd is running"
|
echo "[OK] Dhcpd is running"
|
||||||
else
|
else
|
||||||
echo "Dhcpd is NOT running"
|
echo "[ERR] Dhcpd is not running"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ request_terminate_timeout = 600s
|
||||||
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
|
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
|
||||||
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
|
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
|
||||||
; Default Value: 0
|
; Default Value: 0
|
||||||
request_slowlog_timeout = 5s
|
request_slowlog_timeout = 0
|
||||||
|
|
||||||
; The log file for slow requests
|
; The log file for slow requests
|
||||||
; Default Value: not set
|
; Default Value: not set
|
||||||
|
@ -202,7 +202,7 @@ chdir = <TPL:NGINX_REALPATH>
|
||||||
; Note: on highloaded environement, this can cause some delay in the page
|
; Note: on highloaded environement, this can cause some delay in the page
|
||||||
; process time (several ms).
|
; process time (several ms).
|
||||||
; Default Value: no
|
; Default Value: no
|
||||||
catch_workers_output = yes
|
catch_workers_output = no
|
||||||
|
|
||||||
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
|
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
|
||||||
; the current environment.
|
; the current environment.
|
||||||
|
|
BIN
docs/box-project.png
Normal file
BIN
docs/box-project.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 557 KiB |
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 66 KiB |
|
@ -38,7 +38,7 @@ fi
|
||||||
sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server iptables php5-fpm
|
sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server iptables php5-fpm
|
||||||
|
|
||||||
# Extra packages
|
# Extra packages
|
||||||
sudo apt-get --assume-yes --force-yes install sipcalc iwconfig
|
sudo apt-get --assume-yes --force-yes install sipcalc iw
|
||||||
|
|
||||||
# Compute extra arguments
|
# Compute extra arguments
|
||||||
if [ -z "${ip6_net}" ]; then
|
if [ -z "${ip6_net}" ]; then
|
||||||
|
@ -147,8 +147,6 @@ sudo yunohost service disable hostapd
|
||||||
|
|
||||||
sudo yunohost service add php5-fpm
|
sudo yunohost service add php5-fpm
|
||||||
sudo yunohost service enable php5-fpm
|
sudo yunohost service enable php5-fpm
|
||||||
sudo yunohost service stop php5-fpm
|
|
||||||
sudo yunohost service start php5-fpm
|
|
||||||
|
|
||||||
sudo service nginx reload
|
sudo service nginx reload
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ domain=$(sudo yunohost app setting hotspot domain)
|
||||||
sudo service ynh-hotspot stop
|
sudo service ynh-hotspot stop
|
||||||
sudo yunohost service remove ynh-hotspot
|
sudo yunohost service remove ynh-hotspot
|
||||||
sudo rm -f /etc/init.d/ynh-hotspot
|
sudo rm -f /etc/init.d/ynh-hotspot
|
||||||
sudo rm -f /tmp/.ynh-hotspot-boot
|
sudo rm -f /tmp/.ynh-hotspot-*
|
||||||
|
|
||||||
# Remove confs
|
# Remove confs
|
||||||
sudo rm -f /etc/hostapd/hostapd.conf{.tpl,} /etc/radvd.conf{.tpl,} /etc/dhcp/dhcpd.conf{.tpl,}
|
sudo rm -f /etc/hostapd/hostapd.conf{.tpl,} /etc/radvd.conf{.tpl,} /etc/dhcp/dhcpd.conf{.tpl,}
|
||||||
|
@ -28,6 +28,6 @@ sudo userdel -f wifiadmin
|
||||||
# Remove packets
|
# Remove packets
|
||||||
# The yunohost policy is currently to not uninstall packets (dependency problems)
|
# The yunohost policy is currently to not uninstall packets (dependency problems)
|
||||||
## sudo apt-get --assume-yes --force-yes remove hostapd radvd isc-dhcp-server iptables
|
## sudo apt-get --assume-yes --force-yes remove hostapd radvd isc-dhcp-server iptables
|
||||||
## sudo apt-get --assume-yes --force-yes remove sipcalc iwconfig
|
## sudo apt-get --assume-yes --force-yes remove sipcalc iw
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -18,6 +18,18 @@ function start_service() {
|
||||||
return $retcode;
|
return $retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function service_status() {
|
||||||
|
exec('sudo service ynh-hotspot status', $output);
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function service_faststatus() {
|
||||||
|
exec('sudo service hostapd status', $output, $retcode);
|
||||||
|
|
||||||
|
return $retcode;
|
||||||
|
}
|
||||||
|
|
||||||
function ipv6_expanded($ip) {
|
function ipv6_expanded($ip) {
|
||||||
exec('ipv6_expanded '.escapeshellarg($ip), $output);
|
exec('ipv6_expanded '.escapeshellarg($ip), $output);
|
||||||
|
|
||||||
|
@ -33,7 +45,7 @@ function ipv6_compressed($ip) {
|
||||||
dispatch('/', function() {
|
dispatch('/', function() {
|
||||||
exec('sudo iwconfig', $devs);
|
exec('sudo iwconfig', $devs);
|
||||||
$wifi_device = moulinette_get('wifi_device');
|
$wifi_device = moulinette_get('wifi_device');
|
||||||
$devs_list = "";
|
$devs_list = '';
|
||||||
|
|
||||||
foreach($devs AS $dev) {
|
foreach($devs AS $dev) {
|
||||||
if(preg_match('/802.11/', $dev)) {
|
if(preg_match('/802.11/', $dev)) {
|
||||||
|
@ -60,6 +72,7 @@ dispatch('/', function() {
|
||||||
set('ip4_nat_prefix', moulinette_get('ip4_nat_prefix'));
|
set('ip4_nat_prefix', moulinette_get('ip4_nat_prefix'));
|
||||||
set('ip4_dns0', moulinette_get('ip4_dns0'));
|
set('ip4_dns0', moulinette_get('ip4_dns0'));
|
||||||
set('ip4_dns1', moulinette_get('ip4_dns1'));
|
set('ip4_dns1', moulinette_get('ip4_dns1'));
|
||||||
|
set('faststatus', service_faststatus() == 0);
|
||||||
|
|
||||||
return render('settings.html.php');
|
return render('settings.html.php');
|
||||||
});
|
});
|
||||||
|
@ -165,6 +178,28 @@ dispatch_put('/settings', function() {
|
||||||
redirect_to('/');
|
redirect_to('/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dispatch('/status', function() {
|
||||||
|
$status_lines = service_status();
|
||||||
|
$status_list = '';
|
||||||
|
|
||||||
|
foreach($status_lines AS $status_line) {
|
||||||
|
if(preg_match('/^\[INFO\]/', $status_line)) {
|
||||||
|
$status_list .= "<li class='status-info'>${status_line}</li>";
|
||||||
|
}
|
||||||
|
elseif(preg_match('/^\[OK\]/', $status_line)) {
|
||||||
|
$status_list .= "<li class='status-success'>${status_line}</li>";
|
||||||
|
}
|
||||||
|
elseif(preg_match('/^\[WARN\]/', $status_line)) {
|
||||||
|
$status_list .= "<li class='status-warning'>${status_line}</li>";
|
||||||
|
}
|
||||||
|
elseif(preg_match('/^\[ERR\]/', $status_line)) {
|
||||||
|
$status_list .= "<li class='status-danger'>${status_line}</li>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $status_list;
|
||||||
|
});
|
||||||
|
|
||||||
dispatch('/lang/:locale', function($locale = 'en') {
|
dispatch('/lang/:locale', function($locale = 'en') {
|
||||||
switch ($locale) {
|
switch ($locale) {
|
||||||
case 'fr':
|
case 'fr':
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
li.status-info {
|
||||||
|
color: #5BC0DE;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.status-warning {
|
||||||
|
color: #D9534F;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.status-danger {
|
||||||
|
color: #D9534F;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.status-success {
|
||||||
|
color: #5CB85C;
|
||||||
|
}
|
||||||
|
|
||||||
|
img#status-loading {
|
||||||
|
display: none;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
img#save-loading {
|
||||||
|
display: none;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#status {
|
||||||
|
display: none;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#status ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
BIN
sources/public/img/loading.gif
Normal file
BIN
sources/public/img/loading.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -28,4 +28,25 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.switch').bootstrapToggle();
|
$('.switch').bootstrapToggle();
|
||||||
|
|
||||||
|
$('#save').click(function() {
|
||||||
|
$(this).prop('disabled', true);
|
||||||
|
$('#save-loading').show();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#status .close').click(function() {
|
||||||
|
$(this).parent().hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#statusbtn').click(function() {
|
||||||
|
$('#status-loading').show();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '?/status',
|
||||||
|
}).done(function(data) {
|
||||||
|
$('#status-loading').hide();
|
||||||
|
$('#status-text').html('<ul>' + data + '</ul>');
|
||||||
|
$('#status').show('slow');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
<h2><?= T_("Wifi Hotspot Configuration") ?></h2>
|
<h2><?= T_("Wifi Hotspot Configuration") ?></h2>
|
||||||
|
<?php if($faststatus): ?>
|
||||||
|
<span class="label label-success" data-toggle="tooltip" data-title="<?= T_('This is a fast status. Click on More details to show the complete status.') ?>"><?= T_('Running') ?></span>
|
||||||
|
<?php else: ?>
|
||||||
|
<span class="label label-danger" data-toggle="tooltip" data-title="<?= T_('This is a fast status. Click on More details to show the complete status.') ?>"><?= T_('Not Running') ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<img src="public/img/loading.gif" id="status-loading" alt="Loading..." /><a href="#" id="statusbtn" data-toggle="tooltip" data-title="<?= T_('Loading complete status may take a few minutes. Be patient.') ?>"><?= T_('More details') ?></a>
|
||||||
|
|
||||||
|
<div id="status" class="alert alert-dismissible alert-info fade in" style="margin-top: 10px" role="alert">
|
||||||
|
<button type="button" class="close"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||||
|
<div id="status-text"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
@ -142,7 +154,7 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div style="text-align: center">
|
<div style="text-align: center">
|
||||||
<button type="submit" class="btn btn-default" data-toggle="tooltip" data-title="<?= T_('Reloading may take a few minutes. Be patient.') ?>"><?= T_('Save and reload') ?></button>
|
<button type="submit" class="btn btn-default" data-toggle="tooltip" id="save" data-title="<?= T_('Reloading may take a few minutes. Be patient.') ?>"><?= T_('Save and reload') ?></button> <img src="public/img/loading.gif" id="save-loading" alt="Loading..." />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Add table
Reference in a new issue