proto/ipv6: emit a validation error if 6in4 username is still an md5sum
[project/luci.git] / protocols / ipv6 / luasrc / model / cbi / admin_network / proto_6in4.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, peeraddr, ip6addr, tunnelid, username, password
16 local defaultroute, metric, ttl, mtu
17
18
19 ipaddr = s: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 peeraddr = s:taboption("general", Value, "peeraddr",
27         translate("Remote IPv4 address"),
28         translate("This is usually the address of the nearest PoP operated by the tunnel broker"))
29
30 peeraddr.rmempty  = false
31 peeraddr.datatype = "ip4addr"
32
33
34 ip6addr = s:taboption("general", Value, "ip6addr",
35         translate("Local IPv6 address"),
36         translate("This is the local endpoint address assigned by the tunnel broker, it usually ends with <code>:2</code>"))
37
38 ip6addr.datatype = "ip6addr"
39
40
41 local ip6prefix = s:taboption("general", Value, "ip6prefix",
42         translate("IPv6 routed prefix"),
43         translate("This is the prefix routed to you by the tunnel broker for use by clients"))
44
45 ip6prefix.datatype = "ip6addr"
46
47
48 local update = section:taboption("general", Flag, "_update",
49         translate("Dynamic tunnel"),
50         translate("Enable HE.net dynamic endpoint update"))
51
52 update.enabled  = "1"
53 update.disabled = "0"
54
55 function update.write() end
56 function update.remove() end
57 function update.cfgvalue(self, section)
58         return (tonumber(m:get(section, "tunnelid")) ~= nil)
59                 and self.enabled or self.disabled
60 end
61
62
63 tunnelid = section:taboption("general", Value, "tunnelid", translate("Tunnel ID"))
64 tunnelid.datatype = "uinteger"
65 tunnelid:depends("_update", update.enabled)
66
67
68 username = section:taboption("general", Value, "username",
69         translate("HE.net username"),
70         translate("This is the plain username for logging into the account"))
71
72 username:depends("_update", update.enabled)
73 username.validate = function(self, val, sid)
74         if type(val) == "string" and #val == 32 and val:match("^[a-fA-F0-9]+$") then
75                 return nil, translate("The HE.net endpoint update configuration changed, you must now use the plain username instead of the user ID!")
76         end
77         return val
78 end
79
80
81 password = section:taboption("general", Value, "password",
82         translate("HE.net password"),
83         translate("This is either the \"Update Key\" configured for the tunnel or the account password if no update key has been configured"))
84
85 password.password = true
86 password:depends("_update", update.enabled)
87
88
89 defaultroute = section:taboption("advanced", Flag, "defaultroute",
90         translate("Default gateway"),
91         translate("If unchecked, no default route is configured"))
92
93 defaultroute.default = defaultroute.enabled
94
95
96 metric = section:taboption("advanced", Value, "metric",
97         translate("Use gateway metric"))
98
99 metric.placeholder = "0"
100 metric.datatype    = "uinteger"
101 metric:depends("defaultroute", defaultroute.enabled)
102
103
104 ttl = section:taboption("advanced", Value, "ttl", translate("Use TTL on tunnel interface"))
105 ttl.placeholder = "64"
106 ttl.datatype    = "range(1,255)"
107
108
109 mtu = section:taboption("advanced", Value, "mtu", translate("Use MTU on tunnel interface"))
110 mtu.placeholder = "1280"
111 mtu.datatype    = "max(9200)"