luci-app-travelmate: sync with release 1.1.3 1658/head
authorDirk Brenken <dev@brenken.org>
Fri, 2 Mar 2018 17:06:38 +0000 (18:06 +0100)
committerDirk Brenken <dev@brenken.org>
Fri, 2 Mar 2018 17:06:38 +0000 (18:06 +0100)
* show WiFi QR codes from all configured Access Points

Signed-off-by: Dirk Brenken <dev@brenken.org>
applications/luci-app-travelmate/Makefile
applications/luci-app-travelmate/luasrc/controller/travelmate.lua
applications/luci-app-travelmate/luasrc/view/travelmate/ap_qr.htm [new file with mode: 0644]
applications/luci-app-travelmate/luasrc/view/travelmate/stations.htm

index 6170f9d..2bd25bc 100644 (file)
@@ -1,11 +1,11 @@
-# Copyright 2017 Dirk Brenken (dev@brenken.org)
+# Copyright 2017-2018 Dirk Brenken (dev@brenken.org)
 # This is free software, licensed under the Apache License, Version 2.0
 #
 
 include $(TOPDIR)/rules.mk
 
 LUCI_TITLE:=LuCI support for Travelmate
 # This is free software, licensed under the Apache License, Version 2.0
 #
 
 include $(TOPDIR)/rules.mk
 
 LUCI_TITLE:=LuCI support for Travelmate
-LUCI_DEPENDS:=+travelmate +luci-lib-jsonc
+LUCI_DEPENDS:=+travelmate +luci-lib-jsonc +qrencode
 LUCI_PKGARCH:=all
 
 include ../../luci.mk
 LUCI_PKGARCH:=all
 
 include ../../luci.mk
index 0f75834..14b8d77 100644 (file)
@@ -3,7 +3,6 @@
 
 module("luci.controller.travelmate", package.seeall)
 
 
 module("luci.controller.travelmate", package.seeall)
 
-local fs    = require("nixio.fs")
 local util  = require("luci.util")
 local i18n  = require("luci.i18n")
 local templ = require("luci.template")
 local util  = require("luci.util")
 local i18n  = require("luci.i18n")
 local templ = require("luci.template")
@@ -15,7 +14,8 @@ function index()
        entry({"admin", "services", "travelmate"}, firstchild(), _("Travelmate"), 40).dependent = false
        entry({"admin", "services", "travelmate", "tab_from_cbi"}, cbi("travelmate/overview_tab", {hideresetbtn=true, hidesavebtn=true}), _("Overview"), 10).leaf = true
        entry({"admin", "services", "travelmate", "stations"}, template("travelmate/stations"), _("Wireless Stations"), 20).leaf = true
        entry({"admin", "services", "travelmate"}, firstchild(), _("Travelmate"), 40).dependent = false
        entry({"admin", "services", "travelmate", "tab_from_cbi"}, cbi("travelmate/overview_tab", {hideresetbtn=true, hidesavebtn=true}), _("Overview"), 10).leaf = true
        entry({"admin", "services", "travelmate", "stations"}, template("travelmate/stations"), _("Wireless Stations"), 20).leaf = true
-       entry({"admin", "services", "travelmate", "logfile"}, call("logread"), _("View Logfile"), 30).leaf = true
+       entry({"admin", "services", "travelmate", "apqr"}, template("travelmate/ap_qr"), _("AP QR-Codes"), 30).leaf = true
+       entry({"admin", "services", "travelmate", "logfile"}, call("logread"), _("View Logfile"), 40).leaf = true
        entry({"admin", "services", "travelmate", "advanced"}, firstchild(), _("Advanced"), 100)
        entry({"admin", "services", "travelmate", "advanced", "configuration"}, cbi("travelmate/configuration_tab"), _("Edit Travelmate Configuration"), 110).leaf = true
        entry({"admin", "services", "travelmate", "advanced", "cfg_wireless"}, cbi("travelmate/cfg_wireless_tab"), _("Edit Wireless Configuration"), 120).leaf = true
        entry({"admin", "services", "travelmate", "advanced"}, firstchild(), _("Advanced"), 100)
        entry({"admin", "services", "travelmate", "advanced", "configuration"}, cbi("travelmate/configuration_tab"), _("Edit Travelmate Configuration"), 110).leaf = true
        entry({"admin", "services", "travelmate", "advanced", "cfg_wireless"}, cbi("travelmate/cfg_wireless_tab"), _("Edit Wireless Configuration"), 120).leaf = true
