<%# Copyright 2016-2017 Dan Luedtke Licensed to the public under the Apache License 2.0. -%> <% local data = { } local last_device = "" local wg_dump = io.popen("wg show all dump") if wg_dump then local line for line in wg_dump:lines() do local line = string.split(line, "\t") if not (last_device == line[1]) then last_device = line[1] data[line[1]] = { name = line[1], public_key = line[3], listen_port = line[4], fwmark = line[5], peers = { } } else local peer = { public_key = line[2], endpoint = line[4], allowed_ips = { }, latest_handshake = line[6], transfer_rx = line[7], transfer_tx = line[8], persistent_keepalive = line[9] } if not (line[4] == '(none)') then for ipkey, ipvalue in pairs(string.split(line[5], ",")) do if #ipvalue > 0 then table.insert(peer['allowed_ips'], ipvalue) end end end table.insert(data[line[1]].peers, peer) end end end if luci.http.formvalue("status") == "1" then luci.http.prepare_content("application/json") luci.http.write_json(data) return end -%> <%+header%>

WireGuard Status

<%- for ikey, iface in pairs(data) do -%> <%:Interface%> <%=ikey%>
<%:Configuration%>
 
<%:Collecting data...%>
<%- local cur = uci.cursor() for pkey, peer in pairs(iface.peers) do local desc, tmp_desc, pub_key = "", "", "" cur:foreach("network", "wireguard_" .. ikey, function(s) local tmp_desc, pub_key = "", "" for key, value in pairs(s) do if key == "description" then tmp_desc = value end if value == peer.public_key then pub_key = value end if pub_key == peer.public_key and tmp_desc ~= "" then desc = ': ' .. tmp_desc end end end) -%>
<%:Peer%><%=desc%>

?
<%:Collecting data...%>
<%- end -%>
<%- end -%>
<%+footer%>