diff --git a/TODO b/TODO index 035d166..178506a 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ * Translate PHP interface in French * Support VPN without certificates (only login) -- need tests -* Add service status on the interface diff --git a/conf/init_ynh-vpnclient b/conf/init_ynh-vpnclient index 7c1a46b..6cb3b0b 100644 --- a/conf/init_ynh-vpnclient +++ b/conf/init_ynh-vpnclient @@ -55,7 +55,7 @@ is_openvpn_running() { is_running() { ((has_nativeip6 && is_serverip6route_set "${new_server_ip6}") || ! has_nativeip6)\ - && ((! has_hotspot_app && has_ip6delegatedprefix && is_ip6addr_set) || has_hotspot_app)\ + && ((! has_hotspot_app && has_ip6delegatedprefix && is_ip6addr_set) || has_hotspot_app || ! has_ip6delegatedprefix)\ && is_openvpn_running } @@ -157,19 +157,29 @@ moulinette_set() { fi } +# Restart php5-fpm at the first start (it needs to be restarted after the slapd start) +if [ ! -e /tmp/.ynh-vpnclient-boot ]; then + touch /tmp/.ynh-vpnclient-boot + service php5-fpm restart +fi + # Check configuration consistency if [[ ! "${1}" =~ stop ]]; then + exitcode=0 + if [ ! -e /etc/openvpn/keys/ca-server.crt ]; then - echo "DISABLED SERVICE: You need a CA server (you can add it through the web admin)" >&2 - exit 1 + echo "[WARN] You need a CA server (you can add it through the web admin)" + exitcode=1 fi empty=$(find /etc/openvpn/keys/ -empty -name credentials &> /dev/null | wc -l) if [ "${empty}" -gt 0 -a ! -e /etc/openvpn/keys/user.key ]; then - echo "DISABLED SERVICE: You need either a client certificate, either a username, or both (you can add one through the web admin)" >&2 - exit 1 + echo "[WARN] You need either a client certificate, either a username, or both (you can add one through the web admin)" + exitcode=1 fi + + [ "${exitcode}" -ne 0 ] && exit ${exitcode} fi # Variables @@ -255,12 +265,6 @@ case "${1}" in service ynh-hotspot start fi fi - - # Restart php5-fpm at the first start (it needs to be restarted after the slapd start) - if [ ! -e /tmp/.ynh-vpnclient-boot ]; then - touch /tmp/.ynh-vpnclient-boot - service php5-fpm restart - fi ;; stop) echo "[vpnclient] Stopping..." @@ -289,33 +293,43 @@ case "${1}" in exitcode=0 if has_ip6delegatedprefix; then + echo "[INFO] IPv6 delegated prefix found" + if ! has_hotspot_app; then + echo "[INFO] No Hotspot app detected" + if is_ip6addr_set; then - echo "IPv6 address is correctly set" + echo "[OK] IPv6 address correctly set" else - echo "IPv6 address is NOT set" + echo "[ERR] No IPv6 address set" exitcode=1 fi else - echo "Hotspot app detected" + echo "[INFO] Hotspot app detected" + echo "[INFO] No IPv6 address to set" fi + else + echo "[INFO] No IPv6 delegated prefix found" fi if has_nativeip6; then + echo "[INFO] Native IPv6 detected" + if is_serverip6route_set "${new_server_ip6}"; then - echo "IPv6 server route is correctly set" + echo "[OK] IPv6 server route correctly set" else - echo "IPv6 server route is NOT set" + echo "[ERR] No IPv6 server route set" exitcode=1 fi else - echo "No native IPv6 detected" + echo "[INFO] No native IPv6 detected" + echo "[INFO] No IPv6 server route to set" fi if is_openvpn_running; then - echo "Openvpn is running" + echo "[OK] Openvpn is running" else - echo "Openvpn is NOT running" + echo "[ERR] Openvpn is not running" exitcode=1 fi diff --git a/conf/phpfpm_vpnadmin.conf b/conf/phpfpm_vpnadmin.conf index 06d3e21..4ade216 100644 --- a/conf/phpfpm_vpnadmin.conf +++ b/conf/phpfpm_vpnadmin.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 = ; 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. diff --git a/screenshot.png b/screenshot.png index 495f4fd..03e7b32 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/scripts/install b/scripts/install index a922da0..3462235 100644 --- a/scripts/install +++ b/scripts/install @@ -144,15 +144,10 @@ sudo yunohost service disable openvpn 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 yunohost service add ynh-vpnclient sudo yunohost service enable ynh-vpnclient - -if [ ! -z "${crt_server_ca_path}" ]; then - sudo service ynh-vpnclient start -fi +sudo service ynh-vpnclient start sudo service nginx reload diff --git a/scripts/remove b/scripts/remove index b40d84f..97a82ae 100644 --- a/scripts/remove +++ b/scripts/remove @@ -7,7 +7,7 @@ domain=$(sudo yunohost app setting vpnclient domain) sudo service ynh-vpnclient stop sudo yunohost service remove ynh-vpnclient sudo rm -f /etc/init.d/ynh-vpnclient -sudo rm -f /tmp/.ynh-vpnclient-boot +sudo rm -f /tmp/.ynh-vpnclient-* # Remove confs sudo rm -f /etc/openvpn/client.conf{.tpl,} diff --git a/sources/controller.php b/sources/controller.php index f7dfe11..fc67518 100644 --- a/sources/controller.php +++ b/sources/controller.php @@ -18,6 +18,18 @@ function start_service() { return $retcode; } +function service_status() { + exec('sudo service ynh-vpnclient status', $output); + + return $output; +} + +function service_faststatus() { + exec('ip link show tun0', $output, $retcode); + + return $retcode; +} + function ipv6_expanded($ip) { exec('ipv6_expanded '.escapeshellarg($ip), $output); @@ -43,6 +55,7 @@ dispatch('/', function() { set('crt_client_exists', file_exists('/etc/openvpn/keys/user.crt')); set('crt_client_key_exists', file_exists('/etc/openvpn/keys/user.key')); set('crt_server_ca_exists', file_exists('/etc/openvpn/keys/ca-server.crt')); + set('faststatus', service_faststatus() == 0); return render('settings.html.php'); }); @@ -149,6 +162,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 .= "
  • ${status_line}
  • "; + } + elseif(preg_match('/^\[OK\]/', $status_line)) { + $status_list .= "
  • ${status_line}
  • "; + } + elseif(preg_match('/^\[WARN\]/', $status_line)) { + $status_list .= "
  • ${status_line}
  • "; + } + elseif(preg_match('/^\[ERR\]/', $status_line)) { + $status_list .= "
  • ${status_line}
  • "; + } + } + + echo $status_list; +}); + dispatch('/lang/:locale', function($locale = 'en') { switch ($locale) { case 'fr': diff --git a/sources/public/css/style.css b/sources/public/css/style.css index 6a439cc..77dcc84 100644 --- a/sources/public/css/style.css +++ b/sources/public/css/style.css @@ -1,3 +1,40 @@ +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; + margin-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; +} + a.btn-danger span { color: #eee; } diff --git a/sources/public/img/loading.gif b/sources/public/img/loading.gif new file mode 100644 index 0000000..5f11860 Binary files /dev/null and b/sources/public/img/loading.gif differ diff --git a/sources/public/js/custom.js b/sources/public/js/custom.js index ef2eb52..f9579cf 100644 --- a/sources/public/js/custom.js +++ b/sources/public/js/custom.js @@ -39,4 +39,25 @@ $(document).ready(function() { $(choosertxtid).val($(this).val()); }); + + $('#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(''); + $('#status').show('slow'); + }); + }); }); diff --git a/sources/views/settings.html.php b/sources/views/settings.html.php index bf1e7ec..655fd08 100644 --- a/sources/views/settings.html.php +++ b/sources/views/settings.html.php @@ -1,4 +1,16 @@

    + + + + + + +   Loading... + +
    @@ -142,7 +154,7 @@
    - + Loading...