diff --git a/emhttp/plugins/dynamix/ArrayOperation.page b/emhttp/plugins/dynamix/ArrayOperation.page index 9dcb4f02f..2e20fb0ab 100644 --- a/emhttp/plugins/dynamix/ArrayOperation.page +++ b/emhttp/plugins/dynamix/ArrayOperation.page @@ -307,18 +307,12 @@ var devices = new NchanSubscriber('/sub/devices',{subscri devices.on('message', function(msg,meta) { switch (meta.id.channel()0) { case 0: - // array + pool + ua devices - var tables = msg.split('\0'); - // get array state - var stopped = tables.pop(); - for (var n=0; n < tables.length; n++) { - // get table name and content - var table = tables[n].split('\n'); - $('#'+table[0]).html(table[1]); - } + // array + pool + ua + flash devices + var get = JSON.parse(msg); + for (var name in get) $('#'+name).html(get[name]); display_diskio(); // stop updating when array is stopped - if (stopped==1) { + if (get.stop==1) { $('thead tr').removeClass().addClass('offline'); setTimeout(refresh); diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index c99e5da91..7c8a485c1 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -677,7 +677,7 @@ function hideShow() { _(Overwrite)_: _(Start Cloned VM)_: _(Edit VM after clone)_: -_(Check Free Space)_: +_(Check free space)_: @@ -1478,9 +1478,9 @@ var dashboard = new NchanSubscriber('/sub/cpuload,update1,update2,update3,)}); - $('.var'+k).text(v[1]); - if (k == 0) { - var color = setColor(load,,); - $('.sys0_').text(v[0]); - $('#sys0_').alive(v[0],color); - var start = 0; - var end = parseInt(v[4]); - var ring = [colors[0]+' '+start+'% '+end+'%'] - // create individual elements of the graph - for (var i=6; i < v.length; i=i+2) { - start = end; - end += parseInt(v[i]); - ring.push((colors[(i-2)/2]||blue)+' '+start+'% '+end+'%'); - } - ring.push(colors[1]+' '+v[0]+' 100%'); - $('#sys0').css({'background':'conic-gradient('+ring.join(',')+')'}); - var dynamic = v[v.length-1].split('\n'); - v[v.length-1] = dynamic[0]; - var names = (dynamic[1]||'').split('\r'); - // dynamic info from hook scripts - var html = []; - for (var i=0,name; name=names[i]; i++) if (i!=1) html.push(""+name+": "+(i==0?v[5]:v[i*2+3])); - html.push(""+names[1]+": "+v[3]); - $('#dynamic').html(html.join('
')); - } else { - $('#sys'+k).css({'background':'conic-gradient('+colors[0]+' 0% '+v[0]+','+colors[1]+' '+v[0]+' 100%)'}); - } - }); + var load = get.ram[0].slice(0,-1); + $('.sys0').text(get.ram[0]).css({'color':fontColor(load,,)}); + $('.var0').text(get.ram[1]); + var color = setColor(load,,); + $('.sys0_').text(get.ram[0]); + $('#sys0_').alive(get.ram[0],color); + var start = 0; + var end = parseInt(get.ram[4]); + var ring = [colors[0]+' '+start+'% '+end+'%'] + // create individual elements of the RAM graph + for (var i=6; i < get.ram.length; i=i+2) { + start = end; + end += parseInt(get.ram[i]); + ring.push((colors[(i-2)/2]||blue)+' '+start+'% '+end+'%'); + } + ring.push(colors[1]+' '+get.ram[0]+' 100%'); + $('#sys0').css({'background':'conic-gradient('+ring.join(',')+')'}); + // dynamic info from hook scripts + var html = []; + for (var i=0,name; name=get.name[i]; i++) if (i!=1) html.push(""+name+": "+(i==0?get.ram[5]:get.ram[i*2+3])); + html.push(""+get.name[1]+": "+get.ram[3]); + $('#dynamic').html(html.join('
')); + // flash, Log & Docker graphs + for (var k=1,sys; sys=get.sys[k-1]; k++) { + var load = sys[0].slice(0,-1); + $('.sys'+k).text(sys[0]).css({'color':fontColor(load,,)}); + $('.var'+k).text(sys[1]); + $('#sys'+k).css({'background':'conic-gradient('+colors[0]+' 0% '+sys[0]+','+colors[1]+' '+sys[0]+' 100%)'}); + } // fans rpm - $.each(part[1].split('\0'),function(k,v) {$('#fan'+k).html(v);}); + for (var k=0,fan; fan=get.fan[k]; k++) $('#fan'+k).html(fan); // stream counters (smb only) var tag = $('.smb').is(':visible') ? 'smb' : $('.nfs').is(':visible') ? 'nfs' : ''; - if (tag == 'smb') $.each(part[2].split('\0'),function(k,v) {$('#share'+(k+1)).html(v);}); + if (tag=='smb') for (var k=1,stream; stream=get.stream[k-1]; k++) $('#share'+k).html(stream); break; case 2: if (!update2) break; - var part = msg.split('\1'); - var data = part[0].split('\0'); + var get = JSON.parse(msg); + var data = get.disk.split('\n'); var info = moreInfo(data,"_(Array)_"); // array devices $('#array_list tr.updated').remove(); @@ -1550,19 +1547,18 @@ dashboard.on('message',function(msg,meta) { $('#array_info').html(info); smartMenu('#array_list'); // pool devices - var text = part[1].split('\r'); - for (var i=0,t; t=text[i]; i++) { - var data = t.split('\0'); + for (var i=0,pool; pool=get.pool[i]; i++) { + var data = pool.split('\n'); var info = moreInfo(data,"_(Pool)_"); $('#pool_list'+i+' tr.updated').remove(); - $('#pool_list'+i).append(t).hideMe(); + $('#pool_list'+i).append(pool).hideMe(); $('#pool_info'+i).parent().css({'display':info?'':'none'}); $('#pool_info'+i).html(info); smartMenu('#pool_list'+i); } // unassigned devices - var data = part[2].split('\0'); + var data = get.open.split('\n'); var info = moreInfo(data,"_(Unassigned)_"); $('#devs_list tr.updated').remove(); $('#devs_list').append(data[0]).hideMe(); @@ -1571,44 +1567,40 @@ dashboard.on('message',function(msg,meta) { smartMenu('#devs_list'); // parity status - $('span.parity').html(part[3]); + $('span.parity').html(get.parity); // parity schedule - var data = part[4].split('\0'); + var data = get.schedule.split('\n'); $('#parity').html(data[0]); $('#program').html(data[1]); break; case 3: - var part = msg.split('\1'); - var ports = part[0].split('\n'); + var get = JSON.parse(msg); // rx & tx speeds - for (var i=0,port; port=ports[i]; i++) { - var data = port.split('\0'); - if (data[0] == port_select) { - $('#inbound').text(data[1]); - $('#outbound').text(data[2]); - addChartNet(data[3], data[4]); + for (var i=0,port; port=get.port[i]; i++) { + if (port[0] == port_select) { + $('#inbound').text(port[1]); + $('#outbound').text(port[2]); + addChartNet(port[3], port[4]); netchart.updateSeries([{data:rxd},{data:txd}]); break; } } // port counters - $.each(part[1].split('\0'),function(k,v) {$('#main'+k).html(v);}); - $.each(part[2].split('\0'),function(k,v) {$('#port'+k).html(v);}); - $.each(part[3].split('\0'),function(k,v) {$('#link'+k).html(v);}); + for (let k=0; k < get.mode.length; k++) $('#main'+k).html(get.mode[k]); + for (let k=0; k < get.rxtx.length; k++) $('#port'+k).html(get.rxtx[k]); + for (let k=0; k < get.stat.length; k++) $('#link'+k).html(get.stat[k]); // current date and time - var timedate = part[4].split('\n'); - $('#current_time').html(timedate[0]); - $('#current_time_').html(timedate[0]); - $('#current_date').html(timedate[1]); + $('#current_time').html(get.time[0]); + $('#current_time_').html(get.time[0]); + $('#current_date').html(get.time[1]); break; case 4: // wireguard tunnels + var get = JSON.parse(msg); var n = {}; - var rows = msg.split('\0'); - for (var i=0,row; row=rows[i]; i++) { - var info = row.split(';'); + for (var i=0,info; info=get[i]; i++) { var vtun = info[0]; - if (typeof n[vtun]=='undefined') n[vtun] = 0; else n[vtun]++; + if (typeof n[vtun]=='undefined') n[vtun]=0; else n[vtun]++; if (info[1] == 0) { $('span#'+vtun+'-hs-'+n[vtun]).text("_(not received)_"); } else if (info[1] > 86400) { diff --git a/emhttp/plugins/dynamix/nchan/device_list b/emhttp/plugins/dynamix/nchan/device_list index f31a081fe..6b8e15444 100755 --- a/emhttp/plugins/dynamix/nchan/device_list +++ b/emhttp/plugins/dynamix/nchan/device_list @@ -426,38 +426,42 @@ while (true) { $Flash = &$Flash['flash']; $pools = array_unique(array_map('prefix',array_keys($Cache))); - $echo[0] = "array_devices\n"; + $a = 'array_devices'; + $echo[$a] = []; if (_var($var,'fsState')=='Stopped') { - foreach ($Parity as $disk) $echo[0] .= array_offline($disk); - $echo[0] .= ""; - foreach ($Data as $disk) $echo[0] .= array_offline($disk); - $echo[0] .= ""._('Slots').":".array_slots().""; + foreach ($Parity as $disk) $echo[$a][] = array_offline($disk); + $echo[$a][] = ""; + foreach ($Data as $disk) $echo[$a][] = array_offline($disk); + $echo[$a][] = ""._('Slots').":".array_slots().""; } else { - foreach ($Parity as $disk) if ($disk['status']!='DISK_NP_DSBL') $echo[0] .= array_online($disk); - foreach ($Data as $disk) $echo[0] .= array_online($disk); - if (_var($display,'total') && _var($var,'mdNumDisks',0)>1) $echo[0] .= show_totals(sprintf(_('Array of %s devices'),my_word($var['mdNumDisks'])),true,'disk*'); + foreach ($Parity as $disk) if ($disk['status']!='DISK_NP_DSBL') $echo[$a][] = array_online($disk); + foreach ($Data as $disk) $echo[$a][] = array_online($disk); + if (_var($display,'total') && _var($var,'mdNumDisks',0)>1) $echo[$a][] = show_totals(sprintf(_('Array of %s devices'),my_word($var['mdNumDisks'])),true,'disk*'); } + $echo[$a] = implode($echo[$a]); - $echo[1] = "boot_device\n"; + $a = 'boot_device'; + $echo[$a] = []; $data = explode(' ',$diskio[_var($Flash,'device')] ?? '0 0'); $flash = &$sec['flash']; $share = (_var($var,'shareSMBEnabled')=='yes' && _var($flash,'export')=='e' && _var($flash,'security')=='public') ? " "._('Flash device is set as public share')."
"._('Please change share SMB security')."
"._('Click on **FLASH** above this message')."
" : ""; - $echo[1] .= ""; - $echo[1] .= "".device_info($Flash,true).$share.""; - $echo[1] .= "".device_desc($Flash).""; - $echo[1] .= "*"; - $echo[1] .= "".my_diskio($data[0])."".my_number(_var($Flash,'numReads',0)).""; - $echo[1] .= "".my_diskio($data[1])."".my_number(_var($Flash,'numWrites',0)).""; - $echo[1] .= "".my_number(_var($Flash,'numErrors',0)).""; - $echo[1] .= fs_info($Flash); - $echo[1] .= ""; + $echo[$a][] = ""; + $echo[$a][] = "".device_info($Flash,true).$share.""; + $echo[$a][] = "".device_desc($Flash).""; + $echo[$a][] = "*"; + $echo[$a][] = "".my_diskio($data[0])."".my_number(_var($Flash,'numReads',0)).""; + $echo[$a][] = "".my_diskio($data[1])."".my_number(_var($Flash,'numWrites',0)).""; + $echo[$a][] = "".my_number(_var($Flash,'numErrors',0)).""; + $echo[$a][] = fs_info($Flash); + $echo[$a][] = ""; + $echo[$a] = implode($echo[$a]); - $sum = initSum(); - $n = 2; + $sum = initSum(); $i = 0; foreach ($pools as $pool) { - $echo[$n] = "pool_device".($n-2)."\n"; + $a = 'pool_device'.$i++; + $echo[$a] = []; $root = explode($_tilde_,$pool)[0]; $print = array_filter(array_column($Cache,'name'),function($name) use ($pools,$root) {return in_array($name,$pools) && strncmp($root,$name,strlen($root))==0;}); $print = end($print); @@ -465,7 +469,7 @@ while (true) { $log = @parse_ini_file($pool_log) ?: []; $off = false; foreach ($Cache as $disk) if (prefix(_var($disk,'name'))==$pool) { - $echo[$n] .= array_offline($disk,$pool); + $echo[$a][] = array_offline($disk,$pool); $name = _var($disk,'name'); // tilde is not allowed in array key - replace it $named = no_tilde($name); @@ -474,56 +478,58 @@ while (true) { $data = []; foreach ($log as $key => $value) $data[] = "$key=\"$value\""; $off &= !empty(_var($Cache[$pool],'uuid')); file_put_contents($pool_log,implode("\n",$data)); - $echo[$n] .= ""._('Slots').":".cache_slots($off,$pool,_var($Cache[$pool],'devicesSb'),_var($Cache[$pool],'slots',0)).""; + $echo[$a][] = ""._('Slots').":".cache_slots($off,$pool,_var($Cache[$pool],'devicesSb'),_var($Cache[$pool],'slots',0)).""; $zfsPool = strstr(_var($Cache[$pool],'fsType'),'zfs') && !isSubpool($pool); if ($zfsPool) { $current_subpools = array_filter($pools, function($element) use ($pool,$_tilde_) {return str_contains($element,"{$pool}{$_tilde_}");}); $current_subpools_list = str_replace("{$pool}{$_tilde_}","", implode(',', $current_subpools)); - $echo[$n] .= ""; + $echo[$a][] = ""; } - $echo[$n] .= ""; + $echo[$a][] = ""; } else { foreach ($Cache as $disk) if (prefix($disk['name'])==$pool) { $fstype = str_replace('luks:','',_var($disk,'fsType')); if (substr(_var($Cache[$pool],'fsStatus'),0,11)=='Unmountable' && empty($disk['fsStatus'])) $disk['fsStatus'] = _var($Cache[$pool],'fsStatus'); - $echo[$n] .= array_online($disk,$fstype); + $echo[$a][] = array_online($disk,$fstype); } if (strcmp($root,$pool)!=0) $Cache[$root]['devices'] += $Cache[$pool]['devices']; if (strcmp($pool,$print)==0) { delete_file($pool_log); - if (_var($display,'total') && _var($Cache[$root],'devices',0)>1) $echo[$n] .= show_totals(sprintf(_('Pool of %s devices'),my_word($Cache[$root]['devices'])),str_contains($pool,$_tilde_),"$root*"); + if (_var($display,'total') && _var($Cache[$root],'devices',0)>1) $echo[$a][] = show_totals(sprintf(_('Pool of %s devices'),my_word($Cache[$root]['devices'])),str_contains($pool,$_tilde_),"$root*"); $sum = initSum(); } - } - $n++; + } + $echo[$a] = implode($echo[$a]); } - $echo[$n] = "open_devices\n"; + $a = 'open_devices'; + $echo[$a] = []; foreach ($devs as $disk) { $dev = _var($disk,'device'); $data = explode(' ',$diskio[$dev] ?? '0 0 0 0'); $disk['type'] = 'New'; $disk['color'] = $disk['spundown']=="0" ? 'blue-on' : 'blue-blink'; - $echo[$n] .= ""; - $echo[$n] .= "".device_info($disk,true).""; - $echo[$n] .= "".device_desc($disk).""; - $echo[$n] .= "".my_temp($disk['temp']).""; - $echo[$n] .= "".my_diskio($data[0])."".my_number(_var($disk,'numReads',0)).""; - $echo[$n] .= "".my_diskio($data[1])."".my_number(_var($disk,'numWrites',0)).""; - $echo[$n] .= "".my_number(_var($disk,'numErrors',0)).""; + $echo[$a][] = ""; + $echo[$a][] = "".device_info($disk,true).""; + $echo[$a][] = "".device_desc($disk).""; + $echo[$a][] = "".my_temp($disk['temp']).""; + $echo[$a][] = "".my_diskio($data[0])."".my_number(_var($disk,'numReads',0)).""; + $echo[$a][] = "".my_diskio($data[1])."".my_number(_var($disk,'numWrites',0)).""; + $echo[$a][] = "".my_number(_var($disk,'numErrors',0)).""; if (file_exists("/tmp/preclear_stat_$dev")) { $text = exec("cut -d'|' -f3 /tmp/preclear_stat_$dev|sed 's:\^n:\:g'"); if (!str_contains($text,'Total time')) $text = _('Preclear in progress').'... '.$text; - $echo[$n] .= "$text"; - } else - $echo[$n] .= ""; - $echo[$n] .= ""; + $echo[$a][] = "$text"; + } else { + $echo[$a][] = ""; + } + $echo[$a][] = ""; } + $echo[$a] = implode($echo[$a]); - $n++; - $echo[$n] = _var($var,'fsState')=='Stopped' ? 1 : 0; + $echo['stop'] = _var($var,'fsState')=='Stopped' ? 1 : 0; - $echo = implode("\0",$echo); + $echo = json_encode($echo); $md5_new = md5($echo,true); if ($md5_new !== $md5_old) { publish('devices', $echo); diff --git a/emhttp/plugins/dynamix/nchan/update_1 b/emhttp/plugins/dynamix/nchan/update_1 index 6e1f84271..859d87715 100755 --- a/emhttp/plugins/dynamix/nchan/update_1 +++ b/emhttp/plugins/dynamix/nchan/update_1 @@ -59,38 +59,45 @@ while (true) { exec("sensors -uA 2>/dev/null|grep -Po 'fan\d_input: \K\d+'",$fans); [$total,$free] = $memory; $used = $total-$free; - $names = [_('Services'), _('Free')]; - $bytes = $meminfo = $sysinfo = []; + $names = [_('Services'),_('Free')]; + $bytes = $echo = []; $hooks = array_filter(glob("/usr/local/emhttp/plugins/*/system/*",GLOB_NOSORT),function($file){return is_executable($file);}); foreach ($hooks as $hook) { $data = @intval(exec(escapeshellarg($hook))); if (!$data || $data>$used) continue; - $names[] = _(str_replace('_',' ',basename($hook))); // name of element (with translation) - $bytes[] = $data; // value in bytes of element + $names[] = _(str_replace('_',' ',basename($hook))); // name of element + $bytes[] = $data; // value in bytes } + // parse RAM graph + $a = 'ram'; $services = $used-array_sum($bytes); - $meminfo[] = round(100*$used/$total)."%"; - $meminfo[] = my_scale($used,$unit,null,-1,1024)." $unit"; - $meminfo[] = round(100*$free/$total); - $meminfo[] = my_scale($free,$unit,null,-1,1024)." $unit"; - $meminfo[] = round(100*$services/$total); - $meminfo[] = my_scale($services,$unit,null,-1,1024)." $unit"; + $echo[$a][] = round(100*$used/$total)."%"; + $echo[$a][] = my_scale($used,$unit,null,-1,1024)." $unit"; + $echo[$a][] = round(100*$free/$total); + $echo[$a][] = my_scale($free,$unit,null,-1,1024)." $unit"; + $echo[$a][] = round(100*$services/$total); + $echo[$a][] = my_scale($services,$unit,null,-1,1024)." $unit"; foreach ($bytes as $byte) { // parse hook script information for RAM usage graph - $meminfo[] = round(100*$byte/$total); - $meminfo[] = my_scale($byte,$unit,null,-1,1024)." $unit"; + $echo[$a][] = round(100*$byte/$total); + $echo[$a][] = my_scale($byte,$unit,null,-1,1024)." $unit"; } + // add element names + $echo['name'] = $names; // parse the graphs for flash, log & docker foreach ($df as $data) { [$pcent,$used] = explode(' ',$data); - $sysinfo[] = $pcent.';'.my_scale($used,$unit,null,-1,1024)." $unit"; + $echo['sys'][] = [$pcent,my_scale($used,$unit,null,-1,1024)." $unit"]; } + // add fans information + if (count($fans)) $echo['fan'] = array_map(function($fan){return "$fan RPM";},$fans); + // add streams information $name = array_keys((array)parse_ini_file("$varroot/shares.ini")); - // get number of open files (smb) exec("LANG='en_US.UTF8' lsof -Owl /mnt/disk[0-9]* 2>/dev/null|awk '/^shfs/ && \$0!~/\.AppleD(B|ouble)/ && \$5==\"REG\"'|awk -F/ '{print \$4}'",$lsof); - $counts = array_count_values($lsof); $count = []; - foreach ($name as $share) $count[] = $counts[$share] ?? 0; - $echo = implode(";",$meminfo)."\n".implode("\r",$names)."\0".implode("\0",$sysinfo)."\1".(count($fans)?implode(" RPM\0",$fans).' RPM':'')."\1".implode("\0",$count); + $counts = array_count_values($lsof); + foreach ($name as $share) $echo['stream'][] = $counts[$share] ?? 0; + + $echo = json_encode($echo); $md5_new = md5($echo,true); if ($md5_new !== $md5_old) { publish('update1', $echo); diff --git a/emhttp/plugins/dynamix/nchan/update_2 b/emhttp/plugins/dynamix/nchan/update_2 index ccb68565f..5f757913e 100755 --- a/emhttp/plugins/dynamix/nchan/update_2 +++ b/emhttp/plugins/dynamix/nchan/update_2 @@ -231,7 +231,7 @@ function device_usage(&$disk, &$full, &$high) { else return $text%10==0 ? "-" : "-
"; } -function array_group($type,$pool=false) { +function array_group($type, $pool=false) { global $disks,$error,$warning,$red,$orange,$fail,$smart,$full,$high; $echo = []; foreach ($disks as $disk) if (_var($disk,'type')==$type && strpos(_var($disk,'status'),'DISK_NP')===false && (!$pool||$pool==prefix(_var($disk,'name')))) { @@ -243,7 +243,7 @@ function array_group($type,$pool=false) { $echo[] = "".device_usage($disk,$full,$high).""; $echo[] = ""; } - return implode('',$echo); + return implode($echo); } function extra_group() { global $devs,$error,$warning,$red,$orange,$fail,$smart,$full,$high; @@ -260,7 +260,7 @@ function extra_group() { $echo[] = "".device_usage($disk,$full,$high).""; $echo[] = ""; } - return implode('',$echo); + return implode($echo); } function update_translation($locale) { global $docroot,$language; @@ -304,25 +304,36 @@ while (true) { update_translation($locale_init); } //array devices + $a = 'disk'; + $echo[$a] = []; $error = $warning = $red = $orange = $fail = $smart = $full = $high = 0; - $echo[0] = array_group('Parity'); - $echo[0] .= array_group('Data'); - $echo[0] .= "\0".($error+$warning)."\0".($red+$orange)."\0".($fail+$smart)."\0".($full+$high); + $echo[$a][] = array_group('Parity'); + $echo[$a][] = array_group('Data'); + $echo[$a][] = "\n".($error+$warning)."\n".($red+$orange)."\n".($fail+$smart)."\n".($full+$high); + $echo[$a] = implode($echo[$a]); + //pool devices - $echo[1] = ''; + $a = 'pool'; $p = 0; + $echo[$a] = []; foreach (pools_filter($disks) as $pool) { if (empty($disks[$pool]['devices'])) continue; $error = $warning = $red = $orange = $fail = $smart = $full = $high = 0; - $echo[1] .= array_group('Cache',$pool); - $echo[1] .= "\0".($error+$warning)."\0".($red+$orange)."\0".($fail+$smart)."\0".($full+$high)."\r"; + $echo[$a][$p] = []; + $echo[$a][$p][] = array_group('Cache',$pool); + $echo[$a][$p][] = "\n".($error+$warning)."\n".($red+$orange)."\n".($fail+$smart)."\n".($full+$high); + $echo[$a][$p] = implode($echo[$a][$p]); + $p++; } //unassigned devices + $a = 'open'; + $echo[$a] = []; $error = $warning = $red = $orange = $fail = $smart = $full = $high = 0; - $echo[2] = extra_group(); - $echo[2] .= "\0".($error+$warning)."\0".($red+$orange)."\0".($fail+$smart)."\0".($full+$high); + $echo[$a][] = extra_group(); + $echo[$a][] = "\n".($error+$warning)."\n".($red+$orange)."\n".($fail+$smart)."\n".($full+$high); + $echo[$a] = implode($echo[$a]); // parity status - $echo[3] = ''; + $a = 'parity'; $disks = parity_filter($disks); $parity_slots = count($disks); $parity_disabled = $parity_invalid = 0; @@ -339,68 +350,69 @@ while (true) { case "clear": $mode = 'Disk-Clear'; break; default : $mode = ''; break; } - $echo[3] .= ""._($mode).' '._('in progress').'... '._('Completed').': '.number_format($spot/($size/100+1),1,$number[0],$number[1])." %."; + $echo[$a] = ""._($mode).' '._('in progress').'... '._('Completed').': '.number_format($spot/($size/100+1),1,$number[0],$number[1])." %."; } else { if ($parity_slots==$parity_disabled) { - $echo[3] .= ""._('Parity disk'.($parity_slots==1?'':'s')." not present").""; + $echo[$a] = ""._('Parity disk'.($parity_slots==1?'':'s')." not present").""; } elseif ($parity_slots > $parity_invalid) { if ($parity_invalid==0) { - $echo[3] .= ""._('Parity is valid').""; + $echo[$a] = ""._('Parity is valid').""; } else { - $echo[3] .= ""._('Parity is degraded').": $parity_invalid "._('invalid device'.($parity_invalid==1?'':'s')).""; + $echo[$a] = ""._('Parity is degraded').": $parity_invalid "._('invalid device'.($parity_invalid==1?'':'s')).""; } } else { if (empty($var['mdInvalidDisk'])) { - $echo[3] .= ""._('Parity is invalid').""; + $echo[$a] = ""._('Parity is invalid').""; } else { - $echo[3] .= ""._('Data is invalid').""; + $echo[$a] = ""._('Data is invalid').""; } } } // parity schedule + $a = 'schedule'; + $echo[$a] = []; [$delta,$bytes] = [_var($var,'mdResyncDt',0),_var($var,'mdResyncDb',0)]; $synced = create_sync($stamps); $sbSynced = array_shift($synced) ?: _var($var,'sbSynced'); $sbUpdate = $delta ? $sbSynced : _var($var,'sbUpdated'); if ($spot) { - $echo[4] = sprintf(_('Current operation %s on **%s**'),($delta?_('started'):_('paused')),_(my_time($sbUpdate).day_count($sbUpdate),0)); - $echo[4].= "
"._('Elapsed time').": "._(my_clock(floor((time()-$sbSynced)/60)),2); - $echo[4].= "
"._('Estimated finish').': '.($bytes ? _(my_clock(round(((($delta*(($size-$spot)/($bytes/100+1)))/100)/60),0)),2) : _('Unknown')); - $echo[4].= "
".print_error(_var($var,'sbSyncErrs',0)); - $echo[4] .= "\0"; + $echo[$a][] = sprintf(_('Current operation %s on **%s**'),($delta?_('started'):_('paused')),_(my_time($sbUpdate).day_count($sbUpdate),0)); + $echo[$a][] = "
"._('Elapsed time').": "._(my_clock(floor((time()-$sbSynced)/60)),2); + $echo[$a][] = "
"._('Estimated finish').': '.($bytes ? _(my_clock(round(((($delta*(($size-$spot)/($bytes/100+1)))/100)/60),0)),2) : _('Unknown')); + $echo[$a][] = "
".print_error(_var($var,'sbSyncErrs',0)); } else { [$date,$duration,$speed,$status,$error,$action,$size] = last_parity_log(); if (_var($var,'sbSyncExit',0)!=0) { - $echo[4] = sprintf(_('Last check incomplete on **%s**'),_(my_time(_var($var,'sbSynced2',0)).day_count(_var($var,'sbSynced2',0)),0)); - $echo[4].= "
"._('Error code').": ".my_error(_var($var,'sbSyncExit')); - $echo[4].= "
".print_error(_var($var,'sbSyncErrs',0)); + $echo[$a][] = sprintf(_('Last check incomplete on **%s**'),_(my_time(_var($var,'sbSynced2',0)).day_count(_var($var,'sbSynced2',0)),0)); + $echo[$a][] = "
"._('Error code').": ".my_error(_var($var,'sbSyncExit')); + $echo[$a][] = "
".print_error(_var($var,'sbSyncErrs',0)); } elseif (_var($var,'sbSynced',0)==0) { if (!$date) { - $echo[4] = _('Parity has not been checked yet'); + $echo[$a][] = _('Parity has not been checked yet'); } elseif ($status==0) { - $echo[4] = sprintf(_('Last checked on **%s**'),_(my_time($date).day_count($date),0)); - $echo[4].= "
"._('Duration').": ".my_check($duration,$speed); - $echo[4].= "
".print_error($error); + $echo[$a][] = sprintf(_('Last checked on **%s**'),_(my_time($date).day_count($date),0)); + $echo[$a][] = "
"._('Duration').": ".my_check($duration,$speed); + $echo[$a][] = "
".print_error($error); } else { - $echo[4] = sprintf(_('Last check incomplete on **%s**'),_(my_time($date).day_count($date),0)); - $echo[4].= "
"._('Error code').": ".my_error($status); - $echo[4].= "
".print_error($error); + $echo[$a][] = sprintf(_('Last check incomplete on **%s**'),_(my_time($date).day_count($date),0)); + $echo[$a][] = "
"._('Error code').": ".my_error($status); + $echo[$a][] = "
".print_error($error); } } elseif (_var($var,'sbSynced2',0)==0) { if ($status==0) { - $echo[4] = sprintf(_('Last checked on **%s**'),_(my_time(_var($var,'sbSynced',0)).day_count(_var($var,'sbSynced',0)),0)); - $echo[4].= "
"._('Duration').": ".my_check($duration,$speed); - $echo[4].= "
".print_error($error); + $echo[$a][] = sprintf(_('Last checked on **%s**'),_(my_time(_var($var,'sbSynced',0)).day_count(_var($var,'sbSynced',0)),0)); + $echo[$a][] = "
"._('Duration').": ".my_check($duration,$speed); + $echo[$a][]= "
".print_error($error); } else { - $echo[4] = sprintf(_('Last check incomplete on **%s**'),_(my_time(_var($var,'sbSynced',0)).day_count(_var($var,'sbSynced',0)),0)); - $echo[4].= "
"._('Error code').": ".my_error($status); - $echo[4].= "
".print_error($error); + $echo[$a][] = sprintf(_('Last check incomplete on **%s**'),_(my_time(_var($var,'sbSynced',0)).day_count(_var($var,'sbSynced',0)),0)); + $echo[$a][] = "
"._('Error code').": ".my_error($status); + $echo[$a][] = "
".print_error($error); } } else { - $echo[4] = sprintf(_('Last check completed on **%s**'),_(my_time(_var($var,'sbSynced2',0)).day_count(_var($var,'sbSynced2',0)),0)); - $echo[4].= "
"._('Duration').': '.my_check($duration,$speed); - $echo[4].= "
".print_error(_var($var,'sbSyncErrs',0)); + $echo[$a][] = sprintf(_('Last check completed on **%s**'),_(my_time(_var($var,'sbSynced2',0)).day_count(_var($var,'sbSynced2',0)),0)); + $echo[$a][] = "
"._('Duration').': '.my_check($duration,$speed); + $echo[$a][] = "
".print_error(_var($var,'sbSyncErrs',0)); } [$m,$h] = explode(' ', $parity['hour']); $time = time(); @@ -464,16 +476,18 @@ while (true) { case 'WL': $t = stage(0); break;} break; } - $echo[4] .= "\0"; + $echo[$a][] = "\n"; if ($check) { $frmt = _var($display,'date').(_var($display,'date')!='%c' ? ", "._var($display,'time') : ""); - $echo[4] .= sprintf(_('Next check scheduled on **%s**'),_(my_date($frmt,$time+$t),0)); - $echo[4] .= "
"._('Due in').": "._(my_clock(floor($t/60)),2); + $echo[$a][] = sprintf(_('Next check scheduled on **%s**'),_(my_date($frmt,$time+$t),0)); + $echo[$a][] = "
"._('Due in').": "._(my_clock(floor($t/60)),2); } else { - $echo[4] .= _('Scheduled parity check is disabled'); + $echo[$a][] = _('Scheduled parity check is disabled'); } } - $echo = implode("\1",$echo); + $echo[$a] = implode($echo[$a]); + + $echo = json_encode($echo); $md5_new = md5($echo,true); if ($md5_new !== $md5_old) { publish('update2', $echo); diff --git a/emhttp/plugins/dynamix/nchan/update_3 b/emhttp/plugins/dynamix/nchan/update_3 index 2ac86d2e4..dd00b2788 100755 --- a/emhttp/plugins/dynamix/nchan/update_3 +++ b/emhttp/plugins/dynamix/nchan/update_3 @@ -77,7 +77,8 @@ while (true) { $locale_init = _var($display,'locale'); update_translation($locale_init); } - $echo = $mode = $rxtx = $stat = []; + $echo = []; + $echo['port'] = $echo['mode'] = $echo['rxtx'] = $echo['stat'] = []; $ts = $time1 - $time0; foreach (ports() as $port) { // inbound + outbound speed @@ -95,26 +96,27 @@ while (true) { } $data[$port]['rx'] = $rx; $data[$port]['tx'] = $tx; - $echo[] = "$port\0$rx_speed\0$tx_speed\0$rxd\0$txd"; + $echo['port'][] = [$port,$rx_speed,$tx_speed,$rxd,$txd]; // interface general information $mtu = port_get_contents("$net/$port/mtu"); $link = port_get_contents("$net/$port/carrier")==1; if (substr($port,0,4)=='bond') { if ($link) { $bond_mode = file_exists("$bond/$port") ? str_replace('Bonding Mode: ','',@file("$bond/$port",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)[1]) : '---'; - $mode[] = "$bond_mode, mtu $mtu"; - } else $mode[] = "bond down"; + $echo['mode'][] = "$bond_mode, mtu $mtu"; + } else $echo['mode'][] = "bond down"; } elseif ($port=='lo') { - $mode[] = $link ? "loopback" : "not set"; + $echo['mode'][] = $link ? "loopback" : "not set"; } else { if ($link) { $speed = port_get_contents("$net/$port/speed"); $duplex = port_get_contents("$net/$port/duplex"); - $mode[] = "$speed Mbps, $duplex duplex, mtu $mtu"; - } else $mode[] = "interface down"; + $echo['mode'][] = "$speed Mbps, $duplex duplex, mtu $mtu"; + } else $echo['mode'][] = "interface down"; } // interface counters - $rxtx[] = "$rx\0$tx"; + $echo['rxtx'][] = $rx; + $echo['rxtx'][] = $tx; // interface errors $rx_errors = port_get_contents("$net/$port/statistics/rx_errors"); $rx_drops = port_get_contents("$net/$port/statistics/rx_dropped"); @@ -122,7 +124,8 @@ while (true) { $tx_errors = port_get_contents("$net/$port/statistics/tx_errors"); $tx_drops = port_get_contents("$net/$port/statistics/tx_dropped"); $tx_fifo = port_get_contents("$net/$port/statistics/tx_fifo_errors"); - $stat[] = "Errors: {$rx_errors}
Drops: {$rx_drops}
Overruns: {$rx_fifo}\0Errors: {$tx_errors}
Drops: {$tx_drops}
Overruns: {$tx_fifo}"; + $echo['stat'][] = "Errors: {$rx_errors}
Drops: {$rx_drops}
Overruns: {$rx_fifo}"; + $echo['stat'][] = "Errors: {$tx_errors}
Drops: {$tx_drops}
Overruns: {$tx_fifo}"; } // current date and time $now = time(); @@ -130,7 +133,9 @@ while (true) { $xdate = _var($display,'date')=='%c'; $clock = date($xtime||$xdate ? 'g:i '.esc('').'a'.esc('') : 'G:i',$now); $date = my_date($xdate ? 'D j M Y, T' : $display['date'].', T',$now); - $echo = implode("\n",$echo)."\1".implode("\0",$mode)."\1".implode("\0",$rxtx)."\1".implode("\0",$stat)."\1".$clock."\n"._($date,0); + $echo['time'] = [$clock,_($date,0)]; + + $echo = json_encode($echo); $md5_new = md5($echo,true); if ($md5_new !== $md5_old) { publish('update3', $echo); diff --git a/emhttp/plugins/dynamix/nchan/wg_poller b/emhttp/plugins/dynamix/nchan/wg_poller index cc4a6d0a3..7b05062ed 100755 --- a/emhttp/plugins/dynamix/nchan/wg_poller +++ b/emhttp/plugins/dynamix/nchan/wg_poller @@ -29,14 +29,15 @@ function my_scale($value, &$unit) { $md5_old = -1; while (true) { - $now = time(); $i = 0; - unset($dump); $vtun = []; + $now = time(); + $echo = []; + unset($dump); exec('wg show all dump',$dump); foreach ($dump as $row) { $row = preg_split('/\s+/',$row); - if (count($row)>5) $vtun[] = $row[0].';'.($row[5] ? $now - $row[5] : 0).';'.my_scale($row[6],$unit)." $unit;".my_scale($row[7],$unit)." $unit"; + if (count($row)>5) $echo[] = [$row[0], $row[5]?$now-$row[5]:0, my_scale($row[6],$unit)." $unit", my_scale($row[7],$unit)." $unit"]; } - $echo = implode("\0",$vtun); + $echo = json_encode($echo); $md5_new = md5($echo,true); if ($md5_new !== $md5_old) { publish('wireguard', $echo);