mirror of
https://github.com/unraid/webgui.git
synced 2026-03-07 01:30:59 -06:00
Improved connection checking for plugin updates
This commit is contained in:
@@ -17,15 +17,25 @@ $docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
function plugin($method, $arg = '') {
|
||||
global $docroot;
|
||||
exec("$docroot/plugins/dynamix.plugin.manager/scripts/plugin ".escapeshellarg($method)." ".escapeshellarg($arg), $output, $retval);
|
||||
if ($retval != 0) return false;
|
||||
return implode("\n", $output);
|
||||
return $retval==0 ? implode("\n", $output) : false;
|
||||
}
|
||||
|
||||
function check_plugin($arg, $google='8.8.8.8') {
|
||||
$inet = 3;
|
||||
// ping google DNS server first to ensure internet is present
|
||||
while (1) {
|
||||
if (exec("ping -qnc1 $google|awk '/received/{print $4}'")==1) break;
|
||||
$inet--;
|
||||
if ($inet) sleep(1); else break;
|
||||
}
|
||||
return $inet ? plugin('check',$arg) : false;
|
||||
}
|
||||
|
||||
function make_link($method, $arg, $extra='') {
|
||||
$id = basename($arg, ".plg").$method;
|
||||
$id = basename($arg, '.plg').$method;
|
||||
$check = $method=='remove' ? "<input type='checkbox' onClick='document.getElementById(\"$id\").disabled=!this.checked'>" : "";
|
||||
$disabled = $check ? " disabled" : "";
|
||||
$cmd = $method == "delete" ? "/plugins/dynamix.plugin.manager/scripts/plugin_rm&arg1=$arg" : "/plugins/dynamix.plugin.manager/scripts/plugin&arg1=$method&arg2=$arg".($extra?"&arg3=$extra":"");
|
||||
$disabled = $check ? ' disabled' : '';
|
||||
$cmd = $method == 'delete' ? "/plugins/dynamix.plugin.manager/scripts/plugin_rm&arg1=$arg" : "/plugins/dynamix.plugin.manager/scripts/plugin&arg1=$method&arg2=$arg".($extra?"&arg3=$extra":"");
|
||||
return "{$check}<input type='button' id='$id' value='".ucfirst($method)."' onclick='hideUpgrade();openBox(\"{$cmd}\",\"".ucwords($method)." Plugin\",600,900,true)'{$disabled}>";
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
|
||||
$custom = in_array($name,$builtin);
|
||||
//switch between system and custom plugins
|
||||
if (($system && !$custom) || (!$system && $custom)) continue;
|
||||
//forced plugin check?
|
||||
if ($stale || $system) plugin('check',$name.'.plg');
|
||||
//forced plugin check
|
||||
check_plugin("$name.plg");
|
||||
//OS update?
|
||||
$os = $system && $name==$builtin[0];
|
||||
$toggle = false;
|
||||
@@ -49,9 +49,10 @@ foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
|
||||
exec("sed -ri 's|^(<!ENTITY category).*|\\1 \"{$cat}\">|' $tmp_file");
|
||||
exec("sed -ri 's|^(<!ENTITY pluginURL).*|\\1 \"{$https[$release]}\">|' $tmp_file");
|
||||
symlink($tmp_file,"/var/log/plugins/$tmp_plg");
|
||||
plugin('check',$tmp_plg);
|
||||
copy("/tmp/plugins/$tmp_plg",$tmp_file);
|
||||
$plugin_file = $tmp_file;
|
||||
if (check_plugin($tmp_plg)) {
|
||||
copy("/tmp/plugins/$tmp_plg",$tmp_file);
|
||||
$plugin_file = $tmp_file;
|
||||
}
|
||||
}
|
||||
//link/icon
|
||||
$icon = icon($name);
|
||||
|
||||
Reference in New Issue
Block a user