Emhanced plugin manager with seprate plugin and OS sections

This commit is contained in:
bergware
2017-06-18 10:28:13 +02:00
parent 8fff4fc72b
commit 1c097759d2
7 changed files with 192 additions and 86 deletions

View File

@@ -4,8 +4,8 @@ Title="Installed Plugins"
Tabs="true"
---
<?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,
@@ -18,15 +18,14 @@ Tabs="true"
<?
// Remove stale /tmp/plugin/*.plg entries
$tmp_stale = ($path != $prev);
if ($tmp_stale) foreach (glob("/tmp/plugins/*.{plg,txt}", GLOB_NOSORT+GLOB_BRACE) as $entry) if (!file_exists("/var/log/plugins/".basename($entry))) @unlink($entry);
$stale = ($path != $prev);
if ($stale) foreach (glob("/tmp/plugins/*.{plg,txt}", GLOB_NOSORT+GLOB_BRACE) as $entry) if (!file_exists("/var/log/plugins/".basename($entry))) @unlink($entry);
?>
<link type="text/css" rel="stylesheet" href="/webGui/styles/jquery.filetree.css">
<style>
#plugin_tree{width:33%;height:200px;overflow:scroll;}
#plugin_tree{width:33%;height:200px;overflow-y:scroll;}
</style>
<script src="/webGui/javascript/jquery.filetree.js"></script>
<script>
<?if ($display['resize']):?>
function resize(bind) {
@@ -42,7 +41,7 @@ function resize(bind) {
}
<?endif;?>
$(function() {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{stale:'<?=$tmp_stale?>'},function(data) {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{stale:'<?=$stale?>'},function(data) {
if (data) $('#plugin_list').html(data);
<?if ($display['resize']):?>
resize();
@@ -52,15 +51,9 @@ $(function() {
$('.desc_readmore').readmore({maxHeight:58});
});
$('#plugin_tree').fileTree({root:'/boot/',filter:'plg'}, function(file) {$('#plugin_file').val(file);});
$('.tabs').append("<span class='status vhshift'><input type='button' value='Check for Updates' onclick='openBox(\"/plugins/dynamix.plugin.manager/scripts/plugin&arg1=checkall\",\"Plugin Update Check\",490,430,true)'></span>");
});
</script>
<blockquote class="inline_help ontop">
Click <span class="strong big">check for updates</span> to check all plugins. This page might take some time to load depending on your internet connection and how many plugins need to be checked.
</blockquote>
<table class='tablesorter plugins shift' id='plugin_table'>
<thead><tr><th></th><th>Plugin</th><th>Author</th><th>Version</th><th>Status</th><th></th></tr></thead>
<tbody id="plugin_list"><tr><td colspan='6' style='text-align:center;padding-top:12px'><i class="fa fa-spinner fa-spin icon"></i><em>Please wait, retrieving plugin information ...</em></td><tr></tbody>
<thead><tr><th></th><th>Plugin</th><th>Author</th><th>Version</th><th>Status</th><th>Uninstall</th></tr></thead>
<tbody id="plugin_list"><tr><td colspan='6' style='text-align:center;padding-top:12px'><i class="fa fa-spinner fa-spin icon"></i><em>Please wait,<?=$stale?' updating and':''?> retrieving plugin information ...</em></td><tr></tbody>
</table>

View File

@@ -0,0 +1,47 @@
Menu="About"
Title="Update OS"
---
<?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.
*/
?>
<?$empty = "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-spinner fa-spin icon'></i><em>Please wait, updating and retrieving system information ...</em></td><tr>"?>
<script>
var original = null;
function change_release(release) {
$('#os_list').html("<?=$empty?>");
if (original) {
if (release != original) release = '';
} else {
if (release) original = release;
}
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true',release:release},function(data) {
if (data) $('#os_list').html(data);
$('#os_table').trigger('update',true);
});
}
$(function() {
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{system:'true'},function(data) {
if (data) $('#os_list').html(data);
$('#os_table').tablesorter({sortList:[[1,0]],headers:{0:{sorter:false},5:{sorter:false}}});
<?if (preg_match("/^\*\*REBOOT REQUIRED\!\*\*/",@file_get_contents("$docroot/plugins/unRAIDServer/README.md"))):?>
$('#change_release').prop('disabled',true);
<?endif;?>
});
});
</script>
<table class='tablesorter plugins shift' id='os_table'>
<thead><tr><th></th><th>System</th><th>Author</th><th>Version</th><th>Status</th><th>Release</th></tr></thead>
<tbody id="os_list"><?=$empty?></tbody>
</table>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1008 B

View File

