2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
17 local uci = require "luci.model.uci"
18 local util = require "luci.util"
19 local table = require "table"
22 module "luci.tools.ffwizard"
24 -- Deletes all references of a wifi device
25 function wifi_delete_ifaces(device)
26 local cursor = uci.cursor()
27 cursor:delete_all("wireless", "wifi-iface", {device=device})
28 cursor:save("wireless")
31 -- Deletes a network interface and all occurences of it in firewall zones and dhcp
32 function network_remove_interface(iface)
33 local cursor = uci.cursor()
35 if not cursor:delete("network", iface) then
39 local aliases = {iface}
40 cursor:foreach("network", "alias",
42 table.insert(aliases, section[".name"])
45 -- Delete Aliases and Routes
46 cursor:delete_all("network", nil, {interface=iface})
48 -- Delete DHCP sections
49 cursor:delete_all("dhcp", "dhcp",
51 return util.contains(aliases, section.interface)
54 -- Remove OLSR sections
55 cursor:delete_all("olsr", "Interface", {Interface=iface})
57 -- Remove Splash sections
58 cursor:delete_all("luci-splash", "iface", {network=iface})
60 cursor:save("network")
63 cursor:save("luci-splash")
66 -- Creates a firewall zone
67 function firewall_create_zone(zone, input, output, forward, masq)
68 local cursor = uci.cursor()
69 if not firewall_find_zone(zone) then
70 local stat = cursor:section("firewall", "zone", nil, {
77 cursor:save("firewall")
82 -- Adds interface to zone, creates zone on-demand
83 function firewall_zone_add_interface(name, interface)
84 local cursor = uci.cursor()
85 local zone = firewall_find_zone(name)
86 local net = cursor:get("firewall", zone, "network")
87 cursor:set("firewall", zone, "network", (net or name .. " ") .. interface)
88 cursor:save("firewall")
91 -- Removes interface from zone
92 function firewall_zone_remove_interface(name, interface)
93 local cursor = uci.cursor()
94 local zone = firewall_find_zone(name)
96 local net = cursor:get("firewall", zone, "network")
97 local new = remove_list_entry(net, interface)
100 cursor:set("firewall", zone, "network", new)
102 cursor:delete("firewall", zone, "network")
104 cursor:save("firewall")
110 -- Finds the firewall zone with given name
111 function firewall_find_zone(name)
114 uci.cursor():foreach("firewall", "zone",
116 if section.name == name then
117 find = section[".name"]
128 -- Removes a listentry, handles real and pseduo lists transparently
129 function remove_list_entry(value, entry)
130 if type(value) == "nil" then
134 local result = type(value) == "table" and value or util.split(value, " ")
135 local key = util.contains(result, entry)
138 table.remove(result, key)
139 key = util.contains(result, entry)
142 result = type(value) == "table" and result or table.concat(result, " ")
143 return result ~= value and result