Merge pull request #125 from bergware/6.4-wip

Improved connection checking for plugin updates
This commit is contained in:
tom mortensen
2017-06-19 14:55:59 -07:00
committed by GitHub
8 changed files with 128 additions and 40 deletions
@@ -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);
@@ -1,7 +1,7 @@
#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2012-2016, Bergware International.
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, 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,
@@ -12,7 +12,7 @@
*/
?>
<?
$docroot = $docroot ?: @$_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Wrappers.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
@@ -22,19 +22,18 @@ $unraid = parse_plugin_cfg('dynamix', true);
$notify = "$docroot/webGui/scripts/notify";
$server = strtoupper($var['NAME']);
$output = $unraid['notify']['plugin'];
$builtin = ['unRAIDServer','dynamix'];
plugin("checkall");
plugin('checkall');
foreach (glob("/tmp/plugins/*.plg", GLOB_NOSORT) as $file) {
$plg = basename($file);
$name = basename($plg, '.plg');
if (in_array($name,$builtin)) continue;
$old = plugin('version', "/var/log/plugins/$plg");
$new = plugin('version', $file);
// silently suppress bad download of PLG file
if (strcmp($new, $old) > 0) {
$unRAID = plugin('unRAID', $file);
if ($unRAID === false || version_compare($current['version'], $unRAID, '>=')) {
$name = basename($file, '.plg');
exec("$notify -e ".escapeshellarg("Plugin - $name [$new]")." -s ".escapeshellarg("Notice [$server] - Version update $new")." -d ".escapeshellarg("A new version of $name is available")." -i ".escapeshellarg("normal $output")." -x");
}
exec("$notify -e ".escapeshellarg("Plugin - $name [$new]")." -s ".escapeshellarg("Notice [$server] - Version update $new")." -d ".escapeshellarg("A new version of $name is available")." -i ".escapeshellarg("normal $output")." -x");
}
}
exit(0);
@@ -0,0 +1,42 @@
#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, 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,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Wrappers.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
$var = parse_ini_file('/var/local/emhttp/var.ini');
$current = parse_ini_file('/etc/unraid-version');
$unraid = parse_plugin_cfg('dynamix', true);
$notify = "$docroot/webGui/scripts/notify";
$server = strtoupper($var['NAME']);
$output = $unraid['notify']['plugin'];
$builtin = ['unRAIDServer','dynamix'];
foreach ($builtin as $name) {
$plg = "$name.plg";
plugin('check',$plg);
$file = "/tmp/plugins/$plg";
$old = plugin('version', "/var/log/plugins/$plg");
$new = plugin('version', $file);
// silently suppress bad download of PLG file
if (strcmp($new, $old) > 0) {
$unRAID = plugin('unRAID', $file);
if ($unRAID === false || version_compare($current['version'], $unRAID, '>=')) {
exec("$notify -e ".escapeshellarg("System - $name [$new]")." -s ".escapeshellarg("Notice [$server] - Version update $new")." -d ".escapeshellarg("A new version of $name is available")." -i ".escapeshellarg("normal $output")." -x");
}
}
}
exit(0);
?>
+5 -5
View File
@@ -1,17 +1,17 @@
Menu="About"
Title="Credits"
---
**unRAID webGUI** Copyright &copy; 2005-2016, [Lime Technology, Inc.](http://lime-technology.com).
**unRAID webGUI** Copyright &copy; 2005-2017, [Lime Technology, Inc.](http://lime-technology.com).
**Simple Features** Copyright &copy; 2012, Andrew Hamer-Adams.
**Dynamix** Copyright &copy; 2012-2016, Bergware International.
**Dynamix** Copyright &copy; 2012-2017, Bergware International.
**Extended Docker Configuration Page** Copyright &copy; 2014-2016, Guilherme Jardim.
**Extended Docker Configuration Page** Copyright &copy; 2014-2017, Guilherme Jardim.
**APC UPS Configuration Page** Copyright &copy; 2015, Dan Landon.
**VM Manager** Copyright &copy; 2015-2016, Eric Schultz, Derek Macias.
**VM Manager** Copyright &copy; 2015-2017, Eric Schultz, Derek Macias.
The Software comprising the unRAID webGui, which is all files within this repository except for
files listed below, is licensed under GPL version 2.
@@ -19,7 +19,7 @@ files listed below, is licensed under GPL version 2.
* The Lime Technology logo file(s) `webGui/images/limetech-*.*` are property of Lime Technology, Inc.
and may not be used in any other project without written permission from Lime Technology, Inc.
***unRAID***&reg; is a registered trademark of [Lime Technology, Inc.](http://lime-technology.com).
**unRAID**&reg; is a registered trademark of [Lime Technology, Inc.](http://lime-technology.com).
This file shall be included in all copies or substantial portions of the Software.
+44 -14
View File
@@ -4,8 +4,8 @@ Title="Notification Settings"
Icon="notifications.png"
---
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2012-2016, Bergware International.
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
* Copyright 2012, Andrew Hamer-Adams, http://www.pixeleyes.co.nz.
*
* This program is free software; you can redistribute it and/or
@@ -26,6 +26,7 @@ function prepareNotify(form) {
form.normal.value = form.normal1.checked*1 + form.normal2.checked*2 + form.normal3.checked*4;
form.warning.value = form.warning1.checked*1 + form.warning2.checked*2 + form.warning3.checked*4;
form.alert.value = form.alert1.checked*1 + form.alert2.checked*2 + form.alert3.checked*4;
form.unraid.value = form.unraid1.checked*1 + form.unraid2.checked*2 + form.unraid3.checked*4;
form.plugin.value = form.plugin1.checked*1 + form.plugin2.checked*2 + form.plugin3.checked*4;
form.docker_notify.value = form.docker_notify1.checked*1 + form.docker_notify2.checked*2 + form.docker_notify3.checked*4;
form.report.value = form.report1.checked*1 + form.report2.checked*2 + form.report3.checked*4;
@@ -38,6 +39,9 @@ function prepareNotify(form) {
form.alert1.disabled = true;
form.alert2.disabled = true;
form.alert3.disabled = true;
form.unraid1.disabled = true;
form.unraid2.disabled = true;
form.unraid3.disabled = true;
form.plugin1.disabled = true;
form.plugin2.disabled = true;
form.plugin3.disabled = true;
@@ -48,16 +52,21 @@ function prepareNotify(form) {
form.report2.disabled = true;
form.report3.disabled = true;
}
function prepareCheckbox(index) {
function prepareSystem(index) {
if (index==0) $('.checkbox').attr('disabled','disabled'); else $('.checkbox').removeAttr('disabled');
}
function prepareTitle() {
var title = 'Available notifications:';
$('#pluginTitle,#dockerTitle,#reportTitle').html('&nbsp;');
$('#unraidTitle,#pluginTitle,#dockerTitle,#reportTitle').html('&nbsp;');
if ($('.unraid').is(':visible')) { $('#unraidTitle').html(title); return; }
if ($('.plugin').is(':visible')) { $('#pluginTitle').html(title); return; }
if ($('.docker').is(':visible')) { $('#dockerTitle').html(title); return; }
if ($('.report').is(':visible')) { $('#reportTitle').html(title); return; }
}
function prepareUnraid(value) {
if (value=='') $('.unraid').hide(); else $('.unraid').show();
prepareTitle();
}
function preparePlugin(value) {
if (value=='') $('.plugin').hide(); else $('.plugin').show();
prepareTitle();
@@ -71,6 +80,7 @@ function prepareReport(value) {
prepareTitle();
}
$(function(){
prepareUnraid(document.notify_settings.unraidos.value);
preparePlugin(document.notify_settings.version.value);
prepareDocker(document.notify_settings.docker_update.value);
prepareReport(document.notify_settings.status.value);
@@ -85,6 +95,7 @@ $(function(){
<input type="hidden" name="normal">
<input type="hidden" name="warning">
<input type="hidden" name="alert">
<input type="hidden" name="unraid">
<input type="hidden" name="plugin">
<input type="hidden" name="docker_notify">
<input type="hidden" name="report">
@@ -138,7 +149,7 @@ Store notifications to flash:
> Notifications may be stored permanently on the flash drive under folder '/boot/config/plugins/dynamix' instead.
System notifications:
: <select name="system" size="1" onchange="prepareCheckbox(this.selectedIndex)">
: <select name="system" size="1" onchange="prepareSystem(this.selectedIndex)">
<?=mk_option($notify['system'], "", "Disabled")?>
<?=mk_option($notify['system'], "*/1 * * * *", "Enabled")?>
</select>
@@ -146,7 +157,20 @@ System notifications:
> By default the notifications system is disabled. Enable it here to start receiving notifications.
> The following sections give more options about which and what type of notifications will be sent.
Plugins version notification:
unRAID OS update notification:
: <select name="unraidos" size="1" onchange="prepareUnraid(this.value)">
<?=mk_option($notify['unraidos'], "", "Never check")?>
<?=mk_option($notify['unraidos'], "11 */6 * * *", "Check four times a day")?>
<?=mk_option($notify['unraidos'], "11 0,12 * * *", "Check twice a day")?>
<?=mk_option($notify['unraidos'], "11 0 * * *", "Check once a day")?>
<?=mk_option($notify['unraidos'], "11 0 * * 1", "Check once a week")?>
<?=mk_option($notify['unraidos'], "11 0 1 * *", "Check once a month")?>
</select>
> Start a periodic verification and notify the user when a new version of the unRAID OS system is detected.
> Use the checkboxes below to select how notifications need to be given; by browser, by email and/or by custom agent.
Plugins update notification:
: <select name="version" size="1" onchange="preparePlugin(this.value)">
<?=mk_option($notify['version'], "", "Never check")?>
<?=mk_option($notify['version'], "10 */6 * * *", "Check four times a day")?>
@@ -187,41 +211,47 @@ Array status notification:
> Start a periodic array health check (preventive maintenance) and notify the user the result of this check.
<span id="unraidTitle" class="unraid" style="display:none">&nbsp;</span>
: <span class="unraid" style="display:none"><span style="display:inline-block;width:130px;font-style:italic">unRAID OS update</span>
<input type="checkbox" name="unraid1"<?=($notify['unraid'] & 1)==1 ? ' checked' : ''?>>Browser &nbsp;
<input type="checkbox" name="unraid2"<?=($notify['unraid'] & 2)==2 ? ' checked' : ''?>>Email &nbsp;
<input type="checkbox" name="unraid3"<?=($notify['unraid'] & 4)==4 ? ' checked' : ''?>>Agents &nbsp;</span>
<span id="pluginTitle" class="plugin" style="display:none">&nbsp;</span>
: <span class="plugin" style="display:none"><span style="display:inline-block;width:90px;font-style:italic">Plugins version</span>
: <span class="plugin" style="display:none"><span style="display:inline-block;width:130px;font-style:italic">Plugins update</span>
<input type="checkbox" name="plugin1"<?=($notify['plugin'] & 1)==1 ? ' checked' : ''?>>Browser &nbsp;
<input type="checkbox" name="plugin2"<?=($notify['plugin'] & 2)==2 ? ' checked' : ''?>>Email &nbsp;
<input type="checkbox" name="plugin3"<?=($notify['plugin'] & 4)==4 ? ' checked' : ''?>>Agents &nbsp;</span>
<span id="dockerTitle" class="docker" style="display:none">&nbsp;</span>
: <span class="docker" style="display:none"><span style="display:inline-block;width:90px;font-style:italic">Docker update</span>
: <span class="docker" style="display:none"><span style="display:inline-block;width:130px;font-style:italic">Docker update</span>
<input type="checkbox" name="docker_notify1"<?=($notify['docker_notify'] & 1)==1 ? ' checked' : ''?>>Browser &nbsp;
<input type="checkbox" name="docker_notify2"<?=($notify['docker_notify'] & 2)==2 ? ' checked' : ''?>>Email &nbsp;
<input type="checkbox" name="docker_notify3"<?=($notify['docker_notify'] & 4)==4 ? ' checked' : ''?>>Agents &nbsp;</span>
<span id="reportTitle" class="report" style="display:none">&nbsp;</span>
: <span class="report" style="display:none"><span style="display:inline-block;width:90px;font-style:italic">Array status</span>
: <span class="report" style="display:none"><span style="display:inline-block;width:130px;font-style:italic">Array status</span>
<input type="checkbox" name="report1"<?=($notify['report'] & 1)==1 ? ' checked' : ''?>>Browser &nbsp;
<input type="checkbox" name="report2"<?=($notify['report'] & 2)==2 ? ' checked' : ''?>>Email &nbsp;
<input type="checkbox" name="report3"<?=($notify['report'] & 4)==4 ? ' checked' : ''?>>Agents &nbsp;</span>
> Use the checkboxes above to select what and how notifications need to be given; by browser, by email and/or by a service.
> <br><b>Tip:</b> you can use custom notification agents; just add them to "/boot/config/plugins/dynamix/notification/agents" directory and check 'Agents'.
> Use the checkboxes above to select what and how notifications need to be given; by browser, by email and/or by a service.<br>
> <b>Tip:</b> you can use custom notification agents; just add them to "/boot/config/plugins/dynamix/notification/agents" directory and check 'Agents'.
Notification entity:
: <span style="display:inline-block;width:90px;font-style:italic">Notices</span>
: <span style="display:inline-block;width:130px;font-style:italic">Notices</span>
<input type="checkbox" class="checkbox" name="normal1"<?=($notify['normal'] & 1)==1 ? " checked $disabled" : $disabled?>>Browser &nbsp;
<input type="checkbox" class="checkbox" name="normal2"<?=($notify['normal'] & 2)==2 ? " checked $disabled" : $disabled?>>Email &nbsp;
<input type="checkbox" class="checkbox" name="normal3"<?=($notify['normal'] & 4)==4 ? " checked $disabled" : $disabled?>>Agents &nbsp;
&nbsp;
: <span style="display:inline-block;width:90px;font-style:italic">Warnings</span>
: <span style="display:inline-block;width:130px;font-style:italic">Warnings</span>
<input type="checkbox" class="checkbox" name="warning1"<?=($notify['warning'] & 1)==1 ? " checked $disabled" : $disabled?>>Browser &nbsp;
<input type="checkbox" class="checkbox" name="warning2"<?=($notify['warning'] & 2)==2 ? " checked $disabled" : $disabled?>>Email &nbsp;
<input type="checkbox" class="checkbox" name="warning3"<?=($notify['warning'] & 4)==4 ? " checked $disabled" : $disabled?>>Agents &nbsp;
&nbsp;
: <span style="display:inline-block;width:90px;font-style:italic">Alerts</span>
: <span style="display:inline-block;width:130px;font-style:italic">Alerts</span>
<input type="checkbox" class="checkbox" name="alert1"<?=($notify['alert'] & 1)==1 ? " checked $disabled" : $disabled?>>Browser &nbsp;
<input type="checkbox" class="checkbox" name="alert2"<?=($notify['alert'] & 2)==2 ? " checked $disabled" : $disabled?>>Email &nbsp;
<input type="checkbox" class="checkbox" name="alert3"<?=($notify['alert'] & 4)==4 ? " checked $disabled" : $disabled?>>Agents &nbsp;
+4
View File
@@ -40,9 +40,13 @@ entity="1"
normal="1"
warning="1"
alert="1"
unraid="1"
plugin="1"
docker_notify="1"
report="1"
unraidos=""
version=""
docker_update=""
status=""
[ssmtp]
root=""
+4 -2
View File
@@ -1,7 +1,7 @@
#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2012-2016, Bergware International.
/* Copyright 2005-2017, Lime Technology
* Copyright 2012-2017, Bergware International.
* Copyright 2012, Andrew Hamer-Adams, http://www.pixeleyes.co.nz.
*
* This program is free software; you can redistribute it and/or
@@ -139,6 +139,8 @@ case 'cron-init':
@mkdir($archive,0755,true);
$text = empty($notify['status']) ? "" : "# Generated array status check schedule:\n{$notify['status']} $docroot/plugins/dynamix/scripts/statuscheck &> /dev/null\n\n";
parse_cron_cfg("dynamix", "status-check", $text);
$text = empty($notify['unraidos']) ? "" : "# Generated unRAID OS update check schedule:\n{$notify['unraidos']} $docroot/plugins/dynamix.plugin.manager/scripts/unraidcheck &> /dev/null\n\n";
parse_cron_cfg("dynamix", "unraid-check", $text);
$text = empty($notify['version']) ? "" : "# Generated plugins version check schedule:\n{$notify['version']} $docroot/plugins/dynamix.plugin.manager/scripts/plugincheck &> /dev/null\n\n";
parse_cron_cfg("dynamix", "plugin-check", $text);
$text = empty($notify['system']) ? "" : "# Generated system monitoring schedule:\n{$notify['system']} $docroot/plugins/dynamix/scripts/monitor &> /dev/null\n\n";