From 22ec726111074ea89f7d379f1466344c55736a51 Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 11:26:09 +0200 Subject: [PATCH 01/10] Dashboard: use prototype function This makes it easier for 3rd party developers to automatically hide dynamic content --- emhttp/plugins/dynamix/DashStats.page | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index b9b6fdf7e..24c518768 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -745,6 +745,11 @@ String.prototype.md5 = function() { } return rh(a)+rh(b)+rh(c)+rh(d); } +jQuery.prototype.hideMe = function() { + var hidden = $.cookie('hidden_content'); + hidden = hidden==null ? [] : hidden.split(';'); + if (hidden.indexOf(this.attr('sort'))>=0) this.find('tr:gt(0)').hide(); +} var ports = []; var cpu = []; @@ -889,11 +894,9 @@ function loadlist(init) { $.post('/webGui/include/DashboardApps.php',{display:'',docker:'',vms:''},function(d) { var data = d.split('\0'); $('#docker_view tr.updated').remove(); - $('#docker_view').append(data[0]); - hideMe($('#docker_view')); + $('#docker_view').append(data[0]).hideMe(); $('#vm_view tr.updated').remove(); - $('#vm_view').append(data[1]); - hideMe($('#vm_view')); + $('#vm_view').append(data[1]).hideMe(); if ($.cookie('my_apps')!=null) $('span.apps.stopped').hide(0,noApps()); if ($.cookie('my_vms')!=null) $('span.vms.stopped').hide(0,noVMs()); }); @@ -1189,11 +1192,6 @@ function setColor(l, t1, t2) { case (t2 > 0 && l >= t2): return 'orangebar'; default: return '';} } -function hideMe(tbody) { - var hidden = $.cookie('hidden_content'); - hidden = hidden==null ? [] : hidden.split(';'); - if (hidden.indexOf(tbody.attr('sort'))>=0) tbody.find('tr:gt(0)').hide(); -} function mixed(tbody) { if (tbody.attr('data')) { setTimeout(tbody.attr('data')); @@ -1380,8 +1378,7 @@ dashboard.on('message',function(msg,meta) { var info = moreInfo(data,"_(Array)_"); // array devices $('#array_list tr.updated').remove(); - $('#array_list').append(data[0]); - hideMe($('#array_list')); + $('#array_list').append(data[0]).hideMe(); $('#array_info').parent().css('display',info?'':'none'); $('#array_info').html(info); smartMenu('#array_list'); @@ -1391,8 +1388,7 @@ dashboard.on('message',function(msg,meta) { var data = t.split('\0'); var info = moreInfo(data,"_(Pool)_"); $('#pool_list'+i+' tr.updated').remove(); - $('#pool_list'+i).append(t); - hideMe($('#pool_list'+i)); + $('#pool_list'+i).append(t).hideMe(); $('#pool_info'+i).parent().css('display',info?'':'none'); $('#pool_info'+i).html(info); smartMenu('#pool_list'+i); @@ -1402,8 +1398,7 @@ dashboard.on('message',function(msg,meta) { var data = part[2].split('\0'); var info = moreInfo(data,"_(Unassigned)_"); $('#devs_list tr.updated').remove(); - $('#devs_list').append(data[0]); - hideMe($('#devs_list')); + $('#devs_list').append(data[0]).hideMe(); $('#devs_info').parent().css('display',info?'':'none'); $('#devs_info').html(info); smartMenu('#devs_list'); From f9a72c0dbf8fb85c3f51b11c020454dcc62686cd Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 11:58:32 +0200 Subject: [PATCH 02/10] Dashboard: use prototype function --- emhttp/plugins/dynamix/DashStats.page | 33 +++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index 24c518768..c7291436f 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -750,6 +750,20 @@ jQuery.prototype.hideMe = function() { hidden = hidden==null ? [] : hidden.split(';'); if (hidden.indexOf(this.attr('sort'))>=0) this.find('tr:gt(0)').hide(); } +jQuery.prototype.mixedView = function() { + this.find('tr:gt(0)').show() + if (this.attr('data')) { + setTimeout(this.attr('data')); + } + if (this.hasClass('mixed')) { + var select = this.find('select[name^="enter"]'); + select = parseInt(select.val())+1; + this.find('tr:gt(0)').each(function(){ + var names = ($(this).attr('class')||'').split(' '); + for (var n=0,name; name=names[n]; n++) if (/[0-9]/.test(name.slice(-1)) && name.slice(-1)!=select) $(this).hide(); + }); + } +} var ports = []; var cpu = []; @@ -1192,19 +1206,6 @@ function setColor(l, t1, t2) { case (t2 > 0 && l >= t2): return 'orangebar'; default: return '';} } -function mixed(tbody) { - if (tbody.attr('data')) { - setTimeout(tbody.attr('data')); - } - if (tbody.hasClass('mixed')) { - var select = tbody.find('select[name^="enter"]'); - select = parseInt(select.val())+1; - tbody.find('tr:gt(0)').each(function(){ - var names = ($(this).attr('class')||'').split(' '); - for (var n=0,name; name=names[n]; n++) if (/[0-9]/.test(name.slice(-1)) && name.slice(-1)!=select) $(this).hide(); - }); - } -} function openClose(button) { var hidden = $.cookie('hidden_content'); hidden = hidden==null ? [] : hidden.split(';'); @@ -1217,8 +1218,7 @@ function openClose(button) { hidden.push(tbody.attr('sort')); } else { button.removeClass('fa-chevron-up fa-chevron-down').addClass('fa-chevron-up'); - tbody.find('tr:gt(0)').show(); - mixed(tbody); + tbody.mixedView(); hidden.splice(hidden.indexOf(tbody.attr('sort')),1); } $.cookie('hidden_content',hidden.join(';'),{expires:3650}); @@ -1234,8 +1234,7 @@ function openClose(button) { } else { $('div.frame tbody').each(function(){ $(this).find('.openclose').removeClass('fa-chevron-up fa-chevron-down').addClass('fa-chevron-up'); - $(this).find('tr:gt(0)').show(); - mixed($(this)); + $(this).mixedView(); }); $.removeCookie('hidden_content'); } From 529e6f492fa51af8dff005a82288d3cecdf7a0f5 Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 12:05:44 +0200 Subject: [PATCH 03/10] Dashboard: use prototype function --- emhttp/plugins/dynamix/DashStats.page | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index c7291436f..1c05746d8 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -750,8 +750,12 @@ jQuery.prototype.hideMe = function() { hidden = hidden==null ? [] : hidden.split(';'); if (hidden.indexOf(this.attr('sort'))>=0) this.find('tr:gt(0)').hide(); } -jQuery.prototype.mixedView = function() { - this.find('tr:gt(0)').show() +jQuery.prototype.mixedView = function(s) { + if (s==0) { + this.find('tr:gt(0)').hide(); + return; + } + this.find('tr:gt(0)').show(); if (this.attr('data')) { setTimeout(this.attr('data')); } @@ -1214,11 +1218,11 @@ function openClose(button) { var tbody = button.closest('tbody'); if (button.hasClass('fa-chevron-up')) { button.removeClass('fa-chevron-up fa-chevron-down').addClass('fa-chevron-down'); - tbody.find('tr:gt(0)').hide(); + tbody.mixedView(0); hidden.push(tbody.attr('sort')); } else { button.removeClass('fa-chevron-up fa-chevron-down').addClass('fa-chevron-up'); - tbody.mixedView(); + tbody.mixedView(1); hidden.splice(hidden.indexOf(tbody.attr('sort')),1); } $.cookie('hidden_content',hidden.join(';'),{expires:3650}); @@ -1227,14 +1231,14 @@ function openClose(button) { if (hidden.length==0) { $('div.frame tbody').each(function(){ $(this).find('.openclose').removeClass('fa-chevron-up fa-chevron-down').addClass('fa-chevron-down'); - $(this).find('tr:gt(0)').hide(); + $(this).mixedView(0); hidden.push($(this).attr('sort')); }); $.cookie('hidden_content',hidden.join(';'),{expires:3650}); } else { $('div.frame tbody').each(function(){ $(this).find('.openclose').removeClass('fa-chevron-up fa-chevron-down').addClass('fa-chevron-up'); - $(this).mixedView(); + $(this).mixedView(1); }); $.removeCookie('hidden_content'); } From d0db98ebd3c0956bb133b104e8fc5d8bc9538fa2 Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 18:20:02 +0200 Subject: [PATCH 04/10] Dashboard: description -> model --- emhttp/plugins/dynamix/DashStats.page | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index 1c05746d8..59d92057e 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -256,7 +256,7 @@ input[value=Edit]{margin:12px 0 0 0;padding:5px 10px}
-_(Description)_


+_(Model)_


_(Registration)_
Unraid OS

_(Uptime)_
From 5280224a072cbd167e132837cb49f26a7f31120a Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 18:21:53 +0200 Subject: [PATCH 05/10] Dashboard: description -> model --- emhttp/plugins/dynamix/DashStats.page | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emhttp/plugins/dynamix/DashStats.page b/emhttp/plugins/dynamix/DashStats.page index 59d92057e..20e17c8d0 100644 --- a/emhttp/plugins/dynamix/DashStats.page +++ b/emhttp/plugins/dynamix/DashStats.page @@ -256,7 +256,7 @@ input[value=Edit]{margin:12px 0 0 0;padding:5px 10px}
-_(Model)_


+_(Model)_


_(Registration)_
Unraid OS

_(Uptime)_
From 1c7c315dcd1d8680fb6e48ef681a7ff137b03059 Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 18:29:28 +0200 Subject: [PATCH 06/10] ZFS: fix percentage value to max 100% --- emhttp/plugins/dynamix/nchan/update_1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emhttp/plugins/dynamix/nchan/update_1 b/emhttp/plugins/dynamix/nchan/update_1 index 3937a3830..057263bf9 100755 --- a/emhttp/plugins/dynamix/nchan/update_1 +++ b/emhttp/plugins/dynamix/nchan/update_1 @@ -24,7 +24,7 @@ while (true) { exec("awk '/^c_max|^size/{print \$3}' /proc/spl/kstat/zfs/arcstats 2>/dev/null",$zfs); [$total,$free] = $memory; $used = $total-$free; - $info = max(round(100*(1-$free/$total)),0)."%\0".round(100*($zfs[1]??0)/($zfs[0]??1))."%\0".implode("\0",$sys); + $info = max(round(100*(1-$free/$total)),0)."%\0".min(100,round(100*($zfs[1]??0)/($zfs[0]??1)))."%\0".implode("\0",$sys); $rpms = count($rpms) ? implode(" RPM\0",$rpms).' RPM' : ''; $names = array_keys((array)parse_ini_file("$varroot/shares.ini")); 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); From d2dc649f8b70cb470bb6df3d141eab8c5c0b4bd2 Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 23:51:34 +0200 Subject: [PATCH 07/10] WireGuard: delayed service update to avoid race condition --- emhttp/plugins/dynamix/WG0.page | 2 +- emhttp/plugins/dynamix/scripts/reload_services | 2 +- emhttp/plugins/dynamix/scripts/update_services | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 emhttp/plugins/dynamix/scripts/update_services diff --git a/emhttp/plugins/dynamix/WG0.page b/emhttp/plugins/dynamix/WG0.page index cb9153452..0699423eb 100644 --- a/emhttp/plugins/dynamix/WG0.page +++ b/emhttp/plugins/dynamix/WG0.page @@ -130,7 +130,7 @@ $active = explode(' ',exec('wg show interfaces')); $autostart = explode(' ',@file_get_contents("$etc/autostart")?:''); $build = false; $script = "$docroot/webGui/scripts/upnp_port"; -$services = "$docroot/webGui/scripts/reload_services"; +$services = "$docroot/webGui/scripts/update_services"; $template = "$docroot/webGui/WGX.page"; $tower = _var($var,'NAME'); $ethX = 'eth0'; diff --git a/emhttp/plugins/dynamix/scripts/reload_services b/emhttp/plugins/dynamix/scripts/reload_services index 36361190e..f3750640e 100755 --- a/emhttp/plugins/dynamix/scripts/reload_services +++ b/emhttp/plugins/dynamix/scripts/reload_services @@ -1,5 +1,5 @@ #!/bin/bash -SERVICES="sshd avahidaemon samba rpc nfsd ntpd nginx" +SERVICES="rpc nfsd ntpd nginx sshd avahidaemon samba" if [[ -n $1 ]]; then [[ ! -e $1 ]] && touch $1 || exit 0 diff --git a/emhttp/plugins/dynamix/scripts/update_services b/emhttp/plugins/dynamix/scripts/update_services new file mode 100644 index 000000000..0b59b9f78 --- /dev/null +++ b/emhttp/plugins/dynamix/scripts/update_services @@ -0,0 +1,8 @@ +#!/bin/bash +job=/tmp/wgjob.tmp +reload=/usr/local/emhttp/webGui/scripts/reload_services + +rm -f $job +echo "sleep 5;$reload $job"|at -M now 2>/dev/null +exit 0 + From b186761ee7853ab994f0a9b8da09c1b81facaadf Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 23 Jun 2023 23:53:49 +0200 Subject: [PATCH 08/10] Make script executable --- emhttp/plugins/dynamix/scripts/update_services | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 emhttp/plugins/dynamix/scripts/update_services diff --git a/emhttp/plugins/dynamix/scripts/update_services b/emhttp/plugins/dynamix/scripts/update_services old mode 100644 new mode 100755 From 0dc226b0c9519cf31cf1e8faf3b0080062ee1282 Mon Sep 17 00:00:00 2001 From: bergware Date: Sat, 24 Jun 2023 09:53:51 +0200 Subject: [PATCH 09/10] WireGuard: delayed service update to avoid race condition --- emhttp/plugins/dynamix/scripts/update_services | 8 +++----- sbin/create_network_ini | 5 +---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/emhttp/plugins/dynamix/scripts/update_services b/emhttp/plugins/dynamix/scripts/update_services index 0b59b9f78..8dc4b3ef2 100755 --- a/emhttp/plugins/dynamix/scripts/update_services +++ b/emhttp/plugins/dynamix/scripts/update_services @@ -1,8 +1,6 @@ #!/bin/bash -job=/tmp/wgjob.tmp -reload=/usr/local/emhttp/webGui/scripts/reload_services +lock=/tmp/atlock.tmp -rm -f $job -echo "sleep 5;$reload $job"|at -M now 2>/dev/null +rm -f $lock +echo "sleep ${1:-1};/usr/local/emhttp/webGui/scripts/reload_services $lock"|at -M now 2>/dev/null exit 0 - diff --git a/sbin/create_network_ini b/sbin/create_network_ini index 1b9cc2fd3..9cdd051b0 100755 --- a/sbin/create_network_ini +++ b/sbin/create_network_ini @@ -11,8 +11,6 @@ ini=/var/local/emhttp/network.ini.new cfg=/boot/config/network.cfg -job=/tmp/atjob.tmp -reload=/usr/local/emhttp/webGui/scripts/reload_services declare -A VLANID USE_DHCP IPADDR NETMASK GATEWAY METRIC USE_DHCP6 IPADDR6 NETMASK6 GATEWAY6 PRIVACY6 METRIC6 DESCRIPTION PROTOCOL @@ -222,8 +220,7 @@ done /usr/bin/mv $ini ${ini%.*} # delayed execution -rm -f $job -echo "sleep 35;$reload $job"|at -M now 2>/dev/null +/usr/local/emhttp/webGui/scripts/update_services 35 # send update information if [[ -n $interface && -n $data && -e /var/run/nginx.socket ]]; then From dbb6191e3890b92751e297c06ab6e0e48e789729 Mon Sep 17 00:00:00 2001 From: bergware Date: Sat, 24 Jun 2023 12:25:46 +0200 Subject: [PATCH 10/10] rc.library: do not allow duplicate entries --- etc/rc.d/rc.library.source | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/rc.d/rc.library.source b/etc/rc.d/rc.library.source index 3e071f204..1daeac35d 100644 --- a/etc/rc.d/rc.library.source +++ b/etc/rc.d/rc.library.source @@ -140,12 +140,12 @@ check() { while IFS='\n' read -r net; do net=($net) if [[ "avahi show" =~ $CALLER ]]; then - [[ -n $net ]] && bind+=($net) + [[ -n $net && -z $(good $net) ]] && bind+=($net) [[ -n ${net[1]} ]] && ipv4=yes else # exclude wireguard tunnels for ntp [[ $CALLER == ntp ]] && name=$(show ${net[1]}) || name= - [[ ${name:0:2} != wg && -n ${net[1]} ]] && ipv4=yes bind+=($(sub ${net[1]})) + [[ ${name:0:2} != wg && -n ${net[1]} && -z $(good ${net[1]}) ]] && ipv4=yes bind+=($(sub ${net[1]})) fi done <<< $(ip -br -4 addr|awk '/^(br|bond|eth|wg)[0-9]+(\.[0-9]+)?/ {print $1,$3}') # active ipv6 interfaces (including wireguard) @@ -157,7 +157,7 @@ check() { else # exclude wireguard tunnels for ntp [[ $CALLER == ntp ]] && name=$(show ${net[1]}) || name= - [[ ${name:0:2} != wg && -n ${net[1]} ]] && ipv6=yes bind+=($(sub ${net[1]})) + [[ ${name:0:2} != wg && -n ${net[1]} && -z $(good ${net[1]}) ]] && ipv6=yes bind+=($(sub ${net[1]})) fi done <<< $(ip -br -6 addr|awk '/^(br|bond|eth|wg)[0-9]+(\.[0-9]+)?/ && $3 !~ "^fe80" {print $1,$3}') # add loopback interface