webif/var/mongoose/cgi-bin/browse/delete.jim
hummypkg d7284ff3ef 0.9.9
git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1016 2a923420-c742-0410-a762-8d5b09965624
2012-05-21 20:23:41 +00:00

104 lines
2.0 KiB
Plaintext
Executable File

#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require ts.class pretty_size system.class tdelete
puts "Content-Type: text/html\r\n"
cgi_input
#cgi_dump
set dir [cgi_get dir]
regsub -all {([\\["$])} $dir {\\\1} 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 ndir
if {$dir eq $ndir} { set ndir $dustbin }
system mkdir_p $ndir
return $ndir
}
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\">"
foreach file [cgi_get files] {
puts -nonewline "<li>\"$file\"..."
if {![string match "$dir/*" $file]} {
puts "Error - outside directory."
continue
}
if {$dustbin ne "" && [string first $dustbin $file] > -1} {
set ldustbin ""
} else {
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
} else {
tdelete $file
}
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 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.
}
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..."
}
puts "</li>"
}
puts "</ul>"