Integrate CA's Plugin Helpers

This commit is contained in:
Squidly271
2019-08-31 21:51:48 -04:00
parent 6b24864703
commit 3d8639dd60
2 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
Menu='Buttons'
Link='nav-user'
---
<?
/* Copyright 2005-2019, Lime Technology
* Copyright 2019, Andrew Zawadzki.
*
* 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.
*/
?>
<style>
/* Additional CSS for when user supplies element */
.ca_element_notice{padding-right:20px;width:100%;height:40px;line-height:40px;color:#e68a00;background:#feefb3;border-bottom:#e68a00 1px solid;text-align:center;font-size:1.4rem;z-index:900;display:none;}
.ca_PluginUpdateDismiss{float:right;margin-right:20px;cursor:pointer;}
.ca_pluginUpdateInfo{cursor:pointer;}
.ca_PluginUpdateInstall{cursor:pointer;}
a.bannerInfo {cursor:pointer;text-decoration:none;}
.bannerInfo::before {content:"\f05a";font-family:fontAwesome;color:#e68a00;}
</style>
<script>
var ca_PluginUpdatePLG;
var ca_PluginUpdateElement;
function ca_hidePluginUpdate(version) {
$.cookie(ca_PluginUpdatePLG,version);
$(ca_PluginUpdateElement).hide();
}
function ca_pluginUpdateInstall(plugin) {
openBox("/plugins/dynamix.plugin.manager/scripts/plugin&arg1=update&arg2="+plugin,"Installing Update",600,900,true,"window.location.reload()");
}
function ca_pluginUpdateShowInfo(cmd,title,height,width,load,func,id) {
// open shadowbox window (run in foreground)
var run = cmd.split('?')[0].substr(-4)=='.php' ? cmd : '/logging.htm?cmd='+cmd+'&csrf_token=<?=$var['csrf_token']?>';
var options = load ? (func ? {modal:true,onClose:function(){setTimeout(func+'('+'"'+(id||'')+'")',0);}} : {modal:false,onClose:function(){location=location;}}) : {modal:false};
Shadowbox.open({content:run, player:'iframe', title:title, height:Math.min(height,screen.availHeight), width:Math.min(width,screen.availWidth), options:options});
}
function caPluginUpdateCheck(plugin,options=[],callback) {
ca_PluginUpdatePLG = plugin;
pluginFilename = plugin.substr(0, plugin.lastIndexOf("."));
console.time("checkPlugin "+plugin);
console.log("checkPlugin "+plugin);
$.post("/plugins/dynamix.plugin.manager/scripts/PluginAPI.php",{action:'checkPlugin',options:{plugin:plugin}},function(caAPIresult) {
console.groupCollapsed("Result checkPlugin "+plugin);
console.log(caAPIresult);
console.timeEnd("checkPlugin "+plugin);
console.groupEnd();
var result = JSON.parse(caAPIresult);
if ( options.debug == true ) result.updateAvailable = true;
var name = options.name ? options.name : "this plugin ("+plugin+")";
if ( ! options.element ) {
if ( result.updateAvailable ) {
var HTML = "An upgrade to "+name+" is available. Click <a class='ca_PluginUpdateInstall' onclick='ca_pluginUpdateInstall(&quot;"+plugin+"&quot;);'>here</a> to install version "+result.version+" <a class='bannerInfo fa fa-info-circle' onclick=ca_pluginUpdateShowInfo('/plugins/dynamix.plugin.manager/include/ShowChanges.php?file=%2Ftmp%2Fplugins%2F"+pluginFilename+".txt','Release&nbsp;Notes',600,900); return false;'></a>";
addBannerWarning(HTML,false,options.noDismiss);
}
} else {
if ( $.cookie(plugin) != result.version ) {
if ( result.updateAvailable ) {
var HTML = "An upgrade to "+name+" is available. Click <a class='ca_PluginUpdateInstall' onclick='ca_pluginUpdateInstall(&quot;"+plugin+"&quot;);'>here</a> to install version "+result.version+" <i class='ca_pluginUpdateInfo fa fa-info-circle' onclick=ca_pluginUpdateShowInfo('/plugins/dynamix.plugin.manager/include/ShowChanges.php?file=%2Ftmp%2Fplugins%2F"+pluginFilename+".txt','Release&nbsp;Notes',600,900); return false;'></i>";
if ( ! options.noDismiss ) {
HTML = HTML.concat("<span class='ca_PluginUpdateDismiss'><i class='fa fa-close' onclick='ca_hidePluginUpdate(&quot;"+result.version+"&quot;);'></i>");
}
result.HTML = HTML;
ca_PluginUpdateElement = options.element;
if ( ! options.dontShow ) {
$(options.element).html(HTML);
$(options.element).addClass("ca_element_notice").show();
}
}
}
}
if ( typeof options === "function" ) {
callback = options;
}
if ( typeof callback === "function" ) {
callback(JSON.stringify(result));
}
});
}
</script>

View File

@@ -0,0 +1,51 @@
<?PHP
/* Copyright 2005-2019, Lime Technology
* Copyright 2019, Andrew Zawadzki.
*
* 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.
*/
require_once("/usr/local/emhttp/plugins/dynamix.plugin.manager/include/PluginHelpers.php");
function download_url($url, $path = "", $bg = false, $timeout=45){
if ( ! strpos($url,"?") ) $url .= "?".time();
exec("curl --compressed --connect-timeout 15 --max-time $timeout --silent --insecure --location --fail ".($path ? " -o '$path' " : "")." $url ".($bg ? ">/dev/null 2>&1 &" : "2>/dev/null"), $out, $exit_code );
return ($exit_code === 0 ) ? implode("\n", $out) : false;
}
$options = $_POST['options'];
$plugin = $options['plugin'];
if ( ! $plugin || ! file_exists("/var/log/plugins/$plugin") ) {
echo json_encode(array("updateAvailable"=>false));
return;
}
exec("mkdir -p /tmp/plugins");
@unlink("/tmp/plugins/$plugin");
$url = @plugin("pluginURL","/boot/config/plugins/$plugin");
download_url($url,"/tmp/plugins/$plugin");
$changes = @plugin("changes","/tmp/plugins/$plugin");
$version = @plugin("version","/tmp/plugins/$plugin");
$installedVersion = @plugin("version","/boot/config/plugins/$plugin");
$min = @plugin("min","/tmp/plugins/$plugin") ?: "6.4.0";
if ( $changes ) {
file_put_contents("/tmp/plugins/".pathinfo($plugin, PATHINFO_FILENAME).".txt",$changes);
} else {
@unlink("/tmp/plugins/".pathinfo($plugin, PATHINFO_FILENAME).".txt");
}
$update = false;
if ( strcmp($version,$installedVersion) > 0 ) {
$unraid = parse_ini_file("/etc/unraid-version");
$update = (version_compare($min,$unraid['version'],">")) ? false : true;
}
echo json_encode(array("updateAvailable" => $update,"version" => $version,"min"=>$min,"changes"=>$changes,"installedVersion"=>$installedVersion));
?>