Browse Source

wanssid broken

Danja Vasiliev 10 years ago
parent
commit
38f0147a8b

+ 3 - 3
openwrt/TLWR710/etc/config/system

@@ -1,7 +1,7 @@
 config system
-  option hostname 'superglue'
-  ## Made in Berlin 
-  option timezone 'CET-1CEST'
+	option hostname 'superglue'
+	## made in berlin 
+	option timezone 'CET-1CEST'
 
 config timeserver 'ntp'
 	list server '0.openwrt.pool.ntp.org'

+ 1 - 1
openwrt/auto_scp.sh

@@ -10,7 +10,7 @@ scp $FILE superglue:/$DEST_FILE;
 if [ $? -eq 0 ]; then 
   play -q -n synth 0.1 tri 5000.0 gain -15;
 else
-  play -q -n synth 0.1 tri 1000.0 gain -10;
+  play -q -n synth 0.5 tri 500.0 gain -10;
 fi' 
 
 #CMD='echo %f'

BIN
openwrt/common/opt/lib/cgi/.admin.cgi.swp


BIN
openwrt/common/opt/lib/cgi/.post.cgi.swp


+ 31 - 2
openwrt/common/opt/lib/cgi/admin2.cgi

@@ -2,6 +2,17 @@
 <%# upload limit: 32Mb %>
 <%
 
+## SuperGlue project | http://superglue.it | 2014 | GPLv3
+## http://git.superglue.it/superglue/serverfiles
+##
+## admin2.cgi - control panel for Superglue personal server
+## 
+## example POST request:
+## curl --data-urlencode 'key=value' http://host/uri
+##
+## returns: 200 (+ output of operation) on success
+##          406 (+ error message in debug mode) on error
+
 _WWW='/www'
 _PWDFILE="/opt/lib/htpasswd"
 _TMP="${_WWW}/tmp"
@@ -203,7 +214,7 @@ ssidChange() {
   fi
 
   logThis "ssid: $_ssid [$_mode], key: $_key [$_enc]"
-  logThis $POST_wanssid
+  #logThis $POST_wanssid
 
   if [[ ${#_ssid} -lt 4 ]]; then
    _ERR=1
@@ -303,6 +314,13 @@ upTime() {
   fi
 }
 
+iwScan() {
+  . /opt/lib/scripts/iw-scan.sh
+  headerPrint 200
+  iwScanJ
+  exit 0
+}
+
 doUci() {
   local _CMD=''
   local _ARG=''
@@ -432,6 +450,8 @@ wanuptime=${wan[4]}
 wanssid=$(doUci get wanssid)
 wankey=$(doUci get wankey)
 
+
+logThis $wanifname
 %>
 
 <body>
@@ -453,9 +473,18 @@ wankey=$(doUci get wankey)
   <option value='wlan1' id='wlan' <% ( [[ $wanifname =~ ('wlan') ]] && _echo 'selected' ) %> >Wireless (Wi-Fi)</option>
   </select>
   <fieldset id='wanwifi' <% ( [[ $wanifname =~ ('wlan') ]] && _echo "class='show'" || _echo "class='hide'" ) %>>
-  <input type='text' name='wanssid' value='<% _echo $wanssid %>'>
+    
+  <select name='wanssid' id='wanssid' style='display:block'>
+  <% if [[ -z $wanssid ]]; then
+    _echo '<option disabled>choose network..</option>'
+  else
+    _echo "<option id=$wanssid selected>$wanssid</option>"
+  fi %>
+  </select>
   <input type='password' name='wankey' value='<% _echo $wankey %>'>
+
   </fieldset>
+
   <span class='help'>help</span>
   </div>
 

+ 49 - 2
openwrt/common/opt/lib/resources/admin/admin.js

@@ -19,6 +19,7 @@ for (i = 0; i < selects.length; i++) {
 }
 */
 
+var wanconf = document.getElementById('wanconf');
 wanconf.addEventListener('change', function(event) { wanChange(event.target) });
 
 function wanChange(e) {
@@ -28,6 +29,7 @@ function wanChange(e) {
   switch (e[e.selectedIndex].id) {
     case 'wlan':
       wanwifi.setAttribute('class','show');
+      iwScan();
       break;
     case 'dhcp':
       wanaddr.setAttribute('class','hide');
@@ -41,9 +43,17 @@ function wanChange(e) {
   }
 }
 
+var wanssid = document.getElementById('wanssid');
+wanssid.addEventListener('focus', function(event) { 
+  console.log('scan now');
+  iwScan();
+  event.stopPropagation();
+});
+
+
 /* update uptime output */
-(function uptimeUpdate(){
-  setTimeout(function(){
+(function uptimeUpdate() {
+  setTimeout(function() {
     ajaxReq('POST', '/admin/uptime', 'null', function(xmlDoc) {
       //console.log(xmlDoc['response'])
       document.getElementById('uptime').innerHTML = xmlDoc['response'];
@@ -52,9 +62,46 @@ function wanChange(e) {
   }, 5000);
 })();
 
+//iwScan();
 
 })();
 
+function iwScan() {
+  function comp(a,b) {
+    if (a.quality < b.quality)
+      return 1;
+    if (a.quality > b.quality)
+      return -1;
+    return 0;
+  }
+  ajaxReq('POST', '/admin/iwscan', 'null', function(xmlDoc) {
+    var res = JSON.parse(xmlDoc['response']);
+    var stas = res['results'].sort(comp);
+    sss = stas;
+    var wanssid = document.getElementById('wanssid');
+    for (var i = 0; i < Object.keys(stas).length; i++) { 
+//      console.log(stas[i]['ssid']);
+//      console.log(stas[i]);
+      var sta;
+      if (sta = document.getElementById(stas[i]['ssid'])) {
+        console.log('found ' + stas[i]['ssid'] + ' entry');
+      } else {
+        sta = document.createElement('option');
+        sta.id = stas[i]['ssid'];
+        sta.setAttribute('data-quality',  stas[i]['quality']);
+        if (stas[i]['encryption']['enabled']) {
+          sta.setAttribute('data-enc', 'wpa2');
+        } else {
+          sta.setAttribute('data-enc', 'false');
+        }
+        sta.innerHTML = stas[i]['ssid'];
+        wanssid.appendChild(sta);
+      }
+    }
+    //  console.log(res);
+  });
+}
+
 function ajaxReq(url, method, data, callback) {
   var xmlDoc = new XMLHttpRequest();
   xmlDoc.open(url, method, true);

+ 13 - 3
openwrt/common/opt/lib/scripts/iw-scan.sh

@@ -1,12 +1,22 @@
 #!/bin/bash
 
-function iwScan() {
+iwScan() {
   set -o noglob
-  local AP S
+  local AP
+  local S
   while read -r AP; do
     [[ "${AP//'SSID: '*}" == '' ]] && printf '%b' "${AP/'SSID: '}\n"
     [[ "${AP//'signal: '*}" == '' ]] && ( S=( ${AP/'signal: '} ); printf '%b' "${S[0]},";)
     [[ "${AP//'last seen: '*}" == '' ]] && ( S=( ${AP/'last seen: '} ); printf '%b' "${S[0]},";)
-  done <<< "$(iw wlan0 scan)"
+  done <<< "$(runSuid iw wlan0 scan)"
   set +o noglob
 }
+
+iwScanJ() {
+  set -o noglob
+  local S=$(runSuid "ubus -S call iwinfo scan '{\"device\":\"wlan0\"}'")
+  printf '%b' "$S"
+  set +o noglob
+}
+
+#iwScanJ