Improve disk check functionality and layout

This commit is contained in:
prpr 2022-03-25 23:07:58 +00:00
parent 99f22c6a28
commit 778c328a79
2 changed files with 98 additions and 56 deletions

View File

@ -2,77 +2,119 @@
source /mod/webif/lib/setup
require system.class
if {[system model] eq "HDR"} {
require settings.class
set smartattrs {realloc pending offline spinretry}
set smartattribs(SMART_status) "Unknown"
foreach sa $smartattrs {
set smartattribs(SMART_$sa) 0
set smartattribs(SMART_ack_$sa) 0
}
foreach line [[settings] smartdata] {
lassign $line x name x n x t
if {$name eq "SMART_status"} {
set smartattribs($name) $t
} else {
set smartattribs($name) $n
proc {system disksmart} {} {
set smartmsg ""
set smartattrs {realloc pending offline spinretry}
set smartattribs(SMART_status) "Unknown"
foreach sa $smartattrs {
set smartattribs(SMART_$sa) 0
set smartattribs(SMART_ack_$sa) 0
}
}
# (SMART_ack_status 0 SMART_ack_pending 0 SMART_status PASSED SMART_pending 7 SMART_ack_realloc 0 SMART_ack_offline 0 SMART_realloc 0 SMART_offline 7)
set smartmsg ""
if {$smartattribs(SMART_status) ne "PASSED"} {
append smartmsg \
"Disk overall health assessment is: $smartattribs(SMART_status)\n"
}
foreach sa $smartattrs {
if {$smartattribs(SMART_$sa) != $smartattribs(SMART_ack_$sa)} {
append smartmsg \
"Disk $sa sector count is: $smartattribs(SMART_$sa)"
if {$smartattribs(SMART_ack_$sa) > 0} {
append smartmsg " (was $smartattribs(SMART_ack_$sa))"
foreach line [[settings] smartdata] {
lassign $line x name x n x t
if {$name eq "SMART_status"} {
set smartattribs($name) $t
} else {
set smartattribs($name) $n
}
append smartmsg "\n"
}
# (SMART_ack_status 0 SMART_ack_pending 0 SMART_status PASSED SMART_pending 7 SMART_ack_realloc 0 SMART_ack_offline 0 SMART_realloc 0 SMART_offline 7)
if {$smartattribs(SMART_status) ne "PASSED"} {
append smartmsg \
"Disk overall health assessment is: $smartattribs(SMART_status)\n"
}
foreach sa $smartattrs {
if {$smartattribs(SMART_$sa) != $smartattribs(SMART_ack_$sa)} {
append smartmsg \
"Disk $sa sector count is: $smartattribs(SMART_$sa)"
if {$smartattribs(SMART_ack_$sa) > 0} {
append smartmsg " (was $smartattribs(SMART_ack_$sa))"
}
append smartmsg "\n"
}
}
return $smartmsg
}
if {$smartmsg ne ""} {
proc {system diskro} {} {
if {[system model] eq "HDR"} {
set dev {/mnt/hd[1-3]}
} else {
set dev [system diskpart]
}
# Python re: no POSIX character classes
# Jim TCL regex: no \x character classes
# Why not have both ...
set s {[[:blank:]]}
set a {[[:alnum:]]}
set nc {[^,]}
set roparts [lsearch -all -inline -regexp \
[split [file read /proc/mounts] "\n\r"] \
"${s}${dev}${s}+${a}+${s}*(${s}|${nc}+,)ro(,|$|${s})"]
return [join [lmap line $roparts \
{format "Filesystem %s on %s is read-only" [lindex $line 1] [lindex $line 0]}] "\n"]
}
set smartmsg [system disksmart]
set romsg [system diskro]
if {$smartmsg ne "" || $romsg ne ""} {
if {![dict exists $env SCRIPT_NAME]} { set env(SCRIPT_NAME) "" }
puts "
<div id=smartwarning class=warningbox><center>
puts {
<div id=smartwarning class=warningbox style="width: 80%; left: 1%"><center>
!! WARNING !!
<br><br>
There are potential hardware problems with the internal hard disk on
this device.
<br><br>
<br><br>}
set problems " "
if {$smartmsg ne ""} {
append problems "potential hardware"
}
if {$romsg ne ""} {
if {[string index $problems end] ne " "} {
append problems " and/or "
}
append problems "filesystem"
}
if {[string index $problems end] ne " "} {
append problems " "
}
puts [format "
There are %sproblems with the hard disk on
this system.
<br><br>" $problems]
if {$smartmsg ne ""} {
puts "
[string map {"\n" "<br>"} $smartmsg]
"
<br>
"
}
if {$romsg ne ""} {
puts "
[string map {"\n" "<br>"} $romsg]
<br><br>
"
}
if {$env(SCRIPT_NAME) ne "/diag/disk.jim"} {
puts "
<br>
<a href=/diag/disk.jim>Go to disk diagnostics</a>
"
Go to <a href=/diag/disk.jim>Disk Diagnostics</a>
"
} else {
puts "
<br>
Don't panic; for help, visit
<a target=_blank
href=http://wiki.hummy.tv/wiki/Disk_Problem>
wiki.hummy.tv
</a>
"
<br>
Don't panic; for help, visit
<a target=_blank href=\"http://wiki.hummy.tv/wiki/Disk_Problem\">wiki.hummy.tv</a>
"
}
puts "
</center></div>
"
}
"
}

View File

@ -5,7 +5,7 @@ if {[file exists /mod/tmp/notify.log]} {
source /mod/webif/lib/setup
puts {
<div id=sysnotify class=warningbox style="width: 90%"><center>
<div id=sysnotify class=warningbox style="width: 90%;left: 1%"><center>
!! WARNING !!
<br><br>
You have pending system notifications: