luci-app-travelmate: sync with update 1.2.4 2202/head
authorDirk Brenken <dev@brenken.org>
Fri, 5 Oct 2018 08:21:34 +0000 (10:21 +0200)
committerDirk Brenken <dev@brenken.org>
Fri, 5 Oct 2018 08:27:36 +0000 (10:27 +0200)
* with the config option 'trm_radio' you can now restrict travelmate
  to a single radio (e.g. 'radio1') or change the overall
  scanning order (e.g. 'radio1 radio2 radio0')
* LuCI: show QR codes now inline on the overview page
  (collapsed by default)

Signed-off-by: Dirk Brenken <dev@brenken.org>
applications/luci-app-travelmate/luasrc/controller/travelmate.lua
applications/luci-app-travelmate/luasrc/model/cbi/travelmate/overview_tab.lua
applications/luci-app-travelmate/luasrc/view/travelmate/ap_qr.htm [deleted file]
applications/luci-app-travelmate/luasrc/view/travelmate/runtime.htm

index 775831d9d00090e84dbbf31ecb7b2a8d291fc50b..0c5890810e9aaca12c69222097a91207d25f04a8 100644 (file)
@@ -27,7 +27,6 @@ function index()
        entry({"admin", "services", "travelmate", "logread"}, call("logread"), nil).leaf = true
        entry({"admin", "services", "travelmate", "status"}, call("status_update"), nil).leaf = true
        entry({"admin", "services", "travelmate", "action"}, call("trm_action"), nil).leaf = true
-       entry({"admin", "services", "travelmate", "apqr"}, template("travelmate/ap_qr")).leaf = true
        entry({"admin", "services", "travelmate", "wifiscan"}, template("travelmate/wifi_scan")).leaf = true
        entry({"admin", "services", "travelmate", "wifiadd"}, form("travelmate/wifi_add", {hideresetbtn=true, hidesavebtn=true})).leaf = true
        entry({"admin", "services", "travelmate", "wifiedit"}, form("travelmate/wifi_edit", {hideresetbtn=true, hidesavebtn=true})).leaf = true
index a1a7ed72c3602e0ad3b857062118589b82bac32b..9ba4cf3bf2f9df332c69c6c3a9c58eeca289ad8d 100644 (file)
@@ -56,7 +56,7 @@ end
 
 s = m:section(NamedSection, "global", "travelmate")
 
-o1 = s:option(Flag, "trm_enabled", translate("Enable travelmate"))
+o1 = s:option(Flag, "trm_enabled", translate("Enable Travelmate"))
 o1.default = o1.disabled
 o1.rmempty = false
 
@@ -78,18 +78,6 @@ end
 o3.default = trmiface
 o3.rmempty = false
 
-if fs.access("/usr/bin/qrencode") then
-       btn = s:option(Button, "btn", translate("View AP QR-Codes"),
-               translate("Connect your Android or iOS devices to your router's WiFi using the shown QR code."))
-       btn.inputtitle = translate("QR-Codes")
-       btn.inputstyle = "apply"
-       btn.disabled = false
-
-       function btn.write()
-               luci.http.redirect(luci.dispatcher.build_url("admin", "services", "travelmate", "apqr"))
-       end
-end
-
 -- Runtime information
 
 ds = s:option(DummyValue, "_dummy")
@@ -97,16 +85,15 @@ ds.template = "travelmate/runtime"
 
 -- Extra options
 
-e = m:section(NamedSection, "global", "travelmate", translate("Extra options"),
+e = m:section(NamedSection, "global", "travelmate", translate("Extra Options"),
 translate("Options for further tweaking in case the defaults are not suitable for you."))
 
-e1 = e:option(Flag, "trm_debug", translate("Enable verbose debug logging"))
+e1 = e:option(Flag, "trm_debug", translate("Enable Verbose Debug Logging"))
 e1.default = e1.disabled
 e1.rmempty = false
 
-e2 = e:option(Value, "trm_radio", translate("Radio selection"),
-       translate("Restrict travelmate to a dedicated radio, e.g. 'radio0'."))
-e2.datatype = "and(uciname,rangelength(6,6))"
+e2 = e:option(Value, "trm_radio", translate("Radio Selection / Order"),
+       translate("Restrict travelmate to a single radio (e.g. 'radio1') or change the overall scanning order (e.g. 'radio1 radio2 radio0')."))
 e2.rmempty = true
 
 e3 = e:option(Value, "trm_triggerdelay", translate("Trigger Delay"),
diff --git a/applications/luci-app-travelmate/luasrc/view/travelmate/ap_qr.htm b/applications/luci-app-travelmate/luasrc/view/travelmate/ap_qr.htm
deleted file mode 100644 (file)
index 3f01a81..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-<%#
-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 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 ""
-                       local hidden = s.hidden or "false"
-                       local disabled = s.disabled or ""
-                       local wep_slots = {s.key1 or "", s.key2 or "", s.key3 or "", s.key4 or ""}
-
-                       if device and mode == "ap" and disabled ~= "1" then
-                               if string.match(enc, '^psk') then
-                                       enc = "WPA"
-                               elseif string.match(enc, '^wep') then
-                                       enc = "WEP"
-                                       if tonumber(key) then
-                                               key = wep_slots[tonumber(key)]
-                                       end
-                               elseif enc == "none" then
-                                       enc = "nopass"
-                                       key = "nokey"
-                               else
-                                       enc = ""
-                               end
-
-                               if hidden == "1" then
-                                       hidden = "true"
-                               end
-
-                               if ssid and enc and key then
-                                       local e_ssid = string.gsub(ssid,"[\"\\';:, ]",[[\\\%1]])
-                                       local e_key = string.gsub(key,"[\"\\';:, ]",[[\\\%1]])
-                                       local qrcode = ""
-
-                                       qrcode = luci.sys.exec("/usr/bin/qrencode --inline --8bit --type=SVG --output=- 'WIFI:S:\"'" .. e_ssid .. "'\";T:'" .. enc .. "';P:\"'" .. e_key .. "'\";H:'" .. hidden .. "';'")
-       -%>
-       <div class="cbi-section">
-               <h3>AP on <%=device%> with SSID "<%=ssid%>"</h3>
-               <h3><%=qrcode%></h3>
-       </div>
-       <%-
-                               end
-                       end
-               end)
-       -%>
-</div>
-<div class="cbi-page-actions right">
-       <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/tab_from_cbi')%>" method="post">
-               <input class="cbi-button cbi-button-reset" type="submit" value="<%:Back to overview%>" />
-       </form>
-</div>
-
-<%+footer%>
index 272612600cd95f6e199c19a3a810b9ba869030a3..1a53b577d12afb98202afb95bfa045bea6cfd2f3 100644 (file)
@@ -75,6 +75,15 @@ This is free software, licensed under the Apache License, Version 2.0
                }
        }
 
