<%# 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%> <%- for pkey, peer in pairs(iface.peers) do -%> <%- end -%>
<%:Configuration%>
  <%:Collecting data...%>
<%:Peer%>

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