Plugin system update

This commit is contained in:
bergware
2022-07-15 21:23:21 +02:00
parent a230d199d5
commit 5b641d107b
9 changed files with 181 additions and 62 deletions
+20 -10
View File
@@ -244,21 +244,29 @@ function openTerminal(tag,name,more) {
var socket = ['ttyd','syslog'].includes(tag) ? '/webterminal/'+tag+'/' : '/logterminal/'+name+(more=='.log'?more:'')+'/';
$.get('/webGui/include/OpenTerminal.php',{tag:tag,name:name,more:more},function(){tty_window.location=socket; tty_window.focus();});
}
function bannerAlert(text,cmd,plg,func) {
function bannerAlert(text,cmd,plg,func,start) {
$.post('/webGui/include/StartCommand.php',{cmd:cmd,pid:1},function(pid) {
if (pid == 0) {
if ($(".upgrade_notice").hasClass('done') || timers.bannerAlert==null) {
if ($(".upgrade_notice").hasClass('done') || timers.bannerAlert == null) {
forcedBanner = false;
if ($.cookie('addAlert') != null) {
removeBannerWarning($.cookie('addAlert'));
$.removeCookie('addAlert');
}
$(".upgrade_notice").removeClass('alert done');
if (plg != null) setTimeout((func||'loadlist')+'("'+plg+'")',250);
timers.callback = null;
if (plg != null) {
if ($.cookie('addAlert-page') == null || $.cookie('addAlert-page') == '<?=$task?>') {
setTimeout((func||'loadlist')+'("'+plg+'")',250);
} else if ('Plugins' == '<?=$task?>') {
setTimeout(refresh);
}
$.removeCookie('addAlert-page');
}
} else {
$(".upgrade_notice").removeClass('alert').addClass('done');
timers.bannerAlert = null;
setTimeout(function(){bannerAlert(text,cmd,plg,func);},1000);
setTimeout(function(){bannerAlert(text,cmd,plg,func,start);},1000);
}
} else {
$.cookie('addAlert',addBannerWarning(text,true,true,true));
@@ -266,12 +274,14 @@ function bannerAlert(text,cmd,plg,func) {
$.cookie('addAlert-cmd',cmd);
$.cookie('addAlert-plg',plg);
$.cookie('addAlert-func',func);
timers.bannerAlert = setTimeout(function(){bannerAlert(text,cmd,plg,func);},1000);
if ($.cookie('addAlert-page') == null) $.cookie('addAlert-page','<?=$task?>');
timers.bannerAlert = setTimeout(function(){bannerAlert(text,cmd,plg,func,start);},1000);
if (start == 1 && timers.callback == null && plg != null) timers.callback = setTimeout((func||'loadlist')+'("'+plg+'")',250);
}
});
}
function openPlugin(cmd,title,plg,func) {
$.post('/webGui/include/StartCommand.php',{cmd:cmd+' nchan'},function(pid) {
function openPlugin(cmd,title,plg,func,start=0) {
$.post('/webGui/include/StartCommand.php',{cmd:cmd+' nchan',start:start},function(pid) {
if (pid==0) {
$(".upgrade_notice").addClass('alert');
return;
@@ -281,13 +291,13 @@ function openPlugin(cmd,title,plg,func) {
nchan_plugins.stop();
$('div.spinner.fixed').hide();
$('.sweet-alert').hide('fast').removeClass('nchan');
setTimeout(function(){bannerAlert("<?=_('Attention - operation continues in background')?> ["+pid.toString().padStart(8,'0')+"]<i class='fa fa-bomb fa-fw' title=\"<?=_('Abort background process')?>\" onclick='abortOperation("+pid+")'></i>",cmd,plg,func);});
setTimeout(function(){bannerAlert("<?=_('Attention - operation continues in background')?> ["+pid.toString().padStart(8,'0')+"]<i class='fa fa-bomb fa-fw' title=\"<?=_('Abort background process')?>\" onclick='abortOperation("+pid+")'></i>",cmd,plg,func,start);});
});
$('.sweet-alert').addClass('nchan');
});
}
function abortOperation(pid) {
swal({title:"<?=_('Abort background operation')?>",text:"<?=_('This may leave the system unstable')?>!",html:true,type:'warning',showCancelButton:true,confirmButtonText:"<?=_('Proceed')?>",cancelButtonText:"<?=_('Cancel')?>"},function(){
swal({title:"<?=_('Abort background operation')?>",text:"<?=_('This may leave an unknown state')?>",html:true,type:'warning',showCancelButton:true,confirmButtonText:"<?=_('Proceed')?>",cancelButtonText:"<?=_('Cancel')?>"},function(){
$.post('/webGui/include/StartCommand.php',{kill:pid},function() {
clearTimeout(timers.bannerAlert);
timers.bannerAlert = null;
@@ -886,7 +896,7 @@ $(function() {
var top = ($.cookie('top')||0) - $('.tabs').offset().top - 75;
if (top>0) {$('html,body').scrollTop(top);}
$.removeCookie('top');
if ($.cookie('addAlert')!=null) bannerAlert(addAlert.text,addAlert.cmd,addAlert.plg,addAlert.func);
if ($.cookie('addAlert') != null) bannerAlert(addAlert.text,addAlert.cmd,addAlert.plg,addAlert.func);
<?if ($safemode):?>
showNotice("<?=_('System running in')?> <b><?=('safe mode')?></b>");
<?else:?>
+5 -4
View File
@@ -18,11 +18,12 @@ function pgrep($proc) {
return exec("pgrep -f $proc");
}
if (!empty($_POST['kill']) && $_POST['kill'] > 1) {
if (isset($_POST['kill']) && $_POST['kill'] > 1) {
exec("kill ".$_POST['kill']);
die;
}
$start = isset($_POST['start']) && $_POST['start'] == 1;
[$command,$args] = explode(' ',unscript($_POST['cmd']??''),2);
// find absolute path of command
@@ -35,11 +36,11 @@ if ($command && strncmp($name,$path,strlen($path))===0) {
if (isset($_POST['pid'])) {
// return running pid
$pid = pgrep($name);
} elseif (!pgrep($name)) {
// only execute when command and valid path is given and command not already running
} elseif ($start or !pgrep($name)) {
// start command in background and return pid
exec("echo \"$name $args\" | at -M now >/dev/null 2>&1");
usleep(5000);
$pid = pgrep($name); // started
$pid = pgrep($name);
}
}
echo $pid;