From b67d67eb916d91e6ac4056e3518706d0ba29ce22 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Thu, 4 Apr 2013 10:18:08 +0200 Subject: [PATCH] Initial checkin of Doodle3D WiFi-box project. Files in src directory belong in /usr/share/lua/autowifi on the device and needs several symlinks as described in the readme. --- .buildpath | 4 + .project | 17 ++++ src/README | 8 ++ src/admin/autowifi.css | 42 +++++++++ src/admin/autowifi.html | 37 ++++++++ src/admin/autowifi.js | 149 +++++++++++++++++++++++++++++++ src/admin/index.html | 7 ++ src/autowifi.lua | 156 ++++++++++++++++++++++++++++++++ src/ext/autowifi.js | 148 +++++++++++++++++++++++++++++++ src/ext/autowifi_init | 12 +++ src/ext/wfcf | 10 +++ src/misc/old/post | 12 +++ src/misc/old/test | 9 ++ src/misc/old/wifi-list.html | 63 +++++++++++++ src/misc/old/wifi-scan | 19 ++++ src/misc/temp | 33 +++++++ src/misc/wireless.org | 45 ++++++++++ src/urlcode.lua | 114 ++++++++++++++++++++++++ src/util.lua | 36 ++++++++ src/wifihelper.lua | 172 ++++++++++++++++++++++++++++++++++++ 20 files changed, 1093 insertions(+) create mode 100644 .buildpath create mode 100644 .project create mode 100644 src/README create mode 100644 src/admin/autowifi.css create mode 100644 src/admin/autowifi.html create mode 100644 src/admin/autowifi.js create mode 100644 src/admin/index.html create mode 100644 src/autowifi.lua create mode 100644 src/ext/autowifi.js create mode 100755 src/ext/autowifi_init create mode 100755 src/ext/wfcf create mode 100755 src/misc/old/post create mode 100755 src/misc/old/test create mode 100644 src/misc/old/wifi-list.html create mode 100755 src/misc/old/wifi-scan create mode 100644 src/misc/temp create mode 100644 src/misc/wireless.org create mode 100644 src/urlcode.lua create mode 100644 src/util.lua create mode 100644 src/wifihelper.lua diff --git a/.buildpath b/.buildpath new file mode 100644 index 0000000..54d943d --- /dev/null +++ b/.buildpath @@ -0,0 +1,4 @@ + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..85a135d --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + d3d-box-wifi + + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + + org.eclipse.koneki.ldt.nature + + diff --git a/src/README b/src/README new file mode 100644 index 0000000..fb55a31 --- /dev/null +++ b/src/README @@ -0,0 +1,8 @@ +Installation: +- place the autowifi directory in /usr/share/lua +- create a symlink to ext/wfcf in /www/cgi-bin (make sure the file is executable) +- create a symlink to ext/autowifi.html in /www +- create a symlink to ext/autowifi.css in /www +- create a symlink to ext/autowifi.js in /www +- create a symlink to ext/autowifi_init in /etc/rc.d and name it S19autowifi_init +- enable init script by calling it with 'enable' argument? diff --git a/src/admin/autowifi.css b/src/admin/autowifi.css new file mode 100644 index 0000000..2467f51 --- /dev/null +++ b/src/admin/autowifi.css @@ -0,0 +1,42 @@ +body { + width: 80%; + background-color: #ffe; +} + +.catgroup { + border: 1px solid black; + padding: 0.5em; + margin-bottom: 10px; + background-color: white; + -moz-border-radius: 5px; + border-radius: 5px; +} + +.cattitle { + display: block; + margin-left: 3em; + margin-bottom: 10px; + font-weight: bold; +} + +table.known_nets { + width: 100%; +} + +table.known_nets th, table.known_nets td { + width: 33%; +} + +.result_success { + font-weight: bold; + color: black; +} + +.result_error { + font-weight: normal; + color: red; +} + +.hidden { + display: none; +} diff --git a/src/admin/autowifi.html b/src/admin/autowifi.html new file mode 100644 index 0000000..23d7b65 --- /dev/null +++ b/src/admin/autowifi.html @@ -0,0 +1,37 @@ + + + + + Doodle3D + + + + + + + + +
+ WiFi mode +
+
+ +
+ Available networks +
+ + + +
+
+ +
+ Known networks +
+
+ + diff --git a/src/admin/autowifi.js b/src/admin/autowifi.js new file mode 100644 index 0000000..132ca88 --- /dev/null +++ b/src/admin/autowifi.js @@ -0,0 +1,149 @@ +/* + * TODO + * - finish network creation + * - finish auto operation + * - call auto op from init script + * - in AP mode, route all addresses to the autowifi page + * - escape text where necessary (e.g. in getKnown, '' is currently interpreted as html...) + * - why is $.trim() required in string comparison? do we need to strip newlines in the parse functions? + * - add hidden field to remember encryption (so we know whether or not a passphrase should be entered) + * - instead of showing alerts on missing ssid/phrase in connect, disable the button until contraints have been satisfied + * (this is also cleaner in case no networks are present) + * - use json for communication + * - local all functions (see: http://stackoverflow.com/questions/4643814/why-would-this-lua-optimization-hack-help) + */ + +animSpeed = 200; +cgiBase = "../cgi-bin/wfcf"; + +function setResultNeutral(text) { + c = $("#op_result"); p = c.parent(); + c.removeClass("result_success").removeClass("result_error").html(text); + if (text == "") p.hide(animSpeed); + else p.show(animSpeed); +} + +/* + * Sets div#op_result content to text, assigns appropiate class based on isError and display: block or, with empty text, display:none. + */ +function setResult(text, isError) { + container = $("#op_result"); + parent = container.parent(); + if (isError) container.removeClass("result_success").addClass("result_error"); + else container.removeClass("result_error").addClass("result_success"); + + if (isError) title = "Error
\n"; + else title = "Success
\n"; + container.html(title + text); + + if (text == "") parent.hide(animSpeed); + else parent.show(animSpeed); +} + +//Returns an array with key 'status' (OK/WARN/ERR), 'msg' (can be empty) and 'status' (remainder of data) +function parseResponse(response) { + var r = {}; + var lines = response.split("\n"); + var st = lines[0].trim().split(','); + lines = lines.slice(1); + + r['status'] = st[0]; + r['msg'] = st.slice(1).join(","); + r['payload'] = lines.join("\n"); + + return r; +} + +function parseNetLine(line) { + var r = {}; + line = line.trim().split(","); + r.ssid = line[0]; + r.bssid = line[1]; + r.channel = line[2]; + r.mode = line[3]; + return r; +} + +function fetchNetworkState() { + $.get(cgiBase + "?op=getstate", function(data) { + data = parseResponse(data); + if (data.status == "ERR") setResult(data.msg, true); + var net = parseNetLine(data.payload); + if (net.mode == "ap") { + $("#wlan_state").text("Access point mode (SSID: " + net.ssid + "; BSSID: " + net.bssid + "; channel: " + net.channel + ")"); + } else { + $("#wlan_state").text("Client mode (SSID: " + net.ssid + "; BSSID: " + net.bssid + "; channel: " + net.channel + ")"); + } + }); +} + +function fetchAvailableNetworks() { + $.get(cgiBase + "?op=getavl", function(data) { + data = parseResponse(data); + if (data.status == "ERR") setResult(data.msg, true); +// else setResult(data.msg, false); + + data = data.payload.split("\n"); + var options = $("#wlan_networks"); + options.empty(); + $.each(data, function(index,value) { + if (value != "") { + var ssid = parseNetLine(value).ssid; + options.append($("