Merge pull request #2195 from dibdot/wg-qrcode
luci-app-wireguard: add QR Code support plus fixes
This commit is contained in:
commit
bc974aab96
2 changed files with 241 additions and 201 deletions
|
@ -4,8 +4,10 @@
|
|||
-%>
|
||||
|
||||
<%
|
||||
local uci = uci.cursor()
|
||||
local data = { }
|
||||
local last_device = ""
|
||||
local enc = { }
|
||||
|
||||
local wg_dump = io.popen("wg show all dump")
|
||||
if wg_dump then
|
||||
|
@ -21,6 +23,17 @@
|
|||
fwmark = line[5],
|
||||
peers = { }
|
||||
}
|
||||
local s = uci:get_list("network", line[1], "addresses")
|
||||
local address = ""
|
||||
local key, value
|
||||
for key, value in pairs(s) do
|
||||
if address ~= "" then
|
||||
address = address.. ", " ..value
|
||||
else
|
||||
address = value
|
||||
end
|
||||
end
|
||||
enc[line[1]] = "[Interface]\nPrivateKey = " ..line[2].. "\nAddress = " ..address
|
||||
else
|
||||
local peer = {
|
||||
public_key = line[2],
|
||||
|
@ -32,6 +45,7 @@
|
|||
persistent_keepalive = line[9]
|
||||
}
|
||||
if not (line[4] == '(none)') then
|
||||
local ipkey, ipvalue
|
||||
for ipkey, ipvalue in pairs(string.split(line[5], ",")) do
|
||||
if #ipvalue > 0 then
|
||||
table.insert(peer['allowed_ips'], ipvalue)
|
||||
|
@ -39,6 +53,7 @@
|
|||
end
|
||||
end
|
||||
table.insert(data[line[1]].peers, peer)
|
||||
enc[line[1]] = enc[line[1]].. "\n\n[Peer]\nEndpoint = " ..line[4].. "\nPublicKey = " ..line[2].. "\nAllowedIPs = " ..line[5]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -82,6 +97,15 @@
|
|||
return t.toUTCString() + ' (' + ago + ')';
|
||||
}
|
||||
|
||||
function toggle_qrcode(iface) {
|
||||
var view = document.getElementById(iface.name);
|
||||
if (view.style.display === "none") {
|
||||
view.style.display = "block";
|
||||
} else {
|
||||
view.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
|
||||
function(x, data) {
|
||||
for (var key in data) {
|
||||
|
@ -125,7 +149,7 @@
|
|||
if (peer.allowed_ips.length > 0) {
|
||||
s += '<br /><strong><%:Allowed IPs%>:</strong>';
|
||||
for (var k = 0, klen = peer.allowed_ips.length; k < klen; k++) {
|
||||
s += '<br /> • ' + peer.allowed_ips[k];
|
||||
s += '<br />  • ' + peer.allowed_ips[k];
|
||||
}
|
||||
}
|
||||
if (peer.persistent_keepalive != 'off') {
|
||||
|
@ -147,7 +171,7 @@
|
|||
'<br /><strong><%:Data Received%>: </strong>%s' +
|
||||
'<br /><strong><%:Data Transmitted%>: </strong>%s',
|
||||
bytes_to_str(peer.transfer_rx),
|
||||
bytes_to_str(peer.transfer_tx)
|
||||
bytes_to_str(peer.transfer_tx),
|
||||
);
|
||||
document.getElementById(ifname + "_" + peer.public_key + "_icon").innerHTML = icon;
|
||||
document.getElementById(ifname + "_" + peer.public_key + "_info").innerHTML = s;
|
||||
|
@ -158,32 +182,48 @@
|
|||
|
||||
<h2>WireGuard Status</h2>
|
||||
|
||||
<fieldset class="cbi-section">
|
||||
<div class="cbi-section">
|
||||
<%-
|
||||
local ikey, iface
|
||||
for ikey, iface in pairs(data) do
|
||||
-%>
|
||||
<legend><%:Interface%> <%=ikey%></legend>
|
||||
<div class="table" width="100%" cellspacing="10">
|
||||
<div class="tr">
|
||||
<div class="td" width="33%" style="vertical-align:top"><%:Configuration%></div>
|
||||
<div class="td">
|
||||
<div class="table">
|
||||
<div class="tr">
|
||||
<div class="td" id="<%=ikey%>_icon" style="width:16px; text-align:center; padding:3px">
|
||||
|
||||
<h3><%:Interface%> <%=ikey%></h3>
|
||||
<div class="cbi-value" id="button" style="padding: 5px">
|
||||
<input class="cbi-button cbi-button-apply" type="button" name="qrcode_<%=ikey%>" value="<%:Show/Hide QR-Code%>" onclick="toggle_qrcode(this)" />
|
||||
</div>
|
||||
<%-
|
||||
local qrcode
|
||||
if fs.access("/usr/bin/qrencode") then
|
||||
if enc[ikey]:sub(26,31) ~= "(none)" then
|
||||
qrcode = luci.sys.exec("/usr/bin/qrencode --inline --8bit --type=SVG --output=- '" ..enc[ikey].. "'")
|
||||
end
|
||||
else
|
||||
qrcode = "<em>For QR-Code support please install package 'qrencode'!</em>"
|
||||
end
|
||||
-%>
|
||||
<div class="cbi-value-title">
|
||||
<span class="cbi-value" style="display: none" id="qrcode_<%=ikey%>"><%=qrcode%></span>
|
||||
</div>
|
||||
<div class="cbi-section-node">
|
||||
<div class="table cbi-section-table">
|
||||
<div class="tr cbi-section-table-row" style="text-align: left;">
|
||||
<div class="td" style="text-align: left; vertical-align:top"><%:Configuration%></div>
|
||||
<div class="td" style="flex: 0 1 90%; text-align: left;">
|
||||
<div class="table cbi-section-table" style="border: 0px;">
|
||||
<div class="tr cbi-section-table-row" style="text-align: left; border: 0px;">
|
||||
<div class="td" id="<%=ikey%>_icon" style="width: 22px; text-align: left; border-top: 0px; padding: 3px;"> </div>
|
||||
<div class="td" id="<%=ikey%>_info" style="flex: 0 1 90%; text-align: left; vertical-align:middle; padding: 3px; border-top: 0px;"><em><%:Collecting data...%></em></div>
|
||||
</div>
|
||||
<div class="td" id="<%=ikey%>_info" style="vertical-align:middle; padding: 3px">
|
||||
<em><%:Collecting data...%></em>
|
||||
</div>
|
||||
</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<%-
|
||||
local cur = uci.cursor()
|
||||
local pkey, peer
|
||||
for pkey, peer in pairs(iface.peers) do
|
||||
local desc, tmp_desc, pub_key = "", "", ""
|
||||
local desc
|
||||
cur:foreach("network", "wireguard_" .. ikey, function(s)
|
||||
local tmp_desc, pub_key = "", ""
|
||||
local key, value, tmp_desc, pub_key
|
||||
for key, value in pairs(s) do
|
||||
if key == "description" then
|
||||
tmp_desc = value
|
||||
|
@ -191,34 +231,34 @@ for ikey, iface in pairs(data) do
|
|||
if value == peer.public_key then
|
||||
pub_key = value
|
||||
end
|
||||
if pub_key == peer.public_key and tmp_desc ~= "" then
|
||||
if pub_key and tmp_desc then
|
||||
desc = ': ' ..tmp_desc
|
||||
end
|
||||
end
|
||||
end)
|
||||
-%>
|
||||
<div class="tr">
|
||||
<div class="td" width="33%" style="vertical-align:top"><%:Peer%><%=desc%></div>
|
||||
<div class="td">
|
||||
<div class="table">
|
||||
<div class="tr">
|
||||
<div class="td" id="<%=ikey%>_<%=peer.public_key%>_icon" style="width:16px; text-align:center; padding:3px">
|
||||
<img src="<%=resource%>/icons/tunnel_disabled.png" /><br />
|
||||
<div class="tr cbi-section-table-row" style="text-align: left;">
|
||||
<div class="td" style="text-align: left; vertical-align:top"><%:Peer%><%=desc%></div>
|
||||
<div class="td" style="flex: 0 1 90%; text-align: left;">
|
||||
<div class="table cbi-section-table" style="border: 0px">
|
||||
<div class="tr cbi-section-table-row" style="border: 0px;">
|
||||
<div class="td" id="<%=ikey%>_<%=peer.public_key%>_icon" style="width:16px; text-align: left; padding: 3px;border-top: 0px;">
|
||||
<img src="<%=resource%>/icons/tunnel_disabled.png" />
|
||||
<small>?</small>
|
||||
</div>
|
||||
<div class="td" id="<%=ikey%>_<%=peer.public_key%>_info" style="vertical-align:middle; padding: 3px">
|
||||
<em><%:Collecting data...%></em>
|
||||
<div class="td" id="<%=ikey%>_<%=peer.public_key%>_info" style="flex: 0 1 90%; text-align: left; vertical-align:middle; padding: 3px;border-top: 0px;"><em><%:Collecting data...%></em></div>
|
||||
</div>
|
||||
</div>
|
||||
</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<%-
|
||||
end
|
||||
-%>
|
||||
</div>
|
||||
</div>
|
||||
<%-
|
||||
end
|
||||
-%>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<%+footer%>
|
||||
|
|
Loading…
Reference in a new issue