2008-06-08 08:14:31 +00:00
|
|
|
--[[
|
|
|
|
LuCI - Lua Configuration Interface
|
|
|
|
|
|
|
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
2009-09-29 23:10:04 +00:00
|
|
|
Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
|
2008-06-08 08:14:31 +00:00
|
|
|
|
|
|
|
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$
|
|
|
|
]]--
|
2008-10-23 18:19:27 +00:00
|
|
|
|
2009-07-19 00:24:58 +00:00
|
|
|
local fs = require "nixio.fs"
|
2009-10-08 00:36:22 +00:00
|
|
|
local fw = require "luci.model.firewall"
|
2009-07-19 00:24:58 +00:00
|
|
|
|
2008-08-13 01:24:44 +00:00
|
|
|
arg[1] = arg[1] or ""
|
2008-10-23 18:19:27 +00:00
|
|
|
|
2009-07-19 00:24:58 +00:00
|
|
|
local has_3g = fs.access("/usr/bin/gcom")
|
|
|
|
local has_pptp = fs.access("/usr/sbin/pptp")
|
|
|
|
local has_pppd = fs.access("/usr/sbin/pppd")
|
|
|
|
local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")()
|
|
|
|
local has_pppoa = fs.glob("/usr/lib/pppd/*/pppoatm.so")()
|
2009-09-29 23:10:04 +00:00
|
|
|
local has_ipv6 = fs.access("/proc/net/ipv6_route")
|
2008-10-23 18:19:27 +00:00
|
|
|
|
2008-08-13 01:24:44 +00:00
|
|
|
m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
|
2009-10-08 00:36:22 +00:00
|
|
|
m:chain("firewall")
|
|
|
|
|
|
|
|
fw.init(m.uci)
|
2008-08-07 19:03:25 +00:00
|
|
|
|
2008-08-13 01:30:32 +00:00
|
|
|
s = m:section(NamedSection, arg[1], "interface")
|
2008-08-13 01:24:44 +00:00
|
|
|
s.addremove = true
|
2008-04-11 19:03:30 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
s:tab("general", translate("a_n_general", "General Setup"))
|
|
|
|
if has_ipv6 then s:tab("ipv6", translate("a_n_ipv6", "IPv6 Setup")) end
|
|
|
|
s:tab("physical", translate("a_n_physical", "Physical Settings"))
|
|
|
|
|
|
|
|
--[[
|
|
|
|
back = s:taboption("general", DummyValue, "_overview", translate("overview"))
|
2008-10-03 16:55:06 +00:00
|
|
|
back.value = ""
|
|
|
|
back.titleref = luci.dispatcher.build_url("admin", "network", "network")
|
2009-09-29 23:10:04 +00:00
|
|
|
]]
|
2008-10-03 16:55:06 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
p = s:taboption("general", ListValue, "proto", translate("protocol"))
|
2008-10-23 18:19:27 +00:00
|
|
|
p.override_scheme = true
|
|
|
|
p.default = "static"
|
2008-06-09 10:10:29 +00:00
|
|
|
p:value("static", translate("static"))
|
2008-04-11 19:03:30 +00:00
|
|
|
p:value("dhcp", "DHCP")
|
2008-10-23 18:19:27 +00:00
|
|
|
if has_pppd then p:value("ppp", "PPP") end
|
|
|
|
if has_pppoe then p:value("pppoe", "PPPoE") end
|
|
|
|
if has_pppoa then p:value("pppoa", "PPPoA") end
|
|
|
|
if has_3g then p:value("3g", "UMTS/3G") end
|
|
|
|
if has_pptp then p:value("pptp", "PPTP") end
|
2008-12-23 16:48:48 +00:00
|
|
|
p:value("none", translate("none"))
|
2008-10-23 18:19:27 +00:00
|
|
|
|
|
|
|
if not ( has_pppd and has_pppoe and has_pppoa and has_3g and has_pptp ) then
|
|
|
|
p.description = translate("network_interface_prereq")
|
|
|
|
end
|
2008-04-11 19:03:30 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
br = s:taboption("physical", Flag, "type", translate("a_n_i_bridge"), translate("a_n_i_bridge1"))
|
2008-04-11 19:03:30 +00:00
|
|
|
br.enabled = "bridge"
|
|
|
|
br.rmempty = true
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
stp = s:taboption("physical", Flag, "stp", translate("a_n_i_stp"),
|
2009-05-29 22:32:42 +00:00
|
|
|
translate("a_n_i_stp1", "Enables the Spanning Tree Protocol on this bridge"))
|
2009-05-29 23:03:15 +00:00
|
|
|
stp:depends("type", "1")
|
2009-05-29 22:32:42 +00:00
|
|
|
stp.rmempty = true
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
ifname_single = s:taboption("physical", Value, "ifname_single", translate("interface"))
|
|
|
|
ifname_single.rmempty = true
|
|
|
|
ifname_single:depends("type", "")
|
|
|
|
|
|
|
|
function ifname_single.cfgvalue(self, s)
|
|
|
|
return self.map.uci:get("network", s, "ifname")
|
|
|
|
end
|
|
|
|
|
|
|
|
function ifname_single.write(self, s, val)
|
|
|
|
self.map.uci:set("network", s, "ifname", val)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
ifname_multi = s:taboption("physical", MultiValue, "ifname_multi", translate("interface"))
|
|
|
|
ifname_multi.widget = "checkbox"
|
|
|
|
ifname_multi:depends("type", "1")
|
|
|
|
ifname_multi.cfgvalue = ifname_single.cfgvalue
|
|
|
|
ifname_multi.write = ifname_single.write
|
|
|
|
|
2008-08-06 10:41:47 +00:00
|
|
|
for i,d in ipairs(luci.sys.net.devices()) do
|
|
|
|
if d ~= "lo" then
|
2009-09-29 23:10:04 +00:00
|
|
|
ifname_single:value(d)
|
|
|
|
ifname_multi:value(d)
|
2008-08-06 10:41:47 +00:00
|
|
|
end
|
|
|
|
end
|
2008-04-11 19:03:30 +00:00
|
|
|
|
2009-10-08 00:36:22 +00:00
|
|
|
|
|
|
|
fwzone = s:taboption("general", Value, "_fwzone",
|
|
|
|
translate("network_interface_fwzone"),
|
|
|
|
translate("network_interface_fwzone_desc"))
|
|
|
|
|
|
|
|
fwzone.template = "cbi/firewall_zonelist"
|
|
|
|
fwzone.rmempty = false
|
|
|
|
|
|
|
|
function fwzone.cfgvalue(self, section)
|
|
|
|
self.iface = section
|
|
|
|
local z = fw.get_zones_by_network(section)[1]
|
|
|
|
return z and z:name()
|
|
|
|
end
|
|
|
|
|
|
|
|
function fwzone.write(self, section, value)
|
|
|
|
local zone = fw.get_zone(value)
|
|
|
|
|
|
|
|
if not zone then
|
|
|
|
value = m:formvalue(self:cbid(section) .. ".newzone")
|
|
|
|
if value and #value > 0 and value:match("^[a-zA-Z0-9_]+$") then
|
|
|
|
zone = fw.add_zone(value)
|
2008-08-13 22:54:38 +00:00
|
|
|
end
|
|
|
|
end
|
2009-10-08 00:36:22 +00:00
|
|
|
|
|
|
|
if zone then
|
2009-10-08 00:48:02 +00:00
|
|
|
fw.del_network(section)
|
2009-10-08 00:36:22 +00:00
|
|
|
zone:add_network(section)
|
|
|
|
end
|
2008-08-13 22:54:38 +00:00
|
|
|
end
|
2008-08-07 20:21:38 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
ipaddr = s:taboption("general", Value, "ipaddr", translate("ipaddress"))
|
2008-08-07 17:23:36 +00:00
|
|
|
ipaddr.rmempty = true
|
|
|
|
ipaddr:depends("proto", "static")
|
2008-04-11 19:03:30 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
nm = s:taboption("general", Value, "netmask", translate("netmask"))
|
2008-08-07 17:23:36 +00:00
|
|
|
nm.rmempty = true
|
2008-08-06 10:41:47 +00:00
|
|
|
nm:depends("proto", "static")
|
|
|
|
nm:value("255.255.255.0")
|
|
|
|
nm:value("255.255.0.0")
|
|
|
|
nm:value("255.0.0.0")
|
2008-04-11 19:03:30 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
gw = s:taboption("general", Value, "gateway", translate("gateway"))
|
2008-04-11 19:03:30 +00:00
|
|
|
gw:depends("proto", "static")
|
|
|
|
gw.rmempty = true
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
bcast = s:taboption("general", Value, "bcast", translate("broadcast"))
|
2008-08-07 20:21:38 +00:00
|
|
|
bcast:depends("proto", "static")
|
|
|
|
|
2009-10-02 01:34:54 +00:00
|
|
|
if has_ipv6 then
|
|
|
|
ip6addr = s:taboption("ipv6", Value, "ip6addr", translate("ip6address"), translate("cidr6"))
|
|
|
|
ip6addr:depends("proto", "static")
|
2008-08-07 17:23:36 +00:00
|
|
|
|
2009-10-02 01:34:54 +00:00
|
|
|
ip6gw = s:taboption("ipv6", Value, "ip6gw", translate("gateway6"))
|
|
|
|
ip6gw:depends("proto", "static")
|
|
|
|
end
|
2008-08-07 17:23:36 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
dns = s:taboption("general", Value, "dns", translate("dnsserver"))
|
|
|
|
dns:depends("peerdns", "")
|
2008-04-11 19:03:30 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
mtu = s:taboption("physical", Value, "mtu", "MTU")
|
2008-04-11 19:03:30 +00:00
|
|
|
mtu.isinteger = true
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
mac = s:taboption("physical", Value, "macaddr", translate("macaddress"))
|
2008-04-11 19:03:30 +00:00
|
|
|
|
2008-08-14 11:50:44 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
srv = s:taboption("general", Value, "server", translate("network_interface_server"))
|
2008-08-14 11:50:44 +00:00
|
|
|
srv:depends("proto", "pptp")
|
|
|
|
srv.rmempty = true
|
|
|
|
|
2008-11-29 22:06:29 +00:00
|
|
|
if has_3g then
|
2009-09-29 23:10:04 +00:00
|
|
|
service = s:taboption("general", ListValue, "service", translate("network_interface_service"))
|
2008-11-29 22:06:29 +00:00
|
|
|
service:value("", translate("cbi_select"))
|
|
|
|
service:value("umts", "UMTS/GPRS")
|
|
|
|
service:value("cdma", "CDMA")
|
|
|
|
service:value("evdo", "EV-DO")
|
|
|
|
service:depends("proto", "3g")
|
|
|
|
service.rmempty = true
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
apn = s:taboption("general", Value, "apn", translate("network_interface_apn"))
|
2008-11-29 22:06:29 +00:00
|
|
|
apn:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
pincode = s:taboption("general", Value, "pincode",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_pincode"),
|
|
|
|
translate("network_interface_pincode_desc")
|
|
|
|
)
|
|
|
|
pincode:depends("proto", "3g")
|
|
|
|
end
|
|
|
|
|
2009-01-25 12:15:39 +00:00
|
|
|
if has_pppd or has_pppoe or has_pppoa or has_3g or has_pptp then
|
2009-09-29 23:10:04 +00:00
|
|
|
user = s:taboption("general", Value, "username", translate("username"))
|
2008-11-29 22:06:29 +00:00
|
|
|
user.rmempty = true
|
|
|
|
user:depends("proto", "pptp")
|
|
|
|
user:depends("proto", "pppoe")
|
2009-01-25 12:15:39 +00:00
|
|
|
user:depends("proto", "pppoa")
|
2008-11-29 22:06:29 +00:00
|
|
|
user:depends("proto", "ppp")
|
|
|
|
user:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
pass = s:taboption("general", Value, "password", translate("password"))
|
2008-11-29 22:06:29 +00:00
|
|
|
pass.rmempty = true
|
|
|
|
pass.password = true
|
|
|
|
pass:depends("proto", "pptp")
|
|
|
|
pass:depends("proto", "pppoe")
|
2009-01-25 12:15:39 +00:00
|
|
|
pass:depends("proto", "pppoa")
|
2008-11-29 22:06:29 +00:00
|
|
|
pass:depends("proto", "ppp")
|
|
|
|
pass:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
ka = s:taboption("general", Value, "keepalive",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_keepalive"),
|
|
|
|
translate("network_interface_keepalive_desc")
|
|
|
|
)
|
|
|
|
ka:depends("proto", "pptp")
|
|
|
|
ka:depends("proto", "pppoe")
|
2009-01-25 12:15:39 +00:00
|
|
|
ka:depends("proto", "pppoa")
|
2008-11-29 22:06:29 +00:00
|
|
|
ka:depends("proto", "ppp")
|
|
|
|
ka:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
demand = s:taboption("general", Value, "demand",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_demand"),
|
|
|
|
translate("network_interface_demand_desc")
|
|
|
|
)
|
|
|
|
demand:depends("proto", "pptp")
|
|
|
|
demand:depends("proto", "pppoe")
|
2009-01-25 12:15:39 +00:00
|
|
|
demand:depends("proto", "pppoa")
|
2008-11-29 22:06:29 +00:00
|
|
|
demand:depends("proto", "ppp")
|
|
|
|
demand:depends("proto", "3g")
|
|
|
|
end
|
2008-08-07 20:21:38 +00:00
|
|
|
|
2009-01-25 12:15:39 +00:00
|
|
|
if has_pppoa then
|
2009-09-29 23:10:04 +00:00
|
|
|
encaps = s:taboption("general", ListValue, "encaps", translate("network_interface_encaps"))
|
2009-01-25 12:15:39 +00:00
|
|
|
encaps:depends("proto", "pppoa")
|
|
|
|
encaps:value("", translate("cbi_select"))
|
|
|
|
encaps:value("vc", "VC")
|
|
|
|
encaps:value("llc", "LLC")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
vpi = s:taboption("general", Value, "vpi", "VPI")
|
2009-01-25 12:15:39 +00:00
|
|
|
vpi:depends("proto", "pppoa")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
vci = s:taboption("general", Value, "vci", "VCI")
|
2009-01-25 12:15:39 +00:00
|
|
|
vci:depends("proto", "pppoa")
|
|
|
|
end
|
|
|
|
|
|
|
|
if has_pptp or has_pppd or has_pppoe or has_pppoa or has_3g then
|
2009-09-29 23:10:04 +00:00
|
|
|
device = s:taboption("general", Value, "device",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_device"),
|
|
|
|
translate("network_interface_device_desc")
|
|
|
|
)
|
|
|
|
device:depends("proto", "ppp")
|
|
|
|
device:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
defaultroute = s:taboption("general", Flag, "defaultroute",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_defaultroute"),
|
|
|
|
translate("network_interface_defaultroute_desc")
|
|
|
|
)
|
|
|
|
defaultroute:depends("proto", "ppp")
|
2009-01-25 12:15:39 +00:00
|
|
|
defaultroute:depends("proto", "pppoa")
|
|
|
|
defaultroute:depends("proto", "pppoe")
|
|
|
|
defaultroute:depends("proto", "pptp")
|
2008-11-29 22:06:29 +00:00
|
|
|
defaultroute:depends("proto", "3g")
|
2009-01-07 20:48:05 +00:00
|
|
|
defaultroute.rmempty = false
|
|
|
|
function defaultroute.cfgvalue(...)
|
|
|
|
return ( AbstractValue.cfgvalue(...) or '1' )
|
|
|
|
end
|
2008-11-29 22:06:29 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
peerdns = s:taboption("general", Flag, "peerdns",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_peerdns"),
|
|
|
|
translate("network_interface_peerdns_desc")
|
|
|
|
)
|
|
|
|
peerdns:depends("proto", "ppp")
|
2009-01-25 12:15:39 +00:00
|
|
|
peerdns:depends("proto", "pppoa")
|
|
|
|
peerdns:depends("proto", "pppoe")
|
|
|
|
peerdns:depends("proto", "pptp")
|
|
|
|
peerdns:depends("proto", "3g")
|
2009-01-07 20:48:05 +00:00
|
|
|
peerdns.rmempty = false
|
|
|
|
function peerdns.cfgvalue(...)
|
|
|
|
return ( AbstractValue.cfgvalue(...) or '1' )
|
|
|
|
end
|
2008-11-29 22:06:29 +00:00
|
|
|
|
2009-10-02 01:34:54 +00:00
|
|
|
if has_ipv6 then
|
|
|
|
ipv6 = s:taboption("general", Flag, "ipv6", translate("network_interface_ipv6") )
|
|
|
|
ipv6:depends("proto", "ppp")
|
|
|
|
ipv6:depends("proto", "pppoa")
|
|
|
|
ipv6:depends("proto", "pppoe")
|
|
|
|
ipv6:depends("proto", "pptp")
|
|
|
|
ipv6:depends("proto", "3g")
|
|
|
|
end
|
2008-11-29 22:06:29 +00:00
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
connect = s:taboption("general", Value, "connect",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_connect"),
|
|
|
|
translate("network_interface_connect_desc")
|
|
|
|
)
|
|
|
|
connect:depends("proto", "ppp")
|
2009-01-25 12:15:39 +00:00
|
|
|
connect:depends("proto", "pppoe")
|
|
|
|
connect:depends("proto", "pppoa")
|
|
|
|
connect:depends("proto", "pptp")
|
2008-11-29 22:06:29 +00:00
|
|
|
connect:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
disconnect = s:taboption("general", Value, "disconnect",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_disconnect"),
|
|
|
|
translate("network_interface_disconnect_desc")
|
|
|
|
)
|
|
|
|
disconnect:depends("proto", "ppp")
|
2009-01-25 12:15:39 +00:00
|
|
|
disconnect:depends("proto", "pppoe")
|
|
|
|
disconnect:depends("proto", "pppoa")
|
|
|
|
disconnect:depends("proto", "pptp")
|
2008-11-29 22:06:29 +00:00
|
|
|
disconnect:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
pppd_options = s:taboption("general", Value, "pppd_options",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_pppd_options"),
|
|
|
|
translate("network_interface_pppd_options_desc")
|
|
|
|
)
|
|
|
|
pppd_options:depends("proto", "ppp")
|
2009-01-25 12:15:39 +00:00
|
|
|
pppd_options:depends("proto", "pppoa")
|
|
|
|
pppd_options:depends("proto", "pppoe")
|
|
|
|
pppd_options:depends("proto", "pptp")
|
2008-11-29 22:06:29 +00:00
|
|
|
pppd_options:depends("proto", "3g")
|
|
|
|
|
2009-09-29 23:10:04 +00:00
|
|
|
maxwait = s:taboption("general", Value, "maxwait",
|
2008-11-29 22:06:29 +00:00
|
|
|
translate("network_interface_maxwait"),
|
|
|
|
translate("network_interface_maxwait_desc")
|
|
|
|
)
|
|
|
|
maxwait:depends("proto", "3g")
|
|
|
|
end
|
2008-08-07 20:21:38 +00:00
|
|
|
|
|
|
|
s2 = m:section(TypedSection, "alias", translate("aliases"))
|
|
|
|
s2.addremove = true
|
|
|
|
|
2008-08-13 01:24:44 +00:00
|
|
|
s2:depends("interface", arg[1])
|
|
|
|
s2.defaults.interface = arg[1]
|
2008-08-07 20:21:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
s2.defaults.proto = "static"
|
|
|
|
|
|
|
|
ipaddr = s2:option(Value, "ipaddr", translate("ipaddress"))
|
|
|
|
ipaddr.rmempty = true
|
|
|
|
|
|
|
|
nm = s2:option(Value, "netmask", translate("netmask"))
|
|
|
|
nm.rmempty = true
|
|
|
|
nm:value("255.255.255.0")
|
|
|
|
nm:value("255.255.0.0")
|
|
|
|
nm:value("255.0.0.0")
|
|
|
|
|
|
|
|
gw = s2:option(Value, "gateway", translate("gateway"))
|
|
|
|
gw.rmempty = true
|
|
|
|
|
|
|
|
bcast = s2:option(Value, "bcast", translate("broadcast"))
|
|
|
|
bcast.optional = true
|
|
|
|
|
|
|
|
ip6addr = s2:option(Value, "ip6addr", translate("ip6address"), translate("cidr6"))
|
|
|
|
ip6addr.optional = true
|
|
|
|
|
|
|
|
ip6gw = s2:option(Value, "ip6gw", translate("gateway6"))
|
|
|
|
ip6gw.optional = true
|
|
|
|
|
|
|
|
dns = s2:option(Value, "dns", translate("dnsserver"))
|
|
|
|
dns.optional = true
|
|
|
|
|
|
|
|
return m
|