forked from hummypkg/webif
add media rescan
git-svn-id: file:///root/webif/svn/pkg/webif/trunk@2217 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
parent
db75c29143
commit
73f6fd5519
@ -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
|
||||
|
@ -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 "}"
|
||||
|
||||
|
36
webif/cgi-bin/usbrescan.jim
Executable file
36
webif/cgi-bin/usbrescan.jim
Executable file
@ -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 "}"
|
||||
|
BIN
webif/html/img/media-rescan.png
Normal file
BIN
webif/html/img/media-rescan.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
@ -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(
|
||||
'<tr><td><img class=va height=20 ' +
|
||||
'src=/img/usb.png></td>' +
|
||||
'<td class=usblabel>' + v.device + '</td>' +
|
||||
'<td colspan=3 class=blood>' +
|
||||
'(Device not mounted)</td>' +
|
||||
'<td><img class="va rescan" border=0 height=20' +
|
||||
' device=' + v.device +
|
||||
' src=/img/media-rescan.png></td>' +
|
||||
'</tr>');
|
||||
});
|
||||
|
||||
$('#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('<img src=/img/loading.gif> ' +
|
||||
'<span class=blood>Re-scanning ' + dev + '</span>');
|
||||
$.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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -22,7 +22,7 @@ puts {
|
||||
</div>
|
||||
<div class=right><img src=/images/154_1_00_WIN_MD116_3R.png></div>
|
||||
}
|
||||
if {[system model] eq "HDR" && [system usbmounts] > 0} {
|
||||
if {[system model] eq "HDR" && [system usbdisks] > 0} {
|
||||
source /mod/webif/include/usbeject.jim
|
||||
}
|
||||
puts {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user