From 232546feef9238bf8acba16b92da47e28937fcc7 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Wed, 3 Apr 2013 22:42:15 +0000 Subject: [PATCH] checkpoint on the way to 1.0.0 git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1516 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 2 +- CONTROL/postinst | 3 +- CONTROL/prerm | 2 +- var/mongoose/cgi-bin/settings.jim | 27 +++++ var/mongoose/cgi-bin/xepg.jim | 2 +- var/mongoose/html/css/style.css | 22 +++- var/mongoose/html/diag/disk.jim | 46 ++++++-- var/mongoose/html/diag/diskack.jim | 16 +++ var/mongoose/html/lib/header.jim | 1 + var/mongoose/include/backup.jim | 3 +- var/mongoose/include/diskcheck.jim | 67 ++++++++++++ var/mongoose/include/diskspace.jim | 6 +- var/mongoose/lib/bin/auto | 167 ++++++++++++++++++----------- var/mongoose/lib/bin/diskattrs | 45 ++++++++ var/mongoose/lib/settings.class | 39 +++++++ var/mongoose/lib/system.class | 7 ++ 16 files changed, 377 insertions(+), 78 deletions(-) create mode 100755 var/mongoose/html/diag/diskack.jim create mode 100755 var/mongoose/include/diskcheck.jim create mode 100755 var/mongoose/lib/bin/diskattrs diff --git a/CONTROL/control b/CONTROL/control index 5560a032..f0aa0d44 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 0.13.3-4 +Version: 1.0.0 Architecture: mipsel Maintainer: af123@hummypkg.org.uk Depends: webif-channelicons(>=1.0.5),mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73-1),jim-cgi(>=0.7),jim-binary,service-control(>=1.2),busybox(>=1.20.2-1),lsof,epg(>=1.0.13),hmt(>=1.1.13),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2),stripts(>=1.1.2),smartmontools,tmenu(>=1.05),ffmpeg,id3v2 diff --git a/CONTROL/postinst b/CONTROL/postinst index be606d72..0141dcc3 100755 --- a/CONTROL/postinst +++ b/CONTROL/postinst @@ -19,10 +19,11 @@ grep -v webif/lib/bin/auto $cronf > $tmpf # Add anacron jobs ana=$PKG_ROOT/etc/anacrontab -grep -v 'backup/backup.jim' $ana > $tmpf +egrep -v 'backup/backup.jim|diskattrs' $ana > $tmpf ( cat $tmpf echo "1 8 sched_backup /mod/var/mongoose/cgi-bin/backup/backup.jim" + echo "1 5 diskattrs /mod/webif/lib/bin/diskattrs" ) > $ana $PKG_ROOT/etc/init.d/S02anacron start < /dev/null > /dev/null 2>&1 & diff --git a/CONTROL/prerm b/CONTROL/prerm index 29bc89e5..c2fd54d5 100755 --- a/CONTROL/prerm +++ b/CONTROL/prerm @@ -10,7 +10,7 @@ if [ -f $cronf ]; then fi ana=/mod/etc/anacrontab -grep -v 'backup/backup.jim' $ana > $tmpf +egrep -v 'backup/backup.jim|diskattrs' $ana > $tmpf cp $tmpf $ana exit 0 diff --git a/var/mongoose/cgi-bin/settings.jim b/var/mongoose/cgi-bin/settings.jim index fc9d5559..84663a12 100755 --- a/var/mongoose/cgi-bin/settings.jim +++ b/var/mongoose/cgi-bin/settings.jim @@ -40,6 +40,7 @@ set nomobile [$settings nomobile] set xepghours [$settings xepghours] if {$xepghours == 0} { set xepghours 4 } set genrededup [$settings genrededup] +set autolog [$settings autolog] # Handle updates @@ -80,6 +81,7 @@ handle_int_update pkgdev $pkgdev "Development Package Display" handle_int_update notoolbar $notoolbar "Disable toolbar" handle_int_update nomobile $nomobile "Disable mobile link" handle_int_update genrededup $genrededup "Genre search dedup" +handle_int_update autolog $autolog "Auto-processing log level" set acluser [cgi_get acluser "-"] set aclpass [cgi_get aclpass "-"] @@ -177,6 +179,31 @@ puts "> " +puts -nonewline " +
+ Auto-processing log level + + + + +
+ +
+" + puts "

