<%# 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[5], fwmark = line[6], peers = { } } else local peer = { public_key = line[2], endpoint = line[3], allowed_ips = { }, latest_handshake = line[5], transfer_rx = line[6], transfer_tx = line[7], persistent_keepalive = line[8] } if not (line[4] == '(none)') then for ipkey, ipvalue in pairs(string.split(line[4], ",")) 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%> <%- for pkey, peer in pairs(iface.peers) do -%> <%- end -%>
<%:Configuration%>
  <%:Collecting data...%>
<%:Peer%>

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