From f52ec227175c9db1bfee95f8a59c7c56d01911d4 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 8 Feb 2009 03:56:50 +0000 Subject: modules/admin-full: implement iptables status page i18n/english: resync xml, add strings for iptables page libs/sys/iptparser: implement chain() and is_custom_target() --- .../admin-full/luasrc/controller/admin/status.lua | 19 ++- .../luasrc/view/admin_status/iptables.htm | 137 +++++++++++++++++++++ 2 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 modules/admin-full/luasrc/view/admin_status/iptables.htm (limited to 'modules') diff --git a/modules/admin-full/luasrc/controller/admin/status.lua b/modules/admin-full/luasrc/controller/admin/status.lua index 09e7766c1..fd61459e9 100644 --- a/modules/admin-full/luasrc/controller/admin/status.lua +++ b/modules/admin-full/luasrc/controller/admin/status.lua @@ -19,7 +19,8 @@ function index() entry({"admin", "status"}, template("admin_status/index"), i18n("status", "Status"), 20).index = true entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("syslog", "Systemprotokoll"), 1) - entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("dmesg", "Kernelprotokoll"), 2) + entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("dmesg", "Kernelprotokoll"), 2) + entry({"admin", "status", "iptables"}, call("action_iptables"), i18n("a_s_ipt", "Firewall"), 3) end function action_syslog() @@ -31,3 +32,19 @@ function action_dmesg() local dmesg = luci.sys.dmesg() luci.template.render("admin_status/dmesg", {dmesg=dmesg}) end + +function action_iptables() + if luci.http.formvalue("zero") == "1" then + luci.util.exec("iptables -Z") + luci.http.redirect( + luci.dispatcher.build_url("admin", "status", "iptables") + ) + elseif luci.http.formvalue("restart") == "1" then + luci.util.exec("/etc/init.d/firewall restart") + luci.http.redirect( + luci.dispatcher.build_url("admin", "status", "iptables") + ) + else + luci.template.render("admin_status/iptables") + end +end diff --git a/modules/admin-full/luasrc/view/admin_status/iptables.htm b/modules/admin-full/luasrc/view/admin_status/iptables.htm new file mode 100644 index 000000000..da0a994d9 --- /dev/null +++ b/modules/admin-full/luasrc/view/admin_status/iptables.htm @@ -0,0 +1,137 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2009 Steven Barth +Copyright 2009 Jo-Philipp Wich + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> + +<%- + + require "luci.sys.iptparser" + require "luci.tools.webadmin" + + local ipt = luci.sys.iptparser.IptParser() + local wba = luci.tools.webadmin + + local rowcnt = 1 + function rowstyle() + rowcnt = rowcnt + 1 + return (rowcnt % 2) + 1 + end + + function link_target(t,c) + if ipt:is_custom_target(c) then + return '%s' %{ t:lower(), c, c } + end + return c + end + + function link_iface(i) + local net = wba.iface_get_network(i) + if net and i ~= "lo" then + return '%s' %{ + luci.dispatcher.build_url("admin", "network", "network", net), i + } + + end + return i + end + +-%> + +<%+header%> + +

<%:a_s_ipt_status Firewall Status%>

+ +
+
+
+
+

<%:a_s_ipt_actions Actions%>

+ +
+
+ +
+ <% for _, tbl in ipairs({"Filter", "NAT", "Mangle"}) do chaincnt = 0 %> +

<%:a_s_ipt_table Table%>: <%=tbl%>

+ + <% for _, chain in ipairs(ipt:chains(tbl)) do + rowcnt = 0 + chaincnt = chaincnt + 1 + chaininfo = ipt:chain(tbl, chain) + %> + + + + + + + + + + + + + + + + + + <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %> + + + + + + + + + + + + + + <% end %> + + <% if rowcnt == 1 then %> + + + + <% end %> + <% end %> + + <% if chaincnt == 0 then %> + + + + <% end %> +
+
+ <%:a_s_ipt_chain Chain%> <%=chain%> + (<%- if chaininfo.policy then -%> + <%:a_s_ipt_policy Policy%>: <%=chaininfo.policy%>, <%:a_s_ipt_packets Packets%>: <%=chaininfo.packets%>, <%:a_s_ipt_bytes Traffic%>: <%=wba.byte_format(chaininfo.bytes)-%> + <%- else -%> + <%:a_s_ipt_references References%>: <%=chaininfo.references-%> + <%- end -%>) +
<%:a_s_ipt_rulenum Rule #%><%:a_s_ipt_packets Pkts.%><%:a_s_ipt_bytes Traffic%><%:a_s_ipt_target Target%><%:a_s_ipt_proto Prot.%><%:a_s_ipt_flags Flags%><%:a_s_ipt_inputif In%><%:a_s_ipt_outputif Out%><%:a_s_ipt_source Source%><%:a_s_ipt_destination Destination%><%:a_s_ipt_options Options%>
<%=rule.index%><%=rule.packets%><%=wba.byte_format(rule.bytes)%><%=link_target(tbl, rule.target)%><%=rule.protocol%><%=rule.flags%><%=link_iface(rule.inputif)%><%=link_iface(rule.outputif)%><%=rule.source%><%=rule.destination%><%=#rule.options > 0 and table.concat(rule.options, " ") or "-"%>
<%:a_s_ipt_norules No rules in this chain%>
<%:a_s_ipt_nochains No chains in this table%>
+

+ <% end %> +
+
+
+
+ +<%+footer%> +<% if ret == 0 then luci.sys.reboot() end %> -- cgit v1.2.3