webif/var/mongoose/cgi-bin/browse/delete.jim

63 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/mod/bin/jimsh
package require cgi
source /mod/var/mongoose/lib/setup
require ts.class system.class
puts "Content-Type: text/html"
puts ""
cgi_input
#cgi_dump
set file [dict get $_cgi file]
set type [dict get $_cgi type]
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
}
if {$type eq "ts"} {
set ts [ts fetch $file]
if {$dustbin ne ""} {
$ts move [bindir $file]
} else {
if {[$ts delete]} {
puts "Successfully deleted $file."
} else {
puts "Problem deleting $file, [$ts get error]"
}
}
exit
} elseif {$type eq "dir"} {
puts -nonewline "Directory..."
if {$dustbin ne ""} {
set ndir "[bindir $file]/[file tail $file]"
while {[file isdirectory $ndir]} { append ndir "_" }
file rename $file $ndir
} else {
puts [exec /mod/bin/busybox/rm -rf $file]
}
puts -nonewline "Done..."
} else {
if {$dustbin ne ""} {
file rename $file "[bindir $file]/[file tail $file]"
} else {
file delete $file
}
catch {file delete "[file rootname $file].hmi"}
puts "Successfully deleted $file."
}