many escaping fixes. Remove unecessary regsub/string match and replace with better alternatives

git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@1111 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2012-08-07 22:22:30 +00:00
parent 4e36ecc6f0
commit e4f61f4047
8 changed files with 58 additions and 57 deletions

View File

@ -1,7 +1,7 @@
Package: webif Package: webif
Priority: optional Priority: optional
Section: web Section: web
Version: 0.9.13-1 Version: 0.9.13-3
Architecture: mipsel Architecture: mipsel
Maintainer: af123@hummypkg.org.uk Maintainer: af123@hummypkg.org.uk
Depends: webif-channelicons(>=1.0.2),mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73),jim-cgi(>=0.5),service-control(>=1.2),busybox(>=1.19.3-1),lsof,epg(>=1.0.9),hmt(>=1.1.6),ssmtp,anacron,trm,openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2),stripts(>=1.1.2) Depends: webif-channelicons(>=1.0.2),mongoose(>=3.0-7),jim(>=0.73-1),jim-oo,jim-sqlite3(>=0.73),jim-cgi(>=0.5),service-control(>=1.2),busybox(>=1.19.3-1),lsof,epg(>=1.0.9),hmt(>=1.1.6),ssmtp,anacron,trm,openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2),stripts(>=1.1.2)

View File

@ -59,7 +59,7 @@ switch $action {
set mode [cgi_get mode copy] set mode [cgi_get mode copy]
foreach p $path { foreach p $path {
set p [cgi_unquote_input $p] set p [cgi_unquote_input $p]
if {$dir ne "0" && ![string match "$dir/*" $p]} { if {$dir ne "0" && [string first "$dir/" $p] != 0} {
puts "$p not in directory<br>" puts "$p not in directory<br>"
continue continue
} }
@ -95,13 +95,10 @@ switch $action {
catch {puts [exec /mod/bin/busybox/cp -r \ catch {puts [exec /mod/bin/busybox/cp -r \
$path $dir]} $path $dir]}
} }
} else { } elseif {[string match {*.ts} $path]} {
set root [file rootname $path] set ts [ts fetch $path]
# Protect special characters in root. if {![catch {$ts get file}]} {
# In particular [] characters which are used a lot foreach f [$ts fileset] {
# for torrent names.
regsub -all {([\\["$])} $root {\\\1} root
foreach f [glob -nocomplain "${root}.*"] {
if {$mode eq "cut"} { if {$mode eq "cut"} {
catch {file rename $f \ catch {file rename $f \
"$dir/[file tail $f]"} "$dir/[file tail $f]"}
@ -111,6 +108,13 @@ switch $action {
} }
} }
} }
} else {
if {$mode eq "cut"} {
catch {file rename $path "$dir/[file tail $f]"}
} else {
catch {file copy $path "$dir/[file tail $f]"}
}
}
} }
$cb clear $cb clear
$cb save $cb save

View File

@ -10,7 +10,6 @@ cgi_input
#cgi_dump #cgi_dump
set dir [cgi_get dir] set dir [cgi_get dir]
regsub -all {([\\["$])} $dir {\\\1} dir
#puts "DIR: ($dir)" #puts "DIR: ($dir)"
@ -40,7 +39,7 @@ foreach file [cgi_get files] {
puts -nonewline "<li>\"$file\"..." puts -nonewline "<li>\"$file\"..."
if {![string match "$dir/*" $file]} { if {[string first "$dir/" $file] != 0} {
puts "Error - outside directory." puts "Error - outside directory."
continue continue
} }

View File

@ -12,12 +12,11 @@ cgi_input
set dir [cgi_get dir "/media/My Video/Children"] set dir [cgi_get dir "/media/My Video/Children"]
puts "{" puts "{"
regsub -all {([\\["$])} $dir {\\\1} xdir
foreach file [readdir -nocomplain $dir] { foreach file [readdir -nocomplain $dir] {
if {![string match {*.ts} $file]} { continue } if {![string match {*.ts} $file]} { continue }
regsub -all {([\\["$])} [file rootname $file] {\\\1} xfile set xfile [file rootname $file]
if {[catch {set eit [exec /mod/bin/stripts -cq "$xdir/$xfile"]}]} { if {[catch {set eit [exec /mod/bin/stripts -cq "$dir/$xfile"]}]} {
continue continue
} }

View File

@ -12,19 +12,20 @@ cgi_input
#set _cgi(dir) "/media/My Video" #set _cgi(dir) "/media/My Video"
set dir [dict get $_cgi dir] set dir [dict get $_cgi dir]
set dlen [string length "$dir/"]
#9.4G /media/My Video/Archive #9.4G /media/My Video/Archive
#1.4G /media/My Video/CSI_ Crime Scene Investigation #1.4G /media/My Video/CSI_ Crime Scene Investigation
puts "{" puts "{"
regsub -all {([\\["$])} $dir {\\\1} xdir
foreach line [split [exec /mod/bin/busybox/du -h -d 1 "$dir/"] "\n"] { foreach line [split [exec /mod/bin/busybox/du -h -d 1 "$dir/"] "\n"] {
lassign [split $line "\t"] size node lassign [split $line "\t"] size node
regsub -- "^$xdir/" $node "" node set node [string range $node $dlen end]
puts "\"$node\" : \"$size\"," puts "\"$node\" : \"$size\","
} }
# Handle symbolic links. # Handle symbolic links.
foreach file [glob -nocomplain "$dir/*"] { foreach file [readdir $dir] {
set file "$dir/$file"
if {[catch {set lk [file readlink $file]}]} continue if {[catch {set lk [file readlink $file]}]} continue
if {![string match "/*" $lk]} { set lk "$dir/$lk" } if {![string match "/*" $lk]} { set lk "$dir/$lk" }

View File

@ -58,7 +58,7 @@ proc dedup {dir} {
} }
proc do_shrink {ts} { proc do_shrink {ts} {
global tmp dustbin global tmp dustbin tsgroup
set file [file rootname [$ts get file]] set file [file rootname [$ts get file]]
if {[catch { if {[catch {
@ -112,8 +112,11 @@ proc do_shrink {ts} {
} }
# Finally, rename the shrunken recording again. # Finally, rename the shrunken recording again.
foreach f [glob "${file}_shrunk.*"] { foreach ext $tsgroup {
file rename $f "${file}[file extension $f]" set f "${file}_shrunk.$ext"
if {[file exists $f]} {
file rename $f "${file}.$ext"
}
} }
} }

View File

@ -122,14 +122,11 @@ proc {system busy} {} {
} }
proc {system inuse} {file} { proc {system inuse} {file} {
# Is anything using the file (used to only check the Humax binary)? # Is anything using the file?
# if {[catch {set pid [exec /mod/bin/busybox/pgrep humaxtv]}]} { set file [file rootname [file tail $file]]
# return 0
# }
regsub -all {([\\["$])} [file rootname [file tail $file]] {\\\1} file
set c 0 set c 0
foreach line [split [exec /mod/bin/lsof] "\n"] { foreach line [split [exec /mod/bin/lsof] "\n"] {
if {[string match "*$file*" $line]} { incr c } if {[string first $file $line] >= 0} { incr c }
} }
if {$c > 0} { return 1 } if {$c > 0} { return 1 }
return 0 return 0

View File

@ -5,6 +5,8 @@ require tdelete system.class
set dmsfile /mnt/hd2/dms_cds.db set dmsfile /mnt/hd2/dms_cds.db
set tsgroup {ts nts hmt thm}
class ts { class ts {
file "" file ""
base "" base ""
@ -108,6 +110,19 @@ proc {ts exec} {file} {
return [exec {*}$cmd] return [exec {*}$cmd]
} }
ts method fileset {} {
global tsgroup
set root [file rootname $file]
set fset {}
foreach ext $tsgroup {
if {[file exists "$root.$ext"]} {
lappend fset "$root.$ext"
}
}
return $fset
}
proc {ts fetch} {file {checked 0}} { proc {ts fetch} {file {checked 0}} {
# Check that this is a .ts file which has at least one sidecar # Check that this is a .ts file which has at least one sidecar
# file (.nts) # file (.nts)
@ -120,12 +135,7 @@ proc {ts fetch} {file {checked 0}} {
} }
ts method delete {} { ts method delete {} {
set root [file rootname $file] foreach f [$self fileset] {
# 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}.*"] {
tdelete $f tdelete $f
puts "Removed $f<br>" puts "Removed $f<br>"
} }
@ -133,9 +143,7 @@ ts method delete {} {
} }
ts method move {dst {touch 0} {force 0}} { ts method move {dst {touch 0} {force 0}} {
set root [file rootname $file] foreach f [$self fileset] {
regsub -all {([\\["$])} $root {\\\1} root
foreach f [glob -nocomplain "${root}.*"] {
set nf "$dst/[file tail $f]" set nf "$dst/[file tail $f]"
while {[file exists $nf]} { while {[file exists $nf]} {
set nf "$dst/_[file tail $nf]" set nf "$dst/_[file tail $nf]"
@ -149,20 +157,12 @@ ts method move {dst {touch 0} {force 0}} {
} }
ts method copy {dst} { ts method copy {dst} {
set root [file rootname $file] foreach f [$self fileset] {
regsub -all {([\\["$])} $root {\\\1} root
foreach f [glob -nocomplain "${root}.*"] {
file copy $f "$dst/[file tail $f]" file copy $f "$dst/[file tail $f]"
} }
return 1 return 1
} }
ts method fileset {} {
set root [file rootname $file]
regsub -all {([\\["$])} $root {\\\1} root
return [glob -nocomplain "${root}.*"]
}
ts method settitle {newtitle} { ts method settitle {newtitle} {
if {[string length newtitle] > 48} { return } if {[string length newtitle] > 48} { return }
@ -193,19 +193,17 @@ ts method dlnaloc {} {
} }
proc {ts renamegroup} {from to} { proc {ts renamegroup} {from to} {
global tsgroup
set dir [file dirname $from] set dir [file dirname $from]
set root [file rootname $from] set root [file rootname $from]
# Catch from string without a . character in it # Catch from string without a . character in it
if {$root eq $from} { return } if {$root eq $from} { return }
# Protect special characters in root. In particular [] characters foreach ext $tsgroup {
# which are used a lot for torrent names. set f "$root.$ext"
regsub -all {([\\["$])} $root {\\\1} root if {![file exists $f]} continue
foreach f [glob -nocomplain "${root}.*"] {
set ext [file extension $f]
#puts "rename $f \"${dir}/${to}${ext}\""
file rename $f "${dir}/${to}${ext}" file rename $f "${dir}/${to}${ext}"
} }