2011-06-22 23:36:30 +00:00
|
|
|
#!/mod/bin/jimsh
|
|
|
|
|
|
|
|
package require cgi
|
2012-05-21 20:23:41 +00:00
|
|
|
source /mod/webif/lib/setup
|
2012-01-16 22:28:20 +00:00
|
|
|
require ts.class pretty_size system.class tdelete
|
2011-06-22 23:36:30 +00:00
|
|
|
|
2012-01-16 22:28:20 +00:00
|
|
|
puts "Content-Type: text/html\r\n"
|
2011-06-22 23:36:30 +00:00
|
|
|
|
|
|
|
cgi_input
|
|
|
|
#cgi_dump
|
|
|
|
|
2012-01-16 22:28:20 +00:00
|
|
|
set dir [cgi_get dir]
|
2012-01-25 23:19:57 +00:00
|
|
|
regsub -all {([\\["$])} $dir {\\\1} dir
|
2012-01-16 22:28:20 +00:00
|
|
|
|
|
|
|
#puts "DIR: ($dir)"
|
2011-06-22 23:36:30 +00:00
|
|
|
|
2012-01-10 19:51:45 +00:00
|
|
|
if {[system pkginst undelete]} {
|
|
|
|
set dustbin [system dustbin]
|
|
|
|
} else {
|
|
|
|
set dustbin ""
|
|
|
|
}
|
|
|
|
|
|
|
|
proc bindir {file} {
|
|
|
|
global dustbin
|
|
|
|
set dir [file dirname $file]
|
2012-01-27 21:54:39 +00:00
|
|
|
regsub "^[system mediaroot]" $dir $dustbin ndir
|
|
|
|
if {$dir eq $ndir} { set ndir $dustbin }
|
|
|
|
system mkdir_p $ndir
|
|
|
|
return $ndir
|
2012-01-10 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 22:28:20 +00:00
|
|
|
proc touch {file} {
|
|
|
|
exec /mod/bin/busybox/touch $file
|
|
|
|
}
|
|
|
|
|
|
|
|
puts "<div id=deleting class=blood><img src=/img/loading.gif>Deleting...</div>"
|
|
|
|
puts "<ul style=\"list-style-type: square\">"
|
2012-01-25 23:19:57 +00:00
|
|
|
|
2012-01-16 22:28:20 +00:00
|
|
|
foreach file [cgi_get files] {
|
2012-01-25 23:19:57 +00:00
|
|
|
|
2012-01-16 22:28:20 +00:00
|
|
|
puts -nonewline "<li>\"$file\"..."
|
2012-01-25 23:19:57 +00:00
|
|
|
|
2012-01-16 22:28:20 +00:00
|
|
|
if {![string match "$dir/*" $file]} {
|
|
|
|
puts "Error - outside directory."
|
|
|
|
continue
|
|
|
|
}
|
2012-01-14 00:29:44 +00:00
|
|
|
|
2012-01-25 23:19:57 +00:00
|
|
|
if {$dustbin ne "" && [string first $dustbin $file] > -1} {
|
2012-01-16 22:28:20 +00:00
|
|
|
set ldustbin ""
|
2011-06-22 23:36:30 +00:00
|
|
|
} else {
|
2012-01-16 22:28:20 +00:00
|
|
|
set ldustbin $dustbin
|
|
|
|
}
|
|
|
|
|
|
|
|
set done 0
|
|
|
|
if {[file isdirectory $file]} {
|
|
|
|
puts -nonewline "Directory..."
|
|
|
|
if {$ldustbin ne ""} {
|
|
|
|
set ndir "[bindir $file]/[file tail $file]"
|
2012-05-20 14:10:37 +00:00
|
|
|
while {[file isdirectory $ndir]} {
|
|
|
|
append ndir "_"
|
2012-05-02 17:41:23 +00:00
|
|
|
}
|
2012-01-16 22:28:20 +00:00
|
|
|
file rename $file $ndir
|
|
|
|
touch $ndir
|
2012-01-10 19:51:45 +00:00
|
|
|
} else {
|
2012-01-16 22:28:20 +00:00
|
|
|
tdelete $file
|
2012-01-10 19:51:45 +00:00
|
|
|
}
|
2012-01-16 22:28:20 +00:00
|
|
|
puts -nonewline "Done..."
|
|
|
|
set done 1
|
|
|
|
} elseif {[string match {*.ts} $file]} {
|
|
|
|
set ts [ts fetch $file]
|
|
|
|
|
|
|
|
# Check TS validity
|
|
|
|
if {![catch {$ts get file}]} {
|
|
|
|
if {$ldustbin ne ""} {
|
2012-05-02 17:41:23 +00:00
|
|
|
$ts move [bindir $file] 1 1
|
2012-01-16 22:28:20 +00:00
|
|
|
} else {
|
|
|
|
if {[$ts delete]} {
|
|
|
|
puts "Successfully deleted $file."
|
|
|
|
} else {
|
|
|
|
puts "Problem deleting $file, [$ts get error]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set done 1
|
|
|
|
}
|
|
|
|
# else treat as normal file.
|
2011-06-22 23:36:30 +00:00
|
|
|
}
|
2012-01-16 22:28:20 +00:00
|
|
|
|
|
|
|
if {!$done} {
|
|
|
|
if {$ldustbin ne ""} {
|
|
|
|
set nfile "[bindir $file]/[file tail $file]"
|
|
|
|
file rename $file $nfile
|
|
|
|
touch $nfile
|
|
|
|
} else {
|
|
|
|
tdelete $file
|
|
|
|
}
|
|
|
|
catch {file delete "[file rootname $file].hmi"}
|
|
|
|
puts -nonewline "Done..."
|
2012-01-10 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 22:28:20 +00:00
|
|
|
puts "</li>"
|
2011-06-22 23:36:30 +00:00
|
|
|
}
|
2012-01-16 22:28:20 +00:00
|
|
|
puts "</ul>"
|
2011-06-22 23:36:30 +00:00
|
|
|
|