Parcourir la source

Add service status on the web admin

Julien VAUBOURG il y a 10 ans
Parent
commit
f61bcb410f

+ 53 - 23
conf/init_ynh-hotspot

@@ -181,6 +181,19 @@ moulinette_get() {
   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() {
   var=${1}
   value=${2}
@@ -193,6 +206,12 @@ moulinette_set() {
   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
 
 echo -n "Retrieving Yunohost settings... "
@@ -221,6 +240,21 @@ fi
 
 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
 
 case "$1" in
@@ -298,12 +332,6 @@ case "$1" in
       # Update dynamic settings
       moulinette_set internet_device "${new_internet_device}"
     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)
     echo "[hotspot] Stopping..."
@@ -357,62 +385,64 @@ case "$1" in
     exitcode=0
   
     if has_ip6delegatedprefix; then
+      echo "[INFO] IPv6 delegated prefix found"
+
       if is_ndproxy_set; then
-        echo "NDP proxy is correctly set"
+        echo "[OK] NDP proxy set"
       else
-        echo "NDP proxy is NOT set"
+        echo "[ERR] No NDP proxy set"
         exitcode=1
       fi
   
       if is_ip6addr_set; then
-        echo "IPv6 address is correctly set"
+        echo "[OK] IPv6 address set"
       else
-        echo "IPv6 address is NOT set"
+        echo "[ERR] No IPv6 address set"
         exitcode=1
       fi
   
       if is_radvd_running; then
-        echo "Radvd is running"
+        echo "[OK] Radvd is running"
       else
-        echo "Radvd is NOT running"
+        echo "[ERR] Radvd is not running"
         exitcode=1
       fi
     else
-      echo "No IPv6 delegated prefix"
+      echo "[INFO] No IPv6 delegated prefix found"
     fi
 
     if is_nat_set "${new_internet_device}"; then
-      echo "NAT is correctly set"
+      echo "[OK] IPv4 NAT set"
     else
-      echo "NAT is NOT set"
+      echo "[ERR] No IPv4 NAT set"
       exitcode=1
     fi
 
     if is_ip4nataddr_set; then
-      echo "IPv4 NAT address is correctly set"
+      echo "[OK] IPv4 NAT address set"
     else
-      echo "IPv4 NAT address is NOT set"
+      echo "[ERR] No IPv4 NAT address set"
       exitcode=1
     fi
 
     if is_forwarding_set; then
-      echo "Forwarding is correctly set"
+      echo "[OK] IPv6/IPv4 forwarding set"
     else
-      echo "Forwarding is NOT set"
+      echo "[ERR] No IPv6/IPv4 forwarding set"
       exitcode=1
     fi
 
     if is_hostapd_running; then
-      echo "Hostapd is running"
+      echo "[OK] Hostapd is running"
     else
-      echo "Hostapd is NOT running"
+      echo "[ERR] Hostapd is not running"
       exitcode=1
     fi
 
     if is_dhcpd_running; then
-      echo "Dhcpd is running"
+      echo "[OK] Dhcpd is running"
     else
-      echo "Dhcpd is NOT running"
+      echo "[ERR] Dhcpd is not running"
       exitcode=1
     fi
 

+ 2 - 2
conf/phpfpm_wifiadmin.conf

@@ -165,7 +165,7 @@ request_terminate_timeout = 600s
 ; dumped to the 'slowlog' file. A value of '0s' means 'off'.
 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
 ; Default Value: 0
-request_slowlog_timeout = 5s
+request_slowlog_timeout = 0
 
 ; The log file for slow requests
 ; Default Value: not set
@@ -202,7 +202,7 @@ chdir = <TPL:NGINX_REALPATH>
 ; Note: on highloaded environement, this can cause some delay in the page
 ; process time (several ms).
 ; Default Value: no
-catch_workers_output = yes
+catch_workers_output = no
 
 ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
 ; the current environment.

BIN
docs/box-project.png


BIN
screenshot.png


+ 1 - 3
scripts/install

@@ -38,7 +38,7 @@ fi
 sudo apt-get --assume-yes --force-yes install hostapd radvd isc-dhcp-server iptables php5-fpm
 
 # 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
 if [ -z "${ip6_net}" ]; then
@@ -147,8 +147,6 @@ sudo yunohost service disable hostapd
 
 sudo yunohost service add php5-fpm
 sudo yunohost service enable php5-fpm
-sudo yunohost service stop php5-fpm
-sudo yunohost service start php5-fpm
 
 sudo service nginx reload
 

+ 2 - 2
scripts/remove

@@ -7,7 +7,7 @@ domain=$(sudo yunohost app setting hotspot domain)
 sudo service ynh-hotspot stop
 sudo yunohost service remove 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
 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
 # 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 sipcalc iwconfig
+## sudo apt-get --assume-yes --force-yes remove sipcalc iw
 
 exit 0

+ 36 - 1
sources/controller.php

@@ -18,6 +18,18 @@ function start_service() {
   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) {
   exec('ipv6_expanded '.escapeshellarg($ip), $output);
 
@@ -33,7 +45,7 @@ function ipv6_compressed($ip) {
 dispatch('/', function() {
   exec('sudo iwconfig', $devs);
   $wifi_device = moulinette_get('wifi_device');
-  $devs_list = "";
+  $devs_list = '';
 
   foreach($devs AS $dev) {
     if(preg_match('/802.11/', $dev)) {
@@ -60,6 +72,7 @@ dispatch('/', function() {
   set('ip4_nat_prefix', moulinette_get('ip4_nat_prefix'));
   set('ip4_dns0', moulinette_get('ip4_dns0'));
   set('ip4_dns1', moulinette_get('ip4_dns1'));
+  set('faststatus', service_faststatus() == 0);
 
   return render('settings.html.php');
 });
@@ -165,6 +178,28 @@ dispatch_put('/settings', function() {
   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') {
   switch ($locale) {
     case 'fr':

+ 36 - 0
sources/public/css/style.css

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


+ 21 - 0
sources/public/js/custom.js

@@ -28,4 +28,25 @@ $(document).ready(function() {
   });
 
   $('.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');
+    });
+  });
 });

+ 13 - 1
sources/views/settings.html.php

@@ -1,4 +1,16 @@
 <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; ?>
+
+ &nbsp; <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">&times;</span><span class="sr-only">Close</span></button>
+  <div id="status-text"></div>
+</div>
 
 <hr />
 
@@ -142,7 +154,7 @@
 
       <div class="form-group">
         <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>
     </form>