]>
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"; | |
38 | ||
39 | # enable only the following on debugging purpose | |
8c877a82 AM |
40 | #use warnings; |
41 | #use CGI::Carp 'fatalsToBrowser'; | |
6e13d0a5 | 42 | #workaround to suppress a warning when a variable is used only once |
8c877a82 | 43 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); |
6e13d0a5 MT |
44 | undef (@dummy); |
45 | ||
f2fdd0c1 CS |
46 | my %color = (); |
47 | my %mainsettings = (); | |
48 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
49 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
6e13d0a5 MT |
50 | |
51 | ### | |
52 | ### Initialize variables | |
53 | ### | |
e81be1e1 AM |
54 | my %ccdconfhash=(); |
55 | my %ccdroutehash=(); | |
56 | my %ccdroute2hash=(); | |
6e13d0a5 MT |
57 | my %netsettings=(); |
58 | my %cgiparams=(); | |
59 | my %vpnsettings=(); | |
60 | my %checked=(); | |
61 | my %confighash=(); | |
62 | my %cahash=(); | |
63 | my %selected=(); | |
64 | my $warnmessage = ''; | |
65 | my $errormessage = ''; | |
66 | my %settings=(); | |
54fd0535 | 67 | my $routes_push_file = ''; |
df9b48b7 AM |
68 | my $confighost="${General::swroot}/fwhosts/customhosts"; |
69 | my $configgrp="${General::swroot}/fwhosts/customgroups"; | |
70 | my $customnet="${General::swroot}/fwhosts/customnetworks"; | |
71 | my $name; | |
99bfa85c | 72 | my $col=""; |
ffbe77c8 EK |
73 | my $local_serverconf = "${General::swroot}/ovpn/scripts/server.conf.local"; |
74 | my $local_clientconf = "${General::swroot}/ovpn/scripts/client.conf.local"; | |
75 | ||
6e13d0a5 MT |
76 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
77 | $cgiparams{'ENABLED'} = 'off'; | |
78 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
79 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
80 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
81 | $cgiparams{'NAT'} = 'off'; | |
82 | $cgiparams{'COMPRESSION'} = 'off'; | |
83 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
84 | $cgiparams{'ACTION'} = ''; | |
85 | $cgiparams{'CA_NAME'} = ''; | |
4c962356 EK |
86 | $cgiparams{'DH_NAME'} = 'dh1024.pem'; |
87 | $cgiparams{'DHLENGHT'} = ''; | |
6e13d0a5 MT |
88 | $cgiparams{'DHCP_DOMAIN'} = ''; |
89 | $cgiparams{'DHCP_DNS'} = ''; | |
90 | $cgiparams{'DHCP_WINS'} = ''; | |
54fd0535 | 91 | $cgiparams{'ROUTES_PUSH'} = ''; |
6e13d0a5 | 92 | $cgiparams{'DCOMPLZO'} = 'off'; |
a79fa1d6 | 93 | $cgiparams{'MSSFIX'} = ''; |
8c877a82 | 94 | $cgiparams{'number'} = ''; |
2ee746be | 95 | $cgiparams{'PMTU_DISCOVERY'} = ''; |
4c962356 | 96 | $cgiparams{'DCIPHER'} = ''; |
49abe7af EK |
97 | $cgiparams{'DAUTH'} = ''; |
98 | $cgiparams{'TLSAUTH'} = ''; | |
54fd0535 | 99 | $routes_push_file = "${General::swroot}/ovpn/routes_push"; |
ffbe77c8 EK |
100 | |
101 | # Add CCD files if not already presant | |
102 | unless (-e $routes_push_file) { | |
103 | open(RPF, ">$routes_push_file"); | |
104 | close(RPF); | |
105 | } | |
106 | unless (-e "${General::swroot}/ovpn/ccd.conf") { | |
107 | open(CCDC, ">${General::swroot}/ovpn/ccd.conf"); | |
108 | close (CCDC); | |
109 | } | |
110 | unless (-e "${General::swroot}/ovpn/ccdroute") { | |
111 | open(CCDR, ">${General::swroot}/ovpn/ccdroute"); | |
112 | close (CCDR); | |
113 | } | |
114 | unless (-e "${General::swroot}/ovpn/ccdroute2") { | |
115 | open(CCDRT, ">${General::swroot}/ovpn/ccdroute2"); | |
116 | close (CCDRT); | |
117 | } | |
118 | # Add additional configs if not already presant | |
119 | unless (-e "$local_serverconf") { | |
120 | open(LSC, ">$local_serverconf"); | |
121 | close (LSC); | |
122 | } | |
123 | unless (-e "$local_clientconf") { | |
124 | open(LCC, ">$local_clientconf"); | |
125 | close (LCC); | |
126 | } | |
ce9abb66 | 127 | |
6e13d0a5 MT |
128 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
129 | ||
130 | # prepare openvpn config file | |
131 | ### | |
132 | ### Useful functions | |
133 | ### | |
c6c9630e MT |
134 | sub haveOrangeNet |
135 | { | |
13211b21 CS |
136 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} |
137 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
c6c9630e MT |
138 | return 0; |
139 | } | |
140 | ||
141 | sub haveBlueNet | |
142 | { | |
13211b21 | 143 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} |
c6c9630e | 144 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} |
c6c9630e MT |
145 | return 0; |
146 | } | |
147 | ||
148 | sub sizeformat{ | |
149 | my $bytesize = shift; | |
150 | my $i = 0; | |
151 | ||
152 | while(abs($bytesize) >= 1024){ | |
153 | $bytesize=$bytesize/1024; | |
154 | $i++; | |
155 | last if($i==6); | |
156 | } | |
157 | ||
158 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
159 | my $newsize=(int($bytesize*100 +0.5))/100; | |
160 | return("$newsize $units[$i]"); | |
161 | } | |
162 | ||
c6c9630e MT |
163 | sub cleanssldatabase |
164 | { | |
165 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
166 | print FILE "01"; | |
167 | close FILE; | |
168 | } | |
169 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
170 | print FILE ""; | |
171 | close FILE; | |
172 | } | |
173 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
174 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
175 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
176 | } | |
177 | ||
178 | sub newcleanssldatabase | |
179 | { | |
180 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
181 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
182 | print FILE "01"; | |
183 | close FILE; | |
184 | } | |
185 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
186 | system ("touch ${General::swroot}/ovpn/certs/index.txt"); | |
187 | } | |
188 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
189 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
190 | } | |
191 | ||
192 | sub deletebackupcert | |
193 | { | |
194 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
195 | my $hexvalue = <FILE>; | |
196 | chomp $hexvalue; | |
197 | close FILE; | |
198 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
199 | } | |
200 | } | |
4c962356 | 201 | |
c6c9630e | 202 | sub writeserverconf { |
54fd0535 MT |
203 | my %sovpnsettings = (); |
204 | my @temp = (); | |
c6c9630e | 205 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); |
54fd0535 MT |
206 | &read_routepushfile; |
207 | ||
c6c9630e MT |
208 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; |
209 | flock CONF, 2; | |
210 | print CONF "#OpenVPN Server conf\n"; | |
211 | print CONF "\n"; | |
212 | print CONF "daemon openvpnserver\n"; | |
213 | print CONF "writepid /var/run/openvpn.pid\n"; | |
afabe9f7 | 214 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; |
c6c9630e | 215 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; |
79e7688b | 216 | print CONF "dev tun\n"; |
c6c9630e MT |
217 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; |
218 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
a4fd2325 | 219 | print CONF "script-security 3\n"; |
07675dc3 | 220 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; |
6140e7e0 | 221 | print CONF "client-config-dir /var/ipfire/ovpn/ccd\n"; |
c6c9630e | 222 | print CONF "tls-server\n"; |
4c962356 EK |
223 | print CONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; |
224 | print CONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
225 | print CONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 226 | print CONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
c6c9630e MT |
227 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); |
228 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
8c877a82 | 229 | #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; |
4c962356 | 230 | |
2ee746be SS |
231 | # Check if we are using mssfix, fragment or mtu-disc and set the corretct mtu of 1500. |
232 | # If we doesn't use one of them, we can use the configured mtu value. | |
233 | if ($sovpnsettings{'MSSFIX'} eq 'on') | |
79e7688b | 234 | { print CONF "tun-mtu 1500\n"; } |
2ee746be | 235 | elsif ($sovpnsettings{'FRAGMENT'} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') |
79e7688b | 236 | { print CONF "tun-mtu 1500\n"; } |
1647059d | 237 | elsif (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || |
4c962356 EK |
238 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || |
239 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
79e7688b | 240 | { print CONF "tun-mtu 1500\n"; } |
2ee746be | 241 | else |
79e7688b | 242 | { print CONF "tun-mtu $sovpnsettings{'DMTU'}\n"; } |
2ee746be | 243 | |
54fd0535 | 244 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { |
8c877a82 AM |
245 | @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'}); |
246 | foreach (@temp) | |
247 | { | |
248 | @tempovpnsubnet = split("\/",&General::ipcidr2msk($_)); | |
249 | print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n"; | |
250 | } | |
54fd0535 | 251 | } |
8c877a82 AM |
252 | # a.marx ccd |
253 | my %ccdconfhash=(); | |
254 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
255 | foreach my $key (keys %ccdconfhash) { | |
256 | my $a=$ccdconfhash{$key}[1]; | |
257 | my ($b,$c) = split (/\//, $a); | |
258 | print CONF "route $b ".&General::cidrtosub($c)."\n"; | |
259 | } | |
260 | my %ccdroutehash=(); | |
261 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
262 | foreach my $key (keys %ccdroutehash) { | |
263 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
264 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
265 | print CONF "route $a $b\n"; | |
266 | } | |
267 | } | |
268 | # ccd end | |
54fd0535 | 269 | |
8c877a82 | 270 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { |
c6c9630e MT |
271 | print CONF "client-to-client\n"; |
272 | } | |
1de5c945 | 273 | if ($sovpnsettings{MSSFIX} eq 'on') { |
4c962356 | 274 | print CONF "mssfix\n"; |
1de5c945 EK |
275 | } |
276 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { | |
4c962356 | 277 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
a79fa1d6 | 278 | } |
2ee746be | 279 | |
1647059d SS |
280 | # Check if a valid operating mode has been choosen and use it. |
281 | if (($sovpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
282 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
283 | ($sovpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
284 | print CONF "mtu-disc $sovpnsettings{'PMTU_DISCOVERY'}\n"; | |
2ee746be SS |
285 | } |
286 | ||
c6c9630e MT |
287 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
288 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
289 | } | |
290 | print CONF "status-version 1\n"; | |
87fe47e9 | 291 | print CONF "status /var/run/ovpnserver.log 30\n"; |
a4fd2325 | 292 | print CONF "ncp-disable\n"; |
c6c9630e | 293 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
49abe7af EK |
294 | if ($sovpnsettings{'DAUTH'} eq '') { |
295 | print CONF ""; | |
296 | } else { | |
297 | print CONF "auth $sovpnsettings{'DAUTH'}\n"; | |
298 | } | |
299 | if ($sovpnsettings{'TLSAUTH'} eq 'on') { | |
4be45949 | 300 | print CONF "tls-auth ${General::swroot}/ovpn/certs/ta.key\n"; |
49abe7af | 301 | } |
c6c9630e MT |
302 | if ($sovpnsettings{DCOMPLZO} eq 'on') { |
303 | print CONF "comp-lzo\n"; | |
304 | } | |
305 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
306 | print CONF "push \"redirect-gateway def1\"\n"; | |
307 | } | |
308 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
309 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
310 | } | |
311 | ||
312 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
313 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
314 | } | |
315 | ||
316 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
317 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
318 | } | |
319 | ||
320 | if ($sovpnsettings{DHCP_WINS} eq '') { | |
321 | print CONF "max-clients 100\n"; | |
a79fa1d6 | 322 | } |
c6c9630e MT |
323 | if ($sovpnsettings{DHCP_WINS} ne '') { |
324 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; | |
325 | } | |
1d0a260a | 326 | print CONF "tls-verify /usr/lib/openvpn/verify\n"; |
c6c9630e MT |
327 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; |
328 | print CONF "user nobody\n"; | |
329 | print CONF "group nobody\n"; | |
330 | print CONF "persist-key\n"; | |
331 | print CONF "persist-tun\n"; | |
332 | if ($sovpnsettings{LOG_VERB} ne '') { | |
333 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
334 | } else { | |
335 | print CONF "verb 3\n"; | |
ffbe77c8 EK |
336 | } |
337 | # Print server.conf.local if entries exist to server.conf | |
338 | if ( !-z $local_serverconf && $sovpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
339 | open (LSC, "$local_serverconf"); | |
340 | print CONF "\n#---------------------------\n"; | |
341 | print CONF "# Start of custom directives\n"; | |
342 | print CONF "# from server.conf.local\n"; | |
343 | print CONF "#---------------------------\n\n"; | |
344 | while (<LSC>) { | |
345 | print CONF $_; | |
346 | } | |
347 | print CONF "\n#-----------------------------\n"; | |
348 | print CONF "# End of custom directives\n"; | |
349 | print CONF "#-----------------------------\n"; | |
350 | close (LSC); | |
351 | } | |
c6c9630e MT |
352 | print CONF "\n"; |
353 | ||
354 | close(CONF); | |
355 | } | |
8c877a82 | 356 | |
c6c9630e | 357 | sub emptyserverlog{ |
87fe47e9 | 358 | if (open(FILE, ">/var/run/ovpnserver.log")) { |
c6c9630e MT |
359 | flock FILE, 2; |
360 | print FILE ""; | |
361 | close FILE; | |
362 | } | |
363 | ||
364 | } | |
365 | ||
8c877a82 AM |
366 | sub delccdnet |
367 | { | |
368 | my %ccdconfhash = (); | |
369 | my %ccdhash = (); | |
370 | my $ccdnetname=$_[0]; | |
371 | if (-f "${General::swroot}/ovpn/ovpnconfig"){ | |
372 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
373 | foreach my $key (keys %ccdhash) { | |
374 | if ($ccdhash{$key}[32] eq $ccdnetname) { | |
375 | $errormessage=$Lang::tr{'ccd err hostinnet'}; | |
376 | return; | |
377 | } | |
378 | } | |
379 | } | |
380 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
381 | foreach my $key (keys %ccdconfhash) { | |
382 | if ($ccdconfhash{$key}[0] eq $ccdnetname){ | |
383 | delete $ccdconfhash{$key}; | |
384 | } | |
385 | } | |
386 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
387 | ||
388 | &writeserverconf; | |
389 | return 0; | |
390 | } | |
391 | ||
392 | sub addccdnet | |
393 | { | |
394 | my %ccdconfhash=(); | |
395 | my @ccdconf=(); | |
396 | my $ccdname=$_[0]; | |
397 | my $ccdnet=$_[1]; | |
8c877a82 AM |
398 | my $subcidr; |
399 | my @ip2=(); | |
400 | my $checkup; | |
401 | my $ccdip; | |
402 | my $baseaddress; | |
290007b3 AM |
403 | |
404 | ||
405 | #check name | |
406 | if ($ccdname eq '') | |
407 | { | |
408 | $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>"; | |
409 | return | |
410 | } | |
411 | ||
412 | if(!&General::validhostname($ccdname)) | |
413 | { | |
8c877a82 AM |
414 | $errormessage=$Lang::tr{'ccd err invalidname'}; |
415 | return; | |
416 | } | |
290007b3 AM |
417 | |
418 | ($ccdip,$subcidr) = split (/\//,$ccdnet); | |
419 | $subcidr=&General::iporsubtocidr($subcidr); | |
420 | #check subnet | |
421 | if ($subcidr > 30) | |
422 | { | |
8c877a82 AM |
423 | $errormessage=$Lang::tr{'ccd err invalidnet'}; |
424 | return; | |
425 | } | |
290007b3 AM |
426 | #check ip |
427 | if (!&General::validipandmask($ccdnet)){ | |
428 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
429 | return; | |
8c877a82 | 430 | } |
290007b3 | 431 | |
e2429e8d | 432 | $errormessage=&General::checksubnets($ccdname,$ccdnet); |
290007b3 | 433 | |
8c877a82 AM |
434 | |
435 | if (!$errormessage) { | |
436 | my %ccdconfhash=(); | |
437 | $baseaddress=&General::getnetworkip($ccdip,$subcidr); | |
438 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
439 | my $key = &General::findhasharraykey (\%ccdconfhash); | |
440 | foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";} | |
441 | $ccdconfhash{$key}[0] = $ccdname; | |
442 | $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr; | |
443 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
444 | &writeserverconf; | |
445 | $cgiparams{'ccdname'}=''; | |
446 | $cgiparams{'ccdsubnet'}=''; | |
447 | return 1; | |
448 | } | |
449 | } | |
450 | ||
451 | sub modccdnet | |
452 | { | |
453 | ||
454 | my $newname=$_[0]; | |
455 | my $oldname=$_[1]; | |
456 | my %ccdconfhash=(); | |
457 | my %ccdhash=(); | |
458 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
459 | foreach my $key (keys %ccdconfhash) { | |
460 | if ($ccdconfhash{$key}[0] eq $oldname) { | |
461 | foreach my $key1 (keys %ccdconfhash) { | |
462 | if ($ccdconfhash{$key1}[0] eq $newname){ | |
463 | $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'}; | |
464 | return; | |
465 | }else{ | |
466 | $ccdconfhash{$key}[0]= $newname; | |
467 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
468 | last; | |
469 | } | |
470 | } | |
471 | } | |
472 | } | |
473 | ||
474 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
475 | foreach my $key (keys %ccdhash) { | |
476 | if ($ccdhash{$key}[32] eq $oldname) { | |
477 | $ccdhash{$key}[32]=$newname; | |
478 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
479 | last; | |
480 | } | |
481 | } | |
482 | ||
483 | return 0; | |
484 | } | |
485 | sub ccdmaxclients | |
486 | { | |
487 | my $ccdnetwork=$_[0]; | |
488 | my @octets=(); | |
489 | my @subnet=(); | |
490 | @octets=split("\/",$ccdnetwork); | |
491 | @subnet= split /\./, &General::cidrtosub($octets[1]); | |
492 | my ($a,$b,$c,$d,$e); | |
493 | $a=256-$subnet[0]; | |
494 | $b=256-$subnet[1]; | |
495 | $c=256-$subnet[2]; | |
496 | $d=256-$subnet[3]; | |
497 | $e=($a*$b*$c*$d)/4; | |
498 | return $e-1; | |
499 | } | |
500 | ||
501 | sub getccdadresses | |
502 | { | |
503 | my $ipin=$_[0]; | |
504 | my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin; | |
505 | my $cidr=$_[1]; | |
506 | chomp($cidr); | |
507 | my $count=$_[2]; | |
508 | my $hasip=$_[3]; | |
509 | chomp($hasip); | |
510 | my @iprange=(); | |
511 | my %ccdhash=(); | |
512 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
d9fe5693 | 513 | $iprange[0]=$ip1.".".$ip2.".".$ip3.".".($ip4+2); |
ac87f371 | 514 | for (my $i=1;$i<=$count;$i++) { |
8c877a82 AM |
515 | my $tmpip=$iprange[$i-1]; |
516 | my $stepper=$i*4; | |
517 | $iprange[$i]= &General::getnextip($tmpip,4); | |
518 | } | |
519 | my $r=0; | |
520 | foreach my $key (keys %ccdhash) { | |
521 | $r=0; | |
522 | foreach my $tmp (@iprange){ | |
523 | my ($net,$sub) = split (/\//,$ccdhash{$key}[33]); | |
524 | if ($net eq $tmp) { | |
525 | if ( $hasip ne $ccdhash{$key}[33] ){ | |
526 | splice (@iprange,$r,1); | |
527 | } | |
528 | } | |
529 | $r++; | |
530 | } | |
531 | } | |
532 | return @iprange; | |
533 | } | |
534 | ||
535 | sub fillselectbox | |
536 | { | |
537 | my $boxname=$_[1]; | |
538 | my ($ccdip,$subcidr) = split("/",$_[0]); | |
539 | my $tz=$_[2]; | |
540 | my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz); | |
541 | print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >"; | |
542 | foreach (@allccdips) { | |
543 | my $ip=$_."/30"; | |
544 | chomp($ip); | |
545 | print "<option value='$ip' "; | |
546 | if ( $ip eq $cgiparams{$boxname} ){ | |
547 | print"selected"; | |
548 | } | |
549 | print ">$ip</option>"; | |
550 | } | |
551 | print "</select>"; | |
552 | } | |
553 | ||
554 | sub hostsinnet | |
555 | { | |
556 | my $name=$_[0]; | |
557 | my %ccdhash=(); | |
558 | my $i=0; | |
559 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
560 | foreach my $key (keys %ccdhash) { | |
561 | if ($ccdhash{$key}[32] eq $name){ $i++;} | |
562 | } | |
563 | return $i; | |
564 | } | |
565 | ||
566 | sub check_routes_push | |
567 | { | |
568 | my $val=$_[0]; | |
569 | my ($ip,$cidr) = split (/\//, $val); | |
570 | ##check for existing routes in routes_push | |
571 | if (-e "${General::swroot}/ovpn/routes_push") { | |
572 | open(FILE,"${General::swroot}/ovpn/routes_push"); | |
573 | while (<FILE>) { | |
574 | $_=~s/\s*$//g; | |
575 | ||
576 | my ($ip2,$cidr2) = split (/\//,"$_"); | |
577 | my $val2=$ip2."/".&General::iporsubtodec($cidr2); | |
578 | ||
579 | if($val eq $val2){ | |
580 | return 0; | |
581 | } | |
582 | #subnetcheck | |
583 | if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){ | |
584 | return 0; | |
585 | } | |
586 | }; | |
587 | close(FILE); | |
588 | } | |
589 | return 1; | |
590 | } | |
591 | ||
592 | sub check_ccdroute | |
593 | { | |
594 | my %ccdroutehash=(); | |
595 | my $val=$_[0]; | |
596 | my ($ip,$cidr) = split (/\//, $val); | |
597 | #check for existing routes in ccdroute | |
598 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
599 | foreach my $key (keys %ccdroutehash) { | |
600 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
601 | if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){ | |
602 | return 0; | |
603 | } | |
604 | my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]); | |
605 | #subnetcheck | |
606 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){ | |
607 | return 0; | |
608 | } | |
609 | } | |
610 | } | |
611 | return 1; | |
612 | } | |
613 | sub check_ccdconf | |
614 | { | |
615 | my %ccdconfhash=(); | |
616 | my $val=$_[0]; | |
617 | my ($ip,$cidr) = split (/\//, $val); | |
618 | #check for existing routes in ccdroute | |
619 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
620 | foreach my $key (keys %ccdconfhash) { | |
621 | if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){ | |
622 | return 0; | |
623 | } | |
624 | my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]); | |
625 | #subnetcheck | |
626 | if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){ | |
627 | return 0; | |
628 | } | |
629 | ||
630 | } | |
631 | return 1; | |
632 | } | |
633 | ||
7c1d9faf AH |
634 | ### |
635 | # m.a.d net2net | |
636 | ### | |
637 | ||
638 | sub validdotmask | |
639 | { | |
640 | my $ipdotmask = $_[0]; | |
641 | if (&General::validip($ipdotmask)) { return 0; } | |
642 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
643 | my $mask = $2; | |
644 | if (($mask =~ /\./ )) { return 0; } | |
645 | return 1; | |
646 | } | |
54fd0535 MT |
647 | |
648 | # ------------------------------------------------------------------- | |
649 | ||
650 | sub write_routepushfile | |
651 | { | |
652 | open(FILE, ">$routes_push_file"); | |
653 | flock(FILE, 2); | |
654 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
655 | print FILE $vpnsettings{'ROUTES_PUSH'}; | |
656 | } | |
657 | close(FILE); | |
658 | } | |
659 | ||
660 | sub read_routepushfile | |
661 | { | |
662 | if (-e "$routes_push_file") { | |
663 | open(FILE,"$routes_push_file"); | |
664 | delete $vpnsettings{'ROUTES_PUSH'}; | |
665 | while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ }; | |
666 | close(FILE); | |
667 | $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 | 668 | |
54fd0535 MT |
669 | } |
670 | } | |
7c1d9faf | 671 | |
775b4494 AM |
672 | sub writecollectdconf { |
673 | my $vpncollectd; | |
674 | my %ccdhash=(); | |
675 | ||
676 | open(COLLECTDVPN, ">${General::swroot}/ovpn/collectd.vpn") or die "Unable to open collectd.vpn: $!"; | |
677 | print COLLECTDVPN "Loadplugin openvpn\n"; | |
678 | print COLLECTDVPN "\n"; | |
679 | print COLLECTDVPN "<Plugin openvpn>\n"; | |
680 | print COLLECTDVPN "Statusfile \"/var/run/ovpnserver.log\"\n"; | |
681 | ||
682 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
683 | foreach my $key (keys %ccdhash) { | |
684 | if ($ccdhash{$key}[0] eq 'on' && $ccdhash{$key}[3] eq 'net') { | |
685 | print COLLECTDVPN "Statusfile \"/var/run/openvpn/$ccdhash{$key}[1]-n2n\"\n"; | |
686 | } | |
687 | } | |
688 | ||
689 | print COLLECTDVPN "</Plugin>\n"; | |
690 | close(COLLECTDVPN); | |
691 | ||
692 | # Reload collectd afterwards | |
693 | system("/usr/local/bin/collectdctrl restart &>/dev/null"); | |
694 | } | |
7c1d9faf | 695 | |
c6c9630e MT |
696 | #hier die refresh page |
697 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
698 | my $refresh = ''; | |
699 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
700 | &Header::showhttpheaders(); | |
701 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
702 | &Header::openbigbox('100%', 'center'); | |
703 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
704 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
705 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
706 | &Header::closebox(); | |
707 | &Header::closebigbox(); | |
708 | &Header::closepage(); | |
709 | exit (0); | |
710 | } | |
711 | ##hier die refresh page | |
712 | ||
6e13d0a5 MT |
713 | |
714 | ### | |
715 | ### OpenVPN Server Control | |
716 | ### | |
717 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
718 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
719 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
720 | #start openvpn server |
721 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 722 | &emptyserverlog(); |
6e13d0a5 MT |
723 | system('/usr/local/bin/openvpnctrl', '-s'); |
724 | } | |
725 | #stop openvpn server | |
726 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
6e13d0a5 | 727 | system('/usr/local/bin/openvpnctrl', '-k'); |
c6c9630e | 728 | &emptyserverlog(); |
6e13d0a5 MT |
729 | } |
730 | # #restart openvpn server | |
8c877a82 | 731 | # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ |
6e13d0a5 | 732 | #workarund, till SIGHUP also works when running as nobody |
8c877a82 AM |
733 | # system('/usr/local/bin/openvpnctrl', '-r'); |
734 | # &emptyserverlog(); | |
735 | # } | |
6e13d0a5 MT |
736 | } |
737 | ||
738 | ### | |
739 | ### Save Advanced options | |
740 | ### | |
741 | ||
742 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
743 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
744 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
745 | #DAN this value has to leave. | |
746 | #new settings for daemon | |
747 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
748 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
749 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
750 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
751 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
752 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
ffbe77c8 | 753 | $vpnsettings{'ADDITIONAL_CONFIGS'} = $cgiparams{'ADDITIONAL_CONFIGS'}; |
6e13d0a5 MT |
754 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; |
755 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
756 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
54fd0535 | 757 | $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'}; |
2ee746be | 758 | $vpnsettings{'PMTU_DISCOVERY'} = $cgiparams{'PMTU_DISCOVERY'}; |
4c962356 | 759 | $vpnsettings{'DAUTH'} = $cgiparams{'DAUTH'}; |
49abe7af | 760 | $vpnsettings{'TLSAUTH'} = $cgiparams{'TLSAUTH'}; |
54fd0535 | 761 | my @temp=(); |
6e13d0a5 | 762 | |
a79fa1d6 JPT |
763 | if ($cgiparams{'FRAGMENT'} eq '') { |
764 | delete $vpnsettings{'FRAGMENT'}; | |
765 | } else { | |
766 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
767 | $errormessage = "Incorrect value, please insert only numbers."; | |
768 | goto ADV_ERROR; | |
769 | } else { | |
770 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
771 | } | |
772 | } | |
49abe7af | 773 | |
a79fa1d6 | 774 | if ($cgiparams{'MSSFIX'} ne 'on') { |
1de5c945 | 775 | delete $vpnsettings{'MSSFIX'}; |
a79fa1d6 JPT |
776 | } else { |
777 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
778 | } | |
2ee746be | 779 | |
1647059d SS |
780 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || |
781 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
782 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
783 | ||
2ee746be SS |
784 | if (($cgiparams{'MSSFIX'} eq 'on') || ($cgiparams{'FRAGMENT'} ne '')) { |
785 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
786 | goto ADV_ERROR; | |
787 | } | |
788 | } | |
789 | ||
6e13d0a5 | 790 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
81da1b01 | 791 | unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { |
6e13d0a5 MT |
792 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; |
793 | goto ADV_ERROR; | |
794 | } | |
795 | } | |
796 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
797 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
798 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
799 | goto ADV_ERROR; | |
800 | } | |
801 | } | |
802 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
803 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
804 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
54fd0535 MT |
805 | goto ADV_ERROR; |
806 | } | |
807 | } | |
808 | if ($cgiparams{'ROUTES_PUSH'} ne ''){ | |
809 | @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'}); | |
810 | undef $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 AM |
811 | |
812 | foreach my $tmpip (@temp) | |
54fd0535 MT |
813 | { |
814 | s/^\s+//g; s/\s+$//g; | |
8c877a82 AM |
815 | |
816 | if ($tmpip) | |
54fd0535 | 817 | { |
8c877a82 AM |
818 | $tmpip=~s/\s*$//g; |
819 | unless (&General::validipandmask($tmpip)) { | |
820 | $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'}; | |
821 | goto ADV_ERROR; | |
54fd0535 | 822 | } |
8c877a82 AM |
823 | my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip)); |
824 | ||
54fd0535 MT |
825 | if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) { |
826 | $errormessage = $Lang::tr{'ovpn errmsg green already pushed'}; | |
8c877a82 AM |
827 | goto ADV_ERROR; |
828 | } | |
829 | # a.marx ccd | |
830 | my %ccdroutehash=(); | |
831 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
832 | foreach my $key (keys %ccdroutehash) { | |
833 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
834 | if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){ | |
835 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
836 | goto ADV_ERROR; | |
837 | } | |
838 | my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]); | |
839 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)){ | |
840 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
841 | goto ADV_ERROR; | |
842 | } | |
843 | } | |
54fd0535 | 844 | } |
8c877a82 AM |
845 | |
846 | # ccd end | |
847 | ||
848 | $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n"; | |
54fd0535 | 849 | } |
8c877a82 AM |
850 | } |
851 | &write_routepushfile; | |
54fd0535 | 852 | undef $vpnsettings{'ROUTES_PUSH'}; |
8e148dc3 NP |
853 | } |
854 | else { | |
855 | undef $vpnsettings{'ROUTES_PUSH'}; | |
856 | &write_routepushfile; | |
6e13d0a5 | 857 | } |
6e13d0a5 MT |
858 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) { |
859 | $errormessage = $Lang::tr{'invalid input for max clients'}; | |
860 | goto ADV_ERROR; | |
861 | } | |
862 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
863 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
864 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
865 | goto ADV_ERROR; | |
866 | } | |
867 | } | |
868 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
869 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
870 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
871 | goto ADV_ERROR; | |
872 | } | |
873 | } | |
874 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
875 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
876 | goto ADV_ERROR; | |
877 | } | |
4be45949 EK |
878 | # Create ta.key for tls-auth if not presant |
879 | if ($cgiparams{'TLSAUTH'} eq 'on') { | |
880 | if ( ! -e "${General::swroot}/ovpn/certs/ta.key") { | |
881 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/certs/ta.key"); | |
882 | if ($?) { | |
883 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
884 | goto ADV_ERROR; | |
885 | } | |
886 | } | |
887 | } | |
6e13d0a5 MT |
888 | |
889 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 890 | &writeserverconf();#hier ok |
6e13d0a5 MT |
891 | } |
892 | ||
ce9abb66 | 893 | ### |
7c1d9faf | 894 | # m.a.d net2net |
ce9abb66 AH |
895 | ### |
896 | ||
897 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
898 | { | |
c6c9630e | 899 | |
ce9abb66 AH |
900 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
901 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
54fd0535 | 902 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
d96c89eb | 903 | my $tunmtu = ''; |
531f0835 AH |
904 | |
905 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
906 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
907 | |
908 | 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: $!"; | |
909 | ||
910 | flock SERVERCONF, 2; | |
7c1d9faf | 911 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
ce9abb66 | 912 | print SERVERCONF "\n"; |
b278daf3 | 913 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
914 | print SERVERCONF "user nobody\n"; |
915 | print SERVERCONF "group nobody\n"; | |
916 | print SERVERCONF "persist-tun\n"; | |
917 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 918 | print SERVERCONF "script-security 2\n"; |
60f396d7 | 919 | print SERVERCONF "# IP/DNS for remote Server Gateway\n"; |
c125d8a2 SS |
920 | |
921 | if ($cgiparams{'REMOTE'} ne '') { | |
ce9abb66 | 922 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
c125d8a2 SS |
923 | } |
924 | ||
b278daf3 | 925 | print SERVERCONF "float\n"; |
60f396d7 | 926 | print SERVERCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 927 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; |
60f396d7 | 928 | print SERVERCONF "# Client Gateway Network\n"; |
54fd0535 | 929 | print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n"; |
2913185a | 930 | print SERVERCONF "up \"/etc/init.d/static-routes start\"\n"; |
60f396d7 | 931 | print SERVERCONF "# tun Device\n"; |
ce9abb66 | 932 | print SERVERCONF "dev tun\n"; |
5795fc1b AM |
933 | print SERVERCONF "#Logfile for statistics\n"; |
934 | print SERVERCONF "status-version 1\n"; | |
87fe47e9 | 935 | print SERVERCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; |
60f396d7 | 936 | print SERVERCONF "# Port and Protokol\n"; |
ce9abb66 | 937 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; |
5795fc1b | 938 | |
60f396d7 AH |
939 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { |
940 | print SERVERCONF "proto tcp-server\n"; | |
941 | print SERVERCONF "# Packet size\n"; | |
d96c89eb | 942 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 943 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 944 | } |
60f396d7 AH |
945 | |
946 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
947 | print SERVERCONF "proto udp\n"; | |
948 | print SERVERCONF "# Paketsize\n"; | |
949 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
950 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
951 | if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
952 | if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; }; | |
d96c89eb | 953 | } |
1647059d SS |
954 | |
955 | # Check if a valid operating mode has been choosen and use it. | |
956 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
957 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
958 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be SS |
959 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { |
960 | if($cgiparams{'MTU'} eq '1500') { | |
961 | print SERVERCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
962 | } | |
963 | } | |
964 | } | |
60f396d7 | 965 | print SERVERCONF "# Auth. Server\n"; |
ce9abb66 AH |
966 | print SERVERCONF "tls-server\n"; |
967 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
968 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
969 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 970 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
b278daf3 | 971 | print SERVERCONF "# Cipher\n"; |
4c962356 | 972 | print SERVERCONF "cipher $cgiparams{'DCIPHER'}\n"; |
49abe7af EK |
973 | if ($cgiparams{'DAUTH'} eq '') { |
974 | print SERVERCONF "auth SHA1\n"; | |
975 | } else { | |
976 | print SERVERCONF "# HMAC algorithm\n"; | |
977 | print SERVERCONF "auth $cgiparams{'DAUTH'}\n"; | |
978 | } | |
ce9abb66 | 979 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 980 | print SERVERCONF "# Enable Compression\n"; |
66298ef2 | 981 | print SERVERCONF "comp-lzo\n"; |
b278daf3 | 982 | } |
60f396d7 | 983 | print SERVERCONF "# Debug Level\n"; |
ce9abb66 | 984 | print SERVERCONF "verb 3\n"; |
b278daf3 | 985 | print SERVERCONF "# Tunnel check\n"; |
ce9abb66 | 986 | print SERVERCONF "keepalive 10 60\n"; |
60f396d7 | 987 | print SERVERCONF "# Start as daemon\n"; |
ce9abb66 AH |
988 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; |
989 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 990 | print SERVERCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
991 | if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
992 | else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 AH |
993 | close(SERVERCONF); |
994 | ||
995 | } | |
996 | ||
997 | ### | |
7c1d9faf | 998 | # m.a.d net2net |
ce9abb66 | 999 | ### |
7c1d9faf | 1000 | |
ce9abb66 AH |
1001 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
1002 | { | |
4c962356 | 1003 | |
ce9abb66 | 1004 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); |
54fd0535 | 1005 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 1006 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
d96c89eb | 1007 | my $tunmtu = ''; |
54fd0535 | 1008 | |
531f0835 AH |
1009 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
1010 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
1011 | |
1012 | 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: $!"; | |
1013 | ||
1014 | flock CLIENTCONF, 2; | |
7c1d9faf | 1015 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 1016 | print CLIENTCONF "#\n"; |
b278daf3 | 1017 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
1018 | print CLIENTCONF "user nobody\n"; |
1019 | print CLIENTCONF "group nobody\n"; | |
1020 | print CLIENTCONF "persist-tun\n"; | |
1021 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 1022 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 1023 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
ce9abb66 | 1024 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 | 1025 | print CLIENTCONF "float\n"; |
60f396d7 | 1026 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 1027 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
60f396d7 | 1028 | print CLIENTCONF "# Server Gateway Network\n"; |
54fd0535 | 1029 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
2913185a | 1030 | print CLIENTCONF "up \"/etc/init.d/static-routes start\"\n"; |
60f396d7 | 1031 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 1032 | print CLIENTCONF "dev tun\n"; |
35a21a25 AM |
1033 | print CLIENTCONF "#Logfile for statistics\n"; |
1034 | print CLIENTCONF "status-version 1\n"; | |
1035 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
60f396d7 | 1036 | print CLIENTCONF "# Port and Protokol\n"; |
ce9abb66 | 1037 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; |
60f396d7 AH |
1038 | |
1039 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
1040 | print CLIENTCONF "proto tcp-client\n"; | |
1041 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 1042 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 1043 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 1044 | } |
60f396d7 AH |
1045 | |
1046 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
1047 | print CLIENTCONF "proto udp\n"; | |
1048 | print CLIENTCONF "# Paketsize\n"; | |
1049 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1050 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
1051 | if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
1052 | if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; }; | |
d96c89eb | 1053 | } |
1647059d SS |
1054 | |
1055 | # Check if a valid operating mode has been choosen and use it. | |
1056 | if (($cgiparams{'PMTU_DISCOVERY'} eq 'yes') || | |
1057 | ($cgiparams{'PMTU_DISCOVERY'} eq 'maybe') || | |
1058 | ($cgiparams{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be SS |
1059 | if(($cgiparams{'MSSFIX'} ne 'on') || ($cgiparams{'FRAGMENT'} eq '')) { |
1060 | if ($cgiparams{'MTU'} eq '1500') { | |
1061 | print CLIENTCONF "mtu-disc $cgiparams{'PMTU_DISCOVERY'}\n"; | |
1062 | } | |
1063 | } | |
1647059d | 1064 | } |
b66b02ab EK |
1065 | # Check host certificate if X509 is RFC3280 compliant. |
1066 | # If not, old --ns-cert-type directive will be used. | |
1067 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
1068 | my $hostcert = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1069 | if ($hostcert !~ /TLS Web Server Authentication/) { | |
1070 | print CLIENTCONF "ns-cert-type server\n"; | |
1071 | } else { | |
1072 | print CLIENTCONF "remote-cert-tls server\n"; | |
1073 | } | |
ce9abb66 AH |
1074 | print CLIENTCONF "# Auth. Client\n"; |
1075 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 1076 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 1077 | print CLIENTCONF "cipher $cgiparams{'DCIPHER'}\n"; |
ce9abb66 | 1078 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; |
49abe7af EK |
1079 | if ($cgiparams{'DAUTH'} eq '') { |
1080 | print CLIENTCONF "auth SHA1\n"; | |
1081 | } else { | |
1082 | print CLIENTCONF "# HMAC algorithm\n"; | |
1083 | print CLIENTCONF "auth $cgiparams{'DAUTH'}\n"; | |
1084 | } | |
ce9abb66 | 1085 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1086 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 1087 | print CLIENTCONF "comp-lzo\n"; |
4c962356 | 1088 | } |
ce9abb66 AH |
1089 | print CLIENTCONF "# Debug Level\n"; |
1090 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 1091 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 1092 | print CLIENTCONF "keepalive 10 60\n"; |
60f396d7 | 1093 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
1094 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
1095 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 1096 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
1097 | if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1098 | else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 | 1099 | close(CLIENTCONF); |
c6c9630e | 1100 | |
ce9abb66 AH |
1101 | } |
1102 | ||
6e13d0a5 MT |
1103 | ### |
1104 | ### Save main settings | |
1105 | ### | |
ce9abb66 | 1106 | |
6e13d0a5 MT |
1107 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
1108 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
1109 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
1110 | #DAN this value has to leave. | |
1111 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1112 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
1113 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 1114 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1115 | } |
1116 | } | |
f7fb5bc5 | 1117 | |
6e13d0a5 | 1118 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { |
c6c9630e | 1119 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
4c962356 | 1120 | goto SETTINGS_ERROR; |
c6c9630e MT |
1121 | } |
1122 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
1123 | ||
1124 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
1125 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1126 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
1127 | goto SETTINGS_ERROR; | |
1128 | } | |
1129 | ||
1130 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
1131 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1132 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
1133 | goto SETTINGS_ERROR; | |
1134 | } | |
1135 | ||
1136 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
1137 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1138 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
1139 | goto SETTINGS_ERROR; | |
1140 | } | |
1141 | ||
1142 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
1143 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1144 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
1145 | goto SETTINGS_ERROR; | |
1146 | } | |
1147 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
1148 | while (<ALIASES>) | |
1149 | { | |
1150 | chomp($_); | |
1151 | my @tempalias = split(/\,/,$_); | |
1152 | if ($tempalias[1] eq 'on') { | |
1153 | if (&General::IpInSubnet ($tempalias[0] , | |
1154 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1155 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
1156 | } | |
1157 | } | |
1158 | } | |
1159 | close(ALIASES); | |
6e13d0a5 | 1160 | if ($errormessage ne ''){ |
c6c9630e | 1161 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1162 | } |
1163 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
1164 | $errormessage = $Lang::tr{'invalid input'}; | |
1165 | goto SETTINGS_ERROR; | |
1166 | } | |
1167 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
1168 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
1169 | goto SETTINGS_ERROR; | |
1170 | } | |
1171 | ||
1172 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
c6c9630e MT |
1173 | $errormessage = $Lang::tr{'invalid port'}; |
1174 | goto SETTINGS_ERROR; | |
6e13d0a5 | 1175 | } |
8c252e6a | 1176 | |
6e13d0a5 MT |
1177 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
1178 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
1179 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
1180 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
1181 | #new settings for daemon | |
1182 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
6e13d0a5 MT |
1183 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; |
1184 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
1185 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
1186 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
1187 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
3ffee04b CS |
1188 | #wrtie enable |
1189 | ||
1190 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_blue 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_blue 2>/dev/null");} | |
1191 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable_orange 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable_orange 2>/dev/null");} | |
1192 | if ( $vpnsettings{'ENABLED'} eq 'on' ) {system("touch ${General::swroot}/ovpn/enable 2>/dev/null");}else{system("unlink ${General::swroot}/ovpn/enable 2>/dev/null");} | |
6e13d0a5 MT |
1193 | #new settings for daemon |
1194 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 1195 | &writeserverconf();#hier ok |
6e13d0a5 MT |
1196 | SETTINGS_ERROR: |
1197 | ### | |
1198 | ### Reset all step 2 | |
1199 | ### | |
4c962356 | 1200 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') { |
6e13d0a5 MT |
1201 | my $file = ''; |
1202 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1203 | ||
1e499e90 MT |
1204 | # Kill all N2N connections |
1205 | system("/usr/local/bin/openvpnctrl -kn2n &>/dev/null"); | |
1206 | ||
6e13d0a5 | 1207 | foreach my $key (keys %confighash) { |
2f36a7b4 MT |
1208 | my $name = $confighash{$cgiparams{'$key'}}[1]; |
1209 | ||
c6c9630e MT |
1210 | if ($confighash{$key}[4] eq 'cert') { |
1211 | delete $confighash{$cgiparams{'$key'}}; | |
1212 | } | |
2f36a7b4 MT |
1213 | |
1214 | system ("/usr/local/bin/openvpnctrl -drrd $name"); | |
6e13d0a5 MT |
1215 | } |
1216 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
49abe7af | 1217 | unlink $file; |
6e13d0a5 MT |
1218 | } |
1219 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
49abe7af | 1220 | unlink $file; |
6e13d0a5 MT |
1221 | } |
1222 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
49abe7af | 1223 | unlink $file; |
6e13d0a5 | 1224 | } |
4c962356 | 1225 | &cleanssldatabase(); |
6e13d0a5 MT |
1226 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
1227 | print FILE ""; | |
1228 | close FILE; | |
1229 | } | |
49abe7af EK |
1230 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute")) { |
1231 | print FILE ""; | |
1232 | close FILE; | |
1233 | } | |
1234 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute2")) { | |
1235 | print FILE ""; | |
1236 | close FILE; | |
1237 | } | |
1238 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { | |
1239 | unlink $file | |
1240 | } | |
5795fc1b AM |
1241 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { |
1242 | unlink $file | |
1243 | } | |
49abe7af EK |
1244 | if (open(FILE, ">${General::swroot}/ovpn/ovpn-leases.db")) { |
1245 | print FILE ""; | |
1246 | close FILE; | |
1247 | } | |
1248 | if (open(FILE, ">${General::swroot}/ovpn/ovpnconfig")) { | |
1249 | print FILE ""; | |
1250 | close FILE; | |
1251 | } | |
1252 | while ($file = glob("${General::swroot}/ovpn/n2nconf/*")) { | |
1253 | system ("rm -rf $file"); | |
1254 | } | |
1255 | ||
2f36a7b4 MT |
1256 | # Remove everything from the collectd configuration |
1257 | &writecollectdconf(); | |
1258 | ||
c6c9630e | 1259 | #&writeserverconf(); |
6e13d0a5 MT |
1260 | ### |
1261 | ### Reset all step 1 | |
1262 | ### | |
4c962356 | 1263 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) { |
6e13d0a5 | 1264 | &Header::showhttpheaders(); |
4c962356 EK |
1265 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
1266 | &Header::openbigbox('100%', 'left', '', ''); | |
1267 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
1268 | print <<END; | |
1269 | <form method='post'> | |
1270 | <table width='100%'> | |
1271 | <tr> | |
1272 | <td align='center'> | |
1273 | <input type='hidden' name='AREUSURE' value='yes' /> | |
49abe7af | 1274 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: |
4c962356 EK |
1275 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td> |
1276 | </tr> | |
1277 | <tr> | |
1278 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /> | |
1279 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> | |
1280 | </tr> | |
1281 | </table> | |
1282 | </form> | |
6e13d0a5 MT |
1283 | END |
1284 | ; | |
1285 | &Header::closebox(); | |
1286 | &Header::closebigbox(); | |
1287 | &Header::closepage(); | |
1288 | exit (0); | |
1289 | ||
4c962356 EK |
1290 | ### |
1291 | ### Generate DH key step 2 | |
1292 | ### | |
1293 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
49abe7af | 1294 | # Delete if old key exists |
4c962356 EK |
1295 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { |
1296 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1297 | } | |
1298 | # Create Diffie Hellmann Parameter | |
badd8c1c | 1299 | system('/usr/bin/openssl', 'dhparam', '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
4c962356 EK |
1300 | if ($?) { |
1301 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1302 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
1303 | } | |
1304 | ||
1305 | ### | |
1306 | ### Generate DH key step 1 | |
1307 | ### | |
1308 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'}) { | |
1309 | &Header::showhttpheaders(); | |
1310 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
1311 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1312 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'gen dh'}:"); | |
1313 | print <<END; | |
1314 | <table width='100%'> | |
1315 | <tr> | |
f527e53f | 1316 | <td width='20%'> </td> <td width='15%'></td> <td width='65%'></td> |
49abe7af | 1317 | </tr> |
4c962356 EK |
1318 | <tr> |
1319 | <td class='base'>$Lang::tr{'ovpn dh'}:</td> | |
1320 | <td align='center'> | |
1321 | <form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
1322 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1323 | <select name='DHLENGHT'> | |
6fc0f5eb | 1324 | <option value='1024' $selected{'DHLENGHT'}{'1024'}>1024 $Lang::tr{'bit'} ($Lang::tr{'vpn weak'})</option> |
4c962356 EK |
1325 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> |
1326 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
1327 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
1328 | </select> | |
1329 | </td> | |
1330 | </tr> | |
1331 | <tr><td colspan='4'><br></td></tr> | |
1332 | </table> | |
1333 | <table width='100%'> | |
1334 | <tr> | |
49abe7af | 1335 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'dh key warn'} |
4c962356 | 1336 | </tr> |
49abe7af EK |
1337 | <tr> |
1338 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
1339 | </tr> | |
1340 | <tr><td colspan='2'><br></td></tr> | |
4c962356 EK |
1341 | <tr> |
1342 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
1343 | </form> | |
1344 | </tr> | |
1345 | </table> | |
1346 | ||
1347 | END | |
1348 | ; | |
1349 | &Header::closebox(); | |
1350 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1351 | &Header::closebigbox(); | |
1352 | &Header::closepage(); | |
1353 | exit (0); | |
1354 | ||
1355 | ### | |
1356 | ### Upload DH key | |
1357 | ### | |
1358 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload dh key'}) { | |
4c962356 EK |
1359 | if (ref ($cgiparams{'FH'}) ne 'Fh') { |
1360 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1361 | goto UPLOADCA_ERROR; | |
1362 | } | |
49abe7af | 1363 | # Move uploaded dh key to a temporary file |
4c962356 EK |
1364 | (my $fh, my $filename) = tempfile( ); |
1365 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1366 | $errormessage = $!; | |
49abe7af | 1367 | goto UPLOADCA_ERROR; |
4c962356 | 1368 | } |
49abe7af | 1369 | my $temp = `/usr/bin/openssl dhparam -text -in $filename`; |
4c962356 EK |
1370 | if ($temp !~ /DH Parameters: \((1024|2048|3072|4096) bit\)/) { |
1371 | $errormessage = $Lang::tr{'not a valid dh key'}; | |
1372 | unlink ($filename); | |
1373 | goto UPLOADCA_ERROR; | |
1374 | } else { | |
1375 | # Delete if old key exists | |
1376 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { | |
1377 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1378 | } | |
1379 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"); | |
49abe7af EK |
1380 | if ($? ne 0) { |
1381 | $errormessage = "$Lang::tr{'dh key move failed'}: $!"; | |
1382 | unlink ($filename); | |
1383 | goto UPLOADCA_ERROR; | |
1384 | } | |
4c962356 EK |
1385 | } |
1386 | ||
6e13d0a5 MT |
1387 | ### |
1388 | ### Upload CA Certificate | |
1389 | ### | |
1390 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
1391 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1392 | ||
1393 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
1394 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1395 | goto UPLOADCA_ERROR; | |
1396 | } | |
1397 | ||
1398 | if (length($cgiparams{'CA_NAME'}) >60) { | |
1399 | $errormessage = $Lang::tr{'name too long'}; | |
1400 | goto VPNCONF_ERROR; | |
1401 | } | |
1402 | ||
1403 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
1404 | $errormessage = $Lang::tr{'name is invalid'}; | |
4c962356 | 1405 | goto UPLOADCA_ERROR; |
6e13d0a5 MT |
1406 | } |
1407 | ||
1408 | # Check if there is no other entry with this name | |
1409 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
1410 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
1411 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
1412 | goto UPLOADCA_ERROR; | |
1413 | } | |
6e13d0a5 MT |
1414 | } |
1415 | ||
1416 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
c6c9630e MT |
1417 | $errormessage = $Lang::tr{'there was no file upload'}; |
1418 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1419 | } |
1420 | # Move uploaded ca to a temporary file | |
1421 | (my $fh, my $filename) = tempfile( ); | |
1422 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
1423 | $errormessage = $!; |
1424 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1425 | } |
1426 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; | |
c6c9630e MT |
1427 | if ($temp !~ /CA:TRUE/i) { |
1428 | $errormessage = $Lang::tr{'not a valid ca certificate'}; | |
1429 | unlink ($filename); | |
1430 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1431 | } else { |
c6c9630e MT |
1432 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
1433 | if ($? ne 0) { | |
1434 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1435 | unlink ($filename); | |
1436 | goto UPLOADCA_ERROR; | |
1437 | } | |
6e13d0a5 MT |
1438 | } |
1439 | ||
1440 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`; | |
1441 | $casubject =~ /Subject: (.*)[\n]/; | |
1442 | $casubject = $1; | |
1443 | $casubject =~ s+/Email+, E+; | |
1444 | $casubject =~ s/ ST=/ S=/; | |
1445 | $casubject = &Header::cleanhtml($casubject); | |
1446 | ||
1447 | my $key = &General::findhasharraykey (\%cahash); | |
1448 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
1449 | $cahash{$key}[1] = $casubject; | |
1450 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
1451 | # system('/usr/local/bin/ipsecctrl', 'R'); |
1452 | ||
6e13d0a5 MT |
1453 | UPLOADCA_ERROR: |
1454 | ||
1455 | ### | |
1456 | ### Display ca certificate | |
1457 | ### | |
1458 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
1459 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
1460 | ||
1461 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
1462 | &Header::showhttpheaders(); | |
4c962356 | 1463 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1464 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1465 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
1466 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1467 | $output = &Header::cleanhtml($output,"y"); | |
1468 | print "<pre>$output</pre>\n"; | |
1469 | &Header::closebox(); | |
1470 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1471 | &Header::closebigbox(); | |
1472 | &Header::closepage(); | |
1473 | exit(0); | |
1474 | } else { | |
1475 | $errormessage = $Lang::tr{'invalid key'}; | |
1476 | } | |
1477 | ||
6e13d0a5 MT |
1478 | ### |
1479 | ### Download ca certificate | |
1480 | ### | |
1481 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
1482 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1483 | ||
1484 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1485 | print "Content-Type: application/octet-stream\r\n"; | |
1486 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
1487 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1488 | exit(0); | |
1489 | } else { | |
1490 | $errormessage = $Lang::tr{'invalid key'}; | |
1491 | } | |
1492 | ||
1493 | ### | |
1494 | ### Remove ca certificate (step 2) | |
1495 | ### | |
1496 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1497 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1498 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1499 | ||
1500 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1501 | foreach my $key (keys %confighash) { | |
1502 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
1503 | if ($test =~ /: OK/) { | |
c6c9630e MT |
1504 | # Delete connection |
1505 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1506 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1507 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
1508 | # } | |
6e13d0a5 MT |
1509 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
1510 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
1511 | delete $confighash{$key}; | |
1512 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 1513 | # &writeipsecfiles(); |
6e13d0a5 MT |
1514 | } |
1515 | } | |
1516 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1517 | delete $cahash{$cgiparams{'KEY'}}; | |
1518 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 1519 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
1520 | } else { |
1521 | $errormessage = $Lang::tr{'invalid key'}; | |
1522 | } | |
1523 | ### | |
1524 | ### Remove ca certificate (step 1) | |
1525 | ### | |
1526 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
1527 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1528 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1529 | ||
1530 | my $assignedcerts = 0; | |
1531 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1532 | foreach my $key (keys %confighash) { | |
1533 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
1534 | if ($test =~ /: OK/) { | |
1535 | $assignedcerts++; | |
1536 | } | |
1537 | } | |
1538 | if ($assignedcerts) { | |
1539 | &Header::showhttpheaders(); | |
4c962356 | 1540 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1541 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1542 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
4c962356 | 1543 | print <<END; |
6e13d0a5 MT |
1544 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> |
1545 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1546 | <tr><td align='center'> | |
1547 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1548 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1549 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1550 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1551 | </form></table> | |
1552 | END | |
1553 | ; | |
1554 | &Header::closebox(); | |
1555 | &Header::closebigbox(); | |
1556 | &Header::closepage(); | |
1557 | exit (0); | |
1558 | } else { | |
1559 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1560 | delete $cahash{$cgiparams{'KEY'}}; | |
1561 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1562 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1563 | } | |
1564 | } else { | |
1565 | $errormessage = $Lang::tr{'invalid key'}; | |
1566 | } | |
1567 | ||
1568 | ### | |
1569 | ### Display root certificate | |
1570 | ### | |
c6c9630e MT |
1571 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1572 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
1573 | my $output; | |
1574 | &Header::showhttpheaders(); | |
4c962356 | 1575 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1576 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1577 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1578 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
1579 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1580 | } else { | |
1581 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
1582 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1583 | } | |
1584 | $output = &Header::cleanhtml($output,"y"); | |
1585 | print "<pre>$output</pre>\n"; | |
1586 | &Header::closebox(); | |
1587 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1588 | &Header::closebigbox(); | |
1589 | &Header::closepage(); | |
1590 | exit(0); | |
1591 | ||
6e13d0a5 MT |
1592 | ### |
1593 | ### Download root certificate | |
1594 | ### | |
1595 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1596 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1597 | print "Content-Type: application/octet-stream\r\n"; | |
1598 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
1599 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1600 | exit(0); | |
1601 | } | |
1602 | ||
1603 | ### | |
1604 | ### Download host certificate | |
1605 | ### | |
1606 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1607 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1608 | print "Content-Type: application/octet-stream\r\n"; | |
1609 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
1610 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1611 | exit(0); | |
1612 | } | |
f7fb5bc5 | 1613 | |
fd5ccb2d EK |
1614 | ### |
1615 | ### Download tls-auth key | |
1616 | ### | |
1617 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download tls-auth key'}) { | |
1618 | if ( -f "${General::swroot}/ovpn/certs/ta.key" ) { | |
1619 | print "Content-Type: application/octet-stream\r\n"; | |
1620 | print "Content-Disposition: filename=ta.key\r\n\r\n"; | |
1621 | print `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
1622 | exit(0); | |
1623 | } | |
1624 | ||
6e13d0a5 MT |
1625 | ### |
1626 | ### Form for generating a root certificate | |
1627 | ### | |
1628 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1629 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1630 | ||
1631 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1632 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1633 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1634 | $cgiparams{'ACTION'} = ''; | |
1635 | goto ROOTCERT_ERROR; | |
1636 | } | |
1637 | ||
1638 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1639 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1640 | my $ipaddr = <IPADDR>; | |
1641 | close IPADDR; | |
1642 | chomp ($ipaddr); | |
1643 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1644 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1645 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1646 | } | |
1647 | } | |
1648 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1649 | ||
1650 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1651 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1652 | goto ROOTCERT_ERROR; | |
1653 | } | |
1654 | ||
1655 | # Move uploaded certificate request to a temporary file | |
1656 | (my $fh, my $filename) = tempfile( ); | |
1657 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1658 | $errormessage = $!; | |
1659 | goto ROOTCERT_ERROR; | |
1660 | } | |
1661 | ||
1662 | # Create a temporary dirctory | |
1663 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1664 | ||
1665 | # Extract the CA certificate from the file | |
1666 | my $pid = open(OPENSSL, "|-"); | |
1667 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1668 | if ($pid) { # parent | |
1669 | if ($cgiparams{'P12_PASS'} ne '') { | |
1670 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1671 | } | |
1672 | close (OPENSSL); | |
1673 | if ($?) { | |
1674 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1675 | unlink ($filename); | |
1676 | goto ROOTCERT_ERROR; | |
1677 | } | |
1678 | } else { # child | |
1679 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1680 | '-in', $filename, | |
1681 | '-out', "$tempdir/cacert.pem")) { | |
1682 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1683 | unlink ($filename); | |
1684 | goto ROOTCERT_ERROR; | |
1685 | } | |
1686 | } | |
1687 | ||
1688 | # Extract the Host certificate from the file | |
1689 | $pid = open(OPENSSL, "|-"); | |
1690 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1691 | if ($pid) { # parent | |
1692 | if ($cgiparams{'P12_PASS'} ne '') { | |
1693 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1694 | } | |
1695 | close (OPENSSL); | |
1696 | if ($?) { | |
1697 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1698 | unlink ($filename); | |
1699 | goto ROOTCERT_ERROR; | |
1700 | } | |
1701 | } else { # child | |
1702 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1703 | '-in', $filename, | |
1704 | '-out', "$tempdir/hostcert.pem")) { | |
1705 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1706 | unlink ($filename); | |
1707 | goto ROOTCERT_ERROR; | |
1708 | } | |
1709 | } | |
1710 | ||
1711 | # Extract the Host key from the file | |
1712 | $pid = open(OPENSSL, "|-"); | |
1713 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1714 | if ($pid) { # parent | |
1715 | if ($cgiparams{'P12_PASS'} ne '') { | |
1716 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1717 | } | |
1718 | close (OPENSSL); | |
1719 | if ($?) { | |
1720 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1721 | unlink ($filename); | |
1722 | goto ROOTCERT_ERROR; | |
1723 | } | |
1724 | } else { # child | |
1725 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1726 | '-nodes', | |
1727 | '-in', $filename, | |
1728 | '-out', "$tempdir/serverkey.pem")) { | |
1729 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1730 | unlink ($filename); | |
1731 | goto ROOTCERT_ERROR; | |
1732 | } | |
1733 | } | |
1734 | ||
1735 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1736 | if ($? ne 0) { | |
1737 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1738 | unlink ($filename); | |
1739 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1740 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1741 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1742 | goto ROOTCERT_ERROR; | |
1743 | } | |
1744 | ||
1745 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1746 | if ($? ne 0) { | |
1747 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1748 | unlink ($filename); | |
1749 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1750 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1751 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1752 | goto ROOTCERT_ERROR; | |
1753 | } | |
1754 | ||
1755 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1756 | if ($? ne 0) { | |
1757 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1758 | unlink ($filename); | |
1759 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1760 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1761 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1762 | goto ROOTCERT_ERROR; | |
1763 | } | |
1764 | ||
1765 | goto ROOTCERT_SUCCESS; | |
1766 | ||
1767 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1768 | ||
1769 | # Validate input since the form was submitted | |
1770 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1771 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1772 | goto ROOTCERT_ERROR; | |
1773 | } | |
1774 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1775 | $errormessage = $Lang::tr{'organization too long'}; | |
1776 | goto ROOTCERT_ERROR; | |
1777 | } | |
1778 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1779 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1780 | goto ROOTCERT_ERROR; | |
1781 | } | |
1782 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1783 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1784 | goto ROOTCERT_ERROR; | |
1785 | } | |
1786 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1787 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1788 | goto ROOTCERT_ERROR; | |
1789 | } | |
1790 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1791 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1792 | goto ROOTCERT_ERROR; | |
1793 | } | |
1794 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1795 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1796 | goto ROOTCERT_ERROR; | |
1797 | } | |
1798 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1799 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1800 | goto ROOTCERT_ERROR; | |
1801 | } | |
1802 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1803 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1804 | goto ROOTCERT_ERROR; | |
1805 | } | |
1806 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1807 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1808 | goto ROOTCERT_ERROR; | |
1809 | } | |
1810 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1811 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1812 | goto ROOTCERT_ERROR; | |
1813 | } | |
1814 | ||
1815 | # Copy the cgisettings to vpnsettings and save the configfile | |
1816 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1817 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1818 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1819 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1820 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1821 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1822 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1823 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1824 | ||
1825 | # Replace empty strings with a . | |
1826 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1827 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1828 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1829 | ||
1830 | # refresh | |
c6c9630e | 1831 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
6e13d0a5 MT |
1832 | |
1833 | # Create the CA certificate | |
1834 | my $pid = open(OPENSSL, "|-"); | |
1835 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1836 | if ($pid) { # parent | |
1837 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1838 | print OPENSSL "$state\n"; | |
1839 | print OPENSSL "$city\n"; | |
1840 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1841 | print OPENSSL "$ou\n"; | |
1842 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1843 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1844 | close (OPENSSL); | |
1845 | if ($?) { | |
1846 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1847 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1848 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1849 | goto ROOTCERT_ERROR; | |
1850 | } | |
1851 | } else { # child | |
badd8c1c | 1852 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', |
49abe7af | 1853 | '-days', '999999', '-newkey', 'rsa:4096', '-sha512', |
6e13d0a5 MT |
1854 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", |
1855 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1856 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1857 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1858 | goto ROOTCERT_ERROR; | |
1859 | } | |
1860 | } | |
1861 | ||
1862 | # Create the Host certificate request | |
1863 | $pid = open(OPENSSL, "|-"); | |
1864 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1865 | if ($pid) { # parent | |
1866 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1867 | print OPENSSL "$state\n"; | |
1868 | print OPENSSL "$city\n"; | |
1869 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1870 | print OPENSSL "$ou\n"; | |
1871 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1872 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1873 | print OPENSSL ".\n"; | |
1874 | print OPENSSL ".\n"; | |
1875 | close (OPENSSL); | |
1876 | if ($?) { | |
1877 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1878 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1879 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1880 | goto ROOTCERT_ERROR; | |
1881 | } | |
1882 | } else { # child | |
badd8c1c | 1883 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 1884 | '-newkey', 'rsa:2048', |
6e13d0a5 MT |
1885 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", |
1886 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1887 | '-extensions', 'server', | |
1888 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1889 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1890 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1891 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1892 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1893 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1894 | goto ROOTCERT_ERROR; | |
1895 | } | |
1896 | } | |
1897 | ||
1898 | # Sign the host certificate request | |
1899 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
1900 | '-batch', '-notext', | |
1901 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1902 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1903 | '-extensions', 'server', | |
1904 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1905 | if ($?) { | |
1906 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1907 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1908 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1909 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1910 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1911 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1912 | &newcleanssldatabase(); |
6e13d0a5 MT |
1913 | goto ROOTCERT_ERROR; |
1914 | } else { | |
1915 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1916 | &deletebackupcert(); |
6e13d0a5 MT |
1917 | } |
1918 | ||
1919 | # Create an empty CRL | |
1920 | system('/usr/bin/openssl', 'ca', '-gencrl', | |
1921 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1922 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1923 | if ($?) { | |
1924 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1925 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1926 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1927 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1928 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
c6c9630e | 1929 | &cleanssldatabase(); |
6e13d0a5 | 1930 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1931 | # } else { |
1932 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1933 | } |
1934 | # Create Diffie Hellmann Parameter | |
badd8c1c | 1935 | system('/usr/bin/openssl', 'dhparam', '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
6e13d0a5 MT |
1936 | if ($?) { |
1937 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1938 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1939 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1940 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1941 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1942 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
c6c9630e | 1943 | &cleanssldatabase(); |
6e13d0a5 | 1944 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1945 | # } else { |
1946 | # &cleanssldatabase(); | |
4be45949 EK |
1947 | } |
1948 | # Create ta.key for tls-auth | |
1949 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/certs/ta.key"); | |
1950 | if ($?) { | |
1951 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1952 | &cleanssldatabase(); | |
1953 | goto ROOTCERT_ERROR; | |
1954 | } | |
6e13d0a5 MT |
1955 | goto ROOTCERT_SUCCESS; |
1956 | } | |
1957 | ROOTCERT_ERROR: | |
1958 | if ($cgiparams{'ACTION'} ne '') { | |
1959 | &Header::showhttpheaders(); | |
4c962356 | 1960 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1961 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1962 | if ($errormessage) { | |
1963 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1964 | print "<class name='base'>$errormessage"; | |
1965 | print " </class>"; | |
1966 | &Header::closebox(); | |
1967 | } | |
1968 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
49abe7af | 1969 | print <<END; |
6e13d0a5 MT |
1970 | <form method='post' enctype='multipart/form-data'> |
1971 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
e3edceeb | 1972 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
1973 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> |
1974 | <td width='35%' colspan='2'> </td></tr> | |
e3edceeb | 1975 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
1976 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> |
1977 | <td colspan='2'> </td></tr> | |
e3edceeb | 1978 | <tr><td class='base'>$Lang::tr{'your e-mail'}:</td> |
6e13d0a5 MT |
1979 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> |
1980 | <td colspan='2'> </td></tr> | |
e3edceeb | 1981 | <tr><td class='base'>$Lang::tr{'your department'}:</td> |
6e13d0a5 MT |
1982 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> |
1983 | <td colspan='2'> </td></tr> | |
e3edceeb | 1984 | <tr><td class='base'>$Lang::tr{'city'}:</td> |
6e13d0a5 MT |
1985 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> |
1986 | <td colspan='2'> </td></tr> | |
e3edceeb | 1987 | <tr><td class='base'>$Lang::tr{'state or province'}:</td> |
6e13d0a5 MT |
1988 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> |
1989 | <td colspan='2'> </td></tr> | |
1990 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
1991 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
1992 | ||
1993 | END | |
1994 | ; | |
1995 | foreach my $country (sort keys %{Countries::countries}) { | |
1996 | print "<option value='$Countries::countries{$country}'"; | |
1997 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1998 | print " selected='selected'"; | |
1999 | } | |
2000 | print ">$country</option>"; | |
2001 | } | |
49abe7af | 2002 | print <<END; |
6e13d0a5 | 2003 | </select></td> |
4c962356 EK |
2004 | <tr><td class='base'>$Lang::tr{'ovpn dh'}:</td> |
2005 | <td class='base'><select name='DHLENGHT'> | |
ea6dd5b0 | 2006 | <option value='1024' $selected{'DHLENGHT'}{'1024'}>1024 $Lang::tr{'bit'} ($Lang::tr{'vpn weak'}</option> |
4c962356 EK |
2007 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> |
2008 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
2009 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
2010 | </select> | |
2011 | </td> | |
2012 | </tr> | |
2013 | ||
6e13d0a5 MT |
2014 | <tr><td> </td> |
2015 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
2016 | <td> </td><td> </td></tr> | |
2017 | <tr><td class='base' colspan='4' align='left'> | |
e3edceeb | 2018 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'required field'}</td></tr> |
49abe7af EK |
2019 | <tr><td colspan='2'><br></td></tr> |
2020 | <table width='100%'> | |
2021 | <tr> | |
2022 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'ovpn generating the root and host certificates'} | |
2023 | <td class='base'>$Lang::tr{'dh key warn'}</td> | |
4c962356 | 2024 | </tr> |
49abe7af EK |
2025 | <tr> |
2026 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
4c962356 | 2027 | </tr> |
49abe7af EK |
2028 | <tr><td colspan='2'><br></td></tr> |
2029 | <tr> | |
2030 | </table> | |
4c962356 | 2031 | |
49abe7af | 2032 | <table width='100%'> |
4c962356 | 2033 | <tr><td colspan='4'><hr></td></tr> |
e3edceeb | 2034 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
2035 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> |
2036 | <td colspan='2'> </td></tr> | |
e3edceeb | 2037 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
6e13d0a5 MT |
2038 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> |
2039 | <td colspan='2'> </td></tr> | |
2040 | <tr><td> </td> | |
2041 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
2042 | <td colspan='2'> </td></tr> | |
2043 | <tr><td class='base' colspan='4' align='left'> | |
e3edceeb | 2044 | <img src='/blob.gif' valign='top' alt='*' > $Lang::tr{'required field'}</td> |
4c962356 | 2045 | </tr> |
6e13d0a5 MT |
2046 | </form></table> |
2047 | END | |
2048 | ; | |
2049 | &Header::closebox(); | |
4c962356 | 2050 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2051 | &Header::closebigbox(); |
2052 | &Header::closepage(); | |
2053 | exit(0) | |
2054 | } | |
2055 | ||
2056 | ROOTCERT_SUCCESS: | |
2057 | system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem"); | |
c6c9630e MT |
2058 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
2059 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
2060 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
2061 | # } | |
6e13d0a5 MT |
2062 | |
2063 | ### | |
2064 | ### Enable/Disable connection | |
2065 | ### | |
ce9abb66 AH |
2066 | |
2067 | ### | |
7c1d9faf | 2068 | # m.a.d net2net |
ce9abb66 AH |
2069 | ### |
2070 | ||
6e13d0a5 | 2071 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
c6c9630e MT |
2072 | |
2073 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 | 2074 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 AH |
2075 | # my $n2nactive = ''; |
2076 | my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`; | |
2077 | ||
6e13d0a5 | 2078 | if ($confighash{$cgiparams{'KEY'}}) { |
8c877a82 AM |
2079 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
2080 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
2081 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2082 | |
8c877a82 | 2083 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
775b4494 AM |
2084 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); |
2085 | &writecollectdconf(); | |
8c877a82 AM |
2086 | } |
2087 | } else { | |
ce9abb66 | 2088 | |
8c877a82 AM |
2089 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
2090 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2091 | |
8c877a82 | 2092 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
775b4494 AM |
2093 | if ($n2nactive ne '') { |
2094 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
2095 | &writecollectdconf(); | |
2096 | } | |
ce9abb66 | 2097 | |
8c877a82 | 2098 | } else { |
775b4494 | 2099 | $errormessage = $Lang::tr{'invalid key'}; |
8c877a82 | 2100 | } |
775b4494 | 2101 | } |
ce9abb66 | 2102 | } |
6e13d0a5 MT |
2103 | |
2104 | ### | |
2105 | ### Download OpenVPN client package | |
2106 | ### | |
ce9abb66 AH |
2107 | |
2108 | ||
6e13d0a5 MT |
2109 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
2110 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2111 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2112 | my $file = ''; | |
2113 | my $clientovpn = ''; | |
2114 | my @fileholder; | |
2115 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2116 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
2117 | |
2118 | ### | |
7c1d9faf AH |
2119 | # m.a.d net2net |
2120 | ### | |
ce9abb66 AH |
2121 | |
2122 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
2123 | ||
2124 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
2125 | my $zippathname = "$zippath$zipname"; | |
2126 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
2127 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
54fd0535 | 2128 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 2129 | my $tunmtu = ''; |
7c1d9faf | 2130 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
54fd0535 | 2131 | my $n2nfragment = ''; |
ce9abb66 AH |
2132 | |
2133 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
2134 | flock CLIENTCONF, 2; | |
2135 | ||
2136 | my $zip = Archive::Zip->new(); | |
7c1d9faf | 2137 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 2138 | print CLIENTCONF "# \n"; |
b278daf3 | 2139 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
2140 | print CLIENTCONF "user nobody\n"; |
2141 | print CLIENTCONF "group nobody\n"; | |
2142 | print CLIENTCONF "persist-tun\n"; | |
2143 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 2144 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 2145 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
531f0835 | 2146 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 | 2147 | print CLIENTCONF "float\n"; |
60f396d7 | 2148 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 2149 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 2150 | print CLIENTCONF "# Server Gateway Network\n"; |
7c1d9faf | 2151 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
b278daf3 | 2152 | print CLIENTCONF "# tun Device\n"; |
79e7688b | 2153 | print CLIENTCONF "dev tun\n"; |
35a21a25 AM |
2154 | print CLIENTCONF "#Logfile for statistics\n"; |
2155 | print CLIENTCONF "status-version 1\n"; | |
2156 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
60f396d7 | 2157 | print CLIENTCONF "# Port and Protokoll\n"; |
ce9abb66 | 2158 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; |
60f396d7 AH |
2159 | |
2160 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') { | |
2161 | print CLIENTCONF "proto tcp-client\n"; | |
2162 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 2163 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
60f396d7 | 2164 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 2165 | } |
60f396d7 AH |
2166 | |
2167 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { | |
2168 | print CLIENTCONF "proto udp\n"; | |
2169 | print CLIENTCONF "# Paketsize\n"; | |
2170 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2171 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 2172 | if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";} |
60f396d7 | 2173 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";} |
d96c89eb | 2174 | } |
1647059d SS |
2175 | if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') || |
2176 | ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') || | |
2177 | ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) { | |
2ee746be SS |
2178 | if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) { |
2179 | if ($tunmtu eq '1500' ) { | |
350f2980 | 2180 | print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n"; |
2ee746be SS |
2181 | } |
2182 | } | |
2183 | } | |
b66b02ab EK |
2184 | # Check host certificate if X509 is RFC3280 compliant. |
2185 | # If not, old --ns-cert-type directive will be used. | |
2186 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2187 | my $hostcert = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
2188 | if ($hostcert !~ /TLS Web Server Authentication/) { | |
2189 | print CLIENTCONF "ns-cert-type server\n"; | |
2190 | } else { | |
2191 | print CLIENTCONF "remote-cert-tls server\n"; | |
2192 | } | |
ce9abb66 AH |
2193 | print CLIENTCONF "# Auth. Client\n"; |
2194 | print CLIENTCONF "tls-client\n"; | |
49abe7af | 2195 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 2196 | print CLIENTCONF "cipher $confighash{$cgiparams{'KEY'}}[40]\n"; |
ce9abb66 AH |
2197 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
2198 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2199 | $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 EK |
2200 | } |
2201 | if ($confighash{$cgiparams{'KEY'}}[39] eq '') { | |
2202 | print CLIENTCONF "# HMAC algorithm\n"; | |
2203 | print CLIENTCONF "auth SHA1\n"; | |
2204 | } else { | |
2205 | print CLIENTCONF "# HMAC algorithm\n"; | |
2206 | print CLIENTCONF "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
2207 | } | |
4c962356 | 2208 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 2209 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 2210 | print CLIENTCONF "comp-lzo\n"; |
b278daf3 | 2211 | } |
ce9abb66 AH |
2212 | print CLIENTCONF "# Debug Level\n"; |
2213 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 2214 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 2215 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 2216 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
2217 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; |
2218 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
b278daf3 | 2219 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
2220 | if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"} |
2221 | else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"}; | |
ce9abb66 | 2222 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; |
531f0835 | 2223 | |
ce9abb66 AH |
2224 | |
2225 | close(CLIENTCONF); | |
2226 | ||
2227 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
2228 | my $status = $zip->writeToFileNamed($zippathname); | |
2229 | ||
2230 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2231 | @fileholder = <DLFILE>; | |
2232 | print "Content-Type:application/x-download\n"; | |
2233 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2234 | print @fileholder; | |
2235 | exit (0); | |
2236 | } | |
2237 | else | |
2238 | { | |
2239 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
2240 | my $zippathname = "$zippath$zipname"; | |
2241 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
2242 | ||
2243 | ### | |
7c1d9faf | 2244 | # m.a.d net2net |
ce9abb66 AH |
2245 | ### |
2246 | ||
c6c9630e | 2247 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 MT |
2248 | flock CLIENTCONF, 2; |
2249 | ||
2250 | my $zip = Archive::Zip->new(); | |
2251 | ||
8c877a82 | 2252 | print CLIENTCONF "#OpenVPN Client conf\r\n"; |
6e13d0a5 MT |
2253 | print CLIENTCONF "tls-client\r\n"; |
2254 | print CLIENTCONF "client\r\n"; | |
4f6e3ae3 | 2255 | print CLIENTCONF "nobind\r\n"; |
79e7688b | 2256 | print CLIENTCONF "dev tun\r\n"; |
c6c9630e | 2257 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
2ee746be SS |
2258 | |
2259 | # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500 | |
2260 | # or use configured value. | |
2261 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) | |
79e7688b | 2262 | { print CLIENTCONF "tun-mtu 1500\r\n"; } |
2ee746be | 2263 | elsif ($vpnsettings{MSSFIX} eq 'on') |
79e7688b | 2264 | { print CLIENTCONF "tun-mtu 1500\r\n"; } |
1647059d SS |
2265 | elsif (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || |
2266 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2267 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) | |
79e7688b | 2268 | { print CLIENTCONF "tun-mtu 1500\r\n"; } |
2ee746be | 2269 | else |
79e7688b | 2270 | { print CLIENTCONF "tun-mtu $vpnsettings{'DMTU'}\r\n"; } |
2ee746be | 2271 | |
6e13d0a5 MT |
2272 | if ( $vpnsettings{'ENABLED'} eq 'on'){ |
2273 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
c6c9630e MT |
2274 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
2275 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
2276 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2277 | } | |
2278 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2279 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2280 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2281 | } | |
2282 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2283 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2284 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2285 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2286 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2287 | } | |
2288 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2289 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 MT |
2290 | } |
2291 | ||
71af643c MT |
2292 | my $file_crt = new File::Temp( UNLINK => 1 ); |
2293 | my $file_key = new File::Temp( UNLINK => 1 ); | |
b22d8aaf | 2294 | my $include_certs = 0; |
71af643c | 2295 | |
6e13d0a5 | 2296 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
71af643c | 2297 | if ($cgiparams{'MODE'} eq 'insecure') { |
b22d8aaf MT |
2298 | $include_certs = 1; |
2299 | ||
71af643c | 2300 | # Add the CA |
b22d8aaf | 2301 | print CLIENTCONF ";ca cacert.pem\r\n"; |
71af643c MT |
2302 | $zip->addFile("${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; |
2303 | ||
2304 | # Extract the certificate | |
2305 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", | |
2306 | '-clcerts', '-nokeys', '-nodes', '-out', "$file_crt" , '-passin', 'pass:'); | |
2307 | if ($?) { | |
2308 | die "openssl error: $?"; | |
2309 | } | |
2310 | ||
2311 | $zip->addFile("$file_crt", "$confighash{$cgiparams{'KEY'}}[1].pem") or die; | |
b22d8aaf | 2312 | print CLIENTCONF ";cert $confighash{$cgiparams{'KEY'}}[1].pem\r\n"; |
71af643c MT |
2313 | |
2314 | # Extract the key | |
2315 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", | |
2316 | '-nocerts', '-nodes', '-out', "$file_key", '-passin', 'pass:'); | |
2317 | if ($?) { | |
2318 | die "openssl error: $?"; | |
2319 | } | |
2320 | ||
2321 | $zip->addFile("$file_key", "$confighash{$cgiparams{'KEY'}}[1].key") or die; | |
b22d8aaf | 2322 | print CLIENTCONF ";key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; |
71af643c MT |
2323 | } else { |
2324 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2325 | $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"; | |
2326 | } | |
6e13d0a5 | 2327 | } else { |
c6c9630e MT |
2328 | print CLIENTCONF "ca cacert.pem\r\n"; |
2329 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
2330 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
2331 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
2332 | $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 |
2333 | } |
2334 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
49abe7af EK |
2335 | if ($vpnsettings{'DAUTH'} eq '') { |
2336 | print CLIENTCONF ""; | |
2337 | } else { | |
2338 | print CLIENTCONF "auth $vpnsettings{'DAUTH'}\r\n"; | |
2339 | } | |
2340 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
b22d8aaf MT |
2341 | if ($cgiparams{'MODE'} eq 'insecure') { |
2342 | print CLIENTCONF ";"; | |
2343 | } | |
4be45949 EK |
2344 | print CLIENTCONF "tls-auth ta.key\r\n"; |
2345 | $zip->addFile( "${General::swroot}/ovpn/certs/ta.key", "ta.key") or die "Can't add file ta.key\n"; | |
49abe7af | 2346 | } |
6e13d0a5 MT |
2347 | if ($vpnsettings{DCOMPLZO} eq 'on') { |
2348 | print CLIENTCONF "comp-lzo\r\n"; | |
2349 | } | |
2350 | print CLIENTCONF "verb 3\r\n"; | |
b66b02ab EK |
2351 | # Check host certificate if X509 is RFC3280 compliant. |
2352 | # If not, old --ns-cert-type directive will be used. | |
2353 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2354 | my $hostcert = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
2355 | if ($hostcert !~ /TLS Web Server Authentication/) { | |
2356 | print CLIENTCONF "ns-cert-type server\r\n"; | |
2357 | } else { | |
2358 | print CLIENTCONF "remote-cert-tls server\r\n"; | |
2359 | } | |
964700d4 | 2360 | print CLIENTCONF "verify-x509-name $vpnsettings{ROOTCERT_HOSTNAME} name\r\n"; |
a79fa1d6 JPT |
2361 | if ($vpnsettings{MSSFIX} eq 'on') { |
2362 | print CLIENTCONF "mssfix\r\n"; | |
2363 | } | |
74225cce | 2364 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
2365 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
2366 | } | |
1647059d SS |
2367 | |
2368 | # Check if a valid operating mode has been choosen and use it. | |
2369 | if (($vpnsettings{'PMTU_DISCOVERY'} eq 'yes') || | |
2370 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'maybe') || | |
2371 | ($vpnsettings{'PMTU_DISCOVERY'} eq 'no' )) { | |
2ee746be | 2372 | if(($vpnsettings{MSSFIX} ne 'on') || ($vpnsettings{FRAGMENT} eq '')) { |
4f6e3ae3 | 2373 | print CLIENTCONF "mtu-disc $vpnsettings{'PMTU_DISCOVERY'}\r\n"; |
2ee746be SS |
2374 | } |
2375 | } | |
b22d8aaf MT |
2376 | |
2377 | if ($include_certs) { | |
2378 | print CLIENTCONF "\r\n"; | |
2379 | ||
2380 | # CA | |
2381 | open(FILE, "<${General::swroot}/ovpn/ca/cacert.pem"); | |
2382 | print CLIENTCONF "<ca>\r\n"; | |
2383 | while (<FILE>) { | |
2384 | chomp($_); | |
2385 | print CLIENTCONF "$_\r\n"; | |
2386 | } | |
2387 | print CLIENTCONF "</ca>\r\n\r\n"; | |
2388 | close(FILE); | |
2389 | ||
2390 | # Cert | |
2391 | open(FILE, "<$file_crt"); | |
2392 | print CLIENTCONF "<cert>\r\n"; | |
2393 | while (<FILE>) { | |
2394 | chomp($_); | |
2395 | print CLIENTCONF "$_\r\n"; | |
2396 | } | |
2397 | print CLIENTCONF "</cert>\r\n\r\n"; | |
2398 | close(FILE); | |
2399 | ||
2400 | # Key | |
2401 | open(FILE, "<$file_key"); | |
2402 | print CLIENTCONF "<key>\r\n"; | |
2403 | while (<FILE>) { | |
2404 | chomp($_); | |
2405 | print CLIENTCONF "$_\r\n"; | |
2406 | } | |
2407 | print CLIENTCONF "</key>\r\n\r\n"; | |
2408 | close(FILE); | |
2409 | ||
2410 | # TLS auth | |
2411 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
2412 | open(FILE, "<${General::swroot}/ovpn/certs/ta.key"); | |
2413 | print CLIENTCONF "<tls-auth>\r\n"; | |
2414 | while (<FILE>) { | |
2415 | chomp($_); | |
2416 | print CLIENTCONF "$_\r\n"; | |
2417 | } | |
2418 | print CLIENTCONF "</tls-auth>\r\n\r\n"; | |
2419 | close(FILE); | |
2420 | } | |
2421 | } | |
2422 | ||
ffbe77c8 EK |
2423 | # Print client.conf.local if entries exist to client.ovpn |
2424 | if (!-z $local_clientconf && $vpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
2425 | open (LCC, "$local_clientconf"); | |
2426 | print CLIENTCONF "\n#---------------------------\n"; | |
2427 | print CLIENTCONF "# Start of custom directives\n"; | |
2428 | print CLIENTCONF "# from client.conf.local\n"; | |
2429 | print CLIENTCONF "#---------------------------\n\n"; | |
2430 | while (<LCC>) { | |
2431 | print CLIENTCONF $_; | |
2432 | } | |
2433 | print CLIENTCONF "\n#---------------------------\n"; | |
2434 | print CLIENTCONF "# End of custom directives\n"; | |
2435 | print CLIENTCONF "#---------------------------\n\n"; | |
2436 | close (LCC); | |
2437 | } | |
6e13d0a5 | 2438 | close(CLIENTCONF); |
ce9abb66 | 2439 | |
6e13d0a5 MT |
2440 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
2441 | my $status = $zip->writeToFileNamed($zippathname); | |
2442 | ||
2443 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2444 | @fileholder = <DLFILE>; | |
2445 | print "Content-Type:application/x-download\n"; | |
2446 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2447 | print @fileholder; | |
2448 | exit (0); | |
ce9abb66 AH |
2449 | } |
2450 | ||
2451 | ||
2452 | ||
6e13d0a5 MT |
2453 | ### |
2454 | ### Remove connection | |
2455 | ### | |
ce9abb66 AH |
2456 | |
2457 | ||
6e13d0a5 | 2458 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
323be7c4 AM |
2459 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
2460 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 2461 | |
323be7c4 | 2462 | if ($confighash{$cgiparams{'KEY'}}) { |
fde9c9dd | 2463 | # Revoke certificate if certificate was deleted and rewrite the CRL |
323be7c4 | 2464 | my $temp = `/usr/bin/openssl ca -revoke ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; |
fde9c9dd | 2465 | my $tempA = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; |
ce9abb66 AH |
2466 | |
2467 | ### | |
7c1d9faf | 2468 | # m.a.d net2net |
ce9abb66 | 2469 | ### |
7c1d9faf | 2470 | |
323be7c4 | 2471 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
1e499e90 MT |
2472 | # Stop the N2N connection before it is removed |
2473 | system("/usr/local/bin/openvpnctrl -kn2n $confighash{$cgiparams{'KEY'}}[1] &>/dev/null"); | |
2474 | ||
323be7c4 AM |
2475 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); |
2476 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2477 | unlink ($certfile); | |
2478 | unlink ($conffile); | |
8e6a8fd5 | 2479 | |
323be7c4 AM |
2480 | if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") { |
2481 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2482 | } | |
323be7c4 | 2483 | } |
ce9abb66 | 2484 | |
323be7c4 AM |
2485 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
2486 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
8c877a82 AM |
2487 | |
2488 | # A.Marx CCD delete ccd files and routes | |
2489 | ||
323be7c4 AM |
2490 | if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]") |
2491 | { | |
2492 | unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; | |
8c877a82 | 2493 | } |
e81be1e1 | 2494 | |
323be7c4 AM |
2495 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
2496 | foreach my $key (keys %ccdroutehash) { | |
2497 | if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2498 | delete $ccdroutehash{$key}; | |
2499 | } | |
8c877a82 | 2500 | } |
323be7c4 | 2501 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 2502 | |
323be7c4 AM |
2503 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
2504 | foreach my $key (keys %ccdroute2hash) { | |
2505 | if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2506 | delete $ccdroute2hash{$key}; | |
2507 | } | |
2508 | } | |
2509 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
2510 | &writeserverconf; | |
8c877a82 | 2511 | |
323be7c4 AM |
2512 | # CCD end |
2513 | # Update collectd configuration and delete all RRD files of the removed connection | |
2514 | &writecollectdconf(); | |
2515 | system ("/usr/local/bin/openvpnctrl -drrd $confighash{$cgiparams{'KEY'}}[1]"); | |
8c877a82 | 2516 | |
323be7c4 AM |
2517 | delete $confighash{$cgiparams{'KEY'}}; |
2518 | my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
2519 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2520 | ||
2521 | } else { | |
2522 | $errormessage = $Lang::tr{'invalid key'}; | |
2523 | } | |
b2e75449 | 2524 | &General::firewall_reload(); |
ce9abb66 | 2525 | |
6e13d0a5 MT |
2526 | ### |
2527 | ### Download PKCS12 file | |
2528 | ### | |
2529 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
2530 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2531 | ||
2532 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
2533 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2534 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`; | |
2535 | exit (0); | |
2536 | ||
2537 | ### | |
2538 | ### Display certificate | |
2539 | ### | |
2540 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
2541 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2542 | ||
2543 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e | 2544 | &Header::showhttpheaders(); |
4c962356 | 2545 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
2546 | &Header::openbigbox('100%', 'LEFT', '', ''); |
2547 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
2548 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2549 | $output = &Header::cleanhtml($output,"y"); | |
2550 | print "<pre>$output</pre>\n"; | |
2551 | &Header::closebox(); | |
2552 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2553 | &Header::closebigbox(); | |
2554 | &Header::closepage(); | |
2555 | exit(0); | |
6e13d0a5 | 2556 | } |
4c962356 EK |
2557 | |
2558 | ### | |
2559 | ### Display Diffie-Hellman key | |
2560 | ### | |
2561 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show dh'}) { | |
2562 | ||
2563 | if (! -e "${General::swroot}/ovpn/ca/dh1024.pem") { | |
49abe7af | 2564 | $errormessage = $Lang::tr{'not present'}; |
4c962356 EK |
2565 | } else { |
2566 | &Header::showhttpheaders(); | |
2567 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2568 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2569 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'dh'}:"); | |
2570 | my $output = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem`; | |
2571 | $output = &Header::cleanhtml($output,"y"); | |
2572 | print "<pre>$output</pre>\n"; | |
2573 | &Header::closebox(); | |
2574 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2575 | &Header::closebigbox(); | |
2576 | &Header::closepage(); | |
2577 | exit(0); | |
2578 | } | |
2579 | ||
fd5ccb2d EK |
2580 | ### |
2581 | ### Display tls-auth key | |
2582 | ### | |
2583 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show tls-auth key'}) { | |
2584 | ||
2585 | if (! -e "${General::swroot}/ovpn/certs/ta.key") { | |
2586 | $errormessage = $Lang::tr{'not present'}; | |
2587 | } else { | |
2588 | &Header::showhttpheaders(); | |
2589 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2590 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2591 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ta key'}:"); | |
2592 | my $output = `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
2593 | $output = &Header::cleanhtml($output,"y"); | |
2594 | print "<pre>$output</pre>\n"; | |
2595 | &Header::closebox(); | |
2596 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2597 | &Header::closebigbox(); | |
2598 | &Header::closepage(); | |
2599 | exit(0); | |
2600 | } | |
2601 | ||
6e13d0a5 MT |
2602 | ### |
2603 | ### Display Certificate Revoke List | |
2604 | ### | |
2605 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
2606 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2607 | ||
49abe7af EK |
2608 | if (! -e "${General::swroot}/ovpn/crls/cacrl.pem") { |
2609 | $errormessage = $Lang::tr{'not present'}; | |
2610 | } else { | |
b2e75449 MT |
2611 | &Header::showhttpheaders(); |
2612 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2613 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2614 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
2615 | my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`; | |
2616 | $output = &Header::cleanhtml($output,"y"); | |
2617 | print "<pre>$output</pre>\n"; | |
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 MT |
2623 | } |
2624 | ||
2625 | ### | |
2626 | ### Advanced Server Settings | |
2627 | ### | |
2628 | ||
2629 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
2630 | %cgiparams = (); | |
2631 | %cahash = (); | |
2632 | %confighash = (); | |
8c877a82 | 2633 | my $disabled; |
6e13d0a5 | 2634 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); |
54fd0535 | 2635 | read_routepushfile; |
8c877a82 AM |
2636 | |
2637 | ||
c6c9630e MT |
2638 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
2639 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
2640 | # } | |
6e13d0a5 MT |
2641 | ADV_ERROR: |
2642 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
4c962356 | 2643 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 | 2644 | } |
6e13d0a5 | 2645 | if ($cgiparams{'KEEPALIVE_1'} eq '') { |
4c962356 | 2646 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
2647 | } |
2648 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
4c962356 | 2649 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
2650 | } |
2651 | if ($cgiparams{'LOG_VERB'} eq '') { | |
4c962356 | 2652 | $cgiparams{'LOG_VERB'} = '3'; |
ae9f6139 | 2653 | } |
92b87e17 | 2654 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { |
4c962356 EK |
2655 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; |
2656 | } | |
2657 | if ($cgiparams{'DAUTH'} eq '') { | |
70900745 | 2658 | $cgiparams{'DAUTH'} = 'SHA512'; |
92b87e17 | 2659 | } |
f527e53f | 2660 | if ($cgiparams{'TLSAUTH'} eq '') { |
754066e6 | 2661 | $cgiparams{'TLSAUTH'} = 'off'; |
f527e53f | 2662 | } |
6e13d0a5 MT |
2663 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
2664 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
2665 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
2666 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
2667 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
2668 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
ffbe77c8 EK |
2669 | $checked{'ADDITIONAL_CONFIGS'}{'off'} = ''; |
2670 | $checked{'ADDITIONAL_CONFIGS'}{'on'} = ''; | |
2671 | $checked{'ADDITIONAL_CONFIGS'}{$cgiparams{'ADDITIONAL_CONFIGS'}} = 'CHECKED'; | |
a79fa1d6 JPT |
2672 | $checked{'MSSFIX'}{'off'} = ''; |
2673 | $checked{'MSSFIX'}{'on'} = ''; | |
2674 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
2ee746be | 2675 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; |
49abe7af | 2676 | $selected{'LOG_VERB'}{'0'} = ''; |
6e13d0a5 MT |
2677 | $selected{'LOG_VERB'}{'1'} = ''; |
2678 | $selected{'LOG_VERB'}{'2'} = ''; | |
2679 | $selected{'LOG_VERB'}{'3'} = ''; | |
2680 | $selected{'LOG_VERB'}{'4'} = ''; | |
2681 | $selected{'LOG_VERB'}{'5'} = ''; | |
2682 | $selected{'LOG_VERB'}{'6'} = ''; | |
2683 | $selected{'LOG_VERB'}{'7'} = ''; | |
2684 | $selected{'LOG_VERB'}{'8'} = ''; | |
2685 | $selected{'LOG_VERB'}{'9'} = ''; | |
2686 | $selected{'LOG_VERB'}{'10'} = ''; | |
2687 | $selected{'LOG_VERB'}{'11'} = ''; | |
6e13d0a5 | 2688 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; |
4c962356 EK |
2689 | $selected{'DAUTH'}{'whirlpool'} = ''; |
2690 | $selected{'DAUTH'}{'SHA512'} = ''; | |
2691 | $selected{'DAUTH'}{'SHA384'} = ''; | |
2692 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
2693 | $selected{'DAUTH'}{'SHA1'} = ''; |
2694 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
49abe7af EK |
2695 | $checked{'TLSAUTH'}{'off'} = ''; |
2696 | $checked{'TLSAUTH'}{'on'} = ''; | |
2697 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
f527e53f | 2698 | |
6e13d0a5 MT |
2699 | &Header::showhttpheaders(); |
2700 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
2701 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2702 | if ($errormessage) { | |
c6c9630e MT |
2703 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
2704 | print "<class name='base'>$errormessage\n"; | |
2705 | print " </class>\n"; | |
2706 | &Header::closebox(); | |
6e13d0a5 MT |
2707 | } |
2708 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
4c962356 | 2709 | print <<END; |
b376fae4 | 2710 | <form method='post' enctype='multipart/form-data'> |
b2e75449 | 2711 | <table width='100%' border=0> |
4c962356 EK |
2712 | <tr> |
2713 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
6e13d0a5 MT |
2714 | </tr> |
2715 | <tr> | |
4c962356 | 2716 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> |
6e13d0a5 MT |
2717 | </tr> |
2718 | <tr> | |
4c962356 | 2719 | <td class='base'>Domain</td> |
8c877a82 | 2720 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> |
6e13d0a5 MT |
2721 | </tr> |
2722 | <tr> | |
4c962356 EK |
2723 | <td class='base'>DNS</td> |
2724 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
6e13d0a5 MT |
2725 | </tr> |
2726 | <tr> | |
4c962356 EK |
2727 | <td class='base'>WINS</td> |
2728 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
2729 | </tr> | |
54fd0535 | 2730 | <tr> |
4c962356 | 2731 | <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td> |
54fd0535 MT |
2732 | </tr> |
2733 | <tr> | |
4c962356 EK |
2734 | <td class='base'>$Lang::tr{'ovpn routes push'}</td> |
2735 | <td colspan='2'> | |
2736 | <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'> | |
54fd0535 MT |
2737 | END |
2738 | ; | |
2739 | ||
2740 | if ($cgiparams{'ROUTES_PUSH'} ne '') | |
2741 | { | |
2742 | print $cgiparams{'ROUTES_PUSH'}; | |
2743 | } | |
2744 | ||
8c877a82 | 2745 | print <<END; |
54fd0535 MT |
2746 | </textarea></td> |
2747 | </tr> | |
6e13d0a5 MT |
2748 | </tr> |
2749 | </table> | |
2750 | <hr size='1'> | |
4c962356 | 2751 | <table width='100%'> |
ffbe77c8 | 2752 | <tr> |
4c962356 | 2753 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> |
ffbe77c8 EK |
2754 | </tr> |
2755 | ||
2756 | <tr> | |
4c962356 | 2757 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
ffbe77c8 EK |
2758 | </tr> |
2759 | ||
2760 | <tr> | |
4c962356 EK |
2761 | <td class='base'>Client-To-Client</td> |
2762 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
ffbe77c8 EK |
2763 | </tr> |
2764 | ||
2765 | <tr> | |
4c962356 EK |
2766 | <td class='base'>Redirect-Gateway def1</td> |
2767 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
ffbe77c8 EK |
2768 | </tr> |
2769 | ||
4c962356 | 2770 | <tr> |
ffbe77c8 EK |
2771 | <td class='base'>$Lang::tr{'ovpn add conf'}</td> |
2772 | <td><input type='checkbox' name='ADDITIONAL_CONFIGS' $checked{'ADDITIONAL_CONFIGS'}{'on'} /></td> | |
2773 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2774 | </tr> | |
2775 | ||
2776 | <tr> | |
2777 | <td class='base'>mssfix</td> | |
2778 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
2779 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2780 | </tr> | |
2781 | ||
4c962356 | 2782 | <tr> |
ffbe77c8 EK |
2783 | <td class='base'>fragment <br></td> |
2784 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
2785 | </tr> | |
2786 | ||
2787 | ||
2788 | <tr> | |
2789 | <td class='base'>Max-Clients</td> | |
2790 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> | |
2791 | </tr> | |
2792 | <tr> | |
2793 | <td class='base'>Keepalive <br /> | |
2794 | (ping/ping-restart)</td> | |
2795 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
2796 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
2797 | </tr> | |
2ee746be SS |
2798 | |
2799 | <tr> | |
2800 | <td class='base'>$Lang::tr{'ovpn mtu-disc'}</td> | |
2801 | <td><input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'}</td> | |
2802 | <td><input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'}</td> | |
2803 | <td><input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'}</td> | |
2804 | <td><input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'}</td> | |
2805 | </tr> | |
a79fa1d6 JPT |
2806 | </table> |
2807 | ||
a79fa1d6 | 2808 | <hr size='1'> |
4c962356 | 2809 | <table width='100%'> |
a79fa1d6 | 2810 | <tr> |
49abe7af | 2811 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> |
a79fa1d6 JPT |
2812 | </tr> |
2813 | <tr> | |
49abe7af | 2814 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> |
4c962356 EK |
2815 | </tr> |
2816 | ||
2817 | <tr><td class='base'>VERB</td> | |
2818 | <td><select name='LOG_VERB'> | |
49abe7af EK |
2819 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option> |
2820 | <option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
2821 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
2822 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
2823 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
2824 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
2825 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
2826 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
2827 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
2828 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
2829 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
2830 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
2831 | </td></select> | |
2832 | </table> | |
4c962356 | 2833 | |
6e13d0a5 | 2834 | <hr size='1'> |
4c962356 | 2835 | <table width='100%'> |
6e13d0a5 | 2836 | <tr> |
4c962356 EK |
2837 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}</b></td> |
2838 | </tr> | |
2839 | <tr> | |
2840 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> | |
6e13d0a5 | 2841 | </tr> |
4c962356 EK |
2842 | <tr><td class='base'>$Lang::tr{'ovpn ha'}</td> |
2843 | <td><select name='DAUTH'> | |
b2e75449 MT |
2844 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
2845 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
2846 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
2847 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
f3dfb261 | 2848 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
4c962356 EK |
2849 | </select> |
2850 | </td> | |
040b8b0c | 2851 | <td>$Lang::tr{'openvpn default'}: <span class="base">SHA1 (160 $Lang::tr{'bit'})</span></td> |
49abe7af | 2852 | </tr> |
6e13d0a5 | 2853 | </table> |
49abe7af EK |
2854 | |
2855 | <table width='100%'> | |
6e13d0a5 | 2856 | <tr> |
49abe7af | 2857 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
6e13d0a5 | 2858 | </tr> |
4c962356 | 2859 | |
6e13d0a5 | 2860 | <tr> |
49abe7af EK |
2861 | <td class='base'>HMAC tls-auth</td> |
2862 | <td><input type='checkbox' name='TLSAUTH' $checked{'TLSAUTH'}{'on'} /></td> | |
2863 | </tr> | |
2864 | </table><hr> | |
8c877a82 AM |
2865 | END |
2866 | ||
2867 | if ( -e "/var/run/openvpn.pid"){ | |
2868 | print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br> | |
2869 | $Lang::tr{'server restart'}<br><br> | |
2870 | <hr>"; | |
49abe7af | 2871 | print<<END; |
52d08bcb AM |
2872 | <table width='100%'> |
2873 | <tr> | |
2874 | <td> </td> | |
2875 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td> | |
2876 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2877 | <td> </td> | |
2878 | </tr> | |
2879 | </table> | |
2880 | </form> | |
2881 | END | |
2882 | ; | |
2883 | ||
2884 | ||
2885 | }else{ | |
8c877a82 | 2886 | |
49abe7af | 2887 | print<<END; |
6e13d0a5 MT |
2888 | <table width='100%'> |
2889 | <tr> | |
2890 | <td> </td> | |
2891 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
2892 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2893 | <td> </td> | |
2894 | </tr> | |
2895 | </table> | |
2896 | </form> | |
2897 | END | |
2898 | ; | |
52d08bcb | 2899 | } |
6e13d0a5 | 2900 | &Header::closebox(); |
c6c9630e | 2901 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2902 | &Header::closebigbox(); |
2903 | &Header::closepage(); | |
2904 | exit(0); | |
2905 | ||
8c877a82 AM |
2906 | |
2907 | # A.Marx CCD Add,delete or edit CCD net | |
2908 | ||
2909 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} || | |
2910 | $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} || | |
2911 | $cgiparams{'ACTION'} eq "kill" || | |
2912 | $cgiparams{'ACTION'} eq "edit" || | |
2913 | $cgiparams{'ACTION'} eq 'editsave'){ | |
2914 | &Header::showhttpheaders(); | |
2915 | &Header::openpage($Lang::tr{'ccd net'}, 1, ''); | |
2916 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2917 | ||
2918 | if ($cgiparams{'ACTION'} eq "kill"){ | |
2919 | &delccdnet($cgiparams{'net'}); | |
2920 | } | |
2921 | ||
2922 | if ($cgiparams{'ACTION'} eq 'editsave'){ | |
2923 | my ($a,$b) =split (/\|/,$cgiparams{'ccdname'}); | |
2924 | if ( $a ne $b){ &modccdnet($a,$b);} | |
5068ac38 AM |
2925 | $cgiparams{'ccdname'}=''; |
2926 | $cgiparams{'ccdsubnet'}=''; | |
8c877a82 AM |
2927 | } |
2928 | ||
2929 | if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) { | |
e2429e8d | 2930 | &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'}); |
8c877a82 AM |
2931 | } |
2932 | if ($errormessage) { | |
2933 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2934 | print "<class name='base'>$errormessage"; | |
2935 | print " </class>"; | |
2936 | &Header::closebox(); | |
2937 | } | |
2938 | if ($cgiparams{'ACTION'} eq "edit"){ | |
2939 | ||
2940 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'}); | |
2941 | ||
49abe7af | 2942 | print <<END; |
631b67b7 | 2943 | <table width='100%' border='0'> |
8c877a82 AM |
2944 | <tr><form method='post'> |
2945 | <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
a9fb14d0 | 2946 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly='readonly' /></td></tr> |
8c877a82 AM |
2947 | <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/> |
2948 | <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' /> | |
2949 | </td></tr> | |
2950 | </table></form> | |
2951 | END | |
2952 | ; | |
2953 | &Header::closebox(); | |
2954 | ||
2955 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
49abe7af | 2956 | print <<END; |
8c877a82 AM |
2957 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> |
2958 | <tr> | |
2959 | <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> | |
2960 | END | |
2961 | ; | |
2962 | } | |
2963 | else{ | |
2964 | if (! -e "/var/run/openvpn.pid"){ | |
2965 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'}); | |
49abe7af | 2966 | print <<END; |
8c877a82 AM |
2967 | <table width='100%' border='0'> |
2968 | <tr><form method='post'> | |
2969 | <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr> | |
2970 | <tr> | |
2971 | <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2972 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr> | |
2973 | <tr><td colspan=4><hr /></td></tr><tr> | |
2974 | <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> | |
2975 | </table></form> | |
2976 | END | |
2977 | ||
2978 | &Header::closebox(); | |
2979 | } | |
2980 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
5068ac38 AM |
2981 | if ( -e "/var/run/openvpn.pid"){ |
2982 | print "<b>$Lang::tr{'attention'}:</b><br>"; | |
2983 | print "$Lang::tr{'ccd noaddnet'}<br><hr>"; | |
2984 | } | |
2985 | ||
4c962356 | 2986 | print <<END; |
99bfa85c | 2987 | <table width='100%' cellpadding='0' cellspacing='1'> |
8c877a82 AM |
2988 | <tr> |
2989 | <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> | |
2990 | END | |
2991 | ; | |
2992 | } | |
2993 | my %ccdconfhash=(); | |
2994 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
2995 | my @ccdconf=(); | |
2996 | my $count=0; | |
df9b48b7 | 2997 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
2998 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); |
2999 | $count++; | |
3000 | my $ccdhosts = &hostsinnet($ccdconf[0]); | |
3001 | if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
3002 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
3003 | print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>"; | |
4c962356 | 3004 | print <<END; |
8c877a82 | 3005 | <form method='post' /> |
1638682b | 3006 | <input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> |
8c877a82 AM |
3007 | <input type='hidden' name='ACTION' value='edit'/> |
3008 | <input type='hidden' name='ccdname' value='$ccdconf[0]' /> | |
3009 | <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' /> | |
3010 | </form></td> | |
3011 | <form method='post' /> | |
3012 | <td><input type='hidden' name='ACTION' value='kill'/> | |
3013 | <input type='hidden' name='number' value='$count' /> | |
3014 | <input type='hidden' name='net' value='$ccdconf[0]' /> | |
1638682b | 3015 | <input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /></form></td></tr> |
8c877a82 AM |
3016 | END |
3017 | ; | |
3018 | } | |
3019 | print "</table></form>"; | |
3020 | &Header::closebox(); | |
3021 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3022 | &Header::closebigbox(); | |
3023 | &Header::closepage(); | |
3024 | exit(0); | |
3025 | ||
3026 | #END CCD | |
3027 | ||
6e13d0a5 MT |
3028 | ### |
3029 | ### Openvpn Connections Statistics | |
3030 | ### | |
3031 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
3032 | &Header::showhttpheaders(); | |
3033 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
3034 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
3035 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
3036 | ||
3037 | # | |
3038 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
3039 | # protocol temp removed | |
4c962356 | 3040 | print <<END; |
99bfa85c | 3041 | <table width='100%' cellpadding='2' cellspacing='0' class='tbl'> |
6e13d0a5 | 3042 | <tr> |
99bfa85c AM |
3043 | <th><b>$Lang::tr{'common name'}</b></th> |
3044 | <th><b>$Lang::tr{'real address'}</b></th> | |
3045 | <th><b>$Lang::tr{'virtual address'}</b></th> | |
3046 | <th><b>$Lang::tr{'loged in at'}</b></th> | |
3047 | <th><b>$Lang::tr{'bytes sent'}</b></th> | |
3048 | <th><b>$Lang::tr{'bytes received'}</b></th> | |
3049 | <th><b>$Lang::tr{'last activity'}</b></th> | |
6e13d0a5 MT |
3050 | </tr> |
3051 | END | |
3052 | ; | |
87fe47e9 | 3053 | my $filename = "/var/run/ovpnserver.log"; |
6e13d0a5 MT |
3054 | open(FILE, $filename) or die 'Unable to open config file.'; |
3055 | my @current = <FILE>; | |
3056 | close(FILE); | |
3057 | my @users =(); | |
3058 | my $status; | |
3059 | my $uid = 0; | |
3060 | my $cn; | |
3061 | my @match = (); | |
3062 | my $proto = "udp"; | |
3063 | my $address; | |
3064 | my %userlookup = (); | |
3065 | foreach my $line (@current) | |
3066 | { | |
3067 | chomp($line); | |
3068 | if ( $line =~ /^Updated,(.+)/){ | |
3069 | @match = split( /^Updated,(.+)/, $line); | |
3070 | $status = $match[1]; | |
3071 | } | |
c6c9630e | 3072 | #gian |
6e13d0a5 MT |
3073 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
3074 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
3075 | if ($match[1] ne "Common Name") { | |
3076 | $cn = $match[1]; | |
3077 | $userlookup{$match[2]} = $uid; | |
3078 | $users[$uid]{'CommonName'} = $match[1]; | |
3079 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
3080 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
3081 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
3082 | $users[$uid]{'Since'} = $match[5]; |
3083 | $users[$uid]{'Proto'} = $proto; | |
3084 | $uid++; | |
3085 | } | |
3086 | } | |
3087 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
3088 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
3089 | if ($match[1] ne "Virtual Address") { | |
3090 | $address = $match[3]; | |
3091 | #find the uid in the lookup table | |
3092 | $uid = $userlookup{$address}; | |
3093 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
3094 | $users[$uid]{'LastRef'} = $match[4]; | |
3095 | } | |
3096 | } | |
3097 | } | |
3098 | my $user2 = @users; | |
3099 | if ($user2 >= 1){ | |
99bfa85c | 3100 | for (my $idx = 1; $idx <= $user2; $idx++){ |
6e13d0a5 | 3101 | if ($idx % 2) { |
99bfa85c AM |
3102 | print "<tr>"; |
3103 | $col="bgcolor='$color{'color22'}'"; | |
3104 | } else { | |
3105 | print "<tr>"; | |
3106 | $col="bgcolor='$color{'color20'}'"; | |
6e13d0a5 | 3107 | } |
99bfa85c AM |
3108 | print "<td align='left' $col>$users[$idx-1]{'CommonName'}</td>"; |
3109 | print "<td align='left' $col>$users[$idx-1]{'RealAddress'}</td>"; | |
3110 | print "<td align='left' $col>$users[$idx-1]{'VirtualAddress'}</td>"; | |
3111 | print "<td align='left' $col>$users[$idx-1]{'Since'}</td>"; | |
3112 | print "<td align='left' $col>$users[$idx-1]{'BytesSent'}</td>"; | |
3113 | print "<td align='left' $col>$users[$idx-1]{'BytesReceived'}</td>"; | |
3114 | print "<td align='left' $col>$users[$idx-1]{'LastRef'}</td>"; | |
3115 | } | |
3116 | } | |
6e13d0a5 MT |
3117 | |
3118 | print "</table>"; | |
49abe7af | 3119 | print <<END; |
6e13d0a5 MT |
3120 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> |
3121 | <tr><td></td></tr> | |
3122 | <tr><td></td></tr> | |
3123 | <tr><td></td></tr> | |
3124 | <tr><td></td></tr> | |
3125 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
3126 | </table> | |
3127 | END | |
3128 | ; | |
3129 | &Header::closebox(); | |
3130 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3131 | &Header::closebigbox(); | |
3132 | &Header::closepage(); | |
3133 | exit(0); | |
3134 | ||
3135 | ### | |
3136 | ### Download Certificate | |
3137 | ### | |
3138 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
3139 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 3140 | |
6e13d0a5 | 3141 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
3142 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
3143 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
3144 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
3145 | exit (0); | |
3146 | } | |
3147 | ||
3148 | ### | |
3149 | ### Enable/Disable connection | |
3150 | ### | |
ce9abb66 | 3151 | |
c6c9630e MT |
3152 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
3153 | ||
3154 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3155 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3156 | ||
3157 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 3158 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
3159 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
3160 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3161 | #&writeserverconf(); | |
3162 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3163 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3164 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3165 | # } | |
3166 | } else { | |
3167 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
3168 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3169 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3170 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
3171 | # } | |
3172 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3173 | #&writeserverconf(); | |
3174 | } | |
3175 | } else { | |
3176 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
3177 | } |
3178 | ||
3179 | ### | |
3180 | ### Restart connection | |
3181 | ### | |
3182 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
3183 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3184 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3185 | ||
3186 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
3187 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
3188 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3189 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3190 | # } | |
6e13d0a5 | 3191 | } else { |
c6c9630e | 3192 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
3193 | } |
3194 | ||
ce9abb66 | 3195 | ### |
7c1d9faf | 3196 | # m.a.d net2net |
ce9abb66 AH |
3197 | ### |
3198 | ||
3199 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
3200 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3201 | &Header::showhttpheaders(); | |
4c962356 | 3202 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
ce9abb66 AH |
3203 | &Header::openbigbox('100%', 'LEFT', '', ''); |
3204 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
3205 | |
3206 | if ( -s "${General::swroot}/ovpn/settings") { | |
3207 | ||
49abe7af | 3208 | print <<END; |
ce9abb66 | 3209 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3210 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
ce9abb66 AH |
3211 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> |
3212 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
3213 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
3214 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
3215 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
3216 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
3217 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
e3edceeb | 3218 | <tr><td> </td><td>Import Connection Name</td></tr> |
040b8b0c | 3219 | <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>$Lang::tr{'openvpn default'}: Client Packagename</td></tr> |
54fd0535 | 3220 | <tr><td colspan='3'><hr /></td></tr> |
8c877a82 | 3221 | <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
ce9abb66 AH |
3222 | </form></table> |
3223 | END | |
3224 | ; | |
8c877a82 | 3225 | |
ce9abb66 | 3226 | |
b278daf3 | 3227 | } else { |
49abe7af | 3228 | print <<END; |
b278daf3 | 3229 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3230 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
b278daf3 | 3231 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> |
8c877a82 | 3232 | <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
b278daf3 AH |
3233 | </form></table> |
3234 | END | |
3235 | ; | |
3236 | ||
3237 | } | |
3238 | ||
ce9abb66 | 3239 | &Header::closebox(); |
4c962356 | 3240 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
ce9abb66 AH |
3241 | &Header::closebigbox(); |
3242 | &Header::closepage(); | |
3243 | exit (0); | |
3244 | ||
3245 | ### | |
7c1d9faf | 3246 | # m.a.d net2net |
ce9abb66 AH |
3247 | ### |
3248 | ||
3249 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
3250 | ||
3251 | my @firen2nconf; | |
3252 | my @confdetails; | |
3253 | my $uplconffilename =''; | |
54fd0535 | 3254 | my $uplconffilename2 =''; |
ce9abb66 | 3255 | my $uplp12name = ''; |
54fd0535 | 3256 | my $uplp12name2 = ''; |
ce9abb66 AH |
3257 | my @rem_subnet; |
3258 | my @rem_subnet2; | |
3259 | my @tmposupnet3; | |
3260 | my $key; | |
54fd0535 | 3261 | my @n2nname; |
ce9abb66 AH |
3262 | |
3263 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3264 | ||
3265 | # Check if a file is uploaded | |
3266 | ||
3267 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3268 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3269 | goto N2N_ERROR; | |
3270 | } | |
3271 | ||
3272 | # Move uploaded IPfire n2n package to temporary file | |
3273 | ||
3274 | (my $fh, my $filename) = tempfile( ); | |
3275 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3276 | $errormessage = $!; | |
3277 | goto N2N_ERROR; | |
3278 | } | |
3279 | ||
3280 | my $zip = Archive::Zip->new(); | |
3281 | my $zipName = $filename; | |
3282 | my $status = $zip->read( $zipName ); | |
3283 | if ($status != AZ_OK) { | |
3284 | $errormessage = "Read of $zipName failed\n"; | |
3285 | goto N2N_ERROR; | |
3286 | } | |
3287 | ||
3288 | my $tempdir = tempdir( CLEANUP => 1 ); | |
3289 | my @files = $zip->memberNames(); | |
3290 | for(@files) { | |
3291 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
3292 | } | |
3293 | my $countfiles = @files; | |
3294 | ||
3295 | # Check if we have not more then 2 files | |
3296 | ||
3297 | if ( $countfiles == 2){ | |
3298 | foreach (@files){ | |
3299 | if ( $_ =~ /.conf$/){ | |
3300 | $uplconffilename = $_; | |
3301 | } | |
3302 | if ( $_ =~ /.p12$/){ | |
3303 | $uplp12name = $_; | |
3304 | } | |
3305 | } | |
3306 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
3307 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
3308 | goto N2N_ERROR; | |
3309 | } | |
3310 | ||
3311 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
3312 | @firen2nconf = <FILE>; | |
3313 | close (FILE); | |
3314 | chomp(@firen2nconf); | |
ce9abb66 AH |
3315 | } else { |
3316 | ||
3317 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
3318 | goto N2N_ERROR; | |
3319 | } | |
3320 | ||
7c1d9faf AH |
3321 | ### |
3322 | # m.a.d net2net | |
ce9abb66 | 3323 | ### |
54fd0535 MT |
3324 | |
3325 | if ($cgiparams{'n2nname'} ne ''){ | |
3326 | ||
3327 | $uplconffilename2 = "$cgiparams{'n2nname'}.conf"; | |
3328 | $uplp12name2 = "$cgiparams{'n2nname'}.p12"; | |
3329 | $n2nname[0] = $cgiparams{'n2nname'}; | |
3330 | my @n2nname2 = split(/\./,$uplconffilename); | |
3331 | $n2nname2[0] =~ s/\n|\r//g; | |
3332 | my $input1 = "${General::swroot}/ovpn/certs/$uplp12name"; | |
3333 | my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2"; | |
3334 | my $input2 = "$n2nname2[0]n2n"; | |
3335 | my $output2 = "$n2nname[0]n2n"; | |
3336 | my $filename = "$tempdir/$uplconffilename"; | |
3337 | open(FILE, "< $filename") or die 'Unable to open config file.'; | |
3338 | my @current = <FILE>; | |
3339 | close(FILE); | |
3340 | foreach (@current) {s/$input1/$output1/g;} | |
3341 | foreach (@current) {s/$input2/$output2/g;} | |
3342 | open (OUT, "> $filename") || die 'Unable to open config file.'; | |
3343 | print OUT @current; | |
3344 | close OUT; | |
ce9abb66 | 3345 | |
54fd0535 MT |
3346 | }else{ |
3347 | $uplconffilename2 = $uplconffilename; | |
3348 | $uplp12name2 = $uplp12name; | |
3349 | @n2nname = split(/\./,$uplconffilename); | |
ce9abb66 | 3350 | $n2nname[0] =~ s/\n|\r//g; |
54fd0535 | 3351 | } |
7c1d9faf AH |
3352 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
3353 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
ce9abb66 | 3354 | |
7dfcaef0 AM |
3355 | #Add collectd settings to configfile |
3356 | open(FILE, ">> $tempdir/$uplconffilename") or die 'Unable to open config file.'; | |
3357 | print FILE "# Logfile\n"; | |
3358 | print FILE "status-version 1\n"; | |
3359 | print FILE "status /var/run/openvpn/$n2nname[0]-n2n 10\n"; | |
3360 | close FILE; | |
3361 | ||
54fd0535 | 3362 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2"); |
ce9abb66 AH |
3363 | |
3364 | if ($? ne 0) { | |
3365 | $errormessage = "*.conf move failed: $!"; | |
3366 | unlink ($filename); | |
3367 | goto N2N_ERROR; | |
3368 | } | |
3369 | ||
54fd0535 | 3370 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2"); |
b278daf3 AH |
3371 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; |
3372 | ||
ce9abb66 AH |
3373 | if ($? ne 0) { |
3374 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3375 | unlink ($filename); | |
3376 | goto N2N_ERROR; | |
3377 | } | |
3378 | ||
3379 | my $complzoactive; | |
d96c89eb | 3380 | my $mssfixactive; |
4c962356 | 3381 | my $authactive; |
d96c89eb | 3382 | my $n2nfragment; |
4c962356 | 3383 | my @n2nmtudisc = split(/ /, (grep { /^mtu-disc/ } @firen2nconf)[0]); |
60f396d7 | 3384 | my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
54fd0535 | 3385 | my @n2nproto = split(/-/, $n2nproto2[1]); |
ce9abb66 AH |
3386 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); |
3387 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
3388 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
3389 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
d96c89eb AH |
3390 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
3391 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
54fd0535 | 3392 | #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]); |
d96c89eb | 3393 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); |
ce9abb66 AH |
3394 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
3395 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
3396 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
3397 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
54fd0535 | 3398 | my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]); |
ce9abb66 | 3399 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); |
4c962356 | 3400 | my @n2ncipher = split(/ /, (grep { /^cipher/ } @firen2nconf)[0]); |
f527e53f | 3401 | my @n2nauth = split(/ /, (grep { /^auth/ } @firen2nconf)[0]);; |
60f396d7 | 3402 | |
ce9abb66 AH |
3403 | ### |
3404 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
3405 | ### | |
3406 | ||
ce9abb66 | 3407 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
3408 | $n2novpnsub[0] =~ s/\n|\r//g; |
3409 | $n2novpnsub[1] =~ s/\n|\r//g; | |
3410 | $n2novpnsub[2] =~ s/\n|\r//g; | |
60f396d7 | 3411 | $n2nproto[0] =~ s/\n|\r//g; |
ce9abb66 AH |
3412 | $n2nport[1] =~ s/\n|\r//g; |
3413 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
3414 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 3415 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 3416 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 3417 | $n2nfragment[1] =~ s/\n|\r//g; |
54fd0535 | 3418 | $n2nmgmt[2] =~ s/\n|\r//g; |
2ee746be | 3419 | $n2nmtudisc[1] =~ s/\n|\r//g; |
4c962356 EK |
3420 | $n2ncipher[1] =~ s/\n|\r//g; |
3421 | $n2nauth[1] =~ s/\n|\r//g; | |
ce9abb66 | 3422 | chomp ($complzoactive); |
d96c89eb | 3423 | chomp ($mssfixactive); |
ce9abb66 AH |
3424 | |
3425 | ### | |
7c1d9faf | 3426 | # m.a.d net2net |
ce9abb66 AH |
3427 | ### |
3428 | ||
3429 | ### | |
3430 | # Check if there is no other entry with this name | |
3431 | ### | |
3432 | ||
3433 | foreach my $dkey (keys %confighash) { | |
3434 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
3435 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3436 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3437 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3438 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
ce9abb66 AH |
3439 | goto N2N_ERROR; |
3440 | } | |
3441 | } | |
3442 | ||
d96c89eb AH |
3443 | ### |
3444 | # Check if OpenVPN Subnet is valid | |
3445 | ### | |
3446 | ||
3447 | foreach my $dkey (keys %confighash) { | |
3448 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
3449 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
3450 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3451 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3452 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3453 | goto N2N_ERROR; |
3454 | } | |
3455 | } | |
3456 | ||
3457 | ### | |
4c962356 | 3458 | # Check if Dest Port is vaild |
d96c89eb AH |
3459 | ### |
3460 | ||
3461 | foreach my $dkey (keys %confighash) { | |
3462 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
3463 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
3464 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3465 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3466 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3467 | goto N2N_ERROR; |
3468 | } | |
3469 | } | |
3470 | ||
3471 | ||
3472 | ||
ce9abb66 AH |
3473 | $key = &General::findhasharraykey (\%confighash); |
3474 | ||
49abe7af | 3475 | foreach my $i (0 .. 42) { $confighash{$key}[$i] = "";} |
350f2980 | 3476 | |
ce9abb66 AH |
3477 | $confighash{$key}[0] = 'off'; |
3478 | $confighash{$key}[1] = $n2nname[0]; | |
350f2980 | 3479 | $confighash{$key}[2] = $n2nname[0]; |
ce9abb66 AH |
3480 | $confighash{$key}[3] = 'net'; |
3481 | $confighash{$key}[4] = 'cert'; | |
3482 | $confighash{$key}[6] = 'client'; | |
3483 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
350f2980 SS |
3484 | $confighash{$key}[10] = $n2nremote[1]; |
3485 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; | |
54fd0535 | 3486 | $confighash{$key}[22] = $n2nmgmt[2]; |
350f2980 | 3487 | $confighash{$key}[23] = $mssfixactive; |
d96c89eb | 3488 | $confighash{$key}[24] = $n2nfragment[1]; |
350f2980 | 3489 | $confighash{$key}[25] = 'IPFire n2n Client'; |
ce9abb66 | 3490 | $confighash{$key}[26] = 'red'; |
350f2980 SS |
3491 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; |
3492 | $confighash{$key}[28] = $n2nproto[0]; | |
3493 | $confighash{$key}[29] = $n2nport[1]; | |
3494 | $confighash{$key}[30] = $complzoactive; | |
3495 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
49abe7af | 3496 | $confighash{$key}[38] = $n2nmtudisc[1]; |
4c962356 EK |
3497 | $confighash{$key}[39] = $n2nauth[1]; |
3498 | $confighash{$key}[40] = $n2ncipher[1]; | |
49abe7af | 3499 | $confighash{$key}[41] = 'disabled'; |
ce9abb66 AH |
3500 | |
3501 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
d96c89eb | 3502 | |
ce9abb66 AH |
3503 | N2N_ERROR: |
3504 | ||
3505 | &Header::showhttpheaders(); | |
3506 | &Header::openpage('Validate imported configuration', 1, ''); | |
3507 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3508 | if ($errormessage) { | |
3509 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3510 | print "<class name='base'>$errormessage"; | |
3511 | print " </class>"; | |
3512 | &Header::closebox(); | |
3513 | ||
3514 | } else | |
3515 | { | |
3516 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
3517 | } | |
3518 | if ($errormessage eq ''){ | |
49abe7af | 3519 | print <<END; |
ce9abb66 AH |
3520 | <!-- ipfire net2net config gui --> |
3521 | <table width='100%'> | |
3522 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
3523 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
3524 | <tr><td> </td><td> </td></tr> | |
3525 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
3526 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
3527 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
4c962356 | 3528 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}:</td><td><b>$confighash{$key}[11]</b></td></tr> |
ce9abb66 AH |
3529 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> |
3530 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
3531 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
3532 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
4c962356 EK |
3533 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b>$confighash{$key}[23]</b></td></tr> |
3534 | <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 | 3535 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
350f2980 | 3536 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td><td><b>$confighash{$key}[38]</b></td></tr> |
54fd0535 | 3537 | <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr> |
4c962356 EK |
3538 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn hmac'}:</td><td><b>$confighash{$key}[39]</b></td></tr> |
3539 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td><td><b>$confighash{$key}[40]</b></td></tr> | |
ce9abb66 AH |
3540 | <tr><td> </td><td> </td></tr> |
3541 | </table> | |
3542 | END | |
3543 | ; | |
3544 | &Header::closebox(); | |
3545 | } | |
3546 | ||
3547 | if ($errormessage) { | |
3548 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3549 | } else { | |
3550 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
3551 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
3552 | print "<input type='hidden' name='KEY' value='$key' />"; | |
3553 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3554 | } | |
3555 | &Header::closebigbox(); | |
3556 | &Header::closepage(); | |
4c962356 | 3557 | exit(0); |
ce9abb66 AH |
3558 | |
3559 | ||
3560 | ## | |
3561 | ### Accept IPFire n2n Package Settings | |
3562 | ### | |
3563 | ||
3564 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3565 | ||
3566 | ### | |
3567 | ### Discard and Rollback IPFire n2n Package Settings | |
3568 | ### | |
3569 | ||
3570 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3571 | ||
3572 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3573 | ||
3574 | if ($confighash{$cgiparams{'KEY'}}) { | |
3575 | ||
3576 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
3577 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3578 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
3579 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
3580 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
3581 | delete $confighash{$cgiparams{'KEY'}}; | |
3582 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3583 | ||
3584 | } else { | |
3585 | $errormessage = $Lang::tr{'invalid key'}; | |
3586 | } | |
3587 | ||
3588 | ||
3589 | ### | |
7c1d9faf | 3590 | # m.a.d net2net |
ce9abb66 AH |
3591 | ### |
3592 | ||
3593 | ||
3594 | ### | |
3595 | ### Adding a new connection | |
3596 | ### | |
6e13d0a5 MT |
3597 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
3598 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
3599 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
8c877a82 | 3600 | |
6e13d0a5 MT |
3601 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
3602 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3603 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3604 | ||
3605 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
8c877a82 AM |
3606 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
3607 | $errormessage = $Lang::tr{'invalid key'}; | |
3608 | goto VPNCONF_END; | |
3609 | } | |
4c962356 EK |
3610 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; |
3611 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
3612 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
3613 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
3614 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
3615 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
3616 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
3617 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
8c877a82 | 3618 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; |
4c962356 EK |
3619 | $cgiparams{'OVPN_MGMT'} = $confighash{$cgiparams{'KEY'}}[22]; |
3620 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
3621 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
3622 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; | |
3623 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
3624 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
3625 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
3626 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
3627 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
3628 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
3629 | $cgiparams{'CHECK1'} = $confighash{$cgiparams{'KEY'}}[32]; | |
df9b48b7 | 3630 | $name=$cgiparams{'CHECK1'} ; |
4c962356 EK |
3631 | $cgiparams{$name} = $confighash{$cgiparams{'KEY'}}[33]; |
3632 | $cgiparams{'RG'} = $confighash{$cgiparams{'KEY'}}[34]; | |
3633 | $cgiparams{'CCD_DNS1'} = $confighash{$cgiparams{'KEY'}}[35]; | |
3634 | $cgiparams{'CCD_DNS2'} = $confighash{$cgiparams{'KEY'}}[36]; | |
3635 | $cgiparams{'CCD_WINS'} = $confighash{$cgiparams{'KEY'}}[37]; | |
52d08bcb | 3636 | $cgiparams{'PMTU_DISCOVERY'} = $confighash{$cgiparams{'KEY'}}[38]; |
4c962356 EK |
3637 | $cgiparams{'DAUTH'} = $confighash{$cgiparams{'KEY'}}[39]; |
3638 | $cgiparams{'DCIPHER'} = $confighash{$cgiparams{'KEY'}}[40]; | |
49abe7af | 3639 | $cgiparams{'TLSAUTH'} = $confighash{$cgiparams{'KEY'}}[41]; |
8c877a82 | 3640 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
c6c9630e | 3641 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); |
18837a6a | 3642 | |
8c877a82 | 3643 | #A.Marx CCD check iroute field and convert it to decimal |
52d08bcb | 3644 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
3645 | my @temp=(); |
3646 | my %ccdroutehash=(); | |
3647 | my $keypoint=0; | |
5068ac38 AM |
3648 | my $ip; |
3649 | my $cidr; | |
8c877a82 AM |
3650 | if ($cgiparams{'IR'} ne ''){ |
3651 | @temp = split("\n",$cgiparams{'IR'}); | |
3652 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3653 | #find key to use | |
3654 | foreach my $key (keys %ccdroutehash) { | |
3655 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3656 | $keypoint=$key; | |
3657 | delete $ccdroutehash{$key}; | |
3658 | }else{ | |
3659 | $keypoint = &General::findhasharraykey (\%ccdroutehash); | |
3660 | } | |
3661 | } | |
3662 | $ccdroutehash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3663 | my $i=1; | |
3664 | my $val=0; | |
3665 | foreach $val (@temp){ | |
3666 | chomp($val); | |
3667 | $val=~s/\s*$//g; | |
5068ac38 | 3668 | #check if iroute exists in ccdroute or if new iroute is part of an existing one |
8c877a82 AM |
3669 | foreach my $key (keys %ccdroutehash) { |
3670 | foreach my $oldiroute ( 1 .. $#{$ccdroutehash{$key}}){ | |
5068ac38 AM |
3671 | if ($ccdroutehash{$key}[$oldiroute] eq "$val") { |
3672 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3673 | goto VPNCONF_ERROR; | |
3674 | } | |
3675 | my ($ip1,$cidr1) = split (/\//, $val); | |
82c809c7 | 3676 | $ip1 = &General::getnetworkip($ip1,&General::iporsubtocidr($cidr1)); |
5068ac38 AM |
3677 | my ($ip2,$cidr2) = split (/\//, $ccdroutehash{$key}[$oldiroute]); |
3678 | if (&General::IpInSubnet ($ip1,$ip2,$cidr2)){ | |
3679 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3680 | goto VPNCONF_ERROR; | |
3681 | } | |
3682 | ||
8c877a82 AM |
3683 | } |
3684 | } | |
5068ac38 AM |
3685 | if (!&General::validipandmask($val)){ |
3686 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3687 | goto VPNCONF_ERROR; | |
3688 | }else{ | |
3689 | ($ip,$cidr) = split(/\//,$val); | |
3690 | $ip=&General::getnetworkip($ip,&General::iporsubtocidr($cidr)); | |
3691 | $cidr=&General::iporsubtodec($cidr); | |
3692 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3693 | ||
3694 | } | |
8c877a82 AM |
3695 | |
3696 | #check for existing network IP's | |
52d08bcb AM |
3697 | if (&General::IpInSubnet ($ip,$netsettings{GREEN_NETADDRESS},$netsettings{GREEN_NETMASK}) && $netsettings{GREEN_NETADDRESS} ne '0.0.0.0') |
3698 | { | |
3699 | $errormessage=$Lang::tr{'ccd err green'}; | |
3700 | goto VPNCONF_ERROR; | |
3701 | }elsif(&General::IpInSubnet ($ip,$netsettings{RED_NETADDRESS},$netsettings{RED_NETMASK}) && $netsettings{RED_NETADDRESS} ne '0.0.0.0') | |
3702 | { | |
3703 | $errormessage=$Lang::tr{'ccd err red'}; | |
3704 | goto VPNCONF_ERROR; | |
3705 | }elsif(&General::IpInSubnet ($ip,$netsettings{BLUE_NETADDRESS},$netsettings{BLUE_NETMASK}) && $netsettings{BLUE_NETADDRESS} ne '0.0.0.0' && $netsettings{BLUE_NETADDRESS} gt '') | |
3706 | { | |
3707 | $errormessage=$Lang::tr{'ccd err blue'}; | |
3708 | goto VPNCONF_ERROR; | |
3709 | }elsif(&General::IpInSubnet ($ip,$netsettings{ORANGE_NETADDRESS},$netsettings{ORANGE_NETMASK}) && $netsettings{ORANGE_NETADDRESS} ne '0.0.0.0' && $netsettings{ORANGE_NETADDRESS} gt '' ) | |
3710 | { | |
3711 | $errormessage=$Lang::tr{'ccd err orange'}; | |
8c877a82 AM |
3712 | goto VPNCONF_ERROR; |
3713 | } | |
52d08bcb | 3714 | |
8c877a82 AM |
3715 | if (&General::validipandmask($val)){ |
3716 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3717 | }else{ | |
3718 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($ip/$cidr)"; | |
3719 | goto VPNCONF_ERROR; | |
3720 | } | |
3721 | $i++; | |
3722 | } | |
3723 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3724 | &writeserverconf; | |
3725 | }else{ | |
3726 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3727 | foreach my $key (keys %ccdroutehash) { | |
3728 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3729 | delete $ccdroutehash{$key}; | |
3730 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3731 | &writeserverconf; | |
3732 | } | |
3733 | } | |
3734 | } | |
3735 | undef @temp; | |
3736 | #check route field and convert it to decimal | |
8c877a82 AM |
3737 | my $val=0; |
3738 | my $i=1; | |
8c877a82 | 3739 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
52d08bcb AM |
3740 | #find key to use |
3741 | foreach my $key (keys %ccdroute2hash) { | |
3742 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
3743 | $keypoint=$key; | |
3744 | delete $ccdroute2hash{$key}; | |
3745 | }else{ | |
3746 | $keypoint = &General::findhasharraykey (\%ccdroute2hash); | |
3747 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3748 | &writeserverconf; | |
8c877a82 | 3749 | } |
52d08bcb AM |
3750 | } |
3751 | $ccdroute2hash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3752 | if ($cgiparams{'IFROUTE'} eq ''){$cgiparams{'IFROUTE'} = $Lang::tr{'ccd none'};} | |
3753 | @temp = split(/\|/,$cgiparams{'IFROUTE'}); | |
3754 | my %ownnet=(); | |
3755 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
3756 | foreach $val (@temp){ | |
3757 | chomp($val); | |
3758 | $val=~s/\s*$//g; | |
3759 | if ($val eq $Lang::tr{'green'}) | |
3760 | { | |
3761 | $val=$ownnet{GREEN_NETADDRESS}."/".$ownnet{GREEN_NETMASK}; | |
3762 | } | |
3763 | if ($val eq $Lang::tr{'blue'}) | |
3764 | { | |
3765 | $val=$ownnet{BLUE_NETADDRESS}."/".$ownnet{BLUE_NETMASK}; | |
3766 | } | |
3767 | if ($val eq $Lang::tr{'orange'}) | |
3768 | { | |
3769 | $val=$ownnet{ORANGE_NETADDRESS}."/".$ownnet{ORANGE_NETMASK}; | |
3770 | } | |
3771 | my ($ip,$cidr) = split (/\//, $val); | |
3772 | ||
3773 | if ($val ne $Lang::tr{'ccd none'}) | |
3774 | { | |
8c877a82 AM |
3775 | if (! &check_routes_push($val)){$errormessage=$errormessage."Route $val ".$Lang::tr{'ccd err routeovpn2'}." ($val)";goto VPNCONF_ERROR;} |
3776 | if (! &check_ccdroute($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err inuse'}." ($val)" ;goto VPNCONF_ERROR;} | |
3777 | if (! &check_ccdconf($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err routeovpn'}." ($val)";goto VPNCONF_ERROR;} | |
3778 | if (&General::validipandmask($val)){ | |
3779 | $val=$ip."/".&General::iporsubtodec($cidr); | |
3780 | $ccdroute2hash{$keypoint}[$i] = $val; | |
3781 | }else{ | |
3782 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3783 | goto VPNCONF_ERROR; | |
3784 | } | |
52d08bcb AM |
3785 | }else{ |
3786 | $ccdroute2hash{$keypoint}[$i]=''; | |
3787 | } | |
3788 | $i++; | |
3789 | } | |
3790 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
3791 | ||
8c877a82 AM |
3792 | #check dns1 ip |
3793 | if ($cgiparams{'CCD_DNS1'} ne '' && ! &General::validip($cgiparams{'CCD_DNS1'})) { | |
3794 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 1"; | |
3795 | goto VPNCONF_ERROR; | |
3796 | } | |
3797 | #check dns2 ip | |
3798 | if ($cgiparams{'CCD_DNS2'} ne '' && ! &General::validip($cgiparams{'CCD_DNS2'})) { | |
3799 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 2"; | |
3800 | goto VPNCONF_ERROR; | |
3801 | } | |
3802 | #check wins ip | |
3803 | if ($cgiparams{'CCD_WINS'} ne '' && ! &General::validip($cgiparams{'CCD_WINS'})) { | |
3804 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp wins'}; | |
3805 | goto VPNCONF_ERROR; | |
3806 | } | |
52d08bcb | 3807 | } |
8c877a82 AM |
3808 | |
3809 | #CCD End | |
52d08bcb | 3810 | |
8c877a82 AM |
3811 | |
3812 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
c6c9630e | 3813 | $errormessage = $Lang::tr{'connection type is invalid'}; |
b278daf3 AH |
3814 | if ($cgiparams{'TYPE'} eq 'net') { |
3815 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3816 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3817 | } | |
c6c9630e MT |
3818 | goto VPNCONF_ERROR; |
3819 | } | |
3820 | ||
3821 | ||
3822 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
3823 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
b278daf3 AH |
3824 | if ($cgiparams{'TYPE'} eq 'net') { |
3825 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3826 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3827 | } | |
3828 | goto VPNCONF_ERROR; | |
3829 | } | |
c6c9630e MT |
3830 | |
3831 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
3832 | $errormessage = $Lang::tr{'name is invalid'}; | |
b278daf3 AH |
3833 | if ($cgiparams{'TYPE'} eq 'net') { |
3834 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3835 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3836 | } | |
c6c9630e MT |
3837 | goto VPNCONF_ERROR; |
3838 | } | |
3839 | ||
3840 | if (length($cgiparams{'NAME'}) >60) { | |
3841 | $errormessage = $Lang::tr{'name too long'}; | |
b278daf3 AH |
3842 | if ($cgiparams{'TYPE'} eq 'net') { |
3843 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3844 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3845 | } | |
c6c9630e MT |
3846 | goto VPNCONF_ERROR; |
3847 | } | |
3848 | ||
d96c89eb | 3849 | ### |
7c1d9faf | 3850 | # m.a.d net2net |
d96c89eb AH |
3851 | ### |
3852 | ||
7c1d9faf | 3853 | if ($cgiparams{'TYPE'} eq 'net') { |
ab4cf06c | 3854 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { |
cd0c0a0d | 3855 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
b278daf3 AH |
3856 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3857 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3858 | goto VPNCONF_ERROR; | |
d96c89eb | 3859 | } |
ab4cf06c AM |
3860 | #Bugfix 10357 |
3861 | foreach my $key (sort keys %confighash){ | |
3862 | 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 |
3863 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
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: $!"; | |
ab4cf06c AM |
3866 | goto VPNCONF_ERROR; |
3867 | } | |
3868 | } | |
3869 | if ($cgiparams{'DEST_PORT'} eq '') { | |
3870 | $errormessage = $Lang::tr{'invalid port'}; | |
3871 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3872 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
54fd0535 MT |
3873 | goto VPNCONF_ERROR; |
3874 | } | |
d96c89eb | 3875 | |
f48074ba SS |
3876 | # Check if the input for the transfer net is valid. |
3877 | if (!&General::validipandmask($cgiparams{'OVPN_SUBNET'})){ | |
3878 | $errormessage = $Lang::tr{'ccd err invalidnet'}; | |
3879 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3880 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3881 | goto VPNCONF_ERROR; | |
3882 | } | |
3883 | ||
d96c89eb | 3884 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { |
cd0c0a0d | 3885 | $errormessage = $Lang::tr{'openvpn subnet is used'}; |
b278daf3 AH |
3886 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3887 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3888 | goto VPNCONF_ERROR; |
3889 | } | |
3890 | ||
3891 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
cd0c0a0d | 3892 | $errormessage = $Lang::tr{'openvpn mssfix allowed with udp'}; |
b278daf3 AH |
3893 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3894 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3895 | goto VPNCONF_ERROR; |
3896 | } | |
3897 | ||
3898 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
cd0c0a0d | 3899 | $errormessage = $Lang::tr{'openvpn fragment allowed with udp'}; |
b278daf3 AH |
3900 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3901 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3902 | goto VPNCONF_ERROR; |
3903 | } | |
d96c89eb | 3904 | |
2ee746be SS |
3905 | if ($cgiparams{'PMTU_DISCOVERY'} ne 'off') { |
3906 | if (($cgiparams{'FRAGMENT'} ne '') || ($cgiparams{'MSSFIX'} eq 'on')) { | |
3907 | $errormessage = $Lang::tr{'ovpn mtu-disc with mssfix or fragment'}; | |
3908 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3909 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3910 | goto VPNCONF_ERROR; | |
3911 | } | |
3912 | } | |
3913 | ||
4cdf8b92 SS |
3914 | if (($cgiparams{'PMTU_DISCOVERY'} ne 'off') && ($cgiparams{'MTU'} ne '1500')) { |
3915 | $errormessage = $Lang::tr{'ovpn mtu-disc and mtu not 1500'}; | |
3916 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3917 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3918 | goto VPNCONF_ERROR; | |
3919 | } | |
3920 | ||
7c1d9faf | 3921 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
cd0c0a0d | 3922 | $errormessage = $Lang::tr{'openvpn prefix local subnet'}; |
b278daf3 AH |
3923 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3924 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3925 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3926 | } |
3927 | ||
3928 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
cd0c0a0d | 3929 | $errormessage = $Lang::tr{'openvpn prefix openvpn subnet'}; |
b278daf3 AH |
3930 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3931 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3932 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3933 | } |
3934 | ||
3935 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
cd0c0a0d | 3936 | $errormessage = $Lang::tr{'openvpn prefix remote subnet'}; |
b278daf3 AH |
3937 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3938 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3939 | goto VPNCONF_ERROR; | |
8c252e6a EK |
3940 | } |
3941 | ||
3942 | if ($cgiparams{'DEST_PORT'} <= 1023) { | |
3943 | $errormessage = $Lang::tr{'ovpn port in root range'}; | |
3944 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3945 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3946 | goto VPNCONF_ERROR; | |
3947 | } | |
54fd0535 | 3948 | |
4c962356 | 3949 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c252e6a EK |
3950 | $cgiparams{'OVPN_MGMT'} = $cgiparams{'DEST_PORT'}; |
3951 | } | |
3952 | ||
3953 | if ($cgiparams{'OVPN_MGMT'} <= 1023) { | |
3954 | $errormessage = $Lang::tr{'ovpn mgmt in root range'}; | |
3955 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3956 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3957 | goto VPNCONF_ERROR; | |
b2e75449 MT |
3958 | } |
3959 | #Check if remote subnet is used elsewhere | |
3960 | my ($n2nip,$n2nsub)=split("/",$cgiparams{'REMOTE_SUBNET'}); | |
3961 | $warnmessage=&General::checksubnets('',$n2nip,'ovpn'); | |
3962 | if ($warnmessage){ | |
3963 | $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage; | |
3964 | } | |
7c1d9faf | 3965 | } |
d96c89eb | 3966 | |
ce9abb66 AH |
3967 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
3968 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
3969 | # goto VPNCONF_ERROR; | |
3970 | # } | |
3971 | ||
c6c9630e MT |
3972 | # Check if there is no other entry with this name |
3973 | if (! $cgiparams{'KEY'}) { | |
3974 | foreach my $key (keys %confighash) { | |
3975 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
3976 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3977 | if ($cgiparams{'TYPE'} eq 'net') { |
3978 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3979 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3980 | } | |
c6c9630e | 3981 | goto VPNCONF_ERROR; |
6e13d0a5 | 3982 | } |
c6c9630e MT |
3983 | } |
3984 | } | |
3985 | ||
c125d8a2 | 3986 | # Check if a remote host/IP has been set for the client. |
86228a56 MT |
3987 | if ($cgiparams{'TYPE'} eq 'net') { |
3988 | if ($cgiparams{'SIDE'} ne 'server' && $cgiparams{'REMOTE'} eq '') { | |
3989 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3990 | |
86228a56 MT |
3991 | # Check if this is a N2N connection and drop temporary config. |
3992 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3993 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ce9abb66 | 3994 | |
86228a56 MT |
3995 | goto VPNCONF_ERROR; |
3996 | } | |
c125d8a2 | 3997 | |
86228a56 MT |
3998 | # Check if a remote host/IP has been configured - the field can be empty on the server side. |
3999 | if ($cgiparams{'REMOTE'} ne '') { | |
4000 | # Check if the given IP is valid - otherwise check if it is a valid domain. | |
4001 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
4002 | # Check for a valid domain. | |
4003 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
4004 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 4005 | |
86228a56 MT |
4006 | # Check if this is a N2N connection and drop temporary config. |
4007 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
4008 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
c125d8a2 | 4009 | |
86228a56 MT |
4010 | goto VPNCONF_ERROR; |
4011 | } | |
4012 | } | |
6e13d0a5 | 4013 | } |
c6c9630e | 4014 | } |
c125d8a2 | 4015 | |
c6c9630e MT |
4016 | if ($cgiparams{'TYPE'} ne 'host') { |
4017 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
4018 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
b278daf3 AH |
4019 | if ($cgiparams{'TYPE'} eq 'net') { |
4020 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
4021 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
4022 | } | |
c6c9630e MT |
4023 | goto VPNCONF_ERROR;} |
4024 | } | |
4025 | # Check if there is no other entry without IP-address and PSK | |
4026 | if ($cgiparams{'REMOTE'} eq '') { | |
4027 | foreach my $key (keys %confighash) { | |
4028 | if(($cgiparams{'KEY'} ne $key) && | |
4029 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
4030 | $confighash{$key}[10] eq '') { | |
4031 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
4032 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4033 | } |
c6c9630e MT |
4034 | } |
4035 | } | |
ce9abb66 AH |
4036 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
4037 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
4038 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
4039 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
4040 | goto VPNCONF_ERROR; | |
ce9abb66 | 4041 | } |
c6c9630e MT |
4042 | |
4043 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
4044 | $errormessage = $Lang::tr{'invalid input'}; | |
4045 | goto VPNCONF_ERROR; | |
4046 | } | |
4047 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
4048 | $errormessage = $Lang::tr{'invalid input'}; | |
4049 | goto VPNCONF_ERROR; | |
4050 | } | |
4051 | ||
4052 | #fixplausi | |
4053 | if ($cgiparams{'AUTH'} eq 'psk') { | |
4054 | # if (! length($cgiparams{'PSK'}) ) { | |
4055 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
4056 | # goto VPNCONF_ERROR; | |
4057 | # } | |
4058 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
4059 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
4060 | # goto VPNCONF_ERROR; | |
4061 | # } | |
4062 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
4063 | if ($cgiparams{'KEY'}) { | |
4064 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4065 | goto VPNCONF_ERROR; | |
4066 | } | |
4067 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
4068 | $errormessage = $Lang::tr{'there was no file upload'}; | |
4069 | goto VPNCONF_ERROR; | |
4070 | } | |
4071 | ||
4072 | # Move uploaded certificate request to a temporary file | |
4073 | (my $fh, my $filename) = tempfile( ); | |
4074 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4075 | $errormessage = $!; | |
4076 | goto VPNCONF_ERROR; | |
4077 | } | |
6e13d0a5 | 4078 | |
c6c9630e MT |
4079 | # Sign the certificate request and move it |
4080 | # Sign the host certificate request | |
f6e12093 | 4081 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4082 | '-batch', '-notext', |
4083 | '-in', $filename, | |
4084 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4085 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4086 | if ($?) { | |
4087 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4088 | unlink ($filename); | |
4089 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4090 | &newcleanssldatabase(); | |
4091 | goto VPNCONF_ERROR; | |
4092 | } else { | |
4093 | unlink ($filename); | |
4094 | &deletebackupcert(); | |
4095 | } | |
4096 | ||
4097 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
4098 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
4099 | $temp = $1; | |
4100 | $temp =~ s+/Email+, E+; | |
4101 | $temp =~ s/ ST=/ S=/; | |
4102 | $cgiparams{'CERT_NAME'} = $temp; | |
4103 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4104 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4105 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4106 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4107 | goto VPNCONF_ERROR; | |
4108 | } | |
4109 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
4110 | if ($cgiparams{'KEY'}) { | |
4111 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4112 | goto VPNCONF_ERROR; | |
4113 | } | |
4114 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
4115 | $errormessage = $Lang::tr{'there was no file upload'}; | |
4116 | goto VPNCONF_ERROR; | |
4117 | } | |
4118 | # Move uploaded certificate to a temporary file | |
4119 | (my $fh, my $filename) = tempfile( ); | |
4120 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4121 | $errormessage = $!; | |
4122 | goto VPNCONF_ERROR; | |
4123 | } | |
4124 | ||
4125 | # Verify the certificate has a valid CA and move it | |
4126 | my $validca = 0; | |
4127 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename`; | |
4128 | if ($test =~ /: OK/) { | |
4129 | $validca = 1; | |
4130 | } else { | |
4131 | foreach my $key (keys %cahash) { | |
4132 | $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem $filename`; | |
4133 | if ($test =~ /: OK/) { | |
4134 | $validca = 1; | |
4135 | } | |
6e13d0a5 | 4136 | } |
c6c9630e MT |
4137 | } |
4138 | if (! $validca) { | |
4139 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
4140 | unlink ($filename); | |
4141 | goto VPNCONF_ERROR; | |
4142 | } else { | |
4143 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4144 | if ($? ne 0) { | |
4145 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
4146 | unlink ($filename); | |
4147 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4148 | } |
c6c9630e MT |
4149 | } |
4150 | ||
4151 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
4152 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
4153 | $temp = $1; | |
4154 | $temp =~ s+/Email+, E+; | |
4155 | $temp =~ s/ ST=/ S=/; | |
4156 | $cgiparams{'CERT_NAME'} = $temp; | |
4157 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4158 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4159 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4160 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4161 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4162 | goto VPNCONF_ERROR; | |
4163 | } | |
4164 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
4165 | if ($cgiparams{'KEY'}) { | |
4166 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4167 | goto VPNCONF_ERROR; | |
4168 | } | |
4169 | # Validate input since the form was submitted | |
4170 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
4171 | $errormessage = $Lang::tr{'name too long'}; | |
4172 | goto VPNCONF_ERROR; | |
4173 | } | |
194314b2 | 4174 | if ($cgiparams{'CERT_NAME'} eq '' || $cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { |
c6c9630e MT |
4175 | $errormessage = $Lang::tr{'invalid input for name'}; |
4176 | goto VPNCONF_ERROR; | |
4177 | } | |
4178 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
4179 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
4180 | goto VPNCONF_ERROR; | |
4181 | } | |
4182 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
4183 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
4184 | goto VPNCONF_ERROR; | |
4185 | } | |
4186 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4187 | $errormessage = $Lang::tr{'invalid input for department'}; | |
4188 | goto VPNCONF_ERROR; | |
4189 | } | |
4190 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
4191 | $errormessage = $Lang::tr{'organization too long'}; | |
4192 | goto VPNCONF_ERROR; | |
4193 | } | |
4194 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
4195 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
4196 | goto VPNCONF_ERROR; | |
4197 | } | |
4198 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4199 | $errormessage = $Lang::tr{'invalid input for city'}; | |
4200 | goto VPNCONF_ERROR; | |
4201 | } | |
4202 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4203 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
4204 | goto VPNCONF_ERROR; | |
4205 | } | |
4206 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
4207 | $errormessage = $Lang::tr{'invalid input for country'}; | |
4208 | goto VPNCONF_ERROR; | |
4209 | } | |
4210 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
4211 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
4212 | $errormessage = $Lang::tr{'password too short'}; | |
4213 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4214 | } |
c6c9630e MT |
4215 | } |
4216 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
4217 | $errormessage = $Lang::tr{'passwords do not match'}; | |
4218 | goto VPNCONF_ERROR; | |
4219 | } | |
f4fbb935 EK |
4220 | if ($cgiparams{'DAYS_VALID'} ne '' && $cgiparams{'DAYS_VALID'} !~ /^[0-9]+$/) { |
4221 | $errormessage = $Lang::tr{'invalid input for valid till days'}; | |
4222 | goto VPNCONF_ERROR; | |
4223 | } | |
c6c9630e MT |
4224 | |
4225 | # Replace empty strings with a . | |
4226 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
4227 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
4228 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
4229 | ||
4230 | # Create the Host certificate request client | |
4231 | my $pid = open(OPENSSL, "|-"); | |
4232 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
4233 | if ($pid) { # parent | |
4234 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
4235 | print OPENSSL "$state\n"; | |
4236 | print OPENSSL "$city\n"; | |
4237 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
4238 | print OPENSSL "$ou\n"; | |
4239 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
4240 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
4241 | print OPENSSL ".\n"; | |
4242 | print OPENSSL ".\n"; | |
4243 | close (OPENSSL); | |
4244 | if ($?) { | |
4245 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4246 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4247 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4248 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4249 | } |
c6c9630e | 4250 | } else { # child |
badd8c1c | 4251 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 4252 | '-newkey', 'rsa:2048', |
c6c9630e MT |
4253 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", |
4254 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4255 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
4256 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
4257 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4258 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4259 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4260 | } |
c6c9630e MT |
4261 | } |
4262 | ||
4263 | # Sign the host certificate request | |
f6e12093 | 4264 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4265 | '-batch', '-notext', |
4266 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4267 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4268 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4269 | if ($?) { | |
4270 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4271 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4272 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4273 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4274 | &newcleanssldatabase(); | |
4275 | goto VPNCONF_ERROR; | |
4276 | } else { | |
4277 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4278 | &deletebackupcert(); | |
4279 | } | |
4280 | ||
4281 | # Create the pkcs12 file | |
4282 | system('/usr/bin/openssl', 'pkcs12', '-export', | |
4283 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
4284 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4285 | '-name', $cgiparams{'NAME'}, | |
4286 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
4287 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
4288 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
4289 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4290 | if ($?) { | |
4291 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4292 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4293 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4294 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4295 | goto VPNCONF_ERROR; | |
4296 | } else { | |
4297 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4298 | } | |
4299 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
4300 | ;# Nothing, just editing | |
4301 | } else { | |
4302 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
4303 | goto VPNCONF_ERROR; | |
4304 | } | |
4305 | ||
4306 | # Check if there is no other entry with this common name | |
4307 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
4308 | foreach my $key (keys %confighash) { | |
4309 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
4310 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
4311 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4312 | } |
c6c9630e MT |
4313 | } |
4314 | } | |
4315 | ||
ab4cf06c | 4316 | # Save the config |
c6c9630e | 4317 | my $key = $cgiparams{'KEY'}; |
8c877a82 | 4318 | |
c6c9630e MT |
4319 | if (! $key) { |
4320 | $key = &General::findhasharraykey (\%confighash); | |
49abe7af | 4321 | foreach my $i (0 .. 43) { $confighash{$key}[$i] = "";} |
c6c9630e | 4322 | } |
8c877a82 AM |
4323 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; |
4324 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
c6c9630e | 4325 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { |
8c877a82 | 4326 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; |
c6c9630e | 4327 | } |
8c877a82 AM |
4328 | |
4329 | $confighash{$key}[3] = $cgiparams{'TYPE'}; | |
c6c9630e | 4330 | if ($cgiparams{'AUTH'} eq 'psk') { |
8c877a82 AM |
4331 | $confighash{$key}[4] = 'psk'; |
4332 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
c6c9630e | 4333 | } else { |
8c877a82 | 4334 | $confighash{$key}[4] = 'cert'; |
c6c9630e | 4335 | } |
ce9abb66 | 4336 | if ($cgiparams{'TYPE'} eq 'net') { |
8c877a82 AM |
4337 | $confighash{$key}[6] = $cgiparams{'SIDE'}; |
4338 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
ce9abb66 | 4339 | } |
4c962356 | 4340 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
8c877a82 | 4341 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; |
4c962356 | 4342 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c877a82 | 4343 | $confighash{$key}[22] = $confighash{$key}[29]; |
4c962356 | 4344 | } else { |
8c877a82 | 4345 | $confighash{$key}[22] = $cgiparams{'OVPN_MGMT'}; |
4c962356 | 4346 | } |
8c877a82 AM |
4347 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
4348 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
4349 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
4350 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
c6c9630e | 4351 | # new fields |
8c877a82 AM |
4352 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; |
4353 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
4354 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
4355 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
4356 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
4357 | $confighash{$key}[32] = $cgiparams{'CHECK1'}; | |
df9b48b7 | 4358 | $name=$cgiparams{'CHECK1'}; |
8c877a82 AM |
4359 | $confighash{$key}[33] = $cgiparams{$name}; |
4360 | $confighash{$key}[34] = $cgiparams{'RG'}; | |
4361 | $confighash{$key}[35] = $cgiparams{'CCD_DNS1'}; | |
4362 | $confighash{$key}[36] = $cgiparams{'CCD_DNS2'}; | |
4363 | $confighash{$key}[37] = $cgiparams{'CCD_WINS'}; | |
4c962356 EK |
4364 | $confighash{$key}[38] = $cgiparams{'PMTU_DISCOVERY'}; |
4365 | $confighash{$key}[39] = $cgiparams{'DAUTH'}; | |
4366 | $confighash{$key}[40] = $cgiparams{'DCIPHER'}; | |
350f2980 | 4367 | |
71af643c MT |
4368 | if (($cgiparams{'TYPE'} eq 'host') && ($cgiparams{'CERT_PASS1'} eq "")) { |
4369 | $confighash{$key}[41] = "no-pass"; | |
4370 | } | |
4371 | ||
c6c9630e | 4372 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
8c877a82 AM |
4373 | |
4374 | if ($cgiparams{'CHECK1'} ){ | |
4375 | ||
4376 | my ($ccdip,$ccdsub)=split "/",$cgiparams{$name}; | |
4377 | my ($a,$b,$c,$d) = split (/\./,$ccdip); | |
df9b48b7 AM |
4378 | if ( -e "${General::swroot}/ovpn/ccd/$confighash{$key}[2]"){ |
4379 | unlink "${General::swroot}/ovpn/ccd/$cgiparams{'CERT_NAME'}"; | |
4380 | } | |
8c877a82 | 4381 | open ( CCDRWCONF,'>',"${General::swroot}/ovpn/ccd/$confighash{$key}[2]") or die "Unable to create clientconfigfile $!"; |
82c809c7 | 4382 | print CCDRWCONF "# OpenVPN clientconfig from ccd extension by Copymaster#\n\n"; |
8c877a82 AM |
4383 | if($cgiparams{'CHECK1'} eq 'dynamic'){ |
4384 | print CCDRWCONF "#This client uses the dynamic pool\n"; | |
4385 | }else{ | |
82c809c7 | 4386 | print CCDRWCONF "#Ip address client and server\n"; |
8c877a82 AM |
4387 | print CCDRWCONF "ifconfig-push $ccdip ".&General::getlastip($ccdip,1)."\n"; |
4388 | } | |
4389 | if ($confighash{$key}[34] eq 'on'){ | |
4390 | print CCDRWCONF "\n#Redirect Gateway: \n#All IP traffic is redirected through the vpn \n"; | |
4391 | print CCDRWCONF "push redirect-gateway\n"; | |
4392 | } | |
52d08bcb | 4393 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 4394 | if ($cgiparams{'IR'} ne ''){ |
82c809c7 | 4395 | print CCDRWCONF "\n#Client routes these networks (behind Client)\n"; |
8c877a82 AM |
4396 | foreach my $key (keys %ccdroutehash){ |
4397 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}){ | |
4398 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
4399 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
4400 | print CCDRWCONF "iroute $a $b\n"; | |
4401 | } | |
4402 | } | |
4403 | } | |
4404 | } | |
52d08bcb | 4405 | if ($cgiparams{'IFROUTE'} eq $Lang::tr{'ccd none'} ){$cgiparams{'IFROUTE'}='';} |
8c877a82 | 4406 | if ($cgiparams{'IFROUTE'} ne ''){ |
82c809c7 | 4407 | print CCDRWCONF "\n#Client gets routes to these networks (behind IPFire)\n"; |
8c877a82 AM |
4408 | foreach my $key (keys %ccdroute2hash){ |
4409 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4410 | foreach my $i ( 1 .. $#{$ccdroute2hash{$key}}){ | |
4411 | if($ccdroute2hash{$key}[$i] eq $Lang::tr{'blue'}){ | |
4412 | my %blue=(); | |
4413 | &General::readhash("${General::swroot}/ethernet/settings", \%blue); | |
52d08bcb | 4414 | print CCDRWCONF "push \"route $blue{BLUE_ADDRESS} $blue{BLUE_NETMASK}\n"; |
8c877a82 AM |
4415 | }elsif($ccdroute2hash{$key}[$i] eq $Lang::tr{'orange'}){ |
4416 | my %orange=(); | |
4417 | &General::readhash("${General::swroot}/ethernet/settings", \%orange); | |
4418 | print CCDRWCONF "push \"route $orange{ORANGE_ADDRESS} $orange{ORANGE_NETMASK}\n"; | |
4419 | }else{ | |
4420 | my ($a,$b)=split (/\//,$ccdroute2hash{$key}[$i]); | |
4421 | print CCDRWCONF "push \"route $a $b\"\n"; | |
4422 | } | |
4423 | } | |
4424 | } | |
4425 | } | |
4426 | } | |
4427 | if(($cgiparams{'CCD_DNS1'} eq '') && ($cgiparams{'CCD_DNS1'} ne '')){ $cgiparams{'CCD_DNS1'} = $cgiparams{'CCD_DNS2'};$cgiparams{'CCD_DNS2'}='';} | |
4428 | if($cgiparams{'CCD_DNS1'} ne ''){ | |
82c809c7 | 4429 | print CCDRWCONF "\n#Client gets these nameservers\n"; |
8c877a82 AM |
4430 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS1'}\" \n"; |
4431 | } | |
4432 | if($cgiparams{'CCD_DNS2'} ne ''){ | |
4433 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS2'}\" \n"; | |
4434 | } | |
4435 | if($cgiparams{'CCD_WINS'} ne ''){ | |
4436 | print CCDRWCONF "\n#Client gets this WINS server\n"; | |
4437 | print CCDRWCONF "push \"dhcp-option WINS $cgiparams{'CCD_WINS'}\" \n"; | |
4438 | } | |
4439 | close CCDRWCONF; | |
4440 | } | |
18837a6a AH |
4441 | |
4442 | ### | |
4443 | # m.a.d n2n begin | |
4444 | ### | |
4445 | ||
4446 | if ($cgiparams{'TYPE'} eq 'net') { | |
4447 | ||
4448 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
4449 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4450 | ||
4451 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4452 | my $key = $cgiparams{'KEY'}; | |
4453 | if (! $key) { | |
4454 | $key = &General::findhasharraykey (\%confighash); | |
4455 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
4456 | } | |
4457 | $confighash{$key}[0] = 'on'; | |
4458 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4459 | ||
4460 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4461 | } | |
4462 | } | |
4463 | ||
4464 | ### | |
4465 | # m.a.d n2n end | |
4466 | ### | |
4467 | ||
c6c9630e MT |
4468 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { |
4469 | $cgiparams{'KEY'} = $key; | |
4470 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
4471 | } | |
4472 | goto VPNCONF_END; | |
6e13d0a5 | 4473 | } else { |
c6c9630e | 4474 | $cgiparams{'ENABLED'} = 'on'; |
54fd0535 MT |
4475 | ### |
4476 | # m.a.d n2n begin | |
4477 | ### | |
4478 | $cgiparams{'MSSFIX'} = 'on'; | |
4479 | $cgiparams{'FRAGMENT'} = '1300'; | |
b228aaf0 | 4480 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; |
70900745 | 4481 | $cgiparams{'DAUTH'} = 'SHA512'; |
54fd0535 MT |
4482 | ### |
4483 | # m.a.d n2n end | |
4484 | ### | |
4c962356 | 4485 | $cgiparams{'SIDE'} = 'left'; |
c6c9630e MT |
4486 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { |
4487 | $cgiparams{'AUTH'} = 'psk'; | |
4488 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4489 | $cgiparams{'AUTH'} = 'certfile'; | |
4490 | } else { | |
6e13d0a5 | 4491 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
4492 | } |
4493 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
4494 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
4495 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
4496 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
4497 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
f4fbb935 | 4498 | $cgiparams{'DAYS_VALID'} = $vpnsettings{'DAYS_VALID'}; |
6e13d0a5 | 4499 | } |
c6c9630e | 4500 | |
6e13d0a5 | 4501 | VPNCONF_ERROR: |
6e13d0a5 MT |
4502 | $checked{'ENABLED'}{'off'} = ''; |
4503 | $checked{'ENABLED'}{'on'} = ''; | |
4504 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4505 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4506 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4507 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4508 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4509 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4510 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4511 | |
4512 | ||
6e13d0a5 MT |
4513 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
4514 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
4515 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 4516 | |
6e13d0a5 MT |
4517 | $selected{'SIDE'}{'server'} = ''; |
4518 | $selected{'SIDE'}{'client'} = ''; | |
4519 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
d96c89eb AH |
4520 | |
4521 | $selected{'PROTOCOL'}{'udp'} = ''; | |
4522 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
4523 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
4524 | ||
c6c9630e | 4525 | |
6e13d0a5 MT |
4526 | $checked{'AUTH'}{'psk'} = ''; |
4527 | $checked{'AUTH'}{'certreq'} = ''; | |
4528 | $checked{'AUTH'}{'certgen'} = ''; | |
4529 | $checked{'AUTH'}{'certfile'} = ''; | |
4530 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 4531 | |
6e13d0a5 | 4532 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
c6c9630e | 4533 | |
6e13d0a5 MT |
4534 | $checked{'COMPLZO'}{'off'} = ''; |
4535 | $checked{'COMPLZO'}{'on'} = ''; | |
4536 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 4537 | |
d96c89eb AH |
4538 | $checked{'MSSFIX'}{'off'} = ''; |
4539 | $checked{'MSSFIX'}{'on'} = ''; | |
4540 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4541 | ||
92b87e17 SS |
4542 | if ($cgiparams{'PMTU_DISCOVERY'} eq '') { |
4543 | $cgiparams{'PMTU_DISCOVERY'} = 'off'; | |
4544 | } | |
2ee746be SS |
4545 | $checked{'PMTU_DISCOVERY'}{$cgiparams{'PMTU_DISCOVERY'}} = 'checked=\'checked\''; |
4546 | ||
4c962356 EK |
4547 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
4548 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
4549 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
4550 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4551 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4552 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
4553 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4554 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; | |
4555 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
4556 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4557 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4558 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 4559 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
49abe7af EK |
4560 | # If no cipher has been chossen yet, select |
4561 | # the old default (AES-256-CBC) for compatiblity reasons. | |
4562 | if ($cgiparams{'DCIPHER'} eq '') { | |
4563 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; | |
4564 | } | |
4c962356 | 4565 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
49abe7af EK |
4566 | $selected{'DAUTH'}{'whirlpool'} = ''; |
4567 | $selected{'DAUTH'}{'SHA512'} = ''; | |
4568 | $selected{'DAUTH'}{'SHA384'} = ''; | |
4569 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4570 | $selected{'DAUTH'}{'SHA1'} = ''; | |
4571 | # If no hash algorythm has been choosen yet, select | |
4572 | # the old default value (SHA1) for compatiblity reasons. | |
4573 | if ($cgiparams{'DAUTH'} eq '') { | |
4574 | $cgiparams{'DAUTH'} = 'SHA1'; | |
4575 | } | |
4576 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
4577 | ||
6e13d0a5 MT |
4578 | if (1) { |
4579 | &Header::showhttpheaders(); | |
4c962356 | 4580 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
4581 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
4582 | if ($errormessage) { | |
4583 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4584 | print "<class name='base'>$errormessage"; | |
4585 | print " </class>"; | |
4586 | &Header::closebox(); | |
4587 | } | |
c6c9630e | 4588 | |
6e13d0a5 MT |
4589 | if ($warnmessage) { |
4590 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
4591 | print "<class name='base'>$warnmessage"; | |
4592 | print " </class>"; | |
4593 | &Header::closebox(); | |
4594 | } | |
c6c9630e | 4595 | |
6e13d0a5 | 4596 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 4597 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 4598 | |
6e13d0a5 MT |
4599 | if ($cgiparams{'KEY'}) { |
4600 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
4601 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 4602 | } |
c6c9630e | 4603 | |
6e13d0a5 | 4604 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
8c877a82 | 4605 | print "<table width='100%' border='0'>\n"; |
4c962356 | 4606 | |
e3edceeb | 4607 | print "<tr><td width='14%' class='boldbase'>$Lang::tr{'name'}: <img src='/blob.gif' alt='*' /></td>"; |
8c877a82 | 4608 | |
ce9abb66 | 4609 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 | 4610 | if ($cgiparams{'KEY'}) { |
8c877a82 | 4611 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; |
6e13d0a5 MT |
4612 | } else { |
4613 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
4614 | } | |
c6c9630e MT |
4615 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
4616 | # print "<td><select name='INTERFACE'>"; | |
4617 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
4c962356 EK |
4618 | # if ($netsettings{'BLUE_DEV'} ne '') { |
4619 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
4620 | # } | |
4621 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
4622 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
4623 | # print "</select></td></tr>"; | |
4624 | # print <<END; | |
ce9abb66 AH |
4625 | } else { |
4626 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
4627 | if ($cgiparams{'KEY'}) { | |
4628 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4629 | } else { | |
4630 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
4631 | } | |
4c962356 | 4632 | print <<END; |
ce9abb66 | 4633 | <td width='25%'> </td> |
f527e53f EK |
4634 | <td width='25%'> </td></tr> |
4635 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> | |
4636 | <td><select name='SIDE'> | |
4637 | <option value='server' $selected{'SIDE'}{'server'}>$Lang::tr{'openvpn server'}</option> | |
4638 | <option value='client' $selected{'SIDE'}{'client'}>$Lang::tr{'openvpn client'}</option> | |
4639 | </select> | |
4640 | </td> | |
4c962356 | 4641 | |
f527e53f EK |
4642 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> |
4643 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td> | |
4644 | </tr> | |
4c962356 | 4645 | |
e3edceeb | 4646 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4647 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> |
4c962356 | 4648 | |
e3edceeb | 4649 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f EK |
4650 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td> |
4651 | </tr> | |
4c962356 | 4652 | |
e3edceeb | 4653 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4654 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td> |
49abe7af | 4655 | |
f527e53f EK |
4656 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
4657 | <td><select name='PROTOCOL'> | |
4658 | <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
4659 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4660 | </tr> | |
4661 | ||
4662 | <tr> | |
e3edceeb | 4663 | <td class='boldbase'>$Lang::tr{'destination port'}: <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4664 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td> |
4c962356 | 4665 | |
e3edceeb | 4666 | <td class='boldbase' nowrap='nowrap'>Management Port ($Lang::tr{'openvpn default'}: <span class="base">$Lang::tr{'destination port'}):</td> |
f527e53f EK |
4667 | <td> <input type='TEXT' name='OVPN_MGMT' VALUE='$cgiparams{'OVPN_MGMT'}'size='5' /></td> |
4668 | </tr> | |
49abe7af | 4669 | |
f527e53f EK |
4670 | <tr><td colspan=4><hr /></td></tr><tr> |
4671 | ||
4672 | <tr> | |
4673 | <td class'base'><b>$Lang::tr{'MTU settings'}</b></td> | |
4674 | </tr> | |
49abe7af | 4675 | |
e3edceeb | 4676 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td> |
f527e53f EK |
4677 | <td><input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></td> |
4678 | <td colspan='2'>$Lang::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td> | |
4679 | </tr> | |
4c962356 | 4680 | |
e3edceeb | 4681 | <tr><td class='boldbase' nowrap='nowrap'>fragment:</td> |
f527e53f EK |
4682 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> |
4683 | <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td> | |
4684 | </tr> | |
4c962356 | 4685 | |
e3edceeb | 4686 | <tr><td class='boldbase' nowrap='nowrap'>mssfix:</td> |
f527e53f EK |
4687 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> |
4688 | <td>$Lang::tr{'openvpn default'}: <span class="base">on</span></td> | |
4689 | </tr> | |
4c962356 | 4690 | |
e3edceeb | 4691 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
f527e53f EK |
4692 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> |
4693 | </tr> | |
2ee746be | 4694 | |
49abe7af | 4695 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td> |
4cdf8b92 | 4696 | <td colspan='3'> |
2ee746be SS |
4697 | <input type='radio' name='PMTU_DISCOVERY' value='yes' $checked{'PMTU_DISCOVERY'}{'yes'} /> $Lang::tr{'ovpn mtu-disc yes'} |
4698 | <input type='radio' name='PMTU_DISCOVERY' value='maybe' $checked{'PMTU_DISCOVERY'}{'maybe'} /> $Lang::tr{'ovpn mtu-disc maybe'} | |
4699 | <input type='radio' name='PMTU_DISCOVERY' value='no' $checked{'PMTU_DISCOVERY'}{'no'} /> $Lang::tr{'ovpn mtu-disc no'} | |
4700 | <input type='radio' name='PMTU_DISCOVERY' value='off' $checked{'PMTU_DISCOVERY'}{'off'} /> $Lang::tr{'ovpn mtu-disc off'} | |
4701 | </td> | |
4702 | </tr> | |
f527e53f EK |
4703 | |
4704 | <tr><td colspan=4><hr /></td></tr><tr> | |
4705 | <tr> | |
4706 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}:</b></td> | |
4707 | </tr> | |
4708 | ||
4709 | <tr><td class='boldbase'>$Lang::tr{'cipher'}</td> | |
4710 | <td><select name='DCIPHER'> | |
4711 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> | |
4712 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> | |
4713 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> | |
f7fb5bc5 | 4714 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'}, $Lang::tr{'default'})</option> |
f527e53f EK |
4715 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> |
4716 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
ea6dd5b0 EK |
4717 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
4718 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4719 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4720 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4721 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4722 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
f527e53f EK |
4723 | </select> |
4724 | </td> | |
4725 | ||
4726 | <td class='boldbase'>$Lang::tr{'ovpn ha'}:</td> | |
4727 | <td><select name='DAUTH'> | |
4728 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> | |
4729 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
4730 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
4731 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
f3dfb261 | 4732 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
f527e53f EK |
4733 | </select> |
4734 | </td> | |
4735 | </tr> | |
4736 | <tr><td colspan=4><hr /></td></tr><tr> | |
4737 | ||
ce9abb66 | 4738 | END |
8c877a82 | 4739 | ; |
ce9abb66 | 4740 | } |
2ee746be | 4741 | #jumper |
e3edceeb | 4742 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'}</td>"; |
8c877a82 | 4743 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr></table>"; |
c6c9630e | 4744 | |
ce9abb66 | 4745 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
4746 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>"; |
4747 | } | |
ce9abb66 | 4748 | |
8c877a82 AM |
4749 | print"</tr></table><br><br>"; |
4750 | #A.Marx CCD new client | |
e81be1e1 | 4751 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 | 4752 | 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 |
4753 | my %vpnnet=(); |
4754 | my $vpnip; | |
4755 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); | |
4756 | $vpnip=$vpnnet{'DOVPN_SUBNET'}; | |
4757 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
4758 | my @ccdconf=(); | |
4759 | my $count=0; | |
4760 | my $checked; | |
4761 | $checked{'check1'}{'off'} = ''; | |
4762 | $checked{'check1'}{'on'} = ''; | |
4763 | $checked{'check1'}{$cgiparams{'CHECK1'}} = 'CHECKED'; | |
4764 | 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%'>"; | |
4765 | print"</td></tr></table><br><br>"; | |
4766 | my $name=$cgiparams{'CHECK1'}; | |
4767 | $checked{'RG'}{$cgiparams{'RG'}} = 'CHECKED'; | |
4768 | ||
4769 | if (! -z "${General::swroot}/ovpn/ccd.conf"){ | |
4770 | 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 | 4771 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
4772 | $count++; |
4773 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
4774 | if ($count % 2){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";} | |
4775 | 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%'>"; | |
4776 | &fillselectbox($ccdconf[1],$ccdconf[0],$cgiparams{$name}); | |
4777 | print"</td></tr>"; | |
4778 | } | |
4779 | print "</table><br><br><hr><br><br>"; | |
4780 | } | |
e81be1e1 | 4781 | } |
8c877a82 | 4782 | # ccd end |
6e13d0a5 MT |
4783 | &Header::closebox(); |
4784 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { | |
8c877a82 AM |
4785 | |
4786 | } elsif (! $cgiparams{'KEY'}) { | |
4787 | ||
4788 | ||
6e13d0a5 MT |
4789 | my $disabled=''; |
4790 | my $cakeydisabled=''; | |
4791 | my $cacrtdisabled=''; | |
4792 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
4793 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
8c877a82 | 4794 | |
6e13d0a5 | 4795 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
ce9abb66 AH |
4796 | |
4797 | ||
4798 | if ($cgiparams{'TYPE'} eq 'host') { | |
4799 | ||
49abe7af | 4800 | print <<END; |
6e13d0a5 | 4801 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
54fd0535 | 4802 | |
ce9abb66 AH |
4803 | <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> |
4804 | <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 |
4805 | <tr><td colspan='3'> </td></tr> |
4806 | <tr><td colspan='3'><hr /></td></tr> | |
4807 | <tr><td colspan='3'> </td></tr> | |
ce9abb66 | 4808 | <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 |
4809 | <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> |
4810 | <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> | |
4811 | <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> | |
4812 | <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> | |
4813 | <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> | |
4814 | <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 | 4815 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
6e13d0a5 | 4816 | END |
ce9abb66 AH |
4817 | ; |
4818 | ||
4819 | ### | |
7c1d9faf | 4820 | # m.a.d net2net |
ce9abb66 AH |
4821 | ### |
4822 | ||
4823 | } else { | |
4824 | ||
49abe7af | 4825 | print <<END; |
ce9abb66 AH |
4826 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
4827 | ||
4828 | <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 |
4829 | <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> |
4830 | <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> | |
4831 | <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> | |
4832 | <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> | |
4833 | <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> | |
4834 | <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 | 4835 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
54fd0535 MT |
4836 | |
4837 | ||
ce9abb66 AH |
4838 | END |
4839 | ; | |
4840 | ||
4841 | } | |
4842 | ||
4843 | ### | |
7c1d9faf | 4844 | # m.a.d net2net |
ce9abb66 | 4845 | ### |
c6c9630e | 4846 | |
6e13d0a5 MT |
4847 | foreach my $country (sort keys %{Countries::countries}) { |
4848 | print "<option value='$Countries::countries{$country}'"; | |
4849 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
4850 | print " selected='selected'"; | |
4851 | } | |
4852 | print ">$country</option>"; | |
4853 | } | |
ce9abb66 | 4854 | ### |
7c1d9faf | 4855 | # m.a.d net2net |
ce9abb66 AH |
4856 | ### |
4857 | ||
4858 | if ($cgiparams{'TYPE'} eq 'host') { | |
49abe7af | 4859 | print <<END; |
f4fbb935 EK |
4860 | </select></td></tr> |
4861 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days):</td> | |
4862 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> | |
4863 | <tr><td> </td> | |
6e13d0a5 MT |
4864 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
4865 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
f4fbb935 | 4866 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<br>($Lang::tr{'confirmation'})</td> |
6e13d0a5 | 4867 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> |
f4fbb935 EK |
4868 | <tr><td colspan='3'> </td></tr> |
4869 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4870 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
f4fbb935 | 4871 | </table> |
ce9abb66 AH |
4872 | END |
4873 | }else{ | |
49abe7af | 4874 | print <<END; |
f4fbb935 EK |
4875 | </select></td></tr> |
4876 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days):</td> | |
4877 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> | |
4878 | <tr><td> </td><td> </td><td> </td></tr> | |
4879 | <tr><td> </td><td> </td><td> </td></tr> | |
4880 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4881 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
ce9abb66 AH |
4882 | </table> |
4883 | ||
c6c9630e | 4884 | END |
ce9abb66 AH |
4885 | } |
4886 | ||
4887 | ### | |
7c1d9faf | 4888 | # m.a.d net2net |
ce9abb66 | 4889 | ### |
c6c9630e MT |
4890 | ; |
4891 | &Header::closebox(); | |
8c877a82 AM |
4892 | |
4893 | } | |
e81be1e1 AM |
4894 | |
4895 | #A.Marx CCD new client | |
4896 | if ($cgiparams{'TYPE'} eq 'host') { | |
8c877a82 AM |
4897 | print"<br><br>"; |
4898 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); | |
4899 | ||
8c877a82 AM |
4900 | |
4901 | print <<END; | |
4902 | <table border='0' width='100%'> | |
4903 | <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked{'RG'}{'on'} /></td></tr> | |
4904 | <tr><td colspan='4'><b><br>$Lang::tr{'ccd routes'}</b></td></tr> | |
4905 | <tr><td colspan='4'> </td></tr> | |
4906 | <tr><td valign='top'>$Lang::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'> | |
4907 | END | |
4908 | ||
4909 | if ($cgiparams{'IR'} ne ''){ | |
4910 | print $cgiparams{'IR'}; | |
4911 | }else{ | |
4912 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4913 | foreach my $key (keys %ccdroutehash) { | |
4914 | if( $cgiparams{'NAME'} eq $ccdroutehash{$key}[0]){ | |
4915 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
4916 | if ($ccdroutehash{$key}[$i] ne ''){ | |
4917 | print $ccdroutehash{$key}[$i]."\n"; | |
4918 | } | |
4919 | $cgiparams{'IR'} .= $ccdroutehash{$key}[$i]; | |
4920 | } | |
4921 | } | |
4922 | } | |
c6c9630e | 4923 | } |
8c877a82 AM |
4924 | |
4925 | print <<END; | |
4926 | </textarea></td><td valign='top' colspan='2'>$Lang::tr{'ccd iroutehint'}</td></tr> | |
4927 | <tr><td colspan='4'><br></td></tr> | |
4928 | <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> | |
4929 | END | |
52d08bcb AM |
4930 | |
4931 | my $set=0; | |
4932 | my $selorange=0; | |
4933 | my $selblue=0; | |
4934 | my $selgreen=0; | |
4935 | my $helpblue=0; | |
4936 | my $helporange=0; | |
4937 | my $other=0; | |
df9b48b7 | 4938 | my $none=0; |
52d08bcb AM |
4939 | my @temp=(); |
4940 | ||
8c877a82 | 4941 | our @current = (); |
52d08bcb AM |
4942 | open(FILE, "${General::swroot}/main/routing") ; |
4943 | @current = <FILE>; | |
4944 | close (FILE); | |
4945 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
df9b48b7 AM |
4946 | #check for "none" |
4947 | foreach my $key (keys %ccdroute2hash) { | |
4948 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4949 | if ($ccdroute2hash{$key}[1] eq ''){ | |
4950 | $none=1; | |
4951 | last; | |
4952 | } | |
4953 | } | |
4954 | } | |
4955 | if ($none ne '1'){ | |
4956 | print"<option>$Lang::tr{'ccd none'}</option>"; | |
4957 | }else{ | |
4958 | print"<option selected>$Lang::tr{'ccd none'}</option>"; | |
4959 | } | |
52d08bcb AM |
4960 | #check if static routes are defined for client |
4961 | foreach my $line (@current) { | |
4962 | chomp($line); | |
4963 | $line=~s/\s*$//g; # remove newline | |
4964 | @temp=split(/\,/,$line); | |
4965 | $temp[1] = '' unless defined $temp[1]; # not always populated | |
4966 | my ($a,$b) = split(/\//,$temp[1]); | |
4967 | $temp[1] = $a."/".&General::iporsubtocidr($b); | |
4968 | foreach my $key (keys %ccdroute2hash) { | |
4969 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4970 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4971 | if($ccdroute2hash{$key}[$i] eq $a."/".&General::iporsubtodec($b)){ | |
4972 | $set=1; | |
8c877a82 AM |
4973 | } |
4974 | } | |
8c877a82 | 4975 | } |
52d08bcb AM |
4976 | } |
4977 | if ($set == '1' && $#temp != -1){ print"<option selected>$temp[1]</option>";$set=0;}elsif($set == '0' && $#temp != -1){print"<option>$temp[1]</option>";} | |
4978 | } | |
3a445974 MT |
4979 | |
4980 | my %vpnconfig = (); | |
4981 | &General::readhasharray("${General::swroot}/vpn/config", \%vpnconfig); | |
4982 | foreach my $vpn (keys %vpnconfig) { | |
4983 | # Skip all disabled VPN connections | |
4984 | my $enabled = $vpnconfig{$vpn}[0]; | |
4985 | next unless ($enabled eq "on"); | |
4986 | ||
4987 | my $name = $vpnconfig{$vpn}[1]; | |
4988 | ||
4989 | # Remote subnets | |
4990 | my @networks = split(/\|/, $vpnconfig{$vpn}[11]); | |
4991 | foreach my $network (@networks) { | |
4992 | my $selected = ""; | |
4993 | ||
4994 | foreach my $key (keys %ccdroute2hash) { | |
4995 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
4996 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4997 | if ($ccdroute2hash{$key}[$i] eq $network) { | |
4998 | $selected = "selected"; | |
4999 | } | |
5000 | } | |
5001 | } | |
5002 | } | |
5003 | ||
5004 | print "<option value=\"$network\" $selected>$name ($network)</option>\n"; | |
5005 | } | |
5006 | } | |
5007 | ||
52d08bcb AM |
5008 | #check if green,blue,orange are defined for client |
5009 | foreach my $key (keys %ccdroute2hash) { | |
5010 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
5011 | $other=1; | |
5012 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
5013 | if ($ccdroute2hash{$key}[$i] eq $netsettings{'GREEN_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'GREEN_NETMASK'})){ | |
5014 | $selgreen=1; | |
5015 | } | |
5016 | if (&haveBlueNet()){ | |
5017 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'})) { | |
5018 | $selblue=1; | |
5019 | } | |
5020 | } | |
5021 | if (&haveOrangeNet()){ | |
5022 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'ORANGE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'ORANGE_NETMASK'}) ) { | |
5023 | $selorange=1; | |
5024 | } | |
5025 | } | |
5026 | } | |
5027 | } | |
5028 | } | |
5029 | if (&haveBlueNet() && $selblue == '1'){ print"<option selected>$Lang::tr{'blue'}</option>";$selblue=0;}elsif(&haveBlueNet() && $selblue == '0'){print"<option>$Lang::tr{'blue'}</option>";} | |
5030 | if (&haveOrangeNet() && $selorange == '1'){ print"<option selected>$Lang::tr{'orange'}</option>";$selorange=0;}elsif(&haveOrangeNet() && $selorange == '0'){print"<option>$Lang::tr{'orange'}</option>";} | |
5031 | if ($selgreen == '1' || $other == '0'){ print"<option selected>$Lang::tr{'green'}</option>";$set=0;}else{print"<option>$Lang::tr{'green'}</option>";}; | |
5032 | ||
49abe7af | 5033 | print<<END; |
8c877a82 AM |
5034 | </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value='$cgiparams{'CCD_DNS1'}' size='30' /></td></tr> |
5035 | <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value='$cgiparams{'CCD_DNS2'}' size='30' /></td></tr> | |
5036 | <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> | |
5037 | ||
5038 | END | |
5039 | ; | |
5040 | &Header::closebox(); | |
e81be1e1 | 5041 | } |
c6c9630e MT |
5042 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5043 | if ($cgiparams{'KEY'}) { | |
5044 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
5045 | } | |
5046 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
5047 | &Header::closebigbox(); | |
5048 | &Header::closepage(); | |
5049 | exit (0); | |
6e13d0a5 | 5050 | } |
c6c9630e | 5051 | VPNCONF_END: |
6e13d0a5 | 5052 | } |
c6c9630e MT |
5053 | |
5054 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
5055 | ### |
5056 | ### Default status page | |
5057 | ### | |
c6c9630e MT |
5058 | %cgiparams = (); |
5059 | %cahash = (); | |
5060 | %confighash = (); | |
5061 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
5062 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
5063 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
5064 | ||
87fe47e9 | 5065 | my @status = `/bin/cat /var/run/ovpnserver.log`; |
c6c9630e MT |
5066 | |
5067 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
8c877a82 AM |
5068 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
5069 | my $ipaddr = <IPADDR>; | |
5070 | close IPADDR; | |
5071 | chomp ($ipaddr); | |
5072 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
5073 | if ($cgiparams{'VPN_IP'} eq '') { | |
5074 | $cgiparams{'VPN_IP'} = $ipaddr; | |
5075 | } | |
5076 | } | |
c6c9630e MT |
5077 | } |
5078 | ||
6e13d0a5 | 5079 | #default setzen |
c6c9630e | 5080 | if ($cgiparams{'DCIPHER'} eq '') { |
4c962356 | 5081 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; |
c6c9630e | 5082 | } |
c6c9630e | 5083 | if ($cgiparams{'DDEST_PORT'} eq '') { |
4c962356 | 5084 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
5085 | } |
5086 | if ($cgiparams{'DMTU'} eq '') { | |
4c962356 EK |
5087 | $cgiparams{'DMTU'} = '1400'; |
5088 | } | |
5089 | if ($cgiparams{'MSSFIX'} eq '') { | |
5090 | $cgiparams{'MSSFIX'} = 'off'; | |
5091 | } | |
5092 | if ($cgiparams{'DAUTH'} eq '') { | |
70900745 | 5093 | $cgiparams{'DAUTH'} = 'SHA512'; |
c6c9630e MT |
5094 | } |
5095 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { | |
4c962356 | 5096 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e | 5097 | } |
4c962356 | 5098 | $checked{'ENABLED'}{'off'} = ''; |
c6c9630e MT |
5099 | $checked{'ENABLED'}{'on'} = ''; |
5100 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
5101 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
5102 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
5103 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
5104 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
5105 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
5106 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
5107 | |
5108 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
5109 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
5110 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
4c962356 EK |
5111 | |
5112 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; | |
5113 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
5114 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
5115 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
5116 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
5117 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
c6c9630e MT |
5118 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; |
5119 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4c962356 EK |
5120 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; |
5121 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
5122 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
5123 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 5124 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
c6c9630e | 5125 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
4c962356 EK |
5126 | |
5127 | $selected{'DAUTH'}{'whirlpool'} = ''; | |
5128 | $selected{'DAUTH'}{'SHA512'} = ''; | |
5129 | $selected{'DAUTH'}{'SHA384'} = ''; | |
5130 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
5131 | $selected{'DAUTH'}{'SHA1'} = ''; |
5132 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
5133 | ||
c6c9630e MT |
5134 | $checked{'DCOMPLZO'}{'off'} = ''; |
5135 | $checked{'DCOMPLZO'}{'on'} = ''; | |
5136 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
4c962356 | 5137 | |
d96c89eb AH |
5138 | # m.a.d |
5139 | $checked{'MSSFIX'}{'off'} = ''; | |
5140 | $checked{'MSSFIX'}{'on'} = ''; | |
5141 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 5142 | #new settings |
c6c9630e MT |
5143 | &Header::showhttpheaders(); |
5144 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
5145 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 5146 | |
c6c9630e | 5147 | if ($errormessage) { |
6e13d0a5 MT |
5148 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
5149 | print "<class name='base'>$errormessage\n"; | |
5150 | print " </class>\n"; | |
5151 | &Header::closebox(); | |
c6c9630e | 5152 | } |
6e13d0a5 | 5153 | |
b2e75449 MT |
5154 | if ($warnmessage) { |
5155 | &Header::openbox('100%', 'LEFT', $Lang::tr{'warning messages'}); | |
5156 | print "$warnmessage<br>"; | |
5157 | print "$Lang::tr{'fwdfw warn1'}<br>"; | |
5158 | &Header::closebox(); | |
5159 | print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>"; | |
5160 | &Header::closepage(); | |
5161 | exit 0; | |
5162 | } | |
4d81e0f3 | 5163 | |
c6c9630e MT |
5164 | 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>"; |
5165 | my $srunning = "no"; | |
5166 | my $activeonrun = ""; | |
5167 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
5168 | $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>"; |
5169 | $srunning ="yes"; | |
5170 | $activeonrun = ""; | |
c6c9630e | 5171 | } else { |
6e13d0a5 | 5172 | $activeonrun = "disabled='disabled'"; |
c6c9630e | 5173 | } |
afabe9f7 | 5174 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); |
4c962356 | 5175 | print <<END; |
631b67b7 | 5176 | <table width='100%' border='0'> |
c6c9630e MT |
5177 | <form method='post'> |
5178 | <td width='25%'> </td> | |
5179 | <td width='25%'> </td> | |
5180 | <td width='25%'> </td></tr> | |
5181 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
5182 | <td align='left'>$sactive</td> | |
5183 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
8c877a82 | 5184 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> |
c6c9630e MT |
5185 | END |
5186 | ; | |
5187 | if (&haveBlueNet()) { | |
5188 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
5189 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
5190 | } | |
5191 | if (&haveOrangeNet()) { | |
5192 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
5193 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
5194 | } | |
4c962356 | 5195 | print <<END; |
4e17adad CS |
5196 | <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> |
5197 | <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 |
5198 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
5199 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
5200 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
5201 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
5202 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
5203 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
bc2b3e94 | 5204 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}' size='5' /></td> |
f527e53f | 5205 | |
4c962356 EK |
5206 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> |
5207 | <td><select name='DCIPHER'> | |
5208 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> | |
f527e53f | 5209 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> |
4c962356 EK |
5210 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> |
5211 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'})</option> | |
5212 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> | |
5213 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
4c962356 | 5214 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
ea6dd5b0 EK |
5215 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
5216 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5217 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5218 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5219 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4c962356 EK |
5220 | </select> |
5221 | </td> | |
c6c9630e MT |
5222 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
5223 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
4c962356 | 5224 | </tr> |
f7edf97a | 5225 | <tr><td colspan='4'><br><br></td></tr> |
c6c9630e MT |
5226 | END |
5227 | ; | |
5228 | ||
5229 | if ( $srunning eq "yes" ) { | |
8c877a82 AM |
5230 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' />"; |
5231 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5232 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
5233 | print "<input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td></tr>"; | |
c6c9630e | 5234 | } else{ |
8c877a82 AM |
5235 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5236 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5237 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
c6c9630e MT |
5238 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && |
5239 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
5240 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
5241 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
5242 | (( $cgiparams{'ENABLED'} eq 'on') || | |
5243 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
5244 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
8c877a82 | 5245 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td></tr>"; |
c6c9630e | 5246 | } else { |
8c877a82 | 5247 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td></tr>"; |
c6c9630e MT |
5248 | } |
5249 | } | |
5250 | print "</form></table>"; | |
5251 | &Header::closebox(); | |
6e13d0a5 | 5252 | |
c6c9630e | 5253 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { |
ce9abb66 | 5254 | ### |
7c1d9faf | 5255 | # m.a.d net2net |
54fd0535 | 5256 | #<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 |
5257 | ### |
5258 | ||
4c962356 | 5259 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection status and controlc' }); |
c6c9630e | 5260 | ; |
99bfa85c AM |
5261 | my $id = 0; |
5262 | my $gif; | |
f7edf97a | 5263 | my $col1=""; |
5b942f7f | 5264 | my $lastnet; |
c8b51e28 | 5265 | foreach my $key (sort { ncmp ($confighash{$a}[32],$confighash{$b}[32]) } sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) { |
5b942f7f AM |
5266 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]=$Lang::tr{'fwhost OpenVPN N-2-N'};} |
5267 | if ($confighash{$key}[32] eq "dynamic"){$confighash{$key}[32]=$Lang::tr{'ccd dynrange'};} | |
5268 | if($id == 0){ | |
5269 | print"<b>$confighash{$key}[32]</b>"; | |
5270 | print <<END; | |
5271 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5272 | <tr> | |
5273 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5274 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5275 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5276 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
71af643c | 5277 | <th width='5%' class='boldbase' colspan='7' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5278 | </tr> |
5279 | END | |
5280 | } | |
5281 | if ($id > 0 && $lastnet ne $confighash{$key}[32]){ | |
5282 | print "</table><br>"; | |
5283 | print"<b>$confighash{$key}[32]</b>"; | |
5284 | print <<END; | |
5285 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5286 | <tr> | |
5287 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5288 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5289 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5290 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
71af643c | 5291 | <th width='5%' class='boldbase' colspan='7' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5292 | </tr> |
5293 | END | |
5294 | } | |
eff2dbf8 | 5295 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } |
c6c9630e | 5296 | if ($id % 2) { |
99bfa85c AM |
5297 | print "<tr>"; |
5298 | $col="bgcolor='$color{'color20'}'"; | |
bb89e92a | 5299 | } else { |
99bfa85c AM |
5300 | print "<tr>"; |
5301 | $col="bgcolor='$color{'color22'}'"; | |
c6c9630e | 5302 | } |
99bfa85c AM |
5303 | print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>"; |
5304 | print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
8c877a82 AM |
5305 | #if ($confighash{$key}[4] eq 'cert') { |
5306 | #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
5307 | #} else { | |
5308 | #print "<td align='left'> </td>"; | |
5309 | #} | |
c6c9630e MT |
5310 | my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; |
5311 | $cavalid =~ /Not After : (.*)[\n]/; | |
5312 | $cavalid = $1; | |
99bfa85c | 5313 | print "<td align='center' $col>$confighash{$key}[25]</td>"; |
f7edf97a AM |
5314 | $col1="bgcolor='${Header::colourred}'"; |
5315 | my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
ce9abb66 | 5316 | |
c6c9630e | 5317 | if ($confighash{$key}[0] eq 'off') { |
f7edf97a AM |
5318 | $col1="bgcolor='${Header::colourblue}'"; |
5319 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
c6c9630e | 5320 | } else { |
ce9abb66 AH |
5321 | |
5322 | ### | |
7c1d9faf | 5323 | # m.a.d net2net |
f7edf97a AM |
5324 | ### |
5325 | ||
b278daf3 | 5326 | if ($confighash{$key}[3] eq 'net') { |
54fd0535 MT |
5327 | |
5328 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
5329 | my @output = ""; | |
5330 | my @tustate = ""; | |
5331 | my $tport = $confighash{$key}[22]; | |
5332 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
5333 | if ($tport ne '') { | |
5334 | $tnet->open('127.0.0.1'); | |
5335 | @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
5336 | @tustate = split(/\,/, $output[1]); | |
5337 | ### | |
5338 | #CONNECTING -- OpenVPN's initial state. | |
5339 | #WAIT -- (Client only) Waiting for initial response from server. | |
5340 | #AUTH -- (Client only) Authenticating with server. | |
5341 | #GET_CONFIG -- (Client only) Downloading configuration options from server. | |
5342 | #ASSIGN_IP -- Assigning IP address to virtual network interface. | |
5343 | #ADD_ROUTES -- Adding routes to system. | |
5344 | #CONNECTED -- Initialization Sequence Completed. | |
5345 | #RECONNECTING -- A restart has occurred. | |
5346 | #EXITING -- A graceful exit is in progress. | |
5347 | #### | |
5348 | ||
ed4b4c19 | 5349 | if (($tustate[1] eq 'CONNECTED') || ($tustate[1] eq 'WAIT')) { |
f7edf97a AM |
5350 | $col1="bgcolor='${Header::colourgreen}'"; |
5351 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5352 | }else { | |
5353 | $col1="bgcolor='${Header::colourred}'"; | |
5354 | $active = "<b><font color='#FFFFFF'>$tustate[1]</font></b>"; | |
5355 | } | |
54fd0535 | 5356 | } |
54fd0535 | 5357 | } |
f7edf97a AM |
5358 | }else { |
5359 | ||
5360 | my $cn; | |
5361 | my @match = (); | |
5362 | foreach my $line (@status) { | |
5363 | chomp($line); | |
5364 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
5365 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
5366 | if ($match[1] ne "Common Name") { | |
5367 | $cn = $match[1]; | |
5368 | } | |
5369 | $cn =~ s/[_]/ /g; | |
5370 | if ($cn eq "$confighash{$key}[2]") { | |
5371 | $col1="bgcolor='${Header::colourgreen}'"; | |
5372 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5373 | } | |
5374 | } | |
5375 | } | |
c6c9630e | 5376 | } |
7c1d9faf | 5377 | } |
ce9abb66 AH |
5378 | |
5379 | ||
4c962356 | 5380 | print <<END; |
f7edf97a | 5381 | <td align='center' $col1>$active</td> |
c6c9630e | 5382 | |
99bfa85c | 5383 | <form method='post' name='frm${key}a'><td align='center' $col> |
96096995 AM |
5384 | <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' /> |
5385 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5386 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
5387 | </td></form> |
5388 | END | |
5389 | ; | |
71af643c MT |
5390 | |
5391 | if ($confighash{$key}[41] eq "no-pass") { | |
5392 | print <<END; | |
5393 | <form method='post' name='frm${key}g'><td align='center' $col> | |
5394 | <input type='image' name='$Lang::tr{'dl client arch insecure'}' src='/images/openvpn.png' | |
5395 | alt='$Lang::tr{'dl client arch insecure'}' title='$Lang::tr{'dl client arch insecure'}' border='0' /> | |
5396 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5397 | <input type='hidden' name='MODE' value='insecure' /> | |
5398 | <input type='hidden' name='KEY' value='$key' /> | |
5399 | </td></form> | |
5400 | END | |
5401 | } else { | |
5402 | print "<td $col> </td>"; | |
5403 | } | |
5404 | ||
c6c9630e | 5405 | if ($confighash{$key}[4] eq 'cert') { |
4c962356 | 5406 | print <<END; |
99bfa85c | 5407 | <form method='post' name='frm${key}b'><td align='center' $col> |
c6c9630e MT |
5408 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> |
5409 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
5410 | <input type='hidden' name='KEY' value='$key' /> | |
5411 | </td></form> | |
5412 | END | |
5413 | ; } else { | |
5414 | print "<td> </td>"; | |
5415 | } | |
5416 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
4c962356 | 5417 | print <<END; |
99bfa85c | 5418 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5419 | <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 |
5420 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
5421 | <input type='hidden' name='KEY' value='$key' /> | |
5422 | </td></form> | |
5423 | END | |
5424 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5425 | print <<END; |
99bfa85c | 5426 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5427 | <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 |
5428 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
5429 | <input type='hidden' name='KEY' value='$key' /> | |
5430 | </td></form> | |
5431 | END | |
5432 | ; } else { | |
5433 | print "<td> </td>"; | |
5434 | } | |
5435 | print <<END | |
99bfa85c | 5436 | <form method='post' name='frm${key}d'><td align='center' $col> |
c6c9630e MT |
5437 | <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' /> |
5438 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
5439 | <input type='hidden' name='KEY' value='$key' /> | |
5440 | </td></form> | |
5441 | ||
99bfa85c | 5442 | <form method='post' name='frm${key}e'><td align='center' $col> |
c6c9630e MT |
5443 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> |
5444 | <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'/> | |
5445 | <input type='hidden' name='KEY' value='$key' /> | |
5446 | </td></form> | |
99bfa85c | 5447 | <form method='post' name='frm${key}f'><td align='center' $col> |
c6c9630e MT |
5448 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> |
5449 | <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' /> | |
5450 | <input type='hidden' name='KEY' value='$key' /> | |
5451 | </td></form> | |
5452 | </tr> | |
5453 | END | |
5454 | ; | |
5455 | $id++; | |
5b942f7f | 5456 | $lastnet = $confighash{$key}[32]; |
c6c9630e | 5457 | } |
5b942f7f | 5458 | print"</table>"; |
c6c9630e MT |
5459 | ; |
5460 | ||
5461 | # If the config file contains entries, print Key to action icons | |
5462 | if ( $id ) { | |
4c962356 | 5463 | print <<END; |
8c877a82 | 5464 | <table border='0'> |
c6c9630e | 5465 | <tr> |
4c962356 EK |
5466 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
5467 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
5468 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
5469 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5470 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5471 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
5472 | <td class='base'>$Lang::tr{'edit'}</td> | |
5473 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
5474 | <td class='base'>$Lang::tr{'remove'}</td> | |
c6c9630e MT |
5475 | </tr> |
5476 | <tr> | |
4c962356 EK |
5477 | <td> </td> |
5478 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
5479 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
5480 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> | |
5481 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5482 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> | |
5483 | <td class='base'>$Lang::tr{'dl client arch'}</td> | |
5484 | </tr> | |
f7edf97a | 5485 | </table><br> |
c6c9630e MT |
5486 | END |
5487 | ; | |
5488 | } | |
5489 | ||
4c962356 | 5490 | print <<END; |
c6c9630e MT |
5491 | <table width='100%'> |
5492 | <form method='post'> | |
4c962356 EK |
5493 | <tr><td align='right'> |
5494 | <input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
5495 | <input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td> | |
5496 | </tr> | |
c6c9630e MT |
5497 | </form> |
5498 | </table> | |
5499 | END | |
4c962356 EK |
5500 | ; |
5501 | &Header::closebox(); | |
5502 | } | |
fd5ccb2d EK |
5503 | |
5504 | # CA/key listing | |
4c962356 EK |
5505 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}"); |
5506 | print <<END; | |
5507 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5508 | <tr> | |
5509 | <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5510 | <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th> | |
5511 | <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th> | |
5512 | </tr> | |
5513 | END | |
5514 | ; | |
5515 | my $col1="bgcolor='$color{'color22'}'"; | |
f7fb5bc5 | 5516 | my $col2="bgcolor='$color{'color20'}'"; |
c8f50356 | 5517 | # DH parameter line |
f7fb5bc5 | 5518 | my $col3="bgcolor='$color{'color22'}'"; |
fd5ccb2d EK |
5519 | # ta.key line |
5520 | my $col4="bgcolor='$color{'color20'}'"; | |
f7fb5bc5 | 5521 | |
4c962356 EK |
5522 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { |
5523 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
5524 | $casubject =~ /Subject: (.*)[\n]/; | |
5525 | $casubject = $1; | |
5526 | $casubject =~ s+/Email+, E+; | |
5527 | $casubject =~ s/ ST=/ S=/; | |
5528 | print <<END; | |
5529 | <tr> | |
5530 | <td class='base' $col1>$Lang::tr{'root certificate'}</td> | |
5531 | <td class='base' $col1>$casubject</td> | |
c8f50356 | 5532 | <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1> |
4c962356 EK |
5533 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> |
5534 | <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 |
5535 | </form> |
5536 | <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1> | |
4c962356 EK |
5537 | <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' /> |
5538 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
c8f50356 EK |
5539 | </form> |
5540 | <td width='4%' $col1> </td> | |
5541 | </tr> | |
4c962356 EK |
5542 | END |
5543 | ; | |
5544 | } else { | |
5545 | # display rootcert generation buttons | |
5546 | print <<END; | |
5547 | <tr> | |
5548 | <td class='base' $col1>$Lang::tr{'root certificate'}:</td> | |
5549 | <td class='base' $col1>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5550 | <td colspan='3' $col1> </td> |
5551 | </tr> | |
4c962356 EK |
5552 | END |
5553 | ; | |
5554 | } | |
5555 | ||
5556 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
5557 | my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
5558 | $hostsubject =~ /Subject: (.*)[\n]/; | |
5559 | $hostsubject = $1; | |
5560 | $hostsubject =~ s+/Email+, E+; | |
5561 | $hostsubject =~ s/ ST=/ S=/; | |
5562 | ||
5563 | print <<END; | |
5564 | <tr> | |
5565 | <td class='base' $col2>$Lang::tr{'host certificate'}</td> | |
5566 | <td class='base' $col2>$hostsubject</td> | |
c8f50356 | 5567 | <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2> |
4c962356 EK |
5568 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> |
5569 | <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 |
5570 | </form> |
5571 | <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2> | |
4c962356 EK |
5572 | <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' /> |
5573 | <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" /> | |
c8f50356 EK |
5574 | </td></form> |
5575 | <td width='4%' $col2> </td> | |
5576 | </tr> | |
4c962356 EK |
5577 | END |
5578 | ; | |
5579 | } else { | |
5580 | # Nothing | |
5581 | print <<END; | |
5582 | <tr> | |
5583 | <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td> | |
5584 | <td class='base' $col2>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5585 | </td><td colspan='3' $col2> </td> |
5586 | </tr> | |
4c962356 EK |
5587 | END |
5588 | ; | |
5589 | } | |
ce9abb66 | 5590 | |
f7fb5bc5 EK |
5591 | # Adding DH parameter to chart |
5592 | if (-f "${General::swroot}/ovpn/ca/dh1024.pem") { | |
5593 | my $dhsubject = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem`; | |
c8f50356 | 5594 | $dhsubject =~ / (.*)[\n]/; |
f7fb5bc5 EK |
5595 | $dhsubject = $1; |
5596 | ||
5597 | ||
5598 | print <<END; | |
5599 | <tr> | |
5600 | <td class='base' $col3>$Lang::tr{'dh parameter'}</td> | |
5601 | <td class='base' $col3>$dhsubject</td> | |
c8f50356 | 5602 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> |
f7fb5bc5 EK |
5603 | <input type='hidden' name='ACTION' value='$Lang::tr{'show dh'}' /> |
5604 | <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 |
5605 | </form> |
5606 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> | |
c8f50356 EK |
5607 | </form> |
5608 | <td width='4%' $col3> </td> | |
5609 | </tr> | |
f7fb5bc5 EK |
5610 | END |
5611 | ; | |
5612 | } else { | |
5613 | # Nothing | |
5614 | print <<END; | |
5615 | <tr> | |
5616 | <td width='25%' class='base' $col3>$Lang::tr{'dh parameter'}:</td> | |
5617 | <td class='base' $col3>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5618 | </td><td colspan='3' $col3> </td> |
5619 | </tr> | |
f7fb5bc5 EK |
5620 | END |
5621 | ; | |
5622 | } | |
5623 | ||
fd5ccb2d EK |
5624 | # Adding ta.key to chart |
5625 | if (-f "${General::swroot}/ovpn/certs/ta.key") { | |
5626 | my $tasubject = `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
5627 | $tasubject =~ /# (.*)[\n]/; | |
5628 | $tasubject = $1; | |
5629 | print <<END; | |
5630 | ||
5631 | <tr> | |
5632 | <td class='base' $col4>$Lang::tr{'ta key'}</td> | |
5633 | <td class='base' $col4>$tasubject</td> | |
5634 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5635 | <input type='hidden' name='ACTION' value='$Lang::tr{'show tls-auth key'}' /> | |
5636 | <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' /> | |
5637 | </form> | |
5638 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5639 | <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' /> | |
5640 | <input type='hidden' name='ACTION' value='$Lang::tr{'download tls-auth key'}' /> | |
5641 | </form> | |
5642 | <td width='4%' $col4> </td> | |
5643 | </tr> | |
5644 | END | |
5645 | ; | |
5646 | } else { | |
5647 | # Nothing | |
5648 | print <<END; | |
5649 | <tr> | |
5650 | <td width='25%' class='base' $col4>$Lang::tr{'ta key'}:</td> | |
5651 | <td class='base' $col4>$Lang::tr{'not present'}</td> | |
5652 | <td colspan='3' $col4> </td> | |
5653 | </tr> | |
5654 | END | |
5655 | ; | |
5656 | } | |
5657 | ||
4c962356 EK |
5658 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
5659 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
5660 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; | |
5661 | print "</form></td></tr>\n"; | |
5662 | } | |
5663 | ||
5664 | if (keys %cahash > 0) { | |
5665 | foreach my $key (keys %cahash) { | |
5666 | if (($key + 1) % 2) { | |
5667 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
5668 | } else { | |
5669 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
5670 | } | |
5671 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
5672 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
5673 | print <<END; | |
5674 | <form method='post' name='cafrm${key}a'><td align='center'> | |
5675 | <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' /> | |
5676 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
5677 | <input type='hidden' name='KEY' value='$key' /> | |
5678 | </td></form> | |
5679 | <form method='post' name='cafrm${key}b'><td align='center'> | |
5680 | <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' /> | |
5681 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
5682 | <input type='hidden' name='KEY' value='$key' /> | |
5683 | </td></form> | |
5684 | <form method='post' name='cafrm${key}c'><td align='center'> | |
5685 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
5686 | <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' /> | |
5687 | <input type='hidden' name='KEY' value='$key' /> | |
5688 | </td></form></tr> | |
5689 | END | |
5690 | ; | |
5691 | } | |
5692 | } | |
5693 | ||
5694 | print "</table>"; | |
5695 | ||
5696 | # If the file contains entries, print Key to action icons | |
5697 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
5698 | print <<END; | |
5699 | <table> | |
5700 | <tr> | |
5701 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
5702 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5703 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5704 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> | |
5705 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5706 | </tr> | |
5707 | </table> | |
5708 | END | |
5709 | ; | |
5710 | } | |
ce9abb66 | 5711 | |
4c962356 | 5712 | print <<END |
578f23c8 SS |
5713 | |
5714 | <br><hr><br> | |
5715 | ||
4c962356 | 5716 | <form method='post' enctype='multipart/form-data'> |
578f23c8 SS |
5717 | <table border='0' width='100%'> |
5718 | <tr> | |
5719 | <td colspan='4'><b>$Lang::tr{'upload ca certificate'}</b></td> | |
5720 | </tr> | |
4c962356 | 5721 | |
578f23c8 SS |
5722 | <tr> |
5723 | <td width='10%'>$Lang::tr{'ca name'}:</td> | |
5724 | <td width='30%'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' align='left'></td> | |
5725 | <td width='30%'><input type='file' name='FH' size='25'> | |
5726 | <td width='30%'align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}'></td> | |
5727 | </tr> | |
f527e53f | 5728 | |
578f23c8 SS |
5729 | <tr> |
5730 | <td colspan='3'> </td> | |
5731 | <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> | |
5732 | </tr> | |
5733 | </table> | |
f527e53f | 5734 | |
578f23c8 SS |
5735 | <br> |
5736 | ||
5737 | <table border='0' width='100%'> | |
5738 | <tr> | |
5739 | <td colspan='4'><b>$Lang::tr{'ovpn dh parameters'}</b></td> | |
5740 | </tr> | |
5741 | ||
5742 | <tr> | |
5743 | <td width='40%'>$Lang::tr{'ovpn dh upload'}:</td> | |
5744 | <td width='30%'><input type='file' name='FH' size='25'> | |
5745 | <td width='30%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload dh key'}'></td> | |
5746 | </tr> | |
5747 | ||
5748 | <tr> | |
5749 | <td width='40%'>$Lang::tr{'ovpn dh new key'}:</td> | |
5750 | <td colspan='2' width='60%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
5751 | </tr> | |
5752 | </table> | |
5753 | </form> | |
f527e53f | 5754 | |
578f23c8 | 5755 | <br><hr> |
4c962356 EK |
5756 | END |
5757 | ; | |
5758 | ||
5759 | if ( $srunning eq "yes" ) { | |
5760 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' disabled='disabled' /></div></form>\n"; | |
5761 | } else { | |
5762 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></div></form>\n"; | |
5763 | } | |
5764 | &Header::closebox(); | |
5765 | END | |
5766 | ; | |
5767 | ||
5768 | &Header::closepage(); | |
ce9abb66 | 5769 |