Merge pull request #1250 from dibdot/luci-app-travelmate
[project/luci.git] / protocols / luci-proto-wireguard / luasrc / model / cbi / admin_network / proto_wireguard.lua
1 -- Copyright 2016-2017 Dan Luedtke <mail@danrl.com>
2 -- Licensed to the public under the Apache License 2.0.
3
4
5 local map, section, net = ...
6 local ifname = net:get_interface():name()
7 local private_key, listen_port
8 local metric, mtu, preshared_key
9 local peers, public_key, allowed_ips, endpoint, persistent_keepalive
10
11
12 -- general ---------------------------------------------------------------------
13
14 private_key = section:taboption(
15   "general",
16   Value,
17   "private_key",
18   translate("Private Key"),
19   translate("Required. Base64-encoded private key for this interface.")
20 )
21 private_key.password = true
22 private_key.datatype = "and(base64,rangelength(44,44))"
23 private_key.optional = false
24
25
26 listen_port = section:taboption(
27   "general",
28   Value,
29   "listen_port",
30   translate("Listen Port"),
31   translate("Optional. UDP port used for outgoing and incoming packets.")
32 )
33 listen_port.datatype = "port"
34 listen_port.placeholder = "51820"
35 listen_port.optional = true
36
37 addresses = section:taboption(
38   "general",
39   DynamicList,
40   "addresses",
41   translate("IP Addresses"),
42   translate("Recommended. IP addresses of the WireGuard interface.")
43 )
44 addresses.datatype = "ipaddr"
45 addresses.optional = true
46
47
48 -- advanced --------------------------------------------------------------------
49
50 metric = section:taboption(
51   "advanced",
52   Value,
53   "metric",
54   translate("Metric"),
55   translate("Optional")
56 )
57 metric.datatype = "uinteger"
58 metric.placeholder = "0"
59 metric.optional = true
60
61
62 mtu = section:taboption(
63   "advanced",
64   Value,
65   "mtu",
66   translate("MTU"),
67   translate("Optional. Maximum Transmission Unit of tunnel interface.")
68 )
69 mtu.datatype = "range(1280,1420)"
70 mtu.placeholder = "1420"
71 mtu.optional = true
72
73 fwmark = section:taboption(
74   "advanced",
75   Value,
76   "fwmark",
77   translate("Firewall Mark"),
78   translate("Optional. 32-bit mark for outgoing encrypted packets. " ..
79             "Enter value in hex, starting with <code>0x</code>.")
80 )
81 fwmark.datatype = "hex(4)"
82 fwmark.optional = true
83
84
85 -- peers -----------------------------------------------------------------------
86
87 peers = map:section(
88   TypedSection,
89   "wireguard_" .. ifname,
90   translate("Peers"),
91   translate("Further information about WireGuard interfaces and peers " ..
92             "at <a href=\"http://wireguard.io\">wireguard.io</a>.")
93 )
94 peers.template = "cbi/tsection"
95 peers.anonymous = true
96 peers.addremove = true
97
98
99 public_key = peers:option(
100   Value,
101   "public_key",
102   translate("Public Key"),
103   translate("Required. Base64-encoded public key of peer.")
104 )
105 public_key.datatype = "and(base64,rangelength(44,44))"
106 public_key.optional = false
107
108
109 preshared_key = peers:option(
110   Value,
111   "preshared_key",
112   translate("Preshared Key"),
113   translate("Optional. Base64-encoded preshared key. " ..
114             "Adds in an additional layer of symmetric-key " ..
115             "cryptography for post-quantum resistance.")
116 )
117 preshared_key.password = true
118 preshared_key.datatype = "and(base64,rangelength(44,44))"
119 preshared_key.optional = true
120
121
122 allowed_ips = peers:option(
123   DynamicList,
124   "allowed_ips",
125   translate("Allowed IPs"),
126   translate("Required. IP addresses and prefixes that this peer is allowed " ..
127             "to use inside the tunnel. Usually the peer's tunnel IP " ..
128             "addresses and the networks the peer routes through the tunnel.")
129 )
130 allowed_ips.datatype = "ipaddr"
131 allowed_ips.optional = false
132
133
134 route_allowed_ips = peers:option(
135   Flag,
136   "route_allowed_ips",
137   translate("Route Allowed IPs"),
138   translate("Optional. Create routes for Allowed IPs for this peer.")
139 )
140
141
142 endpoint_host = peers:option(
143   Value,
144   "endpoint_host",
145   translate("Endpoint Host"),
146   translate("Optional. Host of peer. Names are resolved " ..
147             "prior to bringing up the interface."))
148 endpoint_host.placeholder = "vpn.example.com"
149 endpoint_host.datatype = "host"
150
151
152 endpoint_port = peers:option(
153   Value,
154   "endpoint_port",
155   translate("Endpoint Port"),
156   translate("Optional. Port of peer."))
157 endpoint_port.placeholder = "51820"
158 endpoint_port.datatype = "port"
159
160
161 persistent_keepalive = peers:option(
162   Value,
163   "persistent_keepalive",
164   translate("Persistent Keep Alive"),
165   translate("Optional. Seconds between keep alive messages. " ..
166             "Default is 0 (disabled). Recommended value if " ..
167             "this device is behind a NAT is 25."))
168 persistent_keepalive.datatype = "range(0,65535)"
169 persistent_keepalive.placeholder = "0"