From ded94955950133742a4a8e628c4a86225289e91c Mon Sep 17 00:00:00 2001 From: hummypkg Date: Mon, 11 Jul 2011 23:29:21 +0000 Subject: [PATCH] re-implemented package management. Initial suppor for remote scheduling git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@265 2a923420-c742-0410-a762-8d5b09965624 --- var/mongoose/cgi-bin/backup/delete.jim | 2 +- var/mongoose/cgi-bin/backup/files.jim | 2 +- var/mongoose/cgi-bin/db.jim | 45 ++++++++++ var/mongoose/cgi-bin/epg_info.jim | 10 ++- var/mongoose/cgi-bin/epg_schedule.jim | 73 ++++++++++++++++ var/mongoose/cgi-bin/epg_service.jim | 1 + var/mongoose/cgi-bin/opkg.jim | 31 ++++++- var/mongoose/cgi-bin/pkg.jim | 98 ++++++++++++++++++++++ var/mongoose/cgi-bin/settings.jim | 36 ++++++++ var/mongoose/html/index.shtml | 6 +- var/mongoose/html/js/packages.js | 33 -------- var/mongoose/html/lib/header.jim | 2 - var/mongoose/html/packages.shtml | 21 ----- var/mongoose/html/pkg.shtml | 111 +++++++++++++++++++++++++ var/mongoose/include/diskspace.jim | 2 +- var/mongoose/include/packages.jim | 59 ------------- var/mongoose/include/pkg.jim | 46 ++++++++++ var/mongoose/lib/epg.class | 83 +++++++++++++----- var/mongoose/lib/epg_popup | 42 +++++++++- var/mongoose/lib/opkg | 2 +- var/mongoose/lib/pkg.class | 87 +++++++++++-------- var/mongoose/lib/rsv.class | 59 +++++++++++-- var/mongoose/lib/settings.class | 19 ++++- 23 files changed, 678 insertions(+), 192 deletions(-) create mode 100755 var/mongoose/cgi-bin/db.jim create mode 100755 var/mongoose/cgi-bin/epg_schedule.jim create mode 100755 var/mongoose/cgi-bin/pkg.jim delete mode 100755 var/mongoose/html/js/packages.js delete mode 100644 var/mongoose/html/packages.shtml create mode 100644 var/mongoose/html/pkg.shtml delete mode 100755 var/mongoose/include/packages.jim create mode 100755 var/mongoose/include/pkg.jim diff --git a/var/mongoose/cgi-bin/backup/delete.jim b/var/mongoose/cgi-bin/backup/delete.jim index 71043f6..7f4d4bc 100755 --- a/var/mongoose/cgi-bin/backup/delete.jim +++ b/var/mongoose/cgi-bin/backup/delete.jim @@ -6,7 +6,7 @@ source /mod/var/mongoose/lib/setup set dir /mod/var/backup puts "Content-Type: text/html" -puts "Pragma: nocache" +puts "Pragma: no-cache" puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT" puts "" diff --git a/var/mongoose/cgi-bin/backup/files.jim b/var/mongoose/cgi-bin/backup/files.jim index 8c4fdea..3b0a2a0 100755 --- a/var/mongoose/cgi-bin/backup/files.jim +++ b/var/mongoose/cgi-bin/backup/files.jim @@ -3,7 +3,7 @@ package require cgi puts "Content-Type: text/html" -puts "Pragma: nocache" +puts "Pragma: no-cache" puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT" puts "" diff --git a/var/mongoose/cgi-bin/db.jim b/var/mongoose/cgi-bin/db.jim new file mode 100755 index 0000000..8f85ace --- /dev/null +++ b/var/mongoose/cgi-bin/db.jim @@ -0,0 +1,45 @@ +#!/mod/bin/jimsh + +package require sqlite3 +source /mod/var/mongoose/lib/setup +require altrow + +proc db_info {db_file} { + if {![file exists $db_file]} { return } + set db [sqlite3.open $db_file] + set tables [$db query {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}] + + puts "

$db_file

" + + foreach table $tables { + set table_name [lindex $table 1] + set columns [$db query "pragma table_info($table_name)"] + set datas [$db query "SELECT * FROM $table_name"] + + puts "

$table_name

