diff --git a/CONTROL/control b/CONTROL/control
index 806eee3..245088b 100644
--- a/CONTROL/control
+++ b/CONTROL/control
@@ -1,10 +1,10 @@
Package: webif
Priority: optional
Section: web
-Version: 1.2.0-1
+Version: 1.2.0-2
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,mongoose
+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,dbupdate,mongoose
Suggests:
Description: An evolving web interface for the Humax.
Tags: http://hummy.tv/forum/threads/5866/
diff --git a/webif/cgi-bin/wifiscan.jim b/webif/cgi-bin/wifiscan.jim
new file mode 100755
index 0000000..899a905
--- /dev/null
+++ b/webif/cgi-bin/wifiscan.jim
@@ -0,0 +1,68 @@
+#!/mod/bin/jimsh
+
+source /mod/webif/lib/setup
+require system.class
+
+httpheader "application/json"
+
+if {![system has wifi_dongle]} {
+ puts "\[]"
+ exit
+}
+
+catch {exec ifconfig wlan0 up}
+if {[catch {set op [exec /mod/bin/iwlist wlan0 scan]}]} {
+ puts "\[]"
+ exit
+}
+
+set lines [split $op "\n"]
+
+puts "\["
+set cur 0
+foreach line [split $op "\n"] {
+ set extra [lassign [split $line :] key val]
+ switch -glob [string trim $key] {
+ *Address {
+ if {$cur} {
+ puts ""
+ puts " \},"
+ } else {
+ incr cur
+ }
+ puts " \{"
+ set mac "$val:[join $extra :]"
+ puts -nonewline " \"address\": \"[string trim $mac]\""
+ }
+ ESSID {
+ puts ","
+ puts -nonewline " \"ssid\": \"[string trim $val \"]\""
+ }
+ Channel {
+ puts ","
+ puts -nonewline " \"channel\": \"[string trim $val]\""
+ }
+ Quality {
+ puts ","
+ #puts "$val $extra"
+ set q [lindex [split $val /] 0]
+ set s [lindex [split [lindex $extra 0] " "] 0]
+ set n [lindex [split [lindex $extra 1] " "] 0]
+ puts " \"quality\": \"$q\","
+ puts " \"signal\": \"$s\","
+ puts -nonewline " \"noise\": \"$n\""
+ }
+ Encryption?key {
+ puts ","
+ puts -nonewline " \"encryption\": \"[string trim $val]\""
+ }
+ }
+}
+
+if {$cur} {
+ puts ""
+ puts " \}"
+}
+
+puts "\]"
+
diff --git a/webif/html/css/style.css b/webif/html/css/style.css
index f8c1b4e..76ef26d 100644
--- a/webif/html/css/style.css
+++ b/webif/html/css/style.css
@@ -235,7 +235,7 @@ pre, .pre
.blood
{
- color: #ff4000;
+ color: #ff4000 !important;
background: transparent;
}
@@ -254,7 +254,7 @@ pre, .pre
.footnote
{
- color: #ff4000;
+ color: #ff4000 !important;
}
.blueshade
diff --git a/webif/html/settings/modules/advanced/settings.hook b/webif/html/settings/modules/advanced/settings.hook
new file mode 100755
index 0000000..6986b0b
--- /dev/null
+++ b/webif/html/settings/modules/advanced/settings.hook
@@ -0,0 +1,24 @@
+
+######################################################################
+# Advanced Settings
+
+puts -nonewline "
+
Advanced Settings
+
+
+
+"
+
diff --git a/webif/html/settings/modules/epg/settings.hook b/webif/html/settings/modules/epg/settings.hook
new file mode 100755
index 0000000..e6fc2b1
--- /dev/null
+++ b/webif/html/settings/modules/epg/settings.hook
@@ -0,0 +1,125 @@
+
+######################################################################
+# EPG Settings
+
+puts "
+EPG Settings
+
+"
+
diff --git a/webif/html/settings/modules/general/settings.hook b/webif/html/settings/modules/general/settings.hook
new file mode 100755
index 0000000..4373290
--- /dev/null
+++ b/webif/html/settings/modules/general/settings.hook
@@ -0,0 +1,94 @@
+
+######################################################################
+# General Settings
+
+puts "
+ General Settings
+
+"
+
diff --git a/webif/html/settings/modules/network/.disabled b/webif/html/settings/modules/network/.disabled
new file mode 100644
index 0000000..e69de29
diff --git a/webif/html/settings/modules/network/save.jim b/webif/html/settings/modules/network/save.jim
new file mode 100755
index 0000000..5df189d
--- /dev/null
+++ b/webif/html/settings/modules/network/save.jim
@@ -0,0 +1,125 @@
+#!/mod/bin/jimsh
+
+package require cgi
+package require sqlite3
+source /mod/webif/lib/setup
+require system.class hexdump
+
+httpheader
+
+set tag [cgi_get tag -]
+set if [cgi_get if -]
+if {$tag eq "-" || $if eq "-"} {
+ puts "Missing tag or interface."
+ exit
+}
+
+proc ip2x {ip {validate 0}} {
+ set octets [split $ip .]
+ if {[llength $octets] != 4} {
+ error "Invalid IP address (octets)"
+ set octets [lrange [concat $octets 0 0 0] 0 3]
+ }
+ if {$validate} {
+ foreach oct $octets {
+ if {$oct < 0 || $oct > 255} {
+ error "Invalid octet, $oct"
+ }
+ }
+ }
+ binary scan [binary format c4 $octets] H8 x
+ return $x
+ }
+
+proc valid_ip {ip} {
+ if {[catch {ip2x $ip 1} msg]} {
+ return 0
+ }
+ return 1
+}
+
+set file "/mod/boot/dbupdate/webif_network_$if"
+
+switch [cgi_get mode -] {
+ static {
+ foreach f {ip mask gw dns} {
+ set errs {}
+ set $f [cgi_get $f -]
+ if {[set $f] eq "-"} {
+ lappend errs "Missing $f"
+ } elseif {![valid_ip [set $f]]} {
+ lappend errs "Invalid $f - [set $f]"
+ }
+ }
+ if {[llength $errs]} {
+ puts [join $errs "
"]
+ exit
+ }
+ set fd [open $file w]
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_$tag:Value:1"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_IP:Blob:[ip2x $ip]"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_NETMASK:Blob:[ip2x $mask]"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_GATEWAY:Blob:[ip2x $gw]"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_DNS:Blob:[ip2x $dns]"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_IP:Value:1"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_NETMASK:Value:1"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_GATEWAY:Value:1"
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_${tag}_DNS:Value:1"
+ }
+ dhcp {
+ set fd [open $file w]
+ puts $fd "setup:MENUCONFIG:ETHERNET_CONF_$tag:Value:0"
+ }
+ default {
+ puts "Unknown mode."
+ exit
+ }
+}
+
+if {$if eq "wifi"} {
+ set ssid [cgi_get ssid SSID]
+ set pass [cgi_get pass PASSPHRASE]
+ set auth [cgi_get auth 7]
+
+ set data [string repeat "\x0" 0xfc]
+ pack data $ssid -str $([string length $ssid] * 8)
+ pack data $pass -str $([string length $pass] * 8) $(8 * 0x78)
+
+ switch $auth {
+ 8 {
+ # "WPA2 PSK (AES)"
+ set bytes {3 4 4}
+ }
+ 7 {
+ # "WPA2 PSK (TKIP+AES)"
+ set bytes {3 4 2}
+ }
+ 6 {
+ # "WPA PSK (AES)"
+ set bytes {2 3 4}
+ }
+ 5 {
+ # "WPA PSK (TKIP)"
+ set bytes {2 3 2}
+ }
+ default {
+ set bytes {0 0 0}
+ }
+ }
+ pack data [lindex $bytes 0] -intle 8 $(8 * 0x68)
+ pack data [lindex $bytes 1] -intle 8 $(8 * 0x6c)
+ pack data [lindex $bytes 2] -intle 8 $(8 * 0x70)
+ #hexdump $data
+
+ binary scan $data H* val
+ puts $fd "setup:MENUCONFIG:WLAN_CONNECTED_AP:Value:0"
+ puts $fd "setup:MENUCONFIG:WLAN_CONNECTED_AP:Blob:$val"
+ puts $fd "setup:MENUCONFIG:WLAN_IS_CONNECTED:Value:1"
+ puts $fd "setup:MENUCONFIG:WLAN_AUTH_TYPE:Value:$auth"
+}
+
+$fd close
+
+system restartpending
+puts "Settings will take effect on next boot."
+
diff --git a/webif/html/settings/modules/network/script.js b/webif/html/settings/modules/network/script.js
new file mode 100644
index 0000000..2121630
--- /dev/null
+++ b/webif/html/settings/modules/network/script.js
@@ -0,0 +1,72 @@
+
+$('#network_settings form').resetForm();
+
+$('#network_settings').on('change', 'input[name=mode]', function(el) {
+ var form = $(this).closest('form');
+
+ val = $(form).find('input[name=mode]:checked').val();
+
+ if (val == 'dhcp')
+ $(form).find('input.static').disable();
+ else
+ $(form).find('input.static').enable();
+});
+
+$('#network_settings input[name=mode]').trigger('change');
+
+$('#ns_pp_toggle').on('click', function(e) {
+ e.preventDefault();
+ if ($('#ns_pp').attr('type') == 'password')
+ {
+ $('#ns_pp').attr('type', 'input');
+ $('#ns_pp_toggle').text('Hide');
+ }
+ else
+ {
+ $('#ns_pp').attr('type', 'password');
+ $('#ns_pp_toggle').text('Reveal');
+ }
+});
+
+$('#ns_ssid_scan').button({
+ icons : {
+ primary : "ui-icon-signal-diag"
+ }
+}).button('enable')
+.on('click', function(e) {
+ e.preventDefault();
+ $('#ns_ssid_scan').button('disable');
+ $('#ns_ssid_loading').show();
+ $('#ns_ssid_list tbody').empty();
+ $('#ns_ssid_list_row').slideDown();
+
+ $.getJSON('/cgi-bin/wifiscan.jim', function(data) {
+ $.each(data, function(k,v) {
+ index = Math.round(v.quality / 20);
+ if (index > 5) index = 5;
+ str =
+' | ';
+if (v.encryption == 'on')
+ str += ' | ';
+else
+ str += ' | ';
+str += '' + v.ssid + ' | ';
+str += '';
+str += '
';
+ $('#ns_ssid_list').append(str);
+ });
+
+ $('#ns_ssid_loading').hide();
+ $('#ns_ssid_scan').button('enable');
+ });
+});
+
+$('#ns_ssid_list').on('click', 'a.ssid', function(el) {
+ el.preventDefault();
+ var form = $(this).closest('form');
+ $(form).find('input[name=ssid]').val($(this).text());
+});
+
+
+
diff --git a/webif/html/settings/modules/network/settings.hook b/webif/html/settings/modules/network/settings.hook
new file mode 100755
index 0000000..cd6ca69
--- /dev/null
+++ b/webif/html/settings/modules/network/settings.hook
@@ -0,0 +1,174 @@
+
+######################################################################
+# Network Settings
+
+proc _ns_extractip {blob} {
+ if {[string bytelength $blob] != 4} { return "" }
+ set r {}
+ binary scan $blob c4 octets
+ foreach octet $octets {
+ lappend r [expr {$octet & 0xff}]
+ }
+ return [join $r .]
+}
+
+proc _ns_ssid {} {
+ set val [system param WLAN_CONNECTED_AP Blob]
+ if {$val ne "0"} {
+ return [string trim [string range $val 0 20]]
+ }
+ return ""
+}
+
+proc _ns_pass {} {
+ set val [system param WLAN_CONNECTED_AP Blob]
+ if {$val ne "0"} {
+ return [string trim [string range $val 120 239]]
+ }
+ return ""
+}
+
+proc _ns_iftable {if tag} {
+ if {[system param ETHERNET_CONF_${tag}] eq 1} {
+ set _static checked
+ set _dhcp ""
+ } else {
+ set _static ""
+ set _dhcp checked
+ }
+ set r "
+
+
+ "
+}
+
+puts "
+Network Settings
+
+
+
+
+
+
+"
+
+
diff --git a/webif/html/settings/modules/web/settings.hook b/webif/html/settings/modules/web/settings.hook
new file mode 100755
index 0000000..376546e
--- /dev/null
+++ b/webif/html/settings/modules/web/settings.hook
@@ -0,0 +1,107 @@
+
+######################################################################
+# Web Interface Settings
+
+puts "
+ Web Interface Settings
+
+
+
+
+
+"
+
+puts {
+
+}
+
diff --git a/webif/html/settings/settings.jim b/webif/html/settings/settings.jim
index 377b1c0..0a8c666 100755
--- a/webif/html/settings/settings.jim
+++ b/webif/html/settings/settings.jim
@@ -156,368 +156,17 @@ proc setting_toggle {name attr checked {invert 0} {val 0}} {
"
}
-puts "
- General Settings
-
-"
-
-puts "
- Web Interface Settings
-
-
-
-
-
-"
-
-puts {
-
-}
-
-
-puts "
-EPG Settings
-
-"
-
-#puts "
-#
-#
-#"
-
-puts -nonewline "
- Advanced Settings
-
-
-
-"
+######################################################################
+# Plugins
set hook settings
foreach plugin [lsort [glob -nocomplain /mod/webif/plugin/*]] {
diff --git a/webif/include/restart.jim b/webif/include/restart.jim
index 16102dd..c1aa33c 100755
--- a/webif/include/restart.jim
+++ b/webif/include/restart.jim
@@ -13,7 +13,8 @@ puts {
- A restart is required in order to complete a scheduling operation.
+ A restart is required in order to complete a scheduling operation or
+ system settings change.
}
diff --git a/webif/lib/hexdump b/webif/lib/hexdump
index 9c1122e..f14c158 100644
--- a/webif/lib/hexdump
+++ b/webif/lib/hexdump
@@ -7,7 +7,8 @@ proc hexdump data {
set bytes [string byterange $data $n $($n+15)]
binary scan $bytes H* hex
set hex [regexp -all -inline .. $hex]
- regsub -all -- {[^a-z0-9]} $bytes . ascii
+ regsub -all -- {[\x01-\x1f\x80-\xff]} [\
+ string map {\x00 .} $bytes] . ascii
append dump [format "%04X: %-48s %-16s\n" $n $hex $ascii]
incr n 16
}
diff --git a/webif/lib/system.class b/webif/lib/system.class
index 695c9f5..9c19190 100644
--- a/webif/lib/system.class
+++ b/webif/lib/system.class
@@ -456,3 +456,15 @@ proc {system usbmounts} {{full 0}} {
return $ret
}
+proc {system has} {comp} {
+ switch $comp {
+ wifi_dongle {
+ if {[catch {exec /mod/bin/iwgetid}]} {
+ return 0
+ }
+ return 1
+ }
+ }
+ return 0
+}
+