luci-app-travelmate: fixes for new QR code template
[project/luci.git] / applications / luci-app-travelmate / luasrc / view / travelmate / ap_qr.htm
1 <%#
2 Copyright 2018 Dirk Brenken (dev@brenken.org)
3 This is free software, licensed under the Apache License, Version 2.0
4 -%>
5
6 <%+header%>
7
8 <div class="cbi-map">
9     <div class="cbi-map-descr">
10         <%=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.")%>
11     </div>
12 <%-
13   local write = io.write
14   local uci   = require("luci.model.uci").cursor()
15
16   uci:foreach("wireless", "wifi-iface", function(s)
17     local device = s.device or ""
18     local mode = s.mode or ""
19     local ssid = s.ssid or ""
20     local enc = s.encryption or ""
21     local key = s.key or ""
22     local hidden = s.hidden or "false"
23     local disabled = s.disabled or ""
24     local wep_slots = {s.key1 or "", s.key2 or "", s.key3 or "", s.key4 or ""}
25
26     if device and mode == "ap" and disabled ~= "1" then
27       if string.match(enc, '^psk') then
28         enc = "WPA"
29       elseif string.match(enc, '^wep') then
30         enc = "WEP"
31         if tonumber(key) then
32           key = wep_slots[tonumber(key)]
33         end
34       elseif enc == "none" then
35         enc = "nopass"
36         key = "nokey"
37       else
38         enc = ""
39       end
40       if hidden == "1" then
41         hidden = "true"
42       end
43       if ssid and enc and key then
44         local e_ssid = string.gsub(ssid,"[\"\\';:, ]",[[\\\%1]])
45         local e_key = string.gsub(key,"[\"\\';:, ]",[[\\\%1]])
46         local qrcode = ""
47         if nixio.fs.access("/usr/bin/qrencode") then
48           qrcode = luci.sys.exec("/usr/bin/qrencode -I -t SVG -8 -o - 'WIFI:S:\"'" .. e_ssid .. "'\";T:'" .. enc .. "';P:\"'" .. e_key .. "'\";H:'" .. hidden .. "';'")
49         end
50 -%>
51     <fieldset class="cbi-section">
52         <legend>AP on <%=device%> with SSID "<%=ssid%>"</legend>
53         <h3 name="content"><%=qrcode%></h3>
54     </fieldset>
55 <%-
56       end
57     end
58   end)
59 %>
60 </div>
61
62 <%+footer%>