2011-09-02 19:50:10 +00:00
|
|
|
|
2012-01-13 21:23:03 +00:00
|
|
|
if {![exists -proc class]} { package require oo }
|
|
|
|
if {![exists -proc sqlite3.open]} { package require sqlite3 }
|
2011-09-02 19:50:10 +00:00
|
|
|
|
|
|
|
class system {}
|
|
|
|
|
|
|
|
proc {system model} {} {
|
|
|
|
if {[catch {set fp [open /etc/model r]}]} {
|
|
|
|
set model {HD[R]}
|
|
|
|
} else {
|
|
|
|
set model [string trim [read $fp]]
|
|
|
|
close $fp
|
|
|
|
}
|
|
|
|
return $model
|
|
|
|
}
|
|
|
|
|
|
|
|
proc {system hostname} {} {
|
|
|
|
if {[catch {set hostname [string trim [exec hostname]]}]} {
|
|
|
|
set hostname "humax"
|
|
|
|
}
|
|
|
|
return $hostname
|
|
|
|
}
|
|
|
|
|
2012-06-15 21:34:07 +00:00
|
|
|
proc {system ip} {} {
|
|
|
|
if {[catch {set fp [open /etc/hosts r]}]} {
|
|
|
|
set ip "127.0.0.1"
|
|
|
|
} else {
|
|
|
|
set ipl [lindex [split [$fp read] "\n"] 1]
|
|
|
|
regsub -- {[[:space:]].*} $ipl "" ip
|
|
|
|
}
|
|
|
|
return $ip
|
|
|
|
}
|
|
|
|
|
2011-11-12 23:57:19 +00:00
|
|
|
proc {system modversion} {{short 0}} {
|
2011-09-14 19:59:56 +00:00
|
|
|
if {[catch {set fp [open /etc/modversion r]}]} {
|
2011-11-12 23:57:19 +00:00
|
|
|
set modver "102"
|
2011-09-14 19:59:56 +00:00
|
|
|
} else {
|
|
|
|
set modver [string trim [read $fp]]
|
|
|
|
close $fp
|
|
|
|
}
|
2011-11-12 23:57:19 +00:00
|
|
|
if {$short} { return $modver }
|
2011-09-14 19:59:56 +00:00
|
|
|
lassign [split $modver ""] a b c
|
|
|
|
return [format "%d.%d%d" $a $b $c]
|
|
|
|
}
|
|
|
|
|
2013-01-03 22:20:57 +00:00
|
|
|
proc {system modbuild} {} {
|
|
|
|
if {[catch {set fp [open /etc/modbuild r]}]} {
|
|
|
|
return 0
|
|
|
|
} else {
|
|
|
|
set modbuild [string trim [read $fp]]
|
|
|
|
close $fp
|
|
|
|
}
|
|
|
|
return $modbuild
|
|
|
|
}
|
|
|
|
|
2012-06-03 20:12:31 +00:00
|
|
|
proc {system fhtcpversion} {} {
|
|
|
|
set file "/etc/fhtcpversion"
|
|
|
|
if {![file exists $file]} { set file "/root/fhtcpversion" }
|
|
|
|
if {[catch {set fp [open $file r]}]} {
|
|
|
|
set ver "?.??.??"
|
|
|
|
} else {
|
|
|
|
set ver [string trim [read $fp]]
|
|
|
|
close $fp
|
|
|
|
}
|
|
|
|
return $ver
|
|
|
|
}
|
|
|
|
|
2011-09-25 18:25:09 +00:00
|
|
|
proc {system pkgver} {{pkg webif}} {
|
|
|
|
return [lrange [split [exec opkg list-installed $pkg] " "] 2 end]
|
|
|
|
}
|
|
|
|
|
2013-02-25 22:31:54 +00:00
|
|
|
proc {system pkginst} {pkg} {{cache {}} {ncache {}}} {
|
|
|
|
if {$pkg in $cache} { return 1 }
|
|
|
|
if {$pkg in $ncache} { return 0 }
|
|
|
|
|
|
|
|
# It may not be possible to get an opkg lock immediately so
|
|
|
|
# try several times and throw an error if not.
|
|
|
|
set status unknown
|
|
|
|
loop i 0 5 {
|
|
|
|
if {[catch {set status [exec opkg list-installed $pkg]}]} {
|
|
|
|
sleep 1
|
|
|
|
} else break
|
|
|
|
}
|
|
|
|
if {$status eq "unknown"} {
|
2013-02-27 23:15:37 +00:00
|
|
|
error "Could not get opkg lock after 5 seconds."
|
2013-02-25 22:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if {$status ne ""} {
|
|
|
|
lappend $cache $pkg
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
lappend $ncache $pkg
|
|
|
|
return 0
|
2011-11-28 15:24:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-31 13:47:47 +00:00
|
|
|
proc {system mediaroot} {} {
|
|
|
|
switch [system model] {
|
|
|
|
HDR { return "/media/My Video" }
|
|
|
|
HD { return "/media/drive1/Video" }
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2012-01-14 00:12:07 +00:00
|
|
|
proc {system dustbin} {{short 0}} {
|
2012-01-14 23:08:54 +00:00
|
|
|
set dustbin "\[Deleted Items\]"
|
2012-01-13 23:28:48 +00:00
|
|
|
if {![catch {set fd [open "/mod/boot/dustbin.name" r]}]} {
|
|
|
|
set dustbin [lindex [split [read $fd] "\n"] 0]
|
|
|
|
$fd close
|
2012-01-10 19:51:45 +00:00
|
|
|
}
|
2012-01-14 00:12:07 +00:00
|
|
|
if {$short} { return $dustbin }
|
2012-01-13 23:28:48 +00:00
|
|
|
return "[system mediaroot]/$dustbin"
|
2012-01-10 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 19:50:10 +00:00
|
|
|
proc {system diskspace} {} {
|
|
|
|
switch [system model] {
|
|
|
|
HDR { set part /mnt/hd2 }
|
|
|
|
HD { set part /media/drive1 }
|
|
|
|
}
|
|
|
|
|
|
|
|
set size 0
|
|
|
|
set used 0
|
2012-05-21 20:23:41 +00:00
|
|
|
set free 0
|
2011-09-02 19:50:10 +00:00
|
|
|
set perc 0
|
2012-10-25 23:31:09 +00:00
|
|
|
set dev 0
|
2011-09-05 22:23:29 +00:00
|
|
|
foreach line [split [exec /mod/bin/busybox/df -h $part 2>>/dev/null] "\n\r"] {
|
2011-09-02 19:50:10 +00:00
|
|
|
if {[string match "/*" $line]} {
|
|
|
|
regsub -all -- {[[:space:]]+} $line " " line
|
|
|
|
set fields [split $line]
|
2012-10-25 23:31:09 +00:00
|
|
|
set dev [lindex $fields 0]
|
2011-09-02 19:50:10 +00:00
|
|
|
set size [lindex $fields 1]
|
|
|
|
set used [lindex $fields 2]
|
2012-05-21 20:23:41 +00:00
|
|
|
set free [lindex $fields 3]
|
2011-09-02 19:50:10 +00:00
|
|
|
set perc [string trimright [lindex $fields 4] "%"]
|
2012-05-21 20:23:41 +00:00
|
|
|
set fperc $(100 - $perc)
|
2011-09-02 19:50:10 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 23:31:09 +00:00
|
|
|
return [list $size $used $perc $free $fperc $dev]
|
2011-09-02 19:50:10 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 22:42:15 +00:00
|
|
|
proc {system disk} {} {
|
|
|
|
return [string range [lindex [system diskspace] 5] 0 end-1]
|
|
|
|
}
|
|
|
|
|
2013-02-04 22:32:21 +00:00
|
|
|
proc {system diskfree} {} {
|
|
|
|
switch [system model] {
|
|
|
|
HDR { set part /mnt/hd2 }
|
|
|
|
HD { set part /media/drive1 }
|
|
|
|
}
|
|
|
|
|
|
|
|
set free 0
|
|
|
|
foreach line [split [exec /mod/bin/busybox/df -k $part 2>>/dev/null] "\n\r"] {
|
|
|
|
if {[string match "/*" $line]} {
|
|
|
|
regsub -all -- {[[:space:]]+} $line " " line
|
|
|
|
set fields [split $line]
|
|
|
|
set free [lindex $fields 3]
|
|
|
|
set free $($free * 1024)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $free
|
|
|
|
}
|
|
|
|
|
2011-09-02 19:50:10 +00:00
|
|
|
proc {system busy} {} {
|
2011-09-26 20:31:17 +00:00
|
|
|
# Is humaxtv doing anything important?
|
2011-11-27 23:29:14 +00:00
|
|
|
if {[catch {set pid [exec /mod/bin/busybox/pgrep humaxtv]}]} {
|
|
|
|
return 0
|
|
|
|
}
|
2011-09-02 19:50:10 +00:00
|
|
|
set c 0
|
2011-09-26 20:31:17 +00:00
|
|
|
foreach line [split [exec /mod/bin/lsof -p $pid] "\n"] {
|
|
|
|
if {[string match {*Video*.ts} $line]} { incr c }
|
|
|
|
}
|
2011-09-02 19:50:10 +00:00
|
|
|
if {$c > 0} { return 1 }
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2012-01-30 21:59:18 +00:00
|
|
|
proc {system inuse} {file} {
|
2012-08-07 22:22:30 +00:00
|
|
|
# Is anything using the file?
|
|
|
|
set file [file rootname [file tail $file]]
|
2012-01-30 21:59:18 +00:00
|
|
|
set c 0
|
2012-06-15 21:34:07 +00:00
|
|
|
foreach line [split [exec /mod/bin/lsof] "\n"] {
|
2012-08-07 22:22:30 +00:00
|
|
|
if {[string first $file $line] >= 0} { incr c }
|
2012-01-30 21:59:18 +00:00
|
|
|
}
|
|
|
|
if {$c > 0} { return 1 }
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-09-02 19:50:10 +00:00
|
|
|
proc {system reboot} {} {
|
|
|
|
exec /etc/init.d/S90settop shut
|
|
|
|
exec /sbin/reboot
|
|
|
|
}
|
|
|
|
|
|
|
|
proc {system restartpending} {} {
|
|
|
|
close [open /tmp/.restartpending w]
|
|
|
|
}
|
|
|
|
|
2012-04-18 20:26:34 +00:00
|
|
|
proc {system param} {param {type Value} {tbl MENUCONFIG}} {
|
2011-09-19 17:11:18 +00:00
|
|
|
if {[catch {set db [sqlite3.open /var/lib/humaxtv/setup.db]} msg]} {
|
2012-04-08 23:26:38 +00:00
|
|
|
return 0
|
2011-09-19 17:11:18 +00:00
|
|
|
}
|
2012-04-08 23:26:38 +00:00
|
|
|
set val 0
|
|
|
|
set ret [$db query "
|
|
|
|
select item$type
|
2012-04-18 20:26:34 +00:00
|
|
|
from TBL_$tbl
|
2012-04-08 23:26:38 +00:00
|
|
|
where itemName = '$param'
|
|
|
|
"]
|
|
|
|
if {[llength $ret] == 1} {
|
|
|
|
lassign [lindex $ret 0] x val
|
2011-09-18 22:19:54 +00:00
|
|
|
}
|
|
|
|
$db close
|
2012-04-08 23:26:38 +00:00
|
|
|
return $val
|
|
|
|
}
|
|
|
|
|
|
|
|
proc {system padding} {} {
|
|
|
|
return [list \
|
|
|
|
[system param START_PADDING_TIME] \
|
|
|
|
[system param STOP_PADDING_TIME] \
|
|
|
|
]
|
2011-09-18 22:19:54 +00:00
|
|
|
}
|
|
|
|
|
2012-04-18 20:26:34 +00:00
|
|
|
proc {system instandby} {} {
|
|
|
|
return [system param LAST_STANDBY Value USERCONFIG]
|
|
|
|
}
|
|
|
|
|
2012-01-10 19:51:45 +00:00
|
|
|
proc {system mkdir_p} {dir} {
|
|
|
|
exec /mod/bin/busybox/mkdir -p $dir
|
|
|
|
}
|
|
|
|
|
2012-01-21 01:27:06 +00:00
|
|
|
proc {system listening} {{mport 0}} {
|
|
|
|
set ret {}
|
|
|
|
foreach line [split [exec /mod/bin/busybox/netstat -lntpw] "\n"] {
|
|
|
|
# Remove repeated spaces
|
|
|
|
regsub -all -- {[[:space:]]+} $line " " line
|
|
|
|
# tcp 0 0 0.0.0.0:9955 0.0.0.0:* LISTEN 169/humaxtv
|
|
|
|
lassign [split $line " "] x x x port x type app
|
|
|
|
if {$type ne "LISTEN"} { continue }
|
|
|
|
lassign [split $port ":"] x port
|
|
|
|
|
|
|
|
if {$mport && $mport != $port} { continue }
|
|
|
|
lappend ret [list $port [split $app "/"]]
|
|
|
|
}
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
proc {system is_listening} {mport} {
|
|
|
|
return [llength [system listening $mport]]
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:42:15 +00:00
|
|
|
proc {system notify} {msg} {
|
|
|
|
}
|
|
|
|
|