Merge pull request #817 from ascob/luci-app-dynapoint
[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 = "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
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 = "rangelength(44, 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 = "rangelength(44, 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. Usually the peer's tunnel IP " ..
107 "addresses and the networks the peer routes through the tunnel.")
108 )
109 allowed_ips.datatype = "ipaddr"
110 allowed_ips.optional = false
111
112
113 route_allowed_ips = peers:option(
114 Flag,
115 "route_allowed_ips",
116 translate("Route Allowed IPs"),
117 translate("Optional. Create routes for Allowed IPs for this peer.")
118 )
119
120
121 endpoint_host = peers:option(
122 Value,
123 "endpoint_host",
124 translate("Endpoint Host"),
125 translate("Optional. Host of peer. Names are resolved " ..
126 "prior to bringing up the interface."))
127 endpoint_host.placeholder = "vpn.example.com"
128 endpoint_host.datatype = "host"
129
130
131 endpoint_port = peers:option(
132 Value,
133 "endpoint_port",
134 translate("Endpoint Port"),
135 translate("Optional. Port of peer."))
136 endpoint_port.placeholder = "51820"
137 endpoint_port.datatype = "port"
138
139
140 persistent_keepalive = peers:option(
141 Value,
142 "persistent_keepalive",
143 translate("Persistent Keep Alive"),
144 translate("Optional. Seconds between keep alive messages. " ..
145 "Default is 0 (disabled). Recommended value if " ..
146 "this device is behind a NAT is 25."))
147 persistent_keepalive.datatype = "range(0, 65535)"
148 persistent_keepalive.placeholder = "0"