diff --git a/webif/html/settings/settings.jim b/webif/html/settings/settings.jim index 7b338cf..d721166 100755 --- a/webif/html/settings/settings.jim +++ b/webif/html/settings/settings.jim @@ -248,7 +248,7 @@ puts " " setting_toggle "HTTPS web server?" "https" \ - [file exists /mod/etc/mongoose.cert] 0 1 + [file exists /mod/etc/webif.pem] 0 1 puts "
diff --git a/webif/lib/bin/auto b/webif/lib/bin/auto index 3b85038..534fa3c 100755 --- a/webif/lib/bin/auto +++ b/webif/lib/bin/auto @@ -29,6 +29,7 @@ if {[lindex $argv 0] eq "-d"} { } else { set logfd [open "/mod/tmp/auto.log" "a+"] } + proc log {msg {level 1}} { if {$level > $::loglevel} return puts $::logfd "[\ @@ -58,10 +59,10 @@ foreach mod $modules { set "hook_post${mod}scan" {} } -proc register {type fn} { +proc register {type fn {priority 50}} { global "hook_$type" if {[info exists "hook_$type"]} { - lappend "hook_$type" $fn + lappend "hook_$type" [list $fn $priority] log "Registered $fn for $type hook." 1 } else { log "Unknown hook hook_$type" 0 @@ -71,8 +72,10 @@ proc register {type fn} { proc runplugin {name {ts 0}} { set var "hook_$name" global $var - foreach p [subst $$var] { - if {[catch {$p $ts} msg]} { + foreach p [lsort -index end -integer [subst $$var]] { + lassign $p fn priority + log "Running $name plugin $fn (priority $priority)" 2 + if {[catch {$fn $ts} msg]} { log "Plugin error: $msg" 0 } } diff --git a/webif/lib/overrides b/webif/lib/overrides index 37f9414..8b13789 100644 --- a/webif/lib/overrides +++ b/webif/lib/overrides @@ -1,10 +1 @@ -#proc {dict merge} {dict args} { -# foreach d $args { -# foreach k [dict keys $d] { -# dict set dict $k [dict get $d $k] -# } -# } -# return $dict -#} - diff --git a/webif/lib/pkg.class b/webif/lib/pkg.class index c0c478f..ed5a43e 100755 --- a/webif/lib/pkg.class +++ b/webif/lib/pkg.class @@ -131,19 +131,28 @@ proc {pkg loaddiagmeta} {} { } } -proc {pkg fetchmeta} {} { - set f [socket stream hummypkg.org.uk:80] - $f puts -nonewline "GET /hdrfoxt2/pkg.meta HTTP/1.1\r\n" - $f puts -nonewline "Host: hummypkg.org.uk\r\n" +proc {pkg fetchfile} {url} { + set f [socket stream hpkg.tv:80] + $f puts -nonewline "GET /hdrfoxt2/$url HTTP/1.1\r\n" + $f puts -nonewline "Host: hpkg.tv\r\n" $f puts -nonewline "Connection: close\r\n" $f puts -nonewline "\r\n" + # Skip headers in the response. set line [string trim [$f gets]] while {[string length $line]} { + #puts "Web Header: $line" set line [string trim [$f gets]] } - set ::pkgmeta [$f read] + + # Save the body + set ret [$f read] $f close + return $ret +} + +proc {pkg fetchmeta} {} { + set ::pkgmeta [pkg fetchfile pkg.meta] set ff [open "/mod/var/pkg.meta" w] puts $ff $::pkgmeta @@ -151,18 +160,7 @@ proc {pkg fetchmeta} {} { } proc {pkg fetchdiagmeta} {} { - set f [socket stream hummypkg.org.uk:80] - $f puts -nonewline "GET /diag/diag.meta HTTP/1.1\r\n" - $f puts -nonewline "Host: hummypkg.org.uk\r\n" - $f puts -nonewline "Connection: close\r\n" - $f puts -nonewline "\r\n" - - set line [string trim [$f gets]] - while {[string length $line]} { - set line [string trim [$f gets]] - } - set ::diagmeta [$f read] - $f close + set ::diagmeta [pkg fetchfile diag.meta] set ff [open "/mod/var/diag.meta" w] puts $ff $::diagmeta diff --git a/webif/lib/setup b/webif/lib/setup index b79d7da..2c74c9c 100644 --- a/webif/lib/setup +++ b/webif/lib/setup @@ -96,7 +96,7 @@ if {![exists -proc require]} { foreach c $css { _css $c } } - require fileops overrides + require fileops overrides utils # Jim 0.75 removes legacy 'case' alias case switch diff --git a/webif/lib/system.class b/webif/lib/system.class index cda30f5..ffbb864 100644 --- a/webif/lib/system.class +++ b/webif/lib/system.class @@ -119,10 +119,10 @@ proc {system pkginst} {pkg} {{cache {}} {ncache {}}} { } if {$status ne ""} { - lappend $cache $pkg + lappend cache $pkg return 1 } - lappend $ncache $pkg + lappend ncache $pkg return 0 } diff --git a/webif/lib/ts.class b/webif/lib/ts.class index 8ee0099..8a322f4 100644 --- a/webif/lib/ts.class +++ b/webif/lib/ts.class @@ -32,6 +32,10 @@ ts method bfile {} { return [file tail [file rootname $file]] } +ts method dir {} { + return [file dirname $file] +} + ts method duration {{raw 0}} { set d [expr $end - $start] if {!$raw} { set d $($d / 60) } @@ -78,49 +82,56 @@ ts method flag {f} { ts method unlock {} { set cmd [list /mod/bin/hmt -lock $file] exec {*}$cmd + lremove flags "Locked" return 1 } ts method lock {} { set cmd [list /mod/bin/hmt +lock $file] exec {*}$cmd + ladd flags "Locked" return 1 } ts method set_shrunk {} { set cmd [list /mod/bin/hmt +shrunk $file] exec {*}$cmd - lappend flags "Shrunk" + ladd flags "Shrunk" return 1 } ts method set_deduped {} { set cmd [list /mod/bin/hmt +dedup $file] exec {*}$cmd + ladd flags "Deduped" return 1 } ts method unenc {} { set cmd [list /mod/bin/hmt -protect $file] exec {*}$cmd + lremove flags "Encrypted" return 1 } ts method enc {} { set cmd [list /mod/bin/hmt +protect $file] exec {*}$cmd + ladd flags "Encrypted" return 1 } ts method set_new {} { set cmd [list /mod/bin/hmt +new $file] exec {*}$cmd + ladd flags "New" return 1 } ts method set_watched {} { set cmd [list /mod/bin/hmt -new $file] exec {*}$cmd + lremove flags "New" return 1 } @@ -205,12 +216,14 @@ ts method settitle {newtitle} { if {[string length newtitle] > 48} { return } exec /mod/bin/hmt "+settitle=${newtitle}" $file + set title $newtitle } ts method setsynopsis {newsynopsis} { if {[string length newsynopsis] > 252} { return } exec /mod/bin/hmt "+setsynopsis=${newsynopsis}" $file + set synopsis $newsynopsis } ts method setguidance {newguidance} { @@ -221,10 +234,12 @@ ts method setguidance {newguidance} { } else { exec /mod/bin/hmt "+setguidance=${newguidance}" $file } + set guidance $newguidance } ts method setgenre {newgenre} { exec /mod/bin/hmt "+setgenre=-${newgenre}" $file + set genre $newgenre } ts method dlnaloc {{urlbase 0}} { diff --git a/webif/lib/utils b/webif/lib/utils new file mode 100644 index 0000000..1ca1a00 --- /dev/null +++ b/webif/lib/utils @@ -0,0 +1,12 @@ + +proc ladd {var val} { + upvar $var v + if {$val ni $v} { lappend v $val } +} + +proc lremove {var val} { + upvar $var v + if {$val ni $v} return + set v [lsearch -all -inline -not -exact $v $val] +} +