Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / applications / luci-app-openvpn / luasrc / model / cbi / openvpn-advanced.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local fs = require("nixio.fs")
5
6 local knownParams = {
7         --
8         --Widget
9         --      Name
10         --      Default(s)
11         --      Description
12         --      Option(s)
13
14         { "Service", {
15         -- initialisation and daemon options
16                 { ListValue,
17                         "verb",
18                         { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 },
19                         translate("Set output verbosity") },
20                 { Flag,
21                         "mlock",
22                         0,
23                         translate("Disable Paging") },
24                 { Flag,
25                         "disable_occ",
26                         0,
27                         translate("Disable options consistency check") },
28         --      { Value,
29         --              "user",
30         --              "root",
31         --              translate("Set UID to user") },
32         --      { Value,
33         --              "group",
34         --              "root",
35         --              translate("Set GID to group") },
36                 { Value,
37                         "cd",
38                         "/etc/openvpn",
39                         translate("Change to directory before initialization") },
40                 { Value,
41                         "chroot",
42                         "/var/run",
43                         translate("Chroot to directory after initialization") },
44         --      { Value,
45         --              "daemon",
46         --              "Instance-Name",
47         --              translate("Daemonize after initialization") },
48         --      { Value,
49         --              "syslog",
50         --              "Instance-Name",
51         --              translate("Output to syslog and do not daemonize") },
52                 { Flag,
53                         "passtos",
54                         0,
55                         translate("TOS passthrough (applies to IPv4 only)") },
56         --      { Value,
57         --              "inetd",
58         --              "nowait Instance-Name",
59         --              translate("Run as an inetd or xinetd server") },
60                 { Value,
61                         "log",
62                         "/var/log/openvpn.log",
63                         translate("Write log to file") },
64                 { Value,
65                         "log_append",
66                         "/var/log/openvpn.log",
67                         translate("Append log to file") },
68                 { Flag,
69                         "suppress_timestamps",
70                         0,
71                         translate("Don't log timestamps") },
72         --      { Value,
73         --              "writepid",
74         --              "/var/run/openvpn.pid",
75         --              translate("Write process ID to file") },
76                 { Value,
77                         "nice",
78                         0,
79                         translate("Change process priority") },
80                 { Flag,
81                         "fast_io",
82                         0,
83                         translate("Optimize TUN/TAP/UDP writes") },
84                 { Value,
85                         "echo",
86                         "some params echoed to log",
87                         translate("Echo parameters to log") },
88                 { ListValue,
89                         "remap_usr1",
90                         { "SIGHUP", "SIGTERM" },
91                         translate("Remap SIGUSR1 signals") },
92                 { Value,
93                         "status",
94                         "/var/run/openvpn.status 5",
95                         translate("Write status to file every n seconds") },
96                 { Value,
97                         "status_version",
98                         { 1, 2 },
99                         translate("Status file format version") },      -- status
100                 { Value,
101                         "mute",
102                         5,
103                         translate("Limit repeated log messages") },
104                 { Value,
105                         "up",
106                         "/usr/bin/ovpn-up",
107                         translate("Shell cmd to execute after tun device open") },
108                 { Value,
109                         "up_delay",
110                         5,
111                         translate("Delay tun/tap open and up script execution") },
112                 { Value,
113                         "down",
114                         "/usr/bin/ovpn-down",
115                         translate("Shell cmd to run after tun device close") },
116                 { Flag,
117                         "down_pre",
118                         0,
119                         translate("Call down cmd/script before TUN/TAP close") },
120                 { Flag,
121                         "up_restart",
122                         0,
123                         translate("Run up/down scripts for all restarts") },
124                 { Value,
125                         "route_up",
126                         "/usr/bin/ovpn-routeup",
127                         translate("Execute shell cmd after routes are added") },
128                 { Value,
129                         "ipchange",
130                         "/usr/bin/ovpn-ipchange",
131                         translate("Execute shell command on remote ip change"),
132                         { mode="p2p" } },
133                 { DynamicList,
134                         "setenv",
135                         { "VAR1 value1", "VAR2 value2" },
136                         translate("Pass environment variables to script") },
137                 { Value,
138                         "tls_verify",
139                         "/usr/bin/ovpn-tlsverify",
140                         translate("Shell command to verify X509 name") },
141                 { Value,
142                         "client_connect",
143                         "/usr/bin/ovpn-clientconnect",
144                         translate("Run script cmd on client connection") },
145                 { Value,
146                         "client_disconnect",
147                         "/usr/bin/ovpn-clientdisconnect",
148                         translate("Run script cmd on client disconnection") },
149                 { Value,
150                         "learn_address",
151                         "/usr/bin/ovpn-learnaddress",
152                         translate("Executed in server mode whenever an IPv4 address/route or MAC address is added to OpenVPN's internal routing table") },
153                 { Value,
154                         "auth_user_pass_verify",
155                         "/usr/bin/ovpn-userpass via-env",
156                         translate("Executed in server mode on new client connections, when the client is still untrusted") },
157                 { ListValue,
158                         "script_security",
159                         { 0, 1, 2, 3 },
160                         translate("Policy level over usage of external programs and scripts") },
161                 { ListValue,
162                         "compress",
163                         { "lzo", "lz4" },
164                         translate("Enable a compression algorithm") },
165         } },
166
167         { "Networking", {
168         -- socket config
169                 { ListValue,
170                         "mode",
171                         { "p2p", "server" },
172                         translate("Major mode") },
173                 { Value,
174                         "local",
175                         "0.0.0.0",
176                         translate("Local host name or ip address") },
177                 { Value,
178                         "port",
179                         1194,
180                         translate("TCP/UDP port # for both local and remote") },
181                 { Value,
182                         "lport",
183                         1194,
184                         translate("TCP/UDP port # for local (default=1194)") },
185                 { Value,
186                         "rport",
187                         1194,
188                         translate("TCP/UDP port # for remote (default=1194)") },
189                 { Flag,
190                         "float",
191                         0,
192                         translate("Allow remote to change its IP or port") },
193                 { Flag,
194                         "nobind",
195                         0,
196                         translate("Do not bind to local address and port") },
197                 { Value,
198                         "dev",
199                         "tun0",
200                         translate("tun/tap device") },
201                 { ListValue,
202                         "dev_type",
203                         { "tun", "tap" },
204                         translate("Type of used device") },
205                 { Value,
206                         "dev_node",
207                         "/dev/net/tun",
208                         translate("Use tun/tap device node") },
209                 { Value,
210                         "ifconfig",
211                         "10.200.200.3 10.200.200.1",
212                         translate("Set tun/tap adapter parameters") },
213                 { Flag,
214                         "ifconfig_noexec",
215                         0,
216                         translate("Don't actually execute ifconfig") },
217                 { Flag,
218                         "ifconfig_nowarn",
219                         0,
220                         translate("Don't warn on ifconfig inconsistencies") },
221                 { DynamicList,
222                         "route",
223                         "10.123.0.0 255.255.0.0",
224                         translate("Add route after establishing connection") },
225                 { Value,
226                         "route_gateway",
227                         "10.234.1.1",
228                         translate("Specify a default gateway for routes") },
229                 { Value,
230                         "route_delay",
231                         0,
232                         translate("Delay n seconds after connection") },
233                 { Flag,
234                         "route_noexec",
235                         0,
236                         translate("Don't add routes automatically") },
237                 { Flag,
238                         "route_nopull",
239                         0,
240                         translate("Don't pull routes automatically") },
241                 { Flag,
242                         "allow_recursive_routing",
243                         0,
244                         translate("Don't drop incoming tun packets with same destination as host") },
245                 { ListValue,
246                         "mtu_disc",
247                         { "yes", "maybe", "no" },
248                         translate("Enable Path MTU discovery") },
249                 { Flag,
250                         "mtu_test",
251                         0,
252                         translate("Empirically measure MTU") },
253                 { ListValue,
254                         "comp_lzo",
255                         { "yes", "no", "adaptive" },
256                         translate("Use fast LZO compression") },
257                 { Flag,
258                         "comp_noadapt",
259                         0,
260                         translate("Don't use adaptive lzo compression"),
261                         { comp_lzo=1 } },
262                 { Value,
263                         "link_mtu",
264                         1500,
265                         translate("Set TCP/UDP MTU") },
266                 { Value,
267                         "tun_mtu",
268                         1500,
269                         translate("Set tun/tap device MTU") },
270                 { Value,
271                         "tun_mtu_extra",
272                         1500,
273                         translate("Set tun/tap device overhead") },
274                 { Value,
275                         "fragment",
276                         1500,
277                         translate("Enable internal datagram fragmentation"),
278                         { proto="udp" } },
279                 { Value,
280                         "mssfix",
281                         1500,
282                         translate("Set upper bound on TCP MSS"),
283                         { proto="udp" } },
284                 { Value,
285                         "sndbuf",
286                         65536,
287                         translate("Set the TCP/UDP send buffer size") },
288                 { Value,
289                         "rcvbuf",
290                         65536,
291                         translate("Set the TCP/UDP receive buffer size") },
292                 { Value,
293                         "txqueuelen",
294                         100,
295                         translate("Set tun/tap TX queue length") },
296                 { Value,
297                         "shaper",
298                         10240,
299                         translate("Shaping for peer bandwidth") },
300                 { Value,
301                         "inactive",
302                         240,
303                         translate("tun/tap inactivity timeout") },
304                 { Value,
305                         "keepalive",
306                         "10 60",
307                         translate("Helper directive to simplify the expression of --ping and --ping-restart in server mode configurations") },
308                 { Value,
309                         "ping",
310                         30,
311                         translate("Ping remote every n seconds over TCP/UDP port") },
312                 { Value,
313                         "ping_exit",
314                         120,
315                         translate("Remote ping timeout") },
316                 { Value,
317                         "ping_restart",
318                         60,
319                         translate("Restart after remote ping timeout") },
320                 { Flag,
321                         "ping_timer_rem",
322                         0,
323                         translate("Only process ping timeouts if routes exist") },
324                 { Flag,
325                         "persist_tun",
326                         0,
327                         translate("Keep tun/tap device open on restart") },
328                 { Flag,
329                         "persist_key",
330                         0,
331                         translate("Don't re-read key on restart") },
332                 { Flag,
333                         "persist_local_ip",
334                         0,
335                         translate("Keep local IP address on restart") },
336                 { Flag,
337                         "persist_remote_ip",
338                         0,
339                         translate("Keep remote IP address on restart") },
340         -- management channel
341                 { Value,
342                         "management",
343                         "127.0.0.1 31194 /etc/openvpn/mngmt-pwds",
344                         translate("Enable management interface on <em>IP</em> <em>port</em>") },
345         -- management
346                 { Flag,
347                         "management_query_passwords",
348                         0,
349                         translate("Query management channel for private key") },
350         -- management
351                 { Flag,
352                         "management_hold",
353                         0,
354                         translate("Start OpenVPN in a hibernating state") },
355         -- management
356                 { Value,
357                         "management_log_cache",
358                         100,
359                         translate("Number of lines for log file history") },
360                 { ListValue,
361                         "topology",
362                         { "net30", "p2p", "subnet" },
363                         translate("'net30', 'p2p', or 'subnet'"),
364                         {dev_type="tun" } },
365         } },
366
367         { "VPN", {
368                 { Value,
369                         "server",
370                         "10.200.200.0 255.255.255.0",
371                         translate("Configure server mode"),
372                         { client="0" }, { client="" } },
373                 { Value,
374                         "server_bridge",
375                         "10.200.200.1 255.255.255.0 10.200.200.200 10.200.200.250",
376                         translate("Configure server bridge"),
377                         { client="0" }, { client="" } },
378                 { DynamicList,
379                         "push",
380                         { "redirect-gateway", "comp-lzo" },
381                         translate("Push options to peer"),
382                         { client="0" }, { client="" } },
383                 { Flag,
384                         "push_reset",
385                         0,
386                         translate("Don't inherit global push options"),
387                         { client="0" }, { client="" } },
388                 { Flag,
389                         "disable",
390                         0,
391                         translate("Client is disabled"),
392                         { client="0" }, { client="" } },
393                 { Value,
394                         "ifconfig_pool",
395                         "10.200.200.100 10.200.200.150 255.255.255.0",
396                         translate("Set aside a pool of subnets"),
397                         { client="0" }, { client="" } },
398                 { Value,
399                         "ifconfig_pool_persist",
400                         "/etc/openvpn/ipp.txt 600",
401                         translate("Persist/unpersist ifconfig-pool"),
402                         { client="0" }, { client="" } },
403                 { Value,
404                         "ifconfig_push",
405                         "10.200.200.1 255.255.255.255",
406                         translate("Push an ifconfig option to remote"),
407                         { client="0" }, { client="" } },
408                 { Value,
409                         "iroute",
410                         "10.200.200.0 255.255.255.0",
411                         translate("Route subnet to client"),
412                         { client="0" }, { client="" } },
413                 { Flag,
414                         "client_to_client",
415                         0,
416                         translate("Allow client-to-client traffic"),
417                         { client="0" }, { client="" } },
418                 { Flag,
419                         "duplicate_cn",
420                         0,
421                         translate("Allow multiple clients with same certificate"),
422                         { client="0" }, { client="" } },
423                 { Value,
424                         "client_config_dir",
425                         "/etc/openvpn/ccd",
426                         translate("Directory for custom client config files"),
427                         { client="0" }, { client="" } },
428                 { Flag,
429                         "ccd_exclusive",
430                         0,
431                         translate("Refuse connection if no custom client config"),
432                         { client="0" }, { client="" } },
433                 { Value,
434                         "tmp_dir",
435                         "/var/run/openvpn",
436                         translate("Temporary directory for client-connect return file"),
437                         { client="0" }, { client="" } },
438                 { Value,
439                         "hash_size",
440                         "256 256",
441                         translate("Set size of real and virtual address hash tables"),
442                         { client="0" }, { client="" } },
443                 { Value,
444                         "bcast_buffers",
445                         256,
446                         translate("Number of allocated broadcast buffers"),
447                         { client="0" }, { client="" } },
448                 { Value,
449                         "tcp_queue_limit",
450                         64,
451                         translate("Maximum number of queued TCP output packets"),
452                         { client="0" }, { client="" } },
453                 { Value,
454                         "max_clients",
455                         10,
456                         translate("Allowed maximum of connected clients"),
457                         { client="0" }, { client="" } },
458                 { Value,
459                         "max_routes_per_client",
460                         256,
461                         translate("Allowed maximum of internal"),
462                         { client="0" }, { client="" } },
463                 { Value,
464                         "connect_freq",
465                         "3 10",
466                         translate("Allowed maximum of new connections"),
467                         { client="0" }, { client="" } },
468                 { Flag,
469                         "username_as_common_name",
470                         0,
471                         translate("Use username as common name"),
472                         { client="0" }, { client="" } },
473                 { Flag,
474                         "client",
475                         0,
476                         translate("Configure client mode") },
477                 { Flag,
478                         "pull",
479                         0,
480                         translate("Accept options pushed from server"),
481                         { client="1" } },
482                 { FileUpload,
483                         "auth_user_pass",
484                         "/etc/openvpn/userpass.txt",
485                         translate("Authenticate using username/password"),
486                         { client="1" } },
487                 { ListValue,
488                         "auth_retry",
489                         { "none", "nointeract", "interact" },
490                         translate("Handling of authentication failures"),
491                         { client="1" } },
492                 { Value,
493                         "explicit_exit_notify",
494                         1,
495                         translate("Send notification to peer on disconnect"),
496                         { client="1" } },
497                 { DynamicList,
498                         "remote",
499                         "1.2.3.4",
500                         translate("Remote host name or ip address"),
501                         { client="1" } },
502                 { Flag,
503                         "remote_random",
504                         0,
505                         translate("Randomly choose remote server"),
506                         { client="1" } },
507                 { ListValue,
508                         "proto",
509                         { "udp", "tcp-client", "tcp-server" },
510                         translate("Use protocol"),
511                         { client="1" } },
512                 { Value,
513                         "connect_retry",
514                         5,
515                         translate("Connection retry interval"),
516                         { proto="tcp-client" }, { client="1" } },
517                 { Value,
518                         "http_proxy",
519                         "192.168.1.100 8080",
520                         translate("Connect to remote host through an HTTP proxy"),
521                         { client="1" } },
522                 { Flag,
523                         "http_proxy_retry",
524                         0,
525                         translate("Retry indefinitely on HTTP proxy errors"),
526                         { client="1" } },
527                 { Value,
528                         "http_proxy_timeout",
529                         5,
530                         translate("Proxy timeout in seconds"),
531                         { client="1" } },
532                 { DynamicList,
533                         "http_proxy_option",
534                         { "VERSION 1.0", "AGENT OpenVPN/2.0.9" },
535                         translate("Set extended HTTP proxy options"),
536                         { client="1" } },
537                 { Value,
538                         "socks_proxy",
539                         "192.168.1.200 1080",
540                         translate("Connect through Socks5 proxy"),
541                         { client="1" } },
542         -- client && socks_proxy
543                 { Value,
544                         "socks_proxy_retry",
545                         5,
546                         translate("Retry indefinitely on Socks proxy errors"),
547                         { client="1" } },
548                 { Value,
549                         "resolv_retry",
550                         "infinite",
551                         translate("If hostname resolve fails, retry"),
552                         { client="1" } },
553                 { ListValue,
554                         "redirect_gateway",
555                         { "", "local", "def1", "local def1" },
556                         translate("Automatically redirect default route"),
557                         { client="1" } },
558                 { Value,
559                         "verify_client_cert",
560                         {  "none", "optional", "require" },
561                         translate("Specify whether the client is required to supply a valid certificate") },
562         } },
563
564         { "Cryptography", {
565                 { FileUpload,
566                         "secret",
567                         "/etc/openvpn/secret.key",
568                         translate("Enable Static Key encryption mode (non-TLS)") },
569         -- parse
570                 { Value,
571                         "auth",
572                         "SHA1",
573                         translate("HMAC authentication for packets") },
574         -- parse
575                 { Value,
576                         "cipher",
577                         {
578                                 "AES-128-CBC",
579                                 "AES-128-CFB",
580                                 "AES-128-CFB1",
581                                 "AES-128-CFB8",
582                                 "AES-128-GCM",
583                                 "AES-128-OFB",
584                                 "AES-192-CBC",
585                                 "AES-192-CFB",
586                                 "AES-192-CFB1",
587                                 "AES-192-CFB8",
588                                 "AES-192-GCM",
589                                 "AES-192-OFB",
590                                 "AES-256-CBC",
591                                 "AES-256-CFB",
592                                 "AES-256-CFB1",
593                                 "AES-256-CFB8",
594                                 "AES-256-GCM",
595                                 "AES-256-OFB",
596                                 "BF-CBC",
597                                 "BF-CFB",
598                                 "BF-OFB",
599                                 "CAST5-CBC",
600                                 "CAST5-CFB",
601                                 "CAST5-OFB",
602                                 "DES-CBC",
603                                 "DES-CFB",
604                                 "DES-CFB1",
605                                 "DES-CFB8",
606                                 "DES-EDE-CBC",
607                                 "DES-EDE-CFB",
608                                 "DES-EDE-OFB",
609                                 "DES-EDE3-CBC",
610                                 "DES-EDE3-CFB",
611                                 "DES-EDE3-CFB1",
612                                 "DES-EDE3-CFB8",
613                                 "DES-EDE3-OFB",
614                                 "DES-OFB",
615                                 "DESX-CBC",
616                                 "RC2-40-CBC",
617                                 "RC2-64-CBC",
618                                 "RC2-CBC",
619                                 "RC2-CFB",
620                                 "RC2-OFB"
621                         },
622                         translate("Encryption cipher for packets") },
623         -- parse
624                 { Value,
625                         "keysize",
626                         1024,
627                         translate("Size of cipher key") },
628         -- parse
629                 { Value,
630                         "engine",
631                         "dynamic",
632                         translate("Enable OpenSSL hardware crypto engines") },
633                 { Value,
634                         "replay_window",
635                         "64 15",
636                         translate("Replay protection sliding window size") },
637                 { Flag,
638                         "mute_replay_warnings",
639                         0,
640                         translate("Silence the output of replay warnings") },
641                 { Value,
642                         "replay_persist",
643                         "/var/run/openvpn-replay-state",
644                         translate("Persist replay-protection state") },
645                 { Flag,
646                         "tls_server",
647                         0,
648                         translate("Enable TLS and assume server role"),
649                         { tls_client="" }, { tls_client="0" } },
650                 { Flag,
651                         "tls_client",
652                         0,
653                         translate("Enable TLS and assume client role"),
654                         { tls_server="" }, { tls_server="0" } },
655                 { FileUpload,
656                         "ca",
657                         "/etc/easy-rsa/keys/ca.crt",
658                         translate("Certificate authority") },
659                 { FileUpload,
660                         "dh",
661                         "/etc/easy-rsa/keys/dh1024.pem",
662                         translate("Diffie Hellman parameters") },
663                 { FileUpload,
664                         "cert",
665                         "/etc/easy-rsa/keys/some-client.crt",
666                         translate("Local certificate") },
667                 { FileUpload,
668                         "key",
669                         "/etc/easy-rsa/keys/some-client.key",
670                         translate("Local private key") },
671                 { FileUpload,
672                         "pkcs12",
673                         "/etc/easy-rsa/keys/some-client.pk12",
674                         translate("PKCS#12 file containing keys") },
675                 { ListValue,
676                         "key_method",
677                         { 1, 2 },
678                         translate("Enable TLS and assume client role") },
679                 { DynamicList,
680                         "tls_cipher",
681                         {
682                                 "DHE-RSA-AES256-SHA",
683                                 "DHE-DSS-AES256-SHA",
684                                 "AES256-SHA",
685                                 "EDH-RSA-DES-CBC3-SHA",
686                                 "EDH-DSS-DES-CBC3-SHA",
687                                 "DES-CBC3-SHA",
688                                 "DHE-RSA-AES128-SHA",
689                                 "DHE-DSS-AES128-SHA",
690                                 "AES128-SHA",
691                                 "RC4-SHA",
692                                 "RC4-MD5",
693                                 "EDH-RSA-DES-CBC-SHA",
694                                 "EDH-DSS-DES-CBC-SHA",
695                                 "DES-CBC-SHA",
696                                 "EXP-EDH-RSA-DES-CBC-SHA",
697                                 "EXP-EDH-DSS-DES-CBC-SHA",
698                                 "EXP-DES-CBC-SHA",
699                                 "EXP-RC2-CBC-MD5",
700                                 "EXP-RC4-MD5"
701                         },
702                         translate("TLS cipher") },
703                 { DynamicList,
704                         "tls_ciphersuites",
705                         {
706                                 "TLS_AES_256_GCM_SHA384",
707                                 "TLS_AES_128_GCM_SHA256",
708                                 "TLS_CHACHA20_POLY1305_SHA256"
709                         },
710                         translate("TLS 1.3 or newer cipher") },
711                 { Value,
712                         "tls_timeout",
713                         2,
714                         translate("Retransmit timeout on TLS control channel") },
715                 { Value,
716                         "reneg_bytes",
717                         1024,
718                         translate("Renegotiate data chan. key after bytes") },
719                 { Value,
720                         "reneg_pkts",
721                         100,
722                         translate("Renegotiate data chan. key after packets") },
723                 { Value,
724                         "reneg_sec",
725                         3600,
726                         translate("Renegotiate data chan. key after seconds") },
727                 { Value,
728                         "hand_window",
729                         60,
730                         translate("Timeframe for key exchange") },
731                 { Value,
732                         "tran_window",
733                         3600,
734                         translate("Key transition window") },
735                 { Flag,
736                         "single_session",
737                         0,
738                         translate("Allow only one session") },
739                 { Flag,
740                         "tls_exit",
741                         0,
742                         translate("Exit on TLS negotiation failure") },
743                 { Value,
744                         "tls_auth",
745                         "/etc/openvpn/tlsauth.key",
746                         translate("Additional authentication over TLS") },
747                 { Value,
748                         "tls_crypt",
749                         "/etc/openvpn/tlscrypt.key",
750                         translate("Encrypt and authenticate all control channel packets with the key") },
751         --      { Value,
752         --              "askpass",
753         --              "[file]",
754         --              translate("Get PEM password from controlling tty before we daemonize") },
755                 { Flag,
756                         "auth_nocache",
757                         0,
758                         translate("Don't cache --askpass or --auth-user-pass passwords") },
759                 { Value,
760                         "tls_remote",
761                         "remote_x509_name",
762                         translate("Only accept connections from given X509 name") },
763                 { ListValue,
764                         "ns_cert_type",
765                         { "client", "server" },
766                         translate("Require explicit designation on certificate") },
767                 { ListValue,
768                         "remote_cert_tls",
769                         { "client", "server" },
770                         translate("Require explicit key usage on certificate") },
771                 { Value,
772                         "crl_verify",
773                         "/etc/easy-rsa/keys/crl.pem",
774                         translate("Check peer certificate against a CRL") },
775                 { Value,
776                         "tls_version_min",
777                         "1.0",
778                         translate("The lowest supported TLS version") },
779                 { Value,
780                         "tls_version_max",
781                         "1.2",
782                         translate("The highest supported TLS version") },
783                 { ListValue,
784                         "key_direction",
785                         { 0, 1 },
786                         translate("The key direction for 'tls-auth' and 'secret' options") },
787                 { Flag,
788                         "ncp_disable",
789                         0,
790                         translate("This completely disables cipher negotiation") },
791                 { Value,
792                         "ncp_ciphers",
793                         "AES-256-GCM:AES-128-GCM",
794                         translate("Restrict the allowed ciphers to be negotiated") },
795         } }
796 }
797
798
799 local cts = { }
800 local params = { }
801
802 local m = Map("openvpn")
803 m.redirect = luci.dispatcher.build_url("admin", "vpn", "openvpn")
804 m.apply_on_parse = true
805
806 local p = m:section( SimpleSection )
807 p.template = "openvpn/pageswitch"
808 p.mode     = "advanced"
809 p.instance = arg[1]
810 p.category = arg[2] or "Service"
811
812 for _, c in ipairs(knownParams) do
813         cts[#cts+1] = c[1]
814         if c[1] == p.category then params = c[2] end
815 end
816
817 p.categories = cts
818
819
820 local s = m:section(
821         NamedSection, arg[1], "openvpn",
822         translate("%s" % arg[2])
823 )
824
825 s.title     = translate("%s" % arg[2])
826 s.addremove = false
827 s.anonymous = true
828
829
830 for _, option in ipairs(params) do
831         local o = s:option(
832                 option[1], option[2],
833                 option[2], option[4]
834         )
835
836         o.optional = true
837
838         if option[1] == DummyValue then
839                 o.value = option[3]
840         elseif option[1] == FileUpload then
841
842                 function o.cfgvalue(self, section)
843                         local cfg_val = AbstractValue.cfgvalue(self, section)
844
845                         if cfg_val then
846                                 return cfg_val
847                         end
848                 end
849
850                 function o.formvalue(self, section)
851                         local sel_val = AbstractValue.formvalue(self, section)
852                         local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
853
854                         if sel_val and sel_val ~= "" then
855                                 return sel_val
856                         end
857
858                         if txt_val and txt_val ~= "" then
859                                 return txt_val
860                         end
861                 end
862
863                 function o.remove(self, section)
864                         local cfg_val = AbstractValue.cfgvalue(self, section)
865                         local txt_val = luci.http.formvalue("cbid."..self.map.config.."."..section.."."..self.option..".textbox")
866                         
867                         if cfg_val and fs.access(cfg_val) and txt_val == "" then
868                                 fs.unlink(cfg_val)
869                         end
870                         return AbstractValue.remove(self, section)
871                 end
872         elseif option[1] == Flag then
873                 o.default = nil
874         else
875                 if option[1] == DynamicList then
876                         function o.cfgvalue(...)
877                                 local val = AbstractValue.cfgvalue(...)
878                                 return ( val and type(val) ~= "table" ) and { val } or val
879                         end
880                 end
881
882                 if type(option[3]) == "table" then
883                         if o.optional then o:value("", "-- remove --") end
884                         for _, v in ipairs(option[3]) do
885                                 v = tostring(v)
886                                 o:value(v)
887                         end
888                         o.default = tostring(option[3][1])
889                 else
890                         o.default = tostring(option[3])
891                 end
892         end
893
894         for i=5,#option do
895                 if type(option[i]) == "table" then
896                         o:depends(option[i])
897                 end
898         end
899 end
900
901 return m