mirror of
https://github.com/unraid/webgui.git
synced 2026-01-01 23:20:35 -06:00
73 lines
2.7 KiB
PHP
Executable File
73 lines
2.7 KiB
PHP
Executable File
#!/usr/bin/php -q
|
|
<?PHP
|
|
/* Copyright 2005-2023, Lime Technology
|
|
* Copyright 2012-2023, 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 ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
|
|
require_once "$docroot/webGui/include/Wrappers.php";
|
|
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
|
|
|
|
// Multi-language support
|
|
if (!function_exists('_')) {
|
|
function _($text) {return $text;}
|
|
}
|
|
|
|
extract(parse_plugin_cfg('dynamix', true));
|
|
|
|
$var = (array)@parse_ini_file('/var/local/emhttp/var.ini');
|
|
$script = "$docroot/webGui/scripts/notify";
|
|
$server = strtoupper(_var($var,'NAME','server'));
|
|
$output = _var($notify,'plugin');
|
|
$plg = '/var/log/plugins/unRAIDServer.plg';
|
|
|
|
$params = [];
|
|
$params['branch'] = plugin('category', $plg, 'stable');
|
|
$params['current_version'] = plugin('version', $plg) ?: _var($var,'version');
|
|
if (_var($var,'regExp')) $params['update_exp'] = date('m-d-Y', _var($var,'regExp')*1);
|
|
$urlbase = 'https://releases.unraid.net/os';
|
|
$url = $urlbase.'?'.http_build_query($params);
|
|
|
|
$response = "";
|
|
// use error handler to convert warnings from file_get_contents to errors so they can be captured
|
|
function warning_as_error($severity, $message, $filename, $lineno) {
|
|
throw new ErrorException($message, 0, $severity, $filename, $lineno);
|
|
}
|
|
set_error_handler("warning_as_error");
|
|
try {
|
|
$response = file_get_contents($url);
|
|
} catch (Exception $e) {
|
|
$response = json_encode(array('error' => $e->getMessage()), JSON_PRETTY_PRINT);
|
|
}
|
|
restore_error_handler();
|
|
|
|
$json = json_decode($response, true);
|
|
if (!$json) {
|
|
$response = json_encode(array('error' => 'Invalid response from '.$urlbase), JSON_PRETTY_PRINT);
|
|
$json = json_decode($response, true);
|
|
}
|
|
|
|
// add params that were sent to $urlbase
|
|
$json['params'] = $params;
|
|
|
|
// store locally for UPC to access
|
|
$file = '/tmp/unraidcheck/result.json';
|
|
if (!is_dir(dirname($file))) mkdir(dirname($file));
|
|
file_put_contents($file, json_encode($json, JSON_PRETTY_PRINT));
|
|
|
|
// send notification if a newer version is available
|
|
if ($json && array_key_exists('isNewer',$json) && $json['isNewer']) {
|
|
$newver = (array_key_exists('version',$json) && $json['version']) ? $json['version'] : 'unknown';
|
|
exec("$script -e ".escapeshellarg("System - Unraid [$newver]")." -s ".escapeshellarg("Notice [$server] - Version update $newver")." -d ".escapeshellarg("A new version of Unraid is available")." -i ".escapeshellarg("normal $output")." -l '/Tools/Update' -x");
|
|
}
|
|
exit(0);
|
|
?>
|