@@ -1,6 +1,6 @@
<?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,
@@ -11,7 +11,7 @@
*/
?>
<?
$docroot = $docroot ?: @$_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// Invoke the plugin command with indicated method
function plugin($method, $arg = '') {
@@ -21,12 +21,12 @@ function plugin($method, $arg = '') {
return implode("\n", $output);
}
function make_link($method, $arg) {
function make_link($method, $arg, $extra='') {
$id = basename($arg, ".plg").$method;
$check = $method=='update' ? "" : "<input type='checkbox' onClick='document.getElementById(\"$id\").disabled=!this.checked'>";
$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";
return "{$check}<input type='button' id='$id' value='{$method}' onclick='openBox(\"{$cmd}\",\"".ucwords($method)." Plugin\",600,900,true)'{$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}>";
}
// trying our best to find an icon
@@ -47,4 +47,7 @@ function icon($name) {
// last resort - plugin manager icon
return "plugins/dynamix.plugin.manager/images/dynamix.plugin.manager.png";
}
function mk_option($select,$value) {
return "<option value='$value'".($select==$value?" selected":"").">".ucfirst($value)."</option>";
}
?>

View File

@@ -1,6 +1,6 @@
<?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,
@@ -11,78 +11,123 @@
*/
?>
<?
$docroot = $docroot ?: @$_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
$docroot = $docroot ?: $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
require_once "$docroot/webGui/include/Markdown.php";
require_once "$docroot/plugins/dynamix.plugin.manager/include/PluginHelpers.php";
$current = parse_ini_file('/etc/unraid-version');
foreach (glob("/var/log/plugins/*.plg", GLOB_NOSORT) as $plugin_link) {
// only consider symlinks
$stale = $_GET['stale'] ?? false;
$release = $_GET['release'] ?? false;
$system = $_GET['system'] ?? false;
$empty = true;
$nofetch = false;
$builtin = ['unRAIDServer','dynamix'];
$https = ['stable' => 'https://raw.github.com/limetech/\&name;/master/\&name;.plg',
'next' => 'https://s3.amazonaws.com/dnld.lime-technology.com/\&category;/\&name;.plg'];
foreach (glob("/var/log/plugins/*.plg",GLOB_NOSORT) as $plugin_link) {
//only consider symlinks
$plugin_file = @readlink($plugin_link);
if ($plugin_file === false) continue;
// plugin name
$name = plugin("name", $plugin_file);
if ($name === false) $name = basename($plugin_file, ".plg");
// link/icon
//plugin name
$name = plugin('name',$plugin_file) ?: basename($plugin_file,".plg");
$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');
//OS update?
$os = $system && $name==$builtin[0];
$toggle = false;
//toggle stable/next release?
if ($os && $release) {
$toggle = plugin('version',$plugin_file);
$tmp_plg = "$name-.plg";
$tmp_file = "/var/tmp/$name.plg";
copy($plugin_file,$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;
}
//link/icon
$icon = icon($name);
if ($launch = plugin("launch", $plugin_file))
$link = "<a href='/$launch'><img src='/$icon' width='48px'/></a>";
if ($launch = plugin('launch',$plugin_file))
$link = "<a href='/$launch'><img src='/$icon'></a>";
else
$link = "<img src='/{$icon}' width='48px'/>";
// desc
$link = "<img src='/$icon'>";
//description
$readme = "plugins/{$name}/README.md";
if (file_exists($readme))
$desc = Markdown(file_get_contents($readme));
else
$desc = Markdown("**{$name}**");
// author
$author = plugin("author", $plugin_file);
if ($author === false) $author = "anonymous";
// version
$version = plugin("version", $plugin_file);
if ($version === false) $version = "unknown";
// version info
$version_info = $version;
// status info
$status_info = "no update";
//author
$author = plugin('author',$plugin_file) ?: "anonymous";
//version
$version = plugin('version',$plugin_file) ?: "unknown";
//category
$cat = strpos($version,'rc')!==false ? 'next' : 'stable';
//status
$status = 'no update';
$changes_file = $plugin_file;
$URL = plugin("pluginURL", $plugin_file);
$URL = plugin('pluginURL',$plugin_file);
if ($URL !== false) {
$filename = "/tmp/plugins/".basename($URL);
$filename = "/tmp/plugins/".(($os && $release) ? $tmp_plg : basename($URL));
if (file_exists($filename)) {
$latest = plugin("version", $filename);
if (strcmp($latest, $version) > 0) {
$unRAID = plugin("unRAID", $filename);
if ($unRAID === false || version_compare($current['version'], $unRAID, '>=')) {
$version_info .= "<br><span class='red-text'>{$latest}</span>";
$status_info = make_link("update", basename($plugin_file));
$changes_file = $filename;
} else {
$status_info = "up-to-date";
}
if ($toggle && $toggle != $version) {
$status = make_link('install',$plugin_file,'forced');
} else {
$status_info = "up-to-date";
$latest = plugin('version',$filename);
if (strcmp($latest,$version) > 0) {
$unRAID = plugin('unRAID',$filename);
if ($unRAID === false || version_compare($current['version'],$unRAID,'>=')) {
$version .= "<br><span class='red-text'>{$latest}</span>";
$status = make_link("update",basename($plugin_file));
$changes_file = $filename;
} else {
$status = "up-to-date";
}
} else {
$status = "up-to-date";
}
}
} else {
if ($_GET['stale']) $status_info = "unknown";
if ($stale) $status = "unknown";
}
$nofetch |= ($status == 'no update');
}
$changes = plugin("changes", $changes_file);
$changes = plugin('changes',$changes_file);
if ($changes !== false) {
$txtfile = "/tmp/plugins/".basename($plugin_file,'.plg').".txt";
file_put_contents($txtfile, $changes);
$version_info .= "&nbsp;<a href='#' title='View Release Notes' onclick=\"openBox('/plugins/dynamix.plugin.manager/include/ShowChanges.php?file=".urlencode($txtfile)."','Release Notes',600,900); return false\"><img src='/webGui/images/information.png' class='icon'></a>";
file_put_contents($txtfile,$changes);
$version .= "&nbsp;<a href='#' title='View Release Notes' onclick=\"openBox('/plugins/dynamix.plugin.manager/include/ShowChanges.php?file=".urlencode($txtfile)."','Release Notes',600,900); return false\"><img src='/webGui/images/information.png' class='icon'></a>";
}
// action
$action = strpos($plugin_file, "$docroot/plugins") !== 0 ? make_link("remove", basename($plugin_file)) : "built-in";
// write plugin information
//write plugin information
$empty = false;
echo "<tr>";
echo "<td style='vertical-align:top;width:64px'><p style='text-align:center'>{$link}</p></td>";
echo "<td><span class='desc_readmore' style='display:block'>{$desc}</span></td>";
echo "<td>{$author}</td>";
echo "<td>{$version_info}</td>";
echo "<td>{$status_info}</td>";
echo "<td>{$action}</td>";
echo "<td>{$version}</td>";
echo "<td>{$status}</td>";
echo "<td>";
if ($system) {
if ($os) {
echo "<select id='change_release' class='auto' onchange='change_release(this.value)'>";
echo mk_option($cat,'stable');
echo mk_option($cat,'next');
echo "</select>";
}
} else {
echo make_link('remove',basename($plugin_file));
}
echo "</td>";
echo "</tr>";
//remove temporary symlink
@unlink("/var/log/plugins/$tmp_plg");
}
if ($empty) echo "<tr><td colspan='6' style='text-align:center;padding-top:12px'><i class='fa fa-check-square-o icon'></i> No plugins installed</td><tr>";
elseif ($nofetch) echo "<tr><td colspan='4'></td><td><input type='button' value='Retry' onclick='change_release()'></td><td></td><tr>";
?>

View File

@@ -7,13 +7,15 @@
$usage = <<<EOF
Process plugin files.
Usage: plugin install PLUGIN-FILE
Usage: plugin install PLUGIN-FILE [forced]
install a plugin
PLUGIN-FILE is a plugin definition XML file with ".plg" extension.
PLUGIN-FILE can be a local file, or a URL. If a URL, the plugin file is first downloaded to /tmp/plugins.
forced is optional and can be used to install a lower version than currently running.
This command will process all FILE elements in PLUGIN-FILE which are tagged with the "install" method (or
that have no method tag).
@@ -56,7 +58,7 @@ Usage: plugin check PLUGIN
Usage: plugin checkall
check all installed plugins
Runs 'plugin check PLUGIN' for each plugin file linked-to in /var/lib/plugins.
Runs 'plugin check PLUGIN' for each plugin file linked-to in /var/log/plugins.
Usage: plugin update PLUGIN
update the plugin
@@ -438,14 +440,18 @@ if ($method == "install") {
echo "plugin: $error\n";
exit(1);
}
// do not re-install if same plugin already installed or has higher version
if (strcmp($version, $installed_version) < 0) {
echo "plugin: not installing older version\n";
exit(1);
}
if (strcmp($version, $installed_version) == 0) {
echo "plugin: not reinstalling same version\n";
exit(1);
// check version installation?
$forced = $argc==4 ? $argv[3] : false;
if (!$forced) {
// do not re-install if same plugin already installed or has higher version
if (strcmp($version, $installed_version) < 0) {
echo "plugin: not installing older version\n";
exit(1);
}
if (strcmp($version, $installed_version) == 0) {
echo "plugin: not reinstalling same version\n";
exit(1);
}
}
if (plugin("install", $plugin_file, $error) === false) {
echo "plugin: $error\n";

View File

@@ -28,6 +28,8 @@
<style>
.inline_help{display:none}
.upgrade_notice{position:fixed;top:1px;left:0;width:100%;height:40px;line-height:40px;color:#E68A00;background:#FEEFB3;border-bottom:#E68A00 1px solid;text-align:center;font-size:15px;z-index:999}
.upgrade_notice i{margin:14px;float:right;cursor:pointer}
<?
$banner = '/boot/config/plugins/dynamix/banner.png';
echo "#header.image{background-image:url(";
@@ -136,7 +138,6 @@ function openBox(cmd,title,height,width,load) {
var options = load ? {modal:true,onClose:function(){location=location;}} : {modal:true};
Shadowbox.open({content:run, player:'iframe', title:title, height:height, width:width, options:options});
}
function openWindow(cmd,title,height,width) {
// open regular window (run in background)
var window_name = title.replace(/ /g,"_");
@@ -171,7 +172,19 @@ function showNotice(data,plugin) {
var href = "href=\"#\" onclick=\"openBox('/plugins/dynamix.plugin.manager/scripts/plugin&arg1=update&arg2="+plugin+".plg','Update Plugin',600,900,true)\"";
else
var href = "href=\"/Plugins\"";
$('#user-notice').html(data.replace(/<a>(.*?)<\/a>/,"<a "+href+">$1</a>"));
$('#user-notice').html(data.replace(/<a>(.*)<\/a>/,"<a "+href+">$1</a>"));
}
function showUpgrade(data,plugin) {
var href = "href=\"#\" onclick=\"hideUpgrade();openBox('/plugins/dynamix.plugin.manager/scripts/plugin&arg1=update&arg2="+plugin+".plg','Update Plugin',600,900,true)\"";
if ($.cookie('os_upgrade')==null)
$('.upgrade_notice').html(data.replace(/<a(.*)>(.*)<\/a>/,"<a "+href+"$1>$2</a>")+"<i class='fa fa-close' title='Close' onclick='hideUpgrade(true)'></i>").show();
}
function hideUpgrade(set) {
$('.upgrade_notice').hide();
if (set)
$.cookie('os_upgrade','true',{path:'/'});
else
$.removeCookie('os_upgrade',{path:'/'});
}
function notifier() {
var tub1 = 0, tub2 = 0, tub3 = 0;
@@ -272,6 +285,7 @@ $(document).ajaxSend(function(elm, xhr, s){
</head>
<body class="<?='page_'.strtolower($myPage['name'])?>">
<div id="template">
<div class="upgrade_notice" style="display:none"></div>
<div id="header" class="<?=$display['banner']?>">
<div class="logo">
<a href="#" onclick="openBox('/webGui/include/Feedback.php','Feedback',450,450,false);return false;"><img src="/webGui/images/limetech-logo-<?=$display['theme']?>.png" title="Feedback" border="0"/></a><br/>
@@ -400,12 +414,10 @@ $(function() {
<?if (strpos(file_get_contents('/proc/cmdline'),'unraidsafemode')!==false):?>
showNotice('System running in <b>safe</b> mode');
<?else:?>
<?if ($version = plugin_update_available('unRAIDServer',true)):?>
showNotice('unRAID OS v<?=$version?> is available. <a>Download Now</a>','unRAIDServer');
<?elseif (preg_match("/^\*\*REBOOT REQUIRED\!\*\*/", @file_get_contents("$docroot/plugins/unRAIDServer/README.md"))):?>
showNotice('Reboot required to apply unRAID OS update');
<?elseif ($version = plugin_update_available('dynamix')):?>
showNotice('Dynamix webGUI v<?=$version?> is available. <a>Download Now</a>','dynamix');
<?if (preg_match("/^\*\*REBOOT REQUIRED\!\*\*/",@file_get_contents("$docroot/plugins/unRAIDServer/README.md"))):?>
showUpgrade('<b>Reboot required</b> to apply unRAID OS update');
<?elseif ($version = plugin_update_available('unRAIDServer',true)):?>
showUpgrade('unRAID OS v<?=$version?> is available. <a>Download Now</a>','unRAIDServer');
<?endif;?>
<?endif;?>
<?if ($notify['display']):?>