2011-06-14 11:48:55 +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-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"
|
2014-02-21 21:25:33 +00:00
|
|
|
service_style "grid"
|
2011-06-16 23:49:48 +00:00
|
|
|
smtp_server ""
|
2011-07-11 23:29:21 +00:00
|
|
|
pkgdev 0
|
2012-05-21 20:23:41 +00:00
|
|
|
notoolbar 0
|
2012-10-30 18:58:54 +00:00
|
|
|
nomobile 0
|
2013-04-05 20:07:42 +00:00
|
|
|
nohelplinks 0
|
2014-01-22 21:18:12 +00:00
|
|
|
notwitfeed 0
|
2013-09-09 19:38:56 +00:00
|
|
|
nounwatchedcount 0
|
2013-01-05 22:27:00 +00:00
|
|
|
xepghours 4
|
2013-02-17 22:58:37 +00:00
|
|
|
genrededup 0
|
2013-04-03 22:42:15 +00:00
|
|
|
autolog 0
|
2013-09-18 17:54:33 +00:00
|
|
|
changechangenc 0
|
2014-03-03 14:00:46 +00:00
|
|
|
audiomp3 0
|
2011-06-14 11:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
settings method hostname {{name ""}} {
|
|
|
|
if {$name == ""} {
|
|
|
|
# Get
|
2013-10-29 20:05:15 +00:00
|
|
|
if {[catch {set fd [open "/var/lib/humaxtv/mod/hostname" r]}]} {
|
2011-06-14 11:48:55 +00:00
|
|
|
set name "humax"
|
|
|
|
} else {
|
|
|
|
set name [string trim [read $fd]]
|
|
|
|
close $fd
|
|
|
|
}
|
|
|
|
return $name
|
|
|
|
} else {
|
|
|
|
# Set
|
|
|
|
if [string is alnum -strict $name] {
|
2013-10-29 20:05:15 +00:00
|
|
|
set fd [open "/var/lib/humaxtv/mod/hostname" w]
|
2011-06-14 11:48:55 +00:00
|
|
|
puts $fd $name
|
|
|
|
close $fd
|
2013-10-29 20:05:15 +00:00
|
|
|
exec hostname -F /var/lib/humaxtv/mod/hostname
|
2011-06-14 11:48:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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}} {
|
2012-04-18 20:26:34 +00:00
|
|
|
global settingsdb
|
2011-06-14 11:48:55 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:42:15 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-14 11:48:55 +00:00
|
|
|
settings method channel_group {{group -1}} {
|
|
|
|
return [$self _nval_setting channel_group $group]
|
|
|
|
}
|
|
|
|
|
2013-01-05 22:27:00 +00:00
|
|
|
settings method xepghours {{hours -1}} {
|
|
|
|
return [$self _nval_setting xepghours $hours]
|
|
|
|
}
|
|
|
|
|
2011-10-03 09:37:24 +00:00
|
|
|
settings method epg_style {{style -1}} {
|
|
|
|
if {$style != -1} {
|
2014-02-21 21:25:33 +00:00
|
|
|
if {$style eq "grid"} { set style 1 } else { set style 0 }
|
2011-10-03 09:37:24 +00:00
|
|
|
return [$self _nval_setting epg_style $style]
|
|
|
|
}
|
|
|
|
set val [$self _nval_setting epg_style]
|
2014-02-21 21:25:33 +00:00
|
|
|
if {$val == 1} { return "grid" }
|
2011-10-03 09:37:24 +00:00
|
|
|
return "standard"
|
|
|
|
}
|
|
|
|
|
2014-02-21 21:25:33 +00:00
|
|
|
settings method service_style {{style -1}} {
|
|
|
|
if {$style != -1} {
|
|
|
|
if {$style eq "grid"} { set style 0 } else { set style 1 }
|
|
|
|
return [$self _nval_setting service_style $style]
|
|
|
|
}
|
|
|
|
set val [$self _nval_setting service_style]
|
|
|
|
if {$val == 1} { return "standard" }
|
|
|
|
return "grid"
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
settings method pkgdev {{val -1}} {
|
|
|
|
return [$self _nval_setting pkgdev $val]
|
|
|
|
}
|
|
|
|
|
2012-05-21 20:23:41 +00:00
|
|
|
settings method notoolbar {{val -1}} {
|
|
|
|
return [$self _nval_setting notoolbar $val]
|
|
|
|
}
|
|
|
|
|
2013-02-17 22:58:37 +00:00
|
|
|
settings method genrededup {{val -1}} {
|
|
|
|
return [$self _nval_setting genrededup $val]
|
|
|
|
}
|
|
|
|
|
2012-10-30 18:58:54 +00:00
|
|
|
settings method nomobile {{val -1}} {
|
|
|
|
return [$self _nval_setting nomobile $val]
|
|
|
|
}
|
|
|
|
|
2013-04-05 20:07:42 +00:00
|
|
|
settings method nohelplinks {{val -1}} {
|
|
|
|
return [$self _nval_setting nohelplinks $val]
|
|
|
|
}
|
|
|
|
|
2014-01-22 21:18:12 +00:00
|
|
|
settings method notwitfeed {{val -1}} {
|
|
|
|
return [$self _nval_setting notwitfeed $val]
|
|
|
|
}
|
|
|
|
|
2013-09-09 19:38:56 +00:00
|
|
|
settings method nounwatchedcount {{val -1}} {
|
|
|
|
return [$self _nval_setting nounwatchedcount $val]
|
|
|
|
}
|
|
|
|
|
2013-09-18 17:54:33 +00:00
|
|
|
settings method chanchangenc {{val -1}} {
|
|
|
|
return [$self _nval_setting chanchangenc $val]
|
|
|
|
}
|
|
|
|
|
2011-12-06 00:13:41 +00:00
|
|
|
settings method sortorder {{val -1}} {
|
|
|
|
return [$self _nval_setting sortorder $val]
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:42:15 +00:00
|
|
|
settings method autolog {{level -1}} {
|
|
|
|
return [$self _nval_setting autolog $level]
|
|
|
|
}
|
|
|
|
|
2014-03-03 14:00:46 +00:00
|
|
|
settings method audiomp3 {{val -1}} {
|
|
|
|
return [$self _nval_setting audiomp3 $val]
|
|
|
|
}
|
|
|
|
|
|
|
|
settings method audiomp3descr {val} {
|
|
|
|
switch $val {
|
|
|
|
1 { return "MPEG-1 Audio Layer III (MP3)" }
|
|
|
|
default { return "MPEG-1 Audio Layer II (MP2)" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-11-12 23:57:19 +00:00
|
|
|
settings method aclusers {} {
|
|
|
|
if {![file exists "/mod/etc/htpasswd"]} { return {} }
|
|
|
|
set fd [open "/mod/etc/htpasswd" r]
|
|
|
|
set users {}
|
|
|
|
foreach line [string trim [split [read $fd] "\n"]] {
|
|
|
|
set info [split $line ":"]
|
|
|
|
if {[llength $info] != 3} { continue }
|
|
|
|
lappend users $info
|
|
|
|
}
|
|
|
|
$fd close
|
|
|
|
return $users
|
|
|
|
}
|
|
|
|
|
2014-04-22 00:03:29 +00:00
|
|
|
# Legacy function for Mongoose.
|
|
|
|
|
2011-11-12 23:57:19 +00:00
|
|
|
settings method mongooseauth {{mode 1}} {
|
2014-04-22 00:03:29 +00:00
|
|
|
if {![file exists /mod/etc/mongoose.conf]} return
|
2011-11-12 23:57:19 +00:00
|
|
|
set fd [open "/mod/etc/mongoose.conf" r]
|
|
|
|
set fdnew [open "/mod/etc/mongoose.conf.new" w]
|
|
|
|
foreach line [string trim [split [read $fd] "\n"]] {
|
|
|
|
if {[string match -nocase {authentication_domain*} $line]} {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if {[string match -nocase {global_passwords_file*} $line]} {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if {$line ne ""} { puts $fdnew $line }
|
|
|
|
}
|
|
|
|
$fd close
|
|
|
|
if {$mode} {
|
|
|
|
puts $fdnew "authentication_domain webif"
|
|
|
|
puts $fdnew "global_passwords_file /mod/etc/htpasswd"
|
|
|
|
}
|
|
|
|
$fdnew close
|
|
|
|
file delete "/mod/etc/mongoose.conf"
|
|
|
|
file rename "/mod/etc/mongoose.conf.new" "/mod/etc/mongoose.conf"
|
|
|
|
}
|
|
|
|
|
2014-04-22 00:03:29 +00:00
|
|
|
settings method htdigest {user pass} {
|
|
|
|
set str "$user:webif:$pass"
|
|
|
|
set hash [string range [exec echo -n $str | md5sum] 0 32]
|
|
|
|
return "$user:webif:$hash"
|
2011-11-12 23:57:19 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 00:03:29 +00:00
|
|
|
settings method modacluser {user {pass 0}} {
|
2011-11-12 23:57:19 +00:00
|
|
|
set fdnew [open "/mod/etc/htpasswd.new" w]
|
2014-04-22 00:03:29 +00:00
|
|
|
|
|
|
|
# Remove existing user, if present.
|
|
|
|
if {[file exists "/mod/etc/htpasswd"]} {
|
|
|
|
set fd [open "/mod/etc/htpasswd" r]
|
|
|
|
set num 0
|
|
|
|
foreach line [string trim [split [read $fd] "\n"]] {
|
|
|
|
lassign [split $line ":"] xuser
|
|
|
|
if {$xuser eq $user} { continue }
|
|
|
|
if {$line ne ""} {
|
|
|
|
puts $fdnew $line
|
|
|
|
incr num
|
|
|
|
}
|
2011-11-12 23:57:19 +00:00
|
|
|
}
|
2014-04-22 00:03:29 +00:00
|
|
|
$fd close
|
2011-11-12 23:57:19 +00:00
|
|
|
}
|
2014-04-22 00:03:29 +00:00
|
|
|
|
|
|
|
# Add user, if required.
|
|
|
|
if {$pass ne "0"} {
|
|
|
|
puts $fdnew [$self htdigest $user $pass]
|
|
|
|
incr num
|
|
|
|
set msg "Added/updated user $user"
|
|
|
|
} else {
|
|
|
|
set msg "Removed user $user"
|
|
|
|
}
|
|
|
|
|
2011-11-12 23:57:19 +00:00
|
|
|
$fdnew close
|
|
|
|
file delete "/mod/etc/htpasswd"
|
|
|
|
file rename "/mod/etc/htpasswd.new" "/mod/etc/htpasswd"
|
|
|
|
|
2014-04-22 00:03:29 +00:00
|
|
|
$self mongooseauth $num
|
|
|
|
|
2011-11-12 23:57:19 +00:00
|
|
|
return $msg
|
|
|
|
}
|
|
|
|
|
2014-04-22 00:03:29 +00:00
|
|
|
settings method addacluser {user pass} {
|
|
|
|
return [$self modacluser $user $pass]
|
|
|
|
}
|
|
|
|
|
|
|
|
settings method delacluser {user} {
|
|
|
|
return [$self modacluser $user]
|
|
|
|
}
|
|
|
|
|
2013-04-03 22:42:15 +00:00
|
|
|
settings method smartdata {} {
|
|
|
|
global settingsdb
|
|
|
|
|
|
|
|
set res [$settingsdb query "
|
|
|
|
select name, nval, tval from settings
|
|
|
|
where name like 'SMART_%%'
|
|
|
|
"]
|
|
|
|
|
|
|
|
return $res
|
|
|
|
}
|
|
|
|
|