From e4f61f4047bd99532925f867fa75bbbdedeef81d Mon Sep 17 00:00:00 2001 From: hummypkg Date: Tue, 7 Aug 2012 22:22:30 +0000 Subject: [PATCH] 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 --- CONTROL/control | 2 +- var/mongoose/cgi-bin/browse/clipboard.jim | 32 ++++++++------- var/mongoose/cgi-bin/browse/delete.jim | 3 +- var/mongoose/cgi-bin/browse/shrunk.jim | 5 +-- var/mongoose/cgi-bin/browse/sizes.jim | 7 ++-- var/mongoose/lib/bin/auto | 9 +++-- var/mongoose/lib/system.class | 9 ++--- var/mongoose/lib/ts.class | 48 +++++++++++------------ 8 files changed, 58 insertions(+), 57 deletions(-) diff --git a/CONTROL/control b/CONTROL/control index 0333546..aa2be10 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 0.9.13-1 +Version: 0.9.13-3 Architecture: mipsel 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) diff --git a/var/mongoose/cgi-bin/browse/clipboard.jim b/var/mongoose/cgi-bin/browse/clipboard.jim index 4dde470..333e96d 100755 --- a/var/mongoose/cgi-bin/browse/clipboard.jim +++ b/var/mongoose/cgi-bin/browse/clipboard.jim @@ -59,7 +59,7 @@ switch $action { set mode [cgi_get mode copy] foreach p $path { 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
" continue } @@ -95,21 +95,25 @@ switch $action { catch {puts [exec /mod/bin/busybox/cp -r \ $path $dir]} } - } else { - set root [file rootname $path] - # 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}.*"] { - if {$mode eq "cut"} { - catch {file rename $f \ - "$dir/[file tail $f]"} - } else { - catch {file copy $f \ - "$dir/[file tail $f]"} + } elseif {[string match {*.ts} $path]} { + set ts [ts fetch $path] + if {![catch {$ts get file}]} { + foreach f [$ts fileset] { + if {$mode eq "cut"} { + catch {file rename $f \ + "$dir/[file tail $f]"} + } else { + catch {file copy $f \ + "$dir/[file tail $f]"} + } } } + } else { + if {$mode eq "cut"} { + catch {file rename $path "$dir/[file tail $f]"} + } else { + catch {file copy $path "$dir/[file tail $f]"} + } } } $cb clear diff --git a/var/mongoose/cgi-bin/browse/delete.jim b/var/mongoose/cgi-bin/browse/delete.jim index 6a779d5..8a990fe 100755 --- a/var/mongoose/cgi-bin/browse/delete.jim +++ b/var/mongoose/cgi-bin/browse/delete.jim @@ -10,7 +10,6 @@ cgi_input #cgi_dump set dir [cgi_get dir] -regsub -all {([\\["$])} $dir {\\\1} dir #puts "DIR: ($dir)" @@ -40,7 +39,7 @@ foreach file [cgi_get files] { puts -nonewline "
  • \"$file\"..." - if {![string match "$dir/*" $file]} { + if {[string first "$dir/" $file] != 0} { puts "Error - outside directory." continue } diff --git a/var/mongoose/cgi-bin/browse/shrunk.jim b/var/mongoose/cgi-bin/browse/shrunk.jim index 18c7ab2..5f91827 100755 --- a/var/mongoose/cgi-bin/browse/shrunk.jim +++ b/var/mongoose/cgi-bin/browse/shrunk.jim @@ -12,12 +12,11 @@ cgi_input set dir [cgi_get dir "/media/My Video/Children"] puts "{" -regsub -all {([\\["$])} $dir {\\\1} xdir foreach file [readdir -nocomplain $dir] { if {![string match {*.ts} $file]} { continue } - regsub -all {([\\["$])} [file rootname $file] {\\\1} xfile - if {[catch {set eit [exec /mod/bin/stripts -cq "$xdir/$xfile"]}]} { + set xfile [file rootname $file] + if {[catch {set eit [exec /mod/bin/stripts -cq "$dir/$xfile"]}]} { continue } diff --git a/var/mongoose/cgi-bin/browse/sizes.jim b/var/mongoose/cgi-bin/browse/sizes.jim index 794709c..428afec 100755 --- a/var/mongoose/cgi-bin/browse/sizes.jim +++ b/var/mongoose/cgi-bin/browse/sizes.jim @@ -12,19 +12,20 @@ cgi_input #set _cgi(dir) "/media/My Video" set dir [dict get $_cgi dir] +set dlen [string length "$dir/"] #9.4G /media/My Video/Archive #1.4G /media/My Video/CSI_ Crime Scene Investigation puts "{" -regsub -all {([\\["$])} $dir {\\\1} xdir foreach line [split [exec /mod/bin/busybox/du -h -d 1 "$dir/"] "\n"] { lassign [split $line "\t"] size node - regsub -- "^$xdir/" $node "" node + set node [string range $node $dlen end] puts "\"$node\" : \"$size\"," } # 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 {![string match "/*" $lk]} { set lk "$dir/$lk" } diff --git a/var/mongoose/lib/bin/auto b/var/mongoose/lib/bin/auto index d12bd61..18ecaf8 100755 --- a/var/mongoose/lib/bin/auto +++ b/var/mongoose/lib/bin/auto @@ -58,7 +58,7 @@ proc dedup {dir} { } proc do_shrink {ts} { - global tmp dustbin + global tmp dustbin tsgroup set file [file rootname [$ts get file]] if {[catch { @@ -112,8 +112,11 @@ proc do_shrink {ts} { } # Finally, rename the shrunken recording again. - foreach f [glob "${file}_shrunk.*"] { - file rename $f "${file}[file extension $f]" + foreach ext $tsgroup { + set f "${file}_shrunk.$ext" + if {[file exists $f]} { + file rename $f "${file}.$ext" + } } } diff --git a/var/mongoose/lib/system.class b/var/mongoose/lib/system.class index 686732f..e9861b1 100644 --- a/var/mongoose/lib/system.class +++ b/var/mongoose/lib/system.class @@ -122,14 +122,11 @@ proc {system busy} {} { } proc {system inuse} {file} { - # Is anything using the file (used to only check the Humax binary)? -# if {[catch {set pid [exec /mod/bin/busybox/pgrep humaxtv]}]} { -# return 0 -# } - regsub -all {([\\["$])} [file rootname [file tail $file]] {\\\1} file + # Is anything using the file? + set file [file rootname [file tail $file]] set c 0 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 } return 0 diff --git a/var/mongoose/lib/ts.class b/var/mongoose/lib/ts.class index 7a857c6..077c170 100644 --- a/var/mongoose/lib/ts.class +++ b/var/mongoose/lib/ts.class @@ -5,6 +5,8 @@ require tdelete system.class set dmsfile /mnt/hd2/dms_cds.db +set tsgroup {ts nts hmt thm} + class ts { file "" base "" @@ -108,6 +110,19 @@ proc {ts exec} {file} { 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}} { # Check that this is a .ts file which has at least one sidecar # file (.nts) @@ -120,12 +135,7 @@ proc {ts fetch} {file {checked 0}} { } ts method delete {} { - set root [file rootname $file] - # 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}.*"] { + foreach f [$self fileset] { tdelete $f puts "Removed $f
    " } @@ -133,9 +143,7 @@ ts method delete {} { } ts method move {dst {touch 0} {force 0}} { - set root [file rootname $file] - regsub -all {([\\["$])} $root {\\\1} root - foreach f [glob -nocomplain "${root}.*"] { + foreach f [$self fileset] { set nf "$dst/[file tail $f]" while {[file exists $nf]} { set nf "$dst/_[file tail $nf]" @@ -149,20 +157,12 @@ ts method move {dst {touch 0} {force 0}} { } ts method copy {dst} { - set root [file rootname $file] - regsub -all {([\\["$])} $root {\\\1} root - foreach f [glob -nocomplain "${root}.*"] { + foreach f [$self fileset] { file copy $f "$dst/[file tail $f]" } return 1 } -ts method fileset {} { - set root [file rootname $file] - regsub -all {([\\["$])} $root {\\\1} root - return [glob -nocomplain "${root}.*"] -} - ts method settitle {newtitle} { if {[string length newtitle] > 48} { return } @@ -193,19 +193,17 @@ ts method dlnaloc {} { } proc {ts renamegroup} {from to} { + global tsgroup + set dir [file dirname $from] set root [file rootname $from] # Catch from string without a . character in it if {$root eq $from} { return } - # 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}.*"] { - set ext [file extension $f] - #puts "rename $f \"${dir}/${to}${ext}\"" + foreach ext $tsgroup { + set f "$root.$ext" + if {![file exists $f]} continue file rename $f "${dir}/${to}${ext}" }