Merge pull request #1 from unraid/master

catch up
This commit is contained in:
Squidly271
2025-04-01 19:11:29 -04:00
committed by GitHub
9 changed files with 130 additions and 74 deletions
+5 -5
View File
@@ -319,7 +319,7 @@ $('div[class=title]:not(":last, .disable_diskio")').each(function(){$(this).appe
$('.tooltip_diskio').tooltipster({delay:100,trigger:'custom',triggerOpen:{mouseenter:true},triggerClose:{click:false,scroll:true,mouseleave:true}});
<?if (_var($var,'fsState')=='Started'):?>
var mymonitor = new NchanSubscriber('/sub/mymonitor',{subscriber:'websocket'});
var mymonitor = new NchanSubscriber('/sub/mymonitor',{subscriber:'websocket', reconnectTimeout:5000});
mymonitor.on('message', function(state) {
switch (state) {
case '0': // normal operation
@@ -367,12 +367,12 @@ mymonitor.on('message', function(state) {
mymonitor.start();
<?endif;?>
var arraymonitor = new NchanSubscriber('/sub/arraymonitor',{subscriber:'websocket'});
var arraymonitor = new NchanSubscriber('/sub/arraymonitor',{subscriber:'websocket', reconnectTimeout:5000});
arraymonitor.on('message', function(state) {
if (state==1 && !timers.arraymonitor) timers.arraymonitor = setTimeout(refresh,1250);
});
var devices = new NchanSubscriber('/sub/devices<?=$spot?",parity":""?>',{subscriber:'websocket'});
var devices = new NchanSubscriber('/sub/devices<?=$spot?",parity":""?>',{subscriber:'websocket', reconnectTimeout:5000});
devices.on('message', function(msg,meta) {
switch (<?if($spot):?>meta.id.channel()<?else:?>0<?endif;?>) {
case 0:
@@ -423,7 +423,7 @@ devices.on('message', function(msg,meta) {
devices.start().monitor();
<?if (substr(_var($var,'fsState'),-3)=='ing'):?>
var fsState = new NchanSubscriber('/sub/fsState',{subscriber:'websocket'});
var fsState = new NchanSubscriber('/sub/fsState',{subscriber:'websocket', reconnectTimeout:5000});
fsState.on('message', function(msg) {
switch (msg) {
case 'stop':
@@ -438,7 +438,7 @@ fsState.start();
<?elseif ($spot):?>
setTimeout(function(){$('#pauseButton').prop('disabled',false);$('#cancelButton').prop('disabled',false);},250);
<?else:?>
var paritymonitor = new NchanSubscriber('/sub/paritymonitor',{subscriber:'websocket'});
var paritymonitor = new NchanSubscriber('/sub/paritymonitor',{subscriber:'websocket', reconnectTimeout:5000});
paritymonitor.on('message', function(busy){if (busy==1) refresh();});
setTimeout(function(){paritymonitor.start();},5000);
<?endif;?>
+3 -3
View File
@@ -1614,7 +1614,7 @@ function cpu_parse(msg) {
}
<?if ($vmusage == "Y"):?>
var vmdashusage = new NchanSubscriber('/sub/vm_dashusage',{subscriber:'websocket'});
var vmdashusage = new NchanSubscriber('/sub/vm_dashusage',{subscriber:'websocket', reconnectTimeout:5000});
vmdashusage.on('message', function(msg){
var data = JSON.parse(msg);
for (const [vm, vmdata] of Object.entries(data)) {
@@ -1625,7 +1625,7 @@ vmdashusage.on('message', function(msg){
});
<?endif;?>
var dashboard = new NchanSubscriber('/sub/cpuload,update1,update2,update3<?=$wireguard?",wireguard":""?>',{subscriber:'websocket'});
var dashboard = new NchanSubscriber('/sub/cpuload,update1,update2,update3<?=$wireguard?",wireguard":""?>',{subscriber:'websocket', reconnectTimeout:5000});
dashboard.on('message',function(msg,meta) {
switch (meta.id.channel()) {
case 0:
@@ -1770,7 +1770,7 @@ dashboard.on('message',function(msg,meta) {
});
<?if ($apcupsd):?>
var apcups = new NchanSubscriber('/sub/apcups',{subscriber:'websocket'});
var apcups = new NchanSubscriber('/sub/apcups',{subscriber:'websocket', reconnectTimeout:5000});
apcups.on('message',function(msg) {
var get = JSON.parse(msg);
$('#ups_model').html(get[0]);
+3 -3
View File
@@ -42,7 +42,7 @@ _(Regulatory region)_:
[$code, $country] = my_explode('|', $region);
echo mk_option(_var($wlan0,'REGION'), $code, _($country));
}
?></select><span id="manual" class="hide">_(Manual input)_ [XX]: <input type="text" name="REGION_XX" class="wifi" value="<?=_var($wlan0,'REGION_XX')?>" minlength="2" maxlength="2"></span>
?></select><span id="manual" class="hide">_(Manual input)_ [XX]: <input type="text" name="REGION_XX" class="wifi" value="<?=_var($wlan0,'REGION_XX')?>" minlength="2" maxlength="2" title="_(Two letter country code)_ (ISO 3166)"></span>
&nbsp;
: <input type="submit" value="_(Apply)_" disabled><input type="button" value="_(Done)_" onclick="done()">
@@ -67,7 +67,7 @@ _(Other networks)_:
<div markdown="1" class="shade-<?=$display['theme']?>">
_(Add network)_:
: <span class="wifi"><input name="CUSTOM" type="text" class="narrow" maxlength="20" autocomplete="off" spellcheck="false" value=""></span><i class="fa fa-wifi hand grey-text" onclick="manage_wifi(encodeURIComponent($('input[name=CUSTOM]').val()),3)" title="<?=$title?>"></i>
: <span class="wifi"><input name="CUSTOM" type="text" class="narrow" maxlength="32" autocomplete="off" spellcheck="false" value=""></span><i class="fa fa-wifi hand grey-text" onclick="manage_wifi(encodeURIComponent($('input[name=CUSTOM]').val()),3)" title="<?=$title?>"></i>
</div>
</div>
@@ -110,7 +110,7 @@ function manage_wifi(ssid,task) {
}
function showManual(val) {
if (val == '00') $('#manual').show(); else $('#manual').hide();
if (val == '00') {$('#manual').show(); $('input[name="REGION_XX"]').focus()} else $('#manual').hide();
}
function showDHCP(val, v) {
@@ -106,13 +106,13 @@ if (!file_exists($notes)) file_put_contents($notes,shell_exec("$docroot/plugins/
String.prototype.actionName = function(){return this.split(/[\\/]/g).pop();}
String.prototype.channel = function(){return this.split(':')[1].split(',').findIndex((e)=>/\[\d\]/.test(e));}
NchanSubscriber.prototype.monitor = function(){subscribers.push(this);}
Shadowbox.init({skipSetup:true});
context.init();
// list of nchan subscribers to start/stop at focus change
var subscribers = [];
// server uptime
var uptime = <?=strtok(exec("cat /proc/uptime"),' ')?>;
var expiretime = <?=_var($var,'regTy')=='Trial'||strstr(_var($var,'regTy'),'expired')?_var($var,'regTm2'):0?>;
@@ -144,6 +144,7 @@ function pauseEvents(id) {
if (!id || i==id) clearTimeout(timer);
});
}
function resumeEvents(id,delay) {
var startDelay = delay||50;
$.each(timers, function(i,timer) {
@@ -151,9 +152,11 @@ function resumeEvents(id,delay) {
startDelay += 50;
});
}
function plus(value,single,plural,last) {
return value>0 ? (value+' '+(value==1?single:plural)+(last?'':', ')) : '';
}
function updateTime() {
var now = new Date();
var days = parseInt(uptime/86400);
@@ -183,6 +186,7 @@ function updateTime() {
}
setTimeout(updateTime,1000);
}
function refresh(top) {
if (typeof top === 'undefined') {
for (var i=0,element; element=document.querySelectorAll('input,button,select')[i]; i++) {element.disabled = true;}
@@ -193,11 +197,13 @@ function refresh(top) {
location.reload();
}
}
function initab(page) {
$.removeCookie('one');
$.removeCookie('tab');
if (page != null) location.replace(page);
}
function settab(tab) {
<?switch ($myPage['name']):?>
<?case'Main':?>
@@ -213,6 +219,7 @@ function settab(tab) {
$.cookie('one',tab);
<?endswitch;?>
}
function done(key) {
var url = location.pathname.split('/');
var path = '/'+url[1];
@@ -220,10 +227,12 @@ function done(key) {
$.removeCookie('one');
location.replace(path);
}
function chkDelete(form, button) {
button.value = form.confirmDelete.checked ? "<?=_('Delete')?>" : "<?=_('Apply')?>";
button.disabled = false;
}
function makeWindow(name,height,width) {
var top = (screen.height-height)/2;
if (top < 0) {top = 0; height = screen.availHeight;}
@@ -231,6 +240,7 @@ function makeWindow(name,height,width) {
if (left < 0) {left = 0; width = screen.availWidth;}
return window.open('',name,'resizeable=yes,scrollbars=yes,height='+height+',width='+width+',top='+top+',left='+left);
}
function openBox(cmd,title,height,width,load,func,id) {
// open shadowbox window (run in foreground)
// included for legacy purposes, replaced by openPlugin
@@ -239,6 +249,7 @@ function openBox(cmd,title,height,width,load,func,id) {
var options = load ? (func ? {modal:true,onClose:function(){setTimeout(func+'('+'"'+(id||'')+'")');}} : {modal:true,onClose:function(){location.reload();}}) : {modal:false};
Shadowbox.open({content:run, player:'iframe', title:title, height:Math.min(screen.availHeight,800), width:Math.min(screen.availWidth,1200), options:options});
}
function openWindow(cmd,title,height,width) {
// open regular window (run in background)
// included for legacy purposes, replaced by openTerminal
@@ -256,6 +267,7 @@ function openWindow(cmd,title,height,width) {
makeWindow(window_name,height,width);
form.submit();
}
function openTerminal(tag,name,more) {
if (/MSIE|Edge/.test(navigator.userAgent)) {
swal({title:"_(Unsupported Feature)_",text:"_(Sorry, this feature is not supported by MSIE/Edge)_.<br>_(Please try a different browser)_",type:'error',html:true,animation:'none',confirmButtonText:"_(Ok)_"});
@@ -267,6 +279,7 @@ 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(){setTimeout(function(){tty_window.location=socket; tty_window.focus();},200);});
}
function bannerAlert(text,cmd,plg,func,start) {
$.post('/webGui/include/StartCommand.php',{cmd:cmd,pid:1},function(pid) {
if (pid == 0) {
@@ -303,6 +316,7 @@ function bannerAlert(text,cmd,plg,func,start) {
}
});
}
function openPlugin(cmd,title,plg,func,start=0,button=0) {
// start = 0 : run command only when not already running (default)
// start = 1 : run command unconditionally
@@ -326,6 +340,7 @@ function openPlugin(cmd,title,plg,func,start=0,button=0) {
$('button.confirm').prop('disabled',button!=0);
});
}
function openDocker(cmd,title,plg,func,start=0,button=0) {
// start = 0 : run command only when not already running (default)
// start = 1 : run command unconditionally
@@ -349,6 +364,7 @@ function openDocker(cmd,title,plg,func,start=0,button=0) {
$('button.confirm').prop('disabled',button==0);
});
}
function openVMAction(cmd,title,plg,func,start=0,button=0) {
// start = 0 : run command only when not already running (default)
// start = 1 : run command unconditionally
@@ -372,6 +388,7 @@ function openVMAction(cmd,title,plg,func,start=0,button=0) {
$('button.confirm').prop('disabled',button==0);
});
}
function abortOperation(pid) {
swal({title:"<?=_('Abort background operation')?>",text:"<?=_('This may leave an unknown state')?>",html:true,animation:'none',type:'warning',showCancelButton:true,confirmButtonText:"<?=_('Proceed')?>",cancelButtonText:"<?=_('Cancel')?>"},function(){
$.post('/webGui/include/StartCommand.php',{kill:pid},function() {
@@ -385,6 +402,7 @@ function abortOperation(pid) {
});
});
}
function openChanges(cmd,title,nchan,button=0) {
$('div.spinner.fixed').show();
// button = 0 : hide CLOSE button (default)
@@ -401,6 +419,7 @@ function openChanges(cmd,title,nchan,button=0) {
$('button.confirm').text("<?=_('Done')?>").prop('disabled',false).show();
});
}
function openAlert(cmd,title,func) {
$.post('/webGui/include/StartCommand.php',{cmd:cmd,start:2},function(data) {
$('div.spinner.fixed').hide();
@@ -411,6 +430,7 @@ function openAlert(cmd,title,func) {
$('pre#swalbody').html(data);
});
}
function openDone(data) {
if (data == '_DONE_') {
$('div.spinner.fixed').hide();
@@ -425,6 +445,7 @@ function openDone(data) {
}
return false;
}
function openError(data) {
if (data == '_ERROR_') {
$('div.spinner.fixed').hide();
@@ -433,16 +454,20 @@ function openError(data) {
}
return false;
}
function showStatus(name,plugin,job) {
$.post('/webGui/include/ProcessStatus.php',{name:name,plugin:plugin,job:job},function(status){$(".tabs").append(status);});
}
function showFooter(data, id) {
if (id !== undefined) $('#'+id).remove();
$('#copyright').prepend(data);
}
function showNotice(data) {
$('#user-notice').html(data.replace(/<a>(.*)<\/a>/,"<a href='/Plugins'>$1</a>"));
}
function escapeQuotes(form) {
$(form).find('input[type=text]').each(function(){$(this).val($(this).val().replace(/"/g,'\\"'));});
}
@@ -520,12 +545,14 @@ function removeRebootNotice(message="<?=_('You must reboot for changes to take e
function showUpgradeChanges() { /** @note can likely be removed, not used in webgui or api repos */
openChanges("showchanges /tmp/plugins/unRAIDServer.txt","<?=_('Release Notes')?>");
}
function showUpgrade(text,noDismiss=false) { /** @note can likely be removed, not used in webgui or api repos */
if ($.cookie('os_upgrade')==null) {
if (osUpgradeWarning) removeBannerWarning(osUpgradeWarning);
osUpgradeWarning = addBannerWarning(text.replace(/<a>(.+?)<\/a>/,"<a href='#' onclick='openUpgrade()'>$1</a>").replace(/<b>(.*)<\/b>/,"<a href='#' onclick='document.rebootNow.submit()'>$1</a>"),false,noDismiss);
}
}
function hideUpgrade(set) { /** @note can likely be removed, not used in webgui or api repos */
removeBannerWarning(osUpgradeWarning);
if (set)
@@ -533,6 +560,7 @@ function hideUpgrade(set) { /** @note can likely be removed, not used in webgui
else
$.removeCookie('os_upgrade');
}
function confirmUpgrade(confirm) {
if (confirm) {
swal({title:"<?=_('Update')?> Unraid OS",text:"<?=_('Do you want to update to the new version')?>?",type:'warning',html:true,animation:'none',showCancelButton:true,closeOnConfirm:false,confirmButtonText:"<?=_('Proceed')?>",cancelButtonText:"<?=_('Cancel')?>"},function(){
@@ -542,6 +570,7 @@ function confirmUpgrade(confirm) {
openPlugin("plugin update unRAIDServer.plg","<?=_('Update')?> Unraid OS");
}
}
function openUpgrade() {
hideUpgrade();
$.get('/plugins/dynamix.plugin.manager/include/ShowPlugins.php',{cmd:'alert'},function(data) {
@@ -554,11 +583,13 @@ function openUpgrade() {
}
});
}
function digits(number) {
if (number < 10) return 'one';
if (number < 100) return 'two';
return 'three';
}
function openNotifier() {
$.post('/webGui/include/Notify.php',{cmd:'get',csrf_token:csrf_token},function(msg) {
$.each($.parseJSON(msg), function(i, notify){
@@ -575,6 +606,7 @@ function openNotifier() {
});
});
}
function closeNotifier() {
$.post('/webGui/include/Notify.php',{cmd:'get',csrf_token:csrf_token},function(msg) {
$.each($.parseJSON(msg), function(i, notify){
@@ -583,14 +615,17 @@ function closeNotifier() {
$('div.jGrowl').find('div.jGrowl-close').trigger('click');
});
}
function viewHistory() {
location.replace('/Tools/NotificationsArchive');
}
function flashReport() {
$.post('/webGui/include/Report.php',{cmd:'config'},function(check){
if (check>0) addBannerWarning("<?=_('Your flash drive is corrupted or offline').'. '._('Post your diagnostics in the forum for help').'.'?> <a target='_blank' href='https://docs.unraid.net/go/changing-the-flash-device/'><?=_('See also here')?></a>");
});
}
$(function() {
let tab;
<?switch ($myPage['name']):?>
@@ -723,7 +758,8 @@ unset($buttons,$button);
// Build page content
// Reload page every X minutes during extended viewing?
if (isset($myPage['Load']) && $myPage['Load']>0) echo "\n<script>timers.reload = setInterval(function(){if (nchanPaused === false)location.reload();},".($myPage['Load']*60000).");</script>\n";echo "<div class='tabs'>";
if (isset($myPage['Load']) && $myPage['Load'] > 0) echo "\n<script>timers.reload = setInterval(function(){if (nchanPaused === false)location.reload();},".($myPage['Load']*60000).");</script>\n";
echo "<div class='tabs'>";
$tab = 1;
$pages = [];
if (!empty($myPage['text'])) $pages[$myPage['name']] = $myPage;
@@ -867,7 +903,7 @@ function parseINI(msg) {
// unraid animated logo
var unraid_logo = '<?readfile("$docroot/webGui/images/animated-logo.svg")?>';
var defaultPage = new NchanSubscriber('/sub/session,var<?=$entity?",notify":""?>',{subscriber:'websocket'});
var defaultPage = new NchanSubscriber('/sub/session,var<?=$entity?",notify":""?>',{subscriber:'websocket', reconnectTimeout:5000});
defaultPage.on('message', function(msg,meta) {
switch (meta.id.channel()) {
case 0:
@@ -936,7 +972,7 @@ function wlanSettings() {
window.location = '/Settings/NetworkSettings';
}
var nchan_wlan0 = new NchanSubscriber('/sub/wlan0',{subscriber:'websocket'});
var nchan_wlan0 = new NchanSubscriber('/sub/wlan0',{subscriber:'websocket', reconnectTimeout:5000});
nchan_wlan0.on('message', function(msg) {
var wlan = JSON.parse(msg);
$('#wlan0').removeClass().addClass(wlan.color).attr('title',wlan.title);
@@ -944,7 +980,7 @@ nchan_wlan0.on('message', function(msg) {
nchan_wlan0.start();
<?endif;?>
var nchan_plugins = new NchanSubscriber('/sub/plugins',{subscriber:'websocket'});
var nchan_plugins = new NchanSubscriber('/sub/plugins',{subscriber:'websocket', reconnectTimeout:5000});
nchan_plugins.on('message', function(data) {
if (!data || openDone(data)) return;
var box = $('pre#swaltext');
@@ -957,7 +993,7 @@ nchan_plugins.on('message', function(data) {
box.html(text.join('<br>')).scrollTop(box[0].scrollHeight);
});
var nchan_docker = new NchanSubscriber('/sub/docker',{subscriber:'websocket'});
var nchan_docker = new NchanSubscriber('/sub/docker',{subscriber:'websocket', reconnectTimeout:5000});
nchan_docker.on('message', function(data) {
if (!data || openDone(data)) return;
var box = $('pre#swaltext');
@@ -1006,7 +1042,7 @@ nchan_docker.on('message', function(data) {
box.scrollTop(box[0].scrollHeight);
});
var nchan_vmaction = new NchanSubscriber('/sub/vmaction',{subscriber:'websocket'});
var nchan_vmaction = new NchanSubscriber('/sub/vmaction',{subscriber:'websocket', reconnectTimeout:5000});
nchan_vmaction.on('message', function(data) {
if (!data || openDone(data) || openError(data)) return;
var box = $('pre#swaltext');
@@ -1235,7 +1271,7 @@ $('body').on('click','a,.ca_href', function(e) {
}
}
});
// Start & stop live updates when window loses focus
var nchanPaused = false;
var blurTimer = false;
@@ -1257,7 +1293,7 @@ document.addEventListener("visibilitychange", (event) => {
<? if ( $display['liveUpdate'] == "no" ):?>
if (document.hidden) {
nchanFocusStop();
}
}
<?else:?>
if (document.hidden) {
nchanFocusStop();
@@ -1276,15 +1312,15 @@ function nchanFocusStart() {
if (nchanPaused !== false ) {
removeBannerWarning(nchanPaused);
nchanPaused = false;
try {
pageFocusFunction();
} catch(error) {}
subscribers.forEach(function(e) {
e.start();
});
}
}
}
function nchanFocusStop(banner=true) {
+10 -13
View File
@@ -85,18 +85,15 @@ case 'list':
$port = array_key_first($wifi);
$carrier = "/sys/class/net/$port/carrier";
$echo = [];
if ($load && count(array_keys($wifi)) > 1) {
foreach ($wifi as $network => $block) {
if ($network == $port) continue;
$wlan[$network][0] = $block['ATTR1'] ?? '';
$wlan[$network][2] = $block['ATTR2'] ?? '';
$wlan[$network][4] = $block['ATTR3'] ?? $block['SECURITY'] ?? '';
$wlan[$network][1] = $block['ATTR4'] ?? '';
$wlan[$network][3] = $network;
}
} else {
$wlan = scanWifi($port);
foreach ($wifi as $network => $block) {
if ($network == $port) continue;
$wlan[$network][0] = $block['ATTR1'] ?? '';
$wlan[$network][1] = $block['ATTR4'] ?? '';
$wlan[$network][2] = $block['ATTR2'] ?? '';
$wlan[$network][3] = $network;
$wlan[$network][4] = $block['ATTR3'] ?? $block['SECURITY'] ?? '';
}
if (!$load) $wlan = array_replace_recursive($wlan, scanWifi($port));
if (count($wlan)) {
try {
$up = @file_get_contents($carrier) == 1;
@@ -198,8 +195,8 @@ case 'join':
echo mk_option($safe, 'IEEE 802.1X/SHA-256', _('WPA3 Enterprise'));
echo "</select></td></tr>";
}
if ($ieee1 || $manual || $safe) echo "<tr id=\"username\" class=\"$hide0\"><td>"._('Username').":</td><td><input type=\"text\" name=\"USERNAME\" class=\"narrow\" autocomplete=\"off\" spellcheck=\"false\" value=\"$user\"></td></tr>";
if ($attr3 || $manual || $safe) echo "<tr id=\"password\" class=\"$hide1\"><td>"._('Password').":</td><td><input type=\"password\" name=\"PASSWORD\" class=\"narrow\" autocomplete=\"off\" spellcheck=\"false\" value=\"$passwd\"><i id=\"showPass\" class=\"fa fa-eye\" onclick=\"showPassword()\"></i></td></tr>";
if ($ieee1 || $manual || $safe) echo "<tr id=\"username\" class=\"$hide0\"><td>"._('Username').":</td><td><input type=\"text\" name=\"USERNAME\" class=\"narrow\" maxlength=\"63\" autocomplete=\"off\" spellcheck=\"false\" value=\"$user\"></td></tr>";
if ($attr3 || $manual || $safe) echo "<tr id=\"password\" class=\"$hide1\"><td>"._('Password').":</td><td><input type=\"password\" name=\"PASSWORD\" class=\"narrow\" maxlength=\"63\" autocomplete=\"off\" spellcheck=\"false\" value=\"$passwd\"><i id=\"showPass\" class=\"fa fa-eye\" onclick=\"showPassword()\"></i></td></tr>";
echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
echo "<tr><td>"._('IPv4 address assignment').":</td><td><select name=\"DHCP4\" onclick=\"showDHCP(this.value,4)\">";
echo mk_option($dhcp4, 'yes', _('Automatic'));
+1 -1
View File
@@ -38,7 +38,7 @@ if ($arg == 'yes') {
}
}
if (count($text)>2) {
exec("/etc/rc.d/rc.wireless stop");
if (file_exists($ini)) exec("/etc/rc.d/rc.wireless stop");
file_put_contents_atomic($ini,implode("\n",$text)."\n");
exec("/etc/rc.d/rc.wireless join &>/dev/null &");
exec("$docroot/webGui/scripts/update_services 20");
+17 -10
View File
@@ -149,6 +149,7 @@ build_servers(){
nchan_publisher;
nchan_channel_id "$1";
nchan_message_buffer_length $arg_buffer_length;
nchan_message_timeout 0;
}
location ~ /nchan_stub_status$ {
nchan_stub_status;
@@ -387,13 +388,11 @@ build_locations(){
#
location ~ /sub/(.*)$ {
nchan_subscriber;
nchan_subscriber_timeout 0;
# nchan_authorize_request <url here>
nchan_channel_id "$1";
nchan_channel_id_split_delimiter ",";
}
location /nchan_stub_status {
nchan_stub_status;
}
#
# my servers proxy
#
@@ -687,6 +686,7 @@ nginx_waitfor_shutdown(){
if ! nginx_running; then break; fi
sleep 1
done
return 0
}
nginx_check(){
@@ -712,6 +712,8 @@ nginx_start(){
[[ -x $NGINX ]] && $NGINX -c $CONF 2>/dev/null
# side-load unraid-api
unraid_api_control start
# resume nchan publishers
/usr/local/sbin/monitor_nchan start
if nginx_running; then REPLY="Started"; else REPLY="Failed"; fi
fi
rm -f /tmp/nginxStopped
@@ -725,15 +727,14 @@ nginx_stop(){
REPLY="Already stopped"
else
unraid_api_control stop
# pause nchan publishers
/usr/local/sbin/monitor_nchan stop
kill -QUIT $(cat $PID)
nginx_waitfor_shutdown
if ! nginx_running; then
REPLY="Stopped"
else
pkill -f $NGINX
nginx_waitfor_shutdown
if ! nginx_running; then REPLY="Killed"; else REPLY="Failed"; fi
fi
# safety hammer
pkill -f $NGINX
nginx_waitfor_shutdown
if ! nginx_running; then REPLY="Stopped"; else REPLY="Failed"; fi
fi
log "$DAEMON... $REPLY."
}
@@ -745,6 +746,8 @@ nginx_stop_forced(){
REPLY="Already stopped"
else
unraid_api_control stop
# stop nchan publishers
/usr/local/sbin/monitor_nchan stop remove
kill -TERM $(cat $PID)
nginx_waitfor_shutdown
if ! nginx_running; then REPLY="Stopped"; else REPLY="Failed"; fi
@@ -775,6 +778,8 @@ nginx_reload(){
build_ssl
if nginx_check; then
log "Reloading $DAEMON configuration..."
# pause nchan publishers
/usr/local/sbin/monitor_nchan stop
kill -HUP $(cat $PID)
sleep 1
if tail -10 $SYSLOG | grep -qm1 'Address already in use'; then
@@ -783,6 +788,8 @@ nginx_reload(){
log "Restarting $DAEMON..."
nginx_renew
fi
# resume nchan publishers
/usr/local/sbin/monitor_nchan start
else
log "Invalid configuration, $DAEMON not reloaded"
return 1
+10 -2
View File
@@ -176,6 +176,12 @@ wifi_start(){
[[ -e $SYSTEM/$LINK ]] || run ip link add link $PORT name $LINK type ipvtap mode l2 bridge
run ip link set $PORT up
run ip link set $LINK up
# set regulatory region (if set) upon start
REGION=$(grep -Pom1 '^REGION="\K[^"]+' $CFG)
REGION_XX=$(grep -Pom1 '^REGION_XX="\K[^"]+' $CFG)
[[ $REGION == '00' ]] && CC=$REGION_XX || CC=$REGION
[[ -n $CC ]] && run iw reg set $CC
# initialise openssl encryption parameters
$OPENSSL load
# start active SSID
$STARTWIFI
@@ -282,8 +288,10 @@ wifi_join(){
echo 1 >$CONF6/$PORT/disable_ipv6
fi
if wifi_running; then
CC=($(iw reg get | grep -Po '^country \K..'))
[[ ${CC[0]} != ${CC[1]} ]] && iw reg set ${CC[1]}
if [[ -z $CC ]]; then
CC=($(iw reg get | grep -Po '^country \K..'))
[[ ${CC[0]} != ${CC[1]} ]] && iw reg set ${CC[1]}
fi
REPLY="Joined"
else
REPLY="Failed"
+32 -24
View File
@@ -4,27 +4,38 @@ nchan_pid=/var/run/nchan.pid # keeps list of nchan proce
disk_load=/var/local/emhttp/diskload.ini # disk load statistics
nginx=/var/run/nginx.socket # nginx local access
status=http://localhost/pub/session?buffer_length=1 # nchan information about GUI subscribers
nchan_list=/tmp/nchan_list.tmp
nchan_id=$(basename "$0")
# immediate kill command
if [[ $1 == kill ]]; then
[[ -s $nchan_pid ]] || exit
echo "Killing nchan processes..."
while IFS=$'\n' read -r running; do
name="${running##*/}"
# kill all processes or single process
if [[ -z $2 || $2 == ${name/:stop/} ]]; then
echo "$name"
pkill -f "$docroot/${running/:stop/}"
nchan_stop() {
echo -n >$nchan_list
while IFS=$'\n' read -r nchan; do
[[ ${nchan##*/} == '.*' ]] && continue
echo $nchan >>$nchan_list
pkill -f $nchan
done <<< $(ps -eo cmd | grep -Po '/usr/local/emhttp/.*/nchan/.*')
}
nchan_start() {
[[ -e $nchan_list ]] || return
while IFS=$'\n' read -r nchan; do
if ! pgrep -f $nchan >/dev/null; then
$nchan &>/dev/null &
fi
done < $nchan_pid
if [[ -z $2 ]]; then
# remove pid file
rm -f $nchan_pid $disk_load
else
# remove single entry
sed -i "/$2/d" $nchan_pid
fi
done < $nchan_list
rm -f $nchan_list
}
if [[ $1 == stop ]]; then
echo "Stopping nchan processes..."
nchan_stop
[[ $2 == remove ]] && rm -f $nchan_pid $disk_load
exit
fi
if [[ $1 == start ]]; then
echo "Starting nchan processes..."
nchan_start
exit
fi
@@ -33,11 +44,11 @@ while :; do
# only act when GUI registered nchan processes are running
if [[ -s $nchan_pid ]]; then
# get number of GUI nchan subscribers
subs=$(curl --unix-socket $nginx $status 2>/dev/null|grep -Pom1 'subscribers: \K\d+')
subs=$(curl --unix-socket $nginx $status 2>/dev/null | grep -Pom1 'subscribers: \K\d+')
if [[ -z $subs || $subs -eq 0 ]]; then
sleep 5
# steady state?
subs=$(curl --unix-socket $nginx $status 2>/dev/null|grep -Pom1 'subscribers: \K\d+')
subs=$(curl --unix-socket $nginx $status 2>/dev/null | grep -Pom1 'subscribers: \K\d+')
if [[ -z $subs || $subs -eq 0 ]]; then
now=$(date +%s)
# log at 1 hour interval
@@ -45,10 +56,7 @@ while :; do
logger -t $nchan_id -- "Stop running nchan processes"
start=$now
fi
# kill GUI registered nchan processes
while IFS=$'\n' read -r running; do
pkill -f $docroot/${running/:stop/}
done < $nchan_pid
nchan_stop
# empty GUI registered list & statistics
rm -f $nchan_pid $disk_load
fi