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
@@ -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>";
}
?>
@@ -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>";
?>