+       function toggle_qrcode() {
+               var view = document.getElementById("qrcode");
+               if (view.style.display === "none") {
+                       view.style.display = "block";
+               } else {
+                       view.style.display = "none";
+               }
+       }
+
        XHR.get('<%=luci.dispatcher.build_url("admin", "services", "travelmate", "status")%>', null,
        function(x, json_info)
        {
@@ -142,3 +151,74 @@ This is free software, licensed under the Apache License, Version 2.0
                <span id="btn1_running" style="display:inline-block; width:16px; height:16px; margin:0 5px"></span>
        </div>
 </div>
+<div class="cbi-value" id="button_2">
+       <label class="cbi-value-title" for="button_2"><%:View AP QR-Codes%></label>
+       <div class="cbi-value-field">
+               <input class="cbi-button cbi-button-apply" type="button" value="<%:Show/Hide QR-Codes%>" onclick="toggle_qrcode()" />
+       </div>
+</div>
+<div class="cbi-value" style="margin-bottom: 0px">
+       <span class="cbi-value" style="display: none" id="qrcode">
+<%-
+               local fs  = require("nixio.fs")
+               local uci = require("luci.model.uci").cursor()
+               local qrcode
+
+               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 ""
+                       local hidden = s.hidden or "false"
+                       local disabled = s.disabled or ""
+                       local wep_slots = {s.key1 or "", s.key2 or "", s.key3 or "", s.key4 or ""}
+
+                       if device and mode == "ap" and disabled ~= "1" then
+                               if string.match(enc, '^psk') then
+                                       enc = "WPA"
+                               elseif string.match(enc, '^wep') then
+                                       enc = "WEP"
+                                       if tonumber(key) then
+                                               key = wep_slots[tonumber(key)]
+                                       end
+                               elseif enc == "none" then
+                                       enc = "nopass"
+                                       key = "nokey"
+                               else
+                                       enc = ""
+                               end
+
+                               if hidden == "1" then
+                                       hidden = "true"
+                               end
+
+                               if ssid and enc and key then
+                                       local e_ssid = string.gsub(ssid,"[\"\\';:, ]",[[\\\%1]])
+                                       local e_key = string.gsub(key,"[\"\\';:, ]",[[\\\%1]])
+
+                                       if fs.access("/usr/bin/qrencode") then
+                                               qrcode = luci.sys.exec("/usr/bin/qrencode --inline --8bit --type=SVG --output=- 'WIFI:S:\"'" .. e_ssid .. "'\";T:'" .. enc .. "';P:\"'" .. e_key .. "'\";H:'" .. hidden .. "';'")
+-%>
+               <div class="cbi-value" style="border-bottom: 0px; margin-bottom: 0px; padding: 0.25em 0.6em; text-align: left">
+                       <%=qrcode%>
+               </div>
+               <div class="cbi-value" style="border-bottom: 0px; margin-bottom: 0px; padding: 0.25em 0.6em; text-align: left">
+                       <em><%:AP on %><%=device%><%: with SSID %>"<%=ssid%>"</em>
+                       <hr />
+               </div>
+<%-
+                                       end
+                               end
+                       end
+               end)
+               if not qrcode then
+-%>
+               <div class="cbi-value" style="border-bottom: 0px; margin-bottom: 0px; padding: 0.25em 0.6em; text-align: left">
+                       <em><%:For QR-Code support please install package 'qrencode'!%></em>
+               </div>
+<%-
+               end
+-%>
+       </span>
+</div>