" + puts "" + puts " " + foreach column $columns { + puts " " + } + puts " " + foreach data $datas { + altrow + + for {set i 1} {$i < [llength $data]} {incr i 2} { + puts " " + } + puts " " + } + puts "
[lindex $column 3]
[lindex $data $i]
" + } + + $db close +} + +puts {} +db_info /var/lib/humaxtv/rsv.db +db_info /var/lib/humaxtv/setup.db +db_info /var/lib/humaxtv/channel.db +#db_info /mnt/hd2/dms_cds.db + diff --git a/var/mongoose/cgi-bin/epg_info.jim b/var/mongoose/cgi-bin/epg_info.jim index 2f0e1bf..53cdd4b 100755 --- a/var/mongoose/cgi-bin/epg_info.jim +++ b/var/mongoose/cgi-bin/epg_info.jim @@ -35,7 +35,13 @@ puts " [clock format [$record get start] -format {%c %Z}] Duration - [clock format [$record get duration] -format %T] + [clock format [$record get duration] -format %T] +" +if {[$record showing]} { + puts [progressbar [$record percent]] +} +puts " + Type [$record get content_type] ([$record get content_code]) @@ -103,6 +109,8 @@ puts " " +puts "
" + epg cleanup if {! [dict exists $_cgi bare]} { footer } diff --git a/var/mongoose/cgi-bin/epg_schedule.jim b/var/mongoose/cgi-bin/epg_schedule.jim new file mode 100755 index 0000000..184be43 --- /dev/null +++ b/var/mongoose/cgi-bin/epg_schedule.jim @@ -0,0 +1,73 @@ +#!/mod/bin/jimsh + +package require cgi +source /mod/var/mongoose/lib/setup +require epg.class + +puts "Content-Type: text/html" +puts "" + +cgi_input +#cgi_dump + +#set _cgi(service) 4351 +#set _cgi(event) 41795 +#set _cgi(type) 1 + +if {![dict exists $_cgi service] || ![dict exists $_cgi event]} { + puts "Error, insufficient parameters passed." + exit +} + +set service $_cgi(service) +set event $_cgi(event) +set type 1 +if {[dict exists $_cgi type]} { set type $_cgi(type) } + +set event [lindex [epg fetch dump -service $service -event $event] 0] +if {$event eq ""} { + puts "Error, cannot find event to schedule." + exit +} +if {[$event percent] > 0} { + puts "Error, cannot record programme which has already started showing." + exit +} + +$event get_channel_info + +set args {} + +set args(ersvtype) 3 +set args(hsvc) [$event get channel_hsvc] +set args(nsttime) [$event get start] +set args(nduration) [$event get duration] +set args(usevtid) [$event get event_id] +set args(szevtname) "\025[$event get name]" +set args(eReady) 30 + +if {$type == 1} { + # Event + set args(ucCRIDType) 49 + set args(ucRecKind) 1 + set args(szCRID) "[$event get channel_crid][$event get event_crid]" + set args(szEventToRecord) "1$args(szCRID)|" +} else { + # Series + set args(ucCRIDType) 50 + set args(ucRecKind) 4 + set args(szCRID) "[$event get channel_crid][$event get series_crid]" + set args(szFPBRecPath) "$args(szevtname)" +} + +set msg "" +#set msg "Testing" +if {$msg ne "" || [catch {[rsv new $args] insert} msg]} { + puts "Error encountered while scheduling the recording: $msg" +} else { + puts "Successfully scheduled recording of [$event get name]" + #close [open /tmp/.restartpending w] +} + +epg cleanup + diff --git a/var/mongoose/cgi-bin/epg_service.jim b/var/mongoose/cgi-bin/epg_service.jim index 1368d44..1fadae6 100755 --- a/var/mongoose/cgi-bin/epg_service.jim +++ b/var/mongoose/cgi-bin/epg_service.jim @@ -54,6 +54,7 @@ puts { set i 0 foreach record $records { altrow + $record get_channel_info if {[$record showing]} { puts "" } else { puts "" } diff --git a/var/mongoose/cgi-bin/opkg.jim b/var/mongoose/cgi-bin/opkg.jim index eb032b9..705b6f5 100755 --- a/var/mongoose/cgi-bin/opkg.jim +++ b/var/mongoose/cgi-bin/opkg.jim @@ -1,8 +1,11 @@ #!/mod/bin/jimsh package require cgi +source /mod/var/mongoose/lib/setup +require pkg.class puts "Content-Type: text/html" +puts "Transfer-Encoding: chunked" puts "" cgi_input @@ -10,9 +13,33 @@ cgi_input #set _cgi(cmd) {remove binutils} -if {![dict exists $_cgi cmd]} { set _cgi(cmd) status } +if {![dict exists $_cgi cmd]} { set _cgi(cmd) update } set cmd [dict get $_cgi cmd] -puts [exec /mod/var/mongoose/lib/opkg {*}$cmd] +proc chunk {chk} { + puts -nonewline [format "%x\r\n" [string length $chk]] + puts -nonewline "$chk\r\n" + flush stdout +} + +# Kick the browser into life... +chunk [string range [format "%301d" 0] 1 end-1] + +#puts [exec /mod/var/mongoose/lib/opkg {*}$cmd] +set bcmd "|/mod/var/mongoose/lib/opkg $cmd" +set fd [open $bcmd r] +while {[gets $fd line] >= 0} { + chunk "$line\r\n" +} +close $fd + +if {$cmd eq "update"} { + chunk "Updating package meta information\r\n" + pkg fetchmeta + chunk "Done.\r\n" +} + +chunk "" +puts "\r\n" diff --git a/var/mongoose/cgi-bin/pkg.jim b/var/mongoose/cgi-bin/pkg.jim new file mode 100755 index 0000000..9d435ff --- /dev/null +++ b/var/mongoose/cgi-bin/pkg.jim @@ -0,0 +1,98 @@ +#!/mod/bin/jimsh + +package require cgi +source /mod/var/mongoose/lib/setup +require settings.class pkg.class altrow + +if {[[settings] pkgdev]} { set filter 0 } else { set filter 1 } + +puts "Content-Type: text/html" +puts "Pragma: no-cache" +puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT" +puts "" + +cgi_input +#cgi_dump +if {![dict exists $_cgi type]} { set _cgi(type) avail } + +proc pkgrow {pkg} { + set name [$pkg get name] + altrow + puts " + $name + " + + if {$::type eq "avail"} { + puts "[$pkg get latest]" + } else { + puts "[$pkg get installed]" + } + + if {$::type eq "upgr"} { + puts "[$pkg get latest]" + } + + if {[dict exists $::pkgmeta $name]} { + puts "$::pkgmeta($name)" + } else { + puts "[$pkg get descr]" + } + + if {![$pkg is installed]} { + set type Install + } elseif {$::type eq "upgr" && [$pkg is upgradable]} { + set type Upgrade + } else { + set type Remove + } + + puts "" + + puts "" +} + +pkg loadmeta + +set type $_cgi(type) + +set pkgs [pkg $type] + +if {[llength $pkgs] > 0} { + puts "" + + if {$type eq "avail"} { + puts "" + } else { + puts "" + } + + if {$type eq "upgr"} { + puts "" + } + + puts " + + + + " + + foreach pkg $pkgs { + if {$filter && ![dict exists $::pkgmeta $pkg]} { continue } + pkgrow [pkg load $pkg] + } + puts "
PackageAvailableInstalledAvailDescription  Action  
" + if {$filter} { + puts "This is a filtered package list. To show all packages, enable the Show development and advanced packages in the settings screen." + } +} else { + puts "No packages " + switch $type { + inst { puts "are installed." } + upgr { puts "are available for upgrade." } + avail { puts "are available for installation." } + } + puts "" +} + diff --git a/var/mongoose/cgi-bin/settings.jim b/var/mongoose/cgi-bin/settings.jim index 3cf857d..132c432 100755 --- a/var/mongoose/cgi-bin/settings.jim +++ b/var/mongoose/cgi-bin/settings.jim @@ -16,6 +16,7 @@ set settings [settings new] set hostname [$settings hostname] set smtp_server [$settings smtp_server] set channel_group [$settings channel_group] +set pkgdev [$settings pkgdev] # Handle updates @@ -50,6 +51,10 @@ proc handle_str_update {var old {text "Value"}} { handle_str_update hostname $hostname Hostname _handle_update ascii smtp_server $smtp_server "SMTP Server" handle_int_update channel_group $channel_group "Channel Group" +if {[dict exists $_cgi pkgdevoff] && ![dict exists $_cgi pkgdev]} { + set _cgi(pkgdev) 0 +} +handle_int_update pkgdev $pkgdev "Development Package Display" header @@ -76,6 +81,9 @@ puts { } puts " + +
General Settings @@ -155,6 +163,34 @@ puts " " +puts " + +
+

