2011-06-22 23:36:30 +00:00
|
|
|
#!/mod/bin/jimsh
|
|
|
|
|
|
|
|
package require cgi
|
2012-01-10 19:51:45 +00:00
|
|
|
source /mod/var/mongoose/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]
|
|
|
|
regsub "^[system mediaroot]" $dir $dustbin dir
|
|
|
|
system mkdir_p $dir
|
|
|
|
return $dir
|
|
|
|
}
|
|
|
|
|
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]"
|
|
|
|
while {[file isdirectory $ndir]} { append ndir "_" }
|
|
|
|
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 ""} {
|
|
|
|
$ts move [bindir $file] 1
|
|
|
|
} 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
|
|
|
|