diff --git a/var/mongoose/cgi-bin/xepg.jim b/var/mongoose/cgi-bin/xepg.jim index 6d2f9f50..a409cd2f 100755 --- a/var/mongoose/cgi-bin/xepg.jim +++ b/var/mongoose/cgi-bin/xepg.jim @@ -221,7 +221,7 @@ puts " onSelect: function(val, sel) { var stt = \$(this).attr('stt'); // Extract date part - dval = ~~(val / 86400000); + dval = Math.round(val / 86400000.0); // Extract current time part var tm = ~~(stt % 86400); diff --git a/var/mongoose/html/css/style.css b/var/mongoose/html/css/style.css index 3f8d42fc..b8889998 100644 --- a/var/mongoose/html/css/style.css +++ b/var/mongoose/html/css/style.css @@ -65,13 +65,33 @@ div.footer padding-top: 2em; } -div.warningbox +div.owarningbox { background: url('/img/redshade.png') repeat-x; padding: 0.5em; margin: 1em; } +div.warningbox +{ + width: 60%; + background: url('/img/redshade.png') repeat-x; + background-size: 100%; + #color: #005000; + border: 1px solid #7a4707; + padding: 10px; + position: relative; + top: -2px; + left: -2px; + font-weight: bold; + z-index: 30; + box-shadow: 2px 2px 11px #666; + -moz-box-shadow: 2px 2px 11px #666; + -webkit-box-shadow: 2px 2px 11px #666; + border-radius: 5px; + -moz-border-radius: 5px; +} + table { empty-cells: show; diff --git a/var/mongoose/html/diag/disk.jim b/var/mongoose/html/diag/disk.jim index f2d816fd..1cf3e8fa 100755 --- a/var/mongoose/html/diag/disk.jim +++ b/var/mongoose/html/diag/disk.jim @@ -2,12 +2,12 @@ package require cgi source /mod/webif/lib/setup -require system.class +require system.class settings.class header -set space [system diskspace] -set device [string range [lindex $space 5] 0 end-1] +set device [system disk] +set settings [settings] set smart Unknown set line "" @@ -16,9 +16,11 @@ catch { set line [exec /mod/bin/smartctl -H $device | sed -n 5p] } msg if {$msg ne "" && $line eq ""} { set line $msg } if {$line ne ""} { set smart [string range [lindex [split $line :] 1] 1 end] + $settings _tval_setting "SMART_status" $smart } puts " +

