luci-proto-wireguard: WireGuard VPN Protocol (New)
[project/luci.git] / protocols / luci-proto-wireguard / luasrc / model / cbi / admin_network / proto_wireguard.lua
1 -- Copyright 2016 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(minlength(44),maxlength(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
38 -- advanced --------------------------------------------------------------------
39
40 metric = section:taboption(
41   "advanced",
42   Value,
43   "metric",
44   translate("Metric"),
45   translate("Optional.")
46 )
47 metric.datatype = "uinteger"
48 metric.placeholder = "0"
49 metric.optional = true
50
51
52 mtu = section:taboption(
53   "advanced",
54   Value,
55   "mtu",
56   translate("MTU"),
57   translate("Optional. Maximum Transmission Unit of tunnel interface.")
58 )
59 mtu.datatype = "range(1280,1423)"
60 mtu.placeholder = "1423"
61 mtu.optional = true
62
63
64 preshared_key = section:taboption(
65   "advanced",
66   Value,
67   "preshared_key",
68   translate("Preshared Key"),
69   translate("Optional. Adds in an additional layer of symmetric-key " ..
70             "cryptography for post-quantum resistance.")
71 )
72 preshared_key.password = true
73 preshared_key.datatype = "and(minlength(44),maxlength(44))"
74 preshared_key.optional = true
75
76
77 -- peers -----------------------------------------------------------------------
78
79 peers = map:section(
80   TypedSection,
81   "wireguard_" .. ifname,
82   translate("Peers"),
83   translate("Further information about WireGuard interfaces and peers " ..
84             "at <a href=\"http://wireguard.io\">wireguard.io</a>.")
85 )
86 peers.template = "cbi/tsection"
87 peers.anonymous = true
88 peers.addremove = true
89
90
91 public_key = peers:option(
92   Value,
93   "public_key",
94   translate("Public Key"),
95   translate("Required. Public key of peer.")
96 )
97 public_key.datatype = "and(minlength(44),maxlength(44))"
98 public_key.optional = false
99
100
101 allowed_ips = peers:option(
102   DynamicList,
103   "allowed_ips",
104   translate("Allowed IPs"),
105   translate("Required. IP addresses and prefixes that this peer is allowed " ..
106             "to use inside the tunnel. Routes will be added accordingly.")
107 )
108 allowed_ips.datatype = "or(ip6addr, ip4addr)"
109 allowed_ips.optional = false
110
111
112 route_allowed_ips = peers:option(
113   Flag,
114   "route_allowed_ips",
115   translate("Route Allowed IPs"),
116   translate("Optional. Create routes for Allowed IPs for this peer.")
117 )
118
119
120 endpoint_host = peers:option(
121   Value,
122   "endpoint_host",
123   translate("Endpoint Host"),
124   translate("Optional. Host of peer. Names are resolved " ..
125             "prior to bringing up the interface."))
126 endpoint_host.placeholder = "vpn.example.com"
127 endpoint_host.datatype = "host"
128
129
130 endpoint_port = peers:option(
131   Value,
132   "endpoint_port",
133   translate("Endpoint Port"),
134   translate("Optional. Port of peer."))
135 endpoint_port.placeholder = "51820"
136 endpoint_port.datatype = "port"
137
138
139 persistent_keepalive = peers:option(
140   Value,
141   "persistent_keepalive",
142   translate("Persistent Keep Alive"),
143   translate("Optional. Seconds between keep alive messages. " ..
144             "Default is 0 (disabled). Recommended value if " ..
145             "this device is behind a NAT is 25."))
146 persistent_keepalive.datatype = "range(0, 65535)"
147 persistent_keepalive.placeholder = "0"