webif/var/mongoose/cgi-bin/browse/clipboard.jim
hummypkg ccb513be49 0.8.11
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@639 2a923420-c742-0410-a762-8d5b09965624
2012-01-08 21:10:38 +00:00

117 lines
2.5 KiB
Plaintext
Executable File

#!/mod/bin/jimsh
package require cgi
source /mod/var/mongoose/lib/setup
require clipboard.class ts.class chunked
start_chunked "text/html; no-cache\r\nExpires: Thu, 01 Jan 1970 00:00:00 GMT\r\nPragma: nocache"
cgi_input 1
#cgi_dump
set cb [[clipboard new {path "/tmp/webif-browse.cb"}] load]
set action [cgi_get act list]
switch $action {
list {
if {![$cb size]} {
chunk "<i>Clipboard is empty</i>"
break
}
chunk "<div class=cliplist>"
foreach file [$cb get items] {
set img "page_white_copy"
if {[$file get action] eq "cut"} {
set img "cut"
}
set path [$file get path]
set xpath [cgi_quote_html $path]
chunk "<span title=\"$xpath\" alt=\"$xpath\">"
chunk "<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
src=/images/711_1_09_Media_Folder.png>"
}
chunk [cgi_quote_html $dfile]
chunk "<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>"
}
chunk "</div>"
chunk "<button id=clipclear>Empty clipboard</button>"
}
add {
if {[set path [cgi_get path]] eq "0"} {
chunk "No path."
exit
}
set dir [cgi_unquote_input [cgi_get dir]]
set mode [cgi_get mode copy]
foreach p $path {
set p [cgi_unquote_input $p]
if {$dir ne "0" && ![string match "$dir/*" $p]} {
chunk "$p not in directory<br>"
continue
}
if {![$cb present $p]} {
$cb add $mode $p
chunk "Added $p for $mode<br>"
}
}
$cb save
}
remove {
$cb remove [cgi_unquote_input [cgi_get path]]
$cb save
}
clear {
$cb clear
$cb save
}
paste {
set dir [cgi_unquote_input [cgi_get dir]]
foreach item [$cb get items] {
set path [$item get path]
set file [file tail $path]
set mode [$item get action]
chunk "Pasting $file"
chunk_pad
if {[file isdirectory $path]} {
# Directory
if {$mode eq "cut"} {
file rename $path "$dir/$file"
} else {
chunk [exec /mod/bin/busybox/cp -r \
$path $dir]
}
} else {
set root [file rootname $path]
# 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}.*"] {
if {$mode eq "cut"} {
file rename $f "$dir/[file tail $f]"
} else {
file copy $f "$dir/[file tail $f]"
}
}
}
}
$cb clear
$cb save
}
}
end_chunked