SMART data read from device $device @@ -99,9 +101,18 @@ foreach line [split [exec /mod/bin/smartctl -A $device] "\n"] { id name flags val worst thresh type updated when rval set class normal switch $id { - 5 { if {$rval > 0} { set class orangeshade } } - 197 { if {$rval > 0} { set class redshade } } - 198 { if {$rval > 0} { set class redshade } } + 5 { + $settings _nval_setting "SMART_realloc" $rval + if {$rval > 0} { set class orangeshade } + } + 197 { + $settings _nval_setting "SMART_pending" $rval + if {$rval > 0} { set class redshade } + } + 198 { + $settings _nval_setting "SMART_offline" $rval + if {$rval > 0} { set class redshade } + } } puts "" puts " @@ -144,6 +155,7 @@ foreach line [split $msg "\n"] { regsub -all -- {[[:space:]][[:space:]]+} $line "|" line if {[incr i] < 7} continue lassign [split $line "|"] id name status remaining when lba + if {[string length $id] > 10} continue puts " $id $name @@ -157,6 +169,28 @@ foreach line [split $msg "\n"] { puts { + + +
+ +
+ + + } footer diff --git a/var/mongoose/html/diag/diskack.jim b/var/mongoose/html/diag/diskack.jim new file mode 100755 index 00000000..c68ff482 --- /dev/null +++ b/var/mongoose/html/diag/diskack.jim @@ -0,0 +1,16 @@ +#!/mod/bin/jimsh + +source /mod/webif/lib/setup +require settings.class + +httpheader + +set settings [settings] + +foreach attr {realloc pending offline} { + set val [$settings _nval_setting "SMART_$attr"] + if {$val <= 0} continue + $settings _nval_setting "SMART_ack_$attr" $val +} + + diff --git a/var/mongoose/html/lib/header.jim b/var/mongoose/html/lib/header.jim index 8aecb194..d826daf4 100755 --- a/var/mongoose/html/lib/header.jim +++ b/var/mongoose/html/lib/header.jim @@ -25,6 +25,7 @@ source /mod/webif/html/lib/topbar.jim puts "
" source /mod/webif/include/restart.jim puts "
" +source /mod/webif/include/diskcheck.jim puts {
diff --git a/var/mongoose/include/backup.jim b/var/mongoose/include/backup.jim index f9304cce..76047fc2 100755 --- a/var/mongoose/include/backup.jim +++ b/var/mongoose/include/backup.jim @@ -8,12 +8,13 @@ puts {

Backup/Restore

diff --git a/var/mongoose/include/diskcheck.jim b/var/mongoose/include/diskcheck.jim new file mode 100755 index 00000000..a3cba52f --- /dev/null +++ b/var/mongoose/include/diskcheck.jim @@ -0,0 +1,67 @@ +#!/mod/bin/jimsh + +source /mod/webif/lib/setup +require settings.class + +set smartattrs {realloc pending offline} + +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 + } +} + +# (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))" + } + append smartmsg "\n" + } +} + +if {$smartmsg ne ""} { + puts " +
+!! WARNING !! +

+There are some issues with the internal hard disk on this device. +

+[string map {"\n" "
"} $smartmsg] + " + if {$env(REQUEST_URI) ne "/diag/disk.jim"} { + puts " +
+ Go to disk diagnostics + " + } else { + puts " +
+ For help and assistance, visit + hummy.tv + " + } + puts " +
+ " +} + diff --git a/var/mongoose/include/diskspace.jim b/var/mongoose/include/diskspace.jim index 71a59d50..e6f3e6e3 100755 --- a/var/mongoose/include/diskspace.jim +++ b/var/mongoose/include/diskspace.jim @@ -4,7 +4,9 @@ source /mod/webif/lib/setup require system.class lassign [system diskspace] size used perc free fperc -set file [format "%02d" [expr {$perc * 25 / 100 + 1}]] +set dsindex $($perc * 25 / 100 + 1) +if {$dsindex > 25} { set dsindex 25 } +set dsfile [format "%02d" $dsindex] # The HD model only has the USB images which are blue. I prefer the green # one so use those if available. @@ -19,7 +21,7 @@ puts " - + diff --git a/var/mongoose/lib/bin/auto b/var/mongoose/lib/bin/auto index 76b1874e..05874970 100755 --- a/var/mongoose/lib/bin/auto +++ b/var/mongoose/lib/bin/auto @@ -1,9 +1,10 @@ #!/mod/bin/jimsh source /mod/webif/lib/setup -require lock system.class ts.class tdelete pretty_size browse.class safe_delete +require lock system.class ts.class tdelete pretty_size browse.class \ + safe_delete settings.class -set debug 0 +set loglevel [[settings] autolog] if {![acquire_lock webif_auto]} { puts "Cannot acquire exclusive lock, terminating." @@ -18,8 +19,8 @@ if {[file exists $logfile] && [file size $logfile] > 2097152} { } set logfd [open "/mod/tmp/auto.log" "a+"] -proc log {msg {always 0}} { - if {!$::debug && !$always} return +proc log {msg {level 1}} { + if {$level > $::loglevel} return puts $::logfd "[\ clock format [clock seconds] -format "%d/%m/%Y %H:%M"\ ] - $msg" @@ -41,7 +42,7 @@ proc endclock {size} { } set scanstart [clock milliseconds] -log "-------------------------------------------------------" 1 +log "-------------------------------------------------------" # is_listening is relatively expensive so it is checked once globally at # the start and then if the server is not listening then no decrypt @@ -51,13 +52,13 @@ log "-------------------------------------------------------" 1 # of the run. if {[system is_listening 9000]} { set dlnaok 1 - if {$::debug} { log "DLNA Server is running." } + log "DLNA Server is running." 2 } else { set dlnaok 0 - if {$::debug} { log "DLNA Server is NOT running." } + log "DLNA Server is NOT running." 2 } -log "Media scan starting, DLNA server status: $dlnaok" 1 +log "Media scan starting, DLNA server status: $dlnaok" proc dsc {{size 0}} { set free [system diskfree] @@ -66,7 +67,7 @@ proc dsc {{size 0}} { set req $($size * 3 + 1073741824) if {$free < $req} { - log "Insufficient disk space. Require=$req, Free=$free" 1 + log "Insufficient disk space. Require=$req, Free=$free" 0 exit } } @@ -76,11 +77,11 @@ dsc set tmp "/mod/tmp/webif_auto" if {![file exists $tmp]} { if {[catch {file mkdir $tmp} msg]} { - log "Cannot create temporary directory - $tmp ($msg)" 1 + log "Cannot create temporary directory - $tmp ($msg)" 0 exit } } elseif {![file isdirectory $tmp]} { - log "Cannot create temporary directory - $tmp (file exists)" 1 + log "Cannot create temporary directory - $tmp (file exists)" 0 exit } @@ -93,14 +94,14 @@ if {[system pkginst undelete]} { set dustbin "" } -log "Dustbin: $dustbin" +log "Dustbin: $dustbin" 2 proc dedup {dir} { - log "DEDUP: \[$dir]" + log "DEDUP: \[$dir]" 2 loop i 0 1 { foreach line [split \ [exec /mod/webif/html/dedup/dedup -yes -auto $dir] "\n"] { - log $line 1 + log $line 2 } } } @@ -111,39 +112,41 @@ proc do_expire {ts} { # Calculate the age of the file in days. set age $(([clock seconds] - [$ts get start]) / 86400.0) - log " EXPIRE: $file (age = $age)" + log " EXPIRE: $file (age = $age)" 2 if {$age > $ax_days} { - log " EXPIRE: $file ($age > $ax_days)" 1 if {[$ts inuse]} { - log " In use." 1 + log " EXPIRE: $file ($age > $ax_days)" + log " In use." return } if {[safe_delete $file]} { - log " Deleted." 1 + log " EXPIRE: $file ($age > $ax_days)" 0 + log " Deleted." 0 } } } proc do_shrink {ts} { global tmp dustbin tsgroup + set file [$ts get file] if {[$ts flag "Shrunk"]} { - log " Already shrunk." + log " $file - already shrunk." 2 return } set file [file rootname [$ts get file]] if {[$ts inuse]} { - log " $file - in use." 1 + log " $file - in use." 2 return } if {[catch { set perc [exec /mod/bin/stripts -aq $file] } msg]} { - log " Error: $msg" 1 + log " Error: $msg" 0 return } if {[string match {*%} $perc]} { @@ -153,24 +156,24 @@ proc do_shrink {ts} { } if {$perc == 0} { - log " Already shrunk." + log " $file - already shrunk." 2 $ts set_shrunk return } set size [$ts size] dsc $size startclock - log " SHRINK: $file" 1 - log " Estimate $perc% saving." 1 - log " Shrinking..." 1 + log " SHRINK: $file" 0 + log " Estimate $perc% saving." 0 + log " Shrinking..." 0 if {[catch { foreach line [split \ [exec nice -n 19 /mod/bin/stripts -q $file $tmp/shrunk] \ "\n"] { - log $line 1 + log $line 0 } } msg]} { - log "Error during shrink: $msg" 1 + log "Error during shrink: $msg" 0 return } @@ -196,7 +199,7 @@ proc do_shrink {ts} { } } $ts set_shrunk - log "Done... [endclock $size]" 1 + log "Done... [endclock $size]" 0 } proc do_decrypt {ts} { @@ -207,37 +210,72 @@ proc do_decrypt {ts} { set bfile [file tail $file] if {![$ts flag "ODEncrypted"]} { - log " Already decrypted." + log " $file - Already decrypted." 2 return } lassign [$ts dlnaloc "127.0.0.1"] url if {$url eq ""} { - log " Not yet indexed." + log " $file - Not yet indexed." return } if {![system is_listening 9000]} { - log " DLNA Server not running." + log " $file - DLNA Server not running." 2 set ::dlnaok 0 return } if {[$ts inuse]} { - log " In use." 1 + log " $file - In use." return } + + # Check that the file is not already decrypted by analysing it. + set anencd [exec /mod/bin/stripts -qE $rfile] + if {$anencd != "1"} { + log " $file - already decrypted but the HMT flag is wrong." 0 + system notify "$file - auto-decrypt - file is already decrypted but the HMT flag is wrong." + return + } + + # Perform the decryption by requesting the file from the DLNA server. set size [$ts size] dsc $size set flagfile "$tmp/decrypting.$bfile" exec /mod/bin/busybox/touch $flagfile startclock - log " DECRYPT: $rfile" 1 - log " DLNA: $url" 1 + log " DECRYPT: $rfile" 0 + log " DLNA: $url" 0 exec wget -O "$tmp/$bfile" $url if {[file size $file] != [file size "$tmp/$bfile"]} { - log " File size mismatch." 1 + log " $file - File size mismatch." 0 + file delete "$tmp/$bfile" + file delete $flagfile + return + } + + # Check if the file is in use. It is possible that the file is + # now being played even though it was free when decryption started. + if {[$ts inuse]} { + log " $file - In use." + file delete "$tmp/$bfile" + file delete $flagfile + return + } + + # Copy the HMT file over for stripts + set thmt "$tmp/[file rootname $bfile].hmt" + file copy "$rfile.hmt" $thmt + # Check that the file is no longer encrypted by analysing it. + set anencd [exec /mod/bin/stripts -qE "$tmp/[file rootname $bfile]"] + file delete $thmt + + if {$anencd != "0"} { + log " $file - File did not decrypt properly." 0 + system notify "$file - auto-decrypt failed." + file delete "$tmp/$bfile" file delete $flagfile return } @@ -249,7 +287,7 @@ proc do_decrypt {ts} { # Patch the HMT - quickest way to get back to a playable file. exec /mod/bin/hmt -encrypted "$rfile.hmt" - log " Removing/binning old copy." + log " Removing/binning old copy." 0 # Move the old recording to the bin if undelete is installed. if {$dustbin ne ""} { set bin [_del_bindir $file "webif_autodecrypt"] @@ -268,7 +306,7 @@ proc do_decrypt {ts} { } else { tdelete "$rfile.encrypted" } - log "Done... [endclock $size]" 1 + log "Done... [endclock $size]" 0 file delete $flagfile } @@ -283,7 +321,7 @@ proc do_mpg {ts} { } if {[$ts flag "ODEncrypted"]} { - log " Not decrypted." + log " $file - Not decrypted." 2 return } @@ -293,23 +331,23 @@ proc do_mpg {ts} { } if {[$ts inuse]} { - log " In use." 1 + log " $file - In use." return } dsc [$ts size] - log " MPG: $file" 1 - log " Converting..." 1 + log " MPG: $file" 0 + log " Converting..." 0 if {[catch { foreach line [split \ [exec nice -n 19 /mod/bin/ffmpeg -y -benchmark -v 0 \ -i $file.ts \ -map 0:0 -map 0:1 \ -vcodec copy -acodec copy $tmp/mpg.mpg] "\n"] { - log $line 1 + log $line 0 } } msg]} { - log "Error during mpg extract: $msg" 1 + log "Error during mpg extract: $msg" 0 return } @@ -328,32 +366,33 @@ proc do_mp3 {ts} { } if {[$ts flag "ODEncrypted"]} { - log " Not decrypted." + log " $file - Not decrypted." 2 return } if {[$ts get definition] eq "HD"} { # Cannot extract a useful MP3 from a HD recording. + log " $file - High definition." 2 return } if {[$ts inuse]} { - log " In use." 1 + log " $file - In use." return } dsc [$ts size] - log " MP3: $file" 1 - log " Converting..." 1 + log " MP3: $file" 0 + log " Converting..." 0 if {[catch { foreach line [split \ [exec nice -n 19 /mod/bin/ffmpeg -y -benchmark -v 0 \ -i $file.ts \ -f mp3 -vn -acodec copy $tmp/mp3.mp3] "\n"] { - log $line 1 + log $line 0 } } msg]} { - log "Error during mp3 extract: $msg" 1 + log "Error during mp3 extract: $msg" 0 return } @@ -363,7 +402,7 @@ proc do_mp3 {ts} { --comment "[$ts get synopsis]" \ --album "[$ts get channel_name]" \ --year "[clock format [$ts get start] -format {%Y}]" \ - "$tmp/mp3.mp3"] + "$tmp/mp3.mp3"] 0 } # Move the MP3 into the local directory @@ -380,28 +419,28 @@ proc entries {dir callback} { } proc shrink {dir} { - log "SHRINK: \[$dir]" + log "SHRINK: \[$dir]" 2 entries $dir do_shrink } proc decrypt {dir} { - log "DECRYPT: \[$dir]" + log "DECRYPT: \[$dir]" 2 if {$::dlnaok} { entries $dir do_decrypt } } proc mpg {dir} { - log "MPG: \[$dir]" + log "MPG: \[$dir]" 2 entries $dir do_mpg } proc mp3 {dir} { - log "MP3: \[$dir]" + log "MP3: \[$dir]" 2 entries $dir do_mp3 } proc expire {dir} { global ax_days - log "EXPIRE: \[$dir]" + log "EXPIRE: \[$dir]" 2 set ax_days [{dir expiry} $dir] entries $dir do_expire @@ -412,10 +451,10 @@ proc scan {dir attr {force 0}} {{indent 0}} { incr indent 2 - log "[string repeat " " $indent]\[$dir]" + log "[string repeat " " $indent]\[$dir]" 2 if {$dir eq $dustbin} { - log "Dustbin, skipping." + log "Dustbin, skipping." 2 return } @@ -423,18 +462,18 @@ proc scan {dir attr {force 0}} {{indent 0}} { # Special folder file stat "$dir/" st if {$st(dev) != $::rootdev} { - log "Special folder on different device, skipping." + log "Special folder on different device, skipping." 2 return } if {$force} { set force 0 - log "Special folder, overriding recursion." + log "Special folder, overriding recursion." 2 } } # Recursion if {!$force && [file exists "$dir/.auto${attr}r"]} { - log "[string repeat " " $indent] (R)" + log "[string repeat " " $indent] (R)" 2 set force 1 } @@ -454,20 +493,20 @@ proc scan {dir attr {force 0}} {{indent 0}} { set root [system mediaroot] file stat "$root/" rootstat set rootdev $rootstat(dev) -#log "Root device: $rootdev" 1 +log "Root device: $rootdev" 2 if {[llength $argv] > 0} { - set debug 1 + set loglevel 2 foreach arg $argv { scan $root $arg } } else { foreach arg {dedup decrypt shrink mpg mp3 expire} { set st [clock milliseconds] scan $root $arg - log "$arg scan completed in [elapsed $st] seconds." 1 + log "$arg scan completed in [elapsed $st] seconds." } } release_lock webif_auto -log "Media scan completed in [elapsed $scanstart] seconds." 1 +log "Media scan completed in [elapsed $scanstart] seconds." diff --git a/var/mongoose/lib/bin/diskattrs b/var/mongoose/lib/bin/diskattrs new file mode 100755 index 00000000..7918d6b5 --- /dev/null +++ b/var/mongoose/lib/bin/diskattrs @@ -0,0 +1,45 @@ +#!/mod/bin/jimsh + +source /mod/webif/lib/setup +require system.class settings.class + +if {[system model] eq "HD"} exit + +set disk [system disk] +set settings [settings] + +# Extract overall SMART status. +set smart "" +set line "" +# smartctl uses non-zero exit status to indicate health hence catch. +catch { set line [exec /mod/bin/smartctl -H $disk | sed -n 5p] } msg +if {$msg ne "" && $line eq ""} { set line $msg } +if {$line ne ""} { + set smart [string range [lindex [split $line :] 1] 1 end] + $settings _tval_setting "SMART_status" $smart +} + +foreach line [split [exec /mod/bin/smartctl -A -f brief $disk] "\n"] { + regsub -all -- {[[:space:]]+} $line " " line + regsub -all -- {^[[:space:]]+} $line "" line + lassign [split $line] id name flags val worst thresh when rval + if {![string is integer $id]} continue + set attrs($id) $rval +} + +#puts "Attrs: ($attrs)" +puts "SMART: ($smart)" +puts "Reallocated: $attrs(5)" +puts "Pending: $attrs(197)" +puts "Offline: $attrs(198)" + +if {[dict exists $attrs 5]} { + $settings _nval_setting "SMART_realloc" $attrs(5) +} +if {[dict exists $attrs 197]} { + $settings _nval_setting "SMART_pending" $attrs(197) +} +if {[dict exists $attrs 198]} { + $settings _nval_setting "SMART_offline" $attrs(198) +} + diff --git a/var/mongoose/lib/settings.class b/var/mongoose/lib/settings.class index a729e5a9..a5968f47 100644 --- a/var/mongoose/lib/settings.class +++ b/var/mongoose/lib/settings.class @@ -26,6 +26,7 @@ class settings { nomobile 0 xepghours 4 genrededup 0 + autolog 0 } settings method hostname {{name ""}} { @@ -100,6 +101,29 @@ settings method _nval_setting {name {val -1}} { } } +settings method _tval_setting {name {val -1}} { + global settingsdb + + if {$val == -1} { + # Get + set res [$settingsdb query " + select tval from settings + where name = '$name' + "] + if {$res ne ""} { + return [lindex [lindex $res end] end] + } + return 0 + } else { + # Set + $settingsdb query " + replace into settings(name,tval) + values('$name', '%s') + " $val + return 0 + } +} + settings method channel_group {{group -1}} { return [$self _nval_setting channel_group $group] } @@ -140,6 +164,10 @@ settings method sortorder {{val -1}} { return [$self _nval_setting sortorder $val] } +settings method autolog {{level -1}} { + return [$self _nval_setting autolog $level] +} + settings method channel_groups {} { set ret "" set db [sqlite3.open /var/lib/humaxtv/setup.db] @@ -232,3 +260,14 @@ settings method delacluser {user} { return $msg } +settings method smartdata {} { + global settingsdb + + set res [$settingsdb query " + select name, nval, tval from settings + where name like 'SMART_%%' + "] + + return $res +} + diff --git a/var/mongoose/lib/system.class b/var/mongoose/lib/system.class index ec868676..c60bd247 100644 --- a/var/mongoose/lib/system.class +++ b/var/mongoose/lib/system.class @@ -139,6 +139,10 @@ proc {system diskspace} {} { return [list $size $used $perc $free $fperc $dev] } +proc {system disk} {} { + return [string range [lindex [system diskspace] 5] 0 end-1] +} + proc {system diskfree} {} { switch [system model] { HDR { set part /mnt/hd2 } @@ -244,3 +248,6 @@ proc {system is_listening} {mport} { return [llength [system listening $mport]] } +proc {system notify} {msg} { +} +