Verify internet access using NCSI method

NCSI = network connection status indicator
This method tries to access a specific Microsoft site to test internet access. The same method is used in Windows.
This commit is contained in:
bergware
2018-08-04 13:21:42 +02:00
parent 27beaf361e
commit 894a2b2375
2 changed files with 9 additions and 7 deletions
@@ -1,6 +1,6 @@
<?PHP
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
/* Copyright 2005-2018, Lime Technology
* Copyright 2012-2018, 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,
@@ -20,9 +20,10 @@ function plugin($method, $arg = '') {
return $retval==0 ? implode("\n", $output) : false;
}
function check_plugin($arg, $dns='8.8.8.8') {
// ping DNS server first to ensure internet is present
return exec("ping -qnl2 -c2 -W3 $dns 2>/dev/null|awk '/received/{print $4}'") ? plugin('check',$arg) : false;
function check_plugin($arg, &$ncsi) {
// Get network connection status indicator (NCSI)
if ($ncsi===null) passthru("wget --quiet --spider --timeout=10 --tries=1 http://www.msftncsi.com/ncsi.txt",$ncsi);
return $ncsi===0 ? plugin('check',$arg) : false;
}
function make_link($method, $arg, $extra='') {
@@ -23,6 +23,7 @@ $empty = true;
$updates = 0;
$builtin = ['unRAIDServer'];
$plugins = "/var/log/plugins/*.plg";
$ncsi = null; // network connection status indicator
if ($audit) {
list($plg,$action) = explode(':',$audit);
@@ -44,7 +45,7 @@ foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
//switch between system and custom plugins
if (($system && !$custom) || (!$system && $custom)) continue;
//forced plugin check?
$checked = (!$audit && !$check) ? check_plugin(basename($plugin_file)) : true;
$checked = (!$audit && !$check) ? check_plugin(basename($plugin_file),$ncsi) : true;
//OS update?
$os = $system && $name==$builtin[0];
$toggle = false;
@@ -56,7 +57,7 @@ foreach (glob($plugins,GLOB_NOSORT) as $plugin_link) {
copy($plugin_file,$tmp_file);
exec("sed -ri 's|^(<!ENTITY category).*|\\1 \"{$branch}\">|' $tmp_file");
symlink($tmp_file,"/var/log/plugins/$tmp_plg");
if (check_plugin($tmp_plg)) {
if (check_plugin($tmp_plg,$ncsi)) {
copy("/tmp/plugins/$tmp_plg",$tmp_file);
$plugin_file = $tmp_file;
}