2011-12-28 14:11:10 +00:00
|
|
|
#!/mod/bin/jimsh
|
|
|
|
|
|
|
|
package require cgi
|
|
|
|
source /mod/var/mongoose/lib/setup
|
2012-01-10 19:51:45 +00:00
|
|
|
require clipboard.class ts.class
|
2011-12-28 14:11:10 +00:00
|
|
|
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "Content-Type: text/html; no-cache"
|
|
|
|
puts "Expires: Thu, 01 Jan 1970 00:00:00 GMT"
|
|
|
|
puts "Pragma: nocache"
|
|
|
|
puts ""
|
2011-12-28 14:11:10 +00:00
|
|
|
|
2011-12-28 21:36:35 +00:00
|
|
|
cgi_input 1
|
2011-12-28 14:11:10 +00:00
|
|
|
#cgi_dump
|
|
|
|
|
|
|
|
set cb [[clipboard new {path "/tmp/webif-browse.cb"}] load]
|
|
|
|
|
|
|
|
set action [cgi_get act list]
|
|
|
|
|
|
|
|
switch $action {
|
|
|
|
list {
|
|
|
|
if {![$cb size]} {
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "<i>Clipboard is empty</i>"
|
2011-12-29 00:57:18 +00:00
|
|
|
break
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "<div class=cliplist>"
|
2011-12-28 21:36:35 +00:00
|
|
|
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]
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "<span title=\"$xpath\" alt=\"$xpath\">"
|
|
|
|
puts "<img src=/img/context/$img.png>"
|
2011-12-28 21:36:35 +00:00
|
|
|
set dfile [file tail $path]
|
|
|
|
if {[string length $dfile] > 25} {
|
|
|
|
set dfile "[string range $dfile 0 22]..."
|
|
|
|
}
|
|
|
|
if {[file isdirectory $path]} {
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "<img height=16
|
2011-12-28 21:36:35 +00:00
|
|
|
src=/images/711_1_09_Media_Folder.png>"
|
|
|
|
}
|
2012-01-10 19:51:45 +00:00
|
|
|
puts [cgi_quote_html $dfile]
|
|
|
|
puts "<a class=clipdel href=# alt=\"Remove\" title=\"Remove\"
|
2011-12-28 21:36:35 +00:00
|
|
|
path=\"[cgi_quote_url $path]\">
|
2011-12-29 01:17:32 +00:00
|
|
|
<img border=0 src=/img/close.png height=16></a>"
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "</span>"
|
2011-12-28 21:36:35 +00:00
|
|
|
}
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "</div>"
|
2012-02-01 21:02:43 +00:00
|
|
|
puts "<button id=paste>Paste to current folder</button>"
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "<button id=clipclear>Empty clipboard</button>"
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
|
|
|
add {
|
2011-12-28 21:36:35 +00:00
|
|
|
if {[set path [cgi_get path]] eq "0"} {
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "No path."
|
2011-12-28 21:36:35 +00:00
|
|
|
exit
|
|
|
|
}
|
2012-01-08 21:10:38 +00:00
|
|
|
set dir [cgi_unquote_input [cgi_get dir]]
|
2011-12-28 21:36:35 +00:00
|
|
|
set mode [cgi_get mode copy]
|
2012-01-08 20:54:07 +00:00
|
|
|
foreach p $path {
|
2011-12-28 21:36:35 +00:00
|
|
|
set p [cgi_unquote_input $p]
|
2012-01-08 21:10:38 +00:00
|
|
|
if {$dir ne "0" && ![string match "$dir/*" $p]} {
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "$p not in directory<br>"
|
2012-01-08 21:10:38 +00:00
|
|
|
continue
|
|
|
|
}
|
2011-12-28 21:36:35 +00:00
|
|
|
if {![$cb present $p]} {
|
|
|
|
$cb add $mode $p
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "Added $p for $mode<br>"
|
2011-12-28 21:36:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$cb save
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
2011-12-28 21:36:35 +00:00
|
|
|
remove {
|
|
|
|
$cb remove [cgi_unquote_input [cgi_get path]]
|
|
|
|
$cb save
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
|
|
|
clear {
|
2011-12-28 21:36:35 +00:00
|
|
|
$cb clear
|
|
|
|
$cb save
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
2011-12-29 00:57:18 +00:00
|
|
|
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]
|
|
|
|
|
2012-01-10 19:51:45 +00:00
|
|
|
puts "Pasting $file"
|
2011-12-29 00:57:18 +00:00
|
|
|
|
|
|
|
if {[file isdirectory $path]} {
|
|
|
|
# Directory
|
|
|
|
if {$mode eq "cut"} {
|
2012-01-10 19:51:45 +00:00
|
|
|
catch {file rename $path "$dir/$file"}
|
2011-12-29 00:57:18 +00:00
|
|
|
} else {
|
2012-01-10 19:51:45 +00:00
|
|
|
catch {puts [exec /mod/bin/busybox/cp -r \
|
|
|
|
$path $dir]}
|
2011-12-29 00:57:18 +00:00
|
|
|
}
|
|
|
|
} 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"} {
|
2012-01-22 19:47:47 +00:00
|
|
|
catch {file rename $f \
|
|
|
|
"$dir/[file tail $f]"}
|
2011-12-29 00:57:18 +00:00
|
|
|
} else {
|
2012-01-22 19:47:47 +00:00
|
|
|
catch {file copy $f \
|
|
|
|
"$dir/[file tail $f]"}
|
2011-12-29 00:57:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$cb clear
|
|
|
|
$cb save
|
|
|
|
}
|
2011-12-28 14:11:10 +00:00
|
|
|
}
|
|
|
|
|