]>
Commit | Line | Data |
---|---|---|
6e13d0a5 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
49abe7af | 5 | # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org> # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
54fd0535 | 21 | ### |
f527e53f | 22 | # Based on IPFireCore 77 |
54fd0535 | 23 | ### |
6e13d0a5 MT |
24 | use CGI; |
25 | use CGI qw/:standard/; | |
26 | use Net::DNS; | |
ce9abb66 | 27 | use Net::Ping; |
54fd0535 | 28 | use Net::Telnet; |
6e13d0a5 MT |
29 | use File::Copy; |
30 | use File::Temp qw/ tempfile tempdir /; | |
31 | use strict; | |
32 | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
eff2dbf8 | 33 | use Sort::Naturally; |
6e13d0a5 | 34 | require '/var/ipfire/general-functions.pl'; |
6e13d0a5 MT |
35 | require "${General::swroot}/lang.pl"; |
36 | require "${General::swroot}/header.pl"; | |
37 | require "${General::swroot}/countries.pl"; | |
e2e270e1 | 38 | require "${General::swroot}/location-functions.pl"; |
6e13d0a5 MT |
39 | |
40 | # enable only the following on debugging purpose | |
8c877a82 AM |
41 | #use warnings; |
42 | #use CGI::Carp 'fatalsToBrowser'; | |
6e13d0a5 | 43 | #workaround to suppress a warning when a variable is used only once |
8c877a82 | 44 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); |
6e13d0a5 MT |
45 | undef (@dummy); |
46 | ||
f2fdd0c1 CS |
47 | my %color = (); |
48 | my %mainsettings = (); | |
49 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 50 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
6e13d0a5 MT |
51 | |
52 | ### | |
53 | ### Initialize variables | |
54 | ### | |
e81be1e1 AM |
55 | my %ccdconfhash=(); |
56 | my %ccdroutehash=(); | |
57 | my %ccdroute2hash=(); | |
6e13d0a5 MT |
58 | my %netsettings=(); |
59 | my %cgiparams=(); | |
60 | my %vpnsettings=(); | |
61 | my %checked=(); | |
62 | my %confighash=(); | |
63 | my %cahash=(); | |
64 | my %selected=(); | |
65 | my $warnmessage = ''; | |
66 | my $errormessage = ''; | |
400c8afd EK |
67 | my $cryptoerror = ''; |
68 | my $cryptowarning = ''; | |
6e13d0a5 | 69 | my %settings=(); |
54fd0535 | 70 | my $routes_push_file = ''; |
df9b48b7 AM |
71 | my $confighost="${General::swroot}/fwhosts/customhosts"; |
72 | my $configgrp="${General::swroot}/fwhosts/customgroups"; | |
73 | my $customnet="${General::swroot}/fwhosts/customnetworks"; | |
74 | my $name; | |
99bfa85c | 75 | my $col=""; |
ffbe77c8 EK |
76 | my $local_serverconf = "${General::swroot}/ovpn/scripts/server.conf.local"; |
77 | my $local_clientconf = "${General::swroot}/ovpn/scripts/client.conf.local"; | |
78 | ||
6e13d0a5 MT |
79 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
80 | $cgiparams{'ENABLED'} = 'off'; | |
81 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
82 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
83 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
84 | $cgiparams{'NAT'} = 'off'; | |
85 | $cgiparams{'COMPRESSION'} = 'off'; | |
86 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
87 | $cgiparams{'ACTION'} = ''; | |
88 | $cgiparams{'CA_NAME'} = ''; | |
4c962356 EK |
89 | $cgiparams{'DH_NAME'} = 'dh1024.pem'; |
90 | $cgiparams{'DHLENGHT'} = ''; | |
6e13d0a5 MT |
91 | $cgiparams{'DHCP_DOMAIN'} = ''; |
92 | $cgiparams{'DHCP_DNS'} = ''; | |
93 | $cgiparams{'DHCP_WINS'} = ''; | |
54fd0535 | 94 | $cgiparams{'ROUTES_PUSH'} = ''; |
6e13d0a5 | 95 | $cgiparams{'DCOMPLZO'} = 'off'; |
a79fa1d6 | 96 | $cgiparams{'MSSFIX'} = ''; |
8c877a82 | 97 | $cgiparams{'number'} = ''; |
4c962356 | 98 | $cgiparams{'DCIPHER'} = ''; |
49abe7af EK |
99 | $cgiparams{'DAUTH'} = ''; |
100 | $cgiparams{'TLSAUTH'} = ''; | |
54fd0535 | 101 | $routes_push_file = "${General::swroot}/ovpn/routes_push"; |
400c8afd EK |
102 | # Perform crypto and configration test |
103 | &pkiconfigcheck; | |
ffbe77c8 EK |
104 | |
105 | # Add CCD files if not already presant | |
106 | unless (-e $routes_push_file) { | |
107 | open(RPF, ">$routes_push_file"); | |
108 | close(RPF); | |
109 | } | |
110 | unless (-e "${General::swroot}/ovpn/ccd.conf") { | |
111 | open(CCDC, ">${General::swroot}/ovpn/ccd.conf"); | |
112 | close (CCDC); | |
113 | } | |
114 | unless (-e "${General::swroot}/ovpn/ccdroute") { | |
115 | open(CCDR, ">${General::swroot}/ovpn/ccdroute"); | |
116 | close (CCDR); | |
117 | } | |
118 | unless (-e "${General::swroot}/ovpn/ccdroute2") { | |
119 | open(CCDRT, ">${General::swroot}/ovpn/ccdroute2"); | |
120 | close (CCDRT); | |
121 | } | |
122 | # Add additional configs if not already presant | |
123 | unless (-e "$local_serverconf") { | |
124 | open(LSC, ">$local_serverconf"); | |
125 | close (LSC); | |
126 | } | |
127 | unless (-e "$local_clientconf") { | |
128 | open(LCC, ">$local_clientconf"); | |
129 | close (LCC); | |
130 | } | |
ce9abb66 | 131 | |
6e13d0a5 MT |
132 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
133 | ||
134 | # prepare openvpn config file | |
135 | ### | |
136 | ### Useful functions | |
137 | ### | |
c6c9630e MT |
138 | sub haveOrangeNet |
139 | { | |
13211b21 CS |
140 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} |
141 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
c6c9630e MT |
142 | return 0; |
143 | } | |
144 | ||
145 | sub haveBlueNet | |
146 | { | |
13211b21 | 147 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} |
c6c9630e | 148 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} |
c6c9630e MT |
149 | return 0; |
150 | } | |
151 | ||
152 | sub sizeformat{ | |
153 | my $bytesize = shift; | |
154 | my $i = 0; | |
155 | ||
156 | while(abs($bytesize) >= 1024){ | |
157 | $bytesize=$bytesize/1024; | |
158 | $i++; | |
159 | last if($i==6); | |
160 | } | |
161 | ||
162 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
163 | my $newsize=(int($bytesize*100 +0.5))/100; | |
164 | return("$newsize $units[$i]"); | |
165 | } | |
166 | ||
c6c9630e MT |
167 | sub cleanssldatabase |
168 | { | |
169 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
170 | print FILE "01"; | |
171 | close FILE; | |
172 | } | |
173 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
174 | print FILE ""; | |
175 | close FILE; | |
176 | } | |
e6f7f8e7 EK |
177 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt.attr")) { |
178 | print FILE ""; | |
179 | close FILE; | |
180 | } | |
c6c9630e | 181 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); |
e6f7f8e7 | 182 | unlink ("${General::swroot}/ovpn/certs/index.txt.attr.old"); |
c6c9630e MT |
183 | unlink ("${General::swroot}/ovpn/certs/serial.old"); |
184 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
185 | } | |
186 | ||
187 | sub newcleanssldatabase | |
188 | { | |
189 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
190 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
191 | print FILE "01"; | |
192 | close FILE; | |
193 | } | |
194 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
2feacd98 | 195 | &General::system("touch", "${General::swroot}/ovpn/certs/index.txt"); |
c6c9630e | 196 | } |
e6f7f8e7 | 197 | if (! -s ">${General::swroot}/ovpn/certs/index.txt.attr") { |
2feacd98 | 198 | &General::system("touch", "${General::swroot}/ovpn/certs/index.txt.attr"); |
e6f7f8e7 | 199 | } |
c6c9630e | 200 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); |
e6f7f8e7 | 201 | unlink ("${General::swroot}/ovpn/certs/index.txt.attr.old"); |
c6c9630e MT |
202 | unlink ("${General::swroot}/ovpn/certs/serial.old"); |
203 | } | |
204 | ||
205 | sub deletebackupcert | |
206 | { | |
207 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
208 | my $hexvalue = <FILE>; | |
209 | chomp $hexvalue; | |
210 | close FILE; | |
211 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
212 | } | |
213 | } | |
4c962356 | 214 | |
400c8afd EK |
215 | ### |
216 | ### Check for PKI and configure problems | |
217 | ### | |
218 | ||
219 | sub pkiconfigcheck | |
220 | { | |
221 | # Warning if DH parameter is 1024 bit | |
222 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { | |
2feacd98 | 223 | my @dhparameter = &General::system_output("/usr/bin/openssl", "dhparam", "-text", "-in", "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"); |
f5604080 | 224 | my $dhbit; |
2feacd98 | 225 | |
f5604080 | 226 | # Loop through the output and search for the DH bit lenght. |
2feacd98 | 227 | foreach my $line (@dhparameter) { |
f5604080 SS |
228 | if ($line =~ (/(\d+)/)) { |
229 | # Assign match to dhbit value. | |
230 | $dhbit = $1; | |
231 | ||
232 | last; | |
2feacd98 | 233 | } |
400c8afd | 234 | } |
f5604080 SS |
235 | |
236 | # Check if the used key lenght is at least 2048 bit. | |
237 | if ($dhbit < 2048) { | |
238 | $cryptoerror = "$Lang::tr{'ovpn error dh'}"; | |
239 | goto CRYPTO_ERROR; | |
240 | } | |
400c8afd EK |
241 | } |
242 | ||
243 | # Warning if md5 is in usage | |
244 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
2feacd98 SS |
245 | my @signature = &General::system_output("/usr/bin/openssl", "x509", "-noout", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
246 | if (grep(/md5WithRSAEncryption/, @signature) ) { | |
400c8afd EK |
247 | $cryptoerror = "$Lang::tr{'ovpn error md5'}"; |
248 | goto CRYPTO_ERROR; | |
249 | } | |
250 | } | |
251 | ||
252 | CRYPTO_ERROR: | |
253 | ||
254 | # Warning if certificate is not compliant to RFC3280 TLS rules | |
255 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
2feacd98 SS |
256 | my @extendkeyusage = &General::system_output("/usr/bin/openssl", "x509", "-noout", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
257 | if ( ! grep(/TLS Web Server Authentication/, @extendkeyusage)) { | |
400c8afd EK |
258 | $cryptowarning = "$Lang::tr{'ovpn warning rfc3280'}"; |
259 | goto CRYPTO_WARNING; | |
260 | } | |
261 | } | |
262 | ||
263 | CRYPTO_WARNING: | |
264 | } | |
265 | ||
c6c9630e | 266 | sub writeserverconf { |
54fd0535 MT |
267 | my %sovpnsettings = (); |
268 | my @temp = (); | |
c6c9630e | 269 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); |
54fd0535 MT |
270 | &read_routepushfile; |
271 | ||
c6c9630e MT |
272 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; |
273 | flock CONF, 2; | |
274 | print CONF "#OpenVPN Server conf\n"; | |
275 | print CONF "\n"; | |
276 | print CONF "daemon openvpnserver\n"; | |
277 | print CONF "writepid /var/run/openvpn.pid\n"; | |
afabe9f7 | 278 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; |
c6c9630e | 279 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; |
79e7688b | 280 | print CONF "dev tun\n"; |
c6c9630e MT |
281 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; |
282 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
a4fd2325 | 283 | print CONF "script-security 3\n"; |
07675dc3 | 284 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; |
6140e7e0 | 285 | print CONF "client-config-dir /var/ipfire/ovpn/ccd\n"; |
c6c9630e | 286 | print CONF "tls-server\n"; |
4c962356 EK |
287 | print CONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; |
288 | print CONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
289 | print CONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 290 | print CONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
c6c9630e MT |
291 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); |
292 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
8c877a82 | 293 | #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; |
4c962356 | 294 | |
d6989b4b | 295 | print CONF "tun-mtu $sovpnsettings{'DMTU'}\n"; |
2ee746be | 296 | |
54fd0535 | 297 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { |
8c877a82 AM |
298 | @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'}); |
299 | foreach (@temp) | |
300 | { | |
301 | @tempovpnsubnet = split("\/",&General::ipcidr2msk($_)); | |
302 | print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n"; | |
303 | } | |
54fd0535 | 304 | } |
8c877a82 AM |
305 | # a.marx ccd |
306 | my %ccdconfhash=(); | |
307 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
308 | foreach my $key (keys %ccdconfhash) { | |
309 | my $a=$ccdconfhash{$key}[1]; | |
310 | my ($b,$c) = split (/\//, $a); | |
311 | print CONF "route $b ".&General::cidrtosub($c)."\n"; | |
312 | } | |
313 | my %ccdroutehash=(); | |
314 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
315 | foreach my $key (keys %ccdroutehash) { | |
316 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
317 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
318 | print CONF "route $a $b\n"; | |
319 | } | |
320 | } | |
321 | # ccd end | |
54fd0535 | 322 | |
8c877a82 | 323 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { |
c6c9630e MT |
324 | print CONF "client-to-client\n"; |
325 | } | |
1de5c945 | 326 | if ($sovpnsettings{MSSFIX} eq 'on') { |
4c962356 | 327 | print CONF "mssfix\n"; |
d6989b4b MT |
328 | } else { |
329 | print CONF "mssfix 0\n"; | |
1de5c945 EK |
330 | } |
331 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { | |
4c962356 | 332 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
a79fa1d6 | 333 | } |
2ee746be | 334 | |
c6c9630e MT |
335 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
336 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
337 | } | |
338 | print CONF "status-version 1\n"; | |
87fe47e9 | 339 | print CONF "status /var/run/ovpnserver.log 30\n"; |
a4fd2325 | 340 | print CONF "ncp-disable\n"; |
c6c9630e | 341 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
49abe7af | 342 | print CONF "auth $sovpnsettings{'DAUTH'}\n"; |
942446b5 EK |
343 | # Set TLSv2 as minimum |
344 | print CONF "tls-version-min 1.2\n"; | |
86308adb | 345 | |
49abe7af | 346 | if ($sovpnsettings{'TLSAUTH'} eq 'on') { |
4be45949 | 347 | print CONF "tls-auth ${General::swroot}/ovpn/certs/ta.key\n"; |
49abe7af | 348 | } |
c6c9630e MT |
349 | if ($sovpnsettings{DCOMPLZO} eq 'on') { |
350 | print CONF "comp-lzo\n"; | |
351 | } | |
352 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
353 | print CONF "push \"redirect-gateway def1\"\n"; | |
354 | } | |
355 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
356 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
357 | } | |
358 | ||
359 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
360 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
361 | } | |
362 | ||
363 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
364 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
365 | } | |
366 | ||
fa527476 | 367 | if ($sovpnsettings{MAX_CLIENTS} eq '') { |
c6c9630e | 368 | print CONF "max-clients 100\n"; |
a79fa1d6 | 369 | } |
fa527476 | 370 | if ($sovpnsettings{MAX_CLIENTS} ne '') { |
c6c9630e MT |
371 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; |
372 | } | |
1d0a260a | 373 | print CONF "tls-verify /usr/lib/openvpn/verify\n"; |
c6c9630e MT |
374 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; |
375 | print CONF "user nobody\n"; | |
376 | print CONF "group nobody\n"; | |
377 | print CONF "persist-key\n"; | |
378 | print CONF "persist-tun\n"; | |
379 | if ($sovpnsettings{LOG_VERB} ne '') { | |
380 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
381 | } else { | |
382 | print CONF "verb 3\n"; | |
ffbe77c8 | 383 | } |
708f2b73 MT |
384 | |
385 | print CONF "# Log clients connecting/disconnecting\n"; | |
386 | print CONF "client-connect \"/usr/sbin/openvpn-metrics client-connect\"\n"; | |
387 | print CONF "client-disconnect \"/usr/sbin/openvpn-metrics client-disconnect\"\n"; | |
388 | ||
ffbe77c8 EK |
389 | # Print server.conf.local if entries exist to server.conf |
390 | if ( !-z $local_serverconf && $sovpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
391 | open (LSC, "$local_serverconf"); | |
392 | print CONF "\n#---------------------------\n"; | |
393 | print CONF "# Start of custom directives\n"; | |
394 | print CONF "# from server.conf.local\n"; | |
395 | print CONF "#---------------------------\n\n"; | |
396 | while (<LSC>) { | |
397 | print CONF $_; | |
398 | } | |
399 | print CONF "\n#-----------------------------\n"; | |
400 | print CONF "# End of custom directives\n"; | |
401 | print CONF "#-----------------------------\n"; | |
402 | close (LSC); | |
403 | } | |
c6c9630e MT |
404 | print CONF "\n"; |
405 | ||
406 | close(CONF); | |
407 | } | |
8c877a82 | 408 | |
c6c9630e | 409 | sub emptyserverlog{ |
87fe47e9 | 410 | if (open(FILE, ">/var/run/ovpnserver.log")) { |
c6c9630e MT |
411 | flock FILE, 2; |
412 | print FILE ""; | |
413 | close FILE; | |
414 | } | |
415 | ||
416 | } | |
417 | ||
8c877a82 AM |
418 | sub delccdnet |
419 | { | |
420 | my %ccdconfhash = (); | |
421 | my %ccdhash = (); | |
422 | my $ccdnetname=$_[0]; | |
423 | if (-f "${General::swroot}/ovpn/ovpnconfig"){ | |
424 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
425 | foreach my $key (keys %ccdhash) { | |
426 | if ($ccdhash{$key}[32] eq $ccdnetname) { | |
427 | $errormessage=$Lang::tr{'ccd err hostinnet'}; | |
428 | return; | |
429 | } | |
430 | } | |
431 | } | |
432 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
433 | foreach my $key (keys %ccdconfhash) { | |
434 | if ($ccdconfhash{$key}[0] eq $ccdnetname){ | |
435 | delete $ccdconfhash{$key}; | |
436 | } | |
437 | } | |
438 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
439 | ||
440 | &writeserverconf; | |
441 | return 0; | |
442 | } | |
443 | ||
444 | sub addccdnet | |
445 | { | |
446 | my %ccdconfhash=(); | |
447 | my @ccdconf=(); | |
448 | my $ccdname=$_[0]; | |
449 | my $ccdnet=$_[1]; | |
8c877a82 AM |
450 | my $subcidr; |
451 | my @ip2=(); | |
452 | my $checkup; | |
453 | my $ccdip; | |
454 | my $baseaddress; | |
290007b3 AM |
455 | |
456 | ||
457 | #check name | |
458 | if ($ccdname eq '') | |
459 | { | |
460 | $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>"; | |
461 | return | |
462 | } | |
463 | ||
464 | if(!&General::validhostname($ccdname)) | |
465 | { | |
8c877a82 AM |
466 | $errormessage=$Lang::tr{'ccd err invalidname'}; |
467 | return; | |
468 | } | |
290007b3 AM |
469 | |
470 | ($ccdip,$subcidr) = split (/\//,$ccdnet); | |
471 | $subcidr=&General::iporsubtocidr($subcidr); | |
472 | #check subnet | |
473 | if ($subcidr > 30) | |
474 | { | |
8c877a82 AM |
475 | $errormessage=$Lang::tr{'ccd err invalidnet'}; |
476 | return; | |
477 | } | |
290007b3 AM |
478 | #check ip |
479 | if (!&General::validipandmask($ccdnet)){ | |
480 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
481 | return; | |
8c877a82 | 482 | } |
b6c60092 | 483 | |
8c877a82 AM |
484 | if (!$errormessage) { |
485 | my %ccdconfhash=(); | |
486 | $baseaddress=&General::getnetworkip($ccdip,$subcidr); | |
487 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
488 | my $key = &General::findhasharraykey (\%ccdconfhash); | |
489 | foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";} | |
490 | $ccdconfhash{$key}[0] = $ccdname; | |
491 | $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr; | |
492 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
493 | &writeserverconf; | |
494 | $cgiparams{'ccdname'}=''; | |
495 | $cgiparams{'ccdsubnet'}=''; | |
496 | return 1; | |
497 | } | |
498 | } | |
499 | ||
500 | sub modccdnet | |
501 | { | |
502 | ||
503 | my $newname=$_[0]; | |
504 | my $oldname=$_[1]; | |
505 | my %ccdconfhash=(); | |
506 | my %ccdhash=(); | |
7ad653cc SS |
507 | |
508 | # Check if the new name is valid. | |
509 | if(!&General::validhostname($newname)) { | |
510 | $errormessage=$Lang::tr{'ccd err invalidname'}; | |
511 | return; | |
512 | } | |
513 | ||
8c877a82 AM |
514 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); |
515 | foreach my $key (keys %ccdconfhash) { | |
516 | if ($ccdconfhash{$key}[0] eq $oldname) { | |
517 | foreach my $key1 (keys %ccdconfhash) { | |
518 | if ($ccdconfhash{$key1}[0] eq $newname){ | |
519 | $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'}; | |
520 | return; | |
521 | }else{ | |
522 | $ccdconfhash{$key}[0]= $newname; | |
523 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
524 | last; | |
525 | } | |
526 | } | |
527 | } | |
528 | } | |
529 | ||
530 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
531 | foreach my $key (keys %ccdhash) { | |
532 | if ($ccdhash{$key}[32] eq $oldname) { | |
533 | $ccdhash{$key}[32]=$newname; | |
534 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
535 | last; | |
536 | } | |
537 | } | |
538 | ||
539 | return 0; | |
540 | } | |
541 | sub ccdmaxclients | |
542 | { | |
543 | my $ccdnetwork=$_[0]; | |
544 | my @octets=(); | |
545 | my @subnet=(); | |
546 | @octets=split("\/",$ccdnetwork); | |
547 | @subnet= split /\./, &General::cidrtosub($octets[1]); | |
548 | my ($a,$b,$c,$d,$e); | |
549 | $a=256-$subnet[0]; | |
550 | $b=256-$subnet[1]; | |
551 | $c=256-$subnet[2]; | |
552 | $d=256-$subnet[3]; | |
553 | $e=($a*$b*$c*$d)/4; | |
554 | return $e-1; | |
555 | } | |
556 | ||
557 | sub getccdadresses | |
558 | { | |
559 | my $ipin=$_[0]; | |
560 | my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin; | |
561 | my $cidr=$_[1]; | |
562 | chomp($cidr); | |
563 | my $count=$_[2]; | |
564 | my $hasip=$_[3]; | |
565 | chomp($hasip); | |
566 | my @iprange=(); | |
567 | my %ccdhash=(); | |
568 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
d9fe5693 | 569 | $iprange[0]=$ip1.".".$ip2.".".$ip3.".".($ip4+2); |
ac87f371 | 570 | for (my $i=1;$i<=$count;$i++) { |
8c877a82 AM |
571 | my $tmpip=$iprange[$i-1]; |
572 | my $stepper=$i*4; | |
573 | $iprange[$i]= &General::getnextip($tmpip,4); | |
574 | } | |
575 | my $r=0; | |
576 | foreach my $key (keys %ccdhash) { | |
577 | $r=0; | |
578 | foreach my $tmp (@iprange){ | |
579 | my ($net,$sub) = split (/\//,$ccdhash{$key}[33]); | |
580 | if ($net eq $tmp) { | |
581 | if ( $hasip ne $ccdhash{$key}[33] ){ | |
582 | splice (@iprange,$r,1); | |
583 | } | |
584 | } | |
585 | $r++; | |
586 | } | |
587 | } | |
588 | return @iprange; | |
589 | } | |
590 | ||
591 | sub fillselectbox | |
592 | { | |
593 | my $boxname=$_[1]; | |
594 | my ($ccdip,$subcidr) = split("/",$_[0]); | |
595 | my $tz=$_[2]; | |
596 | my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz); | |
597 | print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >"; | |
598 | foreach (@allccdips) { | |
599 | my $ip=$_."/30"; | |
600 | chomp($ip); | |
601 | print "<option value='$ip' "; | |
602 | if ( $ip eq $cgiparams{$boxname} ){ | |
603 | print"selected"; | |
604 | } | |
605 | print ">$ip</option>"; | |
606 | } | |
607 | print "</select>"; | |
608 | } | |
609 | ||
610 | sub hostsinnet | |
611 | { | |
612 | my $name=$_[0]; | |
613 | my %ccdhash=(); | |
614 | my $i=0; | |
615 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
616 | foreach my $key (keys %ccdhash) { | |
617 | if ($ccdhash{$key}[32] eq $name){ $i++;} | |
618 | } | |
619 | return $i; | |
620 | } | |
621 | ||
622 | sub check_routes_push | |
623 | { | |
624 | my $val=$_[0]; | |
625 | my ($ip,$cidr) = split (/\//, $val); | |
626 | ##check for existing routes in routes_push | |
627 | if (-e "${General::swroot}/ovpn/routes_push") { | |
628 | open(FILE,"${General::swroot}/ovpn/routes_push"); | |
629 | while (<FILE>) { | |
630 | $_=~s/\s*$//g; | |
631 | ||
632 | my ($ip2,$cidr2) = split (/\//,"$_"); | |
633 | my $val2=$ip2."/".&General::iporsubtodec($cidr2); | |
634 | ||
635 | if($val eq $val2){ | |
636 | return 0; | |
637 | } | |
638 | #subnetcheck | |
639 | if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){ | |
640 | return 0; | |
641 | } | |
642 | }; | |
643 | close(FILE); | |
644 | } | |
645 | return 1; | |
646 | } | |
647 | ||
648 | sub check_ccdroute | |
649 | { | |
650 | my %ccdroutehash=(); | |
651 | my $val=$_[0]; | |
652 | my ($ip,$cidr) = split (/\//, $val); | |
653 | #check for existing routes in ccdroute | |
654 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
655 | foreach my $key (keys %ccdroutehash) { | |
656 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
657 | if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){ | |
658 | return 0; | |
659 | } | |
660 | my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]); | |
661 | #subnetcheck | |
662 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){ | |
663 | return 0; | |
664 | } | |
665 | } | |
666 | } | |
667 | return 1; | |
668 | } | |
669 | sub check_ccdconf | |
670 | { | |
671 | my %ccdconfhash=(); | |
672 | my $val=$_[0]; | |
673 | my ($ip,$cidr) = split (/\//, $val); | |
674 | #check for existing routes in ccdroute | |
675 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
676 | foreach my $key (keys %ccdconfhash) { | |
677 | if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){ | |
678 | return 0; | |
679 | } | |
680 | my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]); | |
681 | #subnetcheck | |
682 | if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){ | |
683 | return 0; | |
684 | } | |
685 | ||
686 | } | |
687 | return 1; | |
688 | } | |
689 | ||
7c1d9faf AH |
690 | ### |
691 | # m.a.d net2net | |
692 | ### | |
693 | ||
694 | sub validdotmask | |
695 | { | |
696 | my $ipdotmask = $_[0]; | |
697 | if (&General::validip($ipdotmask)) { return 0; } | |
698 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
699 | my $mask = $2; | |
700 | if (($mask =~ /\./ )) { return 0; } | |
701 | return 1; | |
702 | } | |
54fd0535 MT |
703 | |
704 | # ------------------------------------------------------------------- | |
705 | ||
706 | sub write_routepushfile | |
707 | { | |
708 | open(FILE, ">$routes_push_file"); | |
709 | flock(FILE, 2); | |
710 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
711 | print FILE $vpnsettings{'ROUTES_PUSH'}; | |
712 | } | |
713 | close(FILE); | |
714 | } | |
715 | ||
716 | sub read_routepushfile | |
717 | { | |
718 | if (-e "$routes_push_file") { | |
719 | open(FILE,"$routes_push_file"); | |
720 | delete $vpnsettings{'ROUTES_PUSH'}; | |
721 | while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ }; | |
722 | close(FILE); | |
723 | $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 | 724 | |
54fd0535 MT |
725 | } |
726 | } | |
7c1d9faf | 727 | |
775b4494 AM |
728 | sub writecollectdconf { |
729 | my $vpncollectd; | |
730 | my %ccdhash=(); | |
731 | ||
732 | open(COLLECTDVPN, ">${General::swroot}/ovpn/collectd.vpn") or die "Unable to open collectd.vpn: $!"; | |
733 | print COLLECTDVPN "Loadplugin openvpn\n"; | |
734 | print COLLECTDVPN "\n"; | |
735 | print COLLECTDVPN "<Plugin openvpn>\n"; | |
736 | print COLLECTDVPN "Statusfile \"/var/run/ovpnserver.log\"\n"; | |
737 | ||
738 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
739 | foreach my $key (keys %ccdhash) { | |
740 | if ($ccdhash{$key}[0] eq 'on' && $ccdhash{$key}[3] eq 'net') { | |
741 | print COLLECTDVPN "Statusfile \"/var/run/openvpn/$ccdhash{$key}[1]-n2n\"\n"; | |
742 | } | |
743 | } | |
744 | ||
745 | print COLLECTDVPN "</Plugin>\n"; | |
746 | close(COLLECTDVPN); | |
747 | ||
748 | # Reload collectd afterwards | |
2feacd98 | 749 | &General::system("/usr/local/bin/collectdctrl", "restart"); |
775b4494 | 750 | } |
7c1d9faf | 751 | |
c6c9630e MT |
752 | #hier die refresh page |
753 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
754 | my $refresh = ''; | |
755 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
756 | &Header::showhttpheaders(); | |
757 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
758 | &Header::openbigbox('100%', 'center'); | |
759 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
760 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
761 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
762 | &Header::closebox(); | |
763 | &Header::closebigbox(); | |
764 | &Header::closepage(); | |
765 | exit (0); | |
766 | } | |
767 | ##hier die refresh page | |
768 | ||
6e13d0a5 MT |
769 | |
770 | ### | |
771 | ### OpenVPN Server Control | |
772 | ### | |
773 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
774 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
775 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
776 | #start openvpn server |
777 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 778 | &emptyserverlog(); |
2feacd98 | 779 | &General::system("/usr/local/bin/openvpnctrl", "-s"); |
6e13d0a5 MT |
780 | } |
781 | #stop openvpn server | |
782 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
2feacd98 | 783 | &General::system("/usr/local/bin/openvpnctrl", "-k"); |
c6c9630e | 784 | &emptyserverlog(); |
6e13d0a5 MT |
785 | } |
786 | # #restart openvpn server | |
8c877a82 | 787 | # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ |
6e13d0a5 | 788 | #workarund, till SIGHUP also works when running as nobody |
8c877a82 AM |
789 | # system('/usr/local/bin/openvpnctrl', '-r'); |
790 | # &emptyserverlog(); | |
791 | # } | |
6e13d0a5 MT |
792 | } |
793 | ||
794 | ### | |
795 | ### Save Advanced options | |
796 | ### | |
797 | ||
798 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
799 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
800 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
801 | #DAN this value has to leave. | |
802 | #new settings for daemon | |
803 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
804 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
805 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
806 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
807 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
808 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
6a9d9ff4 | 809 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; |
ffbe77c8 | 810 | $vpnsettings{'ADDITIONAL_CONFIGS'} = $cgiparams{'ADDITIONAL_CONFIGS'}; |
6e13d0a5 MT |
811 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; |
812 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
813 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
54fd0535 MT |
814 | $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'}; |
815 | my @temp=(); | |
6e13d0a5 | 816 | |
a79fa1d6 JPT |
817 | if ($cgiparams{'FRAGMENT'} eq '') { |
818 | delete $vpnsettings{'FRAGMENT'}; | |
819 | } else { | |
820 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
821 | $errormessage = "Incorrect value, please insert only numbers."; | |
822 | goto ADV_ERROR; | |
823 | } else { | |
824 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
825 | } | |
826 | } | |
49abe7af | 827 | |
a79fa1d6 | 828 | if ($cgiparams{'MSSFIX'} ne 'on') { |
1de5c945 | 829 | delete $vpnsettings{'MSSFIX'}; |
a79fa1d6 JPT |
830 | } else { |
831 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
832 | } | |
2ee746be | 833 | |
6e13d0a5 | 834 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
81da1b01 | 835 | unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { |
6e13d0a5 MT |
836 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; |
837 | goto ADV_ERROR; | |
838 | } | |
839 | } | |
840 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
841 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
842 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
843 | goto ADV_ERROR; | |
844 | } | |
845 | } | |
846 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
847 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
848 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
54fd0535 MT |
849 | goto ADV_ERROR; |
850 | } | |
851 | } | |
852 | if ($cgiparams{'ROUTES_PUSH'} ne ''){ | |
853 | @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'}); | |
854 | undef $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 AM |
855 | |
856 | foreach my $tmpip (@temp) | |
54fd0535 MT |
857 | { |
858 | s/^\s+//g; s/\s+$//g; | |
8c877a82 AM |
859 | |
860 | if ($tmpip) | |
54fd0535 | 861 | { |
8c877a82 AM |
862 | $tmpip=~s/\s*$//g; |
863 | unless (&General::validipandmask($tmpip)) { | |
864 | $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'}; | |
865 | goto ADV_ERROR; | |
54fd0535 | 866 | } |
8c877a82 AM |
867 | my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip)); |
868 | ||
54fd0535 MT |
869 | if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) { |
870 | $errormessage = $Lang::tr{'ovpn errmsg green already pushed'}; | |
8c877a82 AM |
871 | goto ADV_ERROR; |
872 | } | |
873 | # a.marx ccd | |
874 | my %ccdroutehash=(); | |
875 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
876 | foreach my $key (keys %ccdroutehash) { | |
877 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
878 | if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){ | |
879 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
880 | goto ADV_ERROR; | |
881 | } | |
882 | my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]); | |
883 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)){ | |
884 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
885 | goto ADV_ERROR; | |
886 | } | |
887 | } | |
54fd0535 | 888 | } |
8c877a82 AM |
889 | |
890 | # ccd end | |
891 | ||
892 | $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n"; | |
54fd0535 | 893 | } |
8c877a82 AM |
894 | } |
895 | &write_routepushfile; | |
54fd0535 | 896 | undef $vpnsettings{'ROUTES_PUSH'}; |
8e148dc3 NP |
897 | } |
898 | else { | |
899 | undef $vpnsettings{'ROUTES_PUSH'}; | |
900 | &write_routepushfile; | |
6e13d0a5 | 901 | } |
ba50f66d | 902 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 1024 )) { |
6e13d0a5 MT |
903 | $errormessage = $Lang::tr{'invalid input for max clients'}; |
904 | goto ADV_ERROR; | |
905 | } | |
906 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
907 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
908 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
909 | goto ADV_ERROR; | |
910 | } | |
911 | } | |
912 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
913 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
914 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
915 | goto ADV_ERROR; | |
916 | } | |
917 | } | |
918 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
919 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
920 | goto ADV_ERROR; | |
921 | } | |
6e13d0a5 | 922 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); |
c6c9630e | 923 | &writeserverconf();#hier ok |
6e13d0a5 MT |
924 | } |
925 | ||
ce9abb66 | 926 | ### |
7c1d9faf | 927 | # m.a.d net2net |
ce9abb66 AH |
928 | ### |
929 | ||
930 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
931 | { | |
c6c9630e | 932 | |
ce9abb66 AH |
933 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
934 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
54fd0535 | 935 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
d96c89eb | 936 | my $tunmtu = ''; |
531f0835 AH |
937 | |
938 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
939 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
940 | |
941 | open(SERVERCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
942 | ||
943 | flock SERVERCONF, 2; | |
7c1d9faf | 944 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
ce9abb66 | 945 | print SERVERCONF "\n"; |
b278daf3 | 946 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
947 | print SERVERCONF "user nobody\n"; |
948 | print SERVERCONF "group nobody\n"; | |
949 | print SERVERCONF "persist-tun\n"; | |
950 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 951 | print SERVERCONF "script-security 2\n"; |
60f396d7 | 952 | print SERVERCONF "# IP/DNS for remote Server Gateway\n"; |
c125d8a2 SS |
953 | |
954 | if ($cgiparams{'REMOTE'} ne '') { | |
ce9abb66 | 955 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
c125d8a2 SS |
956 | } |
957 | ||
b278daf3 | 958 | print SERVERCONF "float\n"; |
60f396d7 | 959 | print SERVERCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 960 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; |
60f396d7 | 961 | print SERVERCONF "# Client Gateway Network\n"; |
54fd0535 | 962 | print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n"; |
2913185a | 963 | print SERVERCONF "up \"/etc/init.d/static-routes start\"\n"; |
60f396d7 | 964 | print SERVERCONF "# tun Device\n"; |
ce9abb66 | 965 | print SERVERCONF "dev tun\n"; |
5795fc1b AM |
966 | print SERVERCONF "#Logfile for statistics\n"; |
967 | print SERVERCONF "status-version 1\n"; | |
87fe47e9 | 968 | print SERVERCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; |
60f396d7 | 969 | print SERVERCONF "# Port and Protokol\n"; |
ce9abb66 | 970 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; |
5795fc1b | 971 | |
60f396d7 AH |
972 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { |
973 | print SERVERCONF "proto tcp-server\n"; | |
974 | print SERVERCONF "# Packet size\n"; | |
d96c89eb | 975 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 976 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 977 | } |
60f396d7 AH |
978 | |
979 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
980 | print SERVERCONF "proto udp\n"; | |
981 | print SERVERCONF "# Paketsize\n"; | |
982 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
983 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 984 | if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
d6989b4b | 985 | if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; } else { print SERVERCONF "mssfix 0\n" }; |
d96c89eb | 986 | } |
1647059d | 987 | |
60f396d7 | 988 | print SERVERCONF "# Auth. Server\n"; |
ce9abb66 AH |
989 | print SERVERCONF "tls-server\n"; |
990 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
991 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
992 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 993 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
b278daf3 | 994 | print SERVERCONF "# Cipher\n"; |
4c962356 | 995 | print SERVERCONF "cipher $cgiparams{'DCIPHER'}\n"; |
52f61e49 EKD |
996 | |
997 | # If GCM cipher is used, do not use --auth | |
998 | if (($cgiparams{'DCIPHER'} eq 'AES-256-GCM') || | |
999 | ($cgiparams{'DCIPHER'} eq 'AES-192-GCM') || | |
1000 | ($cgiparams{'DCIPHER'} eq 'AES-128-GCM')) { | |
1001 | print SERVERCONF unless "# HMAC algorithm\n"; | |
1002 | print SERVERCONF unless "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1003 | } else { |
52f61e49 EKD |
1004 | print SERVERCONF "# HMAC algorithm\n"; |
1005 | print SERVERCONF "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1006 | } |
52f61e49 | 1007 | |
942446b5 EK |
1008 | # Set TLSv1.2 as minimum |
1009 | print SERVERCONF "tls-version-min 1.2\n"; | |
1010 | ||
ce9abb66 | 1011 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1012 | print SERVERCONF "# Enable Compression\n"; |
66298ef2 | 1013 | print SERVERCONF "comp-lzo\n"; |
b278daf3 | 1014 | } |
60f396d7 | 1015 | print SERVERCONF "# Debug Level\n"; |
ce9abb66 | 1016 | print SERVERCONF "verb 3\n"; |
b278daf3 | 1017 | print SERVERCONF "# Tunnel check\n"; |
ce9abb66 | 1018 | print SERVERCONF "keepalive 10 60\n"; |
60f396d7 | 1019 | print SERVERCONF "# Start as daemon\n"; |
ce9abb66 AH |
1020 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; |
1021 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 1022 | print SERVERCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
1023 | if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1024 | else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 AH |
1025 | close(SERVERCONF); |
1026 | ||
1027 | } | |
1028 | ||
1029 | ### | |
7c1d9faf | 1030 | # m.a.d net2net |
ce9abb66 | 1031 | ### |
7c1d9faf | 1032 | |
ce9abb66 AH |
1033 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
1034 | { | |
4c962356 | 1035 | |
ce9abb66 | 1036 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); |
54fd0535 | 1037 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 1038 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
d96c89eb | 1039 | my $tunmtu = ''; |
54fd0535 | 1040 | |
531f0835 AH |
1041 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
1042 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
1043 | |
1044 | open(CLIENTCONF, ">${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Unable to open ${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf: $!"; | |
1045 | ||
1046 | flock CLIENTCONF, 2; | |
7c1d9faf | 1047 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 1048 | print CLIENTCONF "#\n"; |
b278daf3 | 1049 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
1050 | print CLIENTCONF "user nobody\n"; |
1051 | print CLIENTCONF "group nobody\n"; | |
1052 | print CLIENTCONF "persist-tun\n"; | |
1053 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 1054 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 1055 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
ce9abb66 | 1056 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 | 1057 | print CLIENTCONF "float\n"; |
60f396d7 | 1058 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 1059 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
60f396d7 | 1060 | print CLIENTCONF "# Server Gateway Network\n"; |
54fd0535 | 1061 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
ebcecb4b | 1062 | print CLIENTCONF "up \"/etc/init.d/static-routes start\"\n"; |
60f396d7 | 1063 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 1064 | print CLIENTCONF "dev tun\n"; |
35a21a25 AM |
1065 | print CLIENTCONF "#Logfile for statistics\n"; |
1066 | print CLIENTCONF "status-version 1\n"; | |
1067 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
60f396d7 | 1068 | print CLIENTCONF "# Port and Protokol\n"; |
ce9abb66 | 1069 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; |
60f396d7 AH |
1070 | |
1071 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
1072 | print CLIENTCONF "proto tcp-client\n"; | |
1073 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 1074 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 1075 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 1076 | } |
60f396d7 AH |
1077 | |
1078 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
1079 | print CLIENTCONF "proto udp\n"; | |
1080 | print CLIENTCONF "# Paketsize\n"; | |
1081 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1082 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 1083 | if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
d6989b4b | 1084 | if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; } else { print CLIENTCONF "mssfix 0\n" }; |
d96c89eb | 1085 | } |
1647059d | 1086 | |
b66b02ab EK |
1087 | # Check host certificate if X509 is RFC3280 compliant. |
1088 | # If not, old --ns-cert-type directive will be used. | |
1089 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2feacd98 SS |
1090 | my @hostcert = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
1091 | if ( ! grep(/TLS Web Server Authentication/, @hostcert)) { | |
b66b02ab EK |
1092 | print CLIENTCONF "ns-cert-type server\n"; |
1093 | } else { | |
1094 | print CLIENTCONF "remote-cert-tls server\n"; | |
1095 | } | |
ce9abb66 AH |
1096 | print CLIENTCONF "# Auth. Client\n"; |
1097 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 1098 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 1099 | print CLIENTCONF "cipher $cgiparams{'DCIPHER'}\n"; |
ce9abb66 | 1100 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; |
52f61e49 EKD |
1101 | |
1102 | # If GCM cipher is used, do not use --auth | |
1103 | if (($cgiparams{'DCIPHER'} eq 'AES-256-GCM') || | |
1104 | ($cgiparams{'DCIPHER'} eq 'AES-192-GCM') || | |
1105 | ($cgiparams{'DCIPHER'} eq 'AES-128-GCM')) { | |
1106 | print CLIENTCONF unless "# HMAC algorithm\n"; | |
1107 | print CLIENTCONF unless "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1108 | } else { |
52f61e49 EKD |
1109 | print CLIENTCONF "# HMAC algorithm\n"; |
1110 | print CLIENTCONF "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1111 | } |
52f61e49 | 1112 | |
942446b5 EK |
1113 | # Set TLSv1.2 as minimum |
1114 | print CLIENTCONF "tls-version-min 1.2\n"; | |
1115 | ||
ce9abb66 | 1116 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1117 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 1118 | print CLIENTCONF "comp-lzo\n"; |
4c962356 | 1119 | } |
ce9abb66 AH |
1120 | print CLIENTCONF "# Debug Level\n"; |
1121 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 1122 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 1123 | print CLIENTCONF "keepalive 10 60\n"; |
60f396d7 | 1124 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
1125 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
1126 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 1127 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
1128 | if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1129 | else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 | 1130 | close(CLIENTCONF); |
c6c9630e | 1131 | |
ce9abb66 | 1132 | } |
400c8afd | 1133 | |
6e13d0a5 MT |
1134 | ### |
1135 | ### Save main settings | |
1136 | ### | |
ce9abb66 | 1137 | |
6e13d0a5 MT |
1138 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
1139 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
1140 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
1141 | #DAN this value has to leave. | |
1142 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1143 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
1144 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 1145 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1146 | } |
1147 | } | |
f7fb5bc5 | 1148 | |
6e13d0a5 | 1149 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { |
c6c9630e | 1150 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
4c962356 | 1151 | goto SETTINGS_ERROR; |
c6c9630e MT |
1152 | } |
1153 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
1154 | ||
1155 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
1156 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1157 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
1158 | goto SETTINGS_ERROR; | |
1159 | } | |
1160 | ||
1161 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
1162 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1163 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
1164 | goto SETTINGS_ERROR; | |
1165 | } | |
1166 | ||
1167 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
1168 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1169 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
1170 | goto SETTINGS_ERROR; | |
1171 | } | |
1172 | ||
1173 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
1174 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1175 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
1176 | goto SETTINGS_ERROR; | |
1177 | } | |
1178 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
1179 | while (<ALIASES>) | |
1180 | { | |
1181 | chomp($_); | |
1182 | my @tempalias = split(/\,/,$_); | |
1183 | if ($tempalias[1] eq 'on') { | |
1184 | if (&General::IpInSubnet ($tempalias[0] , | |
1185 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1186 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
1187 | } | |
1188 | } | |
1189 | } | |
1190 | close(ALIASES); | |
6e13d0a5 | 1191 | if ($errormessage ne ''){ |
c6c9630e | 1192 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1193 | } |
1194 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
1195 | $errormessage = $Lang::tr{'invalid input'}; | |
1196 | goto SETTINGS_ERROR; | |
1197 | } | |
1198 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
1199 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
1200 | goto SETTINGS_ERROR; | |
1201 | } | |
1202 | ||
1203 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
c6c9630e MT |
1204 | $errormessage = $Lang::tr{'invalid port'}; |
1205 | goto SETTINGS_ERROR; | |
6e13d0a5 | 1206 | } |
8c252e6a | 1207 | |
b21a6319 EK |
1208 | # Create ta.key for tls-auth if not presant |
1209 | if ($cgiparams{'TLSAUTH'} eq 'on') { | |
1210 | if ( ! -e "${General::swroot}/ovpn/certs/ta.key") { | |
2feacd98 SS |
1211 | # This system call is safe, because all arguements are passed as an array. |
1212 | system("/usr/sbin/openvpn", "--genkey", "--secret", "${General::swroot}/ovpn/certs/ta.key"); | |
b21a6319 EK |
1213 | if ($?) { |
1214 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1215 | goto SETTINGS_ERROR; | |
1216 | } | |
1217 | } | |
1218 | } | |
1219 | ||
6e13d0a5 MT |
1220 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
1221 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
1222 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
1223 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
1224 | #new settings for daemon | |
1225 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
6e13d0a5 MT |
1226 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; |
1227 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
1228 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
1229 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
1230 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
86308adb | 1231 | $vpnsettings{'DAUTH'} = $cgiparams{'DAUTH'}; |
0c4ffc69 | 1232 | $vpnsettings{'TLSAUTH'} = $cgiparams{'TLSAUTH'}; |
3ffee04b CS |
1233 | #wrtie enable |
1234 | ||
2feacd98 SS |
1235 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' ) { |
1236 | &General::system("touch", "${General::swroot}/ovpn/enable_blue"); | |
1237 | } else { | |
274ca65b | 1238 | unlink("${General::swroot}/ovpn/enable_blue"); |
2feacd98 SS |
1239 | } |
1240 | ||
1241 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' ) { | |
1242 | &General::system("touch", "${General::swroot}/ovpn/enable_orange"); | |
1243 | } else { | |
1244 | unlink("${General::swroot}/ovpn/enable_orange"); | |
1245 | } | |
1246 | ||
1247 | if ( $vpnsettings{'ENABLED'} eq 'on' ) { | |
1248 | &General::system("touch", "${General::swroot}/ovpn/enable"); | |
1249 | } else { | |
1250 | unlink("${General::swroot}/ovpn/enable"); | |
1251 | } | |
1252 | ||
6e13d0a5 MT |
1253 | #new settings for daemon |
1254 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 1255 | &writeserverconf();#hier ok |
6e13d0a5 MT |
1256 | SETTINGS_ERROR: |
1257 | ### | |
1258 | ### Reset all step 2 | |
1259 | ### | |
4c962356 | 1260 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') { |
6e13d0a5 MT |
1261 | my $file = ''; |
1262 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1263 | ||
1e499e90 | 1264 | # Kill all N2N connections |
2feacd98 | 1265 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n"); |
1e499e90 | 1266 | |
6e13d0a5 | 1267 | foreach my $key (keys %confighash) { |
2f36a7b4 MT |
1268 | my $name = $confighash{$cgiparams{'$key'}}[1]; |
1269 | ||
c6c9630e MT |
1270 | if ($confighash{$key}[4] eq 'cert') { |
1271 | delete $confighash{$cgiparams{'$key'}}; | |
1272 | } | |
2f36a7b4 | 1273 | |
2feacd98 | 1274 | &General::system("/usr/local/bin/openvpnctrl", "-drrd", "$name"); |
6e13d0a5 MT |
1275 | } |
1276 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
49abe7af | 1277 | unlink $file; |
6e13d0a5 MT |
1278 | } |
1279 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
49abe7af | 1280 | unlink $file; |
6e13d0a5 MT |
1281 | } |
1282 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
49abe7af | 1283 | unlink $file; |
6e13d0a5 | 1284 | } |
4c962356 | 1285 | &cleanssldatabase(); |
6e13d0a5 MT |
1286 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
1287 | print FILE ""; | |
1288 | close FILE; | |
1289 | } | |
49abe7af EK |
1290 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute")) { |
1291 | print FILE ""; | |
1292 | close FILE; | |
1293 | } | |
1294 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute2")) { | |
1295 | print FILE ""; | |
1296 | close FILE; | |
1297 | } | |
1298 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { | |
1299 | unlink $file | |
1300 | } | |
5795fc1b AM |
1301 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { |
1302 | unlink $file | |
1303 | } | |
49abe7af EK |
1304 | if (open(FILE, ">${General::swroot}/ovpn/ovpn-leases.db")) { |
1305 | print FILE ""; | |
1306 | close FILE; | |
1307 | } | |
1308 | if (open(FILE, ">${General::swroot}/ovpn/ovpnconfig")) { | |
1309 | print FILE ""; | |
1310 | close FILE; | |
1311 | } | |
1312 | while ($file = glob("${General::swroot}/ovpn/n2nconf/*")) { | |
2feacd98 | 1313 | unlink($file); |
49abe7af EK |
1314 | } |
1315 | ||
2f36a7b4 MT |
1316 | # Remove everything from the collectd configuration |
1317 | &writecollectdconf(); | |
1318 | ||
c6c9630e | 1319 | #&writeserverconf(); |
6e13d0a5 MT |
1320 | ### |
1321 | ### Reset all step 1 | |
1322 | ### | |
4c962356 | 1323 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) { |
6e13d0a5 | 1324 | &Header::showhttpheaders(); |
4c962356 EK |
1325 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
1326 | &Header::openbigbox('100%', 'left', '', ''); | |
1327 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
1328 | print <<END; | |
1329 | <form method='post'> | |
1330 | <table width='100%'> | |
1331 | <tr> | |
1332 | <td align='center'> | |
1333 | <input type='hidden' name='AREUSURE' value='yes' /> | |
49abe7af | 1334 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: |
4c962356 EK |
1335 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td> |
1336 | </tr> | |
1337 | <tr> | |
1338 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /> | |
1339 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> | |
1340 | </tr> | |
1341 | </table> | |
1342 | </form> | |
6e13d0a5 MT |
1343 | END |
1344 | ; | |
1345 | &Header::closebox(); | |
1346 | &Header::closebigbox(); | |
1347 | &Header::closepage(); | |
1348 | exit (0); | |
1349 | ||
4c962356 EK |
1350 | ### |
1351 | ### Generate DH key step 2 | |
1352 | ### | |
1353 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
49abe7af | 1354 | # Delete if old key exists |
4c962356 EK |
1355 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { |
1356 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1357 | } | |
1358 | # Create Diffie Hellmann Parameter | |
2feacd98 SS |
1359 | # The system call is safe, because all arguments are passed as an array. |
1360 | system("/usr/bin/openssl", "dhparam", "-out", "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); | |
4c962356 EK |
1361 | if ($?) { |
1362 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1363 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
1364 | } | |
1365 | ||
1366 | ### | |
1367 | ### Generate DH key step 1 | |
1368 | ### | |
1369 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'}) { | |
1370 | &Header::showhttpheaders(); | |
1371 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
1372 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1373 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'gen dh'}:"); | |
1374 | print <<END; | |
1375 | <table width='100%'> | |
1376 | <tr> | |
f527e53f | 1377 | <td width='20%'> </td> <td width='15%'></td> <td width='65%'></td> |
49abe7af | 1378 | </tr> |
4c962356 EK |
1379 | <tr> |
1380 | <td class='base'>$Lang::tr{'ovpn dh'}:</td> | |
1381 | <td align='center'> | |
1382 | <form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
1383 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1384 | <select name='DHLENGHT'> | |
4c962356 EK |
1385 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> |
1386 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
1387 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
1388 | </select> | |
1389 | </td> | |
1390 | </tr> | |
1391 | <tr><td colspan='4'><br></td></tr> | |
1392 | </table> | |
1393 | <table width='100%'> | |
1394 | <tr> | |
49abe7af | 1395 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'dh key warn'} |
4c962356 | 1396 | </tr> |
49abe7af EK |
1397 | <tr> |
1398 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
1399 | </tr> | |
1400 | <tr><td colspan='2'><br></td></tr> | |
4c962356 EK |
1401 | <tr> |
1402 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
1403 | </form> | |
1404 | </tr> | |
1405 | </table> | |
1406 | ||
1407 | END | |
1408 | ; | |
1409 | &Header::closebox(); | |
1410 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1411 | &Header::closebigbox(); | |
1412 | &Header::closepage(); | |
1413 | exit (0); | |
1414 | ||
1415 | ### | |
1416 | ### Upload DH key | |
1417 | ### | |
1418 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload dh key'}) { | |
2ad1b18b | 1419 | unless (ref ($cgiparams{'FH'})) { |
4c962356 EK |
1420 | $errormessage = $Lang::tr{'there was no file upload'}; |
1421 | goto UPLOADCA_ERROR; | |
1422 | } | |
49abe7af | 1423 | # Move uploaded dh key to a temporary file |
4c962356 EK |
1424 | (my $fh, my $filename) = tempfile( ); |
1425 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1426 | $errormessage = $!; | |
49abe7af | 1427 | goto UPLOADCA_ERROR; |
4c962356 | 1428 | } |
2feacd98 SS |
1429 | my @temp = &General::system_output("/usr/bin/openssl", "dhparam", "-text", "-in", "$filename"); |
1430 | if ( ! grep(/DH Parameters: \((2048|3072|4096) bit\)/, @temp)) { | |
4c962356 EK |
1431 | $errormessage = $Lang::tr{'not a valid dh key'}; |
1432 | unlink ($filename); | |
1433 | goto UPLOADCA_ERROR; | |
1434 | } else { | |
1435 | # Delete if old key exists | |
1436 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { | |
1437 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1438 | } | |
1439 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"); | |
49abe7af EK |
1440 | if ($? ne 0) { |
1441 | $errormessage = "$Lang::tr{'dh key move failed'}: $!"; | |
1442 | unlink ($filename); | |
1443 | goto UPLOADCA_ERROR; | |
1444 | } | |
4c962356 EK |
1445 | } |
1446 | ||
6e13d0a5 MT |
1447 | ### |
1448 | ### Upload CA Certificate | |
1449 | ### | |
1450 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
1451 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1452 | ||
1453 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
1454 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1455 | goto UPLOADCA_ERROR; | |
1456 | } | |
1457 | ||
1458 | if (length($cgiparams{'CA_NAME'}) >60) { | |
1459 | $errormessage = $Lang::tr{'name too long'}; | |
1460 | goto VPNCONF_ERROR; | |
1461 | } | |
1462 | ||
1463 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
1464 | $errormessage = $Lang::tr{'name is invalid'}; | |
4c962356 | 1465 | goto UPLOADCA_ERROR; |
6e13d0a5 MT |
1466 | } |
1467 | ||
1468 | # Check if there is no other entry with this name | |
1469 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
1470 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
1471 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
1472 | goto UPLOADCA_ERROR; | |
1473 | } | |
6e13d0a5 MT |
1474 | } |
1475 | ||
2ad1b18b | 1476 | unless (ref ($cgiparams{'FH'})) { |
c6c9630e MT |
1477 | $errormessage = $Lang::tr{'there was no file upload'}; |
1478 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1479 | } |
1480 | # Move uploaded ca to a temporary file | |
1481 | (my $fh, my $filename) = tempfile( ); | |
1482 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
1483 | $errormessage = $!; |
1484 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1485 | } |
2feacd98 SS |
1486 | my @temp = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "$filename"); |
1487 | if ( ! grep(/CA:TRUE/i, @temp )) { | |
c6c9630e MT |
1488 | $errormessage = $Lang::tr{'not a valid ca certificate'}; |
1489 | unlink ($filename); | |
1490 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1491 | } else { |
c6c9630e MT |
1492 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
1493 | if ($? ne 0) { | |
1494 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1495 | unlink ($filename); | |
1496 | goto UPLOADCA_ERROR; | |
1497 | } | |
6e13d0a5 MT |
1498 | } |
1499 | ||
274ca65b | 1500 | my @casubject = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
2feacd98 SS |
1501 | my $casubject; |
1502 | ||
1503 | foreach my $line (@casubject) { | |
1504 | if ($line =~ /Subject: (.*)[\n]/) { | |
1505 | $casubject = $1; | |
1506 | $casubject =~ s+/Email+, E+; | |
1507 | $casubject =~ s/ ST=/ S=/; | |
1508 | ||
1509 | last; | |
1510 | } | |
1511 | } | |
1512 | ||
6e13d0a5 MT |
1513 | $casubject = &Header::cleanhtml($casubject); |
1514 | ||
1515 | my $key = &General::findhasharraykey (\%cahash); | |
1516 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
1517 | $cahash{$key}[1] = $casubject; | |
1518 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
1519 | # system('/usr/local/bin/ipsecctrl', 'R'); |
1520 | ||
6e13d0a5 MT |
1521 | UPLOADCA_ERROR: |
1522 | ||
1523 | ### | |
1524 | ### Display ca certificate | |
1525 | ### | |
1526 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
1527 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
1528 | ||
1529 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
1530 | &Header::showhttpheaders(); | |
4c962356 | 1531 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1532 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1533 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
2feacd98 | 1534 | my @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); |
8c946d1c MT |
1535 | my $output = &Header::cleanhtml(join("", @output),"y"); |
1536 | print "<pre>$output</pre>\n"; | |
c6c9630e MT |
1537 | &Header::closebox(); |
1538 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1539 | &Header::closebigbox(); | |
1540 | &Header::closepage(); | |
1541 | exit(0); | |
1542 | } else { | |
1543 | $errormessage = $Lang::tr{'invalid key'}; | |
1544 | } | |
1545 | ||
6e13d0a5 MT |
1546 | ### |
1547 | ### Download ca certificate | |
1548 | ### | |
1549 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
1550 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1551 | ||
1552 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1553 | print "Content-Type: application/octet-stream\r\n"; | |
1554 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
2feacd98 SS |
1555 | |
1556 | my @tmp = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1557 | print "@tmp"; | |
1558 | ||
6e13d0a5 MT |
1559 | exit(0); |
1560 | } else { | |
1561 | $errormessage = $Lang::tr{'invalid key'}; | |
1562 | } | |
1563 | ||
1564 | ### | |
1565 | ### Remove ca certificate (step 2) | |
1566 | ### | |
1567 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1568 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1569 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1570 | ||
1571 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1572 | foreach my $key (keys %confighash) { | |
2feacd98 SS |
1573 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem", "${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem"); |
1574 | if (grep(/: OK/, @test)) { | |
c6c9630e MT |
1575 | # Delete connection |
1576 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1577 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1578 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
1579 | # } | |
6e13d0a5 MT |
1580 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
1581 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
1582 | delete $confighash{$key}; | |
1583 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 1584 | # &writeipsecfiles(); |
6e13d0a5 MT |
1585 | } |
1586 | } | |
1587 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1588 | delete $cahash{$cgiparams{'KEY'}}; | |
1589 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 1590 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
1591 | } else { |
1592 | $errormessage = $Lang::tr{'invalid key'}; | |
1593 | } | |
1594 | ### | |
1595 | ### Remove ca certificate (step 1) | |
1596 | ### | |
1597 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
1598 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1599 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1600 | ||
1601 | my $assignedcerts = 0; | |
1602 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1603 | foreach my $key (keys %confighash) { | |
2feacd98 SS |
1604 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem", "${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem"); |
1605 | if (grep(/: OK/, @test)) { | |
6e13d0a5 MT |
1606 | $assignedcerts++; |
1607 | } | |
1608 | } | |
1609 | if ($assignedcerts) { | |
1610 | &Header::showhttpheaders(); | |
4c962356 | 1611 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1612 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1613 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
4c962356 | 1614 | print <<END; |
6e13d0a5 MT |
1615 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> |
1616 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1617 | <tr><td align='center'> | |
1618 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1619 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1620 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1621 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1622 | </form></table> | |
1623 | END | |
1624 | ; | |
1625 | &Header::closebox(); | |
1626 | &Header::closebigbox(); | |
1627 | &Header::closepage(); | |
1628 | exit (0); | |
1629 | } else { | |
1630 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1631 | delete $cahash{$cgiparams{'KEY'}}; | |
1632 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1633 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1634 | } | |
1635 | } else { | |
1636 | $errormessage = $Lang::tr{'invalid key'}; | |
1637 | } | |
1638 | ||
1639 | ### | |
1640 | ### Display root certificate | |
1641 | ### | |
c6c9630e MT |
1642 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1643 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
2feacd98 | 1644 | my @output; |
c6c9630e | 1645 | &Header::showhttpheaders(); |
4c962356 | 1646 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1647 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1648 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1649 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
2feacd98 | 1650 | @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/cacert.pem"); |
c6c9630e MT |
1651 | } else { |
1652 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
2feacd98 | 1653 | @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
c6c9630e | 1654 | } |
8c946d1c MT |
1655 | my $output = &Header::cleanhtml(join("", @output), "y"); |
1656 | print "<pre>$output</pre>\n"; | |
c6c9630e MT |
1657 | &Header::closebox(); |
1658 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1659 | &Header::closebigbox(); | |
1660 | &Header::closepage(); | |
1661 | exit(0); | |
1662 | ||
6e13d0a5 MT |
1663 | ### |
1664 | ### Download root certificate | |
1665 | ### | |
1666 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1667 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1668 | print "Content-Type: application/octet-stream\r\n"; | |
1669 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
2feacd98 SS |
1670 | |
1671 | my @tmp = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1672 | print "@tmp"; | |
1673 | ||
6e13d0a5 MT |
1674 | exit(0); |
1675 | } | |
1676 | ||
1677 | ### | |
1678 | ### Download host certificate | |
1679 | ### | |
1680 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1681 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1682 | print "Content-Type: application/octet-stream\r\n"; | |
1683 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
2feacd98 SS |
1684 | |
1685 | my @tmp = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1686 | print "@tmp"; | |
1687 | ||
6e13d0a5 MT |
1688 | exit(0); |
1689 | } | |
f7fb5bc5 | 1690 | |
fd5ccb2d EK |
1691 | ### |
1692 | ### Download tls-auth key | |
1693 | ### | |
1694 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download tls-auth key'}) { | |
1695 | if ( -f "${General::swroot}/ovpn/certs/ta.key" ) { | |
1696 | print "Content-Type: application/octet-stream\r\n"; | |
1697 | print "Content-Disposition: filename=ta.key\r\n\r\n"; | |
2feacd98 SS |
1698 | |
1699 | open(FILE, "${General::swroot}/ovpn/certs/ta.key"); | |
1700 | my @tmp = <FILE>; | |
1701 | close(FILE); | |
1702 | ||
1703 | print "@tmp"; | |
1704 | ||
fd5ccb2d EK |
1705 | exit(0); |
1706 | } | |
1707 | ||
6e13d0a5 MT |
1708 | ### |
1709 | ### Form for generating a root certificate | |
1710 | ### | |
1711 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1712 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1713 | ||
1714 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1715 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1716 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1717 | $cgiparams{'ACTION'} = ''; | |
1718 | goto ROOTCERT_ERROR; | |
1719 | } | |
1720 | ||
1721 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1722 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1723 | my $ipaddr = <IPADDR>; | |
1724 | close IPADDR; | |
1725 | chomp ($ipaddr); | |
1726 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1727 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1728 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1729 | } | |
1730 | } | |
1731 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
2ad1b18b | 1732 | unless (ref ($cgiparams{'FH'})) { |
6e13d0a5 MT |
1733 | $errormessage = $Lang::tr{'there was no file upload'}; |
1734 | goto ROOTCERT_ERROR; | |
1735 | } | |
1736 | ||
1737 | # Move uploaded certificate request to a temporary file | |
1738 | (my $fh, my $filename) = tempfile( ); | |
1739 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1740 | $errormessage = $!; | |
1741 | goto ROOTCERT_ERROR; | |
1742 | } | |
1743 | ||
1744 | # Create a temporary dirctory | |
1745 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1746 | ||
1747 | # Extract the CA certificate from the file | |
1748 | my $pid = open(OPENSSL, "|-"); | |
1749 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1750 | if ($pid) { # parent | |
1751 | if ($cgiparams{'P12_PASS'} ne '') { | |
1752 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1753 | } | |
1754 | close (OPENSSL); | |
1755 | if ($?) { | |
1756 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1757 | unlink ($filename); | |
1758 | goto ROOTCERT_ERROR; | |
1759 | } | |
1760 | } else { # child | |
1761 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1762 | '-in', $filename, | |
1763 | '-out', "$tempdir/cacert.pem")) { | |
1764 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1765 | unlink ($filename); | |
1766 | goto ROOTCERT_ERROR; | |
1767 | } | |
1768 | } | |
1769 | ||
1770 | # Extract the Host certificate from the file | |
1771 | $pid = open(OPENSSL, "|-"); | |
1772 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1773 | if ($pid) { # parent | |
1774 | if ($cgiparams{'P12_PASS'} ne '') { | |
1775 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1776 | } | |
1777 | close (OPENSSL); | |
1778 | if ($?) { | |
1779 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1780 | unlink ($filename); | |
1781 | goto ROOTCERT_ERROR; | |
1782 | } | |
1783 | } else { # child | |
1784 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1785 | '-in', $filename, | |
1786 | '-out', "$tempdir/hostcert.pem")) { | |
1787 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1788 | unlink ($filename); | |
1789 | goto ROOTCERT_ERROR; | |
1790 | } | |
1791 | } | |
1792 | ||
1793 | # Extract the Host key from the file | |
1794 | $pid = open(OPENSSL, "|-"); | |
1795 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1796 | if ($pid) { # parent | |
1797 | if ($cgiparams{'P12_PASS'} ne '') { | |
1798 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1799 | } | |
1800 | close (OPENSSL); | |
1801 | if ($?) { | |
1802 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1803 | unlink ($filename); | |
1804 | goto ROOTCERT_ERROR; | |
1805 | } | |
1806 | } else { # child | |
1807 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1808 | '-nodes', | |
1809 | '-in', $filename, | |
1810 | '-out', "$tempdir/serverkey.pem")) { | |
1811 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1812 | unlink ($filename); | |
1813 | goto ROOTCERT_ERROR; | |
1814 | } | |
1815 | } | |
1816 | ||
1817 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1818 | if ($? ne 0) { | |
1819 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1820 | unlink ($filename); | |
1821 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1822 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1823 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1824 | goto ROOTCERT_ERROR; | |
1825 | } | |
1826 | ||
1827 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1828 | if ($? ne 0) { | |
1829 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1830 | unlink ($filename); | |
1831 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1832 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1833 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1834 | goto ROOTCERT_ERROR; | |
1835 | } | |
1836 | ||
1837 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1838 | if ($? ne 0) { | |
1839 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1840 | unlink ($filename); | |
1841 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1842 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1843 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1844 | goto ROOTCERT_ERROR; | |
1845 | } | |
1846 | ||
1847 | goto ROOTCERT_SUCCESS; | |
1848 | ||
1849 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1850 | ||
1851 | # Validate input since the form was submitted | |
1852 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1853 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1854 | goto ROOTCERT_ERROR; | |
1855 | } | |
1856 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1857 | $errormessage = $Lang::tr{'organization too long'}; | |
1858 | goto ROOTCERT_ERROR; | |
1859 | } | |
1860 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1861 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1862 | goto ROOTCERT_ERROR; | |
1863 | } | |
1864 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1865 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1866 | goto ROOTCERT_ERROR; | |
1867 | } | |
1868 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1869 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1870 | goto ROOTCERT_ERROR; | |
1871 | } | |
1872 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1873 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1874 | goto ROOTCERT_ERROR; | |
1875 | } | |
1876 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1877 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1878 | goto ROOTCERT_ERROR; | |
1879 | } | |
1880 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1881 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1882 | goto ROOTCERT_ERROR; | |
1883 | } | |
1884 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1885 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1886 | goto ROOTCERT_ERROR; | |
1887 | } | |
1888 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1889 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1890 | goto ROOTCERT_ERROR; | |
1891 | } | |
1892 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1893 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1894 | goto ROOTCERT_ERROR; | |
1895 | } | |
1896 | ||
1897 | # Copy the cgisettings to vpnsettings and save the configfile | |
1898 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1899 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1900 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1901 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1902 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1903 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1904 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1905 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1906 | ||
1907 | # Replace empty strings with a . | |
1908 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1909 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1910 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1911 | ||
1912 | # refresh | |
c6c9630e | 1913 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
6e13d0a5 MT |
1914 | |
1915 | # Create the CA certificate | |
1916 | my $pid = open(OPENSSL, "|-"); | |
1917 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1918 | if ($pid) { # parent | |
1919 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1920 | print OPENSSL "$state\n"; | |
1921 | print OPENSSL "$city\n"; | |
1922 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1923 | print OPENSSL "$ou\n"; | |
1924 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1925 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1926 | close (OPENSSL); | |
1927 | if ($?) { | |
1928 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1929 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1930 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1931 | goto ROOTCERT_ERROR; | |
1932 | } | |
1933 | } else { # child | |
badd8c1c | 1934 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', |
49abe7af | 1935 | '-days', '999999', '-newkey', 'rsa:4096', '-sha512', |
6e13d0a5 MT |
1936 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", |
1937 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1938 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1939 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1940 | goto ROOTCERT_ERROR; | |
1941 | } | |
1942 | } | |
1943 | ||
1944 | # Create the Host certificate request | |
1945 | $pid = open(OPENSSL, "|-"); | |
1946 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1947 | if ($pid) { # parent | |
1948 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1949 | print OPENSSL "$state\n"; | |
1950 | print OPENSSL "$city\n"; | |
1951 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1952 | print OPENSSL "$ou\n"; | |
1953 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1954 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1955 | print OPENSSL ".\n"; | |
1956 | print OPENSSL ".\n"; | |
1957 | close (OPENSSL); | |
1958 | if ($?) { | |
1959 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1960 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1961 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1962 | goto ROOTCERT_ERROR; | |
1963 | } | |
1964 | } else { # child | |
badd8c1c | 1965 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 1966 | '-newkey', 'rsa:2048', |
6e13d0a5 MT |
1967 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", |
1968 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1969 | '-extensions', 'server', | |
1970 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1971 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1972 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1973 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1974 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1975 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1976 | goto ROOTCERT_ERROR; | |
1977 | } | |
1978 | } | |
1979 | ||
1980 | # Sign the host certificate request | |
2feacd98 | 1981 | # This system call is safe, because all argeuments are passed as an array. |
6e13d0a5 MT |
1982 | system('/usr/bin/openssl', 'ca', '-days', '999999', |
1983 | '-batch', '-notext', | |
1984 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1985 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1986 | '-extensions', 'server', | |
1987 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1988 | if ($?) { | |
1989 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1990 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1991 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1992 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1993 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1994 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1995 | &newcleanssldatabase(); |
6e13d0a5 MT |
1996 | goto ROOTCERT_ERROR; |
1997 | } else { | |
1998 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1999 | &deletebackupcert(); |
6e13d0a5 MT |
2000 | } |
2001 | ||
2002 | # Create an empty CRL | |
2feacd98 | 2003 | # System call is safe, because all arguments are passed as array. |
6e13d0a5 MT |
2004 | system('/usr/bin/openssl', 'ca', '-gencrl', |
2005 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
2006 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
2007 | if ($?) { | |
2008 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2009 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
2010 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
2011 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
2012 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
c6c9630e | 2013 | &cleanssldatabase(); |
6e13d0a5 | 2014 | goto ROOTCERT_ERROR; |
c6c9630e MT |
2015 | # } else { |
2016 | # &cleanssldatabase(); | |
6e13d0a5 | 2017 | } |
ae04d0a3 | 2018 | # Create ta.key for tls-auth |
2feacd98 | 2019 | # This system call is safe, because all arguments are passed as an array. |
ae04d0a3 EK |
2020 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/certs/ta.key"); |
2021 | if ($?) { | |
2022 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2023 | &cleanssldatabase(); | |
2024 | goto ROOTCERT_ERROR; | |
2025 | } | |
6e13d0a5 | 2026 | # Create Diffie Hellmann Parameter |
2feacd98 | 2027 | # The system call is safe, because all arguments are passed as an array. |
badd8c1c | 2028 | system('/usr/bin/openssl', 'dhparam', '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
6e13d0a5 MT |
2029 | if ($?) { |
2030 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2031 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
2032 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
2033 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
2034 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
2035 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
c6c9630e | 2036 | &cleanssldatabase(); |
6e13d0a5 | 2037 | goto ROOTCERT_ERROR; |
c6c9630e MT |
2038 | # } else { |
2039 | # &cleanssldatabase(); | |
4be45949 | 2040 | } |
6e13d0a5 MT |
2041 | goto ROOTCERT_SUCCESS; |
2042 | } | |
2043 | ROOTCERT_ERROR: | |
2044 | if ($cgiparams{'ACTION'} ne '') { | |
2045 | &Header::showhttpheaders(); | |
4c962356 | 2046 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
2047 | &Header::openbigbox('100%', 'LEFT', '', ''); |
2048 | if ($errormessage) { | |
2049 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2050 | print "<class name='base'>$errormessage"; | |
2051 | print " </class>"; | |
2052 | &Header::closebox(); | |
2053 | } | |
2054 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
49abe7af | 2055 | print <<END; |
6e13d0a5 MT |
2056 | <form method='post' enctype='multipart/form-data'> |
2057 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
e3edceeb | 2058 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
2059 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> |
2060 | <td width='35%' colspan='2'> </td></tr> | |
e3edceeb | 2061 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
2062 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> |
2063 | <td colspan='2'> </td></tr> | |
e3edceeb | 2064 | <tr><td class='base'>$Lang::tr{'your e-mail'}:</td> |
6e13d0a5 MT |
2065 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> |
2066 | <td colspan='2'> </td></tr> | |
e3edceeb | 2067 | <tr><td class='base'>$Lang::tr{'your department'}:</td> |
6e13d0a5 MT |
2068 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> |
2069 | <td colspan='2'> </td></tr> | |
e3edceeb | 2070 | <tr><td class='base'>$Lang::tr{'city'}:</td> |
6e13d0a5 MT |
2071 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> |
2072 | <td colspan='2'> </td></tr> | |
e3edceeb | 2073 | <tr><td class='base'>$Lang::tr{'state or province'}:</td> |
6e13d0a5 MT |
2074 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> |
2075 | <td colspan='2'> </td></tr> | |
2076 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
2077 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
2078 | ||
2079 | END | |
2080 | ; | |
2081 | foreach my $country (sort keys %{Countries::countries}) { | |
2082 | print "<option value='$Countries::countries{$country}'"; | |
2083 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
2084 | print " selected='selected'"; | |
2085 | } | |
2086 | print ">$country</option>"; | |
2087 | } | |
49abe7af | 2088 | print <<END; |
6e13d0a5 | 2089 | </select></td> |
4c962356 EK |
2090 | <tr><td class='base'>$Lang::tr{'ovpn dh'}:</td> |
2091 | <td class='base'><select name='DHLENGHT'> | |
4c962356 EK |
2092 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> |
2093 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
2094 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
2095 | </select> | |
2096 | </td> | |
2097 | </tr> | |
2098 | ||
6e13d0a5 MT |
2099 | <tr><td> </td> |
2100 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
2101 | <td> </td><td> </td></tr> | |
2102 | <tr><td class='base' colspan='4' align='left'> | |
e3edceeb | 2103 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'required field'}</td></tr> |
49abe7af EK |
2104 | <tr><td colspan='2'><br></td></tr> |
2105 | <table width='100%'> | |
2106 | <tr> | |
2107 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'ovpn generating the root and host certificates'} | |
2108 | <td class='base'>$Lang::tr{'dh key warn'}</td> | |
4c962356 | 2109 | </tr> |
49abe7af EK |
2110 | <tr> |
2111 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
4c962356 | 2112 | </tr> |
49abe7af EK |
2113 | <tr><td colspan='2'><br></td></tr> |
2114 | <tr> | |
2115 | </table> | |
4c962356 | 2116 | |
49abe7af | 2117 | <table width='100%'> |
4c962356 | 2118 | <tr><td colspan='4'><hr></td></tr> |
e3edceeb | 2119 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
2120 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> |
2121 | <td colspan='2'> </td></tr> | |
e3edceeb | 2122 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
6e13d0a5 MT |
2123 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> |
2124 | <td colspan='2'> </td></tr> | |
2125 | <tr><td> </td> | |
2126 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
2127 | <td colspan='2'> </td></tr> | |
2128 | <tr><td class='base' colspan='4' align='left'> | |
e3edceeb | 2129 | <img src='/blob.gif' valign='top' alt='*' > $Lang::tr{'required field'}</td> |
4c962356 | 2130 | </tr> |
6e13d0a5 MT |
2131 | </form></table> |
2132 | END | |
2133 | ; | |
2134 | &Header::closebox(); | |
4c962356 | 2135 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2136 | &Header::closebigbox(); |
2137 | &Header::closepage(); | |
2138 | exit(0) | |
2139 | } | |
2140 | ||
2141 | ROOTCERT_SUCCESS: | |
2feacd98 | 2142 | &General::system("chmod", "600", "${General::swroot}/ovpn/certs/serverkey.pem"); |
c6c9630e MT |
2143 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
2144 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
2145 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
2146 | # } | |
6e13d0a5 MT |
2147 | |
2148 | ### | |
2149 | ### Enable/Disable connection | |
2150 | ### | |
ce9abb66 AH |
2151 | |
2152 | ### | |
7c1d9faf | 2153 | # m.a.d net2net |
ce9abb66 AH |
2154 | ### |
2155 | ||
6e13d0a5 | 2156 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
c6c9630e MT |
2157 | |
2158 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 | 2159 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2feacd98 SS |
2160 | my $n2nactive = ''; |
2161 | my @ps = &General::system_output("/bin/ps", "ax"); | |
2162 | ||
2163 | if(grep(/$confighash{$cgiparams{'KEY'}}[1]/, @ps)) { | |
2164 | $n2nactive = "1"; | |
2165 | } | |
ce9abb66 | 2166 | |
6e13d0a5 | 2167 | if ($confighash{$cgiparams{'KEY'}}) { |
8c877a82 AM |
2168 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
2169 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
2170 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2171 | |
8c877a82 | 2172 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
2feacd98 | 2173 | &General::system("/usr/local/bin/openvpnctrl", "-sn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
775b4494 | 2174 | &writecollectdconf(); |
8c877a82 AM |
2175 | } |
2176 | } else { | |
ce9abb66 | 2177 | |
8c877a82 AM |
2178 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
2179 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2180 | |
8c877a82 | 2181 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
775b4494 | 2182 | if ($n2nactive ne '') { |
2feacd98 | 2183 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
775b4494 AM |
2184 | &writecollectdconf(); |
2185 | } | |
8c877a82 | 2186 | } |
775b4494 | 2187 | } |
ce9abb66 | 2188 | } |
6e13d0a5 MT |
2189 | |
2190 | ### | |
2191 | ### Download OpenVPN client package | |
2192 | ### | |
ce9abb66 AH |
2193 | |
2194 | ||
6e13d0a5 MT |
2195 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
2196 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2197 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2198 | my $file = ''; | |
2199 | my $clientovpn = ''; | |
2200 | my @fileholder; | |
2201 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2202 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
2203 | |
2204 | ### | |
7c1d9faf AH |
2205 | # m.a.d net2net |
2206 | ### | |
ce9abb66 AH |
2207 | |
2208 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
2209 | ||
2210 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
2211 | my $zippathname = "$zippath$zipname"; | |
2212 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
2213 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
54fd0535 | 2214 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 2215 | my $tunmtu = ''; |
7c1d9faf | 2216 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
54fd0535 | 2217 | my $n2nfragment = ''; |
ce9abb66 AH |
2218 | |
2219 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
2220 | flock CLIENTCONF, 2; | |
2221 | ||
2222 | my $zip = Archive::Zip->new(); | |
7c1d9faf | 2223 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 2224 | print CLIENTCONF "# \n"; |
b278daf3 | 2225 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
2226 | print CLIENTCONF "user nobody\n"; |
2227 | print CLIENTCONF "group nobody\n"; | |
2228 | print CLIENTCONF "persist-tun\n"; | |
2229 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 2230 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 2231 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
531f0835 | 2232 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 | 2233 | print CLIENTCONF "float\n"; |
60f396d7 | 2234 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 2235 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 2236 | print CLIENTCONF "# Server Gateway Network\n"; |
7c1d9faf | 2237 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
b278daf3 | 2238 | print CLIENTCONF "# tun Device\n"; |
79e7688b | 2239 | print CLIENTCONF "dev tun\n"; |
35a21a25 AM |
2240 | print CLIENTCONF "#Logfile for statistics\n"; |
2241 | print CLIENTCONF "status-version 1\n"; | |
2242 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
60f396d7 | 2243 | print CLIENTCONF "# Port and Protokoll\n"; |
ce9abb66 | 2244 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; |
60f396d7 AH |
2245 | |
2246 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') { | |
2247 | print CLIENTCONF "proto tcp-client\n"; | |
2248 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 2249 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
60f396d7 | 2250 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 2251 | } |
60f396d7 AH |
2252 | |
2253 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { | |
2254 | print CLIENTCONF "proto udp\n"; | |
2255 | print CLIENTCONF "# Paketsize\n"; | |
2256 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2257 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 2258 | if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";} |
d6989b4b | 2259 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";} else { print CLIENTCONF "mssfix 0\n"; } |
d96c89eb | 2260 | } |
b66b02ab EK |
2261 | # Check host certificate if X509 is RFC3280 compliant. |
2262 | # If not, old --ns-cert-type directive will be used. | |
2263 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2feacd98 SS |
2264 | my @hostcert = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
2265 | if (! grep(/TLS Web Server Authentication/, @hostcert)) { | |
b66b02ab EK |
2266 | print CLIENTCONF "ns-cert-type server\n"; |
2267 | } else { | |
2268 | print CLIENTCONF "remote-cert-tls server\n"; | |
2269 | } | |
ce9abb66 AH |
2270 | print CLIENTCONF "# Auth. Client\n"; |
2271 | print CLIENTCONF "tls-client\n"; | |
49abe7af | 2272 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 2273 | print CLIENTCONF "cipher $confighash{$cgiparams{'KEY'}}[40]\n"; |
ce9abb66 AH |
2274 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
2275 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2276 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
49abe7af | 2277 | } |
52f61e49 EKD |
2278 | |
2279 | # If GCM cipher is used, do not use --auth | |
2280 | if (($confighash{$cgiparams{'KEY'}}[40] eq 'AES-256-GCM') || | |
2281 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-192-GCM') || | |
2282 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-128-GCM')) { | |
2283 | print CLIENTCONF unless "# HMAC algorithm\n"; | |
2284 | print CLIENTCONF unless "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
49abe7af | 2285 | } else { |
52f61e49 EKD |
2286 | print CLIENTCONF "# HMAC algorithm\n"; |
2287 | print CLIENTCONF "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
49abe7af | 2288 | } |
52f61e49 | 2289 | |
4c962356 | 2290 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 2291 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 2292 | print CLIENTCONF "comp-lzo\n"; |
b278daf3 | 2293 | } |
ce9abb66 AH |
2294 | print CLIENTCONF "# Debug Level\n"; |
2295 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 2296 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 2297 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 2298 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
2299 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; |
2300 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
b278daf3 | 2301 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
2302 | if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"} |
2303 | else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"}; | |
ce9abb66 | 2304 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; |
531f0835 | 2305 | |
ce9abb66 AH |
2306 | |
2307 | close(CLIENTCONF); | |
2308 | ||
2309 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
2310 | my $status = $zip->writeToFileNamed($zippathname); | |
2311 | ||
2312 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2313 | @fileholder = <DLFILE>; | |
2314 | print "Content-Type:application/x-download\n"; | |
2315 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2316 | print @fileholder; | |
2317 | exit (0); | |
2318 | } | |
2319 | else | |
2320 | { | |
2321 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
2322 | my $zippathname = "$zippath$zipname"; | |
2323 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
2324 | ||
2325 | ### | |
7c1d9faf | 2326 | # m.a.d net2net |
ce9abb66 AH |
2327 | ### |
2328 | ||
c6c9630e | 2329 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 MT |
2330 | flock CLIENTCONF, 2; |
2331 | ||
2332 | my $zip = Archive::Zip->new(); | |
2333 | ||
8c877a82 | 2334 | print CLIENTCONF "#OpenVPN Client conf\r\n"; |
6e13d0a5 MT |
2335 | print CLIENTCONF "tls-client\r\n"; |
2336 | print CLIENTCONF "client\r\n"; | |
4f6e3ae3 | 2337 | print CLIENTCONF "nobind\r\n"; |
79e7688b | 2338 | print CLIENTCONF "dev tun\r\n"; |
c6c9630e | 2339 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
d6989b4b | 2340 | print CLIENTCONF "tun-mtu $vpnsettings{'DMTU'}\r\n"; |
2ee746be | 2341 | |
6e13d0a5 MT |
2342 | if ( $vpnsettings{'ENABLED'} eq 'on'){ |
2343 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
c6c9630e MT |
2344 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
2345 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
2346 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2347 | } | |
2348 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2349 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2350 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2351 | } | |
2352 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2353 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2354 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2355 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2356 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2357 | } | |
2358 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2359 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 MT |
2360 | } |
2361 | ||
71af643c MT |
2362 | my $file_crt = new File::Temp( UNLINK => 1 ); |
2363 | my $file_key = new File::Temp( UNLINK => 1 ); | |
b22d8aaf | 2364 | my $include_certs = 0; |
71af643c | 2365 | |
6e13d0a5 | 2366 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
71af643c | 2367 | if ($cgiparams{'MODE'} eq 'insecure') { |
b22d8aaf MT |
2368 | $include_certs = 1; |
2369 | ||
71af643c | 2370 | # Add the CA |
b22d8aaf | 2371 | print CLIENTCONF ";ca cacert.pem\r\n"; |
71af643c MT |
2372 | $zip->addFile("${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; |
2373 | ||
2374 | # Extract the certificate | |
2feacd98 | 2375 | # This system call is safe, because all arguments are passed as an array. |
71af643c MT |
2376 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", |
2377 | '-clcerts', '-nokeys', '-nodes', '-out', "$file_crt" , '-passin', 'pass:'); | |
2378 | if ($?) { | |
2379 | die "openssl error: $?"; | |
2380 | } | |
2381 | ||
2382 | $zip->addFile("$file_crt", "$confighash{$cgiparams{'KEY'}}[1].pem") or die; | |
b22d8aaf | 2383 | print CLIENTCONF ";cert $confighash{$cgiparams{'KEY'}}[1].pem\r\n"; |
71af643c MT |
2384 | |
2385 | # Extract the key | |
2feacd98 | 2386 | # This system call is safe, because all arguments are passed as an array. |
71af643c MT |
2387 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", |
2388 | '-nocerts', '-nodes', '-out', "$file_key", '-passin', 'pass:'); | |
2389 | if ($?) { | |
2390 | die "openssl error: $?"; | |
2391 | } | |
2392 | ||
2393 | $zip->addFile("$file_key", "$confighash{$cgiparams{'KEY'}}[1].key") or die; | |
b22d8aaf | 2394 | print CLIENTCONF ";key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; |
71af643c MT |
2395 | } else { |
2396 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2397 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", "$confighash{$cgiparams{'KEY'}}[1].p12") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1].p12\n"; | |
2398 | } | |
6e13d0a5 | 2399 | } else { |
c6c9630e MT |
2400 | print CLIENTCONF "ca cacert.pem\r\n"; |
2401 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
2402 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
2403 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
2404 | $zip->addFile( "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem", "$confighash{$cgiparams{'KEY'}}[1]cert.pem") or die "Can't add file $confighash{$cgiparams{'KEY'}}[1]cert.pem\n"; | |
6e13d0a5 MT |
2405 | } |
2406 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
49abe7af | 2407 | print CLIENTCONF "auth $vpnsettings{'DAUTH'}\r\n"; |
86308adb | 2408 | |
49abe7af | 2409 | if ($vpnsettings{'TLSAUTH'} eq 'on') { |
b22d8aaf MT |
2410 | if ($cgiparams{'MODE'} eq 'insecure') { |
2411 | print CLIENTCONF ";"; | |
2412 | } | |
4be45949 EK |
2413 | print CLIENTCONF "tls-auth ta.key\r\n"; |
2414 | $zip->addFile( "${General::swroot}/ovpn/certs/ta.key", "ta.key") or die "Can't add file ta.key\n"; | |
49abe7af | 2415 | } |
6e13d0a5 MT |
2416 | if ($vpnsettings{DCOMPLZO} eq 'on') { |
2417 | print CLIENTCONF "comp-lzo\r\n"; | |
2418 | } | |
2419 | print CLIENTCONF "verb 3\r\n"; | |
b66b02ab EK |
2420 | # Check host certificate if X509 is RFC3280 compliant. |
2421 | # If not, old --ns-cert-type directive will be used. | |
2422 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2feacd98 SS |
2423 | my @hostcert = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
2424 | if (! grep(/TLS Web Server Authentication/, @hostcert)) { | |
b66b02ab EK |
2425 | print CLIENTCONF "ns-cert-type server\r\n"; |
2426 | } else { | |
2427 | print CLIENTCONF "remote-cert-tls server\r\n"; | |
2428 | } | |
964700d4 | 2429 | print CLIENTCONF "verify-x509-name $vpnsettings{ROOTCERT_HOSTNAME} name\r\n"; |
a79fa1d6 JPT |
2430 | if ($vpnsettings{MSSFIX} eq 'on') { |
2431 | print CLIENTCONF "mssfix\r\n"; | |
d6989b4b MT |
2432 | } else { |
2433 | print CLIENTCONF "mssfix 0\r\n"; | |
a79fa1d6 | 2434 | } |
74225cce | 2435 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
2436 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
2437 | } | |
1647059d | 2438 | |
b22d8aaf MT |
2439 | if ($include_certs) { |
2440 | print CLIENTCONF "\r\n"; | |
2441 | ||
2442 | # CA | |
2443 | open(FILE, "<${General::swroot}/ovpn/ca/cacert.pem"); | |
2444 | print CLIENTCONF "<ca>\r\n"; | |
2445 | while (<FILE>) { | |
2446 | chomp($_); | |
2447 | print CLIENTCONF "$_\r\n"; | |
2448 | } | |
2449 | print CLIENTCONF "</ca>\r\n\r\n"; | |
2450 | close(FILE); | |
2451 | ||
2452 | # Cert | |
2453 | open(FILE, "<$file_crt"); | |
2454 | print CLIENTCONF "<cert>\r\n"; | |
2455 | while (<FILE>) { | |
2456 | chomp($_); | |
2457 | print CLIENTCONF "$_\r\n"; | |
2458 | } | |
2459 | print CLIENTCONF "</cert>\r\n\r\n"; | |
2460 | close(FILE); | |
2461 | ||
2462 | # Key | |
2463 | open(FILE, "<$file_key"); | |
2464 | print CLIENTCONF "<key>\r\n"; | |
2465 | while (<FILE>) { | |
2466 | chomp($_); | |
2467 | print CLIENTCONF "$_\r\n"; | |
2468 | } | |
2469 | print CLIENTCONF "</key>\r\n\r\n"; | |
2470 | close(FILE); | |
2471 | ||
2472 | # TLS auth | |
2473 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
2474 | open(FILE, "<${General::swroot}/ovpn/certs/ta.key"); | |
2475 | print CLIENTCONF "<tls-auth>\r\n"; | |
2476 | while (<FILE>) { | |
2477 | chomp($_); | |
2478 | print CLIENTCONF "$_\r\n"; | |
2479 | } | |
2480 | print CLIENTCONF "</tls-auth>\r\n\r\n"; | |
2481 | close(FILE); | |
2482 | } | |
2483 | } | |
2484 | ||
ffbe77c8 EK |
2485 | # Print client.conf.local if entries exist to client.ovpn |
2486 | if (!-z $local_clientconf && $vpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
2487 | open (LCC, "$local_clientconf"); | |
2488 | print CLIENTCONF "\n#---------------------------\n"; | |
2489 | print CLIENTCONF "# Start of custom directives\n"; | |
2490 | print CLIENTCONF "# from client.conf.local\n"; | |
2491 | print CLIENTCONF "#---------------------------\n\n"; | |
2492 | while (<LCC>) { | |
2493 | print CLIENTCONF $_; | |
2494 | } | |
2495 | print CLIENTCONF "\n#---------------------------\n"; | |
2496 | print CLIENTCONF "# End of custom directives\n"; | |
2497 | print CLIENTCONF "#---------------------------\n\n"; | |
2498 | close (LCC); | |
2499 | } | |
6e13d0a5 | 2500 | close(CLIENTCONF); |
ce9abb66 | 2501 | |
6e13d0a5 MT |
2502 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
2503 | my $status = $zip->writeToFileNamed($zippathname); | |
2504 | ||
2505 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2506 | @fileholder = <DLFILE>; | |
2507 | print "Content-Type:application/x-download\n"; | |
2508 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2509 | print @fileholder; | |
2510 | exit (0); | |
ce9abb66 AH |
2511 | } |
2512 | ||
2513 | ||
2514 | ||
6e13d0a5 MT |
2515 | ### |
2516 | ### Remove connection | |
2517 | ### | |
ce9abb66 AH |
2518 | |
2519 | ||
6e13d0a5 | 2520 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
323be7c4 AM |
2521 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
2522 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 2523 | |
323be7c4 | 2524 | if ($confighash{$cgiparams{'KEY'}}) { |
fde9c9dd | 2525 | # Revoke certificate if certificate was deleted and rewrite the CRL |
274ca65b | 2526 | &General::system("/usr/bin/openssl", "ca", "-revoke", "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem", "-config", "${General::swroot}/ovpn/openssl/ovpn.cnf"); |
2feacd98 | 2527 | &General::system("/usr/bin/openssl", "ca", "-gencrl", "-out", "${General::swroot}/ovpn/crls/cacrl.pem", "-config", "${General::swroot}/ovpn/openssl/ovpn.cnf"); |
ce9abb66 AH |
2528 | |
2529 | ### | |
7c1d9faf | 2530 | # m.a.d net2net |
ce9abb66 | 2531 | ### |
7c1d9faf | 2532 | |
323be7c4 | 2533 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
1e499e90 | 2534 | # Stop the N2N connection before it is removed |
2feacd98 | 2535 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
1e499e90 | 2536 | |
323be7c4 AM |
2537 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); |
2538 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2539 | unlink ($certfile); | |
2540 | unlink ($conffile); | |
8e6a8fd5 | 2541 | |
323be7c4 AM |
2542 | if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") { |
2543 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2544 | } | |
323be7c4 | 2545 | } |
ce9abb66 | 2546 | |
323be7c4 AM |
2547 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
2548 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
8c877a82 AM |
2549 | |
2550 | # A.Marx CCD delete ccd files and routes | |
2551 | ||
323be7c4 AM |
2552 | if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]") |
2553 | { | |
2554 | unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; | |
8c877a82 | 2555 | } |
e81be1e1 | 2556 | |
323be7c4 AM |
2557 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
2558 | foreach my $key (keys %ccdroutehash) { | |
2559 | if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2560 | delete $ccdroutehash{$key}; | |
2561 | } | |
8c877a82 | 2562 | } |
323be7c4 | 2563 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 2564 | |
323be7c4 AM |
2565 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
2566 | foreach my $key (keys %ccdroute2hash) { | |
2567 | if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2568 | delete $ccdroute2hash{$key}; | |
2569 | } | |
2570 | } | |
2571 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
2572 | &writeserverconf; | |
8c877a82 | 2573 | |
323be7c4 AM |
2574 | # CCD end |
2575 | # Update collectd configuration and delete all RRD files of the removed connection | |
2576 | &writecollectdconf(); | |
2feacd98 | 2577 | &General::system("/usr/local/bin/openvpnctrl", "-drrd", "$confighash{$cgiparams{'KEY'}}[1]"); |
8c877a82 | 2578 | |
323be7c4 | 2579 | delete $confighash{$cgiparams{'KEY'}}; |
2feacd98 | 2580 | &General::system("/usr/bin/openssl", "ca", "-gencrl", "-out", "${General::swroot}/ovpn/crls/cacrl.pem", "-config", "${General::swroot}/ovpn/openssl/ovpn.cnf"); |
323be7c4 AM |
2581 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2582 | ||
2583 | } else { | |
2584 | $errormessage = $Lang::tr{'invalid key'}; | |
2585 | } | |
b2e75449 | 2586 | &General::firewall_reload(); |
ce9abb66 | 2587 | |
6e13d0a5 MT |
2588 | ### |
2589 | ### Download PKCS12 file | |
2590 | ### | |
2591 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
2592 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2593 | ||
2594 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
2595 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2feacd98 SS |
2596 | |
2597 | open(FILE, "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2598 | my @tmp = <FILE>; | |
2599 | close(FILE); | |
2600 | ||
2601 | print "@tmp"; | |
6e13d0a5 MT |
2602 | exit (0); |
2603 | ||
2604 | ### | |
2605 | ### Display certificate | |
2606 | ### | |
2607 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
2608 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2609 | ||
2610 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e | 2611 | &Header::showhttpheaders(); |
4c962356 | 2612 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
2613 | &Header::openbigbox('100%', 'LEFT', '', ''); |
2614 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
2feacd98 | 2615 | my @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
8c946d1c MT |
2616 | my $output = &Header::cleanhtml(join("", @output), "y"); |
2617 | print "<pre>$output</pre>\n"; | |
c6c9630e MT |
2618 | &Header::closebox(); |
2619 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2620 | &Header::closebigbox(); | |
2621 | &Header::closepage(); | |
2622 | exit(0); | |
6e13d0a5 | 2623 | } |
4c962356 EK |
2624 | |
2625 | ### | |
2626 | ### Display Diffie-Hellman key | |
2627 | ### | |
2628 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show dh'}) { | |
2629 | ||
2630 | if (! -e "${General::swroot}/ovpn/ca/dh1024.pem") { | |
49abe7af | 2631 | $errormessage = $Lang::tr{'not present'}; |
4c962356 EK |
2632 | } else { |
2633 | &Header::showhttpheaders(); | |
2634 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2635 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2636 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'dh'}:"); | |
2feacd98 | 2637 | my @output = &General::system_output("/usr/bin/openssl", "dhparam", "-text", "-in", "${General::swroot}/ovpn/ca/dh1024.pem"); |
8c946d1c MT |
2638 | my $output = &Header::cleanhtml(join("", @output) ,"y"); |
2639 | print "<pre>$output</pre>\n"; | |
4c962356 EK |
2640 | &Header::closebox(); |
2641 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2642 | &Header::closebigbox(); | |
2643 | &Header::closepage(); | |
2644 | exit(0); | |
2645 | } | |
2646 | ||
fd5ccb2d EK |
2647 | ### |
2648 | ### Display tls-auth key | |
2649 | ### | |
2650 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show tls-auth key'}) { | |
2651 | ||
2652 | if (! -e "${General::swroot}/ovpn/certs/ta.key") { | |
2653 | $errormessage = $Lang::tr{'not present'}; | |
2654 | } else { | |
2655 | &Header::showhttpheaders(); | |
2656 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2657 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2658 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ta key'}:"); | |
2feacd98 SS |
2659 | |
2660 | open(FILE, "${General::swroot}/ovpn/certs/ta.key"); | |
2661 | my @output = <FILE>; | |
2662 | close(FILE); | |
2663 | ||
8c946d1c MT |
2664 | my $output = &Header::cleanhtml(join("", @output),"y"); |
2665 | print "<pre>$output</pre>\n"; | |
fd5ccb2d EK |
2666 | &Header::closebox(); |
2667 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2668 | &Header::closebigbox(); | |
2669 | &Header::closepage(); | |
2670 | exit(0); | |
2671 | } | |
2672 | ||
6e13d0a5 MT |
2673 | ### |
2674 | ### Display Certificate Revoke List | |
2675 | ### | |
2676 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
2677 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2678 | ||
49abe7af EK |
2679 | if (! -e "${General::swroot}/ovpn/crls/cacrl.pem") { |
2680 | $errormessage = $Lang::tr{'not present'}; | |
2681 | } else { | |
b2e75449 MT |
2682 | &Header::showhttpheaders(); |
2683 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2684 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2685 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
2feacd98 | 2686 | my @output = &General::system_output("/usr/bin/openssl", "crl", "-text", "-noout", "-in", "${General::swroot}/ovpn/crls/cacrl.pem"); |
8c946d1c MT |
2687 | my $output = &Header::cleanhtml(join("", @output), "y"); |
2688 | print "<pre>$output</pre>\n"; | |
b2e75449 MT |
2689 | &Header::closebox(); |
2690 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2691 | &Header::closebigbox(); | |
2692 | &Header::closepage(); | |
2693 | exit(0); | |
6e13d0a5 MT |
2694 | } |
2695 | ||
2696 | ### | |
2697 | ### Advanced Server Settings | |
2698 | ### | |
2699 | ||
2700 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
2701 | %cgiparams = (); | |
2702 | %cahash = (); | |
2703 | %confighash = (); | |
8c877a82 | 2704 | my $disabled; |
6e13d0a5 | 2705 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); |
54fd0535 | 2706 | read_routepushfile; |
8c877a82 AM |
2707 | |
2708 | ||
c6c9630e MT |
2709 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
2710 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
2711 | # } | |
6e13d0a5 MT |
2712 | ADV_ERROR: |
2713 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
4c962356 | 2714 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 | 2715 | } |
6e13d0a5 | 2716 | if ($cgiparams{'KEEPALIVE_1'} eq '') { |
4c962356 | 2717 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
2718 | } |
2719 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
4c962356 | 2720 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
2721 | } |
2722 | if ($cgiparams{'LOG_VERB'} eq '') { | |
4c962356 | 2723 | $cgiparams{'LOG_VERB'} = '3'; |
ae9f6139 | 2724 | } |
f527e53f | 2725 | if ($cgiparams{'TLSAUTH'} eq '') { |
754066e6 | 2726 | $cgiparams{'TLSAUTH'} = 'off'; |
f527e53f | 2727 | } |
6e13d0a5 MT |
2728 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
2729 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
2730 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
2731 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
2732 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
2733 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
13389777 EK |
2734 | $checked{'DCOMPLZO'}{'off'} = ''; |
2735 | $checked{'DCOMPLZO'}{'on'} = ''; | |
2736 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
ffbe77c8 EK |
2737 | $checked{'ADDITIONAL_CONFIGS'}{'off'} = ''; |
2738 | $checked{'ADDITIONAL_CONFIGS'}{'on'} = ''; | |
2739 | $checked{'ADDITIONAL_CONFIGS'}{$cgiparams{'ADDITIONAL_CONFIGS'}} = 'CHECKED'; | |
a79fa1d6 JPT |
2740 | $checked{'MSSFIX'}{'off'} = ''; |
2741 | $checked{'MSSFIX'}{'on'} = ''; | |
2742 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
49abe7af | 2743 | $selected{'LOG_VERB'}{'0'} = ''; |
6e13d0a5 MT |
2744 | $selected{'LOG_VERB'}{'1'} = ''; |
2745 | $selected{'LOG_VERB'}{'2'} = ''; | |
2746 | $selected{'LOG_VERB'}{'3'} = ''; | |
2747 | $selected{'LOG_VERB'}{'4'} = ''; | |
2748 | $selected{'LOG_VERB'}{'5'} = ''; | |
2749 | $selected{'LOG_VERB'}{'6'} = ''; | |
2750 | $selected{'LOG_VERB'}{'7'} = ''; | |
2751 | $selected{'LOG_VERB'}{'8'} = ''; | |
2752 | $selected{'LOG_VERB'}{'9'} = ''; | |
2753 | $selected{'LOG_VERB'}{'10'} = ''; | |
2754 | $selected{'LOG_VERB'}{'11'} = ''; | |
6e13d0a5 | 2755 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; |
f527e53f | 2756 | |
6e13d0a5 MT |
2757 | &Header::showhttpheaders(); |
2758 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
2759 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2760 | if ($errormessage) { | |
c6c9630e MT |
2761 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
2762 | print "<class name='base'>$errormessage\n"; | |
2763 | print " </class>\n"; | |
2764 | &Header::closebox(); | |
6e13d0a5 MT |
2765 | } |
2766 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
4c962356 | 2767 | print <<END; |
b376fae4 | 2768 | <form method='post' enctype='multipart/form-data'> |
b2e75449 | 2769 | <table width='100%' border=0> |
4c962356 EK |
2770 | <tr> |
2771 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
6e13d0a5 MT |
2772 | </tr> |
2773 | <tr> | |
4c962356 | 2774 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> |
6e13d0a5 MT |
2775 | </tr> |
2776 | <tr> | |
4c962356 | 2777 | <td class='base'>Domain</td> |
8c877a82 | 2778 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> |
6e13d0a5 MT |
2779 | </tr> |
2780 | <tr> | |
4c962356 EK |
2781 | <td class='base'>DNS</td> |
2782 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
6e13d0a5 MT |
2783 | </tr> |
2784 | <tr> | |
4c962356 EK |
2785 | <td class='base'>WINS</td> |
2786 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
2787 | </tr> | |
54fd0535 | 2788 | <tr> |
4c962356 | 2789 | <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td> |
54fd0535 MT |
2790 | </tr> |
2791 | <tr> | |
4c962356 EK |
2792 | <td class='base'>$Lang::tr{'ovpn routes push'}</td> |
2793 | <td colspan='2'> | |
2794 | <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'> | |
54fd0535 MT |
2795 | END |
2796 | ; | |
2797 | ||
2798 | if ($cgiparams{'ROUTES_PUSH'} ne '') | |
2799 | { | |
2800 | print $cgiparams{'ROUTES_PUSH'}; | |
2801 | } | |
2802 | ||
8c877a82 | 2803 | print <<END; |
54fd0535 MT |
2804 | </textarea></td> |
2805 | </tr> | |
6e13d0a5 MT |
2806 | </tr> |
2807 | </table> | |
2808 | <hr size='1'> | |
4c962356 | 2809 | <table width='100%'> |
ffbe77c8 | 2810 | <tr> |
4c962356 | 2811 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> |
ffbe77c8 EK |
2812 | </tr> |
2813 | ||
2814 | <tr> | |
d2de0a00 | 2815 | <td width='20%'></td> <td width='15%'> </td><td width='35%'> </td><td width='20%'></td><td width='35%'></td> |
ffbe77c8 EK |
2816 | </tr> |
2817 | ||
2818 | <tr> | |
4c962356 EK |
2819 | <td class='base'>Client-To-Client</td> |
2820 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
ffbe77c8 EK |
2821 | </tr> |
2822 | ||
2823 | <tr> | |
4c962356 EK |
2824 | <td class='base'>Redirect-Gateway def1</td> |
2825 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
ffbe77c8 EK |
2826 | </tr> |
2827 | ||
13389777 EK |
2828 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
2829 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
2830 | <td>$Lang::tr{'openvpn default'}: off <font color='red'>($Lang::tr{'attention'} exploitable via Voracle)</font></td> | |
2831 | </tr> | |
2832 | ||
4c962356 | 2833 | <tr> |
ffbe77c8 EK |
2834 | <td class='base'>$Lang::tr{'ovpn add conf'}</td> |
2835 | <td><input type='checkbox' name='ADDITIONAL_CONFIGS' $checked{'ADDITIONAL_CONFIGS'}{'on'} /></td> | |
2836 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2837 | </tr> | |
2838 | ||
2839 | <tr> | |
2840 | <td class='base'>mssfix</td> | |
2841 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
2842 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2843 | </tr> | |
2844 | ||
4c962356 | 2845 | <tr> |
ffbe77c8 EK |
2846 | <td class='base'>fragment <br></td> |
2847 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
2848 | </tr> | |
2849 | ||
2850 | ||
2851 | <tr> | |
2852 | <td class='base'>Max-Clients</td> | |
2853 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> | |
2854 | </tr> | |
2855 | <tr> | |
2856 | <td class='base'>Keepalive <br /> | |
2857 | (ping/ping-restart)</td> | |
2858 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
2859 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
2860 | </tr> | |
a79fa1d6 JPT |
2861 | </table> |
2862 | ||
a79fa1d6 | 2863 | <hr size='1'> |
4c962356 | 2864 | <table width='100%'> |
a79fa1d6 | 2865 | <tr> |
49abe7af | 2866 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> |
a79fa1d6 JPT |
2867 | </tr> |
2868 | <tr> | |
49abe7af | 2869 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> |
4c962356 EK |
2870 | </tr> |
2871 | ||
2872 | <tr><td class='base'>VERB</td> | |
2873 | <td><select name='LOG_VERB'> | |
49abe7af EK |
2874 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option> |
2875 | <option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
2876 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
2877 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
2878 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
2879 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
2880 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
2881 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
2882 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
2883 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
2884 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
2885 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
2886 | </td></select> | |
2887 | </table> | |
4c962356 | 2888 | |
6e13d0a5 | 2889 | <hr size='1'> |
8c877a82 AM |
2890 | END |
2891 | ||
2892 | if ( -e "/var/run/openvpn.pid"){ | |
2893 | print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br> | |
2894 | $Lang::tr{'server restart'}<br><br> | |
2895 | <hr>"; | |
49abe7af | 2896 | print<<END; |
52d08bcb AM |
2897 | <table width='100%'> |
2898 | <tr> | |
2899 | <td> </td> | |
2900 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td> | |
2901 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2902 | <td> </td> | |
2903 | </tr> | |
2904 | </table> | |
2905 | </form> | |
2906 | END | |
2907 | ; | |
2908 | ||
2909 | ||
2910 | }else{ | |
8c877a82 | 2911 | |
49abe7af | 2912 | print<<END; |
6e13d0a5 MT |
2913 | <table width='100%'> |
2914 | <tr> | |
2915 | <td> </td> | |
2916 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
2917 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2918 | <td> </td> | |
2919 | </tr> | |
2920 | </table> | |
2921 | </form> | |
2922 | END | |
2923 | ; | |
52d08bcb | 2924 | } |
6e13d0a5 | 2925 | &Header::closebox(); |
c6c9630e | 2926 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2927 | &Header::closebigbox(); |
2928 | &Header::closepage(); | |
2929 | exit(0); | |
2930 | ||
8c877a82 AM |
2931 | |
2932 | # A.Marx CCD Add,delete or edit CCD net | |
2933 | ||
2934 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} || | |
2935 | $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} || | |
2936 | $cgiparams{'ACTION'} eq "kill" || | |
2937 | $cgiparams{'ACTION'} eq "edit" || | |
2938 | $cgiparams{'ACTION'} eq 'editsave'){ | |
2939 | &Header::showhttpheaders(); | |
2940 | &Header::openpage($Lang::tr{'ccd net'}, 1, ''); | |
2941 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2942 | ||
2943 | if ($cgiparams{'ACTION'} eq "kill"){ | |
2944 | &delccdnet($cgiparams{'net'}); | |
2945 | } | |
2946 | ||
2947 | if ($cgiparams{'ACTION'} eq 'editsave'){ | |
2948 | my ($a,$b) =split (/\|/,$cgiparams{'ccdname'}); | |
2949 | if ( $a ne $b){ &modccdnet($a,$b);} | |
5068ac38 AM |
2950 | $cgiparams{'ccdname'}=''; |
2951 | $cgiparams{'ccdsubnet'}=''; | |
8c877a82 AM |
2952 | } |
2953 | ||
2954 | if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) { | |
e2429e8d | 2955 | &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'}); |
8c877a82 AM |
2956 | } |
2957 | if ($errormessage) { | |
2958 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2959 | print "<class name='base'>$errormessage"; | |
2960 | print " </class>"; | |
2961 | &Header::closebox(); | |
2962 | } | |
2963 | if ($cgiparams{'ACTION'} eq "edit"){ | |
2964 | ||
2965 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'}); | |
2966 | ||
49abe7af | 2967 | print <<END; |
631b67b7 | 2968 | <table width='100%' border='0'> |
8c877a82 AM |
2969 | <tr><form method='post'> |
2970 | <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
a9fb14d0 | 2971 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly='readonly' /></td></tr> |
8c877a82 AM |
2972 | <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/> |
2973 | <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' /> | |
2974 | </td></tr> | |
2975 | </table></form> | |
2976 | END | |
2977 | ; | |
2978 | &Header::closebox(); | |
2979 | ||
2980 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
49abe7af | 2981 | print <<END; |
8c877a82 AM |
2982 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> |
2983 | <tr> | |
2984 | <td class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' width='15%' align='center'><b>$Lang::tr{'ccd used'}</td><td width='3%'></td><td width='3%'></td></tr> | |
2985 | END | |
2986 | ; | |
2987 | } | |
2988 | else{ | |
2989 | if (! -e "/var/run/openvpn.pid"){ | |
2990 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'}); | |
49abe7af | 2991 | print <<END; |
8c877a82 AM |
2992 | <table width='100%' border='0'> |
2993 | <tr><form method='post'> | |
2994 | <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr> | |
2995 | <tr> | |
2996 | <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2997 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr> | |
2998 | <tr><td colspan=4><hr /></td></tr><tr> | |
2999 | <td colspan='4' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'ccd add'}' /><input type='submit' value='$Lang::tr{'add'}' /><input type='hidden' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}'/></td></tr> | |
3000 | </table></form> | |
3001 | END | |
3002 | ||
3003 | &Header::closebox(); | |
3004 | } | |
3005 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
5068ac38 AM |
3006 | if ( -e "/var/run/openvpn.pid"){ |
3007 | print "<b>$Lang::tr{'attention'}:</b><br>"; | |
3008 | print "$Lang::tr{'ccd noaddnet'}<br><hr>"; | |
3009 | } | |
3010 | ||
4c962356 | 3011 | print <<END; |
99bfa85c | 3012 | <table width='100%' cellpadding='0' cellspacing='1'> |
8c877a82 AM |
3013 | <tr> |
3014 | <td class='boldbase' align='center' nowrap='nowrap' width='20%'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center' width='8%'><b>$Lang::tr{'network'}</td><td class='boldbase' width='8%' align='center' nowrap='nowrap'><b>$Lang::tr{'ccd used'}</td><td width='1%' align='center'></td><td width='1%' align='center'></td></tr> | |
3015 | END | |
3016 | ; | |
3017 | } | |
3018 | my %ccdconfhash=(); | |
3019 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
3020 | my @ccdconf=(); | |
3021 | my $count=0; | |
df9b48b7 | 3022 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
3023 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); |
3024 | $count++; | |
3025 | my $ccdhosts = &hostsinnet($ccdconf[0]); | |
3026 | if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
3027 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
3028 | print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>"; | |
4c962356 | 3029 | print <<END; |
8c877a82 | 3030 | <form method='post' /> |
1638682b | 3031 | <input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> |
8c877a82 AM |
3032 | <input type='hidden' name='ACTION' value='edit'/> |
3033 | <input type='hidden' name='ccdname' value='$ccdconf[0]' /> | |
3034 | <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' /> | |
3035 | </form></td> | |
3036 | <form method='post' /> | |
3037 | <td><input type='hidden' name='ACTION' value='kill'/> | |
3038 | <input type='hidden' name='number' value='$count' /> | |
3039 | <input type='hidden' name='net' value='$ccdconf[0]' /> | |
1638682b | 3040 | <input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /></form></td></tr> |
8c877a82 AM |
3041 | END |
3042 | ; | |
3043 | } | |
3044 | print "</table></form>"; | |
3045 | &Header::closebox(); | |
3046 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3047 | &Header::closebigbox(); | |
3048 | &Header::closepage(); | |
3049 | exit(0); | |
3050 | ||
3051 | #END CCD | |
3052 | ||
6e13d0a5 MT |
3053 | ### |
3054 | ### Openvpn Connections Statistics | |
3055 | ### | |
3056 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
3057 | &Header::showhttpheaders(); | |
3058 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
3059 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
3060 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
3061 | ||
3062 | # | |
3063 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
3064 | # protocol temp removed | |
4c962356 | 3065 | print <<END; |
99bfa85c | 3066 | <table width='100%' cellpadding='2' cellspacing='0' class='tbl'> |
6e13d0a5 | 3067 | <tr> |
99bfa85c AM |
3068 | <th><b>$Lang::tr{'common name'}</b></th> |
3069 | <th><b>$Lang::tr{'real address'}</b></th> | |
d8ef6a95 | 3070 | <th><b>$Lang::tr{'country'}</b></th> |
99bfa85c AM |
3071 | <th><b>$Lang::tr{'virtual address'}</b></th> |
3072 | <th><b>$Lang::tr{'loged in at'}</b></th> | |
3073 | <th><b>$Lang::tr{'bytes sent'}</b></th> | |
3074 | <th><b>$Lang::tr{'bytes received'}</b></th> | |
3075 | <th><b>$Lang::tr{'last activity'}</b></th> | |
6e13d0a5 MT |
3076 | </tr> |
3077 | END | |
3078 | ; | |
87fe47e9 | 3079 | my $filename = "/var/run/ovpnserver.log"; |
6e13d0a5 MT |
3080 | open(FILE, $filename) or die 'Unable to open config file.'; |
3081 | my @current = <FILE>; | |
3082 | close(FILE); | |
3083 | my @users =(); | |
3084 | my $status; | |
3085 | my $uid = 0; | |
3086 | my $cn; | |
3087 | my @match = (); | |
3088 | my $proto = "udp"; | |
3089 | my $address; | |
3090 | my %userlookup = (); | |
3091 | foreach my $line (@current) | |
3092 | { | |
3093 | chomp($line); | |
3094 | if ( $line =~ /^Updated,(.+)/){ | |
3095 | @match = split( /^Updated,(.+)/, $line); | |
3096 | $status = $match[1]; | |
3097 | } | |
c6c9630e | 3098 | #gian |
6e13d0a5 MT |
3099 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
3100 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
3101 | if ($match[1] ne "Common Name") { | |
3102 | $cn = $match[1]; | |
3103 | $userlookup{$match[2]} = $uid; | |
3104 | $users[$uid]{'CommonName'} = $match[1]; | |
3105 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
3106 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
3107 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
3108 | $users[$uid]{'Since'} = $match[5]; |
3109 | $users[$uid]{'Proto'} = $proto; | |
d8ef6a95 PM |
3110 | |
3111 | # get country code for "RealAddress"... | |
07e42be9 | 3112 | my $ccode = &Location::Functions::lookup_country_code((split ':', $users[$uid]{'RealAddress'})[0]); |
e2e270e1 | 3113 | my $flag_icon = &Location::Functions::get_flag_icon($ccode); |
d8ef6a95 | 3114 | $users[$uid]{'Country'} = "<a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a>"; |
6e13d0a5 MT |
3115 | $uid++; |
3116 | } | |
3117 | } | |
3118 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
3119 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
3120 | if ($match[1] ne "Virtual Address") { | |
3121 | $address = $match[3]; | |
3122 | #find the uid in the lookup table | |
3123 | $uid = $userlookup{$address}; | |
3124 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
3125 | $users[$uid]{'LastRef'} = $match[4]; | |
3126 | } | |
3127 | } | |
3128 | } | |
3129 | my $user2 = @users; | |
3130 | if ($user2 >= 1){ | |
99bfa85c | 3131 | for (my $idx = 1; $idx <= $user2; $idx++){ |
6e13d0a5 | 3132 | if ($idx % 2) { |
99bfa85c AM |
3133 | print "<tr>"; |
3134 | $col="bgcolor='$color{'color22'}'"; | |
3135 | } else { | |
3136 | print "<tr>"; | |
3137 | $col="bgcolor='$color{'color20'}'"; | |
6e13d0a5 | 3138 | } |
99bfa85c AM |
3139 | print "<td align='left' $col>$users[$idx-1]{'CommonName'}</td>"; |
3140 | print "<td align='left' $col>$users[$idx-1]{'RealAddress'}</td>"; | |
d8ef6a95 PM |
3141 | print "<td align='center' $col>$users[$idx-1]{'Country'}</td>"; |
3142 | print "<td align='center' $col>$users[$idx-1]{'VirtualAddress'}</td>"; | |
99bfa85c AM |
3143 | print "<td align='left' $col>$users[$idx-1]{'Since'}</td>"; |
3144 | print "<td align='left' $col>$users[$idx-1]{'BytesSent'}</td>"; | |
3145 | print "<td align='left' $col>$users[$idx-1]{'BytesReceived'}</td>"; | |
3146 | print "<td align='left' $col>$users[$idx-1]{'LastRef'}</td>"; | |
3147 | } | |
3148 | } | |
6e13d0a5 MT |
3149 | |
3150 | print "</table>"; | |
49abe7af | 3151 | print <<END; |
6e13d0a5 MT |
3152 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> |
3153 | <tr><td></td></tr> | |
3154 | <tr><td></td></tr> | |
3155 | <tr><td></td></tr> | |
3156 | <tr><td></td></tr> | |
3157 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
3158 | </table> | |
3159 | END | |
3160 | ; | |
3161 | &Header::closebox(); | |
3162 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3163 | &Header::closebigbox(); | |
3164 | &Header::closepage(); | |
3165 | exit(0); | |
3166 | ||
3167 | ### | |
3168 | ### Download Certificate | |
3169 | ### | |
3170 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
3171 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 3172 | |
6e13d0a5 | 3173 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
3174 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
3175 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2feacd98 SS |
3176 | |
3177 | open(FILE, "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
3178 | my @tmp = <FILE>; | |
3179 | close(FILE); | |
3180 | ||
3181 | print "@tmp"; | |
c6c9630e MT |
3182 | exit (0); |
3183 | } | |
3184 | ||
3185 | ### | |
3186 | ### Enable/Disable connection | |
3187 | ### | |
ce9abb66 | 3188 | |
c6c9630e MT |
3189 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
3190 | ||
3191 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3192 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3193 | ||
3194 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 3195 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
3196 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
3197 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3198 | #&writeserverconf(); | |
3199 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3200 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3201 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3202 | # } | |
3203 | } else { | |
3204 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
3205 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3206 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3207 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
3208 | # } | |
3209 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3210 | #&writeserverconf(); | |
3211 | } | |
3212 | } else { | |
3213 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
3214 | } |
3215 | ||
3216 | ### | |
3217 | ### Restart connection | |
3218 | ### | |
3219 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
3220 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3221 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3222 | ||
3223 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
3224 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
3225 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3226 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3227 | # } | |
6e13d0a5 | 3228 | } else { |
c6c9630e | 3229 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
3230 | } |
3231 | ||
ce9abb66 | 3232 | ### |
7c1d9faf | 3233 | # m.a.d net2net |
ce9abb66 AH |
3234 | ### |
3235 | ||
3236 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
3237 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3238 | &Header::showhttpheaders(); | |
4c962356 | 3239 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
ce9abb66 AH |
3240 | &Header::openbigbox('100%', 'LEFT', '', ''); |
3241 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
3242 | |
3243 | if ( -s "${General::swroot}/ovpn/settings") { | |
3244 | ||
49abe7af | 3245 | print <<END; |
ce9abb66 | 3246 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3247 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
ce9abb66 AH |
3248 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> |
3249 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
3250 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
3251 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
3252 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
3253 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
3254 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
e3edceeb | 3255 | <tr><td> </td><td>Import Connection Name</td></tr> |
040b8b0c | 3256 | <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>$Lang::tr{'openvpn default'}: Client Packagename</td></tr> |
54fd0535 | 3257 | <tr><td colspan='3'><hr /></td></tr> |
8c877a82 | 3258 | <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
ce9abb66 AH |
3259 | </form></table> |
3260 | END | |
3261 | ; | |
8c877a82 | 3262 | |
ce9abb66 | 3263 | |
b278daf3 | 3264 | } else { |
49abe7af | 3265 | print <<END; |
b278daf3 | 3266 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3267 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
b278daf3 | 3268 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> |
8c877a82 | 3269 | <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
b278daf3 AH |
3270 | </form></table> |
3271 | END | |
3272 | ; | |
3273 | ||
3274 | } | |
3275 | ||
ce9abb66 | 3276 | &Header::closebox(); |
4c962356 | 3277 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
ce9abb66 AH |
3278 | &Header::closebigbox(); |
3279 | &Header::closepage(); | |
3280 | exit (0); | |
3281 | ||
3282 | ### | |
7c1d9faf | 3283 | # m.a.d net2net |
ce9abb66 AH |
3284 | ### |
3285 | ||
3286 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
3287 | ||
3288 | my @firen2nconf; | |
3289 | my @confdetails; | |
3290 | my $uplconffilename =''; | |
54fd0535 | 3291 | my $uplconffilename2 =''; |
ce9abb66 | 3292 | my $uplp12name = ''; |
54fd0535 | 3293 | my $uplp12name2 = ''; |
ce9abb66 AH |
3294 | my @rem_subnet; |
3295 | my @rem_subnet2; | |
3296 | my @tmposupnet3; | |
3297 | my $key; | |
54fd0535 | 3298 | my @n2nname; |
ce9abb66 AH |
3299 | |
3300 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3301 | ||
2ad1b18b MT |
3302 | # Check if a file is uploaded |
3303 | unless (ref ($cgiparams{'FH'})) { | |
ce9abb66 AH |
3304 | $errormessage = $Lang::tr{'there was no file upload'}; |
3305 | goto N2N_ERROR; | |
3306 | } | |
3307 | ||
3308 | # Move uploaded IPfire n2n package to temporary file | |
3309 | ||
3310 | (my $fh, my $filename) = tempfile( ); | |
3311 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3312 | $errormessage = $!; | |
3313 | goto N2N_ERROR; | |
3314 | } | |
3315 | ||
3316 | my $zip = Archive::Zip->new(); | |
3317 | my $zipName = $filename; | |
3318 | my $status = $zip->read( $zipName ); | |
3319 | if ($status != AZ_OK) { | |
3320 | $errormessage = "Read of $zipName failed\n"; | |
3321 | goto N2N_ERROR; | |
3322 | } | |
3323 | ||
3324 | my $tempdir = tempdir( CLEANUP => 1 ); | |
3325 | my @files = $zip->memberNames(); | |
3326 | for(@files) { | |
3327 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
3328 | } | |
3329 | my $countfiles = @files; | |
3330 | ||
3331 | # Check if we have not more then 2 files | |
3332 | ||
3333 | if ( $countfiles == 2){ | |
3334 | foreach (@files){ | |
3335 | if ( $_ =~ /.conf$/){ | |
3336 | $uplconffilename = $_; | |
3337 | } | |
3338 | if ( $_ =~ /.p12$/){ | |
3339 | $uplp12name = $_; | |
3340 | } | |
3341 | } | |
3342 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
3343 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
3344 | goto N2N_ERROR; | |
3345 | } | |
3346 | ||
3347 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
3348 | @firen2nconf = <FILE>; | |
3349 | close (FILE); | |
3350 | chomp(@firen2nconf); | |
ce9abb66 AH |
3351 | } else { |
3352 | ||
3353 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
3354 | goto N2N_ERROR; | |
3355 | } | |
3356 | ||
7c1d9faf AH |
3357 | ### |
3358 | # m.a.d net2net | |
ce9abb66 | 3359 | ### |
54fd0535 MT |
3360 | |
3361 | if ($cgiparams{'n2nname'} ne ''){ | |
3362 | ||
3363 | $uplconffilename2 = "$cgiparams{'n2nname'}.conf"; | |
3364 | $uplp12name2 = "$cgiparams{'n2nname'}.p12"; | |
3365 | $n2nname[0] = $cgiparams{'n2nname'}; | |
3366 | my @n2nname2 = split(/\./,$uplconffilename); | |
3367 | $n2nname2[0] =~ s/\n|\r//g; | |
3368 | my $input1 = "${General::swroot}/ovpn/certs/$uplp12name"; | |
3369 | my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2"; | |
3370 | my $input2 = "$n2nname2[0]n2n"; | |
3371 | my $output2 = "$n2nname[0]n2n"; | |
3372 | my $filename = "$tempdir/$uplconffilename"; | |
3373 | open(FILE, "< $filename") or die 'Unable to open config file.'; | |
3374 | my @current = <FILE>; | |
3375 | close(FILE); | |
3376 | foreach (@current) {s/$input1/$output1/g;} | |
3377 | foreach (@current) {s/$input2/$output2/g;} | |
3378 | open (OUT, "> $filename") || die 'Unable to open config file.'; | |
3379 | print OUT @current; | |
3380 | close OUT; | |
ce9abb66 | 3381 | |
54fd0535 MT |
3382 | }else{ |
3383 | $uplconffilename2 = $uplconffilename; | |
3384 | $uplp12name2 = $uplp12name; | |
3385 | @n2nname = split(/\./,$uplconffilename); | |
ce9abb66 | 3386 | $n2nname[0] =~ s/\n|\r//g; |
54fd0535 | 3387 | } |
7c1d9faf AH |
3388 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
3389 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
ce9abb66 | 3390 | |
7dfcaef0 AM |
3391 | #Add collectd settings to configfile |
3392 | open(FILE, ">> $tempdir/$uplconffilename") or die 'Unable to open config file.'; | |
3393 | print FILE "# Logfile\n"; | |
3394 | print FILE "status-version 1\n"; | |
3395 | print FILE "status /var/run/openvpn/$n2nname[0]-n2n 10\n"; | |
3396 | close FILE; | |
3397 | ||
54fd0535 | 3398 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2"); |
ce9abb66 AH |
3399 | |
3400 | if ($? ne 0) { | |
3401 | $errormessage = "*.conf move failed: $!"; | |
3402 | unlink ($filename); | |
3403 | goto N2N_ERROR; | |
3404 | } | |
3405 | ||
54fd0535 | 3406 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2"); |
b278daf3 AH |
3407 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; |
3408 | ||
ce9abb66 AH |
3409 | if ($? ne 0) { |
3410 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3411 | unlink ($filename); | |
3412 | goto N2N_ERROR; | |
3413 | } | |
3414 | ||
3415 | my $complzoactive; | |
d96c89eb | 3416 | my $mssfixactive; |
4c962356 | 3417 | my $authactive; |
d96c89eb | 3418 | my $n2nfragment; |
60f396d7 | 3419 | my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
54fd0535 | 3420 | my @n2nproto = split(/-/, $n2nproto2[1]); |
ce9abb66 AH |
3421 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); |
3422 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
3423 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
3424 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
d96c89eb AH |
3425 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
3426 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
54fd0535 | 3427 | #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]); |
d96c89eb | 3428 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); |
ce9abb66 AH |
3429 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
3430 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
3431 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
3432 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
54fd0535 | 3433 | my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]); |
ce9abb66 | 3434 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); |
4c962356 | 3435 | my @n2ncipher = split(/ /, (grep { /^cipher/ } @firen2nconf)[0]); |
f527e53f | 3436 | my @n2nauth = split(/ /, (grep { /^auth/ } @firen2nconf)[0]);; |
60f396d7 | 3437 | |
ce9abb66 AH |
3438 | ### |
3439 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
3440 | ### | |
3441 | ||
ce9abb66 | 3442 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
3443 | $n2novpnsub[0] =~ s/\n|\r//g; |
3444 | $n2novpnsub[1] =~ s/\n|\r//g; | |
3445 | $n2novpnsub[2] =~ s/\n|\r//g; | |
60f396d7 | 3446 | $n2nproto[0] =~ s/\n|\r//g; |
ce9abb66 AH |
3447 | $n2nport[1] =~ s/\n|\r//g; |
3448 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
3449 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 3450 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 3451 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 3452 | $n2nfragment[1] =~ s/\n|\r//g; |
54fd0535 | 3453 | $n2nmgmt[2] =~ s/\n|\r//g; |
4c962356 EK |
3454 | $n2ncipher[1] =~ s/\n|\r//g; |
3455 | $n2nauth[1] =~ s/\n|\r//g; | |
ce9abb66 | 3456 | chomp ($complzoactive); |
d96c89eb | 3457 | chomp ($mssfixactive); |
ce9abb66 AH |
3458 | |
3459 | ### | |
7c1d9faf | 3460 | # m.a.d net2net |
ce9abb66 AH |
3461 | ### |
3462 | ||
3463 | ### | |
3464 | # Check if there is no other entry with this name | |
3465 | ### | |
3466 | ||
3467 | foreach my $dkey (keys %confighash) { | |
3468 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
3469 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3470 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3471 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3472 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
ce9abb66 AH |
3473 | goto N2N_ERROR; |
3474 | } | |
3475 | } | |
3476 | ||
d96c89eb AH |
3477 | ### |
3478 | # Check if OpenVPN Subnet is valid | |
3479 | ### | |
3480 | ||
3481 | foreach my $dkey (keys %confighash) { | |
3482 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
3483 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
3484 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3485 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3486 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3487 | goto N2N_ERROR; |
3488 | } | |
3489 | } | |
3490 | ||
3491 | ### | |
4c962356 | 3492 | # Check if Dest Port is vaild |
d96c89eb AH |
3493 | ### |
3494 | ||
3495 | foreach my $dkey (keys %confighash) { | |
3496 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
3497 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
3498 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3499 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3500 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3501 | goto N2N_ERROR; |
3502 | } | |
3503 | } | |
3504 | ||
3505 | ||
3506 | ||
ce9abb66 AH |
3507 | $key = &General::findhasharraykey (\%confighash); |
3508 | ||
49abe7af | 3509 | foreach my $i (0 .. 42) { $confighash{$key}[$i] = "";} |
350f2980 | 3510 | |
ce9abb66 AH |
3511 | $confighash{$key}[0] = 'off'; |
3512 | $confighash{$key}[1] = $n2nname[0]; | |
350f2980 | 3513 | $confighash{$key}[2] = $n2nname[0]; |
ce9abb66 AH |
3514 | $confighash{$key}[3] = 'net'; |
3515 | $confighash{$key}[4] = 'cert'; | |
3516 | $confighash{$key}[6] = 'client'; | |
3517 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
350f2980 SS |
3518 | $confighash{$key}[10] = $n2nremote[1]; |
3519 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; | |
54fd0535 | 3520 | $confighash{$key}[22] = $n2nmgmt[2]; |
350f2980 | 3521 | $confighash{$key}[23] = $mssfixactive; |
d96c89eb | 3522 | $confighash{$key}[24] = $n2nfragment[1]; |
350f2980 | 3523 | $confighash{$key}[25] = 'IPFire n2n Client'; |
ce9abb66 | 3524 | $confighash{$key}[26] = 'red'; |
350f2980 SS |
3525 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; |
3526 | $confighash{$key}[28] = $n2nproto[0]; | |
3527 | $confighash{$key}[29] = $n2nport[1]; | |
3528 | $confighash{$key}[30] = $complzoactive; | |
3529 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
4c962356 EK |
3530 | $confighash{$key}[39] = $n2nauth[1]; |
3531 | $confighash{$key}[40] = $n2ncipher[1]; | |
49abe7af | 3532 | $confighash{$key}[41] = 'disabled'; |
ce9abb66 AH |
3533 | |
3534 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
d96c89eb | 3535 | |
ce9abb66 AH |
3536 | N2N_ERROR: |
3537 | ||
3538 | &Header::showhttpheaders(); | |
3539 | &Header::openpage('Validate imported configuration', 1, ''); | |
3540 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3541 | if ($errormessage) { | |
3542 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3543 | print "<class name='base'>$errormessage"; | |
3544 | print " </class>"; | |
3545 | &Header::closebox(); | |
3546 | ||
3547 | } else | |
3548 | { | |
3549 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
3550 | } | |
3551 | if ($errormessage eq ''){ | |
49abe7af | 3552 | print <<END; |
ce9abb66 AH |
3553 | <!-- ipfire net2net config gui --> |
3554 | <table width='100%'> | |
3555 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
3556 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
3557 | <tr><td> </td><td> </td></tr> | |
3558 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
3559 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
3560 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
4c962356 | 3561 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}:</td><td><b>$confighash{$key}[11]</b></td></tr> |
ce9abb66 AH |
3562 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> |
3563 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
3564 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
3565 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
4c962356 EK |
3566 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b>$confighash{$key}[23]</b></td></tr> |
3567 | <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 | 3568 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
54fd0535 | 3569 | <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr> |
0c4ffc69 | 3570 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn tls auth'}:</td><td><b>$confighash{$key}[39]</b></td></tr> |
4c962356 | 3571 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td><td><b>$confighash{$key}[40]</b></td></tr> |
ce9abb66 AH |
3572 | <tr><td> </td><td> </td></tr> |
3573 | </table> | |
3574 | END | |
3575 | ; | |
3576 | &Header::closebox(); | |
3577 | } | |
3578 | ||
3579 | if ($errormessage) { | |
3580 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3581 | } else { | |
3582 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
3583 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
3584 | print "<input type='hidden' name='KEY' value='$key' />"; | |
3585 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3586 | } | |
3587 | &Header::closebigbox(); | |
3588 | &Header::closepage(); | |
4c962356 | 3589 | exit(0); |
ce9abb66 AH |
3590 | |
3591 | ||
3592 | ## | |
3593 | ### Accept IPFire n2n Package Settings | |
3594 | ### | |
3595 | ||
3596 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3597 | ||
3598 | ### | |
3599 | ### Discard and Rollback IPFire n2n Package Settings | |
3600 | ### | |
3601 | ||
3602 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3603 | ||
3604 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3605 | ||
3606 | if ($confighash{$cgiparams{'KEY'}}) { | |
3607 | ||
3608 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
3609 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3610 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
3611 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
3612 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
3613 | delete $confighash{$cgiparams{'KEY'}}; | |
3614 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3615 | ||
3616 | } else { | |
3617 | $errormessage = $Lang::tr{'invalid key'}; | |
3618 | } | |
3619 | ||
3620 | ||
3621 | ### | |
7c1d9faf | 3622 | # m.a.d net2net |
ce9abb66 AH |
3623 | ### |
3624 | ||
3625 | ||
3626 | ### | |
3627 | ### Adding a new connection | |
3628 | ### | |
6e13d0a5 MT |
3629 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
3630 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
3631 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
8c877a82 | 3632 | |
6e13d0a5 MT |
3633 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
3634 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3635 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3636 | ||
3637 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
8c877a82 AM |
3638 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
3639 | $errormessage = $Lang::tr{'invalid key'}; | |
3640 | goto VPNCONF_END; | |
3641 | } | |
4c962356 EK |
3642 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; |
3643 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
3644 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
3645 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
3646 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
3647 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
3648 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
3649 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
8c877a82 | 3650 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; |
4c962356 EK |
3651 | $cgiparams{'OVPN_MGMT'} = $confighash{$cgiparams{'KEY'}}[22]; |
3652 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
3653 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
3654 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; | |
3655 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
3656 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
3657 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
3658 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
3659 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
3660 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
3661 | $cgiparams{'CHECK1'} = $confighash{$cgiparams{'KEY'}}[32]; | |
df9b48b7 | 3662 | $name=$cgiparams{'CHECK1'} ; |
4c962356 EK |
3663 | $cgiparams{$name} = $confighash{$cgiparams{'KEY'}}[33]; |
3664 | $cgiparams{'RG'} = $confighash{$cgiparams{'KEY'}}[34]; | |
3665 | $cgiparams{'CCD_DNS1'} = $confighash{$cgiparams{'KEY'}}[35]; | |
3666 | $cgiparams{'CCD_DNS2'} = $confighash{$cgiparams{'KEY'}}[36]; | |
3667 | $cgiparams{'CCD_WINS'} = $confighash{$cgiparams{'KEY'}}[37]; | |
4c962356 EK |
3668 | $cgiparams{'DAUTH'} = $confighash{$cgiparams{'KEY'}}[39]; |
3669 | $cgiparams{'DCIPHER'} = $confighash{$cgiparams{'KEY'}}[40]; | |
49abe7af | 3670 | $cgiparams{'TLSAUTH'} = $confighash{$cgiparams{'KEY'}}[41]; |
8c877a82 | 3671 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
c6c9630e | 3672 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); |
18837a6a | 3673 | |
8c877a82 | 3674 | #A.Marx CCD check iroute field and convert it to decimal |
52d08bcb | 3675 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
3676 | my @temp=(); |
3677 | my %ccdroutehash=(); | |
3678 | my $keypoint=0; | |
5068ac38 AM |
3679 | my $ip; |
3680 | my $cidr; | |
8c877a82 AM |
3681 | if ($cgiparams{'IR'} ne ''){ |
3682 | @temp = split("\n",$cgiparams{'IR'}); | |
3683 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3684 | #find key to use | |
3685 | foreach my $key (keys %ccdroutehash) { | |
3686 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3687 | $keypoint=$key; | |
3688 | delete $ccdroutehash{$key}; | |
3689 | }else{ | |
3690 | $keypoint = &General::findhasharraykey (\%ccdroutehash); | |
3691 | } | |
3692 | } | |
3693 | $ccdroutehash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3694 | my $i=1; | |
3695 | my $val=0; | |
3696 | foreach $val (@temp){ | |
3697 | chomp($val); | |
3698 | $val=~s/\s*$//g; | |
5068ac38 | 3699 | #check if iroute exists in ccdroute or if new iroute is part of an existing one |
8c877a82 AM |
3700 | foreach my $key (keys %ccdroutehash) { |
3701 | foreach my $oldiroute ( 1 .. $#{$ccdroutehash{$key}}){ | |
5068ac38 AM |
3702 | if ($ccdroutehash{$key}[$oldiroute] eq "$val") { |
3703 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3704 | goto VPNCONF_ERROR; | |
3705 | } | |
3706 | my ($ip1,$cidr1) = split (/\//, $val); | |
82c809c7 | 3707 | $ip1 = &General::getnetworkip($ip1,&General::iporsubtocidr($cidr1)); |
5068ac38 AM |
3708 | my ($ip2,$cidr2) = split (/\//, $ccdroutehash{$key}[$oldiroute]); |
3709 | if (&General::IpInSubnet ($ip1,$ip2,$cidr2)){ | |
3710 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3711 | goto VPNCONF_ERROR; | |
3712 | } | |
3713 | ||
8c877a82 AM |
3714 | } |
3715 | } | |
5068ac38 AM |
3716 | if (!&General::validipandmask($val)){ |
3717 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3718 | goto VPNCONF_ERROR; | |
3719 | }else{ | |
3720 | ($ip,$cidr) = split(/\//,$val); | |
3721 | $ip=&General::getnetworkip($ip,&General::iporsubtocidr($cidr)); | |
3722 | $cidr=&General::iporsubtodec($cidr); | |
3723 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3724 | ||
3725 | } | |
8c877a82 AM |
3726 | |
3727 | #check for existing network IP's | |
52d08bcb AM |
3728 | if (&General::IpInSubnet ($ip,$netsettings{GREEN_NETADDRESS},$netsettings{GREEN_NETMASK}) && $netsettings{GREEN_NETADDRESS} ne '0.0.0.0') |
3729 | { | |
3730 | $errormessage=$Lang::tr{'ccd err green'}; | |
3731 | goto VPNCONF_ERROR; | |
3732 | }elsif(&General::IpInSubnet ($ip,$netsettings{RED_NETADDRESS},$netsettings{RED_NETMASK}) && $netsettings{RED_NETADDRESS} ne '0.0.0.0') | |
3733 | { | |
3734 | $errormessage=$Lang::tr{'ccd err red'}; | |
3735 | goto VPNCONF_ERROR; | |
3736 | }elsif(&General::IpInSubnet ($ip,$netsettings{BLUE_NETADDRESS},$netsettings{BLUE_NETMASK}) && $netsettings{BLUE_NETADDRESS} ne '0.0.0.0' && $netsettings{BLUE_NETADDRESS} gt '') | |
3737 | { | |
3738 | $errormessage=$Lang::tr{'ccd err blue'}; | |
3739 | goto VPNCONF_ERROR; | |
3740 | }elsif(&General::IpInSubnet ($ip,$netsettings{ORANGE_NETADDRESS},$netsettings{ORANGE_NETMASK}) && $netsettings{ORANGE_NETADDRESS} ne '0.0.0.0' && $netsettings{ORANGE_NETADDRESS} gt '' ) | |
3741 | { | |
3742 | $errormessage=$Lang::tr{'ccd err orange'}; | |
8c877a82 AM |
3743 | goto VPNCONF_ERROR; |
3744 | } | |
52d08bcb | 3745 | |
8c877a82 AM |
3746 | if (&General::validipandmask($val)){ |
3747 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3748 | }else{ | |
3749 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($ip/$cidr)"; | |
3750 | goto VPNCONF_ERROR; | |
3751 | } | |
3752 | $i++; | |
3753 | } | |
3754 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3755 | &writeserverconf; | |
3756 | }else{ | |
3757 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3758 | foreach my $key (keys %ccdroutehash) { | |
3759 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3760 | delete $ccdroutehash{$key}; | |
3761 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3762 | &writeserverconf; | |
3763 | } | |
3764 | } | |
3765 | } | |
3766 | undef @temp; | |
3767 | #check route field and convert it to decimal | |
8c877a82 AM |
3768 | my $val=0; |
3769 | my $i=1; | |
8c877a82 | 3770 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
52d08bcb AM |
3771 | #find key to use |
3772 | foreach my $key (keys %ccdroute2hash) { | |
3773 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
3774 | $keypoint=$key; | |
3775 | delete $ccdroute2hash{$key}; | |
3776 | }else{ | |
3777 | $keypoint = &General::findhasharraykey (\%ccdroute2hash); | |
3778 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3779 | &writeserverconf; | |
8c877a82 | 3780 | } |
52d08bcb AM |
3781 | } |
3782 | $ccdroute2hash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3783 | if ($cgiparams{'IFROUTE'} eq ''){$cgiparams{'IFROUTE'} = $Lang::tr{'ccd none'};} | |
3784 | @temp = split(/\|/,$cgiparams{'IFROUTE'}); | |
3785 | my %ownnet=(); | |
3786 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
3787 | foreach $val (@temp){ | |
3788 | chomp($val); | |
3789 | $val=~s/\s*$//g; | |
3790 | if ($val eq $Lang::tr{'green'}) | |
3791 | { | |
3792 | $val=$ownnet{GREEN_NETADDRESS}."/".$ownnet{GREEN_NETMASK}; | |
3793 | } | |
3794 | if ($val eq $Lang::tr{'blue'}) | |
3795 | { | |
3796 | $val=$ownnet{BLUE_NETADDRESS}."/".$ownnet{BLUE_NETMASK}; | |
3797 | } | |
3798 | if ($val eq $Lang::tr{'orange'}) | |
3799 | { | |
3800 | $val=$ownnet{ORANGE_NETADDRESS}."/".$ownnet{ORANGE_NETMASK}; | |
3801 | } | |
3802 | my ($ip,$cidr) = split (/\//, $val); | |
3803 | ||
3804 | if ($val ne $Lang::tr{'ccd none'}) | |
3805 | { | |
8c877a82 AM |
3806 | if (! &check_routes_push($val)){$errormessage=$errormessage."Route $val ".$Lang::tr{'ccd err routeovpn2'}." ($val)";goto VPNCONF_ERROR;} |
3807 | if (! &check_ccdroute($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err inuse'}." ($val)" ;goto VPNCONF_ERROR;} | |
3808 | if (! &check_ccdconf($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err routeovpn'}." ($val)";goto VPNCONF_ERROR;} | |
3809 | if (&General::validipandmask($val)){ | |
3810 | $val=$ip."/".&General::iporsubtodec($cidr); | |
3811 | $ccdroute2hash{$keypoint}[$i] = $val; | |
3812 | }else{ | |
3813 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3814 | goto VPNCONF_ERROR; | |
3815 | } | |
52d08bcb AM |
3816 | }else{ |
3817 | $ccdroute2hash{$keypoint}[$i]=''; | |
3818 | } | |
3819 | $i++; | |
3820 | } | |
3821 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
3822 | ||
8c877a82 AM |
3823 | #check dns1 ip |
3824 | if ($cgiparams{'CCD_DNS1'} ne '' && ! &General::validip($cgiparams{'CCD_DNS1'})) { | |
3825 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 1"; | |
3826 | goto VPNCONF_ERROR; | |
3827 | } | |
3828 | #check dns2 ip | |
3829 | if ($cgiparams{'CCD_DNS2'} ne '' && ! &General::validip($cgiparams{'CCD_DNS2'})) { | |
3830 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 2"; | |
3831 | goto VPNCONF_ERROR; | |
3832 | } | |
3833 | #check wins ip | |
3834 | if ($cgiparams{'CCD_WINS'} ne '' && ! &General::validip($cgiparams{'CCD_WINS'})) { | |
3835 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp wins'}; | |
3836 | goto VPNCONF_ERROR; | |
3837 | } | |
52d08bcb | 3838 | } |
8c877a82 AM |
3839 | |
3840 | #CCD End | |
52d08bcb | 3841 | |
8c877a82 | 3842 | |
73735ad9 EK |
3843 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { |
3844 | $errormessage = $Lang::tr{'connection type is invalid'}; | |
3845 | if ($cgiparams{'TYPE'} eq 'net') { | |
3846 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3847 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3848 | goto VPNCONF_ERROR; | |
3849 | } | |
3850 | goto VPNCONF_ERROR; | |
c6c9630e MT |
3851 | } |
3852 | ||
c6c9630e | 3853 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { |
73735ad9 EK |
3854 | $errormessage = $Lang::tr{'name must only contain characters'}; |
3855 | if ($cgiparams{'TYPE'} eq 'net') { | |
3856 | goto VPNCONF_ERROR; | |
3857 | } | |
3858 | goto VPNCONF_ERROR; | |
3859 | } | |
c6c9630e MT |
3860 | |
3861 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
73735ad9 EK |
3862 | $errormessage = $Lang::tr{'name is invalid'}; |
3863 | if ($cgiparams{'TYPE'} eq 'net') { | |
3864 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3865 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3866 | goto VPNCONF_ERROR; | |
3867 | } | |
3868 | goto VPNCONF_ERROR; | |
c6c9630e MT |
3869 | } |
3870 | ||
3871 | if (length($cgiparams{'NAME'}) >60) { | |
73735ad9 EK |
3872 | $errormessage = $Lang::tr{'name too long'}; |
3873 | if ($cgiparams{'TYPE'} eq 'net') { | |
3874 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3875 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3876 | goto VPNCONF_ERROR; | |
3877 | } | |
3878 | goto VPNCONF_ERROR; | |
c6c9630e MT |
3879 | } |
3880 | ||
d96c89eb | 3881 | ### |
7c1d9faf | 3882 | # m.a.d net2net |
d96c89eb AH |
3883 | ### |
3884 | ||
7c1d9faf | 3885 | if ($cgiparams{'TYPE'} eq 'net') { |
ab4cf06c | 3886 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { |
cd0c0a0d | 3887 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
b278daf3 AH |
3888 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3889 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3890 | goto VPNCONF_ERROR; | |
d96c89eb | 3891 | } |
ab4cf06c AM |
3892 | #Bugfix 10357 |
3893 | foreach my $key (sort keys %confighash){ | |
3894 | if ( ($confighash{$key}[22] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1]) || ($confighash{$key}[29] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1])){ | |
54fd0535 MT |
3895 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
3896 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3897 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ab4cf06c AM |
3898 | goto VPNCONF_ERROR; |
3899 | } | |
3900 | } | |
3901 | if ($cgiparams{'DEST_PORT'} eq '') { | |
3902 | $errormessage = $Lang::tr{'invalid port'}; | |
3903 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3904 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
54fd0535 MT |
3905 | goto VPNCONF_ERROR; |
3906 | } | |
d96c89eb | 3907 | |
f48074ba SS |
3908 | # Check if the input for the transfer net is valid. |
3909 | if (!&General::validipandmask($cgiparams{'OVPN_SUBNET'})){ | |
3910 | $errormessage = $Lang::tr{'ccd err invalidnet'}; | |
3911 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3912 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3913 | goto VPNCONF_ERROR; | |
3914 | } | |
3915 | ||
d96c89eb | 3916 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { |
cd0c0a0d | 3917 | $errormessage = $Lang::tr{'openvpn subnet is used'}; |
b278daf3 AH |
3918 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3919 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3920 | goto VPNCONF_ERROR; |
3921 | } | |
3922 | ||
3923 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
cd0c0a0d | 3924 | $errormessage = $Lang::tr{'openvpn mssfix allowed with udp'}; |
b278daf3 AH |
3925 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3926 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3927 | goto VPNCONF_ERROR; |
3928 | } | |
3929 | ||
3930 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
cd0c0a0d | 3931 | $errormessage = $Lang::tr{'openvpn fragment allowed with udp'}; |
b278daf3 AH |
3932 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3933 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3934 | goto VPNCONF_ERROR; |
3935 | } | |
d96c89eb | 3936 | |
7c1d9faf | 3937 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
cd0c0a0d | 3938 | $errormessage = $Lang::tr{'openvpn prefix local subnet'}; |
b278daf3 AH |
3939 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3940 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3941 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3942 | } |
3943 | ||
3944 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
cd0c0a0d | 3945 | $errormessage = $Lang::tr{'openvpn prefix openvpn subnet'}; |
b278daf3 AH |
3946 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3947 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3948 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3949 | } |
3950 | ||
3951 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
cd0c0a0d | 3952 | $errormessage = $Lang::tr{'openvpn prefix remote subnet'}; |
b278daf3 AH |
3953 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3954 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3955 | goto VPNCONF_ERROR; | |
8c252e6a EK |
3956 | } |
3957 | ||
3958 | if ($cgiparams{'DEST_PORT'} <= 1023) { | |
3959 | $errormessage = $Lang::tr{'ovpn port in root range'}; | |
3960 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3961 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3962 | goto VPNCONF_ERROR; | |
3963 | } | |
54fd0535 | 3964 | |
4c962356 | 3965 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c252e6a EK |
3966 | $cgiparams{'OVPN_MGMT'} = $cgiparams{'DEST_PORT'}; |
3967 | } | |
3968 | ||
3969 | if ($cgiparams{'OVPN_MGMT'} <= 1023) { | |
3970 | $errormessage = $Lang::tr{'ovpn mgmt in root range'}; | |
3971 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3972 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3973 | goto VPNCONF_ERROR; | |
b2e75449 MT |
3974 | } |
3975 | #Check if remote subnet is used elsewhere | |
3976 | my ($n2nip,$n2nsub)=split("/",$cgiparams{'REMOTE_SUBNET'}); | |
3977 | $warnmessage=&General::checksubnets('',$n2nip,'ovpn'); | |
3978 | if ($warnmessage){ | |
3979 | $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage; | |
3980 | } | |
7c1d9faf | 3981 | } |
d96c89eb | 3982 | |
ce9abb66 AH |
3983 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
3984 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
3985 | # goto VPNCONF_ERROR; | |
3986 | # } | |
3987 | ||
c6c9630e MT |
3988 | # Check if there is no other entry with this name |
3989 | if (! $cgiparams{'KEY'}) { | |
3990 | foreach my $key (keys %confighash) { | |
3991 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
3992 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3993 | if ($cgiparams{'TYPE'} eq 'net') { |
3994 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3995 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3996 | } | |
c6c9630e | 3997 | goto VPNCONF_ERROR; |
6e13d0a5 | 3998 | } |
c6c9630e MT |
3999 | } |
4000 | } | |
4001 | ||
c125d8a2 | 4002 | # Check if a remote host/IP has been set for the client. |
86228a56 MT |
4003 | if ($cgiparams{'TYPE'} eq 'net') { |
4004 | if ($cgiparams{'SIDE'} ne 'server' && $cgiparams{'REMOTE'} eq '') { | |
4005 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 4006 | |
86228a56 MT |
4007 | # Check if this is a N2N connection and drop temporary config. |
4008 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
4009 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ce9abb66 | 4010 | |
86228a56 MT |
4011 | goto VPNCONF_ERROR; |
4012 | } | |
c125d8a2 | 4013 | |
86228a56 MT |
4014 | # Check if a remote host/IP has been configured - the field can be empty on the server side. |
4015 | if ($cgiparams{'REMOTE'} ne '') { | |
4016 | # Check if the given IP is valid - otherwise check if it is a valid domain. | |
4017 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
4018 | # Check for a valid domain. | |
4019 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
4020 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 4021 | |
86228a56 MT |
4022 | # Check if this is a N2N connection and drop temporary config. |
4023 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
4024 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
c125d8a2 | 4025 | |
86228a56 MT |
4026 | goto VPNCONF_ERROR; |
4027 | } | |
4028 | } | |
6e13d0a5 | 4029 | } |
c6c9630e | 4030 | } |
c125d8a2 | 4031 | |
c6c9630e MT |
4032 | if ($cgiparams{'TYPE'} ne 'host') { |
4033 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
4034 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
b278daf3 AH |
4035 | if ($cgiparams{'TYPE'} eq 'net') { |
4036 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
4037 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
4038 | } | |
c6c9630e MT |
4039 | goto VPNCONF_ERROR;} |
4040 | } | |
4041 | # Check if there is no other entry without IP-address and PSK | |
4042 | if ($cgiparams{'REMOTE'} eq '') { | |
4043 | foreach my $key (keys %confighash) { | |
4044 | if(($cgiparams{'KEY'} ne $key) && | |
4045 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
4046 | $confighash{$key}[10] eq '') { | |
4047 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
4048 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4049 | } |
c6c9630e MT |
4050 | } |
4051 | } | |
ce9abb66 AH |
4052 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
4053 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
4054 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
4055 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
4056 | goto VPNCONF_ERROR; | |
ce9abb66 | 4057 | } |
c6c9630e | 4058 | |
425465ed EK |
4059 | # Check for N2N that OpenSSL maximum of valid days will not be exceeded |
4060 | if ($cgiparams{'TYPE'} eq 'net') { | |
4061 | if ($cgiparams{'DAYS_VALID'} >= '999999') { | |
4062 | $errormessage = $Lang::tr{'invalid input for valid till days'}; | |
4063 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
4064 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
4065 | goto VPNCONF_ERROR; | |
4066 | } | |
4067 | } | |
4068 | ||
c6c9630e MT |
4069 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { |
4070 | $errormessage = $Lang::tr{'invalid input'}; | |
4071 | goto VPNCONF_ERROR; | |
4072 | } | |
4073 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
4074 | $errormessage = $Lang::tr{'invalid input'}; | |
4075 | goto VPNCONF_ERROR; | |
4076 | } | |
4077 | ||
4078 | #fixplausi | |
4079 | if ($cgiparams{'AUTH'} eq 'psk') { | |
4080 | # if (! length($cgiparams{'PSK'}) ) { | |
4081 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
4082 | # goto VPNCONF_ERROR; | |
4083 | # } | |
4084 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
4085 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
4086 | # goto VPNCONF_ERROR; | |
4087 | # } | |
4088 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
4089 | if ($cgiparams{'KEY'}) { | |
4090 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4091 | goto VPNCONF_ERROR; | |
4092 | } | |
2ad1b18b | 4093 | unless (ref ($cgiparams{'FH'})) { |
c6c9630e MT |
4094 | $errormessage = $Lang::tr{'there was no file upload'}; |
4095 | goto VPNCONF_ERROR; | |
4096 | } | |
4097 | ||
4098 | # Move uploaded certificate request to a temporary file | |
4099 | (my $fh, my $filename) = tempfile( ); | |
4100 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4101 | $errormessage = $!; | |
4102 | goto VPNCONF_ERROR; | |
4103 | } | |
6e13d0a5 | 4104 | |
c6c9630e MT |
4105 | # Sign the certificate request and move it |
4106 | # Sign the host certificate request | |
2feacd98 | 4107 | # The system call is safe, because all arguments are passed as an array. |
f6e12093 | 4108 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4109 | '-batch', '-notext', |
4110 | '-in', $filename, | |
4111 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4112 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4113 | if ($?) { | |
4114 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4115 | unlink ($filename); | |
4116 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4117 | &newcleanssldatabase(); | |
4118 | goto VPNCONF_ERROR; | |
4119 | } else { | |
4120 | unlink ($filename); | |
4121 | &deletebackupcert(); | |
4122 | } | |
4123 | ||
2feacd98 SS |
4124 | my @temp = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); |
4125 | my $temp; | |
4126 | ||
4127 | foreach my $line (@temp) { | |
4128 | if ($line =~ /Subject:.*CN\s?=\s?(.*)[\n]/) { | |
4129 | $temp = $1; | |
4130 | $temp =~ s+/Email+, E+; | |
4131 | $temp =~ s/ ST=/ S=/; | |
4132 | ||
4133 | last; | |
4134 | } | |
4135 | } | |
4136 | ||
c6c9630e MT |
4137 | $cgiparams{'CERT_NAME'} = $temp; |
4138 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4139 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4140 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4141 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4142 | goto VPNCONF_ERROR; | |
4143 | } | |
4144 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
4145 | if ($cgiparams{'KEY'}) { | |
4146 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4147 | goto VPNCONF_ERROR; | |
4148 | } | |
2ad1b18b | 4149 | unless (ref ($cgiparams{'FH'})) { |
c6c9630e MT |
4150 | $errormessage = $Lang::tr{'there was no file upload'}; |
4151 | goto VPNCONF_ERROR; | |
4152 | } | |
4153 | # Move uploaded certificate to a temporary file | |
4154 | (my $fh, my $filename) = tempfile( ); | |
4155 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4156 | $errormessage = $!; | |
4157 | goto VPNCONF_ERROR; | |
4158 | } | |
4159 | ||
4160 | # Verify the certificate has a valid CA and move it | |
4161 | my $validca = 0; | |
2feacd98 SS |
4162 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/cacert.pem", "$filename"); |
4163 | if (grep(/: OK/, @test)) { | |
c6c9630e MT |
4164 | $validca = 1; |
4165 | } else { | |
4166 | foreach my $key (keys %cahash) { | |
2feacd98 SS |
4167 | @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem", "$filename"); |
4168 | if (grep(/: OK/, @test)) { | |
c6c9630e MT |
4169 | $validca = 1; |
4170 | } | |
6e13d0a5 | 4171 | } |
c6c9630e MT |
4172 | } |
4173 | if (! $validca) { | |
4174 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
4175 | unlink ($filename); | |
4176 | goto VPNCONF_ERROR; | |
4177 | } else { | |
4178 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4179 | if ($? ne 0) { | |
4180 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
4181 | unlink ($filename); | |
4182 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4183 | } |
c6c9630e MT |
4184 | } |
4185 | ||
2feacd98 SS |
4186 | my @temp = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); |
4187 | my $temp; | |
4188 | ||
4189 | foreach my $line (@temp) { | |
4190 | if ($line =~ /Subject:.*CN\s?=\s?(.*)[\n]/) { | |
4191 | $temp = $1; | |
4192 | $temp =~ s+/Email+, E+; | |
4193 | $temp =~ s/ ST=/ S=/; | |
4194 | ||
4195 | last; | |
4196 | } | |
4197 | } | |
4198 | ||
c6c9630e MT |
4199 | $cgiparams{'CERT_NAME'} = $temp; |
4200 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4201 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4202 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4203 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4204 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4205 | goto VPNCONF_ERROR; | |
4206 | } | |
4207 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
4208 | if ($cgiparams{'KEY'}) { | |
4209 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4210 | goto VPNCONF_ERROR; | |
4211 | } | |
4212 | # Validate input since the form was submitted | |
4213 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
4214 | $errormessage = $Lang::tr{'name too long'}; | |
4215 | goto VPNCONF_ERROR; | |
4216 | } | |
194314b2 | 4217 | if ($cgiparams{'CERT_NAME'} eq '' || $cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { |
c6c9630e MT |
4218 | $errormessage = $Lang::tr{'invalid input for name'}; |
4219 | goto VPNCONF_ERROR; | |
4220 | } | |
4221 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
4222 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
4223 | goto VPNCONF_ERROR; | |
4224 | } | |
4225 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
4226 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
4227 | goto VPNCONF_ERROR; | |
4228 | } | |
4229 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4230 | $errormessage = $Lang::tr{'invalid input for department'}; | |
4231 | goto VPNCONF_ERROR; | |
4232 | } | |
4233 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
4234 | $errormessage = $Lang::tr{'organization too long'}; | |
4235 | goto VPNCONF_ERROR; | |
4236 | } | |
4237 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
4238 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
4239 | goto VPNCONF_ERROR; | |
4240 | } | |
4241 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4242 | $errormessage = $Lang::tr{'invalid input for city'}; | |
4243 | goto VPNCONF_ERROR; | |
4244 | } | |
4245 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4246 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
4247 | goto VPNCONF_ERROR; | |
4248 | } | |
4249 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
4250 | $errormessage = $Lang::tr{'invalid input for country'}; | |
4251 | goto VPNCONF_ERROR; | |
4252 | } | |
4253 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
4254 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
4255 | $errormessage = $Lang::tr{'password too short'}; | |
4256 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4257 | } |
c6c9630e MT |
4258 | } |
4259 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
4260 | $errormessage = $Lang::tr{'passwords do not match'}; | |
4261 | goto VPNCONF_ERROR; | |
4262 | } | |
425465ed | 4263 | if ($cgiparams{'DAYS_VALID'} eq '' && $cgiparams{'DAYS_VALID'} !~ /^[0-9]+$/) { |
f4fbb935 EK |
4264 | $errormessage = $Lang::tr{'invalid input for valid till days'}; |
4265 | goto VPNCONF_ERROR; | |
4266 | } | |
c6c9630e | 4267 | |
425465ed EK |
4268 | # Check for RW that OpenSSL maximum of valid days will not be exceeded |
4269 | if ($cgiparams{'TYPE'} eq 'host') { | |
4270 | if ($cgiparams{'DAYS_VALID'} >= '999999') { | |
4271 | $errormessage = $Lang::tr{'invalid input for valid till days'}; | |
4272 | goto VPNCONF_ERROR; | |
4273 | } | |
4274 | } | |
4275 | ||
beac479f EK |
4276 | # Check for RW if client name is already set |
4277 | if ($cgiparams{'TYPE'} eq 'host') { | |
4278 | foreach my $key (keys %confighash) { | |
4279 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
4280 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
4281 | goto VPNCONF_ERROR; | |
4282 | } | |
4283 | } | |
4284 | } | |
4285 | ||
c6c9630e MT |
4286 | # Replace empty strings with a . |
4287 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
4288 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
4289 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
4290 | ||
4291 | # Create the Host certificate request client | |
4292 | my $pid = open(OPENSSL, "|-"); | |
4293 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
4294 | if ($pid) { # parent | |
4295 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
4296 | print OPENSSL "$state\n"; | |
4297 | print OPENSSL "$city\n"; | |
4298 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
4299 | print OPENSSL "$ou\n"; | |
4300 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
4301 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
4302 | print OPENSSL ".\n"; | |
4303 | print OPENSSL ".\n"; | |
4304 | close (OPENSSL); | |
4305 | if ($?) { | |
4306 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4307 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4308 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4309 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4310 | } |
c6c9630e | 4311 | } else { # child |
badd8c1c | 4312 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 4313 | '-newkey', 'rsa:2048', |
c6c9630e MT |
4314 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", |
4315 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4316 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
4317 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
4318 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4319 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4320 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4321 | } |
c6c9630e MT |
4322 | } |
4323 | ||
4324 | # Sign the host certificate request | |
2feacd98 | 4325 | # The system call is safe, because all arguments are passed as an array. |
f6e12093 | 4326 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4327 | '-batch', '-notext', |
4328 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4329 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4330 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4331 | if ($?) { | |
4332 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4333 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4334 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4335 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4336 | &newcleanssldatabase(); | |
4337 | goto VPNCONF_ERROR; | |
4338 | } else { | |
4339 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4340 | &deletebackupcert(); | |
4341 | } | |
4342 | ||
4343 | # Create the pkcs12 file | |
2feacd98 | 4344 | # The system call is safe, because all arguments are passed as an array. |
c6c9630e MT |
4345 | system('/usr/bin/openssl', 'pkcs12', '-export', |
4346 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
4347 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4348 | '-name', $cgiparams{'NAME'}, | |
4349 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
4350 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
4351 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
4352 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4353 | if ($?) { | |
4354 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4355 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4356 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4357 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4358 | goto VPNCONF_ERROR; | |
4359 | } else { | |
4360 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4361 | } | |
4362 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
4363 | ;# Nothing, just editing | |
4364 | } else { | |
4365 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
4366 | goto VPNCONF_ERROR; | |
4367 | } | |
4368 | ||
4369 | # Check if there is no other entry with this common name | |
4370 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
4371 | foreach my $key (keys %confighash) { | |
4372 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
4373 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
4374 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4375 | } |
c6c9630e MT |
4376 | } |
4377 | } | |
4378 | ||
ab4cf06c | 4379 | # Save the config |
c6c9630e | 4380 | my $key = $cgiparams{'KEY'}; |
8c877a82 | 4381 | |
c6c9630e MT |
4382 | if (! $key) { |
4383 | $key = &General::findhasharraykey (\%confighash); | |
49abe7af | 4384 | foreach my $i (0 .. 43) { $confighash{$key}[$i] = "";} |
c6c9630e | 4385 | } |
8c877a82 AM |
4386 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; |
4387 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
c6c9630e | 4388 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { |
8c877a82 | 4389 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; |
c6c9630e | 4390 | } |
8c877a82 AM |
4391 | |
4392 | $confighash{$key}[3] = $cgiparams{'TYPE'}; | |
c6c9630e | 4393 | if ($cgiparams{'AUTH'} eq 'psk') { |
8c877a82 AM |
4394 | $confighash{$key}[4] = 'psk'; |
4395 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
c6c9630e | 4396 | } else { |
8c877a82 | 4397 | $confighash{$key}[4] = 'cert'; |
c6c9630e | 4398 | } |
ce9abb66 | 4399 | if ($cgiparams{'TYPE'} eq 'net') { |
8c877a82 AM |
4400 | $confighash{$key}[6] = $cgiparams{'SIDE'}; |
4401 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
ce9abb66 | 4402 | } |
4c962356 | 4403 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
8c877a82 | 4404 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; |
4c962356 | 4405 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c877a82 | 4406 | $confighash{$key}[22] = $confighash{$key}[29]; |
4c962356 | 4407 | } else { |
8c877a82 | 4408 | $confighash{$key}[22] = $cgiparams{'OVPN_MGMT'}; |
4c962356 | 4409 | } |
8c877a82 AM |
4410 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
4411 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
4412 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
4413 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
c6c9630e | 4414 | # new fields |
8c877a82 AM |
4415 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; |
4416 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
4417 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
4418 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
4419 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
4420 | $confighash{$key}[32] = $cgiparams{'CHECK1'}; | |
df9b48b7 | 4421 | $name=$cgiparams{'CHECK1'}; |
8c877a82 AM |
4422 | $confighash{$key}[33] = $cgiparams{$name}; |
4423 | $confighash{$key}[34] = $cgiparams{'RG'}; | |
4424 | $confighash{$key}[35] = $cgiparams{'CCD_DNS1'}; | |
4425 | $confighash{$key}[36] = $cgiparams{'CCD_DNS2'}; | |
4426 | $confighash{$key}[37] = $cgiparams{'CCD_WINS'}; | |
4c962356 EK |
4427 | $confighash{$key}[39] = $cgiparams{'DAUTH'}; |
4428 | $confighash{$key}[40] = $cgiparams{'DCIPHER'}; | |
350f2980 | 4429 | |
71af643c MT |
4430 | if (($cgiparams{'TYPE'} eq 'host') && ($cgiparams{'CERT_PASS1'} eq "")) { |
4431 | $confighash{$key}[41] = "no-pass"; | |
4432 | } | |
4433 | ||
c6c9630e | 4434 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
8c877a82 AM |
4435 | |
4436 | if ($cgiparams{'CHECK1'} ){ | |
4437 | ||
4438 | my ($ccdip,$ccdsub)=split "/",$cgiparams{$name}; | |
4439 | my ($a,$b,$c,$d) = split (/\./,$ccdip); | |
df9b48b7 AM |
4440 | if ( -e "${General::swroot}/ovpn/ccd/$confighash{$key}[2]"){ |
4441 | unlink "${General::swroot}/ovpn/ccd/$cgiparams{'CERT_NAME'}"; | |
4442 | } | |
8c877a82 | 4443 | open ( CCDRWCONF,'>',"${General::swroot}/ovpn/ccd/$confighash{$key}[2]") or die "Unable to create clientconfigfile $!"; |
82c809c7 | 4444 | print CCDRWCONF "# OpenVPN clientconfig from ccd extension by Copymaster#\n\n"; |
8c877a82 AM |
4445 | if($cgiparams{'CHECK1'} eq 'dynamic'){ |
4446 | print CCDRWCONF "#This client uses the dynamic pool\n"; | |
4447 | }else{ | |
82c809c7 | 4448 | print CCDRWCONF "#Ip address client and server\n"; |
8c877a82 AM |
4449 | print CCDRWCONF "ifconfig-push $ccdip ".&General::getlastip($ccdip,1)."\n"; |
4450 | } | |
4451 | if ($confighash{$key}[34] eq 'on'){ | |
4452 | print CCDRWCONF "\n#Redirect Gateway: \n#All IP traffic is redirected through the vpn \n"; | |
4453 | print CCDRWCONF "push redirect-gateway\n"; | |
4454 | } | |
52d08bcb | 4455 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 4456 | if ($cgiparams{'IR'} ne ''){ |
82c809c7 | 4457 | print CCDRWCONF "\n#Client routes these networks (behind Client)\n"; |
8c877a82 AM |
4458 | foreach my $key (keys %ccdroutehash){ |
4459 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}){ | |
4460 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
4461 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
4462 | print CCDRWCONF "iroute $a $b\n"; | |
4463 | } | |
4464 | } | |
4465 | } | |
4466 | } | |
52d08bcb | 4467 | if ($cgiparams{'IFROUTE'} eq $Lang::tr{'ccd none'} ){$cgiparams{'IFROUTE'}='';} |
8c877a82 | 4468 | if ($cgiparams{'IFROUTE'} ne ''){ |
82c809c7 | 4469 | print CCDRWCONF "\n#Client gets routes to these networks (behind IPFire)\n"; |
8c877a82 AM |
4470 | foreach my $key (keys %ccdroute2hash){ |
4471 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4472 | foreach my $i ( 1 .. $#{$ccdroute2hash{$key}}){ | |
4473 | if($ccdroute2hash{$key}[$i] eq $Lang::tr{'blue'}){ | |
4474 | my %blue=(); | |
4475 | &General::readhash("${General::swroot}/ethernet/settings", \%blue); | |
52d08bcb | 4476 | print CCDRWCONF "push \"route $blue{BLUE_ADDRESS} $blue{BLUE_NETMASK}\n"; |
8c877a82 AM |
4477 | }elsif($ccdroute2hash{$key}[$i] eq $Lang::tr{'orange'}){ |
4478 | my %orange=(); | |
4479 | &General::readhash("${General::swroot}/ethernet/settings", \%orange); | |
4480 | print CCDRWCONF "push \"route $orange{ORANGE_ADDRESS} $orange{ORANGE_NETMASK}\n"; | |
4481 | }else{ | |
4482 | my ($a,$b)=split (/\//,$ccdroute2hash{$key}[$i]); | |
4483 | print CCDRWCONF "push \"route $a $b\"\n"; | |
4484 | } | |
4485 | } | |
4486 | } | |
4487 | } | |
4488 | } | |
4489 | if(($cgiparams{'CCD_DNS1'} eq '') && ($cgiparams{'CCD_DNS1'} ne '')){ $cgiparams{'CCD_DNS1'} = $cgiparams{'CCD_DNS2'};$cgiparams{'CCD_DNS2'}='';} | |
4490 | if($cgiparams{'CCD_DNS1'} ne ''){ | |
82c809c7 | 4491 | print CCDRWCONF "\n#Client gets these nameservers\n"; |
8c877a82 AM |
4492 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS1'}\" \n"; |
4493 | } | |
4494 | if($cgiparams{'CCD_DNS2'} ne ''){ | |
4495 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS2'}\" \n"; | |
4496 | } | |
4497 | if($cgiparams{'CCD_WINS'} ne ''){ | |
4498 | print CCDRWCONF "\n#Client gets this WINS server\n"; | |
4499 | print CCDRWCONF "push \"dhcp-option WINS $cgiparams{'CCD_WINS'}\" \n"; | |
4500 | } | |
4501 | close CCDRWCONF; | |
4502 | } | |
18837a6a AH |
4503 | |
4504 | ### | |
4505 | # m.a.d n2n begin | |
4506 | ### | |
4507 | ||
4508 | if ($cgiparams{'TYPE'} eq 'net') { | |
4509 | ||
2feacd98 SS |
4510 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { |
4511 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); | |
18837a6a | 4512 | |
2feacd98 SS |
4513 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
4514 | my $key = $cgiparams{'KEY'}; | |
4515 | if (! $key) { | |
4516 | $key = &General::findhasharraykey (\%confighash); | |
4517 | foreach my $i (0 .. 31) { | |
4518 | $confighash{$key}[$i] = ""; | |
4519 | } | |
4520 | } | |
4521 | ||
4522 | $confighash{$key}[0] = 'on'; | |
4523 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
18837a6a | 4524 | |
2feacd98 SS |
4525 | &General::system("/usr/local/bin/openvpnctrl", "-sn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
4526 | } | |
4527 | } | |
18837a6a AH |
4528 | |
4529 | ### | |
4530 | # m.a.d n2n end | |
4531 | ### | |
4532 | ||
c6c9630e MT |
4533 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { |
4534 | $cgiparams{'KEY'} = $key; | |
4535 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
4536 | } | |
4537 | goto VPNCONF_END; | |
6e13d0a5 | 4538 | } else { |
c6c9630e | 4539 | $cgiparams{'ENABLED'} = 'on'; |
54fd0535 MT |
4540 | ### |
4541 | # m.a.d n2n begin | |
4542 | ### | |
4543 | $cgiparams{'MSSFIX'} = 'on'; | |
4544 | $cgiparams{'FRAGMENT'} = '1300'; | |
70900745 | 4545 | $cgiparams{'DAUTH'} = 'SHA512'; |
54fd0535 MT |
4546 | ### |
4547 | # m.a.d n2n end | |
4548 | ### | |
4c962356 | 4549 | $cgiparams{'SIDE'} = 'left'; |
c6c9630e MT |
4550 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { |
4551 | $cgiparams{'AUTH'} = 'psk'; | |
4552 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4553 | $cgiparams{'AUTH'} = 'certfile'; | |
4554 | } else { | |
6e13d0a5 | 4555 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
4556 | } |
4557 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
4558 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
4559 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
4560 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
4561 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
c0a7c9b2 | 4562 | $cgiparams{'DAYS_VALID'} = $vpnsettings{'DAYS_VALID'} = '730'; |
6e13d0a5 | 4563 | } |
c6c9630e | 4564 | |
6e13d0a5 | 4565 | VPNCONF_ERROR: |
6e13d0a5 MT |
4566 | $checked{'ENABLED'}{'off'} = ''; |
4567 | $checked{'ENABLED'}{'on'} = ''; | |
4568 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4569 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4570 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4571 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4572 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4573 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4574 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4575 | |
4576 | ||
6e13d0a5 MT |
4577 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
4578 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
4579 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 4580 | |
6e13d0a5 MT |
4581 | $selected{'SIDE'}{'server'} = ''; |
4582 | $selected{'SIDE'}{'client'} = ''; | |
4583 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
d96c89eb AH |
4584 | |
4585 | $selected{'PROTOCOL'}{'udp'} = ''; | |
4586 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
4587 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
4588 | ||
c6c9630e | 4589 | |
6e13d0a5 MT |
4590 | $checked{'AUTH'}{'psk'} = ''; |
4591 | $checked{'AUTH'}{'certreq'} = ''; | |
4592 | $checked{'AUTH'}{'certgen'} = ''; | |
4593 | $checked{'AUTH'}{'certfile'} = ''; | |
4594 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 4595 | |
6e13d0a5 | 4596 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
c6c9630e | 4597 | |
6e13d0a5 MT |
4598 | $checked{'COMPLZO'}{'off'} = ''; |
4599 | $checked{'COMPLZO'}{'on'} = ''; | |
4600 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 4601 | |
d96c89eb AH |
4602 | $checked{'MSSFIX'}{'off'} = ''; |
4603 | $checked{'MSSFIX'}{'on'} = ''; | |
4604 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4605 | ||
52f61e49 EKD |
4606 | $selected{'DCIPHER'}{'AES-256-GCM'} = ''; |
4607 | $selected{'DCIPHER'}{'AES-192-GCM'} = ''; | |
4608 | $selected{'DCIPHER'}{'AES-128-GCM'} = ''; | |
4c962356 EK |
4609 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
4610 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
4611 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
4612 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4613 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4614 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
4615 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4616 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; | |
4617 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
4618 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4619 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4620 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 4621 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
49abe7af EK |
4622 | # If no cipher has been chossen yet, select |
4623 | # the old default (AES-256-CBC) for compatiblity reasons. | |
4624 | if ($cgiparams{'DCIPHER'} eq '') { | |
4625 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; | |
4626 | } | |
4c962356 | 4627 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
49abe7af EK |
4628 | $selected{'DAUTH'}{'whirlpool'} = ''; |
4629 | $selected{'DAUTH'}{'SHA512'} = ''; | |
4630 | $selected{'DAUTH'}{'SHA384'} = ''; | |
4631 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4632 | $selected{'DAUTH'}{'SHA1'} = ''; | |
49abe7af | 4633 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; |
0c4ffc69 EK |
4634 | $checked{'TLSAUTH'}{'off'} = ''; |
4635 | $checked{'TLSAUTH'}{'on'} = ''; | |
4636 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
49abe7af | 4637 | |
6e13d0a5 MT |
4638 | if (1) { |
4639 | &Header::showhttpheaders(); | |
4c962356 | 4640 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
4641 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
4642 | if ($errormessage) { | |
4643 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4644 | print "<class name='base'>$errormessage"; | |
4645 | print " </class>"; | |
4646 | &Header::closebox(); | |
4647 | } | |
c6c9630e | 4648 | |
6e13d0a5 MT |
4649 | if ($warnmessage) { |
4650 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
4651 | print "<class name='base'>$warnmessage"; | |
4652 | print " </class>"; | |
4653 | &Header::closebox(); | |
4654 | } | |
c6c9630e | 4655 | |
6e13d0a5 | 4656 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 4657 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 4658 | |
6e13d0a5 MT |
4659 | if ($cgiparams{'KEY'}) { |
4660 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
4661 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 4662 | } |
c6c9630e | 4663 | |
6e13d0a5 | 4664 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
8c877a82 | 4665 | print "<table width='100%' border='0'>\n"; |
4c962356 | 4666 | |
e3edceeb | 4667 | print "<tr><td width='14%' class='boldbase'>$Lang::tr{'name'}: <img src='/blob.gif' alt='*' /></td>"; |
8c877a82 | 4668 | |
ce9abb66 | 4669 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 | 4670 | if ($cgiparams{'KEY'}) { |
8c877a82 | 4671 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; |
6e13d0a5 MT |
4672 | } else { |
4673 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
4674 | } | |
c6c9630e MT |
4675 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
4676 | # print "<td><select name='INTERFACE'>"; | |
4677 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
4c962356 EK |
4678 | # if ($netsettings{'BLUE_DEV'} ne '') { |
4679 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
4680 | # } | |
4681 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
4682 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
4683 | # print "</select></td></tr>"; | |
4684 | # print <<END; | |
ce9abb66 AH |
4685 | } else { |
4686 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
4687 | if ($cgiparams{'KEY'}) { | |
4688 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4689 | } else { | |
4690 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
4691 | } | |
52f61e49 EKD |
4692 | |
4693 | # If GCM ciphers are in usage, HMAC menu is disabled | |
4694 | my $hmacdisabled; | |
4695 | if (($confighash{$cgiparams{'KEY'}}[40] eq 'AES-256-GCM') || | |
4696 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-192-GCM') || | |
4697 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-128-GCM')) { | |
4698 | $hmacdisabled = "disabled='disabled'"; | |
4699 | }; | |
4700 | ||
4c962356 | 4701 | print <<END; |
ce9abb66 | 4702 | <td width='25%'> </td> |
f527e53f EK |
4703 | <td width='25%'> </td></tr> |
4704 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> | |
4705 | <td><select name='SIDE'> | |
4706 | <option value='server' $selected{'SIDE'}{'server'}>$Lang::tr{'openvpn server'}</option> | |
4707 | <option value='client' $selected{'SIDE'}{'client'}>$Lang::tr{'openvpn client'}</option> | |
4708 | </select> | |
4709 | </td> | |
4c962356 | 4710 | |
f527e53f EK |
4711 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> |
4712 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td> | |
4713 | </tr> | |
4c962356 | 4714 | |
e3edceeb | 4715 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4716 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> |
4c962356 | 4717 | |
e3edceeb | 4718 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f EK |
4719 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td> |
4720 | </tr> | |
4c962356 | 4721 | |
e3edceeb | 4722 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4723 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td> |
49abe7af | 4724 | |
f527e53f EK |
4725 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
4726 | <td><select name='PROTOCOL'> | |
4727 | <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
4728 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4729 | </tr> | |
4730 | ||
4731 | <tr> | |
e3edceeb | 4732 | <td class='boldbase'>$Lang::tr{'destination port'}: <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4733 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td> |
4c962356 | 4734 | |
e3edceeb | 4735 | <td class='boldbase' nowrap='nowrap'>Management Port ($Lang::tr{'openvpn default'}: <span class="base">$Lang::tr{'destination port'}):</td> |
f527e53f EK |
4736 | <td> <input type='TEXT' name='OVPN_MGMT' VALUE='$cgiparams{'OVPN_MGMT'}'size='5' /></td> |
4737 | </tr> | |
49abe7af | 4738 | |
f527e53f EK |
4739 | <tr><td colspan=4><hr /></td></tr><tr> |
4740 | ||
4741 | <tr> | |
4742 | <td class'base'><b>$Lang::tr{'MTU settings'}</b></td> | |
4743 | </tr> | |
49abe7af | 4744 | |
e3edceeb | 4745 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td> |
f527e53f EK |
4746 | <td><input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></td> |
4747 | <td colspan='2'>$Lang::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td> | |
4748 | </tr> | |
4c962356 | 4749 | |
e3edceeb | 4750 | <tr><td class='boldbase' nowrap='nowrap'>fragment:</td> |
f527e53f EK |
4751 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> |
4752 | <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td> | |
4753 | </tr> | |
4c962356 | 4754 | |
e3edceeb | 4755 | <tr><td class='boldbase' nowrap='nowrap'>mssfix:</td> |
f527e53f EK |
4756 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> |
4757 | <td>$Lang::tr{'openvpn default'}: <span class="base">on</span></td> | |
4758 | </tr> | |
4c962356 | 4759 | |
e3edceeb | 4760 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
f527e53f EK |
4761 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> |
4762 | </tr> | |
2ee746be | 4763 | |
f527e53f EK |
4764 | <tr><td colspan=4><hr /></td></tr><tr> |
4765 | <tr> | |
4766 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}:</b></td> | |
4767 | </tr> | |
4768 | ||
4769 | <tr><td class='boldbase'>$Lang::tr{'cipher'}</td> | |
52f61e49 EKD |
4770 | <td><select name='DCIPHER' id="n2ncipher" required> |
4771 | <option value='AES-256-GCM' $selected{'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang::tr{'bit'})</option> | |
4772 | <option value='AES-192-GCM' $selected{'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang::tr{'bit'})</option> | |
4773 | <option value='AES-128-GCM' $selected{'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang::tr{'bit'})</option> | |
f527e53f EK |
4774 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> |
4775 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> | |
4776 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> | |
f7fb5bc5 | 4777 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'}, $Lang::tr{'default'})</option> |
f527e53f EK |
4778 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> |
4779 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
ea6dd5b0 EK |
4780 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
4781 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4782 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4783 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4784 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4785 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
f527e53f EK |
4786 | </select> |
4787 | </td> | |
4788 | ||
4789 | <td class='boldbase'>$Lang::tr{'ovpn ha'}:</td> | |
52f61e49 | 4790 | <td><select name='DAUTH' id="n2nhmac" $hmacdisabled> |
f527e53f EK |
4791 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
4792 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
4793 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
4794 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
f3dfb261 | 4795 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
f527e53f EK |
4796 | </select> |
4797 | </td> | |
4798 | </tr> | |
4799 | <tr><td colspan=4><hr /></td></tr><tr> | |
4800 | ||
ce9abb66 | 4801 | END |
8c877a82 | 4802 | ; |
ce9abb66 | 4803 | } |
52f61e49 EKD |
4804 | |
4805 | #### JAVA SCRIPT #### | |
4806 | # Validate N2N cipher. If GCM will be used, HMAC menu will be disabled onchange | |
4807 | print<<END; | |
4808 | <script> | |
4809 | var disable_options = false; | |
4810 | document.getElementById('n2ncipher').onchange = function () { | |
4811 | if((this.value == "AES-256-GCM"||this.value == "AES-192-GCM"||this.value == "AES-128-GCM")) { | |
4812 | document.getElementById('n2nhmac').setAttribute('disabled', true); | |
4813 | } else { | |
4814 | document.getElementById('n2nhmac').removeAttribute('disabled'); | |
4815 | } | |
4816 | } | |
4817 | </script> | |
4818 | END | |
4819 | ||
2ee746be | 4820 | #jumper |
e3edceeb | 4821 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'}</td>"; |
8c877a82 | 4822 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr></table>"; |
c6c9630e | 4823 | |
ce9abb66 | 4824 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
4825 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>"; |
4826 | } | |
ce9abb66 | 4827 | |
8c877a82 AM |
4828 | print"</tr></table><br><br>"; |
4829 | #A.Marx CCD new client | |
e81be1e1 | 4830 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 | 4831 | print "<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td colspan='3'><hr><br><b>$Lang::tr{'ccd choose net'}</td></tr><tr><td height='20' colspan='3'></td></tr>"; |
8c877a82 AM |
4832 | my %vpnnet=(); |
4833 | my $vpnip; | |
4834 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); | |
4835 | $vpnip=$vpnnet{'DOVPN_SUBNET'}; | |
4836 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
4837 | my @ccdconf=(); | |
4838 | my $count=0; | |
4839 | my $checked; | |
4840 | $checked{'check1'}{'off'} = ''; | |
4841 | $checked{'check1'}{'on'} = ''; | |
4842 | $checked{'check1'}{$cgiparams{'CHECK1'}} = 'CHECKED'; | |
4843 | print"<tr><td align='center' width='1%' valign='top'><input type='radio' name='CHECK1' value='dynamic' checked /></td><td align='left' valign='top' width='35%'>$Lang::tr{'ccd dynrange'} ($vpnip)</td><td width='30%'>"; | |
4844 | print"</td></tr></table><br><br>"; | |
4845 | my $name=$cgiparams{'CHECK1'}; | |
4846 | $checked{'RG'}{$cgiparams{'RG'}} = 'CHECKED'; | |
4847 | ||
4848 | if (! -z "${General::swroot}/ovpn/ccd.conf"){ | |
4849 | print"<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td width='1%'></td><td width='30%' class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td width='15%' class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' align='center' width='18%'><b>$Lang::tr{'ccd clientip'}</td></tr>"; | |
df9b48b7 | 4850 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
4851 | $count++; |
4852 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
4853 | if ($count % 2){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";} | |
4854 | print"<td align='center' width='1%'><input type='radio' name='CHECK1' value='$ccdconf[0]' $checked{'check1'}{$ccdconf[0]}/></td><td>$ccdconf[0]</td><td width='40%' align='center'>$ccdconf[1]</td><td align='left' width='10%'>"; | |
4855 | &fillselectbox($ccdconf[1],$ccdconf[0],$cgiparams{$name}); | |
4856 | print"</td></tr>"; | |
4857 | } | |
4858 | print "</table><br><br><hr><br><br>"; | |
4859 | } | |
e81be1e1 | 4860 | } |
8c877a82 | 4861 | # ccd end |
6e13d0a5 MT |
4862 | &Header::closebox(); |
4863 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { | |
8c877a82 AM |
4864 | |
4865 | } elsif (! $cgiparams{'KEY'}) { | |
4866 | ||
4867 | ||
6e13d0a5 MT |
4868 | my $disabled=''; |
4869 | my $cakeydisabled=''; | |
4870 | my $cacrtdisabled=''; | |
4871 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
4872 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
8c877a82 | 4873 | |
6e13d0a5 | 4874 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
ce9abb66 AH |
4875 | |
4876 | ||
4877 | if ($cgiparams{'TYPE'} eq 'host') { | |
4878 | ||
49abe7af | 4879 | print <<END; |
6e13d0a5 | 4880 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
54fd0535 | 4881 | |
ce9abb66 AH |
4882 | <tr><td><input type='radio' name='AUTH' value='certreq' $checked{'AUTH'}{'certreq'} $cakeydisabled /></td><td class='base'>$Lang::tr{'upload a certificate request'}</td><td class='base' rowspan='2'><input type='file' name='FH' size='30' $cacrtdisabled></td></tr> |
4883 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
54fd0535 MT |
4884 | <tr><td colspan='3'> </td></tr> |
4885 | <tr><td colspan='3'><hr /></td></tr> | |
4886 | <tr><td colspan='3'> </td></tr> | |
ce9abb66 | 4887 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> |
e3edceeb LS |
4888 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> |
4889 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4890 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4891 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4892 | <tr><td> </td><td class='base'>$Lang::tr{'city'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4893 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
ce9abb66 | 4894 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
6e13d0a5 | 4895 | END |
ce9abb66 AH |
4896 | ; |
4897 | ||
4898 | ### | |
7c1d9faf | 4899 | # m.a.d net2net |
ce9abb66 AH |
4900 | ### |
4901 | ||
4902 | } else { | |
4903 | ||
49abe7af | 4904 | print <<END; |
ce9abb66 AH |
4905 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
4906 | ||
4907 | <tr><td><input type='radio' name='AUTH' value='certgen' $checked{'AUTH'}{'certgen'} $cakeydisabled /></td><td class='base'>$Lang::tr{'generate a certificate'}</td><td> </td></tr> | |
e3edceeb LS |
4908 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> |
4909 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4910 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4911 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4912 | <tr><td> </td><td class='base'>$Lang::tr{'city'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4913 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
ce9abb66 | 4914 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
54fd0535 MT |
4915 | |
4916 | ||
ce9abb66 AH |
4917 | END |
4918 | ; | |
4919 | ||
4920 | } | |
4921 | ||
4922 | ### | |
7c1d9faf | 4923 | # m.a.d net2net |
ce9abb66 | 4924 | ### |
c6c9630e | 4925 | |
6e13d0a5 MT |
4926 | foreach my $country (sort keys %{Countries::countries}) { |
4927 | print "<option value='$Countries::countries{$country}'"; | |
4928 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
4929 | print " selected='selected'"; | |
4930 | } | |
4931 | print ">$country</option>"; | |
4932 | } | |
ce9abb66 | 4933 | ### |
7c1d9faf | 4934 | # m.a.d net2net |
ce9abb66 AH |
4935 | ### |
4936 | ||
4937 | if ($cgiparams{'TYPE'} eq 'host') { | |
49abe7af | 4938 | print <<END; |
f4fbb935 | 4939 | </select></td></tr> |
425465ed | 4940 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td> |
f4fbb935 EK |
4941 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4942 | <tr><td> </td> | |
6e13d0a5 MT |
4943 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
4944 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
f4fbb935 | 4945 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<br>($Lang::tr{'confirmation'})</td> |
6e13d0a5 | 4946 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> |
f4fbb935 EK |
4947 | <tr><td colspan='3'> </td></tr> |
4948 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4949 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
f4fbb935 | 4950 | </table> |
ce9abb66 AH |
4951 | END |
4952 | }else{ | |
49abe7af | 4953 | print <<END; |
f4fbb935 | 4954 | </select></td></tr> |
425465ed | 4955 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td> |
f4fbb935 EK |
4956 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4957 | <tr><td> </td><td> </td><td> </td></tr> | |
4958 | <tr><td> </td><td> </td><td> </td></tr> | |
4959 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4960 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
ce9abb66 AH |
4961 | </table> |
4962 | ||
c6c9630e | 4963 | END |
ce9abb66 AH |
4964 | } |
4965 | ||
4966 | ### | |
7c1d9faf | 4967 | # m.a.d net2net |
ce9abb66 | 4968 | ### |
c6c9630e MT |
4969 | ; |
4970 | &Header::closebox(); | |
8c877a82 AM |
4971 | |
4972 | } | |
e81be1e1 AM |
4973 | |
4974 | #A.Marx CCD new client | |
4975 | if ($cgiparams{'TYPE'} eq 'host') { | |
8c877a82 AM |
4976 | print"<br><br>"; |
4977 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); | |
4978 | ||
8c877a82 AM |
4979 | |
4980 | print <<END; | |
4981 | <table border='0' width='100%'> | |
4982 | <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked{'RG'}{'on'} /></td></tr> | |
4983 | <tr><td colspan='4'><b><br>$Lang::tr{'ccd routes'}</b></td></tr> | |
4984 | <tr><td colspan='4'> </td></tr> | |
4985 | <tr><td valign='top'>$Lang::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'> | |
4986 | END | |
4987 | ||
4988 | if ($cgiparams{'IR'} ne ''){ | |
4989 | print $cgiparams{'IR'}; | |
4990 | }else{ | |
4991 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4992 | foreach my $key (keys %ccdroutehash) { | |
4993 | if( $cgiparams{'NAME'} eq $ccdroutehash{$key}[0]){ | |
4994 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
4995 | if ($ccdroutehash{$key}[$i] ne ''){ | |
4996 | print $ccdroutehash{$key}[$i]."\n"; | |
4997 | } | |
4998 | $cgiparams{'IR'} .= $ccdroutehash{$key}[$i]; | |
4999 | } | |
5000 | } | |
5001 | } | |
c6c9630e | 5002 | } |
8c877a82 AM |
5003 | |
5004 | print <<END; | |
5005 | </textarea></td><td valign='top' colspan='2'>$Lang::tr{'ccd iroutehint'}</td></tr> | |
5006 | <tr><td colspan='4'><br></td></tr> | |
5007 | <tr><td valign='top' rowspan='3'>$Lang::tr{'ccd iroute2'}</td><td align='left' valign='top' rowspan='3'><select name='IFROUTE' style="width: 205px"; size='6' multiple> | |
5008 | END | |
52d08bcb AM |
5009 | |
5010 | my $set=0; | |
5011 | my $selorange=0; | |
5012 | my $selblue=0; | |
5013 | my $selgreen=0; | |
5014 | my $helpblue=0; | |
5015 | my $helporange=0; | |
5016 | my $other=0; | |
df9b48b7 | 5017 | my $none=0; |
52d08bcb AM |
5018 | my @temp=(); |
5019 | ||
8c877a82 | 5020 | our @current = (); |
52d08bcb AM |
5021 | open(FILE, "${General::swroot}/main/routing") ; |
5022 | @current = <FILE>; | |
5023 | close (FILE); | |
5024 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
df9b48b7 AM |
5025 | #check for "none" |
5026 | foreach my $key (keys %ccdroute2hash) { | |
5027 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
5028 | if ($ccdroute2hash{$key}[1] eq ''){ | |
5029 | $none=1; | |
5030 | last; | |
5031 | } | |
5032 | } | |
5033 | } | |
5034 | if ($none ne '1'){ | |
5035 | print"<option>$Lang::tr{'ccd none'}</option>"; | |
5036 | }else{ | |
5037 | print"<option selected>$Lang::tr{'ccd none'}</option>"; | |
5038 | } | |
52d08bcb AM |
5039 | #check if static routes are defined for client |
5040 | foreach my $line (@current) { | |
5041 | chomp($line); | |
5042 | $line=~s/\s*$//g; # remove newline | |
5043 | @temp=split(/\,/,$line); | |
5044 | $temp[1] = '' unless defined $temp[1]; # not always populated | |
5045 | my ($a,$b) = split(/\//,$temp[1]); | |
5046 | $temp[1] = $a."/".&General::iporsubtocidr($b); | |
5047 | foreach my $key (keys %ccdroute2hash) { | |
5048 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
5049 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
5050 | if($ccdroute2hash{$key}[$i] eq $a."/".&General::iporsubtodec($b)){ | |
5051 | $set=1; | |
8c877a82 AM |
5052 | } |
5053 | } | |
8c877a82 | 5054 | } |
52d08bcb AM |
5055 | } |
5056 | if ($set == '1' && $#temp != -1){ print"<option selected>$temp[1]</option>";$set=0;}elsif($set == '0' && $#temp != -1){print"<option>$temp[1]</option>";} | |
5057 | } | |
3a445974 MT |
5058 | |
5059 | my %vpnconfig = (); | |
5060 | &General::readhasharray("${General::swroot}/vpn/config", \%vpnconfig); | |
5061 | foreach my $vpn (keys %vpnconfig) { | |
5062 | # Skip all disabled VPN connections | |
5063 | my $enabled = $vpnconfig{$vpn}[0]; | |
5064 | next unless ($enabled eq "on"); | |
5065 | ||
5066 | my $name = $vpnconfig{$vpn}[1]; | |
5067 | ||
5068 | # Remote subnets | |
5069 | my @networks = split(/\|/, $vpnconfig{$vpn}[11]); | |
5070 | foreach my $network (@networks) { | |
5071 | my $selected = ""; | |
5072 | ||
5073 | foreach my $key (keys %ccdroute2hash) { | |
5074 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
5075 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
5076 | if ($ccdroute2hash{$key}[$i] eq $network) { | |
5077 | $selected = "selected"; | |
5078 | } | |
5079 | } | |
5080 | } | |
5081 | } | |
5082 | ||
5083 | print "<option value=\"$network\" $selected>$name ($network)</option>\n"; | |
5084 | } | |
5085 | } | |
5086 | ||
52d08bcb AM |
5087 | #check if green,blue,orange are defined for client |
5088 | foreach my $key (keys %ccdroute2hash) { | |
5089 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
5090 | $other=1; | |
5091 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
5092 | if ($ccdroute2hash{$key}[$i] eq $netsettings{'GREEN_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'GREEN_NETMASK'})){ | |
5093 | $selgreen=1; | |
5094 | } | |
5095 | if (&haveBlueNet()){ | |
5096 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'})) { | |
5097 | $selblue=1; | |
5098 | } | |
5099 | } | |
5100 | if (&haveOrangeNet()){ | |
5101 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'ORANGE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'ORANGE_NETMASK'}) ) { | |
5102 | $selorange=1; | |
5103 | } | |
5104 | } | |
5105 | } | |
5106 | } | |
5107 | } | |
5108 | if (&haveBlueNet() && $selblue == '1'){ print"<option selected>$Lang::tr{'blue'}</option>";$selblue=0;}elsif(&haveBlueNet() && $selblue == '0'){print"<option>$Lang::tr{'blue'}</option>";} | |
5109 | if (&haveOrangeNet() && $selorange == '1'){ print"<option selected>$Lang::tr{'orange'}</option>";$selorange=0;}elsif(&haveOrangeNet() && $selorange == '0'){print"<option>$Lang::tr{'orange'}</option>";} | |
5110 | if ($selgreen == '1' || $other == '0'){ print"<option selected>$Lang::tr{'green'}</option>";$set=0;}else{print"<option>$Lang::tr{'green'}</option>";}; | |
5111 | ||
49abe7af | 5112 | print<<END; |
8c877a82 AM |
5113 | </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value='$cgiparams{'CCD_DNS1'}' size='30' /></td></tr> |
5114 | <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value='$cgiparams{'CCD_DNS2'}' size='30' /></td></tr> | |
5115 | <tr valign='top'><td valign='top'>WINS:</td><td><input type='TEXT' name='CCD_WINS' value='$cgiparams{'CCD_WINS'}' size='30' /></td></tr></table><br><hr> | |
5116 | ||
5117 | END | |
5118 | ; | |
5119 | &Header::closebox(); | |
e81be1e1 | 5120 | } |
c6c9630e MT |
5121 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5122 | if ($cgiparams{'KEY'}) { | |
5123 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
5124 | } | |
5125 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
5126 | &Header::closebigbox(); | |
5127 | &Header::closepage(); | |
5128 | exit (0); | |
6e13d0a5 | 5129 | } |
c6c9630e | 5130 | VPNCONF_END: |
6e13d0a5 | 5131 | } |
c6c9630e MT |
5132 | |
5133 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
5134 | ### |
5135 | ### Default status page | |
5136 | ### | |
c6c9630e MT |
5137 | %cgiparams = (); |
5138 | %cahash = (); | |
5139 | %confighash = (); | |
5140 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
5141 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
5142 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
5143 | ||
2feacd98 SS |
5144 | open(FILE, "/var/run/ovpnserver.log"); |
5145 | my @status = <FILE>; | |
5146 | close(FILE); | |
c6c9630e MT |
5147 | |
5148 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
8c877a82 AM |
5149 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
5150 | my $ipaddr = <IPADDR>; | |
5151 | close IPADDR; | |
5152 | chomp ($ipaddr); | |
5153 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
5154 | if ($cgiparams{'VPN_IP'} eq '') { | |
5155 | $cgiparams{'VPN_IP'} = $ipaddr; | |
5156 | } | |
5157 | } | |
c6c9630e MT |
5158 | } |
5159 | ||
6e13d0a5 | 5160 | #default setzen |
c6c9630e | 5161 | if ($cgiparams{'DCIPHER'} eq '') { |
4c962356 | 5162 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; |
c6c9630e | 5163 | } |
c6c9630e | 5164 | if ($cgiparams{'DDEST_PORT'} eq '') { |
4c962356 | 5165 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
5166 | } |
5167 | if ($cgiparams{'DMTU'} eq '') { | |
4c962356 EK |
5168 | $cgiparams{'DMTU'} = '1400'; |
5169 | } | |
5170 | if ($cgiparams{'MSSFIX'} eq '') { | |
5171 | $cgiparams{'MSSFIX'} = 'off'; | |
5172 | } | |
5173 | if ($cgiparams{'DAUTH'} eq '') { | |
86308adb EK |
5174 | if (-z "${General::swroot}/ovpn/ovpnconfig") { |
5175 | $cgiparams{'DAUTH'} = 'SHA512'; | |
5176 | } | |
5177 | foreach my $key (keys %confighash) { | |
5178 | if ($confighash{$key}[3] ne 'host') { | |
5179 | $cgiparams{'DAUTH'} = 'SHA512'; | |
5180 | } else { | |
5181 | $cgiparams{'DAUTH'} = 'SHA1'; | |
5182 | } | |
5183 | } | |
5184 | } | |
0c4ffc69 EK |
5185 | if ($cgiparams{'TLSAUTH'} eq '') { |
5186 | $cgiparams{'TLSAUTH'} = 'off'; | |
5187 | } | |
c6c9630e | 5188 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { |
4c962356 | 5189 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e | 5190 | } |
4c962356 | 5191 | $checked{'ENABLED'}{'off'} = ''; |
c6c9630e MT |
5192 | $checked{'ENABLED'}{'on'} = ''; |
5193 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
5194 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
5195 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
5196 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
5197 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
5198 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
5199 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
5200 | |
5201 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
5202 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
5203 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
4c962356 | 5204 | |
52f61e49 EKD |
5205 | $selected{'DCIPHER'}{'AES-256-GCM'} = ''; |
5206 | $selected{'DCIPHER'}{'AES-192-GCM'} = ''; | |
5207 | $selected{'DCIPHER'}{'AES-128-GCM'} = ''; | |
4c962356 EK |
5208 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
5209 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
5210 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
5211 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
5212 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
5213 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
c6c9630e MT |
5214 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; |
5215 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4c962356 EK |
5216 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; |
5217 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
5218 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
5219 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 5220 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
c6c9630e | 5221 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
4c962356 EK |
5222 | |
5223 | $selected{'DAUTH'}{'whirlpool'} = ''; | |
5224 | $selected{'DAUTH'}{'SHA512'} = ''; | |
5225 | $selected{'DAUTH'}{'SHA384'} = ''; | |
5226 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
5227 | $selected{'DAUTH'}{'SHA1'} = ''; |
5228 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
5229 | ||
0c4ffc69 EK |
5230 | $checked{'TLSAUTH'}{'off'} = ''; |
5231 | $checked{'TLSAUTH'}{'on'} = ''; | |
5232 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
5233 | ||
c6c9630e MT |
5234 | $checked{'DCOMPLZO'}{'off'} = ''; |
5235 | $checked{'DCOMPLZO'}{'on'} = ''; | |
5236 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
4c962356 | 5237 | |
d96c89eb AH |
5238 | # m.a.d |
5239 | $checked{'MSSFIX'}{'off'} = ''; | |
5240 | $checked{'MSSFIX'}{'on'} = ''; | |
5241 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 5242 | #new settings |
c6c9630e MT |
5243 | &Header::showhttpheaders(); |
5244 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
5245 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 5246 | |
c6c9630e | 5247 | if ($errormessage) { |
6e13d0a5 MT |
5248 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
5249 | print "<class name='base'>$errormessage\n"; | |
5250 | print " </class>\n"; | |
5251 | &Header::closebox(); | |
c6c9630e | 5252 | } |
6e13d0a5 | 5253 | |
400c8afd EK |
5254 | if ($cryptoerror) { |
5255 | &Header::openbox('100%', 'LEFT', $Lang::tr{'crypto error'}); | |
5256 | print "<class name='base'>$cryptoerror"; | |
5257 | print " </class>"; | |
5258 | &Header::closebox(); | |
5259 | } | |
5260 | ||
5261 | if ($cryptowarning) { | |
5262 | &Header::openbox('100%', 'LEFT', $Lang::tr{'crypto warning'}); | |
5263 | print "<class name='base'>$cryptowarning"; | |
5264 | print " </class>"; | |
5265 | &Header::closebox(); | |
5266 | } | |
5267 | ||
b2e75449 MT |
5268 | if ($warnmessage) { |
5269 | &Header::openbox('100%', 'LEFT', $Lang::tr{'warning messages'}); | |
5270 | print "$warnmessage<br>"; | |
5271 | print "$Lang::tr{'fwdfw warn1'}<br>"; | |
5272 | &Header::closebox(); | |
5273 | print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>"; | |
5274 | &Header::closepage(); | |
5275 | exit 0; | |
5276 | } | |
4d81e0f3 | 5277 | |
c6c9630e MT |
5278 | my $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourred}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'stopped'}</font></b></td></tr></table>"; |
5279 | my $srunning = "no"; | |
5280 | my $activeonrun = ""; | |
5281 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
5282 | $sactive = "<table cellpadding='2' cellspacing='0' bgcolor='${Header::colourgreen}' width='50%'><tr><td align='center'><b><font color='#FFFFFF'>$Lang::tr{'running'}</font></b></td></tr></table>"; |
5283 | $srunning ="yes"; | |
5284 | $activeonrun = ""; | |
c6c9630e | 5285 | } else { |
6e13d0a5 | 5286 | $activeonrun = "disabled='disabled'"; |
c6c9630e | 5287 | } |
afabe9f7 | 5288 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); |
4c962356 | 5289 | print <<END; |
631b67b7 | 5290 | <table width='100%' border='0'> |
c6c9630e MT |
5291 | <form method='post'> |
5292 | <td width='25%'> </td> | |
5293 | <td width='25%'> </td> | |
5294 | <td width='25%'> </td></tr> | |
5295 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
5296 | <td align='left'>$sactive</td> | |
5297 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
8c877a82 | 5298 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> |
c6c9630e MT |
5299 | END |
5300 | ; | |
5301 | if (&haveBlueNet()) { | |
5302 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
5303 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
5304 | } | |
5305 | if (&haveOrangeNet()) { | |
5306 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
5307 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
86308adb EK |
5308 | } |
5309 | ||
5310 | print <<END; | |
5311 | ||
5312 | <tr><td colspan='4'><br></td></tr> | |
5313 | <tr> | |
5314 | <td class'base'><b>$Lang::tr{'net config'}:</b></td> | |
5315 | </tr> | |
5316 | <tr><td colspan='1'><br></td></tr> | |
5317 | ||
4e17adad CS |
5318 | <tr><td class='base' nowrap='nowrap' colspan='2'>$Lang::tr{'local vpn hostname/ip'}:<br /><input type='text' name='VPN_IP' value='$cgiparams{'VPN_IP'}' size='30' /></td> |
5319 | <td class='boldbase' nowrap='nowrap' colspan='2'>$Lang::tr{'ovpn subnet'}<br /><input type='TEXT' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}' size='30' /></td></tr> | |
c6c9630e MT |
5320 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
5321 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
5322 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
5323 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
5324 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
5325 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
bc2b3e94 | 5326 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}' size='5' /></td> |
86308adb EK |
5327 | </tr> |
5328 | ||
5329 | <tr><td colspan='4'><br></td></tr> | |
5330 | <tr> | |
5331 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}:</b></td> | |
5332 | </tr> | |
5333 | <tr><td colspan='1'><br></td></tr> | |
5334 | ||
5335 | <tr> | |
5336 | <td class='base'>$Lang::tr{'ovpn ha'}</td> | |
5337 | <td><select name='DAUTH'> | |
5338 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> | |
5339 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
5340 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
5341 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
5342 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5343 | </select> | |
5344 | </td> | |
f527e53f | 5345 | |
4c962356 EK |
5346 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> |
5347 | <td><select name='DCIPHER'> | |
52f61e49 EKD |
5348 | <option value='AES-256-GCM' $selected{'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang::tr{'bit'})</option> |
5349 | <option value='AES-192-GCM' $selected{'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang::tr{'bit'})</option> | |
5350 | <option value='AES-128-GCM' $selected{'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang::tr{'bit'})</option> | |
4c962356 | 5351 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> |
f527e53f | 5352 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> |
4c962356 EK |
5353 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> |
5354 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'})</option> | |
5355 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> | |
5356 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
4c962356 | 5357 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
ea6dd5b0 EK |
5358 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
5359 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5360 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5361 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5362 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4c962356 EK |
5363 | </select> |
5364 | </td> | |
4c962356 | 5365 | </tr> |
0c4ffc69 EK |
5366 | |
5367 | <tr><td colspan='4'><br></td></tr> | |
5368 | <tr> | |
5369 | <td class='base'>$Lang::tr{'ovpn tls auth'}</td> | |
5370 | <td><input type='checkbox' name='TLSAUTH' $checked{'TLSAUTH'}{'on'} /></td> | |
5371 | </tr> | |
5372 | ||
f7edf97a | 5373 | <tr><td colspan='4'><br><br></td></tr> |
c6c9630e MT |
5374 | END |
5375 | ; | |
5376 | ||
5377 | if ( $srunning eq "yes" ) { | |
8c877a82 AM |
5378 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' />"; |
5379 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5380 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
5381 | print "<input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td></tr>"; | |
c6c9630e | 5382 | } else{ |
8c877a82 AM |
5383 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5384 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5385 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
c6c9630e MT |
5386 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && |
5387 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
5388 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
5389 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
5390 | (( $cgiparams{'ENABLED'} eq 'on') || | |
5391 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
5392 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
8c877a82 | 5393 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td></tr>"; |
c6c9630e | 5394 | } else { |
8c877a82 | 5395 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td></tr>"; |
c6c9630e MT |
5396 | } |
5397 | } | |
5398 | print "</form></table>"; | |
5399 | &Header::closebox(); | |
6e13d0a5 | 5400 | |
c6c9630e | 5401 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { |
ce9abb66 | 5402 | ### |
7c1d9faf | 5403 | # m.a.d net2net |
54fd0535 | 5404 | #<td width='25%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b><br /><img src='/images/null.gif' width='125' height='1' border='0' alt='L2089' /></td> |
ce9abb66 AH |
5405 | ### |
5406 | ||
4c962356 | 5407 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection status and controlc' }); |
c6c9630e | 5408 | ; |
99bfa85c AM |
5409 | my $id = 0; |
5410 | my $gif; | |
f7edf97a | 5411 | my $col1=""; |
5b942f7f | 5412 | my $lastnet; |
c8b51e28 | 5413 | foreach my $key (sort { ncmp ($confighash{$a}[32],$confighash{$b}[32]) } sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) { |
5b942f7f AM |
5414 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]=$Lang::tr{'fwhost OpenVPN N-2-N'};} |
5415 | if ($confighash{$key}[32] eq "dynamic"){$confighash{$key}[32]=$Lang::tr{'ccd dynrange'};} | |
5416 | if($id == 0){ | |
5417 | print"<b>$confighash{$key}[32]</b>"; | |
5418 | print <<END; | |
5419 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5420 | <tr> | |
5421 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5422 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5423 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5424 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
71af643c | 5425 | <th width='5%' class='boldbase' colspan='7' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5426 | </tr> |
5427 | END | |
5428 | } | |
5429 | if ($id > 0 && $lastnet ne $confighash{$key}[32]){ | |
5430 | print "</table><br>"; | |
5431 | print"<b>$confighash{$key}[32]</b>"; | |
5432 | print <<END; | |
5433 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5434 | <tr> | |
5435 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5436 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5437 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5438 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
71af643c | 5439 | <th width='5%' class='boldbase' colspan='7' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5440 | </tr> |
5441 | END | |
5442 | } | |
eff2dbf8 | 5443 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } |
c6c9630e | 5444 | if ($id % 2) { |
99bfa85c AM |
5445 | print "<tr>"; |
5446 | $col="bgcolor='$color{'color20'}'"; | |
bb89e92a | 5447 | } else { |
99bfa85c AM |
5448 | print "<tr>"; |
5449 | $col="bgcolor='$color{'color22'}'"; | |
c6c9630e | 5450 | } |
99bfa85c AM |
5451 | print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>"; |
5452 | print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
8c877a82 AM |
5453 | #if ($confighash{$key}[4] eq 'cert') { |
5454 | #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
5455 | #} else { | |
5456 | #print "<td align='left'> </td>"; | |
5457 | #} | |
2feacd98 SS |
5458 | my @cavalid = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem"); |
5459 | my $cavalid; | |
5460 | ||
5461 | foreach my $line (@cavalid) { | |
5462 | if ($line =~ /Not After : (.*)[\n]/) { | |
5463 | $cavalid = $1; | |
5464 | ||
5465 | last; | |
5466 | } | |
5467 | } | |
5468 | ||
99bfa85c | 5469 | print "<td align='center' $col>$confighash{$key}[25]</td>"; |
f7edf97a AM |
5470 | $col1="bgcolor='${Header::colourred}'"; |
5471 | my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
ce9abb66 | 5472 | |
c6c9630e | 5473 | if ($confighash{$key}[0] eq 'off') { |
f7edf97a AM |
5474 | $col1="bgcolor='${Header::colourblue}'"; |
5475 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
c6c9630e | 5476 | } else { |
ce9abb66 AH |
5477 | |
5478 | ### | |
7c1d9faf | 5479 | # m.a.d net2net |
f7edf97a AM |
5480 | ### |
5481 | ||
b278daf3 | 5482 | if ($confighash{$key}[3] eq 'net') { |
54fd0535 MT |
5483 | |
5484 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
5485 | my @output = ""; | |
5486 | my @tustate = ""; | |
5487 | my $tport = $confighash{$key}[22]; | |
5488 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
5489 | if ($tport ne '') { | |
5490 | $tnet->open('127.0.0.1'); | |
5491 | @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
5492 | @tustate = split(/\,/, $output[1]); | |
5493 | ### | |
5494 | #CONNECTING -- OpenVPN's initial state. | |
5495 | #WAIT -- (Client only) Waiting for initial response from server. | |
5496 | #AUTH -- (Client only) Authenticating with server. | |
5497 | #GET_CONFIG -- (Client only) Downloading configuration options from server. | |
5498 | #ASSIGN_IP -- Assigning IP address to virtual network interface. | |
5499 | #ADD_ROUTES -- Adding routes to system. | |
5500 | #CONNECTED -- Initialization Sequence Completed. | |
5501 | #RECONNECTING -- A restart has occurred. | |
5502 | #EXITING -- A graceful exit is in progress. | |
5503 | #### | |
5504 | ||
ed4b4c19 | 5505 | if (($tustate[1] eq 'CONNECTED') || ($tustate[1] eq 'WAIT')) { |
f7edf97a AM |
5506 | $col1="bgcolor='${Header::colourgreen}'"; |
5507 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5508 | }else { | |
5509 | $col1="bgcolor='${Header::colourred}'"; | |
5510 | $active = "<b><font color='#FFFFFF'>$tustate[1]</font></b>"; | |
5511 | } | |
54fd0535 | 5512 | } |
54fd0535 | 5513 | } |
f7edf97a AM |
5514 | }else { |
5515 | ||
5516 | my $cn; | |
5517 | my @match = (); | |
5518 | foreach my $line (@status) { | |
5519 | chomp($line); | |
5520 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
5521 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
5522 | if ($match[1] ne "Common Name") { | |
5523 | $cn = $match[1]; | |
5524 | } | |
5525 | $cn =~ s/[_]/ /g; | |
5526 | if ($cn eq "$confighash{$key}[2]") { | |
5527 | $col1="bgcolor='${Header::colourgreen}'"; | |
5528 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5529 | } | |
5530 | } | |
5531 | } | |
c6c9630e | 5532 | } |
7c1d9faf | 5533 | } |
ce9abb66 AH |
5534 | |
5535 | ||
4c962356 | 5536 | print <<END; |
f7edf97a | 5537 | <td align='center' $col1>$active</td> |
c6c9630e | 5538 | |
99bfa85c | 5539 | <form method='post' name='frm${key}a'><td align='center' $col> |
96096995 AM |
5540 | <input type='image' name='$Lang::tr{'dl client arch'}' src='/images/openvpn.png' alt='$Lang::tr{'dl client arch'}' title='$Lang::tr{'dl client arch'}' border='0' /> |
5541 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5542 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
5543 | </td></form> |
5544 | END | |
5545 | ; | |
71af643c MT |
5546 | |
5547 | if ($confighash{$key}[41] eq "no-pass") { | |
5548 | print <<END; | |
5549 | <form method='post' name='frm${key}g'><td align='center' $col> | |
5550 | <input type='image' name='$Lang::tr{'dl client arch insecure'}' src='/images/openvpn.png' | |
5551 | alt='$Lang::tr{'dl client arch insecure'}' title='$Lang::tr{'dl client arch insecure'}' border='0' /> | |
5552 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5553 | <input type='hidden' name='MODE' value='insecure' /> | |
5554 | <input type='hidden' name='KEY' value='$key' /> | |
5555 | </td></form> | |
5556 | END | |
5557 | } else { | |
5558 | print "<td $col> </td>"; | |
5559 | } | |
5560 | ||
c6c9630e | 5561 | if ($confighash{$key}[4] eq 'cert') { |
4c962356 | 5562 | print <<END; |
99bfa85c | 5563 | <form method='post' name='frm${key}b'><td align='center' $col> |
c6c9630e MT |
5564 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> |
5565 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
5566 | <input type='hidden' name='KEY' value='$key' /> | |
5567 | </td></form> | |
5568 | END | |
5569 | ; } else { | |
5570 | print "<td> </td>"; | |
5571 | } | |
5572 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
4c962356 | 5573 | print <<END; |
99bfa85c | 5574 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5575 | <input type='image' name='$Lang::tr{'download pkcs12 file'}' src='/images/media-floppy.png' alt='$Lang::tr{'download pkcs12 file'}' title='$Lang::tr{'download pkcs12 file'}' border='0' /> |
c6c9630e MT |
5576 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
5577 | <input type='hidden' name='KEY' value='$key' /> | |
5578 | </td></form> | |
5579 | END | |
5580 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5581 | print <<END; |
99bfa85c | 5582 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5583 | <input type='image' name='$Lang::tr{'download certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' title='$Lang::tr{'download certificate'}' border='0' /> |
c6c9630e MT |
5584 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
5585 | <input type='hidden' name='KEY' value='$key' /> | |
5586 | </td></form> | |
5587 | END | |
5588 | ; } else { | |
5589 | print "<td> </td>"; | |
5590 | } | |
5591 | print <<END | |
99bfa85c | 5592 | <form method='post' name='frm${key}d'><td align='center' $col> |
c6c9630e MT |
5593 | <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' border='0' /> |
5594 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
5595 | <input type='hidden' name='KEY' value='$key' /> | |
5596 | </td></form> | |
5597 | ||
99bfa85c | 5598 | <form method='post' name='frm${key}e'><td align='center' $col> |
c6c9630e MT |
5599 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> |
5600 | <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' width='20' height='20' border='0'/> | |
5601 | <input type='hidden' name='KEY' value='$key' /> | |
5602 | </td></form> | |
99bfa85c | 5603 | <form method='post' name='frm${key}f'><td align='center' $col> |
c6c9630e MT |
5604 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> |
5605 | <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' width='20' height='20' border='0' /> | |
5606 | <input type='hidden' name='KEY' value='$key' /> | |
5607 | </td></form> | |
5608 | </tr> | |
5609 | END | |
5610 | ; | |
5611 | $id++; | |
5b942f7f | 5612 | $lastnet = $confighash{$key}[32]; |
c6c9630e | 5613 | } |
5b942f7f | 5614 | print"</table>"; |
c6c9630e MT |
5615 | ; |
5616 | ||
5617 | # If the config file contains entries, print Key to action icons | |
5618 | if ( $id ) { | |
4c962356 | 5619 | print <<END; |
8c877a82 | 5620 | <table border='0'> |
c6c9630e | 5621 | <tr> |
4c962356 EK |
5622 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
5623 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
5624 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
5625 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5626 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5627 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
5628 | <td class='base'>$Lang::tr{'edit'}</td> | |
5629 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
5630 | <td class='base'>$Lang::tr{'remove'}</td> | |
c6c9630e MT |
5631 | </tr> |
5632 | <tr> | |
4c962356 EK |
5633 | <td> </td> |
5634 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
5635 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
5636 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> | |
5637 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5638 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> | |
5639 | <td class='base'>$Lang::tr{'dl client arch'}</td> | |
5640 | </tr> | |
f7edf97a | 5641 | </table><br> |
c6c9630e MT |
5642 | END |
5643 | ; | |
5644 | } | |
5645 | ||
4c962356 | 5646 | print <<END; |
c6c9630e MT |
5647 | <table width='100%'> |
5648 | <form method='post'> | |
4c962356 EK |
5649 | <tr><td align='right'> |
5650 | <input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
5651 | <input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td> | |
5652 | </tr> | |
c6c9630e MT |
5653 | </form> |
5654 | </table> | |
5655 | END | |
4c962356 EK |
5656 | ; |
5657 | &Header::closebox(); | |
5658 | } | |
fd5ccb2d EK |
5659 | |
5660 | # CA/key listing | |
4c962356 EK |
5661 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}"); |
5662 | print <<END; | |
5663 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5664 | <tr> | |
5665 | <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5666 | <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th> | |
5667 | <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th> | |
5668 | </tr> | |
5669 | END | |
5670 | ; | |
5671 | my $col1="bgcolor='$color{'color22'}'"; | |
f7fb5bc5 | 5672 | my $col2="bgcolor='$color{'color20'}'"; |
c8f50356 | 5673 | # DH parameter line |
f7fb5bc5 | 5674 | my $col3="bgcolor='$color{'color22'}'"; |
fd5ccb2d EK |
5675 | # ta.key line |
5676 | my $col4="bgcolor='$color{'color20'}'"; | |
f7fb5bc5 | 5677 | |
4c962356 | 5678 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { |
2feacd98 SS |
5679 | my @casubject = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/cacert.pem"); |
5680 | my $casubject; | |
5681 | ||
5682 | foreach my $line (@casubject) { | |
5683 | if ($line =~ /Subject: (.*)[\n]/) { | |
5684 | $casubject = $1; | |
5685 | $casubject =~ s+/Email+, E+; | |
5686 | $casubject =~ s/ ST=/ S=/; | |
5687 | ||
5688 | last; | |
5689 | } | |
5690 | } | |
5691 | ||
4c962356 EK |
5692 | print <<END; |
5693 | <tr> | |
5694 | <td class='base' $col1>$Lang::tr{'root certificate'}</td> | |
5695 | <td class='base' $col1>$casubject</td> | |
c8f50356 | 5696 | <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1> |
4c962356 EK |
5697 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> |
5698 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show root certificate'}' title='$Lang::tr{'show root certificate'}' width='20' height='20' border='0' /> | |
c8f50356 EK |
5699 | </form> |
5700 | <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1> | |
4c962356 EK |
5701 | <input type='image' name='$Lang::tr{'download root certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download root certificate'}' title='$Lang::tr{'download root certificate'}' border='0' /> |
5702 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
c8f50356 EK |
5703 | </form> |
5704 | <td width='4%' $col1> </td> | |
5705 | </tr> | |
4c962356 EK |
5706 | END |
5707 | ; | |
5708 | } else { | |
5709 | # display rootcert generation buttons | |
5710 | print <<END; | |
5711 | <tr> | |
5712 | <td class='base' $col1>$Lang::tr{'root certificate'}:</td> | |
5713 | <td class='base' $col1>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5714 | <td colspan='3' $col1> </td> |
5715 | </tr> | |
4c962356 EK |
5716 | END |
5717 | ; | |
5718 | } | |
5719 | ||
5720 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
2feacd98 SS |
5721 | my @hostsubject = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
5722 | my $hostsubject; | |
5723 | ||
5724 | foreach my $line (@hostsubject) { | |
5725 | if ($line =~ /Subject: (.*)[\n]/) { | |
5726 | $hostsubject = $1; | |
5727 | $hostsubject =~ s+/Email+, E+; | |
5728 | $hostsubject =~ s/ ST=/ S=/; | |
5729 | ||
5730 | last; | |
5731 | } | |
5732 | } | |
4c962356 EK |
5733 | |
5734 | print <<END; | |
5735 | <tr> | |
5736 | <td class='base' $col2>$Lang::tr{'host certificate'}</td> | |
5737 | <td class='base' $col2>$hostsubject</td> | |
c8f50356 | 5738 | <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2> |
4c962356 EK |
5739 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> |
5740 | <input type='image' name='$Lang::tr{'show host certificate'}' src='/images/info.gif' alt='$Lang::tr{'show host certificate'}' title='$Lang::tr{'show host certificate'}' width='20' height='20' border='0' /> | |
c8f50356 EK |
5741 | </form> |
5742 | <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2> | |
4c962356 EK |
5743 | <input type='image' name="$Lang::tr{'download host certificate'}" src='/images/media-floppy.png' alt="$Lang::tr{'download host certificate'}" title="$Lang::tr{'download host certificate'}" border='0' /> |
5744 | <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" /> | |
c8f50356 EK |
5745 | </td></form> |
5746 | <td width='4%' $col2> </td> | |
5747 | </tr> | |
4c962356 EK |
5748 | END |
5749 | ; | |
5750 | } else { | |
5751 | # Nothing | |
5752 | print <<END; | |
5753 | <tr> | |
5754 | <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td> | |
5755 | <td class='base' $col2>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5756 | </td><td colspan='3' $col2> </td> |
5757 | </tr> | |
4c962356 EK |
5758 | END |
5759 | ; | |
5760 | } | |
ce9abb66 | 5761 | |
f7fb5bc5 EK |
5762 | # Adding DH parameter to chart |
5763 | if (-f "${General::swroot}/ovpn/ca/dh1024.pem") { | |
b959b9f5 | 5764 | my @dhsubject = &General::system_output("/usr/bin/openssl", "dhparam", "-text", "-in", "${General::swroot}/ovpn/ca/dh1024.pem"); |
2feacd98 | 5765 | my $dhsubject; |
f7fb5bc5 | 5766 | |
2feacd98 SS |
5767 | foreach my $line (@dhsubject) { |
5768 | if ($line =~ / (.*)[\n]/) { | |
5769 | $dhsubject = $1; | |
5770 | ||
5771 | last; | |
5772 | } | |
5773 | } | |
f7fb5bc5 EK |
5774 | |
5775 | print <<END; | |
5776 | <tr> | |
5777 | <td class='base' $col3>$Lang::tr{'dh parameter'}</td> | |
5778 | <td class='base' $col3>$dhsubject</td> | |
c8f50356 | 5779 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> |
f7fb5bc5 EK |
5780 | <input type='hidden' name='ACTION' value='$Lang::tr{'show dh'}' /> |
5781 | <input type='image' name='$Lang::tr{'show dh'}' src='/images/info.gif' alt='$Lang::tr{'show dh'}' title='$Lang::tr{'show dh'}' width='20' height='20' border='0' /> | |
c8f50356 EK |
5782 | </form> |
5783 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> | |
c8f50356 EK |
5784 | </form> |
5785 | <td width='4%' $col3> </td> | |
5786 | </tr> | |
f7fb5bc5 EK |
5787 | END |
5788 | ; | |
5789 | } else { | |
5790 | # Nothing | |
5791 | print <<END; | |
5792 | <tr> | |
5793 | <td width='25%' class='base' $col3>$Lang::tr{'dh parameter'}:</td> | |
5794 | <td class='base' $col3>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5795 | </td><td colspan='3' $col3> </td> |
5796 | </tr> | |
f7fb5bc5 EK |
5797 | END |
5798 | ; | |
5799 | } | |
5800 | ||
fd5ccb2d EK |
5801 | # Adding ta.key to chart |
5802 | if (-f "${General::swroot}/ovpn/certs/ta.key") { | |
2feacd98 SS |
5803 | open(FILE, "${General::swroot}/ovpn/certs/ta.key"); |
5804 | my @tasubject = <FILE>; | |
5805 | close(FILE); | |
5806 | ||
5807 | my $tasubject; | |
5808 | foreach my $line (@tasubject) { | |
5809 | if($line =~ /# (.*)[\n]/) { | |
5810 | $tasubject = $1; | |
5811 | ||
5812 | last; | |
5813 | } | |
5814 | } | |
5815 | ||
fd5ccb2d EK |
5816 | print <<END; |
5817 | ||
5818 | <tr> | |
5819 | <td class='base' $col4>$Lang::tr{'ta key'}</td> | |
5820 | <td class='base' $col4>$tasubject</td> | |
5821 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5822 | <input type='hidden' name='ACTION' value='$Lang::tr{'show tls-auth key'}' /> | |
5823 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show tls-auth key'}' title='$Lang::tr{'show tls-auth key'}' width='20' height='20' border='0' /> | |
5824 | </form> | |
5825 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5826 | <input type='image' name='$Lang::tr{'download tls-auth key'}' src='/images/media-floppy.png' alt='$Lang::tr{'download tls-auth key'}' title='$Lang::tr{'download tls-auth key'}' border='0' /> | |
5827 | <input type='hidden' name='ACTION' value='$Lang::tr{'download tls-auth key'}' /> | |
5828 | </form> | |
5829 | <td width='4%' $col4> </td> | |
5830 | </tr> | |
5831 | END | |
5832 | ; | |
5833 | } else { | |
5834 | # Nothing | |
5835 | print <<END; | |
5836 | <tr> | |
5837 | <td width='25%' class='base' $col4>$Lang::tr{'ta key'}:</td> | |
5838 | <td class='base' $col4>$Lang::tr{'not present'}</td> | |
5839 | <td colspan='3' $col4> </td> | |
5840 | </tr> | |
5841 | END | |
5842 | ; | |
5843 | } | |
5844 | ||
4c962356 EK |
5845 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
5846 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
5847 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; | |
5848 | print "</form></td></tr>\n"; | |
5849 | } | |
5850 | ||
5851 | if (keys %cahash > 0) { | |
5852 | foreach my $key (keys %cahash) { | |
5853 | if (($key + 1) % 2) { | |
5854 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
5855 | } else { | |
5856 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
5857 | } | |
5858 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
5859 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
5860 | print <<END; | |
5861 | <form method='post' name='cafrm${key}a'><td align='center'> | |
5862 | <input type='image' name='$Lang::tr{'show ca certificate'}' src='/images/info.gif' alt='$Lang::tr{'show ca certificate'}' title='$Lang::tr{'show ca certificate'}' border='0' /> | |
5863 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
5864 | <input type='hidden' name='KEY' value='$key' /> | |
5865 | </td></form> | |
5866 | <form method='post' name='cafrm${key}b'><td align='center'> | |
5867 | <input type='image' name='$Lang::tr{'download ca certificate'}' src='/images/media-floppy.png' alt='$Lang::tr{'download ca certificate'}' title='$Lang::tr{'download ca certificate'}' border='0' /> | |
5868 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
5869 | <input type='hidden' name='KEY' value='$key' /> | |
5870 | </td></form> | |
5871 | <form method='post' name='cafrm${key}c'><td align='center'> | |
5872 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
5873 | <input type='image' name='$Lang::tr{'remove ca certificate'}' src='/images/delete.gif' alt='$Lang::tr{'remove ca certificate'}' title='$Lang::tr{'remove ca certificate'}' width='20' height='20' border='0' /> | |
5874 | <input type='hidden' name='KEY' value='$key' /> | |
5875 | </td></form></tr> | |
5876 | END | |
5877 | ; | |
5878 | } | |
5879 | } | |
5880 | ||
5881 | print "</table>"; | |
5882 | ||
5883 | # If the file contains entries, print Key to action icons | |
5884 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
5885 | print <<END; | |
5886 | <table> | |
5887 | <tr> | |
5888 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
5889 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5890 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5891 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> | |
5892 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5893 | </tr> | |
5894 | </table> | |
5895 | END | |
5896 | ; | |
5897 | } | |
ce9abb66 | 5898 | |
4c962356 | 5899 | print <<END |
578f23c8 SS |
5900 | |
5901 | <br><hr><br> | |
5902 | ||
4c962356 | 5903 | <form method='post' enctype='multipart/form-data'> |
578f23c8 SS |
5904 | <table border='0' width='100%'> |
5905 | <tr> | |
5906 | <td colspan='4'><b>$Lang::tr{'upload ca certificate'}</b></td> | |
5907 | </tr> | |
4c962356 | 5908 | |
578f23c8 SS |
5909 | <tr> |
5910 | <td width='10%'>$Lang::tr{'ca name'}:</td> | |
5911 | <td width='30%'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' align='left'></td> | |
5912 | <td width='30%'><input type='file' name='FH' size='25'> | |
5913 | <td width='30%'align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}'></td> | |
5914 | </tr> | |
f527e53f | 5915 | |
578f23c8 SS |
5916 | <tr> |
5917 | <td colspan='3'> </td> | |
5918 | <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> | |
5919 | </tr> | |
5920 | </table> | |
f527e53f | 5921 | |
578f23c8 SS |
5922 | <br> |
5923 | ||
5924 | <table border='0' width='100%'> | |
5925 | <tr> | |
5926 | <td colspan='4'><b>$Lang::tr{'ovpn dh parameters'}</b></td> | |
5927 | </tr> | |
5928 | ||
5929 | <tr> | |
5930 | <td width='40%'>$Lang::tr{'ovpn dh upload'}:</td> | |
5931 | <td width='30%'><input type='file' name='FH' size='25'> | |
5932 | <td width='30%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload dh key'}'></td> | |
5933 | </tr> | |
5934 | ||
5935 | <tr> | |
5936 | <td width='40%'>$Lang::tr{'ovpn dh new key'}:</td> | |
5937 | <td colspan='2' width='60%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
5938 | </tr> | |
5939 | </table> | |
5940 | </form> | |
f527e53f | 5941 | |
578f23c8 | 5942 | <br><hr> |
4c962356 EK |
5943 | END |
5944 | ; | |
5945 | ||
5946 | if ( $srunning eq "yes" ) { | |
5947 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' disabled='disabled' /></div></form>\n"; | |
5948 | } else { | |
5949 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></div></form>\n"; | |
5950 | } | |
5951 | &Header::closebox(); | |
5952 | END | |
5953 | ; | |
5954 | ||
5955 | &Header::closepage(); | |
ce9abb66 | 5956 |