proto/6x4: cast 6to4 adv_interface to string when saving to uci, fixes 6in4.sh not...
[project/luci.git] / protocols / 6x4 / luasrc / model / cbi / admin_network / proto_6to4.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11 ]]--
12
13 local map, section, net = ...
14
15 local ipaddr, adv_interface, adv_subnet
16 local adv_valid_lifetime, adv_preferred_lifetime, defaultroute, metric, ttl, mtu
17
18
19 ipaddr = section:taboption("general", Value, "ipaddr",
20         translate("Local IPv4 address"),
21         translate("Leave empty to use the current WAN address"))
22
23 ipaddr.datatype = "ip4addr"
24
25
26 adv_interface = section:taboption("general", Value, "adv_interface", translate("Advertise IPv6 on network"))
27 adv_interface.widget = "checkbox"
28 adv_interface.exclude = arg[1]
29 adv_interface.default = "lan"
30 adv_interface.template = "cbi/network_netlist"
31 adv_interface.nocreate = true
32 adv_interface.nobridges = true
33 adv_interface.novirtual = true
34
35 function adv_interface.write(self, section, value)
36         if type(value) == "table" then
37                 Value.write(self, section, table.concat(value, " "))
38         else
39                 Value.write(self, section, value)
40         end
41 end
42
43 function adv_interface.remove(self, section)
44         self:write(section, " ")
45 end
46
47 adv_subnet  = section:taboption("general", Value, "adv_subnet",
48         translate("Advertised network ID"),
49         translate("Allowed range is 1 to 65535"))
50
51 adv_subnet.placeholder = "1"
52 adv_subnet.datatype    = "range(1,65535)"
53
54 function adv_subnet.cfgvalue(self, section)
55         local v = Value.cfgvalue(self, section)
56         return v and tonumber(v, 16)
57 end
58
59 function adv_subnet .write(self, section, value)
60         value = tonumber(value) or 1
61
62         if value > 65535 then value = 65535
63         elseif value < 1 then value = 1 end
64
65         Value.write(self, section, "%X" % value)
66 end
67
68
69 adv_valid_lifetime = section:taboption("advanced", Value, "adv_valid_lifetime",
70         translate("Use valid lifetime"),
71         translate("Specifies the advertised valid prefix lifetime in seconds"))
72
73 adv_valid_lifetime.placeholder = "300"
74 adv_valid_lifetime.datatype    = "uinteger"
75
76
77 adv_preferred_lifetime = section:taboption("advanced", Value, "adv_preferred_lifetime",
78         translate("Use preferred lifetime"),
79         translate("Specifies the advertised preferred prefix lifetime in seconds"))
80
81 adv_preferred_lifetime.placeholder = "120"
82 adv_preferred_lifetime.datatype    = "uinteger"
83
84
85
86 defaultroute = section:taboption("advanced", Flag, "defaultroute",
87         translate("Use default gateway"),
88         translate("If unchecked, no default route is configured"))
89
90 defaultroute.default = defaultroute.enabled
91
92
93 metric = section:taboption("advanced", Value, "metric",
94         translate("Use gateway metric"))
95
96 metric.placeholder = "0"
97 metric.datatype    = "uinteger"
98 metric:depends("defaultroute", defaultroute.enabled)
99
100
101 ttl = section:taboption("advanced", Value, "ttl", translate("Use TTL on tunnel interface"))
102 ttl.placeholder = "64"
103 ttl.datatype    = "range(1,255)"
104
105
106 mtu = section:taboption("advanced", Value, "mtu", translate("Use MTU on tunnel interface"))
107 mtu.placeholder = "1280"
108 mtu.datatype    = "max(1500)"