From 73f6fd5519bf1e17f680bed5c00692ac7c182c24 Mon Sep 17 00:00:00 2001 From: hummypkg Date: Thu, 22 Jan 2015 23:21:19 +0000 Subject: [PATCH] add media rescan git-svn-id: file:///root/webif/svn/pkg/webif/trunk@2217 2a923420-c742-0410-a762-8d5b09965624 --- CONTROL/control | 2 +- webif/cgi-bin/usbinfo.jim | 40 +++++++++++++++++++++++++------- webif/cgi-bin/usbrescan.jim | 36 ++++++++++++++++++++++++++++ webif/html/img/media-rescan.png | Bin 0 -> 2164 bytes webif/html/js/usbeject.js | 37 ++++++++++++++++++++++++++++- webif/html/lib/topbar.jim | 2 +- webif/lib/system.class | 22 ++++++++++++++++++ 7 files changed, 128 insertions(+), 11 deletions(-) create mode 100755 webif/cgi-bin/usbrescan.jim create mode 100644 webif/html/img/media-rescan.png diff --git a/CONTROL/control b/CONTROL/control index a81a147..0551c48 100644 --- a/CONTROL/control +++ b/CONTROL/control @@ -1,7 +1,7 @@ Package: webif Priority: optional Section: web -Version: 1.2.0-3 +Version: 1.2.0-4 Architecture: mipsel Maintainer: af123@hummypkg.org.uk Depends: webif-channelicons(>=1.1.14),lighttpd(>=1.4.35-2),jim(>=0.75-1),jim-oo,jim-sqlite3(>=0.75),jim-cgi(>=0.7),jim-binary(>=0.75),service-control(>=2.1),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.0),hmt(>=1.2.0),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,mongoose diff --git a/webif/cgi-bin/usbinfo.jim b/webif/cgi-bin/usbinfo.jim index 4253702..7de762f 100755 --- a/webif/cgi-bin/usbinfo.jim +++ b/webif/cgi-bin/usbinfo.jim @@ -13,23 +13,47 @@ if {[file isdirectory /mnt/hd2]} { lappend ignoredev $st(dev) } -puts "\[" +set usbdisks [system usbdisks 1] + +puts "{" +puts " \"mounts\": \[" set flag 0 foreach usb [system usbmounts 1] { file stat $usb(MP) st if {$usb(MODEL) ne $fsg && $st(dev) in $ignoredev} continue if {$flag} { puts "," } else { set flag 1 } - puts " {" + puts " {" set sf 0 - foreach k [array names usb] { + foreach {k v} $usb { if {$sf} { puts "," } else { set sf 1 } - puts -nonewline " \"$k\": \"$usb($k)\"" + puts -nonewline " \"$k\": \"$v\"" } puts "" - puts -nonewline " }" -} -puts "" -puts "]" + puts -nonewline " }" + + if {[dict exists $usbdisks $usb(RDEV)]} { + dict unset usbdisks $usb(RDEV) + } +} +if {$flag} { puts "" } +puts -nonewline " ]" + +if {[llength $usbdisks] > 0} { + puts "," + puts " \"disks\": \[" + set flag 0 + foreach {k v} $usbdisks { + if {$flag} { puts "," } else { incr flag } + puts " {" + puts " \"device\": \"$k\"," + puts " \"id\": \"$v\"" + puts -nonewline " }" + } + puts "" + puts -nonewline "]" +} + +puts "}" diff --git a/webif/cgi-bin/usbrescan.jim b/webif/cgi-bin/usbrescan.jim new file mode 100755 index 0000000..5907866 --- /dev/null +++ b/webif/cgi-bin/usbrescan.jim @@ -0,0 +1,36 @@ +#!/mod/bin/jimsh + +package require cgi +source /mod/webif/lib/setup +require system.class + +httpheader "application/json" + +set dev [cgi_get device -] + +set disks [system usbdisks 1] + +puts "{" +if {![dict exists $disks $dev]} { + puts "\"status\": 0," + puts "\"result\": \"No such device - $dev.\"" +} else { + set root "/sys/bus/usb/drivers/usb-storage" + set id $disks($dev) + if {[catch { + set fd [open "$root/unbind" w] + puts -nonewline $fd $id + $fd close + set fd [open "$root/bind" w] + puts -nonewline $fd $id + $fd close + } msg]} { + puts "\"status\": 0," + puts "\"result\": \"$msg\"" + } else { + puts "\"status\": 1," + puts "\"result\": \"Successfully re-scanned $dev\"" + } +} +puts "}" + diff --git a/webif/html/img/media-rescan.png b/webif/html/img/media-rescan.png new file mode 100644 index 0000000000000000000000000000000000000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r^RPuIoHEG<0@o`}W-~BHGAH zxj{ruclT$788d3%&xW8-}Qu*4wO zURb|r)B3Lv(aeNtGm-^X%!>fvAR-<+c5+q}MSVo%A|hH@+)qS3j^iA4U3Vx+5(xl} zNs_EV#HWa8iIweyi0Hb`OM`>|{?m>fKMoKvwjVmi06W_S0MNX7bNJr9`&$w501^3R zGvNc%@Ko(v%Siy(A*I}x&9WQ@19cDe3?5^gGj9iypT?e|tFkC`J2ke?Q%O1s* zQso96N~cqg2_ZgcYg?PLswc9af|$*=I@XKjAwEDvc()Kx5s^Cu@)BuKG;&zhD;`2_9HvrU literal 0 HcmV?d00001 diff --git a/webif/html/js/usbeject.js b/webif/html/js/usbeject.js index 6a85831..7c86590 100644 --- a/webif/html/js/usbeject.js +++ b/webif/html/js/usbeject.js @@ -28,7 +28,8 @@ $('#usbeject').on('click', function(e) { $('#usbejectinfo').slideDown(); $.getJSON('/cgi-bin/usbinfo.jim', function(data) { var num = 0; - $.each(data, function(k,v) { + + $.each(data.mounts, function(k,v) { num++; var size = v.SIZE / 1000000000; if (size >= 1000) @@ -71,6 +72,22 @@ $('#usbeject').on('click', function(e) { lineCap: 'butt' }); }); + + if (data.disks) + $.each(data.disks, function(k,v) { + num++; + $('#usbejecttab').append( + '' + + '' + v.device + '' + + '' + + '(Device not mounted)' + + '' + + ''); + }); + $('#usbejectout').empty(); if (!num) $('#usbejectout').html('No removable drives found.'); @@ -95,5 +112,23 @@ $('#usbeject').on('click', function(e) { $(this).remove(); }); }); +}).on('click', 'img.rescan', function(e) { + e.stopPropagation(); + var btn = $(this); + var dev = btn.attr('device'); + if (!confirm('Rescan ' + dev + '?')) + return; + $('#usbejectout').html(' ' + + 'Re-scanning ' + dev + ''); + $.getJSON('/cgi-bin/usbrescan.jim', { + device: dev + }, function(data) { + $('#usbejectout').html(data.result); + if (data.status) + // Success + btn.closest('tr').slideUp('slow', function() { + $(this).remove(); + }); + }); }); diff --git a/webif/html/lib/topbar.jim b/webif/html/lib/topbar.jim index c0e5242..3ac1ff1 100644 --- a/webif/html/lib/topbar.jim +++ b/webif/html/lib/topbar.jim @@ -22,7 +22,7 @@ puts {
} -if {[system model] eq "HDR" && [system usbmounts] > 0} { +if {[system model] eq "HDR" && [system usbdisks] > 0} { source /mod/webif/include/usbeject.jim } puts { diff --git a/webif/lib/system.class b/webif/lib/system.class index 9c19190..b9f7d4f 100644 --- a/webif/lib/system.class +++ b/webif/lib/system.class @@ -392,6 +392,28 @@ proc {system strip} {str} { return $str } +proc {system usbdisks} {{full 0}} { + set disks [glob -nocomplain \ + -directory /sys/bus/usb/drivers/usb-storage *:*] + if {!$full} { + return [llength $disks] + } + if {![llength $disks]} { return {} } + + # Build list of device to device ID + set map {} + foreach block [glob -nocomplain -directory /sys/block sd?] { + set link [file readlink /sys/block/$block/device] + foreach disk $disks { + if {[string first "/$disk/" $link] >= 0} { + set map($block) $disk + } + } + + } + return $map +} + proc {system usbmounts} {{full 0}} { if {!$full} { set num 0