From b47afa09346e39d0ff66a03b3f66ad2888b4d5d8 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 10 Oct 2009 21:13:39 +0000 Subject: modules/admin-full: rename iface_add_s1.lua --- .../luasrc/model/cbi/admin_network/iface_add.lua | 106 +++++++++++++++++++++ .../model/cbi/admin_network/iface_add_s1.lua | 106 --------------------- 2 files changed, 106 insertions(+), 106 deletions(-) create mode 100644 modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua delete mode 100644 modules/admin-full/luasrc/model/cbi/admin_network/iface_add_s1.lua (limited to 'modules') diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua b/modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua new file mode 100644 index 0000000000..759a7c9bfb --- /dev/null +++ b/modules/admin-full/luasrc/model/cbi/admin_network/iface_add.lua @@ -0,0 +1,106 @@ +--[[ +LuCI - Lua Configuration Interface + +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$ +]]-- + +local nw = require "luci.model.network" +local fw = require "luci.model.firewall" +local uci = require "luci.model.uci".cursor() + +m = SimpleForm("network", translate("a_n_create", "Create Or Attach Network"), + translate("a_n_c_desc", + "If the interface is attached to an existing network it will be bridged " .. + "to the existing interfaces and is covered by the firewall zone of the choosen network.
" .. + "Uncheck the attach option to define a new standalone network for this interface." + )) + +nw.init(uci) +fw.init(uci) + +attachnet = m:field(Flag, "_attach", translate("a_n_c_attach", "Attach to existing network")) +attachnet.rmempty = false +attachnet.default = "1" + +newnet = m:field(Value, "_netname_new", translate("a_n_c_netname", "Name of the new network"), + translate("a_n_c_netname_desc", + "The allowed characters are: A-Z, a-z, " .. + "0-9 and _" + )) + +newnet:depends("_attach", "") +newnet.default = "net_" .. arg[1]:gsub("[^%w_]+", "_") + +addnet = m:field(Value, "_netname_attach", + translate("a_n_c_network", "Network to attach interface to")) + +addnet.template = "cbi/network_netlist" +addnet.widget = "radio" +addnet.nocreate = true +addnet:depends("_attach", "1") + +fwzone = m:field(Value, "_fwzone", + translate("network_interface_fwzone"), + translate("network_interface_fwzone_desc")) + +fwzone.template = "cbi/firewall_zonelist" +addnet.widget = "radio" +fwzone:depends("_attach", "") +fwzone.default = "zone_" .. arg[1]:gsub("[^%w_]+", "_") + + +function attachnet.write(self, section, value) + local net, zone + + if value == "1" then + net = nw:get_network(addnet:formvalue(section)) + if net then + net:type("bridge") + end + else + local zval = fwzone:formvalue(section) + + net = nw:add_network(newnet:formvalue(section), { proto = "none" }) + zone = fw:get_zone(zval) + + if not zone and zval == '-' then + zval = m:formvalue(fwzone:cbid(section) .. ".newzone") + if zval and #zval > 0 then + zone = fw:add_zone(zval) + else + fw:del_network(arg[1]) + end + end + end + + if not net then + self.error = { [section] = "missing" } + else + net:add_interface(arg[1]) + + if zone then + fw:del_network(net:name()) + zone:add_network(net:name()) + end + + uci:save("network") + uci:save("firewall") + luci.http.redirect(luci.dispatcher.build_url("admin/network/network", net:name())) + end +end + +function fwzone.cfgvalue(self, section) + self.iface = section + local z = fw:get_zone_by_network(section) + return z and z:name() +end + +return m diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/iface_add_s1.lua b/modules/admin-full/luasrc/model/cbi/admin_network/iface_add_s1.lua deleted file mode 100644 index 759a7c9bfb..0000000000 --- a/modules/admin-full/luasrc/model/cbi/admin_network/iface_add_s1.lua +++ /dev/null @@ -1,106 +0,0 @@ ---[[ -LuCI - Lua Configuration Interface - -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$ -]]-- - -local nw = require "luci.model.network" -local fw = require "luci.model.firewall" -local uci = require "luci.model.uci".cursor() - -m = SimpleForm("network", translate("a_n_create", "Create Or Attach Network"), - translate("a_n_c_desc", - "If the interface is attached to an existing network it will be bridged " .. - "to the existing interfaces and is covered by the firewall zone of the choosen network.
" .. - "Uncheck the attach option to define a new standalone network for this interface." - )) - -nw.init(uci) -fw.init(uci) - -attachnet = m:field(Flag, "_attach", translate("a_n_c_attach", "Attach to existing network")) -attachnet.rmempty = false -attachnet.default = "1" - -newnet = m:field(Value, "_netname_new", translate("a_n_c_netname", "Name of the new network"), - translate("a_n_c_netname_desc", - "The allowed characters are: A-Z, a-z, " .. - "0-9 and _" - )) - -newnet:depends("_attach", "") -newnet.default = "net_" .. arg[1]:gsub("[^%w_]+", "_") - -addnet = m:field(Value, "_netname_attach", - translate("a_n_c_network", "Network to attach interface to")) - -addnet.template = "cbi/network_netlist" -addnet.widget = "radio" -addnet.nocreate = true -addnet:depends("_attach", "1") - -fwzone = m:field(Value, "_fwzone", - translate("network_interface_fwzone"), - translate("network_interface_fwzone_desc")) - -fwzone.template = "cbi/firewall_zonelist" -addnet.widget = "radio" -fwzone:depends("_attach", "") -fwzone.default = "zone_" .. arg[1]:gsub("[^%w_]+", "_") - - -function attachnet.write(self, section, value) - local net, zone - - if value == "1" then - net = nw:get_network(addnet:formvalue(section)) - if net then - net:type("bridge") - end - else - local zval = fwzone:formvalue(section) - - net = nw:add_network(newnet:formvalue(section), { proto = "none" }) - zone = fw:get_zone(zval) - - if not zone and zval == '-' then - zval = m:formvalue(fwzone:cbid(section) .. ".newzone") - if zval and #zval > 0 then - zone = fw:add_zone(zval) - else - fw:del_network(arg[1]) - end - end - end - - if not net then - self.error = { [section] = "missing" } - else - net:add_interface(arg[1]) - - if zone then - fw:del_network(net:name()) - zone:add_network(net:name()) - end - - uci:save("network") - uci:save("firewall") - luci.http.redirect(luci.dispatcher.build_url("admin/network/network", net:name())) - end -end - -function fwzone.cfgvalue(self, section) - self.iface = section - local z = fw:get_zone_by_network(section) - return z and z:name() -end - -return m -- cgit v1.2.3