forked from hummypkg/webif
initial backup function
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@235 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
parent
5f6c7a843c
commit
5523ec6a43
73
var/mongoose/cgi-bin/backup/backup.jim
Executable file
73
var/mongoose/cgi-bin/backup/backup.jim
Executable file
@ -0,0 +1,73 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
package require cgi
|
||||
source /mod/var/mongoose/lib/setup
|
||||
|
||||
require rsv.class
|
||||
|
||||
set dir /mod/var/backup
|
||||
|
||||
puts "Content-Type: text/html"
|
||||
puts ""
|
||||
|
||||
cgi_input
|
||||
#cgi_dump
|
||||
|
||||
if {![dict exists $_cgi file]} {
|
||||
puts "No filename supplied."
|
||||
exit
|
||||
}
|
||||
|
||||
set file [file tail [dict get $_cgi file]]
|
||||
set ffile "/$dir/$file"
|
||||
|
||||
if {[file exists $ffile]} {
|
||||
puts "Backup file <i>$file</i> already exists."
|
||||
exit
|
||||
}
|
||||
|
||||
if {[catch { set fd [open $ffile w] } msg]} {
|
||||
puts "Error creating backup file. - $msg"
|
||||
exit
|
||||
}
|
||||
|
||||
puts "Backing up scheduled recordings and events..."
|
||||
|
||||
set events [rsv list]
|
||||
|
||||
set fields [lsort [[rsv] vars]]
|
||||
|
||||
puts $fd "# [join $fields "\t"]"
|
||||
|
||||
foreach event $events {
|
||||
puts " Backing up scheduled event '[$event name]'"
|
||||
|
||||
foreach f $fields {
|
||||
puts -nonewline $fd "event\t[$event get $f]\t"
|
||||
}
|
||||
puts $fd ""
|
||||
}
|
||||
puts "Done."
|
||||
|
||||
puts "Backing up channel favourites..."
|
||||
|
||||
set grp 0
|
||||
foreach res [$rsvdb query {
|
||||
select eFavGroup,
|
||||
TBL_FAV.eSvcType,
|
||||
substr(szSvcName, 2) as szSvcName
|
||||
from TBL_FAV join TBL_SVC using (hSvc)
|
||||
order by eFavGroup
|
||||
}] {
|
||||
if {$res(eFavGroup) != $grp} {
|
||||
set grp $res(eFavGroup)
|
||||
puts " Group $grp"
|
||||
}
|
||||
puts " $res(szSvcName)"
|
||||
puts $fd "fav\t$res(eFavGroup)\t$res(eSvcType)\t$res(szSvcName)"
|
||||
}
|
||||
puts "Done."
|
||||
|
||||
close $fd
|
||||
rsv cleanup
|
||||
|
45
var/mongoose/cgi-bin/backup/backup.js
Executable file
45
var/mongoose/cgi-bin/backup/backup.js
Executable file
@ -0,0 +1,45 @@
|
||||
|
||||
function refresh_files()
|
||||
{
|
||||
$('#backup_files').load('/cgi-bin/backup/files.jim', function() {
|
||||
$('input.restore').change(function() {
|
||||
$('#restore_button').removeAttr('disabled')
|
||||
.button('option', 'disabled', false);
|
||||
$('#delete_button').removeAttr('disabled')
|
||||
.button('option', 'disabled', false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$('button').button();
|
||||
|
||||
refresh_files();
|
||||
|
||||
$('#backup_button').click(function() {
|
||||
$('#backup_working').slideDown();
|
||||
$('#results').load('/cgi-bin/backup/backup.jim?' +
|
||||
$('#backup_name').serialize(), function() {
|
||||
$('#results').slideDown(function() {
|
||||
$('#backup_working').slideUp();
|
||||
refresh_files();
|
||||
});
|
||||
});
|
||||
});
|
||||
$('#delete_button').click(function() {
|
||||
var backup = $('input.restore').val();
|
||||
if (confirm('Confirm deletion of ' + backup))
|
||||
{
|
||||
$('#results').load('/cgi-bin/backup/delete.jim?' +
|
||||
$('input.restore').serialize(), function() {
|
||||
$('#results').slideDown(function() {
|
||||
refresh_files();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
$('#restore_button').click(function() {
|
||||
console.log('Clicked');
|
||||
});
|
||||
});
|
||||
|
31
var/mongoose/cgi-bin/backup/delete.jim
Executable file
31
var/mongoose/cgi-bin/backup/delete.jim
Executable file
@ -0,0 +1,31 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
package require cgi
|
||||
source /mod/var/mongoose/lib/setup
|
||||
|
||||
set dir /mod/var/backup
|
||||
|
||||
puts "Content-Type: text/html"
|
||||
puts "Pragma: nocache"
|
||||
puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
|
||||
puts ""
|
||||
|
||||
cgi_input
|
||||
#cgi_dump
|
||||
|
||||
if {![dict exists $_cgi restore_file]} {
|
||||
puts "No filename supplied."
|
||||
exit
|
||||
}
|
||||
|
||||
set file [file tail [dict get $_cgi restore_file]]
|
||||
set ffile "/$dir/$file"
|
||||
|
||||
if {![file exists $ffile]} {
|
||||
puts "Backup file <i>$file</i> does not exist."
|
||||
} elseif {[catch { file delete $ffile } msg]} {
|
||||
puts "Deletion failed: $msg"
|
||||
} else {
|
||||
puts "Successfully deleted <i>$file</i>"
|
||||
}
|
||||
|
39
var/mongoose/cgi-bin/backup/files.jim
Executable file
39
var/mongoose/cgi-bin/backup/files.jim
Executable file
@ -0,0 +1,39 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
package require cgi
|
||||
|
||||
puts "Content-Type: text/html"
|
||||
puts "Pragma: nocache"
|
||||
puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
|
||||
puts ""
|
||||
|
||||
set dir "/mod/var/backup"
|
||||
|
||||
proc empty {} {
|
||||
puts "<font style=\"color: grey\">
|
||||
<i>No current backup files.</i>
|
||||
</font>"
|
||||
}
|
||||
|
||||
if {![file isdirectory $dir]} {
|
||||
empty
|
||||
exit
|
||||
}
|
||||
|
||||
set backups [glob -nocomplain "$dir/*"]
|
||||
|
||||
if {![llength $backups]} {
|
||||
empty
|
||||
exit
|
||||
}
|
||||
|
||||
foreach backup [glob -nocomplain "$dir/*"] {
|
||||
set b [file tail $backup]
|
||||
puts "<input name=restore_file class=restore
|
||||
type=radio value=\"$b\">$b <font class=footnote>(
|
||||
[clock format [file mtime $backup] -format {%c %Z}]
|
||||
)</font></input>
|
||||
<br>
|
||||
"
|
||||
}
|
||||
|
4
var/mongoose/html/backup.shtml
Normal file
4
var/mongoose/html/backup.shtml
Normal file
@ -0,0 +1,4 @@
|
||||
<!--#include virtual="/lib/header.shtml" -->
|
||||
<!--#exec cmd="/mod/var/mongoose/include/backup.jim" -->
|
||||
<!--#include virtual="/lib/footer.shtml" -->
|
||||
|
BIN
var/mongoose/html/img/lightning.png
Normal file
BIN
var/mongoose/html/img/lightning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 671 B |
51
var/mongoose/include/backup.jim
Executable file
51
var/mongoose/include/backup.jim
Executable file
@ -0,0 +1,51 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
source /mod/var/mongoose/lib/setup
|
||||
require altrow rsv.class
|
||||
|
||||
puts {
|
||||
<script type=text/javascript src=/cgi-bin/backup/backup.js></script>
|
||||
<h2>Backup/Restore</h2>
|
||||
|
||||
<div style="clear: both; float: left; width: 40%; border: 1px solid grey;
|
||||
padding: 1em">
|
||||
To create a backup of your current favourite channel configuration and
|
||||
scheduled recordings, enter a name in the box below and click the button.
|
||||
A suggested name has been entered for you.
|
||||
|
||||
<p>
|
||||
}
|
||||
|
||||
puts "<input type=text size=30 maxlength=50 id=backup_name name=file
|
||||
class=\"text ui-widget-content ui-corner-all\"
|
||||
value=\"[clock format [clock seconds] -format "backup-%Y-%b-%d-%H:%M"]\">"
|
||||
puts "<button id=backup_button>Create Backup</button>"
|
||||
|
||||
puts {
|
||||
<br>
|
||||
<div id=backup_working class=va style="display: none;">
|
||||
<img class=va src=/img/loading.gif>
|
||||
<font class=footnote>Backing up...</font>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id=backup_files_outer
|
||||
style="float: left; width: 40%; border: 1px solid grey; margin-left: 1em;
|
||||
padding: 0 1em 1em 1em">
|
||||
<h3>Available Backups</h3>
|
||||
<div id=backup_files style="padding: 0 0 0 2em">
|
||||
<img src=/img/loading.gif>Retrieving list of backups...
|
||||
</div>
|
||||
<br>
|
||||
<button id=restore_button disabled>Restore Backup</button>
|
||||
<button id=delete_button disabled>Delete Backup</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div id=results class=pre
|
||||
style="display: none; clear: both; float: left; padding: 1em;
|
||||
margin-top: 1em; border: 1px solid grey; width: 70%">
|
||||
</div>
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ set events [rsv list]
|
||||
puts {
|
||||
<table class=borders>
|
||||
<tr>
|
||||
<th colspan=3>Channel</th>
|
||||
<th colspan=2>Channel</th>
|
||||
<th>Programme</th>
|
||||
<th>Start Time</th>
|
||||
<th>Duration</th>
|
||||
@ -19,25 +19,19 @@ puts {
|
||||
}
|
||||
|
||||
foreach event $events {
|
||||
$event cleanstrings
|
||||
|
||||
set name [$event get szevtname]
|
||||
set name [$event name]
|
||||
|
||||
altrow
|
||||
|
||||
set rsvicon ""
|
||||
set alta ""
|
||||
switch [$event get ersvtype] {
|
||||
1 { set rsvicon "175_1_00_Reservation_Watch.png" }
|
||||
2 { set rsvicon "175_1_00_Reservation_Watch.png" }
|
||||
3 { set rsvicon "175_1_11_Reservation_Record.png" }
|
||||
5 { set rsvicon "745_1_10_Video_2Live.png"; set alta "Wake-up" }
|
||||
6 { set rsvicon "745_1_11_Video_1REC.png"; set alta "Sleep" }
|
||||
7 { set rsvicon "345_6_08_ST_Ad_Hoc.png"
|
||||
set alta "Auto Update" }
|
||||
default { set alta "Unknown type [$event get ersvtype]" }
|
||||
5 { set rsvicon "745_1_10_Video_2Live.png" }
|
||||
6 { set rsvicon "745_1_11_Video_1REC.png" }
|
||||
7 { set rsvicon "345_6_08_ST_Ad_Hoc.png" }
|
||||
}
|
||||
if {$name == ""} { set name "-- $alta --" }
|
||||
|
||||
set series 0
|
||||
if {[$event get ucRecKind] == 4} {
|
||||
@ -62,15 +56,15 @@ foreach event $events {
|
||||
|
||||
if {[$event get usLcn] ne ""} {
|
||||
puts "
|
||||
<td>[$event get usLcn]</td>
|
||||
<td>
|
||||
<img src=\"/img/channels/[$event get szSvcName].png\"
|
||||
<img src=\"/img/channels/[$event channel_name].png\"
|
||||
width=50>
|
||||
</td>
|
||||
<td nowrap>[$event get szSvcName]</td>
|
||||
<td nowrap>[$event get usLcn]<br>
|
||||
[$event channel_name]</td>
|
||||
"
|
||||
} else {
|
||||
puts "<td colspan=3> <br><br></td>"
|
||||
puts "<td colspan=2> <br><br></td>"
|
||||
}
|
||||
|
||||
puts "<td nowrap>$name</td>"
|
||||
@ -85,7 +79,8 @@ foreach event $events {
|
||||
} else {
|
||||
puts "<td nowrap class=va>"
|
||||
}
|
||||
puts "[clock format $s -format {%c %Z}]"
|
||||
puts "[clock format $s -format "%a %d %b %Y"]<br>
|
||||
[clock format $s -format "%H:%M %Z"]"
|
||||
|
||||
if {$d > 0 && $n > $s && $n < $e} {
|
||||
puts "<br>"
|
||||
|
@ -1,35 +0,0 @@
|
||||
#!/mod/bin/jimsh
|
||||
|
||||
set ::env(PATH) "/mod/bin/busybox:/mod/bin:/bin"
|
||||
|
||||
set pid [exec pgrep humaxtv]
|
||||
|
||||
if {[catch {set line [exec lsof -p $pid | grep Video | fgrep .ts]} ]} {
|
||||
exit
|
||||
}
|
||||
|
||||
regsub -all -- {[[:space:]]+} $line " " line
|
||||
set fields [split $line " "]
|
||||
set size [lindex $fields 6]
|
||||
|
||||
sleep 2
|
||||
|
||||
set line [exec lsof -p $pid | grep Video | fgrep .ts]
|
||||
regsub -all -- {[[:space:]]+} $line " " line
|
||||
set fields [split $line " "]
|
||||
set size2 [lindex $fields 6]
|
||||
|
||||
if { $size2 > $size } {
|
||||
set mode "Recording"
|
||||
set icon "745_1_11_Video_1REC.png"
|
||||
} else {
|
||||
set mode "Watching"
|
||||
set icon "745_1_10_Video_2Live.png"
|
||||
}
|
||||
|
||||
set name [lindex [split $line "/"] end]
|
||||
|
||||
puts "<div class=shadowbox><div>"
|
||||
puts "<img src=/images/$icon>$mode $name"
|
||||
puts "</div></div>"
|
||||
|
@ -39,12 +39,25 @@ class rsv {
|
||||
sort 0
|
||||
}
|
||||
|
||||
rsv method cleanstrings {} {
|
||||
set szevtname [string range $szevtname 1 end]
|
||||
if {[string first "i7" $szevtname] == 0} {
|
||||
set szevtname [string range $szevtname 2 end]
|
||||
rsv method name {} {
|
||||
set name [string range $szevtname 1 end]
|
||||
if {[string first "i7" $name] == 0} {
|
||||
set name [string range $name 2 end]
|
||||
}
|
||||
set szSvcName [string range $szSvcName 1 end]
|
||||
if {$name == ""} {
|
||||
switch $ersvtype {
|
||||
5 { set name "--- Wake-up ---" }
|
||||
6 { set name "--- Sleep ---" }
|
||||
7 { set name "--- Auto Update ---" }
|
||||
default { set name "--- Unknown event type $ersvtype ---" }
|
||||
}
|
||||
}
|
||||
|
||||
return $name
|
||||
}
|
||||
|
||||
rsv method channel_name {} {
|
||||
return [string range $szSvcName 1 end]
|
||||
}
|
||||
|
||||
proc {rsv list} {} {
|
||||
|
@ -1,8 +1,11 @@
|
||||
|
||||
if {![exists -proc require]} {
|
||||
proc require {args} {
|
||||
proc require {args} {{done {}}} {
|
||||
foreach file $args {
|
||||
uplevel source "/mod/var/mongoose/lib/$file"
|
||||
if {[lsearch -exact $done $file] == -1} {
|
||||
uplevel source "/mod/var/mongoose/lib/$file"
|
||||
lappend $done $file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user