2011-06-14 11:48:55 +00:00
|
|
|
|
2011-07-01 22:56:53 +00:00
|
|
|
if {![exists -proc class ]} { package require oo }
|
|
|
|
if {![exists -proc sqlite3.open ]} { package require sqlite3 }
|
2011-06-14 11:48:55 +00:00
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
if {![file exists /mod/etc/webif.db]} {
|
|
|
|
set settingsdb [sqlite3.open /mod/etc/webif.db]
|
|
|
|
catch {
|
|
|
|
$settingsdb query {
|
|
|
|
CREATE TABLE settings(name text, nval int, tval text);
|
|
|
|
}
|
|
|
|
$settingsdb query {
|
|
|
|
CREATE UNIQUE INDEX key on settings(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set settingsdb [sqlite3.open /mod/etc/webif.db]
|
|
|
|
}
|
2011-06-14 11:48:55 +00:00
|
|
|
|
|
|
|
class settings {
|
|
|
|
hostname ""
|
|
|
|
channel_group 0
|
2011-10-03 09:37:24 +00:00
|
|
|
epg_style "standard"
|
2011-06-16 23:49:48 +00:00
|
|
|
smtp_server ""
|
2011-07-11 23:29:21 +00:00
|
|
|
pkgdev 0
|
2011-06-14 11:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
settings method hostname {{name ""}} {
|
|
|
|
if {$name == ""} {
|
|
|
|
# Get
|
|
|
|
if {[catch {set fd [open "/var/lib/humaxtv/hostname" r]}]} {
|
|
|
|
set name "humax"
|
|
|
|
} else {
|
|
|
|
set name [string trim [read $fd]]
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
return $name
|
|
|
|
} else {
|
|
|
|
# Set
|
|
|
|
if [string is alnum -strict $name] {
|
|
|
|
set fd [open "/var/lib/humaxtv/hostname" w]
|
|
|
|
puts $fd $name
|
|
|
|
close $fd
|
|
|
|
exec hostname -F /var/lib/humaxtv/hostname
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-16 23:49:48 +00:00
|
|
|
settings method smtp_server {{server ""}} {
|
|
|
|
if {$server == ""} {
|
|
|
|
# Get
|
|
|
|
if {[catch {set fd [open "/mod/etc/ssmtp/ssmtp.conf" r]}]} {
|
|
|
|
set server "mail"
|
|
|
|
} else {
|
|
|
|
foreach line [split [read $fd] "\n"] {
|
|
|
|
set a [string first "mailhub=" $line]
|
|
|
|
if {$a == 0} {
|
|
|
|
set server [string range $line 8 end]
|
|
|
|
set server [string trim $server]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
return $server
|
|
|
|
} else {
|
|
|
|
# Set
|
|
|
|
if {[string is ascii -strict $server]} {
|
|
|
|
set fd [open "/mod/etc/ssmtp/ssmtp.conf" w]
|
|
|
|
puts $fd "mailhub=$server"
|
|
|
|
puts $fd "rewriteDomain=hummypkg.org.uk"
|
|
|
|
puts $fd "hostname=[$self hostname].hummypkg.org.uk"
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-14 11:48:55 +00:00
|
|
|
settings method _nval_setting {name {val -1}} {
|
|
|
|
global settingsdb;
|
|
|
|
|
|
|
|
if {$val == -1} {
|
|
|
|
# Get
|
|
|
|
set res [$settingsdb query "
|
|
|
|
select nval from settings
|
|
|
|
where name = '$name'
|
|
|
|
"]
|
|
|
|
if {$res ne ""} {
|
|
|
|
return [lindex [lindex $res end] end]
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
} else {
|
|
|
|
# Set
|
|
|
|
$settingsdb query "
|
|
|
|
replace into settings(name,nval)
|
|
|
|
values('$name', $val)
|
|
|
|
"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
settings method channel_group {{group -1}} {
|
|
|
|
return [$self _nval_setting channel_group $group]
|
|
|
|
}
|
|
|
|
|
2011-10-03 09:37:24 +00:00
|
|
|
settings method epg_style {{style -1}} {
|
|
|
|
if {$style != -1} {
|
|
|
|
if {$style eq "grid"} { set style 1 } else { set style 0}
|
|
|
|
return [$self _nval_setting epg_style $style]
|
|
|
|
}
|
|
|
|
set val [$self _nval_setting epg_style]
|
|
|
|
if {$val == 1} {
|
|
|
|
return "grid"
|
|
|
|
}
|
|
|
|
return "standard"
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
settings method pkgdev {{val -1}} {
|
|
|
|
return [$self _nval_setting pkgdev $val]
|
|
|
|
}
|
|
|
|
|
2011-06-14 11:48:55 +00:00
|
|
|
settings method channel_groups {} {
|
|
|
|
set ret ""
|
|
|
|
set db [sqlite3.open /var/lib/humaxtv/setup.db]
|
|
|
|
set res [$db query {
|
|
|
|
select itemText from TBL_MENUCONFIG
|
|
|
|
where itemName like 'FAV\_CUSTOM\_STR%%' ESCAPE '\'
|
|
|
|
}]
|
|
|
|
$db close
|
|
|
|
foreach g $res {
|
|
|
|
set g $g(itemText)
|
|
|
|
if {[string index $g 0] == "\025"} {
|
|
|
|
lappend ret [string range $g 1 end]
|
|
|
|
} else {
|
|
|
|
lappend ret $g
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|