dustbin support + bugfix

git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@648 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2012-01-10 19:51:45 +00:00
parent ccb513be49
commit 6e2a0f3e2b
7 changed files with 133 additions and 44 deletions

View File

@ -1,7 +1,7 @@
Package: webif
Priority: optional
Section: web
Version: 0.8.11
Version: 0.8.11-1
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: mongoose(>=3.0-2),jim(>=0.71-1),jim-sqlite3(>=0.71-1),jim-cgi(>=0.5),jim-oo,jim-pack,service-control,busybox(>=1.19.3-1),lsof,epg(>=1.0.8),hmt(>=1.1.4),ssmtp,anacron

View File

@ -106,7 +106,7 @@ foreach line $data {
puts " $chan"
if {!$hsvc} {
if {$hsvc eq ""} {
puts " Cannot map channel name to service."
continue
}

View File

@ -2,9 +2,12 @@
package require cgi
source /mod/var/mongoose/lib/setup
require clipboard.class ts.class chunked
require clipboard.class ts.class
start_chunked "text/html; no-cache\r\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\r\nPragma: nocache"
puts "Content-Type: text/html; no-cache"
puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
puts "Pragma: nocache"
puts ""
cgi_input 1
#cgi_dump
@ -16,10 +19,10 @@ set action [cgi_get act list]
switch $action {
list {
if {![$cb size]} {
chunk "<i>Clipboard is empty</i>"
puts "<i>Clipboard is empty</i>"
break
}
chunk "<div class=cliplist>"
puts "<div class=cliplist>"
foreach file [$cb get items] {
set img "page_white_copy"
if {[$file get action] eq "cut"} {
@ -27,28 +30,28 @@ switch $action {
}
set path [$file get path]
set xpath [cgi_quote_html $path]
chunk "<span title=\"$xpath\" alt=\"$xpath\">"
chunk "<img src=/img/context/$img.png>"
puts "<span title=\"$xpath\" alt=\"$xpath\">"
puts "<img src=/img/context/$img.png>"
set dfile [file tail $path]
if {[string length $dfile] > 25} {
set dfile "[string range $dfile 0 22]..."
}
if {[file isdirectory $path]} {
chunk "<img height=16
puts "<img height=16
src=/images/711_1_09_Media_Folder.png>"
}
chunk [cgi_quote_html $dfile]
chunk "<a class=clipdel href=# alt=\"Remove\" title=\"Remove\"
puts [cgi_quote_html $dfile]
puts "<a class=clipdel href=# alt=\"Remove\" title=\"Remove\"
path=\"[cgi_quote_url $path]\">
<img border=0 src=/img/close.png height=16></a>"
chunk "</span>"
puts "</span>"
}
chunk "</div>"
chunk "<button id=clipclear>Empty clipboard</button>"
puts "</div>"
puts "<button id=clipclear>Empty clipboard</button>"
}
add {
if {[set path [cgi_get path]] eq "0"} {
chunk "No path."
puts "No path."
exit
}
set dir [cgi_unquote_input [cgi_get dir]]
@ -56,12 +59,12 @@ switch $action {
foreach p $path {
set p [cgi_unquote_input $p]
if {$dir ne "0" && ![string match "$dir/*" $p]} {
chunk "$p not in directory<br>"
puts "$p not in directory<br>"
continue
}
if {![$cb present $p]} {
$cb add $mode $p
chunk "Added $p for $mode<br>"
puts "Added $p for $mode<br>"
}
}
$cb save
@ -81,16 +84,15 @@ switch $action {
set file [file tail $path]
set mode [$item get action]
chunk "Pasting $file"
chunk_pad
puts "Pasting $file"
if {[file isdirectory $path]} {
# Directory
if {$mode eq "cut"} {
file rename $path "$dir/$file"
catch {file rename $path "$dir/$file"}
} else {
chunk [exec /mod/bin/busybox/cp -r \
$path $dir]
catch {puts [exec /mod/bin/busybox/cp -r \
$path $dir]}
}
} else {
set root [file rootname $path]
@ -100,9 +102,9 @@ switch $action {
regsub -all {([\\["$])} $root {\\\1} root
foreach f [glob -nocomplain "${root}.*"] {
if {$mode eq "cut"} {
file rename $f "$dir/[file tail $f]"
catch {file rename $f "$dir/[file tail $f]"}
} else {
file copy $f "$dir/[file tail $f]"
catch {file copy $f "$dir/[file tail $f]"}
}
}
}
@ -112,5 +114,3 @@ switch $action {
}
}
end_chunked

View File

@ -1,7 +1,8 @@
#!/mod/bin/jimsh
package require cgi
source /mod/var/mongoose/lib/ts.class
source /mod/var/mongoose/lib/setup
require ts.class system.class
puts "Content-Type: text/html"
puts ""
@ -12,21 +13,50 @@ cgi_input
set file [dict get $_cgi file]
set type [dict get $_cgi type]
if {[system pkginst undelete]} {
set dustbin [system dustbin]
} else {
set dustbin ""
}
proc bindir {file} {
global dustbin
set dir [file dirname $file]
regsub "^[system mediaroot]" $dir $dustbin dir
system mkdir_p $dir
return $dir
}
if {$type eq "ts"} {
set ts [ts fetch $file]
if {[$ts delete]} {
puts "Successfully deleted $file."
if {$dustbin ne ""} {
$ts move [bindir $file]
} else {
puts "Problem deleting $file, [$ts get error]"
if {[$ts delete]} {
puts "Successfully deleted $file."
} else {
puts "Problem deleting $file, [$ts get error]"
}
}
exit
} elseif {$type eq "dir"} {
puts -nonewline "Directory..."
puts [exec /mod/bin/busybox/rm -rf $file]
if {$dustbin ne ""} {
set ndir "[bindir $file]/[file tail $file]"
while {[file isdirectory $ndir]} { append ndir "_" }
file rename $file $ndir
} else {
puts [exec /mod/bin/busybox/rm -rf $file]
}
puts -nonewline "Done..."
} else {
file delete $file
file delete "[file rootname $file].hmi"
if {$dustbin ne ""} {
file rename $file "[bindir $file]/[file tail $file]"
} else {
file delete $file
}
catch {file delete "[file rootname $file].hmi"}
puts "Successfully deleted $file."
}

View File

@ -2,7 +2,7 @@
package require cgi
source /mod/var/mongoose/lib/setup
require ts.class pretty_size
require ts.class pretty_size system.class
puts "Content-Type: text/html\r\n\r\n"
@ -13,6 +13,20 @@ set dir [cgi_unquote_input [cgi_get dir]]
#puts "DIR: ($dir)"
if {[system pkginst undelete]} {
set dustbin [system dustbin]
} else {
set dustbin ""
}
proc bindir {file} {
global dustbin
set dir [file dirname $file]
regsub "^[system mediaroot]" $dir $dustbin dir
system mkdir_p $dir
return $dir
}
puts "<div id=deleting class=blood><img src=/img/loading.gif>Deleting...</div>"
puts "<ul style=\"list-style-type: square\">"
foreach file [cgi_get files] {
@ -25,22 +39,33 @@ foreach file [cgi_get files] {
if {[file isdirectory $file]} {
puts -nonewline "Directory..."
puts [exec /mod/bin/busybox/rm -rf $file]
if {$dustbin ne ""} {
set ndir "[bindir $file]/[file tail $file]"
while {[file isdirectory $ndir]} { append ndir "_" }
file rename $file $ndir
} else {
puts [exec /mod/bin/busybox/rm -rf $file]
}
puts -nonewline "Done..."
} elseif {[string match {*.ts} $file]} {
set ts [ts fetch $file]
if {[catch {$ts delete} msg]} {
puts -nonewline "Error loading TS file..."
if {$dustbin ne ""} {
$ts move [bindir $file]
} else {
puts -nonewline "Done..."
if {[$ts delete]} {
puts "Successfully deleted $file."
} else {
puts "Problem deleting $file, [$ts get error]"
}
}
} else {
if {[catch {file delete $file} msg]} {
puts -nonewline "Error: $msg"
if {$dustbin ne ""} {
file rename $file "[bindir $file]/[file tail $file]"
} else {
catch {file delete "[file rootname $file].hmi"}
puts -nonewline "Done..."
file delete $file
}
catch {file delete "[file rootname $file].hmi"}
puts -nonewline "Done..."
}
puts "</li>"
}

View File

@ -50,6 +50,14 @@ proc {system mediaroot} {} {
return ""
}
proc {system dustbin} {} {
switch [system model] {
HDR { return "/media/My Video/_dustbin" }
HD { return "/media/drive1/Video/_dustbin" }
}
return ""
}
proc {system diskspace} {} {
switch [system model] {
HDR { set part /mnt/hd2 }
@ -116,3 +124,7 @@ proc {system padding} {} {
return [list $start $stop]
}
proc {system mkdir_p} {dir} {
exec /mod/bin/busybox/mkdir -p $dir
}

View File

@ -118,14 +118,36 @@ proc {ts fetch} {file {checked 0}} {
}
ts method delete {} {
# Extract file basename
foreach f [glob -nocomplain "[file rootname $file].*"] {
set root [file rootname $file]
# Protect special characters in root.
# In particular [] characters which are used a lot
# for torrent names.
regsub -all {([\\["$])} $root {\\\1} root
foreach f [glob -nocomplain "${root}.*"] {
puts "Removed $f<br>"
file delete $f
}
return 1
}
ts method move {dst} {
set root [file rootname $file]
regsub -all {([\\["$])} $root {\\\1} root
foreach f [glob -nocomplain "${root}.*"] {
file rename $f "$dst/[file tail $f]"
}
return 1
}
ts method copy {dst} {
set root [file rootname $file]
regsub -all {([\\["$])} $root {\\\1} root
foreach f [glob -nocomplain "${root}.*"] {
file copy $f "$dst/[file tail $f]"
}
return 1
}
ts method settitle {newtitle} {
if {[string length newtitle] > 48} { return }