Globally reduce copyright headers
[project/luci.git] / applications / luci-app-ocserv / luasrc / model / cbi / ocserv / user-config.lua
1 -- Copyright 2014 Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local fs = require "nixio.fs"
5 local has_ipv6 = fs.access("/proc/net/ipv6_route")
6
7 m = Map("ocserv", translate("OpenConnect VPN"))
8
9 s = m:section(TypedSection, "ocserv", "OpenConnect")
10 s.anonymous = true
11
12 s:tab("general",  translate("General Settings"))
13 s:tab("ca", translate("CA certificate"))
14 s:tab("template", translate("Edit Template"))
15
16 local e = s:taboption("general", Flag, "enable", translate("Enable server"))
17 e.rmempty = false
18 e.default = "1"
19
20 function m.on_commit(map)
21         luci.sys.call("/usr/bin/occtl reload  >/dev/null 2>&1")
22 end
23
24 function e.write(self, section, value)
25         if value == "0" then
26                 luci.sys.call("/etc/init.d/ocserv stop >/dev/null 2>&1")
27                 luci.sys.call("/etc/init.d/ocserv disable  >/dev/null 2>&1")
28         else
29                 luci.sys.call("/etc/init.d/ocserv enable  >/dev/null 2>&1")
30                 luci.sys.call("/etc/init.d/ocserv restart  >/dev/null 2>&1")
31         end
32         Flag.write(self, section, value)
33 end
34
35 local o
36
37 o = s:taboption("general", ListValue, "auth", translate("User Authentication"),
38         translate("The authentication method for the users. The simplest is plain with a single username-password pair. Use PAM modules to authenticate using another server (e.g., LDAP, Radius)."))
39 o.rmempty = false
40 o.default = "plain"
41 o:value("plain")
42 o:value("PAM")
43
44 o = s:taboption("general", Value, "zone", translate("Firewall Zone"),
45         translate("The firewall zone that the VPN clients will be set to"))
46 o.nocreate = true
47 o.default = "lan"
48 o.template = "cbi/firewall_zonelist"
49
50 s:taboption("general", Value, "port", translate("Port"),
51         translate("The same UDP and TCP ports will be used"))
52 s:taboption("general", Value, "max_clients", translate("Max clients"))
53 s:taboption("general", Value, "max_same", translate("Max same clients"))
54 s:taboption("general", Value, "dpd", translate("Dead peer detection time (secs)"))
55
56 local pip = s:taboption("general", Flag, "predictable_ips", translate("Predictable IPs"),
57         translate("The assigned IPs will be selected deterministically"))
58 pip.default = "1"
59
60 local udp = s:taboption("general", Flag, "udp", translate("Enable UDP"),
61         translate("Enable UDP channel support; this must be enabled unless you know what you are doing"))
62 udp.default = "1"
63
64 local cisco = s:taboption("general", Flag, "cisco_compat", translate("AnyConnect client compatibility"),
65         translate("Enable support for CISCO AnyConnect clients"))
66 cisco.default = "1"
67
68 ipaddr = s:taboption("general", Value, "ipaddr", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Network-Address"))
69 ipaddr.default = "192.168.100.1"
70 ipaddr.datatype = "ip4addr"
71
72 nm = s:taboption("general", Value, "netmask", translate("VPN <abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
73 nm.default = "255.255.255.0"
74 nm.datatype = "ip4addr"
75 nm:value("255.255.255.0")
76 nm:value("255.255.0.0")
77 nm:value("255.0.0.0")
78
79 if has_ipv6 then
80         ip6addr = s:taboption("general", Value, "ip6addr", translate("VPN <abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Network-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix"))
81 end
82
83
84 tmpl = s:taboption("template", Value, "_tmpl",
85         translate("Edit the template that is used for generating the ocserv configuration."))
86
87 tmpl.template = "cbi/tvalue"
88 tmpl.rows = 20
89
90 function tmpl.cfgvalue(self, section)
91         return nixio.fs.readfile("/etc/ocserv/ocserv.conf.template")
92 end
93
94 function tmpl.write(self, section, value)
95         value = value:gsub("\r\n?", "\n")
96         nixio.fs.writefile("/etc/ocserv/ocserv.conf.template", value)
97 end
98
99 ca = s:taboption("ca", Value, "_ca",
100         translate("View the CA certificate used by this server. You will need to save it as 'ca.pem' and import it into the clients."))
101
102 ca.template = "cbi/tvalue"
103 ca.rows = 20
104
105 function ca.cfgvalue(self, section)
106         return nixio.fs.readfile("/etc/ocserv/ca.pem")
107 end
108
109 --[[DNS]]--
110
111 s = m:section(TypedSection, "dns", translate("DNS servers"),
112         translate("The DNS servers to be provided to clients; can be either IPv6 or IPv4"))
113 s.anonymous = true
114 s.addremove = true
115 s.template = "cbi/tblsection"
116
117 s:option(Value, "ip", translate("IP Address")).rmempty = true
118 s.datatype = "ipaddr"
119
120 --[[Routes]]--
121
122 s = m:section(TypedSection, "routes", translate("Routing table"),
123         translate("The routing table to be provided to clients; you can mix IPv4 and IPv6 routes, the server will send only the appropriate. Leave empty to set a default route"))
124 s.anonymous = true
125 s.addremove = true
126 s.template = "cbi/tblsection"
127
128 s:option(Value, "ip", translate("IP Address")).rmempty = true
129 s.datatype = "ipaddr"
130
131 o = s:option(Value, "netmask", translate("Netmask (or IPv6-prefix)"))
132 o.default = "255.255.255.0"
133
134 o:value("255.255.255.0")
135 o:value("255.255.0.0")
136 o:value("255.0.0.0")
137
138
139 return m