+
+ Advanced Settings + +" + +puts " + + + + + + +} + puts "
Show development and advanced packages? + + + + +
+
diff --git a/var/mongoose/html/index.shtml b/var/mongoose/html/index.shtml index f053b3a..90a3757 100644 --- a/var/mongoose/html/index.shtml +++ b/var/mongoose/html/index.shtml @@ -60,7 +60,7 @@ $(document).ready(function() { -
+
@@ -77,11 +77,11 @@ $(document).ready(function() {
- +
- + Package Management
diff --git a/var/mongoose/html/js/packages.js b/var/mongoose/html/js/packages.js deleted file mode 100755 index 20c214b..0000000 --- a/var/mongoose/html/js/packages.js +++ /dev/null @@ -1,33 +0,0 @@ - -$(document).ready(function() { - $('button').button(); - - var $dialog = $('#dialogue').dialog({ - title: "Package Management Results", - modal: false, autoOpen: false, - height: 500, width: 700, - show: 'scale', hide: 'fade', - draggable: true, resizable: true, - buttons: { "Close": - function() {$(this).dialog('close');}}, - close: function(e,u) { window.location.reload(true); } - }); - - var opkg = '/cgi-bin/opkg.jim?cmd='; - - $('#opkgupdate').click(function() { - $('#result_txt').load(opkg + 'update'); - $('#results').show('slow'); - }); - - $('button.remove, button.install, button.upgrade').click(function() { - $('#dspinner').show(); - $('#dresults').load( - opkg + encodeURIComponent( - $(this).attr('action') + ' ' + $(this).attr('id') - ), - function() { $('#dspinner').hide('slow') }); - $dialog.dialog('open'); - }); -}); - diff --git a/var/mongoose/html/lib/header.jim b/var/mongoose/html/lib/header.jim index 77914fc..1b0cb98 100644 --- a/var/mongoose/html/lib/header.jim +++ b/var/mongoose/html/lib/header.jim @@ -6,8 +6,6 @@ puts { source /mod/var/mongoose/include/model.jim puts { - - diff --git a/var/mongoose/html/packages.shtml b/var/mongoose/html/packages.shtml deleted file mode 100644 index e85ce0f..0000000 --- a/var/mongoose/html/packages.shtml +++ /dev/null @@ -1,21 +0,0 @@ - - -

Package Management - -

- - - - - - - diff --git a/var/mongoose/html/pkg.shtml b/var/mongoose/html/pkg.shtml new file mode 100644 index 0000000..64e7931 --- /dev/null +++ b/var/mongoose/html/pkg.shtml @@ -0,0 +1,111 @@ + + + + +
+

Package Management

+ + + +
+ + + + + + + + + + diff --git a/var/mongoose/include/diskspace.jim b/var/mongoose/include/diskspace.jim index 78a42e5..982554c 100755 --- a/var/mongoose/include/diskspace.jim +++ b/var/mongoose/include/diskspace.jim @@ -6,7 +6,7 @@ if {[os.gethostname] eq "hosting"} { set perc "10" } else { foreach df [split [exec df -h 2>>/dev/null] "\n\r"] { - if [string match *sd*2* $df] { + if [string match *sd?2* $df] { regsub -all -- {[[:space:]]+} $df " " df set fields [split $df] set size [lindex $fields 1] diff --git a/var/mongoose/include/packages.jim b/var/mongoose/include/packages.jim deleted file mode 100755 index ff61b0f..0000000 --- a/var/mongoose/include/packages.jim +++ /dev/null @@ -1,59 +0,0 @@ -#!/mod/bin/jimsh - -source /mod/var/mongoose/lib/setup -require pkg.class - -puts { - - - - - - - - - - - - - -} - -set avail [pkg avail] -foreach name [lsort [array names avail]] { - set pkg [pkg load $name $avail($name)] - - if {![$pkg is installed]} { - puts "" - } elseif {[$pkg is upgradable]} { - puts "" - } else { - puts "" - } - - puts " - - - - - " - - if {![$pkg is installed]} { - set type Install - } elseif {[$pkg is upgradable]} { - set type Upgrade - } else { - set type Remove - } - - puts "" - - puts "" -} - -puts "
PackageInstalledAvailDescription
$name[$pkg get installed][$pkg get latest][$pkg get descr]
" - diff --git a/var/mongoose/include/pkg.jim b/var/mongoose/include/pkg.jim new file mode 100755 index 0000000..b2270d5 --- /dev/null +++ b/var/mongoose/include/pkg.jim @@ -0,0 +1,46 @@ +#!/mod/bin/jimsh + +source /mod/var/mongoose/lib/setup + +puts { + + + + + +} + + diff --git a/var/mongoose/lib/epg.class b/var/mongoose/lib/epg.class index 0bba969..8061c4c 100644 --- a/var/mongoose/lib/epg.class +++ b/var/mongoose/lib/epg.class @@ -2,9 +2,8 @@ source /mod/var/mongoose/lib/setup if {![exists -proc class ]} { package require oo } if {![exists -proc sqlite3.open ]} { package require sqlite3 } -if {![exists -proc settings ]} { require settings.class } -require progressbar +require settings.class progressbar rsv.class set ::channeldb 0 catch { set ::channeldb [sqlite3.open /var/lib/humaxtv/channel.db] } @@ -15,6 +14,8 @@ if {![file exists $::epgpath] && [file exists $::hdepgpath]} { set ::epgpath $::hdepgpath } +set ::rsvlookup [rsv lookuptab] + # * service_id, event_id, start, duration, encrypted, name, text # * warning, content code, content type, # * event CRID, series CRID, rec CRID @@ -37,6 +38,10 @@ class epg { channel_num 0 channel_name "" channel_crid "" + channel_hsvc 0 + + sched_type 0 + rsv 0 } epg method _parse {line} { @@ -82,7 +87,7 @@ epg method remaining {} { epg method type_icon {} { set img "" - switch -- [$self get content_code] { + switch -- $content_code { 1 { set img "Movie" } 2 { set img "News" } 3 { set img "Show" } @@ -110,7 +115,7 @@ proc {epg channelicon} {name {width 0} {style ""}} { } epg method channel_icon {{width 0} {style ""}} { - set str " 0} { append str " width=$width" } if {$style ne ""} { append str " style=\"$style\" } append str " alt=\"\">" @@ -122,58 +127,90 @@ epg method get_channel_info {} { if {!$channel_num && $channeldb != ""} { set chan [lindex [$channeldb query { - select szSvcName, usLcn, aucDefaultAuthority + select szSvcName, usLcn, aucDefaultAuthority, hsvc from TBL_SVC - where usSvcId = %s} "[$self get service_id]" + where usSvcId = %s} $service_id ] 0] if {[dict exists $chan usLcn]} { set channel_num $chan(usLcn) set channel_name [string range $chan(szSvcName) 1 end] set channel_crid [string toupper $chan(aucDefaultAuthority)] + set channel_hsvc $chan(hSvc) } } } +epg method get_rsv {} { + if {$hsvc == 0} { $self get_channel_info } + if {$hsvc == 0} { return } + + if {$rsv == 0 && $event_crid ne ""} { + set rsv [rsv entry $event_crid $hsvc] + } + if {$rsv == 0 && $series_crid ne ""} { + set rsv [rsv entry $series_crid $hsvc] + } +} + epg method icon_set {{height 0}} { if {$height > 0} { set height "height=$height" } else { set height "" } set icon [$self type_icon] set set "" if {$icon != ""} { lappend set "\"[$self" + alt=\"$content_type\" title=\"$content_type\">" } - if {[$self get rec_crid] != ""} { + + set sched_type 0 + if {$event_crid ne "" && "$channel_hsvc$event_crid" in $::rsvlookup} { + set sched_type 1 lappend set \ - "" + "" + } elseif {$series_crid ne "" && + "$channel_hsvc$series_crid" in $::rsvlookup} { + set sched_type 2 } - if {[$self get series_crid] != ""} { + + if {$sched_type == 2} { + lappend set \ + "" + } elseif {$series_crid ne ""} { lappend set \ "" } + + if {$rec_crid ne ""} { + lappend set \ + "" + } + return $set } epg method cell {} { - set name [$self get name] - set text [$self get text] - set percent [$self percent] puts "" puts [join [$self icon_set 14] ""] + if {$series_crid ne ""} { + set recopts 2 + } else { + set recopts 1 + } + puts " - - $name" + + $name + " puts "
" puts "" - puts "[clock format [$self get start] -format %H:%M]" - puts " ([clock format [$self get duration] -format %T])" + puts "[clock format $start -format %H:%M]" + puts " ([clock format $duration -format %T])" if {$percent > 0 && $percent < 100} { puts "
[progressbar $percent]" puts "$percent% [clock format [$self elapsed] -format %T] / @@ -184,8 +221,8 @@ epg method cell {} { } epg method next {} { - set tm [expr [$self get start] + [$self get duration] + 60] - set nextlist [epg fetch dump -service [$self get service_id] -time $tm] + set tm $($start + $duration + 60) + set nextlist [epg fetch dump -service $service_id -time $tm] if {[llength nextlist] > 0} { return [lindex $nextlist 0] @@ -196,9 +233,9 @@ epg method next {} { epg method recommended {} { set rec "" - if {[$self get rec_crid] != ""} { + if {$rec_crid ne ""} { catch { set rec [lindex [ - epg fetch dump -crid [$self get rec_crid]] 0] } + epg fetch dump -crid $rec_crid] 0] } } return $rec } diff --git a/var/mongoose/lib/epg_popup b/var/mongoose/lib/epg_popup index a017a70..bd82c6f 100644 --- a/var/mongoose/lib/epg_popup +++ b/var/mongoose/lib/epg_popup @@ -2,23 +2,61 @@ puts {