diff --git a/applications/luci-app-travelmate/luasrc/view/travelmate/ap_qr.htm b/applications/luci-app-travelmate/luasrc/view/travelmate/ap_qr.htm
new file mode 100644 (file)
index 0000000..6d66150
--- /dev/null
@@ -0,0 +1,63 @@
+<%#
+Copyright 2018 Dirk Brenken (dev@brenken.org)
+This is free software, licensed under the Apache License, Version 2.0
+-%>
+
+<%+header%>
+
+<div class="cbi-map">
+    <div class="cbi-map-descr">
+        <%=translate("Here you'll find the QR codes from all of your configured Access Points. It allows you to connect your Android or iOS devices to your router's WiFi using the QR code shown below.")%>
+    </div>
+<%-
+  local write = io.write
+  local uci   = require("luci.model.uci").cursor()
+
+  uci:foreach("wireless", "wifi-iface", function(s)
+    local device = s.device or ""
+    local mode = s.mode or ""
+    local ssid = s.ssid or ""
+    local enc = s.encryption or ""
+    local key = s.key or "nokey"
+    local hidden = s.hidden or "false"
+    local disabled = s.disabled or ""
+    if device ~= "" and mode == "ap" and disabled ~= "1" then
+      if string.match(enc, '^psk2') then
+        enc = "wpa2"
+      elseif string.match(enc, '^psk') then
+        enc = "wpa"
+      elseif string.match(enc, '^wep') then
+        if tonumber(key) then
+          enc = ""
+        else
+          enc = "wep"
+        end
+      elseif enc == "none" then
+        enc = "nopass"
+        key = "nokey"
+      else
+        enc = ""
+      end
+      if hidden == "1" then
+        hidden = "true"
+      end
+      if ssid ~= "" and enc ~= "" then
+        local e_ssid = string.gsub(ssid,"[\";\\:, ]","\\%1")
+        local e_key = string.gsub(key,"[\";\\:, ]","\\%1")
+        local qrcode = ""
+        if nixio.fs.access("/usr/bin/qrencode") then
+          qrcode = luci.sys.exec("/usr/bin/qrencode -I -t SVG -8 -o - 'WIFI:S:\"'" .. e_ssid .. "'\";T:'" .. enc .. "';P:\"'" .. e_key .. "'\";H:'" .. hidden .. "';'")
+        end
+-%>
+    <fieldset class="cbi-section">
+        <legend>AP on <%=device%> with SSID "<%=ssid%>"</legend>
+        <h3 name="content"><%=qrcode%></h3>
+    </fieldset>
+<%-
+      end
+    end
+  end)
+%>
+</div>
+
+<%+footer%>
index a267339..1dacb6e 100644 (file)
@@ -12,7 +12,6 @@ This is free software, licensed under the Apache License, Version 2.0
 <%+header%>
 
 <div class="cbi-map">
 <%+header%>
 
 <div class="cbi-map">
-<h2 name="content"><%:Wireless Stations%></h2>
 <div class="cbi-map-descr">
   <%=translatef("Provides an overview of all configured uplinks for the travelmate interface (%s). You can edit, delete or re-order existing uplinks or scan for a new one. The currently used uplink is emphasized in blue.", trmiface)%>
 </div>
 <div class="cbi-map-descr">
   <%=translatef("Provides an overview of all configured uplinks for the travelmate interface (%s). You can edit, delete or re-order existing uplinks or scan for a new one. The currently used uplink is emphasized in blue.", trmiface)%>
 </div>