]>
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"; | |
d8ef6a95 | 38 | require "${General::swroot}/geoip-functions.pl"; |
6e13d0a5 MT |
39 | |
40 | # enable only the following on debugging purpose | |
8c877a82 AM |
41 | #use warnings; |
42 | #use CGI::Carp 'fatalsToBrowser'; | |
6e13d0a5 | 43 | #workaround to suppress a warning when a variable is used only once |
8c877a82 | 44 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); |
6e13d0a5 MT |
45 | undef (@dummy); |
46 | ||
f2fdd0c1 CS |
47 | my %color = (); |
48 | my %mainsettings = (); | |
49 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
50 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
6e13d0a5 MT |
51 | |
52 | ### | |
53 | ### Initialize variables | |
54 | ### | |
e81be1e1 AM |
55 | my %ccdconfhash=(); |
56 | my %ccdroutehash=(); | |
57 | my %ccdroute2hash=(); | |
6e13d0a5 MT |
58 | my %netsettings=(); |
59 | my %cgiparams=(); | |
60 | my %vpnsettings=(); | |
61 | my %checked=(); | |
62 | my %confighash=(); | |
63 | my %cahash=(); | |
64 | my %selected=(); | |
65 | my $warnmessage = ''; | |
66 | my $errormessage = ''; | |
67 | my %settings=(); | |
54fd0535 | 68 | my $routes_push_file = ''; |
df9b48b7 AM |
69 | my $confighost="${General::swroot}/fwhosts/customhosts"; |
70 | my $configgrp="${General::swroot}/fwhosts/customgroups"; | |
71 | my $customnet="${General::swroot}/fwhosts/customnetworks"; | |
72 | my $name; | |
99bfa85c | 73 | my $col=""; |
ffbe77c8 EK |
74 | my $local_serverconf = "${General::swroot}/ovpn/scripts/server.conf.local"; |
75 | my $local_clientconf = "${General::swroot}/ovpn/scripts/client.conf.local"; | |
76 | ||
6e13d0a5 MT |
77 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
78 | $cgiparams{'ENABLED'} = 'off'; | |
79 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
80 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
81 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
82 | $cgiparams{'NAT'} = 'off'; | |
83 | $cgiparams{'COMPRESSION'} = 'off'; | |
84 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
85 | $cgiparams{'ACTION'} = ''; | |
86 | $cgiparams{'CA_NAME'} = ''; | |
4c962356 EK |
87 | $cgiparams{'DH_NAME'} = 'dh1024.pem'; |
88 | $cgiparams{'DHLENGHT'} = ''; | |
6e13d0a5 MT |
89 | $cgiparams{'DHCP_DOMAIN'} = ''; |
90 | $cgiparams{'DHCP_DNS'} = ''; | |
91 | $cgiparams{'DHCP_WINS'} = ''; | |
54fd0535 | 92 | $cgiparams{'ROUTES_PUSH'} = ''; |
6e13d0a5 | 93 | $cgiparams{'DCOMPLZO'} = 'off'; |
a79fa1d6 | 94 | $cgiparams{'MSSFIX'} = ''; |
8c877a82 | 95 | $cgiparams{'number'} = ''; |
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"; } |
2ee746be | 237 | else |
79e7688b | 238 | { print CONF "tun-mtu $sovpnsettings{'DMTU'}\n"; } |
2ee746be | 239 | |
54fd0535 | 240 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { |
8c877a82 AM |
241 | @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'}); |
242 | foreach (@temp) | |
243 | { | |
244 | @tempovpnsubnet = split("\/",&General::ipcidr2msk($_)); | |
245 | print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n"; | |
246 | } | |
54fd0535 | 247 | } |
8c877a82 AM |
248 | # a.marx ccd |
249 | my %ccdconfhash=(); | |
250 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
251 | foreach my $key (keys %ccdconfhash) { | |
252 | my $a=$ccdconfhash{$key}[1]; | |
253 | my ($b,$c) = split (/\//, $a); | |
254 | print CONF "route $b ".&General::cidrtosub($c)."\n"; | |
255 | } | |
256 | my %ccdroutehash=(); | |
257 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
258 | foreach my $key (keys %ccdroutehash) { | |
259 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
260 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
261 | print CONF "route $a $b\n"; | |
262 | } | |
263 | } | |
264 | # ccd end | |
54fd0535 | 265 | |
8c877a82 | 266 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { |
c6c9630e MT |
267 | print CONF "client-to-client\n"; |
268 | } | |
1de5c945 | 269 | if ($sovpnsettings{MSSFIX} eq 'on') { |
4c962356 | 270 | print CONF "mssfix\n"; |
1de5c945 EK |
271 | } |
272 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { | |
4c962356 | 273 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
a79fa1d6 | 274 | } |
2ee746be | 275 | |
c6c9630e MT |
276 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
277 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
278 | } | |
279 | print CONF "status-version 1\n"; | |
87fe47e9 | 280 | print CONF "status /var/run/ovpnserver.log 30\n"; |
a4fd2325 | 281 | print CONF "ncp-disable\n"; |
c6c9630e | 282 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
49abe7af EK |
283 | if ($sovpnsettings{'DAUTH'} eq '') { |
284 | print CONF ""; | |
285 | } else { | |
286 | print CONF "auth $sovpnsettings{'DAUTH'}\n"; | |
287 | } | |
288 | if ($sovpnsettings{'TLSAUTH'} eq 'on') { | |
4be45949 | 289 | print CONF "tls-auth ${General::swroot}/ovpn/certs/ta.key\n"; |
49abe7af | 290 | } |
c6c9630e MT |
291 | if ($sovpnsettings{DCOMPLZO} eq 'on') { |
292 | print CONF "comp-lzo\n"; | |
293 | } | |
294 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
295 | print CONF "push \"redirect-gateway def1\"\n"; | |
296 | } | |
297 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
298 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
299 | } | |
300 | ||
301 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
302 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
303 | } | |
304 | ||
305 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
306 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
307 | } | |
308 | ||
309 | if ($sovpnsettings{DHCP_WINS} eq '') { | |
310 | print CONF "max-clients 100\n"; | |
a79fa1d6 | 311 | } |
c6c9630e MT |
312 | if ($sovpnsettings{DHCP_WINS} ne '') { |
313 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; | |
314 | } | |
1d0a260a | 315 | print CONF "tls-verify /usr/lib/openvpn/verify\n"; |
c6c9630e MT |
316 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; |
317 | print CONF "user nobody\n"; | |
318 | print CONF "group nobody\n"; | |
319 | print CONF "persist-key\n"; | |
320 | print CONF "persist-tun\n"; | |
321 | if ($sovpnsettings{LOG_VERB} ne '') { | |
322 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
323 | } else { | |
324 | print CONF "verb 3\n"; | |
ffbe77c8 EK |
325 | } |
326 | # Print server.conf.local if entries exist to server.conf | |
327 | if ( !-z $local_serverconf && $sovpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
328 | open (LSC, "$local_serverconf"); | |
329 | print CONF "\n#---------------------------\n"; | |
330 | print CONF "# Start of custom directives\n"; | |
331 | print CONF "# from server.conf.local\n"; | |
332 | print CONF "#---------------------------\n\n"; | |
333 | while (<LSC>) { | |
334 | print CONF $_; | |
335 | } | |
336 | print CONF "\n#-----------------------------\n"; | |
337 | print CONF "# End of custom directives\n"; | |
338 | print CONF "#-----------------------------\n"; | |
339 | close (LSC); | |
340 | } | |
c6c9630e MT |
341 | print CONF "\n"; |
342 | ||
343 | close(CONF); | |
344 | } | |
8c877a82 | 345 | |
c6c9630e | 346 | sub emptyserverlog{ |
87fe47e9 | 347 | if (open(FILE, ">/var/run/ovpnserver.log")) { |
c6c9630e MT |
348 | flock FILE, 2; |
349 | print FILE ""; | |
350 | close FILE; | |
351 | } | |
352 | ||
353 | } | |
354 | ||
8c877a82 AM |
355 | sub delccdnet |
356 | { | |
357 | my %ccdconfhash = (); | |
358 | my %ccdhash = (); | |
359 | my $ccdnetname=$_[0]; | |
360 | if (-f "${General::swroot}/ovpn/ovpnconfig"){ | |
361 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
362 | foreach my $key (keys %ccdhash) { | |
363 | if ($ccdhash{$key}[32] eq $ccdnetname) { | |
364 | $errormessage=$Lang::tr{'ccd err hostinnet'}; | |
365 | return; | |
366 | } | |
367 | } | |
368 | } | |
369 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
370 | foreach my $key (keys %ccdconfhash) { | |
371 | if ($ccdconfhash{$key}[0] eq $ccdnetname){ | |
372 | delete $ccdconfhash{$key}; | |
373 | } | |
374 | } | |
375 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
376 | ||
377 | &writeserverconf; | |
378 | return 0; | |
379 | } | |
380 | ||
381 | sub addccdnet | |
382 | { | |
383 | my %ccdconfhash=(); | |
384 | my @ccdconf=(); | |
385 | my $ccdname=$_[0]; | |
386 | my $ccdnet=$_[1]; | |
8c877a82 AM |
387 | my $subcidr; |
388 | my @ip2=(); | |
389 | my $checkup; | |
390 | my $ccdip; | |
391 | my $baseaddress; | |
290007b3 AM |
392 | |
393 | ||
394 | #check name | |
395 | if ($ccdname eq '') | |
396 | { | |
397 | $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>"; | |
398 | return | |
399 | } | |
400 | ||
401 | if(!&General::validhostname($ccdname)) | |
402 | { | |
8c877a82 AM |
403 | $errormessage=$Lang::tr{'ccd err invalidname'}; |
404 | return; | |
405 | } | |
290007b3 AM |
406 | |
407 | ($ccdip,$subcidr) = split (/\//,$ccdnet); | |
408 | $subcidr=&General::iporsubtocidr($subcidr); | |
409 | #check subnet | |
410 | if ($subcidr > 30) | |
411 | { | |
8c877a82 AM |
412 | $errormessage=$Lang::tr{'ccd err invalidnet'}; |
413 | return; | |
414 | } | |
290007b3 AM |
415 | #check ip |
416 | if (!&General::validipandmask($ccdnet)){ | |
417 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
418 | return; | |
8c877a82 | 419 | } |
290007b3 | 420 | |
e2429e8d | 421 | $errormessage=&General::checksubnets($ccdname,$ccdnet); |
290007b3 | 422 | |
8c877a82 AM |
423 | |
424 | if (!$errormessage) { | |
425 | my %ccdconfhash=(); | |
426 | $baseaddress=&General::getnetworkip($ccdip,$subcidr); | |
427 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
428 | my $key = &General::findhasharraykey (\%ccdconfhash); | |
429 | foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";} | |
430 | $ccdconfhash{$key}[0] = $ccdname; | |
431 | $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr; | |
432 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
433 | &writeserverconf; | |
434 | $cgiparams{'ccdname'}=''; | |
435 | $cgiparams{'ccdsubnet'}=''; | |
436 | return 1; | |
437 | } | |
438 | } | |
439 | ||
440 | sub modccdnet | |
441 | { | |
442 | ||
443 | my $newname=$_[0]; | |
444 | my $oldname=$_[1]; | |
445 | my %ccdconfhash=(); | |
446 | my %ccdhash=(); | |
447 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
448 | foreach my $key (keys %ccdconfhash) { | |
449 | if ($ccdconfhash{$key}[0] eq $oldname) { | |
450 | foreach my $key1 (keys %ccdconfhash) { | |
451 | if ($ccdconfhash{$key1}[0] eq $newname){ | |
452 | $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'}; | |
453 | return; | |
454 | }else{ | |
455 | $ccdconfhash{$key}[0]= $newname; | |
456 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
457 | last; | |
458 | } | |
459 | } | |
460 | } | |
461 | } | |
462 | ||
463 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
464 | foreach my $key (keys %ccdhash) { | |
465 | if ($ccdhash{$key}[32] eq $oldname) { | |
466 | $ccdhash{$key}[32]=$newname; | |
467 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
468 | last; | |
469 | } | |
470 | } | |
471 | ||
472 | return 0; | |
473 | } | |
474 | sub ccdmaxclients | |
475 | { | |
476 | my $ccdnetwork=$_[0]; | |
477 | my @octets=(); | |
478 | my @subnet=(); | |
479 | @octets=split("\/",$ccdnetwork); | |
480 | @subnet= split /\./, &General::cidrtosub($octets[1]); | |
481 | my ($a,$b,$c,$d,$e); | |
482 | $a=256-$subnet[0]; | |
483 | $b=256-$subnet[1]; | |
484 | $c=256-$subnet[2]; | |
485 | $d=256-$subnet[3]; | |
486 | $e=($a*$b*$c*$d)/4; | |
487 | return $e-1; | |
488 | } | |
489 | ||
490 | sub getccdadresses | |
491 | { | |
492 | my $ipin=$_[0]; | |
493 | my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin; | |
494 | my $cidr=$_[1]; | |
495 | chomp($cidr); | |
496 | my $count=$_[2]; | |
497 | my $hasip=$_[3]; | |
498 | chomp($hasip); | |
499 | my @iprange=(); | |
500 | my %ccdhash=(); | |
501 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
d9fe5693 | 502 | $iprange[0]=$ip1.".".$ip2.".".$ip3.".".($ip4+2); |
ac87f371 | 503 | for (my $i=1;$i<=$count;$i++) { |
8c877a82 AM |
504 | my $tmpip=$iprange[$i-1]; |
505 | my $stepper=$i*4; | |
506 | $iprange[$i]= &General::getnextip($tmpip,4); | |
507 | } | |
508 | my $r=0; | |
509 | foreach my $key (keys %ccdhash) { | |
510 | $r=0; | |
511 | foreach my $tmp (@iprange){ | |
512 | my ($net,$sub) = split (/\//,$ccdhash{$key}[33]); | |
513 | if ($net eq $tmp) { | |
514 | if ( $hasip ne $ccdhash{$key}[33] ){ | |
515 | splice (@iprange,$r,1); | |
516 | } | |
517 | } | |
518 | $r++; | |
519 | } | |
520 | } | |
521 | return @iprange; | |
522 | } | |
523 | ||
524 | sub fillselectbox | |
525 | { | |
526 | my $boxname=$_[1]; | |
527 | my ($ccdip,$subcidr) = split("/",$_[0]); | |
528 | my $tz=$_[2]; | |
529 | my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz); | |
530 | print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >"; | |
531 | foreach (@allccdips) { | |
532 | my $ip=$_."/30"; | |
533 | chomp($ip); | |
534 | print "<option value='$ip' "; | |
535 | if ( $ip eq $cgiparams{$boxname} ){ | |
536 | print"selected"; | |
537 | } | |
538 | print ">$ip</option>"; | |
539 | } | |
540 | print "</select>"; | |
541 | } | |
542 | ||
543 | sub hostsinnet | |
544 | { | |
545 | my $name=$_[0]; | |
546 | my %ccdhash=(); | |
547 | my $i=0; | |
548 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
549 | foreach my $key (keys %ccdhash) { | |
550 | if ($ccdhash{$key}[32] eq $name){ $i++;} | |
551 | } | |
552 | return $i; | |
553 | } | |
554 | ||
555 | sub check_routes_push | |
556 | { | |
557 | my $val=$_[0]; | |
558 | my ($ip,$cidr) = split (/\//, $val); | |
559 | ##check for existing routes in routes_push | |
560 | if (-e "${General::swroot}/ovpn/routes_push") { | |
561 | open(FILE,"${General::swroot}/ovpn/routes_push"); | |
562 | while (<FILE>) { | |
563 | $_=~s/\s*$//g; | |
564 | ||
565 | my ($ip2,$cidr2) = split (/\//,"$_"); | |
566 | my $val2=$ip2."/".&General::iporsubtodec($cidr2); | |
567 | ||
568 | if($val eq $val2){ | |
569 | return 0; | |
570 | } | |
571 | #subnetcheck | |
572 | if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){ | |
573 | return 0; | |
574 | } | |
575 | }; | |
576 | close(FILE); | |
577 | } | |
578 | return 1; | |
579 | } | |
580 | ||
581 | sub check_ccdroute | |
582 | { | |
583 | my %ccdroutehash=(); | |
584 | my $val=$_[0]; | |
585 | my ($ip,$cidr) = split (/\//, $val); | |
586 | #check for existing routes in ccdroute | |
587 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
588 | foreach my $key (keys %ccdroutehash) { | |
589 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
590 | if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){ | |
591 | return 0; | |
592 | } | |
593 | my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]); | |
594 | #subnetcheck | |
595 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){ | |
596 | return 0; | |
597 | } | |
598 | } | |
599 | } | |
600 | return 1; | |
601 | } | |
602 | sub check_ccdconf | |
603 | { | |
604 | my %ccdconfhash=(); | |
605 | my $val=$_[0]; | |
606 | my ($ip,$cidr) = split (/\//, $val); | |
607 | #check for existing routes in ccdroute | |
608 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
609 | foreach my $key (keys %ccdconfhash) { | |
610 | if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){ | |
611 | return 0; | |
612 | } | |
613 | my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]); | |
614 | #subnetcheck | |
615 | if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){ | |
616 | return 0; | |
617 | } | |
618 | ||
619 | } | |
620 | return 1; | |
621 | } | |
622 | ||
7c1d9faf AH |
623 | ### |
624 | # m.a.d net2net | |
625 | ### | |
626 | ||
627 | sub validdotmask | |
628 | { | |
629 | my $ipdotmask = $_[0]; | |
630 | if (&General::validip($ipdotmask)) { return 0; } | |
631 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
632 | my $mask = $2; | |
633 | if (($mask =~ /\./ )) { return 0; } | |
634 | return 1; | |
635 | } | |
54fd0535 MT |
636 | |
637 | # ------------------------------------------------------------------- | |
638 | ||
639 | sub write_routepushfile | |
640 | { | |
641 | open(FILE, ">$routes_push_file"); | |
642 | flock(FILE, 2); | |
643 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
644 | print FILE $vpnsettings{'ROUTES_PUSH'}; | |
645 | } | |
646 | close(FILE); | |
647 | } | |
648 | ||
649 | sub read_routepushfile | |
650 | { | |
651 | if (-e "$routes_push_file") { | |
652 | open(FILE,"$routes_push_file"); | |
653 | delete $vpnsettings{'ROUTES_PUSH'}; | |
654 | while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ }; | |
655 | close(FILE); | |
656 | $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 | 657 | |
54fd0535 MT |
658 | } |
659 | } | |
7c1d9faf | 660 | |
775b4494 AM |
661 | sub writecollectdconf { |
662 | my $vpncollectd; | |
663 | my %ccdhash=(); | |
664 | ||
665 | open(COLLECTDVPN, ">${General::swroot}/ovpn/collectd.vpn") or die "Unable to open collectd.vpn: $!"; | |
666 | print COLLECTDVPN "Loadplugin openvpn\n"; | |
667 | print COLLECTDVPN "\n"; | |
668 | print COLLECTDVPN "<Plugin openvpn>\n"; | |
669 | print COLLECTDVPN "Statusfile \"/var/run/ovpnserver.log\"\n"; | |
670 | ||
671 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
672 | foreach my $key (keys %ccdhash) { | |
673 | if ($ccdhash{$key}[0] eq 'on' && $ccdhash{$key}[3] eq 'net') { | |
674 | print COLLECTDVPN "Statusfile \"/var/run/openvpn/$ccdhash{$key}[1]-n2n\"\n"; | |
675 | } | |
676 | } | |
677 | ||
678 | print COLLECTDVPN "</Plugin>\n"; | |
679 | close(COLLECTDVPN); | |
680 | ||
681 | # Reload collectd afterwards | |
682 | system("/usr/local/bin/collectdctrl restart &>/dev/null"); | |
683 | } | |
7c1d9faf | 684 | |
c6c9630e MT |
685 | #hier die refresh page |
686 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
687 | my $refresh = ''; | |
688 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
689 | &Header::showhttpheaders(); | |
690 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
691 | &Header::openbigbox('100%', 'center'); | |
692 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
693 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
694 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
695 | &Header::closebox(); | |
696 | &Header::closebigbox(); | |
697 | &Header::closepage(); | |
698 | exit (0); | |
699 | } | |
700 | ##hier die refresh page | |
701 | ||
6e13d0a5 MT |
702 | |
703 | ### | |
704 | ### OpenVPN Server Control | |
705 | ### | |
706 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
707 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
708 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
709 | #start openvpn server |
710 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 711 | &emptyserverlog(); |
6e13d0a5 MT |
712 | system('/usr/local/bin/openvpnctrl', '-s'); |
713 | } | |
714 | #stop openvpn server | |
715 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
6e13d0a5 | 716 | system('/usr/local/bin/openvpnctrl', '-k'); |
c6c9630e | 717 | &emptyserverlog(); |
6e13d0a5 MT |
718 | } |
719 | # #restart openvpn server | |
8c877a82 | 720 | # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ |
6e13d0a5 | 721 | #workarund, till SIGHUP also works when running as nobody |
8c877a82 AM |
722 | # system('/usr/local/bin/openvpnctrl', '-r'); |
723 | # &emptyserverlog(); | |
724 | # } | |
6e13d0a5 MT |
725 | } |
726 | ||
727 | ### | |
728 | ### Save Advanced options | |
729 | ### | |
730 | ||
731 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
732 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
733 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
734 | #DAN this value has to leave. | |
735 | #new settings for daemon | |
736 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
737 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
738 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
739 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
740 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
741 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
ffbe77c8 | 742 | $vpnsettings{'ADDITIONAL_CONFIGS'} = $cgiparams{'ADDITIONAL_CONFIGS'}; |
6e13d0a5 MT |
743 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; |
744 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
745 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
54fd0535 | 746 | $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'}; |
4c962356 | 747 | $vpnsettings{'DAUTH'} = $cgiparams{'DAUTH'}; |
49abe7af | 748 | $vpnsettings{'TLSAUTH'} = $cgiparams{'TLSAUTH'}; |
54fd0535 | 749 | my @temp=(); |
6e13d0a5 | 750 | |
a79fa1d6 JPT |
751 | if ($cgiparams{'FRAGMENT'} eq '') { |
752 | delete $vpnsettings{'FRAGMENT'}; | |
753 | } else { | |
754 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
755 | $errormessage = "Incorrect value, please insert only numbers."; | |
756 | goto ADV_ERROR; | |
757 | } else { | |
758 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
759 | } | |
760 | } | |
49abe7af | 761 | |
a79fa1d6 | 762 | if ($cgiparams{'MSSFIX'} ne 'on') { |
1de5c945 | 763 | delete $vpnsettings{'MSSFIX'}; |
a79fa1d6 JPT |
764 | } else { |
765 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
766 | } | |
2ee746be | 767 | |
6e13d0a5 | 768 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
81da1b01 | 769 | unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { |
6e13d0a5 MT |
770 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; |
771 | goto ADV_ERROR; | |
772 | } | |
773 | } | |
774 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
775 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
776 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
777 | goto ADV_ERROR; | |
778 | } | |
779 | } | |
780 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
781 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
782 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
54fd0535 MT |
783 | goto ADV_ERROR; |
784 | } | |
785 | } | |
786 | if ($cgiparams{'ROUTES_PUSH'} ne ''){ | |
787 | @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'}); | |
788 | undef $vpnsettings{'ROUTES_PUSH'}; | |
8c877a82 AM |
789 | |
790 | foreach my $tmpip (@temp) | |
54fd0535 MT |
791 | { |
792 | s/^\s+//g; s/\s+$//g; | |
8c877a82 AM |
793 | |
794 | if ($tmpip) | |
54fd0535 | 795 | { |
8c877a82 AM |
796 | $tmpip=~s/\s*$//g; |
797 | unless (&General::validipandmask($tmpip)) { | |
798 | $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'}; | |
799 | goto ADV_ERROR; | |
54fd0535 | 800 | } |
8c877a82 AM |
801 | my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip)); |
802 | ||
54fd0535 MT |
803 | if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) { |
804 | $errormessage = $Lang::tr{'ovpn errmsg green already pushed'}; | |
8c877a82 AM |
805 | goto ADV_ERROR; |
806 | } | |
807 | # a.marx ccd | |
808 | my %ccdroutehash=(); | |
809 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
810 | foreach my $key (keys %ccdroutehash) { | |
811 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
812 | if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){ | |
813 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
814 | goto ADV_ERROR; | |
815 | } | |
816 | my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]); | |
817 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)){ | |
818 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
819 | goto ADV_ERROR; | |
820 | } | |
821 | } | |
54fd0535 | 822 | } |
8c877a82 AM |
823 | |
824 | # ccd end | |
825 | ||
826 | $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n"; | |
54fd0535 | 827 | } |
8c877a82 AM |
828 | } |
829 | &write_routepushfile; | |
54fd0535 | 830 | undef $vpnsettings{'ROUTES_PUSH'}; |
8e148dc3 NP |
831 | } |
832 | else { | |
833 | undef $vpnsettings{'ROUTES_PUSH'}; | |
834 | &write_routepushfile; | |
6e13d0a5 | 835 | } |
6e13d0a5 MT |
836 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) { |
837 | $errormessage = $Lang::tr{'invalid input for max clients'}; | |
838 | goto ADV_ERROR; | |
839 | } | |
840 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
841 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
842 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
843 | goto ADV_ERROR; | |
844 | } | |
845 | } | |
846 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
847 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
848 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
849 | goto ADV_ERROR; | |
850 | } | |
851 | } | |
852 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
853 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
854 | goto ADV_ERROR; | |
855 | } | |
4be45949 EK |
856 | # Create ta.key for tls-auth if not presant |
857 | if ($cgiparams{'TLSAUTH'} eq 'on') { | |
858 | if ( ! -e "${General::swroot}/ovpn/certs/ta.key") { | |
859 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/certs/ta.key"); | |
860 | if ($?) { | |
861 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
862 | goto ADV_ERROR; | |
863 | } | |
864 | } | |
865 | } | |
6e13d0a5 MT |
866 | |
867 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 868 | &writeserverconf();#hier ok |
6e13d0a5 MT |
869 | } |
870 | ||
ce9abb66 | 871 | ### |
7c1d9faf | 872 | # m.a.d net2net |
ce9abb66 AH |
873 | ### |
874 | ||
875 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
876 | { | |
c6c9630e | 877 | |
ce9abb66 AH |
878 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
879 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
54fd0535 | 880 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
d96c89eb | 881 | my $tunmtu = ''; |
531f0835 AH |
882 | |
883 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
884 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
885 | |
886 | 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: $!"; | |
887 | ||
888 | flock SERVERCONF, 2; | |
7c1d9faf | 889 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
ce9abb66 | 890 | print SERVERCONF "\n"; |
b278daf3 | 891 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
892 | print SERVERCONF "user nobody\n"; |
893 | print SERVERCONF "group nobody\n"; | |
894 | print SERVERCONF "persist-tun\n"; | |
895 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 896 | print SERVERCONF "script-security 2\n"; |
60f396d7 | 897 | print SERVERCONF "# IP/DNS for remote Server Gateway\n"; |
c125d8a2 SS |
898 | |
899 | if ($cgiparams{'REMOTE'} ne '') { | |
ce9abb66 | 900 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
c125d8a2 SS |
901 | } |
902 | ||
b278daf3 | 903 | print SERVERCONF "float\n"; |
60f396d7 | 904 | print SERVERCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 905 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; |
60f396d7 | 906 | print SERVERCONF "# Client Gateway Network\n"; |
54fd0535 | 907 | print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n"; |
2913185a | 908 | print SERVERCONF "up \"/etc/init.d/static-routes start\"\n"; |
60f396d7 | 909 | print SERVERCONF "# tun Device\n"; |
ce9abb66 | 910 | print SERVERCONF "dev tun\n"; |
5795fc1b AM |
911 | print SERVERCONF "#Logfile for statistics\n"; |
912 | print SERVERCONF "status-version 1\n"; | |
87fe47e9 | 913 | print SERVERCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; |
60f396d7 | 914 | print SERVERCONF "# Port and Protokol\n"; |
ce9abb66 | 915 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; |
5795fc1b | 916 | |
60f396d7 AH |
917 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { |
918 | print SERVERCONF "proto tcp-server\n"; | |
919 | print SERVERCONF "# Packet size\n"; | |
d96c89eb | 920 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 921 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 922 | } |
60f396d7 AH |
923 | |
924 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
925 | print SERVERCONF "proto udp\n"; | |
926 | print SERVERCONF "# Paketsize\n"; | |
927 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
928 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
929 | if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
930 | if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; }; | |
d96c89eb | 931 | } |
1647059d | 932 | |
60f396d7 | 933 | print SERVERCONF "# Auth. Server\n"; |
ce9abb66 AH |
934 | print SERVERCONF "tls-server\n"; |
935 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
936 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
937 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
49abe7af | 938 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}\n"; |
b278daf3 | 939 | print SERVERCONF "# Cipher\n"; |
4c962356 | 940 | print SERVERCONF "cipher $cgiparams{'DCIPHER'}\n"; |
52f61e49 EKD |
941 | |
942 | # If GCM cipher is used, do not use --auth | |
943 | if (($cgiparams{'DCIPHER'} eq 'AES-256-GCM') || | |
944 | ($cgiparams{'DCIPHER'} eq 'AES-192-GCM') || | |
945 | ($cgiparams{'DCIPHER'} eq 'AES-128-GCM')) { | |
946 | print SERVERCONF unless "# HMAC algorithm\n"; | |
947 | print SERVERCONF unless "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 948 | } else { |
52f61e49 EKD |
949 | print SERVERCONF "# HMAC algorithm\n"; |
950 | print SERVERCONF "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 951 | } |
52f61e49 | 952 | |
ce9abb66 | 953 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 954 | print SERVERCONF "# Enable Compression\n"; |
66298ef2 | 955 | print SERVERCONF "comp-lzo\n"; |
b278daf3 | 956 | } |
60f396d7 | 957 | print SERVERCONF "# Debug Level\n"; |
ce9abb66 | 958 | print SERVERCONF "verb 3\n"; |
b278daf3 | 959 | print SERVERCONF "# Tunnel check\n"; |
ce9abb66 | 960 | print SERVERCONF "keepalive 10 60\n"; |
60f396d7 | 961 | print SERVERCONF "# Start as daemon\n"; |
ce9abb66 AH |
962 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; |
963 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 964 | print SERVERCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
965 | if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
966 | else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 AH |
967 | close(SERVERCONF); |
968 | ||
969 | } | |
970 | ||
971 | ### | |
7c1d9faf | 972 | # m.a.d net2net |
ce9abb66 | 973 | ### |
7c1d9faf | 974 | |
ce9abb66 AH |
975 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
976 | { | |
4c962356 | 977 | |
ce9abb66 | 978 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); |
54fd0535 | 979 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 980 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
d96c89eb | 981 | my $tunmtu = ''; |
54fd0535 | 982 | |
531f0835 AH |
983 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
984 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
985 | |
986 | 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: $!"; | |
987 | ||
988 | flock CLIENTCONF, 2; | |
7c1d9faf | 989 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 990 | print CLIENTCONF "#\n"; |
b278daf3 | 991 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
992 | print CLIENTCONF "user nobody\n"; |
993 | print CLIENTCONF "group nobody\n"; | |
994 | print CLIENTCONF "persist-tun\n"; | |
995 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 996 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 997 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
ce9abb66 | 998 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 | 999 | print CLIENTCONF "float\n"; |
60f396d7 | 1000 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 1001 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
60f396d7 | 1002 | print CLIENTCONF "# Server Gateway Network\n"; |
54fd0535 | 1003 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
2913185a | 1004 | print CLIENTCONF "up \"/etc/init.d/static-routes start\"\n"; |
60f396d7 | 1005 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 1006 | print CLIENTCONF "dev tun\n"; |
35a21a25 AM |
1007 | print CLIENTCONF "#Logfile for statistics\n"; |
1008 | print CLIENTCONF "status-version 1\n"; | |
1009 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
60f396d7 | 1010 | print CLIENTCONF "# Port and Protokol\n"; |
ce9abb66 | 1011 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; |
60f396d7 AH |
1012 | |
1013 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
1014 | print CLIENTCONF "proto tcp-client\n"; | |
1015 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 1016 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 1017 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 1018 | } |
60f396d7 AH |
1019 | |
1020 | if ($cgiparams{'PROTOCOL'} eq 'udp') { | |
1021 | print CLIENTCONF "proto udp\n"; | |
1022 | print CLIENTCONF "# Paketsize\n"; | |
1023 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1024 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 MT |
1025 | if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
1026 | if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; }; | |
d96c89eb | 1027 | } |
1647059d | 1028 | |
b66b02ab EK |
1029 | # Check host certificate if X509 is RFC3280 compliant. |
1030 | # If not, old --ns-cert-type directive will be used. | |
1031 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
1032 | my $hostcert = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1033 | if ($hostcert !~ /TLS Web Server Authentication/) { | |
1034 | print CLIENTCONF "ns-cert-type server\n"; | |
1035 | } else { | |
1036 | print CLIENTCONF "remote-cert-tls server\n"; | |
1037 | } | |
ce9abb66 AH |
1038 | print CLIENTCONF "# Auth. Client\n"; |
1039 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 1040 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 1041 | print CLIENTCONF "cipher $cgiparams{'DCIPHER'}\n"; |
ce9abb66 | 1042 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; |
52f61e49 EKD |
1043 | |
1044 | # If GCM cipher is used, do not use --auth | |
1045 | if (($cgiparams{'DCIPHER'} eq 'AES-256-GCM') || | |
1046 | ($cgiparams{'DCIPHER'} eq 'AES-192-GCM') || | |
1047 | ($cgiparams{'DCIPHER'} eq 'AES-128-GCM')) { | |
1048 | print CLIENTCONF unless "# HMAC algorithm\n"; | |
1049 | print CLIENTCONF unless "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1050 | } else { |
52f61e49 EKD |
1051 | print CLIENTCONF "# HMAC algorithm\n"; |
1052 | print CLIENTCONF "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1053 | } |
52f61e49 | 1054 | |
ce9abb66 | 1055 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1056 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 1057 | print CLIENTCONF "comp-lzo\n"; |
4c962356 | 1058 | } |
ce9abb66 AH |
1059 | print CLIENTCONF "# Debug Level\n"; |
1060 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 1061 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 1062 | print CLIENTCONF "keepalive 10 60\n"; |
60f396d7 | 1063 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
1064 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
1065 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
60f396d7 | 1066 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
1067 | if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1068 | else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 | 1069 | close(CLIENTCONF); |
c6c9630e | 1070 | |
ce9abb66 AH |
1071 | } |
1072 | ||
6e13d0a5 MT |
1073 | ### |
1074 | ### Save main settings | |
1075 | ### | |
ce9abb66 | 1076 | |
6e13d0a5 MT |
1077 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
1078 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
1079 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
1080 | #DAN this value has to leave. | |
1081 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1082 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
1083 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 1084 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1085 | } |
1086 | } | |
f7fb5bc5 | 1087 | |
6e13d0a5 | 1088 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { |
c6c9630e | 1089 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
4c962356 | 1090 | goto SETTINGS_ERROR; |
c6c9630e MT |
1091 | } |
1092 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
1093 | ||
1094 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
1095 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1096 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
1097 | goto SETTINGS_ERROR; | |
1098 | } | |
1099 | ||
1100 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
1101 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1102 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
1103 | goto SETTINGS_ERROR; | |
1104 | } | |
1105 | ||
1106 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
1107 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1108 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
1109 | goto SETTINGS_ERROR; | |
1110 | } | |
1111 | ||
1112 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
1113 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1114 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
1115 | goto SETTINGS_ERROR; | |
1116 | } | |
1117 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
1118 | while (<ALIASES>) | |
1119 | { | |
1120 | chomp($_); | |
1121 | my @tempalias = split(/\,/,$_); | |
1122 | if ($tempalias[1] eq 'on') { | |
1123 | if (&General::IpInSubnet ($tempalias[0] , | |
1124 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
1125 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
1126 | } | |
1127 | } | |
1128 | } | |
1129 | close(ALIASES); | |
6e13d0a5 | 1130 | if ($errormessage ne ''){ |
c6c9630e | 1131 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1132 | } |
1133 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
1134 | $errormessage = $Lang::tr{'invalid input'}; | |
1135 | goto SETTINGS_ERROR; | |
1136 | } | |
1137 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
1138 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
1139 | goto SETTINGS_ERROR; | |
1140 | } | |
1141 | ||
1142 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
c6c9630e MT |
1143 | $errormessage = $Lang::tr{'invalid port'}; |
1144 | goto SETTINGS_ERROR; | |
6e13d0a5 | 1145 | } |
8c252e6a | 1146 | |
6e13d0a5 MT |
1147 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
1148 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
1149 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
1150 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
1151 | #new settings for daemon | |
1152 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
6e13d0a5 MT |
1153 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; |
1154 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
1155 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
1156 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
1157 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
3ffee04b CS |
1158 | #wrtie enable |
1159 | ||
1160 | 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");} | |
1161 | 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");} | |
1162 | 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 |
1163 | #new settings for daemon |
1164 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 1165 | &writeserverconf();#hier ok |
6e13d0a5 MT |
1166 | SETTINGS_ERROR: |
1167 | ### | |
1168 | ### Reset all step 2 | |
1169 | ### | |
4c962356 | 1170 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') { |
6e13d0a5 MT |
1171 | my $file = ''; |
1172 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1173 | ||
1e499e90 MT |
1174 | # Kill all N2N connections |
1175 | system("/usr/local/bin/openvpnctrl -kn2n &>/dev/null"); | |
1176 | ||
6e13d0a5 | 1177 | foreach my $key (keys %confighash) { |
2f36a7b4 MT |
1178 | my $name = $confighash{$cgiparams{'$key'}}[1]; |
1179 | ||
c6c9630e MT |
1180 | if ($confighash{$key}[4] eq 'cert') { |
1181 | delete $confighash{$cgiparams{'$key'}}; | |
1182 | } | |
2f36a7b4 MT |
1183 | |
1184 | system ("/usr/local/bin/openvpnctrl -drrd $name"); | |
6e13d0a5 MT |
1185 | } |
1186 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
49abe7af | 1187 | unlink $file; |
6e13d0a5 MT |
1188 | } |
1189 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
49abe7af | 1190 | unlink $file; |
6e13d0a5 MT |
1191 | } |
1192 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
49abe7af | 1193 | unlink $file; |
6e13d0a5 | 1194 | } |
4c962356 | 1195 | &cleanssldatabase(); |
6e13d0a5 MT |
1196 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
1197 | print FILE ""; | |
1198 | close FILE; | |
1199 | } | |
49abe7af EK |
1200 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute")) { |
1201 | print FILE ""; | |
1202 | close FILE; | |
1203 | } | |
1204 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute2")) { | |
1205 | print FILE ""; | |
1206 | close FILE; | |
1207 | } | |
1208 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { | |
1209 | unlink $file | |
1210 | } | |
5795fc1b AM |
1211 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { |
1212 | unlink $file | |
1213 | } | |
49abe7af EK |
1214 | if (open(FILE, ">${General::swroot}/ovpn/ovpn-leases.db")) { |
1215 | print FILE ""; | |
1216 | close FILE; | |
1217 | } | |
1218 | if (open(FILE, ">${General::swroot}/ovpn/ovpnconfig")) { | |
1219 | print FILE ""; | |
1220 | close FILE; | |
1221 | } | |
1222 | while ($file = glob("${General::swroot}/ovpn/n2nconf/*")) { | |
1223 | system ("rm -rf $file"); | |
1224 | } | |
1225 | ||
2f36a7b4 MT |
1226 | # Remove everything from the collectd configuration |
1227 | &writecollectdconf(); | |
1228 | ||
c6c9630e | 1229 | #&writeserverconf(); |
6e13d0a5 MT |
1230 | ### |
1231 | ### Reset all step 1 | |
1232 | ### | |
4c962356 | 1233 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) { |
6e13d0a5 | 1234 | &Header::showhttpheaders(); |
4c962356 EK |
1235 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
1236 | &Header::openbigbox('100%', 'left', '', ''); | |
1237 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
1238 | print <<END; | |
1239 | <form method='post'> | |
1240 | <table width='100%'> | |
1241 | <tr> | |
1242 | <td align='center'> | |
1243 | <input type='hidden' name='AREUSURE' value='yes' /> | |
49abe7af | 1244 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: |
4c962356 EK |
1245 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td> |
1246 | </tr> | |
1247 | <tr> | |
1248 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /> | |
1249 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> | |
1250 | </tr> | |
1251 | </table> | |
1252 | </form> | |
6e13d0a5 MT |
1253 | END |
1254 | ; | |
1255 | &Header::closebox(); | |
1256 | &Header::closebigbox(); | |
1257 | &Header::closepage(); | |
1258 | exit (0); | |
1259 | ||
4c962356 EK |
1260 | ### |
1261 | ### Generate DH key step 2 | |
1262 | ### | |
1263 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
49abe7af | 1264 | # Delete if old key exists |
4c962356 EK |
1265 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { |
1266 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1267 | } | |
1268 | # Create Diffie Hellmann Parameter | |
badd8c1c | 1269 | system('/usr/bin/openssl', 'dhparam', '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
4c962356 EK |
1270 | if ($?) { |
1271 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1272 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
1273 | } | |
1274 | ||
1275 | ### | |
1276 | ### Generate DH key step 1 | |
1277 | ### | |
1278 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate dh key'}) { | |
1279 | &Header::showhttpheaders(); | |
1280 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
1281 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1282 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'gen dh'}:"); | |
1283 | print <<END; | |
1284 | <table width='100%'> | |
1285 | <tr> | |
f527e53f | 1286 | <td width='20%'> </td> <td width='15%'></td> <td width='65%'></td> |
49abe7af | 1287 | </tr> |
4c962356 EK |
1288 | <tr> |
1289 | <td class='base'>$Lang::tr{'ovpn dh'}:</td> | |
1290 | <td align='center'> | |
1291 | <form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
1292 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1293 | <select name='DHLENGHT'> | |
4c962356 EK |
1294 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> |
1295 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
1296 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
1297 | </select> | |
1298 | </td> | |
1299 | </tr> | |
1300 | <tr><td colspan='4'><br></td></tr> | |
1301 | </table> | |
1302 | <table width='100%'> | |
1303 | <tr> | |
49abe7af | 1304 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'dh key warn'} |
4c962356 | 1305 | </tr> |
49abe7af EK |
1306 | <tr> |
1307 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
1308 | </tr> | |
1309 | <tr><td colspan='2'><br></td></tr> | |
4c962356 EK |
1310 | <tr> |
1311 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
1312 | </form> | |
1313 | </tr> | |
1314 | </table> | |
1315 | ||
1316 | END | |
1317 | ; | |
1318 | &Header::closebox(); | |
1319 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1320 | &Header::closebigbox(); | |
1321 | &Header::closepage(); | |
1322 | exit (0); | |
1323 | ||
1324 | ### | |
1325 | ### Upload DH key | |
1326 | ### | |
1327 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload dh key'}) { | |
4c962356 EK |
1328 | if (ref ($cgiparams{'FH'}) ne 'Fh') { |
1329 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1330 | goto UPLOADCA_ERROR; | |
1331 | } | |
49abe7af | 1332 | # Move uploaded dh key to a temporary file |
4c962356 EK |
1333 | (my $fh, my $filename) = tempfile( ); |
1334 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1335 | $errormessage = $!; | |
49abe7af | 1336 | goto UPLOADCA_ERROR; |
4c962356 | 1337 | } |
49abe7af | 1338 | my $temp = `/usr/bin/openssl dhparam -text -in $filename`; |
4c962356 EK |
1339 | if ($temp !~ /DH Parameters: \((1024|2048|3072|4096) bit\)/) { |
1340 | $errormessage = $Lang::tr{'not a valid dh key'}; | |
1341 | unlink ($filename); | |
1342 | goto UPLOADCA_ERROR; | |
1343 | } else { | |
1344 | # Delete if old key exists | |
1345 | if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") { | |
1346 | unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"; | |
1347 | } | |
1348 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}"); | |
49abe7af EK |
1349 | if ($? ne 0) { |
1350 | $errormessage = "$Lang::tr{'dh key move failed'}: $!"; | |
1351 | unlink ($filename); | |
1352 | goto UPLOADCA_ERROR; | |
1353 | } | |
4c962356 EK |
1354 | } |
1355 | ||
6e13d0a5 MT |
1356 | ### |
1357 | ### Upload CA Certificate | |
1358 | ### | |
1359 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
1360 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1361 | ||
1362 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
1363 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1364 | goto UPLOADCA_ERROR; | |
1365 | } | |
1366 | ||
1367 | if (length($cgiparams{'CA_NAME'}) >60) { | |
1368 | $errormessage = $Lang::tr{'name too long'}; | |
1369 | goto VPNCONF_ERROR; | |
1370 | } | |
1371 | ||
1372 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
1373 | $errormessage = $Lang::tr{'name is invalid'}; | |
4c962356 | 1374 | goto UPLOADCA_ERROR; |
6e13d0a5 MT |
1375 | } |
1376 | ||
1377 | # Check if there is no other entry with this name | |
1378 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
1379 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
1380 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
1381 | goto UPLOADCA_ERROR; | |
1382 | } | |
6e13d0a5 MT |
1383 | } |
1384 | ||
1385 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
c6c9630e MT |
1386 | $errormessage = $Lang::tr{'there was no file upload'}; |
1387 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1388 | } |
1389 | # Move uploaded ca to a temporary file | |
1390 | (my $fh, my $filename) = tempfile( ); | |
1391 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
1392 | $errormessage = $!; |
1393 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1394 | } |
1395 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; | |
c6c9630e MT |
1396 | if ($temp !~ /CA:TRUE/i) { |
1397 | $errormessage = $Lang::tr{'not a valid ca certificate'}; | |
1398 | unlink ($filename); | |
1399 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1400 | } else { |
c6c9630e MT |
1401 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
1402 | if ($? ne 0) { | |
1403 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1404 | unlink ($filename); | |
1405 | goto UPLOADCA_ERROR; | |
1406 | } | |
6e13d0a5 MT |
1407 | } |
1408 | ||
1409 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`; | |
1410 | $casubject =~ /Subject: (.*)[\n]/; | |
1411 | $casubject = $1; | |
1412 | $casubject =~ s+/Email+, E+; | |
1413 | $casubject =~ s/ ST=/ S=/; | |
1414 | $casubject = &Header::cleanhtml($casubject); | |
1415 | ||
1416 | my $key = &General::findhasharraykey (\%cahash); | |
1417 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
1418 | $cahash{$key}[1] = $casubject; | |
1419 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
1420 | # system('/usr/local/bin/ipsecctrl', 'R'); |
1421 | ||
6e13d0a5 MT |
1422 | UPLOADCA_ERROR: |
1423 | ||
1424 | ### | |
1425 | ### Display ca certificate | |
1426 | ### | |
1427 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
1428 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
1429 | ||
1430 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
1431 | &Header::showhttpheaders(); | |
4c962356 | 1432 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1433 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1434 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
1435 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1436 | $output = &Header::cleanhtml($output,"y"); | |
1437 | print "<pre>$output</pre>\n"; | |
1438 | &Header::closebox(); | |
1439 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1440 | &Header::closebigbox(); | |
1441 | &Header::closepage(); | |
1442 | exit(0); | |
1443 | } else { | |
1444 | $errormessage = $Lang::tr{'invalid key'}; | |
1445 | } | |
1446 | ||
6e13d0a5 MT |
1447 | ### |
1448 | ### Download ca certificate | |
1449 | ### | |
1450 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
1451 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1452 | ||
1453 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1454 | print "Content-Type: application/octet-stream\r\n"; | |
1455 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
1456 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
1457 | exit(0); | |
1458 | } else { | |
1459 | $errormessage = $Lang::tr{'invalid key'}; | |
1460 | } | |
1461 | ||
1462 | ### | |
1463 | ### Remove ca certificate (step 2) | |
1464 | ### | |
1465 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1466 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1467 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1468 | ||
1469 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1470 | foreach my $key (keys %confighash) { | |
1471 | 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`; | |
1472 | if ($test =~ /: OK/) { | |
c6c9630e MT |
1473 | # Delete connection |
1474 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1475 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1476 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
1477 | # } | |
6e13d0a5 MT |
1478 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
1479 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
1480 | delete $confighash{$key}; | |
1481 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 1482 | # &writeipsecfiles(); |
6e13d0a5 MT |
1483 | } |
1484 | } | |
1485 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1486 | delete $cahash{$cgiparams{'KEY'}}; | |
1487 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 1488 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
1489 | } else { |
1490 | $errormessage = $Lang::tr{'invalid key'}; | |
1491 | } | |
1492 | ### | |
1493 | ### Remove ca certificate (step 1) | |
1494 | ### | |
1495 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
1496 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1497 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1498 | ||
1499 | my $assignedcerts = 0; | |
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/) { | |
1504 | $assignedcerts++; | |
1505 | } | |
1506 | } | |
1507 | if ($assignedcerts) { | |
1508 | &Header::showhttpheaders(); | |
4c962356 | 1509 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1510 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1511 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
4c962356 | 1512 | print <<END; |
6e13d0a5 MT |
1513 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> |
1514 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1515 | <tr><td align='center'> | |
1516 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1517 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1518 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1519 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1520 | </form></table> | |
1521 | END | |
1522 | ; | |
1523 | &Header::closebox(); | |
1524 | &Header::closebigbox(); | |
1525 | &Header::closepage(); | |
1526 | exit (0); | |
1527 | } else { | |
1528 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1529 | delete $cahash{$cgiparams{'KEY'}}; | |
1530 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1531 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1532 | } | |
1533 | } else { | |
1534 | $errormessage = $Lang::tr{'invalid key'}; | |
1535 | } | |
1536 | ||
1537 | ### | |
1538 | ### Display root certificate | |
1539 | ### | |
c6c9630e MT |
1540 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1541 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
1542 | my $output; | |
1543 | &Header::showhttpheaders(); | |
4c962356 | 1544 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1545 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1546 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1547 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
1548 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1549 | } else { | |
1550 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
1551 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1552 | } | |
1553 | $output = &Header::cleanhtml($output,"y"); | |
1554 | print "<pre>$output</pre>\n"; | |
1555 | &Header::closebox(); | |
1556 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1557 | &Header::closebigbox(); | |
1558 | &Header::closepage(); | |
1559 | exit(0); | |
1560 | ||
6e13d0a5 MT |
1561 | ### |
1562 | ### Download root certificate | |
1563 | ### | |
1564 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1565 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1566 | print "Content-Type: application/octet-stream\r\n"; | |
1567 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
1568 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1569 | exit(0); | |
1570 | } | |
1571 | ||
1572 | ### | |
1573 | ### Download host certificate | |
1574 | ### | |
1575 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1576 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1577 | print "Content-Type: application/octet-stream\r\n"; | |
1578 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
1579 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1580 | exit(0); | |
1581 | } | |
f7fb5bc5 | 1582 | |
fd5ccb2d EK |
1583 | ### |
1584 | ### Download tls-auth key | |
1585 | ### | |
1586 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download tls-auth key'}) { | |
1587 | if ( -f "${General::swroot}/ovpn/certs/ta.key" ) { | |
1588 | print "Content-Type: application/octet-stream\r\n"; | |
1589 | print "Content-Disposition: filename=ta.key\r\n\r\n"; | |
1590 | print `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
1591 | exit(0); | |
1592 | } | |
1593 | ||
6e13d0a5 MT |
1594 | ### |
1595 | ### Form for generating a root certificate | |
1596 | ### | |
1597 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1598 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1599 | ||
1600 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1601 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1602 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1603 | $cgiparams{'ACTION'} = ''; | |
1604 | goto ROOTCERT_ERROR; | |
1605 | } | |
1606 | ||
1607 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1608 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1609 | my $ipaddr = <IPADDR>; | |
1610 | close IPADDR; | |
1611 | chomp ($ipaddr); | |
1612 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1613 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1614 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1615 | } | |
1616 | } | |
1617 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1618 | ||
1619 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1620 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1621 | goto ROOTCERT_ERROR; | |
1622 | } | |
1623 | ||
1624 | # Move uploaded certificate request to a temporary file | |
1625 | (my $fh, my $filename) = tempfile( ); | |
1626 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1627 | $errormessage = $!; | |
1628 | goto ROOTCERT_ERROR; | |
1629 | } | |
1630 | ||
1631 | # Create a temporary dirctory | |
1632 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1633 | ||
1634 | # Extract the CA certificate from the file | |
1635 | my $pid = open(OPENSSL, "|-"); | |
1636 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1637 | if ($pid) { # parent | |
1638 | if ($cgiparams{'P12_PASS'} ne '') { | |
1639 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1640 | } | |
1641 | close (OPENSSL); | |
1642 | if ($?) { | |
1643 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1644 | unlink ($filename); | |
1645 | goto ROOTCERT_ERROR; | |
1646 | } | |
1647 | } else { # child | |
1648 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1649 | '-in', $filename, | |
1650 | '-out', "$tempdir/cacert.pem")) { | |
1651 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1652 | unlink ($filename); | |
1653 | goto ROOTCERT_ERROR; | |
1654 | } | |
1655 | } | |
1656 | ||
1657 | # Extract the Host certificate from the file | |
1658 | $pid = open(OPENSSL, "|-"); | |
1659 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1660 | if ($pid) { # parent | |
1661 | if ($cgiparams{'P12_PASS'} ne '') { | |
1662 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1663 | } | |
1664 | close (OPENSSL); | |
1665 | if ($?) { | |
1666 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1667 | unlink ($filename); | |
1668 | goto ROOTCERT_ERROR; | |
1669 | } | |
1670 | } else { # child | |
1671 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1672 | '-in', $filename, | |
1673 | '-out', "$tempdir/hostcert.pem")) { | |
1674 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1675 | unlink ($filename); | |
1676 | goto ROOTCERT_ERROR; | |
1677 | } | |
1678 | } | |
1679 | ||
1680 | # Extract the Host key from the file | |
1681 | $pid = open(OPENSSL, "|-"); | |
1682 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1683 | if ($pid) { # parent | |
1684 | if ($cgiparams{'P12_PASS'} ne '') { | |
1685 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1686 | } | |
1687 | close (OPENSSL); | |
1688 | if ($?) { | |
1689 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1690 | unlink ($filename); | |
1691 | goto ROOTCERT_ERROR; | |
1692 | } | |
1693 | } else { # child | |
1694 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1695 | '-nodes', | |
1696 | '-in', $filename, | |
1697 | '-out', "$tempdir/serverkey.pem")) { | |
1698 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1699 | unlink ($filename); | |
1700 | goto ROOTCERT_ERROR; | |
1701 | } | |
1702 | } | |
1703 | ||
1704 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1705 | if ($? ne 0) { | |
1706 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1707 | unlink ($filename); | |
1708 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1709 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1710 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1711 | goto ROOTCERT_ERROR; | |
1712 | } | |
1713 | ||
1714 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1715 | if ($? ne 0) { | |
1716 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1717 | unlink ($filename); | |
1718 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1719 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1720 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1721 | goto ROOTCERT_ERROR; | |
1722 | } | |
1723 | ||
1724 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1725 | if ($? ne 0) { | |
1726 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1727 | unlink ($filename); | |
1728 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1729 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1730 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1731 | goto ROOTCERT_ERROR; | |
1732 | } | |
1733 | ||
1734 | goto ROOTCERT_SUCCESS; | |
1735 | ||
1736 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1737 | ||
1738 | # Validate input since the form was submitted | |
1739 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1740 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1741 | goto ROOTCERT_ERROR; | |
1742 | } | |
1743 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1744 | $errormessage = $Lang::tr{'organization too long'}; | |
1745 | goto ROOTCERT_ERROR; | |
1746 | } | |
1747 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1748 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1749 | goto ROOTCERT_ERROR; | |
1750 | } | |
1751 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1752 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1753 | goto ROOTCERT_ERROR; | |
1754 | } | |
1755 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1756 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1757 | goto ROOTCERT_ERROR; | |
1758 | } | |
1759 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1760 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1761 | goto ROOTCERT_ERROR; | |
1762 | } | |
1763 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1764 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1765 | goto ROOTCERT_ERROR; | |
1766 | } | |
1767 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1768 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1769 | goto ROOTCERT_ERROR; | |
1770 | } | |
1771 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1772 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1773 | goto ROOTCERT_ERROR; | |
1774 | } | |
1775 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1776 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1777 | goto ROOTCERT_ERROR; | |
1778 | } | |
1779 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1780 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1781 | goto ROOTCERT_ERROR; | |
1782 | } | |
1783 | ||
1784 | # Copy the cgisettings to vpnsettings and save the configfile | |
1785 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1786 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1787 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1788 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1789 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1790 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1791 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1792 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1793 | ||
1794 | # Replace empty strings with a . | |
1795 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1796 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1797 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1798 | ||
1799 | # refresh | |
c6c9630e | 1800 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
6e13d0a5 MT |
1801 | |
1802 | # Create the CA certificate | |
1803 | my $pid = open(OPENSSL, "|-"); | |
1804 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1805 | if ($pid) { # parent | |
1806 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1807 | print OPENSSL "$state\n"; | |
1808 | print OPENSSL "$city\n"; | |
1809 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1810 | print OPENSSL "$ou\n"; | |
1811 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1812 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1813 | close (OPENSSL); | |
1814 | if ($?) { | |
1815 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1816 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1817 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1818 | goto ROOTCERT_ERROR; | |
1819 | } | |
1820 | } else { # child | |
badd8c1c | 1821 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', |
49abe7af | 1822 | '-days', '999999', '-newkey', 'rsa:4096', '-sha512', |
6e13d0a5 MT |
1823 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", |
1824 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1825 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1826 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1827 | goto ROOTCERT_ERROR; | |
1828 | } | |
1829 | } | |
1830 | ||
1831 | # Create the Host certificate request | |
1832 | $pid = open(OPENSSL, "|-"); | |
1833 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1834 | if ($pid) { # parent | |
1835 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1836 | print OPENSSL "$state\n"; | |
1837 | print OPENSSL "$city\n"; | |
1838 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1839 | print OPENSSL "$ou\n"; | |
1840 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1841 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1842 | print OPENSSL ".\n"; | |
1843 | print OPENSSL ".\n"; | |
1844 | close (OPENSSL); | |
1845 | if ($?) { | |
1846 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1847 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1848 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1849 | goto ROOTCERT_ERROR; | |
1850 | } | |
1851 | } else { # child | |
badd8c1c | 1852 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 1853 | '-newkey', 'rsa:2048', |
6e13d0a5 MT |
1854 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", |
1855 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1856 | '-extensions', 'server', | |
1857 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1858 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1859 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1860 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1861 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1862 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1863 | goto ROOTCERT_ERROR; | |
1864 | } | |
1865 | } | |
1866 | ||
1867 | # Sign the host certificate request | |
1868 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
1869 | '-batch', '-notext', | |
1870 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1871 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1872 | '-extensions', 'server', | |
1873 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1874 | if ($?) { | |
1875 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1876 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1877 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1878 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1879 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1880 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1881 | &newcleanssldatabase(); |
6e13d0a5 MT |
1882 | goto ROOTCERT_ERROR; |
1883 | } else { | |
1884 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1885 | &deletebackupcert(); |
6e13d0a5 MT |
1886 | } |
1887 | ||
1888 | # Create an empty CRL | |
1889 | system('/usr/bin/openssl', 'ca', '-gencrl', | |
1890 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1891 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1892 | if ($?) { | |
1893 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1894 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1895 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1896 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1897 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
c6c9630e | 1898 | &cleanssldatabase(); |
6e13d0a5 | 1899 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1900 | # } else { |
1901 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1902 | } |
1903 | # Create Diffie Hellmann Parameter | |
badd8c1c | 1904 | system('/usr/bin/openssl', 'dhparam', '-out', "${General::swroot}/ovpn/ca/dh1024.pem", "$cgiparams{'DHLENGHT'}"); |
6e13d0a5 MT |
1905 | if ($?) { |
1906 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1907 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1908 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1909 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1910 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1911 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
c6c9630e | 1912 | &cleanssldatabase(); |
6e13d0a5 | 1913 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1914 | # } else { |
1915 | # &cleanssldatabase(); | |
4be45949 EK |
1916 | } |
1917 | # Create ta.key for tls-auth | |
1918 | system('/usr/sbin/openvpn', '--genkey', '--secret', "${General::swroot}/ovpn/certs/ta.key"); | |
1919 | if ($?) { | |
1920 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1921 | &cleanssldatabase(); | |
1922 | goto ROOTCERT_ERROR; | |
1923 | } | |
6e13d0a5 MT |
1924 | goto ROOTCERT_SUCCESS; |
1925 | } | |
1926 | ROOTCERT_ERROR: | |
1927 | if ($cgiparams{'ACTION'} ne '') { | |
1928 | &Header::showhttpheaders(); | |
4c962356 | 1929 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1930 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1931 | if ($errormessage) { | |
1932 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1933 | print "<class name='base'>$errormessage"; | |
1934 | print " </class>"; | |
1935 | &Header::closebox(); | |
1936 | } | |
1937 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
49abe7af | 1938 | print <<END; |
6e13d0a5 MT |
1939 | <form method='post' enctype='multipart/form-data'> |
1940 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
e3edceeb | 1941 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
1942 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> |
1943 | <td width='35%' colspan='2'> </td></tr> | |
e3edceeb | 1944 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
1945 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> |
1946 | <td colspan='2'> </td></tr> | |
e3edceeb | 1947 | <tr><td class='base'>$Lang::tr{'your e-mail'}:</td> |
6e13d0a5 MT |
1948 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> |
1949 | <td colspan='2'> </td></tr> | |
e3edceeb | 1950 | <tr><td class='base'>$Lang::tr{'your department'}:</td> |
6e13d0a5 MT |
1951 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> |
1952 | <td colspan='2'> </td></tr> | |
e3edceeb | 1953 | <tr><td class='base'>$Lang::tr{'city'}:</td> |
6e13d0a5 MT |
1954 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> |
1955 | <td colspan='2'> </td></tr> | |
e3edceeb | 1956 | <tr><td class='base'>$Lang::tr{'state or province'}:</td> |
6e13d0a5 MT |
1957 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> |
1958 | <td colspan='2'> </td></tr> | |
1959 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
1960 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
1961 | ||
1962 | END | |
1963 | ; | |
1964 | foreach my $country (sort keys %{Countries::countries}) { | |
1965 | print "<option value='$Countries::countries{$country}'"; | |
1966 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1967 | print " selected='selected'"; | |
1968 | } | |
1969 | print ">$country</option>"; | |
1970 | } | |
49abe7af | 1971 | print <<END; |
6e13d0a5 | 1972 | </select></td> |
4c962356 EK |
1973 | <tr><td class='base'>$Lang::tr{'ovpn dh'}:</td> |
1974 | <td class='base'><select name='DHLENGHT'> | |
4c962356 EK |
1975 | <option value='2048' $selected{'DHLENGHT'}{'2048'}>2048 $Lang::tr{'bit'}</option> |
1976 | <option value='3072' $selected{'DHLENGHT'}{'3072'}>3072 $Lang::tr{'bit'}</option> | |
1977 | <option value='4096' $selected{'DHLENGHT'}{'4096'}>4096 $Lang::tr{'bit'}</option> | |
1978 | </select> | |
1979 | </td> | |
1980 | </tr> | |
1981 | ||
6e13d0a5 MT |
1982 | <tr><td> </td> |
1983 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
1984 | <td> </td><td> </td></tr> | |
1985 | <tr><td class='base' colspan='4' align='left'> | |
e3edceeb | 1986 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'required field'}</td></tr> |
49abe7af EK |
1987 | <tr><td colspan='2'><br></td></tr> |
1988 | <table width='100%'> | |
1989 | <tr> | |
1990 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}: </font></b>$Lang::tr{'ovpn generating the root and host certificates'} | |
1991 | <td class='base'>$Lang::tr{'dh key warn'}</td> | |
4c962356 | 1992 | </tr> |
49abe7af EK |
1993 | <tr> |
1994 | <td class='base'>$Lang::tr{'dh key warn1'}</td> | |
4c962356 | 1995 | </tr> |
49abe7af EK |
1996 | <tr><td colspan='2'><br></td></tr> |
1997 | <tr> | |
1998 | </table> | |
4c962356 | 1999 | |
49abe7af | 2000 | <table width='100%'> |
4c962356 | 2001 | <tr><td colspan='4'><hr></td></tr> |
e3edceeb | 2002 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
2003 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> |
2004 | <td colspan='2'> </td></tr> | |
e3edceeb | 2005 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
6e13d0a5 MT |
2006 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> |
2007 | <td colspan='2'> </td></tr> | |
2008 | <tr><td> </td> | |
2009 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
2010 | <td colspan='2'> </td></tr> | |
2011 | <tr><td class='base' colspan='4' align='left'> | |
e3edceeb | 2012 | <img src='/blob.gif' valign='top' alt='*' > $Lang::tr{'required field'}</td> |
4c962356 | 2013 | </tr> |
6e13d0a5 MT |
2014 | </form></table> |
2015 | END | |
2016 | ; | |
2017 | &Header::closebox(); | |
4c962356 | 2018 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2019 | &Header::closebigbox(); |
2020 | &Header::closepage(); | |
2021 | exit(0) | |
2022 | } | |
2023 | ||
2024 | ROOTCERT_SUCCESS: | |
2025 | system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem"); | |
c6c9630e MT |
2026 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
2027 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
2028 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
2029 | # } | |
6e13d0a5 MT |
2030 | |
2031 | ### | |
2032 | ### Enable/Disable connection | |
2033 | ### | |
ce9abb66 AH |
2034 | |
2035 | ### | |
7c1d9faf | 2036 | # m.a.d net2net |
ce9abb66 AH |
2037 | ### |
2038 | ||
6e13d0a5 | 2039 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
c6c9630e MT |
2040 | |
2041 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 | 2042 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 AH |
2043 | # my $n2nactive = ''; |
2044 | my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`; | |
2045 | ||
6e13d0a5 | 2046 | if ($confighash{$cgiparams{'KEY'}}) { |
8c877a82 AM |
2047 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
2048 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
2049 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2050 | |
8c877a82 | 2051 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
775b4494 AM |
2052 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); |
2053 | &writecollectdconf(); | |
8c877a82 AM |
2054 | } |
2055 | } else { | |
ce9abb66 | 2056 | |
8c877a82 AM |
2057 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
2058 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2059 | |
8c877a82 | 2060 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
775b4494 AM |
2061 | if ($n2nactive ne '') { |
2062 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
2063 | &writecollectdconf(); | |
2064 | } | |
ce9abb66 | 2065 | |
8c877a82 | 2066 | } else { |
775b4494 | 2067 | $errormessage = $Lang::tr{'invalid key'}; |
8c877a82 | 2068 | } |
775b4494 | 2069 | } |
ce9abb66 | 2070 | } |
6e13d0a5 MT |
2071 | |
2072 | ### | |
2073 | ### Download OpenVPN client package | |
2074 | ### | |
ce9abb66 AH |
2075 | |
2076 | ||
6e13d0a5 MT |
2077 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
2078 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2079 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2080 | my $file = ''; | |
2081 | my $clientovpn = ''; | |
2082 | my @fileholder; | |
2083 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2084 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
2085 | |
2086 | ### | |
7c1d9faf AH |
2087 | # m.a.d net2net |
2088 | ### | |
ce9abb66 AH |
2089 | |
2090 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
2091 | ||
2092 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
2093 | my $zippathname = "$zippath$zipname"; | |
2094 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
2095 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
54fd0535 | 2096 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 2097 | my $tunmtu = ''; |
7c1d9faf | 2098 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
54fd0535 | 2099 | my $n2nfragment = ''; |
ce9abb66 AH |
2100 | |
2101 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
2102 | flock CLIENTCONF, 2; | |
2103 | ||
2104 | my $zip = Archive::Zip->new(); | |
7c1d9faf | 2105 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 2106 | print CLIENTCONF "# \n"; |
b278daf3 | 2107 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
2108 | print CLIENTCONF "user nobody\n"; |
2109 | print CLIENTCONF "group nobody\n"; | |
2110 | print CLIENTCONF "persist-tun\n"; | |
2111 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 2112 | print CLIENTCONF "script-security 2\n"; |
60f396d7 | 2113 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
531f0835 | 2114 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 | 2115 | print CLIENTCONF "float\n"; |
60f396d7 | 2116 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
ce9abb66 | 2117 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 2118 | print CLIENTCONF "# Server Gateway Network\n"; |
7c1d9faf | 2119 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
b278daf3 | 2120 | print CLIENTCONF "# tun Device\n"; |
79e7688b | 2121 | print CLIENTCONF "dev tun\n"; |
35a21a25 AM |
2122 | print CLIENTCONF "#Logfile for statistics\n"; |
2123 | print CLIENTCONF "status-version 1\n"; | |
2124 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
60f396d7 | 2125 | print CLIENTCONF "# Port and Protokoll\n"; |
ce9abb66 | 2126 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; |
60f396d7 AH |
2127 | |
2128 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') { | |
2129 | print CLIENTCONF "proto tcp-client\n"; | |
2130 | print CLIENTCONF "# Packet size\n"; | |
d96c89eb | 2131 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
60f396d7 | 2132 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 2133 | } |
60f396d7 AH |
2134 | |
2135 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { | |
2136 | print CLIENTCONF "proto udp\n"; | |
2137 | print CLIENTCONF "# Paketsize\n"; | |
2138 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2139 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 2140 | if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";} |
60f396d7 | 2141 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";} |
d96c89eb | 2142 | } |
1647059d SS |
2143 | if (($confighash{$cgiparams{'KEY'}}[38] eq 'yes') || |
2144 | ($confighash{$cgiparams{'KEY'}}[38] eq 'maybe') || | |
2145 | ($confighash{$cgiparams{'KEY'}}[38] eq 'no' )) { | |
2ee746be SS |
2146 | if (($confighash{$cgiparams{'KEY'}}[23] ne 'on') || ($confighash{$cgiparams{'KEY'}}[24] eq '')) { |
2147 | if ($tunmtu eq '1500' ) { | |
350f2980 | 2148 | print CLIENTCONF "mtu-disc $confighash{$cgiparams{'KEY'}}[38]\n"; |
2ee746be SS |
2149 | } |
2150 | } | |
2151 | } | |
b66b02ab EK |
2152 | # Check host certificate if X509 is RFC3280 compliant. |
2153 | # If not, old --ns-cert-type directive will be used. | |
2154 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2155 | my $hostcert = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
2156 | if ($hostcert !~ /TLS Web Server Authentication/) { | |
2157 | print CLIENTCONF "ns-cert-type server\n"; | |
2158 | } else { | |
2159 | print CLIENTCONF "remote-cert-tls server\n"; | |
2160 | } | |
ce9abb66 AH |
2161 | print CLIENTCONF "# Auth. Client\n"; |
2162 | print CLIENTCONF "tls-client\n"; | |
49abe7af | 2163 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 2164 | print CLIENTCONF "cipher $confighash{$cgiparams{'KEY'}}[40]\n"; |
ce9abb66 AH |
2165 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
2166 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2167 | $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 | 2168 | } |
52f61e49 EKD |
2169 | |
2170 | # If GCM cipher is used, do not use --auth | |
2171 | if (($confighash{$cgiparams{'KEY'}}[40] eq 'AES-256-GCM') || | |
2172 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-192-GCM') || | |
2173 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-128-GCM')) { | |
2174 | print CLIENTCONF unless "# HMAC algorithm\n"; | |
2175 | print CLIENTCONF unless "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
49abe7af | 2176 | } else { |
52f61e49 EKD |
2177 | print CLIENTCONF "# HMAC algorithm\n"; |
2178 | print CLIENTCONF "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
49abe7af | 2179 | } |
52f61e49 | 2180 | |
4c962356 | 2181 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 2182 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 2183 | print CLIENTCONF "comp-lzo\n"; |
b278daf3 | 2184 | } |
ce9abb66 AH |
2185 | print CLIENTCONF "# Debug Level\n"; |
2186 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 2187 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 2188 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 2189 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
2190 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; |
2191 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
b278daf3 | 2192 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
54fd0535 MT |
2193 | if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"} |
2194 | else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"}; | |
ce9abb66 | 2195 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; |
531f0835 | 2196 | |
ce9abb66 AH |
2197 | |
2198 | close(CLIENTCONF); | |
2199 | ||
2200 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
2201 | my $status = $zip->writeToFileNamed($zippathname); | |
2202 | ||
2203 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2204 | @fileholder = <DLFILE>; | |
2205 | print "Content-Type:application/x-download\n"; | |
2206 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2207 | print @fileholder; | |
2208 | exit (0); | |
2209 | } | |
2210 | else | |
2211 | { | |
2212 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
2213 | my $zippathname = "$zippath$zipname"; | |
2214 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
2215 | ||
2216 | ### | |
7c1d9faf | 2217 | # m.a.d net2net |
ce9abb66 AH |
2218 | ### |
2219 | ||
c6c9630e | 2220 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 MT |
2221 | flock CLIENTCONF, 2; |
2222 | ||
2223 | my $zip = Archive::Zip->new(); | |
2224 | ||
8c877a82 | 2225 | print CLIENTCONF "#OpenVPN Client conf\r\n"; |
6e13d0a5 MT |
2226 | print CLIENTCONF "tls-client\r\n"; |
2227 | print CLIENTCONF "client\r\n"; | |
4f6e3ae3 | 2228 | print CLIENTCONF "nobind\r\n"; |
79e7688b | 2229 | print CLIENTCONF "dev tun\r\n"; |
c6c9630e | 2230 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
2ee746be SS |
2231 | |
2232 | # Check if we are using fragment, mssfix or mtu-disc and set MTU to 1500 | |
2233 | # or use configured value. | |
2234 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) | |
79e7688b | 2235 | { print CLIENTCONF "tun-mtu 1500\r\n"; } |
2ee746be | 2236 | elsif ($vpnsettings{MSSFIX} eq 'on') |
79e7688b | 2237 | { print CLIENTCONF "tun-mtu 1500\r\n"; } |
2ee746be | 2238 | else |
79e7688b | 2239 | { print CLIENTCONF "tun-mtu $vpnsettings{'DMTU'}\r\n"; } |
2ee746be | 2240 | |
6e13d0a5 MT |
2241 | if ( $vpnsettings{'ENABLED'} eq 'on'){ |
2242 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
c6c9630e MT |
2243 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
2244 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
2245 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2246 | } | |
2247 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2248 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2249 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2250 | } | |
2251 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2252 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2253 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2254 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
2255 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2256 | } | |
2257 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2258 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 MT |
2259 | } |
2260 | ||
71af643c MT |
2261 | my $file_crt = new File::Temp( UNLINK => 1 ); |
2262 | my $file_key = new File::Temp( UNLINK => 1 ); | |
b22d8aaf | 2263 | my $include_certs = 0; |
71af643c | 2264 | |
6e13d0a5 | 2265 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
71af643c | 2266 | if ($cgiparams{'MODE'} eq 'insecure') { |
b22d8aaf MT |
2267 | $include_certs = 1; |
2268 | ||
71af643c | 2269 | # Add the CA |
b22d8aaf | 2270 | print CLIENTCONF ";ca cacert.pem\r\n"; |
71af643c MT |
2271 | $zip->addFile("${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; |
2272 | ||
2273 | # Extract the certificate | |
2274 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", | |
2275 | '-clcerts', '-nokeys', '-nodes', '-out', "$file_crt" , '-passin', 'pass:'); | |
2276 | if ($?) { | |
2277 | die "openssl error: $?"; | |
2278 | } | |
2279 | ||
2280 | $zip->addFile("$file_crt", "$confighash{$cgiparams{'KEY'}}[1].pem") or die; | |
b22d8aaf | 2281 | print CLIENTCONF ";cert $confighash{$cgiparams{'KEY'}}[1].pem\r\n"; |
71af643c MT |
2282 | |
2283 | # Extract the key | |
2284 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", | |
2285 | '-nocerts', '-nodes', '-out', "$file_key", '-passin', 'pass:'); | |
2286 | if ($?) { | |
2287 | die "openssl error: $?"; | |
2288 | } | |
2289 | ||
2290 | $zip->addFile("$file_key", "$confighash{$cgiparams{'KEY'}}[1].key") or die; | |
b22d8aaf | 2291 | print CLIENTCONF ";key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; |
71af643c MT |
2292 | } else { |
2293 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2294 | $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"; | |
2295 | } | |
6e13d0a5 | 2296 | } else { |
c6c9630e MT |
2297 | print CLIENTCONF "ca cacert.pem\r\n"; |
2298 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
2299 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
2300 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
2301 | $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 |
2302 | } |
2303 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
49abe7af EK |
2304 | if ($vpnsettings{'DAUTH'} eq '') { |
2305 | print CLIENTCONF ""; | |
2306 | } else { | |
2307 | print CLIENTCONF "auth $vpnsettings{'DAUTH'}\r\n"; | |
2308 | } | |
2309 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
b22d8aaf MT |
2310 | if ($cgiparams{'MODE'} eq 'insecure') { |
2311 | print CLIENTCONF ";"; | |
2312 | } | |
4be45949 EK |
2313 | print CLIENTCONF "tls-auth ta.key\r\n"; |
2314 | $zip->addFile( "${General::swroot}/ovpn/certs/ta.key", "ta.key") or die "Can't add file ta.key\n"; | |
49abe7af | 2315 | } |
6e13d0a5 MT |
2316 | if ($vpnsettings{DCOMPLZO} eq 'on') { |
2317 | print CLIENTCONF "comp-lzo\r\n"; | |
2318 | } | |
2319 | print CLIENTCONF "verb 3\r\n"; | |
b66b02ab EK |
2320 | # Check host certificate if X509 is RFC3280 compliant. |
2321 | # If not, old --ns-cert-type directive will be used. | |
2322 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2323 | my $hostcert = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
2324 | if ($hostcert !~ /TLS Web Server Authentication/) { | |
2325 | print CLIENTCONF "ns-cert-type server\r\n"; | |
2326 | } else { | |
2327 | print CLIENTCONF "remote-cert-tls server\r\n"; | |
2328 | } | |
964700d4 | 2329 | print CLIENTCONF "verify-x509-name $vpnsettings{ROOTCERT_HOSTNAME} name\r\n"; |
a79fa1d6 JPT |
2330 | if ($vpnsettings{MSSFIX} eq 'on') { |
2331 | print CLIENTCONF "mssfix\r\n"; | |
2332 | } | |
74225cce | 2333 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
2334 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
2335 | } | |
1647059d | 2336 | |
b22d8aaf MT |
2337 | if ($include_certs) { |
2338 | print CLIENTCONF "\r\n"; | |
2339 | ||
2340 | # CA | |
2341 | open(FILE, "<${General::swroot}/ovpn/ca/cacert.pem"); | |
2342 | print CLIENTCONF "<ca>\r\n"; | |
2343 | while (<FILE>) { | |
2344 | chomp($_); | |
2345 | print CLIENTCONF "$_\r\n"; | |
2346 | } | |
2347 | print CLIENTCONF "</ca>\r\n\r\n"; | |
2348 | close(FILE); | |
2349 | ||
2350 | # Cert | |
2351 | open(FILE, "<$file_crt"); | |
2352 | print CLIENTCONF "<cert>\r\n"; | |
2353 | while (<FILE>) { | |
2354 | chomp($_); | |
2355 | print CLIENTCONF "$_\r\n"; | |
2356 | } | |
2357 | print CLIENTCONF "</cert>\r\n\r\n"; | |
2358 | close(FILE); | |
2359 | ||
2360 | # Key | |
2361 | open(FILE, "<$file_key"); | |
2362 | print CLIENTCONF "<key>\r\n"; | |
2363 | while (<FILE>) { | |
2364 | chomp($_); | |
2365 | print CLIENTCONF "$_\r\n"; | |
2366 | } | |
2367 | print CLIENTCONF "</key>\r\n\r\n"; | |
2368 | close(FILE); | |
2369 | ||
2370 | # TLS auth | |
2371 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
2372 | open(FILE, "<${General::swroot}/ovpn/certs/ta.key"); | |
2373 | print CLIENTCONF "<tls-auth>\r\n"; | |
2374 | while (<FILE>) { | |
2375 | chomp($_); | |
2376 | print CLIENTCONF "$_\r\n"; | |
2377 | } | |
2378 | print CLIENTCONF "</tls-auth>\r\n\r\n"; | |
2379 | close(FILE); | |
2380 | } | |
2381 | } | |
2382 | ||
ffbe77c8 EK |
2383 | # Print client.conf.local if entries exist to client.ovpn |
2384 | if (!-z $local_clientconf && $vpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
2385 | open (LCC, "$local_clientconf"); | |
2386 | print CLIENTCONF "\n#---------------------------\n"; | |
2387 | print CLIENTCONF "# Start of custom directives\n"; | |
2388 | print CLIENTCONF "# from client.conf.local\n"; | |
2389 | print CLIENTCONF "#---------------------------\n\n"; | |
2390 | while (<LCC>) { | |
2391 | print CLIENTCONF $_; | |
2392 | } | |
2393 | print CLIENTCONF "\n#---------------------------\n"; | |
2394 | print CLIENTCONF "# End of custom directives\n"; | |
2395 | print CLIENTCONF "#---------------------------\n\n"; | |
2396 | close (LCC); | |
2397 | } | |
6e13d0a5 | 2398 | close(CLIENTCONF); |
ce9abb66 | 2399 | |
6e13d0a5 MT |
2400 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
2401 | my $status = $zip->writeToFileNamed($zippathname); | |
2402 | ||
2403 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2404 | @fileholder = <DLFILE>; | |
2405 | print "Content-Type:application/x-download\n"; | |
2406 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2407 | print @fileholder; | |
2408 | exit (0); | |
ce9abb66 AH |
2409 | } |
2410 | ||
2411 | ||
2412 | ||
6e13d0a5 MT |
2413 | ### |
2414 | ### Remove connection | |
2415 | ### | |
ce9abb66 AH |
2416 | |
2417 | ||
6e13d0a5 | 2418 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
323be7c4 AM |
2419 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
2420 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 2421 | |
323be7c4 | 2422 | if ($confighash{$cgiparams{'KEY'}}) { |
fde9c9dd | 2423 | # Revoke certificate if certificate was deleted and rewrite the CRL |
323be7c4 | 2424 | 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 | 2425 | my $tempA = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; |
ce9abb66 AH |
2426 | |
2427 | ### | |
7c1d9faf | 2428 | # m.a.d net2net |
ce9abb66 | 2429 | ### |
7c1d9faf | 2430 | |
323be7c4 | 2431 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
1e499e90 MT |
2432 | # Stop the N2N connection before it is removed |
2433 | system("/usr/local/bin/openvpnctrl -kn2n $confighash{$cgiparams{'KEY'}}[1] &>/dev/null"); | |
2434 | ||
323be7c4 AM |
2435 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); |
2436 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2437 | unlink ($certfile); | |
2438 | unlink ($conffile); | |
8e6a8fd5 | 2439 | |
323be7c4 AM |
2440 | if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") { |
2441 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2442 | } | |
323be7c4 | 2443 | } |
ce9abb66 | 2444 | |
323be7c4 AM |
2445 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
2446 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
8c877a82 AM |
2447 | |
2448 | # A.Marx CCD delete ccd files and routes | |
2449 | ||
323be7c4 AM |
2450 | if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]") |
2451 | { | |
2452 | unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; | |
8c877a82 | 2453 | } |
e81be1e1 | 2454 | |
323be7c4 AM |
2455 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
2456 | foreach my $key (keys %ccdroutehash) { | |
2457 | if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2458 | delete $ccdroutehash{$key}; | |
2459 | } | |
8c877a82 | 2460 | } |
323be7c4 | 2461 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 2462 | |
323be7c4 AM |
2463 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
2464 | foreach my $key (keys %ccdroute2hash) { | |
2465 | if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2466 | delete $ccdroute2hash{$key}; | |
2467 | } | |
2468 | } | |
2469 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
2470 | &writeserverconf; | |
8c877a82 | 2471 | |
323be7c4 AM |
2472 | # CCD end |
2473 | # Update collectd configuration and delete all RRD files of the removed connection | |
2474 | &writecollectdconf(); | |
2475 | system ("/usr/local/bin/openvpnctrl -drrd $confighash{$cgiparams{'KEY'}}[1]"); | |
8c877a82 | 2476 | |
323be7c4 AM |
2477 | delete $confighash{$cgiparams{'KEY'}}; |
2478 | my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
2479 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2480 | ||
2481 | } else { | |
2482 | $errormessage = $Lang::tr{'invalid key'}; | |
2483 | } | |
b2e75449 | 2484 | &General::firewall_reload(); |
ce9abb66 | 2485 | |
6e13d0a5 MT |
2486 | ### |
2487 | ### Download PKCS12 file | |
2488 | ### | |
2489 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
2490 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2491 | ||
2492 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
2493 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2494 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`; | |
2495 | exit (0); | |
2496 | ||
2497 | ### | |
2498 | ### Display certificate | |
2499 | ### | |
2500 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
2501 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2502 | ||
2503 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e | 2504 | &Header::showhttpheaders(); |
4c962356 | 2505 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
2506 | &Header::openbigbox('100%', 'LEFT', '', ''); |
2507 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
2508 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2509 | $output = &Header::cleanhtml($output,"y"); | |
2510 | print "<pre>$output</pre>\n"; | |
2511 | &Header::closebox(); | |
2512 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2513 | &Header::closebigbox(); | |
2514 | &Header::closepage(); | |
2515 | exit(0); | |
6e13d0a5 | 2516 | } |
4c962356 EK |
2517 | |
2518 | ### | |
2519 | ### Display Diffie-Hellman key | |
2520 | ### | |
2521 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show dh'}) { | |
2522 | ||
2523 | if (! -e "${General::swroot}/ovpn/ca/dh1024.pem") { | |
49abe7af | 2524 | $errormessage = $Lang::tr{'not present'}; |
4c962356 EK |
2525 | } else { |
2526 | &Header::showhttpheaders(); | |
2527 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2528 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2529 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'dh'}:"); | |
2530 | my $output = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem`; | |
2531 | $output = &Header::cleanhtml($output,"y"); | |
2532 | print "<pre>$output</pre>\n"; | |
2533 | &Header::closebox(); | |
2534 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2535 | &Header::closebigbox(); | |
2536 | &Header::closepage(); | |
2537 | exit(0); | |
2538 | } | |
2539 | ||
fd5ccb2d EK |
2540 | ### |
2541 | ### Display tls-auth key | |
2542 | ### | |
2543 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show tls-auth key'}) { | |
2544 | ||
2545 | if (! -e "${General::swroot}/ovpn/certs/ta.key") { | |
2546 | $errormessage = $Lang::tr{'not present'}; | |
2547 | } else { | |
2548 | &Header::showhttpheaders(); | |
2549 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2550 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2551 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ta key'}:"); | |
2552 | my $output = `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
2553 | $output = &Header::cleanhtml($output,"y"); | |
2554 | print "<pre>$output</pre>\n"; | |
2555 | &Header::closebox(); | |
2556 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2557 | &Header::closebigbox(); | |
2558 | &Header::closepage(); | |
2559 | exit(0); | |
2560 | } | |
2561 | ||
6e13d0a5 MT |
2562 | ### |
2563 | ### Display Certificate Revoke List | |
2564 | ### | |
2565 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
2566 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2567 | ||
49abe7af EK |
2568 | if (! -e "${General::swroot}/ovpn/crls/cacrl.pem") { |
2569 | $errormessage = $Lang::tr{'not present'}; | |
2570 | } else { | |
b2e75449 MT |
2571 | &Header::showhttpheaders(); |
2572 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2573 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2574 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
2575 | my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`; | |
2576 | $output = &Header::cleanhtml($output,"y"); | |
2577 | print "<pre>$output</pre>\n"; | |
2578 | &Header::closebox(); | |
2579 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2580 | &Header::closebigbox(); | |
2581 | &Header::closepage(); | |
2582 | exit(0); | |
6e13d0a5 MT |
2583 | } |
2584 | ||
2585 | ### | |
2586 | ### Advanced Server Settings | |
2587 | ### | |
2588 | ||
2589 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
2590 | %cgiparams = (); | |
2591 | %cahash = (); | |
2592 | %confighash = (); | |
8c877a82 | 2593 | my $disabled; |
6e13d0a5 | 2594 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); |
54fd0535 | 2595 | read_routepushfile; |
8c877a82 AM |
2596 | |
2597 | ||
c6c9630e MT |
2598 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
2599 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
2600 | # } | |
6e13d0a5 MT |
2601 | ADV_ERROR: |
2602 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
4c962356 | 2603 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 | 2604 | } |
6e13d0a5 | 2605 | if ($cgiparams{'KEEPALIVE_1'} eq '') { |
4c962356 | 2606 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
2607 | } |
2608 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
4c962356 | 2609 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
2610 | } |
2611 | if ($cgiparams{'LOG_VERB'} eq '') { | |
4c962356 | 2612 | $cgiparams{'LOG_VERB'} = '3'; |
ae9f6139 | 2613 | } |
4c962356 | 2614 | if ($cgiparams{'DAUTH'} eq '') { |
70900745 | 2615 | $cgiparams{'DAUTH'} = 'SHA512'; |
92b87e17 | 2616 | } |
f527e53f | 2617 | if ($cgiparams{'TLSAUTH'} eq '') { |
754066e6 | 2618 | $cgiparams{'TLSAUTH'} = 'off'; |
f527e53f | 2619 | } |
6e13d0a5 MT |
2620 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
2621 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
2622 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
2623 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
2624 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
2625 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
ffbe77c8 EK |
2626 | $checked{'ADDITIONAL_CONFIGS'}{'off'} = ''; |
2627 | $checked{'ADDITIONAL_CONFIGS'}{'on'} = ''; | |
2628 | $checked{'ADDITIONAL_CONFIGS'}{$cgiparams{'ADDITIONAL_CONFIGS'}} = 'CHECKED'; | |
a79fa1d6 JPT |
2629 | $checked{'MSSFIX'}{'off'} = ''; |
2630 | $checked{'MSSFIX'}{'on'} = ''; | |
2631 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
49abe7af | 2632 | $selected{'LOG_VERB'}{'0'} = ''; |
6e13d0a5 MT |
2633 | $selected{'LOG_VERB'}{'1'} = ''; |
2634 | $selected{'LOG_VERB'}{'2'} = ''; | |
2635 | $selected{'LOG_VERB'}{'3'} = ''; | |
2636 | $selected{'LOG_VERB'}{'4'} = ''; | |
2637 | $selected{'LOG_VERB'}{'5'} = ''; | |
2638 | $selected{'LOG_VERB'}{'6'} = ''; | |
2639 | $selected{'LOG_VERB'}{'7'} = ''; | |
2640 | $selected{'LOG_VERB'}{'8'} = ''; | |
2641 | $selected{'LOG_VERB'}{'9'} = ''; | |
2642 | $selected{'LOG_VERB'}{'10'} = ''; | |
2643 | $selected{'LOG_VERB'}{'11'} = ''; | |
6e13d0a5 | 2644 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; |
4c962356 EK |
2645 | $selected{'DAUTH'}{'whirlpool'} = ''; |
2646 | $selected{'DAUTH'}{'SHA512'} = ''; | |
2647 | $selected{'DAUTH'}{'SHA384'} = ''; | |
2648 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
2649 | $selected{'DAUTH'}{'SHA1'} = ''; |
2650 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
49abe7af EK |
2651 | $checked{'TLSAUTH'}{'off'} = ''; |
2652 | $checked{'TLSAUTH'}{'on'} = ''; | |
2653 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
f527e53f | 2654 | |
6e13d0a5 MT |
2655 | &Header::showhttpheaders(); |
2656 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
2657 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2658 | if ($errormessage) { | |
c6c9630e MT |
2659 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
2660 | print "<class name='base'>$errormessage\n"; | |
2661 | print " </class>\n"; | |
2662 | &Header::closebox(); | |
6e13d0a5 MT |
2663 | } |
2664 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
4c962356 | 2665 | print <<END; |
b376fae4 | 2666 | <form method='post' enctype='multipart/form-data'> |
b2e75449 | 2667 | <table width='100%' border=0> |
4c962356 EK |
2668 | <tr> |
2669 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
6e13d0a5 MT |
2670 | </tr> |
2671 | <tr> | |
4c962356 | 2672 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> |
6e13d0a5 MT |
2673 | </tr> |
2674 | <tr> | |
4c962356 | 2675 | <td class='base'>Domain</td> |
8c877a82 | 2676 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> |
6e13d0a5 MT |
2677 | </tr> |
2678 | <tr> | |
4c962356 EK |
2679 | <td class='base'>DNS</td> |
2680 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
6e13d0a5 MT |
2681 | </tr> |
2682 | <tr> | |
4c962356 EK |
2683 | <td class='base'>WINS</td> |
2684 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
2685 | </tr> | |
54fd0535 | 2686 | <tr> |
4c962356 | 2687 | <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td> |
54fd0535 MT |
2688 | </tr> |
2689 | <tr> | |
4c962356 EK |
2690 | <td class='base'>$Lang::tr{'ovpn routes push'}</td> |
2691 | <td colspan='2'> | |
2692 | <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'> | |
54fd0535 MT |
2693 | END |
2694 | ; | |
2695 | ||
2696 | if ($cgiparams{'ROUTES_PUSH'} ne '') | |
2697 | { | |
2698 | print $cgiparams{'ROUTES_PUSH'}; | |
2699 | } | |
2700 | ||
8c877a82 | 2701 | print <<END; |
54fd0535 MT |
2702 | </textarea></td> |
2703 | </tr> | |
6e13d0a5 MT |
2704 | </tr> |
2705 | </table> | |
2706 | <hr size='1'> | |
4c962356 | 2707 | <table width='100%'> |
ffbe77c8 | 2708 | <tr> |
4c962356 | 2709 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> |
ffbe77c8 EK |
2710 | </tr> |
2711 | ||
2712 | <tr> | |
4c962356 | 2713 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
ffbe77c8 EK |
2714 | </tr> |
2715 | ||
2716 | <tr> | |
4c962356 EK |
2717 | <td class='base'>Client-To-Client</td> |
2718 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
ffbe77c8 EK |
2719 | </tr> |
2720 | ||
2721 | <tr> | |
4c962356 EK |
2722 | <td class='base'>Redirect-Gateway def1</td> |
2723 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
ffbe77c8 EK |
2724 | </tr> |
2725 | ||
4c962356 | 2726 | <tr> |
ffbe77c8 EK |
2727 | <td class='base'>$Lang::tr{'ovpn add conf'}</td> |
2728 | <td><input type='checkbox' name='ADDITIONAL_CONFIGS' $checked{'ADDITIONAL_CONFIGS'}{'on'} /></td> | |
2729 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2730 | </tr> | |
2731 | ||
2732 | <tr> | |
2733 | <td class='base'>mssfix</td> | |
2734 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
2735 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2736 | </tr> | |
2737 | ||
4c962356 | 2738 | <tr> |
ffbe77c8 EK |
2739 | <td class='base'>fragment <br></td> |
2740 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
2741 | </tr> | |
2742 | ||
2743 | ||
2744 | <tr> | |
2745 | <td class='base'>Max-Clients</td> | |
2746 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> | |
2747 | </tr> | |
2748 | <tr> | |
2749 | <td class='base'>Keepalive <br /> | |
2750 | (ping/ping-restart)</td> | |
2751 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
2752 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
2753 | </tr> | |
a79fa1d6 JPT |
2754 | </table> |
2755 | ||
a79fa1d6 | 2756 | <hr size='1'> |
4c962356 | 2757 | <table width='100%'> |
a79fa1d6 | 2758 | <tr> |
49abe7af | 2759 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> |
a79fa1d6 JPT |
2760 | </tr> |
2761 | <tr> | |
49abe7af | 2762 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> |
4c962356 EK |
2763 | </tr> |
2764 | ||
2765 | <tr><td class='base'>VERB</td> | |
2766 | <td><select name='LOG_VERB'> | |
49abe7af EK |
2767 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option> |
2768 | <option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
2769 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
2770 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
2771 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
2772 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
2773 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
2774 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
2775 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
2776 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
2777 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
2778 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
2779 | </td></select> | |
2780 | </table> | |
4c962356 | 2781 | |
6e13d0a5 | 2782 | <hr size='1'> |
4c962356 | 2783 | <table width='100%'> |
6e13d0a5 | 2784 | <tr> |
4c962356 EK |
2785 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}</b></td> |
2786 | </tr> | |
2787 | <tr> | |
2788 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> | |
6e13d0a5 | 2789 | </tr> |
4c962356 EK |
2790 | <tr><td class='base'>$Lang::tr{'ovpn ha'}</td> |
2791 | <td><select name='DAUTH'> | |
b2e75449 MT |
2792 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
2793 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
2794 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
2795 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
f3dfb261 | 2796 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
4c962356 EK |
2797 | </select> |
2798 | </td> | |
040b8b0c | 2799 | <td>$Lang::tr{'openvpn default'}: <span class="base">SHA1 (160 $Lang::tr{'bit'})</span></td> |
49abe7af | 2800 | </tr> |
6e13d0a5 | 2801 | </table> |
49abe7af EK |
2802 | |
2803 | <table width='100%'> | |
6e13d0a5 | 2804 | <tr> |
49abe7af | 2805 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='15%'></td><td width='35%'></td> |
6e13d0a5 | 2806 | </tr> |
4c962356 | 2807 | |
6e13d0a5 | 2808 | <tr> |
49abe7af EK |
2809 | <td class='base'>HMAC tls-auth</td> |
2810 | <td><input type='checkbox' name='TLSAUTH' $checked{'TLSAUTH'}{'on'} /></td> | |
2811 | </tr> | |
2812 | </table><hr> | |
8c877a82 AM |
2813 | END |
2814 | ||
2815 | if ( -e "/var/run/openvpn.pid"){ | |
2816 | print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br> | |
2817 | $Lang::tr{'server restart'}<br><br> | |
2818 | <hr>"; | |
49abe7af | 2819 | print<<END; |
52d08bcb AM |
2820 | <table width='100%'> |
2821 | <tr> | |
2822 | <td> </td> | |
2823 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td> | |
2824 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2825 | <td> </td> | |
2826 | </tr> | |
2827 | </table> | |
2828 | </form> | |
2829 | END | |
2830 | ; | |
2831 | ||
2832 | ||
2833 | }else{ | |
8c877a82 | 2834 | |
49abe7af | 2835 | print<<END; |
6e13d0a5 MT |
2836 | <table width='100%'> |
2837 | <tr> | |
2838 | <td> </td> | |
2839 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
2840 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
2841 | <td> </td> | |
2842 | </tr> | |
2843 | </table> | |
2844 | </form> | |
2845 | END | |
2846 | ; | |
52d08bcb | 2847 | } |
6e13d0a5 | 2848 | &Header::closebox(); |
c6c9630e | 2849 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2850 | &Header::closebigbox(); |
2851 | &Header::closepage(); | |
2852 | exit(0); | |
2853 | ||
8c877a82 AM |
2854 | |
2855 | # A.Marx CCD Add,delete or edit CCD net | |
2856 | ||
2857 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} || | |
2858 | $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} || | |
2859 | $cgiparams{'ACTION'} eq "kill" || | |
2860 | $cgiparams{'ACTION'} eq "edit" || | |
2861 | $cgiparams{'ACTION'} eq 'editsave'){ | |
2862 | &Header::showhttpheaders(); | |
2863 | &Header::openpage($Lang::tr{'ccd net'}, 1, ''); | |
2864 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2865 | ||
2866 | if ($cgiparams{'ACTION'} eq "kill"){ | |
2867 | &delccdnet($cgiparams{'net'}); | |
2868 | } | |
2869 | ||
2870 | if ($cgiparams{'ACTION'} eq 'editsave'){ | |
2871 | my ($a,$b) =split (/\|/,$cgiparams{'ccdname'}); | |
2872 | if ( $a ne $b){ &modccdnet($a,$b);} | |
5068ac38 AM |
2873 | $cgiparams{'ccdname'}=''; |
2874 | $cgiparams{'ccdsubnet'}=''; | |
8c877a82 AM |
2875 | } |
2876 | ||
2877 | if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) { | |
e2429e8d | 2878 | &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'}); |
8c877a82 AM |
2879 | } |
2880 | if ($errormessage) { | |
2881 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2882 | print "<class name='base'>$errormessage"; | |
2883 | print " </class>"; | |
2884 | &Header::closebox(); | |
2885 | } | |
2886 | if ($cgiparams{'ACTION'} eq "edit"){ | |
2887 | ||
2888 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'}); | |
2889 | ||
49abe7af | 2890 | print <<END; |
631b67b7 | 2891 | <table width='100%' border='0'> |
8c877a82 AM |
2892 | <tr><form method='post'> |
2893 | <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
a9fb14d0 | 2894 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly='readonly' /></td></tr> |
8c877a82 AM |
2895 | <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/> |
2896 | <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' /> | |
2897 | </td></tr> | |
2898 | </table></form> | |
2899 | END | |
2900 | ; | |
2901 | &Header::closebox(); | |
2902 | ||
2903 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
49abe7af | 2904 | print <<END; |
8c877a82 AM |
2905 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> |
2906 | <tr> | |
2907 | <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> | |
2908 | END | |
2909 | ; | |
2910 | } | |
2911 | else{ | |
2912 | if (! -e "/var/run/openvpn.pid"){ | |
2913 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'}); | |
49abe7af | 2914 | print <<END; |
8c877a82 AM |
2915 | <table width='100%' border='0'> |
2916 | <tr><form method='post'> | |
2917 | <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr> | |
2918 | <tr> | |
2919 | <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2920 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr> | |
2921 | <tr><td colspan=4><hr /></td></tr><tr> | |
2922 | <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> | |
2923 | </table></form> | |
2924 | END | |
2925 | ||
2926 | &Header::closebox(); | |
2927 | } | |
2928 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
5068ac38 AM |
2929 | if ( -e "/var/run/openvpn.pid"){ |
2930 | print "<b>$Lang::tr{'attention'}:</b><br>"; | |
2931 | print "$Lang::tr{'ccd noaddnet'}<br><hr>"; | |
2932 | } | |
2933 | ||
4c962356 | 2934 | print <<END; |
99bfa85c | 2935 | <table width='100%' cellpadding='0' cellspacing='1'> |
8c877a82 AM |
2936 | <tr> |
2937 | <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> | |
2938 | END | |
2939 | ; | |
2940 | } | |
2941 | my %ccdconfhash=(); | |
2942 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
2943 | my @ccdconf=(); | |
2944 | my $count=0; | |
df9b48b7 | 2945 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
2946 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); |
2947 | $count++; | |
2948 | my $ccdhosts = &hostsinnet($ccdconf[0]); | |
2949 | if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
2950 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
2951 | print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>"; | |
4c962356 | 2952 | print <<END; |
8c877a82 | 2953 | <form method='post' /> |
1638682b | 2954 | <input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> |
8c877a82 AM |
2955 | <input type='hidden' name='ACTION' value='edit'/> |
2956 | <input type='hidden' name='ccdname' value='$ccdconf[0]' /> | |
2957 | <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' /> | |
2958 | </form></td> | |
2959 | <form method='post' /> | |
2960 | <td><input type='hidden' name='ACTION' value='kill'/> | |
2961 | <input type='hidden' name='number' value='$count' /> | |
2962 | <input type='hidden' name='net' value='$ccdconf[0]' /> | |
1638682b | 2963 | <input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /></form></td></tr> |
8c877a82 AM |
2964 | END |
2965 | ; | |
2966 | } | |
2967 | print "</table></form>"; | |
2968 | &Header::closebox(); | |
2969 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2970 | &Header::closebigbox(); | |
2971 | &Header::closepage(); | |
2972 | exit(0); | |
2973 | ||
2974 | #END CCD | |
2975 | ||
6e13d0a5 MT |
2976 | ### |
2977 | ### Openvpn Connections Statistics | |
2978 | ### | |
2979 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
2980 | &Header::showhttpheaders(); | |
2981 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
2982 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2983 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
2984 | ||
2985 | # | |
2986 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
2987 | # protocol temp removed | |
4c962356 | 2988 | print <<END; |
99bfa85c | 2989 | <table width='100%' cellpadding='2' cellspacing='0' class='tbl'> |
6e13d0a5 | 2990 | <tr> |
99bfa85c AM |
2991 | <th><b>$Lang::tr{'common name'}</b></th> |
2992 | <th><b>$Lang::tr{'real address'}</b></th> | |
d8ef6a95 | 2993 | <th><b>$Lang::tr{'country'}</b></th> |
99bfa85c AM |
2994 | <th><b>$Lang::tr{'virtual address'}</b></th> |
2995 | <th><b>$Lang::tr{'loged in at'}</b></th> | |
2996 | <th><b>$Lang::tr{'bytes sent'}</b></th> | |
2997 | <th><b>$Lang::tr{'bytes received'}</b></th> | |
2998 | <th><b>$Lang::tr{'last activity'}</b></th> | |
6e13d0a5 MT |
2999 | </tr> |
3000 | END | |
3001 | ; | |
87fe47e9 | 3002 | my $filename = "/var/run/ovpnserver.log"; |
6e13d0a5 MT |
3003 | open(FILE, $filename) or die 'Unable to open config file.'; |
3004 | my @current = <FILE>; | |
3005 | close(FILE); | |
3006 | my @users =(); | |
3007 | my $status; | |
3008 | my $uid = 0; | |
3009 | my $cn; | |
3010 | my @match = (); | |
3011 | my $proto = "udp"; | |
3012 | my $address; | |
3013 | my %userlookup = (); | |
3014 | foreach my $line (@current) | |
3015 | { | |
3016 | chomp($line); | |
3017 | if ( $line =~ /^Updated,(.+)/){ | |
3018 | @match = split( /^Updated,(.+)/, $line); | |
3019 | $status = $match[1]; | |
3020 | } | |
c6c9630e | 3021 | #gian |
6e13d0a5 MT |
3022 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
3023 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
3024 | if ($match[1] ne "Common Name") { | |
3025 | $cn = $match[1]; | |
3026 | $userlookup{$match[2]} = $uid; | |
3027 | $users[$uid]{'CommonName'} = $match[1]; | |
3028 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
3029 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
3030 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
3031 | $users[$uid]{'Since'} = $match[5]; |
3032 | $users[$uid]{'Proto'} = $proto; | |
d8ef6a95 PM |
3033 | |
3034 | # get country code for "RealAddress"... | |
3035 | my $ccode = &GeoIP::lookup((split ':', $users[$uid]{'RealAddress'})[0]); | |
3036 | my $flag_icon = &GeoIP::get_flag_icon($ccode); | |
3037 | $users[$uid]{'Country'} = "<a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a>"; | |
6e13d0a5 MT |
3038 | $uid++; |
3039 | } | |
3040 | } | |
3041 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
3042 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
3043 | if ($match[1] ne "Virtual Address") { | |
3044 | $address = $match[3]; | |
3045 | #find the uid in the lookup table | |
3046 | $uid = $userlookup{$address}; | |
3047 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
3048 | $users[$uid]{'LastRef'} = $match[4]; | |
3049 | } | |
3050 | } | |
3051 | } | |
3052 | my $user2 = @users; | |
3053 | if ($user2 >= 1){ | |
99bfa85c | 3054 | for (my $idx = 1; $idx <= $user2; $idx++){ |
6e13d0a5 | 3055 | if ($idx % 2) { |
99bfa85c AM |
3056 | print "<tr>"; |
3057 | $col="bgcolor='$color{'color22'}'"; | |
3058 | } else { | |
3059 | print "<tr>"; | |
3060 | $col="bgcolor='$color{'color20'}'"; | |
6e13d0a5 | 3061 | } |
99bfa85c AM |
3062 | print "<td align='left' $col>$users[$idx-1]{'CommonName'}</td>"; |
3063 | print "<td align='left' $col>$users[$idx-1]{'RealAddress'}</td>"; | |
d8ef6a95 PM |
3064 | print "<td align='center' $col>$users[$idx-1]{'Country'}</td>"; |
3065 | print "<td align='center' $col>$users[$idx-1]{'VirtualAddress'}</td>"; | |
99bfa85c AM |
3066 | print "<td align='left' $col>$users[$idx-1]{'Since'}</td>"; |
3067 | print "<td align='left' $col>$users[$idx-1]{'BytesSent'}</td>"; | |
3068 | print "<td align='left' $col>$users[$idx-1]{'BytesReceived'}</td>"; | |
3069 | print "<td align='left' $col>$users[$idx-1]{'LastRef'}</td>"; | |
3070 | } | |
3071 | } | |
6e13d0a5 MT |
3072 | |
3073 | print "</table>"; | |
49abe7af | 3074 | print <<END; |
6e13d0a5 MT |
3075 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> |
3076 | <tr><td></td></tr> | |
3077 | <tr><td></td></tr> | |
3078 | <tr><td></td></tr> | |
3079 | <tr><td></td></tr> | |
3080 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
3081 | </table> | |
3082 | END | |
3083 | ; | |
3084 | &Header::closebox(); | |
3085 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3086 | &Header::closebigbox(); | |
3087 | &Header::closepage(); | |
3088 | exit(0); | |
3089 | ||
3090 | ### | |
3091 | ### Download Certificate | |
3092 | ### | |
3093 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
3094 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 3095 | |
6e13d0a5 | 3096 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
3097 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
3098 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
3099 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
3100 | exit (0); | |
3101 | } | |
3102 | ||
3103 | ### | |
3104 | ### Enable/Disable connection | |
3105 | ### | |
ce9abb66 | 3106 | |
c6c9630e MT |
3107 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
3108 | ||
3109 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3110 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3111 | ||
3112 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 3113 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
3114 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
3115 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3116 | #&writeserverconf(); | |
3117 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3118 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3119 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3120 | # } | |
3121 | } else { | |
3122 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
3123 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3124 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3125 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
3126 | # } | |
3127 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3128 | #&writeserverconf(); | |
3129 | } | |
3130 | } else { | |
3131 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
3132 | } |
3133 | ||
3134 | ### | |
3135 | ### Restart connection | |
3136 | ### | |
3137 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
3138 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3139 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3140 | ||
3141 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
3142 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
3143 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3144 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3145 | # } | |
6e13d0a5 | 3146 | } else { |
c6c9630e | 3147 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
3148 | } |
3149 | ||
ce9abb66 | 3150 | ### |
7c1d9faf | 3151 | # m.a.d net2net |
ce9abb66 AH |
3152 | ### |
3153 | ||
3154 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
3155 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3156 | &Header::showhttpheaders(); | |
4c962356 | 3157 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
ce9abb66 AH |
3158 | &Header::openbigbox('100%', 'LEFT', '', ''); |
3159 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
3160 | |
3161 | if ( -s "${General::swroot}/ovpn/settings") { | |
3162 | ||
49abe7af | 3163 | print <<END; |
ce9abb66 | 3164 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3165 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
ce9abb66 AH |
3166 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> |
3167 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
3168 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
3169 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
3170 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
3171 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
3172 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
e3edceeb | 3173 | <tr><td> </td><td>Import Connection Name</td></tr> |
040b8b0c | 3174 | <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>$Lang::tr{'openvpn default'}: Client Packagename</td></tr> |
54fd0535 | 3175 | <tr><td colspan='3'><hr /></td></tr> |
8c877a82 | 3176 | <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
ce9abb66 AH |
3177 | </form></table> |
3178 | END | |
3179 | ; | |
8c877a82 | 3180 | |
ce9abb66 | 3181 | |
b278daf3 | 3182 | } else { |
49abe7af | 3183 | print <<END; |
b278daf3 | 3184 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3185 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
b278daf3 | 3186 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> |
8c877a82 | 3187 | <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
b278daf3 AH |
3188 | </form></table> |
3189 | END | |
3190 | ; | |
3191 | ||
3192 | } | |
3193 | ||
ce9abb66 | 3194 | &Header::closebox(); |
4c962356 | 3195 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
ce9abb66 AH |
3196 | &Header::closebigbox(); |
3197 | &Header::closepage(); | |
3198 | exit (0); | |
3199 | ||
3200 | ### | |
7c1d9faf | 3201 | # m.a.d net2net |
ce9abb66 AH |
3202 | ### |
3203 | ||
3204 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
3205 | ||
3206 | my @firen2nconf; | |
3207 | my @confdetails; | |
3208 | my $uplconffilename =''; | |
54fd0535 | 3209 | my $uplconffilename2 =''; |
ce9abb66 | 3210 | my $uplp12name = ''; |
54fd0535 | 3211 | my $uplp12name2 = ''; |
ce9abb66 AH |
3212 | my @rem_subnet; |
3213 | my @rem_subnet2; | |
3214 | my @tmposupnet3; | |
3215 | my $key; | |
54fd0535 | 3216 | my @n2nname; |
ce9abb66 AH |
3217 | |
3218 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3219 | ||
3220 | # Check if a file is uploaded | |
3221 | ||
3222 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
3223 | $errormessage = $Lang::tr{'there was no file upload'}; | |
3224 | goto N2N_ERROR; | |
3225 | } | |
3226 | ||
3227 | # Move uploaded IPfire n2n package to temporary file | |
3228 | ||
3229 | (my $fh, my $filename) = tempfile( ); | |
3230 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3231 | $errormessage = $!; | |
3232 | goto N2N_ERROR; | |
3233 | } | |
3234 | ||
3235 | my $zip = Archive::Zip->new(); | |
3236 | my $zipName = $filename; | |
3237 | my $status = $zip->read( $zipName ); | |
3238 | if ($status != AZ_OK) { | |
3239 | $errormessage = "Read of $zipName failed\n"; | |
3240 | goto N2N_ERROR; | |
3241 | } | |
3242 | ||
3243 | my $tempdir = tempdir( CLEANUP => 1 ); | |
3244 | my @files = $zip->memberNames(); | |
3245 | for(@files) { | |
3246 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
3247 | } | |
3248 | my $countfiles = @files; | |
3249 | ||
3250 | # Check if we have not more then 2 files | |
3251 | ||
3252 | if ( $countfiles == 2){ | |
3253 | foreach (@files){ | |
3254 | if ( $_ =~ /.conf$/){ | |
3255 | $uplconffilename = $_; | |
3256 | } | |
3257 | if ( $_ =~ /.p12$/){ | |
3258 | $uplp12name = $_; | |
3259 | } | |
3260 | } | |
3261 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
3262 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
3263 | goto N2N_ERROR; | |
3264 | } | |
3265 | ||
3266 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
3267 | @firen2nconf = <FILE>; | |
3268 | close (FILE); | |
3269 | chomp(@firen2nconf); | |
ce9abb66 AH |
3270 | } else { |
3271 | ||
3272 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
3273 | goto N2N_ERROR; | |
3274 | } | |
3275 | ||
7c1d9faf AH |
3276 | ### |
3277 | # m.a.d net2net | |
ce9abb66 | 3278 | ### |
54fd0535 MT |
3279 | |
3280 | if ($cgiparams{'n2nname'} ne ''){ | |
3281 | ||
3282 | $uplconffilename2 = "$cgiparams{'n2nname'}.conf"; | |
3283 | $uplp12name2 = "$cgiparams{'n2nname'}.p12"; | |
3284 | $n2nname[0] = $cgiparams{'n2nname'}; | |
3285 | my @n2nname2 = split(/\./,$uplconffilename); | |
3286 | $n2nname2[0] =~ s/\n|\r//g; | |
3287 | my $input1 = "${General::swroot}/ovpn/certs/$uplp12name"; | |
3288 | my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2"; | |
3289 | my $input2 = "$n2nname2[0]n2n"; | |
3290 | my $output2 = "$n2nname[0]n2n"; | |
3291 | my $filename = "$tempdir/$uplconffilename"; | |
3292 | open(FILE, "< $filename") or die 'Unable to open config file.'; | |
3293 | my @current = <FILE>; | |
3294 | close(FILE); | |
3295 | foreach (@current) {s/$input1/$output1/g;} | |
3296 | foreach (@current) {s/$input2/$output2/g;} | |
3297 | open (OUT, "> $filename") || die 'Unable to open config file.'; | |
3298 | print OUT @current; | |
3299 | close OUT; | |
ce9abb66 | 3300 | |
54fd0535 MT |
3301 | }else{ |
3302 | $uplconffilename2 = $uplconffilename; | |
3303 | $uplp12name2 = $uplp12name; | |
3304 | @n2nname = split(/\./,$uplconffilename); | |
ce9abb66 | 3305 | $n2nname[0] =~ s/\n|\r//g; |
54fd0535 | 3306 | } |
7c1d9faf AH |
3307 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
3308 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
ce9abb66 | 3309 | |
7dfcaef0 AM |
3310 | #Add collectd settings to configfile |
3311 | open(FILE, ">> $tempdir/$uplconffilename") or die 'Unable to open config file.'; | |
3312 | print FILE "# Logfile\n"; | |
3313 | print FILE "status-version 1\n"; | |
3314 | print FILE "status /var/run/openvpn/$n2nname[0]-n2n 10\n"; | |
3315 | close FILE; | |
3316 | ||
54fd0535 | 3317 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2"); |
ce9abb66 AH |
3318 | |
3319 | if ($? ne 0) { | |
3320 | $errormessage = "*.conf move failed: $!"; | |
3321 | unlink ($filename); | |
3322 | goto N2N_ERROR; | |
3323 | } | |
3324 | ||
54fd0535 | 3325 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2"); |
b278daf3 AH |
3326 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; |
3327 | ||
ce9abb66 AH |
3328 | if ($? ne 0) { |
3329 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
3330 | unlink ($filename); | |
3331 | goto N2N_ERROR; | |
3332 | } | |
3333 | ||
3334 | my $complzoactive; | |
d96c89eb | 3335 | my $mssfixactive; |
4c962356 | 3336 | my $authactive; |
d96c89eb | 3337 | my $n2nfragment; |
4c962356 | 3338 | my @n2nmtudisc = split(/ /, (grep { /^mtu-disc/ } @firen2nconf)[0]); |
60f396d7 | 3339 | my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
54fd0535 | 3340 | my @n2nproto = split(/-/, $n2nproto2[1]); |
ce9abb66 AH |
3341 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); |
3342 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
3343 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
3344 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
d96c89eb AH |
3345 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
3346 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
54fd0535 | 3347 | #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]); |
d96c89eb | 3348 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); |
ce9abb66 AH |
3349 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
3350 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
3351 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
3352 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
54fd0535 | 3353 | my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]); |
ce9abb66 | 3354 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); |
4c962356 | 3355 | my @n2ncipher = split(/ /, (grep { /^cipher/ } @firen2nconf)[0]); |
f527e53f | 3356 | my @n2nauth = split(/ /, (grep { /^auth/ } @firen2nconf)[0]);; |
60f396d7 | 3357 | |
ce9abb66 AH |
3358 | ### |
3359 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
3360 | ### | |
3361 | ||
ce9abb66 | 3362 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
3363 | $n2novpnsub[0] =~ s/\n|\r//g; |
3364 | $n2novpnsub[1] =~ s/\n|\r//g; | |
3365 | $n2novpnsub[2] =~ s/\n|\r//g; | |
60f396d7 | 3366 | $n2nproto[0] =~ s/\n|\r//g; |
ce9abb66 AH |
3367 | $n2nport[1] =~ s/\n|\r//g; |
3368 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
3369 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 3370 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 3371 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 3372 | $n2nfragment[1] =~ s/\n|\r//g; |
54fd0535 | 3373 | $n2nmgmt[2] =~ s/\n|\r//g; |
2ee746be | 3374 | $n2nmtudisc[1] =~ s/\n|\r//g; |
4c962356 EK |
3375 | $n2ncipher[1] =~ s/\n|\r//g; |
3376 | $n2nauth[1] =~ s/\n|\r//g; | |
ce9abb66 | 3377 | chomp ($complzoactive); |
d96c89eb | 3378 | chomp ($mssfixactive); |
ce9abb66 AH |
3379 | |
3380 | ### | |
7c1d9faf | 3381 | # m.a.d net2net |
ce9abb66 AH |
3382 | ### |
3383 | ||
3384 | ### | |
3385 | # Check if there is no other entry with this name | |
3386 | ### | |
3387 | ||
3388 | foreach my $dkey (keys %confighash) { | |
3389 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
3390 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3391 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3392 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3393 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
ce9abb66 AH |
3394 | goto N2N_ERROR; |
3395 | } | |
3396 | } | |
3397 | ||
d96c89eb AH |
3398 | ### |
3399 | # Check if OpenVPN Subnet is valid | |
3400 | ### | |
3401 | ||
3402 | foreach my $dkey (keys %confighash) { | |
3403 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
3404 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
3405 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3406 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3407 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3408 | goto N2N_ERROR; |
3409 | } | |
3410 | } | |
3411 | ||
3412 | ### | |
4c962356 | 3413 | # Check if Dest Port is vaild |
d96c89eb AH |
3414 | ### |
3415 | ||
3416 | foreach my $dkey (keys %confighash) { | |
3417 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
3418 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
3419 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3420 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3421 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3422 | goto N2N_ERROR; |
3423 | } | |
3424 | } | |
3425 | ||
3426 | ||
3427 | ||
ce9abb66 AH |
3428 | $key = &General::findhasharraykey (\%confighash); |
3429 | ||
49abe7af | 3430 | foreach my $i (0 .. 42) { $confighash{$key}[$i] = "";} |
350f2980 | 3431 | |
ce9abb66 AH |
3432 | $confighash{$key}[0] = 'off'; |
3433 | $confighash{$key}[1] = $n2nname[0]; | |
350f2980 | 3434 | $confighash{$key}[2] = $n2nname[0]; |
ce9abb66 AH |
3435 | $confighash{$key}[3] = 'net'; |
3436 | $confighash{$key}[4] = 'cert'; | |
3437 | $confighash{$key}[6] = 'client'; | |
3438 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
350f2980 SS |
3439 | $confighash{$key}[10] = $n2nremote[1]; |
3440 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; | |
54fd0535 | 3441 | $confighash{$key}[22] = $n2nmgmt[2]; |
350f2980 | 3442 | $confighash{$key}[23] = $mssfixactive; |
d96c89eb | 3443 | $confighash{$key}[24] = $n2nfragment[1]; |
350f2980 | 3444 | $confighash{$key}[25] = 'IPFire n2n Client'; |
ce9abb66 | 3445 | $confighash{$key}[26] = 'red'; |
350f2980 SS |
3446 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; |
3447 | $confighash{$key}[28] = $n2nproto[0]; | |
3448 | $confighash{$key}[29] = $n2nport[1]; | |
3449 | $confighash{$key}[30] = $complzoactive; | |
3450 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
49abe7af | 3451 | $confighash{$key}[38] = $n2nmtudisc[1]; |
4c962356 EK |
3452 | $confighash{$key}[39] = $n2nauth[1]; |
3453 | $confighash{$key}[40] = $n2ncipher[1]; | |
49abe7af | 3454 | $confighash{$key}[41] = 'disabled'; |
ce9abb66 AH |
3455 | |
3456 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
d96c89eb | 3457 | |
ce9abb66 AH |
3458 | N2N_ERROR: |
3459 | ||
3460 | &Header::showhttpheaders(); | |
3461 | &Header::openpage('Validate imported configuration', 1, ''); | |
3462 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3463 | if ($errormessage) { | |
3464 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3465 | print "<class name='base'>$errormessage"; | |
3466 | print " </class>"; | |
3467 | &Header::closebox(); | |
3468 | ||
3469 | } else | |
3470 | { | |
3471 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
3472 | } | |
3473 | if ($errormessage eq ''){ | |
49abe7af | 3474 | print <<END; |
ce9abb66 AH |
3475 | <!-- ipfire net2net config gui --> |
3476 | <table width='100%'> | |
3477 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
3478 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
3479 | <tr><td> </td><td> </td></tr> | |
3480 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
3481 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
3482 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
4c962356 | 3483 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}:</td><td><b>$confighash{$key}[11]</b></td></tr> |
ce9abb66 AH |
3484 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> |
3485 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
3486 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
3487 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
4c962356 EK |
3488 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b>$confighash{$key}[23]</b></td></tr> |
3489 | <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 | 3490 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
350f2980 | 3491 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn mtu-disc'}</td><td><b>$confighash{$key}[38]</b></td></tr> |
54fd0535 | 3492 | <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr> |
4c962356 EK |
3493 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn hmac'}:</td><td><b>$confighash{$key}[39]</b></td></tr> |
3494 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td><td><b>$confighash{$key}[40]</b></td></tr> | |
ce9abb66 AH |
3495 | <tr><td> </td><td> </td></tr> |
3496 | </table> | |
3497 | END | |
3498 | ; | |
3499 | &Header::closebox(); | |
3500 | } | |
3501 | ||
3502 | if ($errormessage) { | |
3503 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3504 | } else { | |
3505 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
3506 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
3507 | print "<input type='hidden' name='KEY' value='$key' />"; | |
3508 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3509 | } | |
3510 | &Header::closebigbox(); | |
3511 | &Header::closepage(); | |
4c962356 | 3512 | exit(0); |
ce9abb66 AH |
3513 | |
3514 | ||
3515 | ## | |
3516 | ### Accept IPFire n2n Package Settings | |
3517 | ### | |
3518 | ||
3519 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3520 | ||
3521 | ### | |
3522 | ### Discard and Rollback IPFire n2n Package Settings | |
3523 | ### | |
3524 | ||
3525 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3526 | ||
3527 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3528 | ||
3529 | if ($confighash{$cgiparams{'KEY'}}) { | |
3530 | ||
3531 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
3532 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3533 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
3534 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
3535 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
3536 | delete $confighash{$cgiparams{'KEY'}}; | |
3537 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3538 | ||
3539 | } else { | |
3540 | $errormessage = $Lang::tr{'invalid key'}; | |
3541 | } | |
3542 | ||
3543 | ||
3544 | ### | |
7c1d9faf | 3545 | # m.a.d net2net |
ce9abb66 AH |
3546 | ### |
3547 | ||
3548 | ||
3549 | ### | |
3550 | ### Adding a new connection | |
3551 | ### | |
6e13d0a5 MT |
3552 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
3553 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
3554 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
8c877a82 | 3555 | |
6e13d0a5 MT |
3556 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
3557 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3558 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3559 | ||
3560 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
8c877a82 AM |
3561 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
3562 | $errormessage = $Lang::tr{'invalid key'}; | |
3563 | goto VPNCONF_END; | |
3564 | } | |
4c962356 EK |
3565 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; |
3566 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
3567 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
3568 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
3569 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
3570 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
3571 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
3572 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
8c877a82 | 3573 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; |
4c962356 EK |
3574 | $cgiparams{'OVPN_MGMT'} = $confighash{$cgiparams{'KEY'}}[22]; |
3575 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
3576 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
3577 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; | |
3578 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
3579 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
3580 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
3581 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
3582 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
3583 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
3584 | $cgiparams{'CHECK1'} = $confighash{$cgiparams{'KEY'}}[32]; | |
df9b48b7 | 3585 | $name=$cgiparams{'CHECK1'} ; |
4c962356 EK |
3586 | $cgiparams{$name} = $confighash{$cgiparams{'KEY'}}[33]; |
3587 | $cgiparams{'RG'} = $confighash{$cgiparams{'KEY'}}[34]; | |
3588 | $cgiparams{'CCD_DNS1'} = $confighash{$cgiparams{'KEY'}}[35]; | |
3589 | $cgiparams{'CCD_DNS2'} = $confighash{$cgiparams{'KEY'}}[36]; | |
3590 | $cgiparams{'CCD_WINS'} = $confighash{$cgiparams{'KEY'}}[37]; | |
4c962356 EK |
3591 | $cgiparams{'DAUTH'} = $confighash{$cgiparams{'KEY'}}[39]; |
3592 | $cgiparams{'DCIPHER'} = $confighash{$cgiparams{'KEY'}}[40]; | |
49abe7af | 3593 | $cgiparams{'TLSAUTH'} = $confighash{$cgiparams{'KEY'}}[41]; |
8c877a82 | 3594 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
c6c9630e | 3595 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); |
18837a6a | 3596 | |
8c877a82 | 3597 | #A.Marx CCD check iroute field and convert it to decimal |
52d08bcb | 3598 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
3599 | my @temp=(); |
3600 | my %ccdroutehash=(); | |
3601 | my $keypoint=0; | |
5068ac38 AM |
3602 | my $ip; |
3603 | my $cidr; | |
8c877a82 AM |
3604 | if ($cgiparams{'IR'} ne ''){ |
3605 | @temp = split("\n",$cgiparams{'IR'}); | |
3606 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3607 | #find key to use | |
3608 | foreach my $key (keys %ccdroutehash) { | |
3609 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3610 | $keypoint=$key; | |
3611 | delete $ccdroutehash{$key}; | |
3612 | }else{ | |
3613 | $keypoint = &General::findhasharraykey (\%ccdroutehash); | |
3614 | } | |
3615 | } | |
3616 | $ccdroutehash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3617 | my $i=1; | |
3618 | my $val=0; | |
3619 | foreach $val (@temp){ | |
3620 | chomp($val); | |
3621 | $val=~s/\s*$//g; | |
5068ac38 | 3622 | #check if iroute exists in ccdroute or if new iroute is part of an existing one |
8c877a82 AM |
3623 | foreach my $key (keys %ccdroutehash) { |
3624 | foreach my $oldiroute ( 1 .. $#{$ccdroutehash{$key}}){ | |
5068ac38 AM |
3625 | if ($ccdroutehash{$key}[$oldiroute] eq "$val") { |
3626 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3627 | goto VPNCONF_ERROR; | |
3628 | } | |
3629 | my ($ip1,$cidr1) = split (/\//, $val); | |
82c809c7 | 3630 | $ip1 = &General::getnetworkip($ip1,&General::iporsubtocidr($cidr1)); |
5068ac38 AM |
3631 | my ($ip2,$cidr2) = split (/\//, $ccdroutehash{$key}[$oldiroute]); |
3632 | if (&General::IpInSubnet ($ip1,$ip2,$cidr2)){ | |
3633 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3634 | goto VPNCONF_ERROR; | |
3635 | } | |
3636 | ||
8c877a82 AM |
3637 | } |
3638 | } | |
5068ac38 AM |
3639 | if (!&General::validipandmask($val)){ |
3640 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3641 | goto VPNCONF_ERROR; | |
3642 | }else{ | |
3643 | ($ip,$cidr) = split(/\//,$val); | |
3644 | $ip=&General::getnetworkip($ip,&General::iporsubtocidr($cidr)); | |
3645 | $cidr=&General::iporsubtodec($cidr); | |
3646 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3647 | ||
3648 | } | |
8c877a82 AM |
3649 | |
3650 | #check for existing network IP's | |
52d08bcb AM |
3651 | if (&General::IpInSubnet ($ip,$netsettings{GREEN_NETADDRESS},$netsettings{GREEN_NETMASK}) && $netsettings{GREEN_NETADDRESS} ne '0.0.0.0') |
3652 | { | |
3653 | $errormessage=$Lang::tr{'ccd err green'}; | |
3654 | goto VPNCONF_ERROR; | |
3655 | }elsif(&General::IpInSubnet ($ip,$netsettings{RED_NETADDRESS},$netsettings{RED_NETMASK}) && $netsettings{RED_NETADDRESS} ne '0.0.0.0') | |
3656 | { | |
3657 | $errormessage=$Lang::tr{'ccd err red'}; | |
3658 | goto VPNCONF_ERROR; | |
3659 | }elsif(&General::IpInSubnet ($ip,$netsettings{BLUE_NETADDRESS},$netsettings{BLUE_NETMASK}) && $netsettings{BLUE_NETADDRESS} ne '0.0.0.0' && $netsettings{BLUE_NETADDRESS} gt '') | |
3660 | { | |
3661 | $errormessage=$Lang::tr{'ccd err blue'}; | |
3662 | goto VPNCONF_ERROR; | |
3663 | }elsif(&General::IpInSubnet ($ip,$netsettings{ORANGE_NETADDRESS},$netsettings{ORANGE_NETMASK}) && $netsettings{ORANGE_NETADDRESS} ne '0.0.0.0' && $netsettings{ORANGE_NETADDRESS} gt '' ) | |
3664 | { | |
3665 | $errormessage=$Lang::tr{'ccd err orange'}; | |
8c877a82 AM |
3666 | goto VPNCONF_ERROR; |
3667 | } | |
52d08bcb | 3668 | |
8c877a82 AM |
3669 | if (&General::validipandmask($val)){ |
3670 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3671 | }else{ | |
3672 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($ip/$cidr)"; | |
3673 | goto VPNCONF_ERROR; | |
3674 | } | |
3675 | $i++; | |
3676 | } | |
3677 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3678 | &writeserverconf; | |
3679 | }else{ | |
3680 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3681 | foreach my $key (keys %ccdroutehash) { | |
3682 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3683 | delete $ccdroutehash{$key}; | |
3684 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3685 | &writeserverconf; | |
3686 | } | |
3687 | } | |
3688 | } | |
3689 | undef @temp; | |
3690 | #check route field and convert it to decimal | |
8c877a82 AM |
3691 | my $val=0; |
3692 | my $i=1; | |
8c877a82 | 3693 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
52d08bcb AM |
3694 | #find key to use |
3695 | foreach my $key (keys %ccdroute2hash) { | |
3696 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
3697 | $keypoint=$key; | |
3698 | delete $ccdroute2hash{$key}; | |
3699 | }else{ | |
3700 | $keypoint = &General::findhasharraykey (\%ccdroute2hash); | |
3701 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3702 | &writeserverconf; | |
8c877a82 | 3703 | } |
52d08bcb AM |
3704 | } |
3705 | $ccdroute2hash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3706 | if ($cgiparams{'IFROUTE'} eq ''){$cgiparams{'IFROUTE'} = $Lang::tr{'ccd none'};} | |
3707 | @temp = split(/\|/,$cgiparams{'IFROUTE'}); | |
3708 | my %ownnet=(); | |
3709 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
3710 | foreach $val (@temp){ | |
3711 | chomp($val); | |
3712 | $val=~s/\s*$//g; | |
3713 | if ($val eq $Lang::tr{'green'}) | |
3714 | { | |
3715 | $val=$ownnet{GREEN_NETADDRESS}."/".$ownnet{GREEN_NETMASK}; | |
3716 | } | |
3717 | if ($val eq $Lang::tr{'blue'}) | |
3718 | { | |
3719 | $val=$ownnet{BLUE_NETADDRESS}."/".$ownnet{BLUE_NETMASK}; | |
3720 | } | |
3721 | if ($val eq $Lang::tr{'orange'}) | |
3722 | { | |
3723 | $val=$ownnet{ORANGE_NETADDRESS}."/".$ownnet{ORANGE_NETMASK}; | |
3724 | } | |
3725 | my ($ip,$cidr) = split (/\//, $val); | |
3726 | ||
3727 | if ($val ne $Lang::tr{'ccd none'}) | |
3728 | { | |
8c877a82 AM |
3729 | if (! &check_routes_push($val)){$errormessage=$errormessage."Route $val ".$Lang::tr{'ccd err routeovpn2'}." ($val)";goto VPNCONF_ERROR;} |
3730 | if (! &check_ccdroute($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err inuse'}." ($val)" ;goto VPNCONF_ERROR;} | |
3731 | if (! &check_ccdconf($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err routeovpn'}." ($val)";goto VPNCONF_ERROR;} | |
3732 | if (&General::validipandmask($val)){ | |
3733 | $val=$ip."/".&General::iporsubtodec($cidr); | |
3734 | $ccdroute2hash{$keypoint}[$i] = $val; | |
3735 | }else{ | |
3736 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3737 | goto VPNCONF_ERROR; | |
3738 | } | |
52d08bcb AM |
3739 | }else{ |
3740 | $ccdroute2hash{$keypoint}[$i]=''; | |
3741 | } | |
3742 | $i++; | |
3743 | } | |
3744 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
3745 | ||
8c877a82 AM |
3746 | #check dns1 ip |
3747 | if ($cgiparams{'CCD_DNS1'} ne '' && ! &General::validip($cgiparams{'CCD_DNS1'})) { | |
3748 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 1"; | |
3749 | goto VPNCONF_ERROR; | |
3750 | } | |
3751 | #check dns2 ip | |
3752 | if ($cgiparams{'CCD_DNS2'} ne '' && ! &General::validip($cgiparams{'CCD_DNS2'})) { | |
3753 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 2"; | |
3754 | goto VPNCONF_ERROR; | |
3755 | } | |
3756 | #check wins ip | |
3757 | if ($cgiparams{'CCD_WINS'} ne '' && ! &General::validip($cgiparams{'CCD_WINS'})) { | |
3758 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp wins'}; | |
3759 | goto VPNCONF_ERROR; | |
3760 | } | |
52d08bcb | 3761 | } |
8c877a82 AM |
3762 | |
3763 | #CCD End | |
52d08bcb | 3764 | |
8c877a82 AM |
3765 | |
3766 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
c6c9630e | 3767 | $errormessage = $Lang::tr{'connection type is invalid'}; |
b278daf3 AH |
3768 | if ($cgiparams{'TYPE'} eq 'net') { |
3769 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3770 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3771 | } | |
c6c9630e MT |
3772 | goto VPNCONF_ERROR; |
3773 | } | |
3774 | ||
3775 | ||
3776 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
3777 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
b278daf3 AH |
3778 | if ($cgiparams{'TYPE'} eq 'net') { |
3779 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3780 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3781 | } | |
3782 | goto VPNCONF_ERROR; | |
3783 | } | |
c6c9630e MT |
3784 | |
3785 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
3786 | $errormessage = $Lang::tr{'name is invalid'}; | |
b278daf3 AH |
3787 | if ($cgiparams{'TYPE'} eq 'net') { |
3788 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3789 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3790 | } | |
c6c9630e MT |
3791 | goto VPNCONF_ERROR; |
3792 | } | |
3793 | ||
3794 | if (length($cgiparams{'NAME'}) >60) { | |
3795 | $errormessage = $Lang::tr{'name too long'}; | |
b278daf3 AH |
3796 | if ($cgiparams{'TYPE'} eq 'net') { |
3797 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3798 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3799 | } | |
c6c9630e MT |
3800 | goto VPNCONF_ERROR; |
3801 | } | |
3802 | ||
d96c89eb | 3803 | ### |
7c1d9faf | 3804 | # m.a.d net2net |
d96c89eb AH |
3805 | ### |
3806 | ||
7c1d9faf | 3807 | if ($cgiparams{'TYPE'} eq 'net') { |
ab4cf06c | 3808 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { |
cd0c0a0d | 3809 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
b278daf3 AH |
3810 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3811 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3812 | goto VPNCONF_ERROR; | |
d96c89eb | 3813 | } |
ab4cf06c AM |
3814 | #Bugfix 10357 |
3815 | foreach my $key (sort keys %confighash){ | |
3816 | 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 |
3817 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
3818 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3819 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ab4cf06c AM |
3820 | goto VPNCONF_ERROR; |
3821 | } | |
3822 | } | |
3823 | if ($cgiparams{'DEST_PORT'} eq '') { | |
3824 | $errormessage = $Lang::tr{'invalid port'}; | |
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: $!"; | |
54fd0535 MT |
3827 | goto VPNCONF_ERROR; |
3828 | } | |
d96c89eb | 3829 | |
f48074ba SS |
3830 | # Check if the input for the transfer net is valid. |
3831 | if (!&General::validipandmask($cgiparams{'OVPN_SUBNET'})){ | |
3832 | $errormessage = $Lang::tr{'ccd err invalidnet'}; | |
3833 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3834 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3835 | goto VPNCONF_ERROR; | |
3836 | } | |
3837 | ||
d96c89eb | 3838 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { |
cd0c0a0d | 3839 | $errormessage = $Lang::tr{'openvpn subnet is used'}; |
b278daf3 AH |
3840 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3841 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3842 | goto VPNCONF_ERROR; |
3843 | } | |
3844 | ||
3845 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
cd0c0a0d | 3846 | $errormessage = $Lang::tr{'openvpn mssfix allowed with udp'}; |
b278daf3 AH |
3847 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3848 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3849 | goto VPNCONF_ERROR; |
3850 | } | |
3851 | ||
3852 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
cd0c0a0d | 3853 | $errormessage = $Lang::tr{'openvpn fragment allowed with udp'}; |
b278daf3 AH |
3854 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3855 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3856 | goto VPNCONF_ERROR; |
3857 | } | |
d96c89eb | 3858 | |
7c1d9faf | 3859 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
cd0c0a0d | 3860 | $errormessage = $Lang::tr{'openvpn prefix local subnet'}; |
b278daf3 AH |
3861 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3862 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3863 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3864 | } |
3865 | ||
3866 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
cd0c0a0d | 3867 | $errormessage = $Lang::tr{'openvpn prefix openvpn subnet'}; |
b278daf3 AH |
3868 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3869 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3870 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
3871 | } |
3872 | ||
3873 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
cd0c0a0d | 3874 | $errormessage = $Lang::tr{'openvpn prefix remote subnet'}; |
b278daf3 AH |
3875 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3876 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3877 | goto VPNCONF_ERROR; | |
8c252e6a EK |
3878 | } |
3879 | ||
3880 | if ($cgiparams{'DEST_PORT'} <= 1023) { | |
3881 | $errormessage = $Lang::tr{'ovpn port in root range'}; | |
3882 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3883 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3884 | goto VPNCONF_ERROR; | |
3885 | } | |
54fd0535 | 3886 | |
4c962356 | 3887 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c252e6a EK |
3888 | $cgiparams{'OVPN_MGMT'} = $cgiparams{'DEST_PORT'}; |
3889 | } | |
3890 | ||
3891 | if ($cgiparams{'OVPN_MGMT'} <= 1023) { | |
3892 | $errormessage = $Lang::tr{'ovpn mgmt in root range'}; | |
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: $!"; | |
3895 | goto VPNCONF_ERROR; | |
b2e75449 MT |
3896 | } |
3897 | #Check if remote subnet is used elsewhere | |
3898 | my ($n2nip,$n2nsub)=split("/",$cgiparams{'REMOTE_SUBNET'}); | |
3899 | $warnmessage=&General::checksubnets('',$n2nip,'ovpn'); | |
3900 | if ($warnmessage){ | |
3901 | $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage; | |
3902 | } | |
7c1d9faf | 3903 | } |
d96c89eb | 3904 | |
ce9abb66 AH |
3905 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
3906 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
3907 | # goto VPNCONF_ERROR; | |
3908 | # } | |
3909 | ||
c6c9630e MT |
3910 | # Check if there is no other entry with this name |
3911 | if (! $cgiparams{'KEY'}) { | |
3912 | foreach my $key (keys %confighash) { | |
3913 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
3914 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3915 | if ($cgiparams{'TYPE'} eq 'net') { |
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 | } | |
c6c9630e | 3919 | goto VPNCONF_ERROR; |
6e13d0a5 | 3920 | } |
c6c9630e MT |
3921 | } |
3922 | } | |
3923 | ||
c125d8a2 | 3924 | # Check if a remote host/IP has been set for the client. |
86228a56 MT |
3925 | if ($cgiparams{'TYPE'} eq 'net') { |
3926 | if ($cgiparams{'SIDE'} ne 'server' && $cgiparams{'REMOTE'} eq '') { | |
3927 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3928 | |
86228a56 MT |
3929 | # Check if this is a N2N connection and drop temporary config. |
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: $!"; | |
ce9abb66 | 3932 | |
86228a56 MT |
3933 | goto VPNCONF_ERROR; |
3934 | } | |
c125d8a2 | 3935 | |
86228a56 MT |
3936 | # Check if a remote host/IP has been configured - the field can be empty on the server side. |
3937 | if ($cgiparams{'REMOTE'} ne '') { | |
3938 | # Check if the given IP is valid - otherwise check if it is a valid domain. | |
3939 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
3940 | # Check for a valid domain. | |
3941 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
3942 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3943 | |
86228a56 MT |
3944 | # Check if this is a N2N connection and drop temporary config. |
3945 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3946 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
c125d8a2 | 3947 | |
86228a56 MT |
3948 | goto VPNCONF_ERROR; |
3949 | } | |
3950 | } | |
6e13d0a5 | 3951 | } |
c6c9630e | 3952 | } |
c125d8a2 | 3953 | |
c6c9630e MT |
3954 | if ($cgiparams{'TYPE'} ne 'host') { |
3955 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
3956 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
b278daf3 AH |
3957 | if ($cgiparams{'TYPE'} eq 'net') { |
3958 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3959 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3960 | } | |
c6c9630e MT |
3961 | goto VPNCONF_ERROR;} |
3962 | } | |
3963 | # Check if there is no other entry without IP-address and PSK | |
3964 | if ($cgiparams{'REMOTE'} eq '') { | |
3965 | foreach my $key (keys %confighash) { | |
3966 | if(($cgiparams{'KEY'} ne $key) && | |
3967 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
3968 | $confighash{$key}[10] eq '') { | |
3969 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
3970 | goto VPNCONF_ERROR; | |
6e13d0a5 | 3971 | } |
c6c9630e MT |
3972 | } |
3973 | } | |
ce9abb66 AH |
3974 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
3975 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
3976 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3977 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3978 | goto VPNCONF_ERROR; | |
ce9abb66 | 3979 | } |
c6c9630e | 3980 | |
425465ed EK |
3981 | # Check for N2N that OpenSSL maximum of valid days will not be exceeded |
3982 | if ($cgiparams{'TYPE'} eq 'net') { | |
3983 | if ($cgiparams{'DAYS_VALID'} >= '999999') { | |
3984 | $errormessage = $Lang::tr{'invalid input for valid till days'}; | |
3985 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3986 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3987 | goto VPNCONF_ERROR; | |
3988 | } | |
3989 | } | |
3990 | ||
c6c9630e MT |
3991 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { |
3992 | $errormessage = $Lang::tr{'invalid input'}; | |
3993 | goto VPNCONF_ERROR; | |
3994 | } | |
3995 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
3996 | $errormessage = $Lang::tr{'invalid input'}; | |
3997 | goto VPNCONF_ERROR; | |
3998 | } | |
3999 | ||
4000 | #fixplausi | |
4001 | if ($cgiparams{'AUTH'} eq 'psk') { | |
4002 | # if (! length($cgiparams{'PSK'}) ) { | |
4003 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
4004 | # goto VPNCONF_ERROR; | |
4005 | # } | |
4006 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
4007 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
4008 | # goto VPNCONF_ERROR; | |
4009 | # } | |
4010 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
4011 | if ($cgiparams{'KEY'}) { | |
4012 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4013 | goto VPNCONF_ERROR; | |
4014 | } | |
4015 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
4016 | $errormessage = $Lang::tr{'there was no file upload'}; | |
4017 | goto VPNCONF_ERROR; | |
4018 | } | |
4019 | ||
4020 | # Move uploaded certificate request to a temporary file | |
4021 | (my $fh, my $filename) = tempfile( ); | |
4022 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4023 | $errormessage = $!; | |
4024 | goto VPNCONF_ERROR; | |
4025 | } | |
6e13d0a5 | 4026 | |
c6c9630e MT |
4027 | # Sign the certificate request and move it |
4028 | # Sign the host certificate request | |
f6e12093 | 4029 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4030 | '-batch', '-notext', |
4031 | '-in', $filename, | |
4032 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4033 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4034 | if ($?) { | |
4035 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4036 | unlink ($filename); | |
4037 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4038 | &newcleanssldatabase(); | |
4039 | goto VPNCONF_ERROR; | |
4040 | } else { | |
4041 | unlink ($filename); | |
4042 | &deletebackupcert(); | |
4043 | } | |
4044 | ||
4045 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
87ea30ff | 4046 | $temp =~ /Subject:.*CN\s?=\s?(.*)[\n]/; |
c6c9630e MT |
4047 | $temp = $1; |
4048 | $temp =~ s+/Email+, E+; | |
4049 | $temp =~ s/ ST=/ S=/; | |
4050 | $cgiparams{'CERT_NAME'} = $temp; | |
4051 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4052 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4053 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4054 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4055 | goto VPNCONF_ERROR; | |
4056 | } | |
4057 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
4058 | if ($cgiparams{'KEY'}) { | |
4059 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4060 | goto VPNCONF_ERROR; | |
4061 | } | |
4062 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
4063 | $errormessage = $Lang::tr{'there was no file upload'}; | |
4064 | goto VPNCONF_ERROR; | |
4065 | } | |
4066 | # Move uploaded certificate to a temporary file | |
4067 | (my $fh, my $filename) = tempfile( ); | |
4068 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4069 | $errormessage = $!; | |
4070 | goto VPNCONF_ERROR; | |
4071 | } | |
4072 | ||
4073 | # Verify the certificate has a valid CA and move it | |
4074 | my $validca = 0; | |
4075 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename`; | |
4076 | if ($test =~ /: OK/) { | |
4077 | $validca = 1; | |
4078 | } else { | |
4079 | foreach my $key (keys %cahash) { | |
4080 | $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem $filename`; | |
4081 | if ($test =~ /: OK/) { | |
4082 | $validca = 1; | |
4083 | } | |
6e13d0a5 | 4084 | } |
c6c9630e MT |
4085 | } |
4086 | if (! $validca) { | |
4087 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
4088 | unlink ($filename); | |
4089 | goto VPNCONF_ERROR; | |
4090 | } else { | |
4091 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4092 | if ($? ne 0) { | |
4093 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
4094 | unlink ($filename); | |
4095 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4096 | } |
c6c9630e MT |
4097 | } |
4098 | ||
4099 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
87ea30ff | 4100 | $temp =~ /Subject:.*CN\s?=\s?(.*)[\n]/; |
c6c9630e MT |
4101 | $temp = $1; |
4102 | $temp =~ s+/Email+, E+; | |
4103 | $temp =~ s/ ST=/ S=/; | |
4104 | $cgiparams{'CERT_NAME'} = $temp; | |
4105 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4106 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4107 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4108 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4109 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4110 | goto VPNCONF_ERROR; | |
4111 | } | |
4112 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
4113 | if ($cgiparams{'KEY'}) { | |
4114 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4115 | goto VPNCONF_ERROR; | |
4116 | } | |
4117 | # Validate input since the form was submitted | |
4118 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
4119 | $errormessage = $Lang::tr{'name too long'}; | |
4120 | goto VPNCONF_ERROR; | |
4121 | } | |
194314b2 | 4122 | if ($cgiparams{'CERT_NAME'} eq '' || $cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { |
c6c9630e MT |
4123 | $errormessage = $Lang::tr{'invalid input for name'}; |
4124 | goto VPNCONF_ERROR; | |
4125 | } | |
4126 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
4127 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
4128 | goto VPNCONF_ERROR; | |
4129 | } | |
4130 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
4131 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
4132 | goto VPNCONF_ERROR; | |
4133 | } | |
4134 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4135 | $errormessage = $Lang::tr{'invalid input for department'}; | |
4136 | goto VPNCONF_ERROR; | |
4137 | } | |
4138 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
4139 | $errormessage = $Lang::tr{'organization too long'}; | |
4140 | goto VPNCONF_ERROR; | |
4141 | } | |
4142 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
4143 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
4144 | goto VPNCONF_ERROR; | |
4145 | } | |
4146 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4147 | $errormessage = $Lang::tr{'invalid input for city'}; | |
4148 | goto VPNCONF_ERROR; | |
4149 | } | |
4150 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4151 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
4152 | goto VPNCONF_ERROR; | |
4153 | } | |
4154 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
4155 | $errormessage = $Lang::tr{'invalid input for country'}; | |
4156 | goto VPNCONF_ERROR; | |
4157 | } | |
4158 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
4159 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
4160 | $errormessage = $Lang::tr{'password too short'}; | |
4161 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4162 | } |
c6c9630e MT |
4163 | } |
4164 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
4165 | $errormessage = $Lang::tr{'passwords do not match'}; | |
4166 | goto VPNCONF_ERROR; | |
4167 | } | |
425465ed | 4168 | if ($cgiparams{'DAYS_VALID'} eq '' && $cgiparams{'DAYS_VALID'} !~ /^[0-9]+$/) { |
f4fbb935 EK |
4169 | $errormessage = $Lang::tr{'invalid input for valid till days'}; |
4170 | goto VPNCONF_ERROR; | |
4171 | } | |
c6c9630e | 4172 | |
425465ed EK |
4173 | # Check for RW that OpenSSL maximum of valid days will not be exceeded |
4174 | if ($cgiparams{'TYPE'} eq 'host') { | |
4175 | if ($cgiparams{'DAYS_VALID'} >= '999999') { | |
4176 | $errormessage = $Lang::tr{'invalid input for valid till days'}; | |
4177 | goto VPNCONF_ERROR; | |
4178 | } | |
4179 | } | |
4180 | ||
beac479f EK |
4181 | # Check for RW if client name is already set |
4182 | if ($cgiparams{'TYPE'} eq 'host') { | |
4183 | foreach my $key (keys %confighash) { | |
4184 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
4185 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
4186 | goto VPNCONF_ERROR; | |
4187 | } | |
4188 | } | |
4189 | } | |
4190 | ||
c6c9630e MT |
4191 | # Replace empty strings with a . |
4192 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
4193 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
4194 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
4195 | ||
4196 | # Create the Host certificate request client | |
4197 | my $pid = open(OPENSSL, "|-"); | |
4198 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
4199 | if ($pid) { # parent | |
4200 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
4201 | print OPENSSL "$state\n"; | |
4202 | print OPENSSL "$city\n"; | |
4203 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
4204 | print OPENSSL "$ou\n"; | |
4205 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
4206 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
4207 | print OPENSSL ".\n"; | |
4208 | print OPENSSL ".\n"; | |
4209 | close (OPENSSL); | |
4210 | if ($?) { | |
4211 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4212 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4213 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4214 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4215 | } |
c6c9630e | 4216 | } else { # child |
badd8c1c | 4217 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
4c962356 | 4218 | '-newkey', 'rsa:2048', |
c6c9630e MT |
4219 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", |
4220 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4221 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
4222 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
4223 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4224 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4225 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4226 | } |
c6c9630e MT |
4227 | } |
4228 | ||
4229 | # Sign the host certificate request | |
f6e12093 | 4230 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4231 | '-batch', '-notext', |
4232 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4233 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4234 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4235 | if ($?) { | |
4236 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4237 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4238 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4239 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4240 | &newcleanssldatabase(); | |
4241 | goto VPNCONF_ERROR; | |
4242 | } else { | |
4243 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4244 | &deletebackupcert(); | |
4245 | } | |
4246 | ||
4247 | # Create the pkcs12 file | |
4248 | system('/usr/bin/openssl', 'pkcs12', '-export', | |
4249 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
4250 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4251 | '-name', $cgiparams{'NAME'}, | |
4252 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
4253 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
4254 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
4255 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4256 | if ($?) { | |
4257 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4258 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4259 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4260 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4261 | goto VPNCONF_ERROR; | |
4262 | } else { | |
4263 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4264 | } | |
4265 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
4266 | ;# Nothing, just editing | |
4267 | } else { | |
4268 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
4269 | goto VPNCONF_ERROR; | |
4270 | } | |
4271 | ||
4272 | # Check if there is no other entry with this common name | |
4273 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
4274 | foreach my $key (keys %confighash) { | |
4275 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
4276 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
4277 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4278 | } |
c6c9630e MT |
4279 | } |
4280 | } | |
4281 | ||
ab4cf06c | 4282 | # Save the config |
c6c9630e | 4283 | my $key = $cgiparams{'KEY'}; |
8c877a82 | 4284 | |
c6c9630e MT |
4285 | if (! $key) { |
4286 | $key = &General::findhasharraykey (\%confighash); | |
49abe7af | 4287 | foreach my $i (0 .. 43) { $confighash{$key}[$i] = "";} |
c6c9630e | 4288 | } |
8c877a82 AM |
4289 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; |
4290 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
c6c9630e | 4291 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { |
8c877a82 | 4292 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; |
c6c9630e | 4293 | } |
8c877a82 AM |
4294 | |
4295 | $confighash{$key}[3] = $cgiparams{'TYPE'}; | |
c6c9630e | 4296 | if ($cgiparams{'AUTH'} eq 'psk') { |
8c877a82 AM |
4297 | $confighash{$key}[4] = 'psk'; |
4298 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
c6c9630e | 4299 | } else { |
8c877a82 | 4300 | $confighash{$key}[4] = 'cert'; |
c6c9630e | 4301 | } |
ce9abb66 | 4302 | if ($cgiparams{'TYPE'} eq 'net') { |
8c877a82 AM |
4303 | $confighash{$key}[6] = $cgiparams{'SIDE'}; |
4304 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
ce9abb66 | 4305 | } |
4c962356 | 4306 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
8c877a82 | 4307 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; |
4c962356 | 4308 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c877a82 | 4309 | $confighash{$key}[22] = $confighash{$key}[29]; |
4c962356 | 4310 | } else { |
8c877a82 | 4311 | $confighash{$key}[22] = $cgiparams{'OVPN_MGMT'}; |
4c962356 | 4312 | } |
8c877a82 AM |
4313 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
4314 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
4315 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
4316 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
c6c9630e | 4317 | # new fields |
8c877a82 AM |
4318 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; |
4319 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
4320 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
4321 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
4322 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
4323 | $confighash{$key}[32] = $cgiparams{'CHECK1'}; | |
df9b48b7 | 4324 | $name=$cgiparams{'CHECK1'}; |
8c877a82 AM |
4325 | $confighash{$key}[33] = $cgiparams{$name}; |
4326 | $confighash{$key}[34] = $cgiparams{'RG'}; | |
4327 | $confighash{$key}[35] = $cgiparams{'CCD_DNS1'}; | |
4328 | $confighash{$key}[36] = $cgiparams{'CCD_DNS2'}; | |
4329 | $confighash{$key}[37] = $cgiparams{'CCD_WINS'}; | |
4c962356 EK |
4330 | $confighash{$key}[39] = $cgiparams{'DAUTH'}; |
4331 | $confighash{$key}[40] = $cgiparams{'DCIPHER'}; | |
350f2980 | 4332 | |
71af643c MT |
4333 | if (($cgiparams{'TYPE'} eq 'host') && ($cgiparams{'CERT_PASS1'} eq "")) { |
4334 | $confighash{$key}[41] = "no-pass"; | |
4335 | } | |
4336 | ||
c6c9630e | 4337 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
8c877a82 AM |
4338 | |
4339 | if ($cgiparams{'CHECK1'} ){ | |
4340 | ||
4341 | my ($ccdip,$ccdsub)=split "/",$cgiparams{$name}; | |
4342 | my ($a,$b,$c,$d) = split (/\./,$ccdip); | |
df9b48b7 AM |
4343 | if ( -e "${General::swroot}/ovpn/ccd/$confighash{$key}[2]"){ |
4344 | unlink "${General::swroot}/ovpn/ccd/$cgiparams{'CERT_NAME'}"; | |
4345 | } | |
8c877a82 | 4346 | open ( CCDRWCONF,'>',"${General::swroot}/ovpn/ccd/$confighash{$key}[2]") or die "Unable to create clientconfigfile $!"; |
82c809c7 | 4347 | print CCDRWCONF "# OpenVPN clientconfig from ccd extension by Copymaster#\n\n"; |
8c877a82 AM |
4348 | if($cgiparams{'CHECK1'} eq 'dynamic'){ |
4349 | print CCDRWCONF "#This client uses the dynamic pool\n"; | |
4350 | }else{ | |
82c809c7 | 4351 | print CCDRWCONF "#Ip address client and server\n"; |
8c877a82 AM |
4352 | print CCDRWCONF "ifconfig-push $ccdip ".&General::getlastip($ccdip,1)."\n"; |
4353 | } | |
4354 | if ($confighash{$key}[34] eq 'on'){ | |
4355 | print CCDRWCONF "\n#Redirect Gateway: \n#All IP traffic is redirected through the vpn \n"; | |
4356 | print CCDRWCONF "push redirect-gateway\n"; | |
4357 | } | |
52d08bcb | 4358 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 4359 | if ($cgiparams{'IR'} ne ''){ |
82c809c7 | 4360 | print CCDRWCONF "\n#Client routes these networks (behind Client)\n"; |
8c877a82 AM |
4361 | foreach my $key (keys %ccdroutehash){ |
4362 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}){ | |
4363 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
4364 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
4365 | print CCDRWCONF "iroute $a $b\n"; | |
4366 | } | |
4367 | } | |
4368 | } | |
4369 | } | |
52d08bcb | 4370 | if ($cgiparams{'IFROUTE'} eq $Lang::tr{'ccd none'} ){$cgiparams{'IFROUTE'}='';} |
8c877a82 | 4371 | if ($cgiparams{'IFROUTE'} ne ''){ |
82c809c7 | 4372 | print CCDRWCONF "\n#Client gets routes to these networks (behind IPFire)\n"; |
8c877a82 AM |
4373 | foreach my $key (keys %ccdroute2hash){ |
4374 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4375 | foreach my $i ( 1 .. $#{$ccdroute2hash{$key}}){ | |
4376 | if($ccdroute2hash{$key}[$i] eq $Lang::tr{'blue'}){ | |
4377 | my %blue=(); | |
4378 | &General::readhash("${General::swroot}/ethernet/settings", \%blue); | |
52d08bcb | 4379 | print CCDRWCONF "push \"route $blue{BLUE_ADDRESS} $blue{BLUE_NETMASK}\n"; |
8c877a82 AM |
4380 | }elsif($ccdroute2hash{$key}[$i] eq $Lang::tr{'orange'}){ |
4381 | my %orange=(); | |
4382 | &General::readhash("${General::swroot}/ethernet/settings", \%orange); | |
4383 | print CCDRWCONF "push \"route $orange{ORANGE_ADDRESS} $orange{ORANGE_NETMASK}\n"; | |
4384 | }else{ | |
4385 | my ($a,$b)=split (/\//,$ccdroute2hash{$key}[$i]); | |
4386 | print CCDRWCONF "push \"route $a $b\"\n"; | |
4387 | } | |
4388 | } | |
4389 | } | |
4390 | } | |
4391 | } | |
4392 | if(($cgiparams{'CCD_DNS1'} eq '') && ($cgiparams{'CCD_DNS1'} ne '')){ $cgiparams{'CCD_DNS1'} = $cgiparams{'CCD_DNS2'};$cgiparams{'CCD_DNS2'}='';} | |
4393 | if($cgiparams{'CCD_DNS1'} ne ''){ | |
82c809c7 | 4394 | print CCDRWCONF "\n#Client gets these nameservers\n"; |
8c877a82 AM |
4395 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS1'}\" \n"; |
4396 | } | |
4397 | if($cgiparams{'CCD_DNS2'} ne ''){ | |
4398 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS2'}\" \n"; | |
4399 | } | |
4400 | if($cgiparams{'CCD_WINS'} ne ''){ | |
4401 | print CCDRWCONF "\n#Client gets this WINS server\n"; | |
4402 | print CCDRWCONF "push \"dhcp-option WINS $cgiparams{'CCD_WINS'}\" \n"; | |
4403 | } | |
4404 | close CCDRWCONF; | |
4405 | } | |
18837a6a AH |
4406 | |
4407 | ### | |
4408 | # m.a.d n2n begin | |
4409 | ### | |
4410 | ||
4411 | if ($cgiparams{'TYPE'} eq 'net') { | |
4412 | ||
4413 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
4414 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4415 | ||
4416 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4417 | my $key = $cgiparams{'KEY'}; | |
4418 | if (! $key) { | |
4419 | $key = &General::findhasharraykey (\%confighash); | |
4420 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
4421 | } | |
4422 | $confighash{$key}[0] = 'on'; | |
4423 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
4424 | ||
4425 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
4426 | } | |
4427 | } | |
4428 | ||
4429 | ### | |
4430 | # m.a.d n2n end | |
4431 | ### | |
4432 | ||
c6c9630e MT |
4433 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { |
4434 | $cgiparams{'KEY'} = $key; | |
4435 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
4436 | } | |
4437 | goto VPNCONF_END; | |
6e13d0a5 | 4438 | } else { |
c6c9630e | 4439 | $cgiparams{'ENABLED'} = 'on'; |
54fd0535 MT |
4440 | ### |
4441 | # m.a.d n2n begin | |
4442 | ### | |
4443 | $cgiparams{'MSSFIX'} = 'on'; | |
4444 | $cgiparams{'FRAGMENT'} = '1300'; | |
70900745 | 4445 | $cgiparams{'DAUTH'} = 'SHA512'; |
54fd0535 MT |
4446 | ### |
4447 | # m.a.d n2n end | |
4448 | ### | |
4c962356 | 4449 | $cgiparams{'SIDE'} = 'left'; |
c6c9630e MT |
4450 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { |
4451 | $cgiparams{'AUTH'} = 'psk'; | |
4452 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4453 | $cgiparams{'AUTH'} = 'certfile'; | |
4454 | } else { | |
6e13d0a5 | 4455 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
4456 | } |
4457 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
4458 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
4459 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
4460 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
4461 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
c0a7c9b2 | 4462 | $cgiparams{'DAYS_VALID'} = $vpnsettings{'DAYS_VALID'} = '730'; |
6e13d0a5 | 4463 | } |
c6c9630e | 4464 | |
6e13d0a5 | 4465 | VPNCONF_ERROR: |
6e13d0a5 MT |
4466 | $checked{'ENABLED'}{'off'} = ''; |
4467 | $checked{'ENABLED'}{'on'} = ''; | |
4468 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4469 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4470 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4471 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4472 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4473 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4474 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4475 | |
4476 | ||
6e13d0a5 MT |
4477 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
4478 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
4479 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 4480 | |
6e13d0a5 MT |
4481 | $selected{'SIDE'}{'server'} = ''; |
4482 | $selected{'SIDE'}{'client'} = ''; | |
4483 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
d96c89eb AH |
4484 | |
4485 | $selected{'PROTOCOL'}{'udp'} = ''; | |
4486 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
4487 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
4488 | ||
c6c9630e | 4489 | |
6e13d0a5 MT |
4490 | $checked{'AUTH'}{'psk'} = ''; |
4491 | $checked{'AUTH'}{'certreq'} = ''; | |
4492 | $checked{'AUTH'}{'certgen'} = ''; | |
4493 | $checked{'AUTH'}{'certfile'} = ''; | |
4494 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 4495 | |
6e13d0a5 | 4496 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
c6c9630e | 4497 | |
6e13d0a5 MT |
4498 | $checked{'COMPLZO'}{'off'} = ''; |
4499 | $checked{'COMPLZO'}{'on'} = ''; | |
4500 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 4501 | |
d96c89eb AH |
4502 | $checked{'MSSFIX'}{'off'} = ''; |
4503 | $checked{'MSSFIX'}{'on'} = ''; | |
4504 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4505 | ||
52f61e49 EKD |
4506 | $selected{'DCIPHER'}{'AES-256-GCM'} = ''; |
4507 | $selected{'DCIPHER'}{'AES-192-GCM'} = ''; | |
4508 | $selected{'DCIPHER'}{'AES-128-GCM'} = ''; | |
4c962356 EK |
4509 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
4510 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
4511 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
4512 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4513 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4514 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
4515 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4516 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; | |
4517 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
4518 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4519 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4520 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 4521 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
49abe7af EK |
4522 | # If no cipher has been chossen yet, select |
4523 | # the old default (AES-256-CBC) for compatiblity reasons. | |
4524 | if ($cgiparams{'DCIPHER'} eq '') { | |
4525 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; | |
4526 | } | |
4c962356 | 4527 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
49abe7af EK |
4528 | $selected{'DAUTH'}{'whirlpool'} = ''; |
4529 | $selected{'DAUTH'}{'SHA512'} = ''; | |
4530 | $selected{'DAUTH'}{'SHA384'} = ''; | |
4531 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4532 | $selected{'DAUTH'}{'SHA1'} = ''; | |
4533 | # If no hash algorythm has been choosen yet, select | |
4534 | # the old default value (SHA1) for compatiblity reasons. | |
4535 | if ($cgiparams{'DAUTH'} eq '') { | |
4536 | $cgiparams{'DAUTH'} = 'SHA1'; | |
4537 | } | |
4538 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
4539 | ||
6e13d0a5 MT |
4540 | if (1) { |
4541 | &Header::showhttpheaders(); | |
4c962356 | 4542 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
4543 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
4544 | if ($errormessage) { | |
4545 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4546 | print "<class name='base'>$errormessage"; | |
4547 | print " </class>"; | |
4548 | &Header::closebox(); | |
4549 | } | |
c6c9630e | 4550 | |
6e13d0a5 MT |
4551 | if ($warnmessage) { |
4552 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
4553 | print "<class name='base'>$warnmessage"; | |
4554 | print " </class>"; | |
4555 | &Header::closebox(); | |
4556 | } | |
c6c9630e | 4557 | |
6e13d0a5 | 4558 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 4559 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 4560 | |
6e13d0a5 MT |
4561 | if ($cgiparams{'KEY'}) { |
4562 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
4563 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 4564 | } |
c6c9630e | 4565 | |
6e13d0a5 | 4566 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
8c877a82 | 4567 | print "<table width='100%' border='0'>\n"; |
4c962356 | 4568 | |
e3edceeb | 4569 | print "<tr><td width='14%' class='boldbase'>$Lang::tr{'name'}: <img src='/blob.gif' alt='*' /></td>"; |
8c877a82 | 4570 | |
ce9abb66 | 4571 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 | 4572 | if ($cgiparams{'KEY'}) { |
8c877a82 | 4573 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; |
6e13d0a5 MT |
4574 | } else { |
4575 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
4576 | } | |
c6c9630e MT |
4577 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
4578 | # print "<td><select name='INTERFACE'>"; | |
4579 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
4c962356 EK |
4580 | # if ($netsettings{'BLUE_DEV'} ne '') { |
4581 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
4582 | # } | |
4583 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
4584 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
4585 | # print "</select></td></tr>"; | |
4586 | # print <<END; | |
ce9abb66 AH |
4587 | } else { |
4588 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
4589 | if ($cgiparams{'KEY'}) { | |
4590 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4591 | } else { | |
4592 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
4593 | } | |
52f61e49 EKD |
4594 | |
4595 | # If GCM ciphers are in usage, HMAC menu is disabled | |
4596 | my $hmacdisabled; | |
4597 | if (($confighash{$cgiparams{'KEY'}}[40] eq 'AES-256-GCM') || | |
4598 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-192-GCM') || | |
4599 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-128-GCM')) { | |
4600 | $hmacdisabled = "disabled='disabled'"; | |
4601 | }; | |
4602 | ||
4c962356 | 4603 | print <<END; |
ce9abb66 | 4604 | <td width='25%'> </td> |
f527e53f EK |
4605 | <td width='25%'> </td></tr> |
4606 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> | |
4607 | <td><select name='SIDE'> | |
4608 | <option value='server' $selected{'SIDE'}{'server'}>$Lang::tr{'openvpn server'}</option> | |
4609 | <option value='client' $selected{'SIDE'}{'client'}>$Lang::tr{'openvpn client'}</option> | |
4610 | </select> | |
4611 | </td> | |
4c962356 | 4612 | |
f527e53f EK |
4613 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> |
4614 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td> | |
4615 | </tr> | |
4c962356 | 4616 | |
e3edceeb | 4617 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4618 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> |
4c962356 | 4619 | |
e3edceeb | 4620 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f EK |
4621 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td> |
4622 | </tr> | |
4c962356 | 4623 | |
e3edceeb | 4624 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4625 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td> |
49abe7af | 4626 | |
f527e53f EK |
4627 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
4628 | <td><select name='PROTOCOL'> | |
4629 | <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
4630 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4631 | </tr> | |
4632 | ||
4633 | <tr> | |
e3edceeb | 4634 | <td class='boldbase'>$Lang::tr{'destination port'}: <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4635 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td> |
4c962356 | 4636 | |
e3edceeb | 4637 | <td class='boldbase' nowrap='nowrap'>Management Port ($Lang::tr{'openvpn default'}: <span class="base">$Lang::tr{'destination port'}):</td> |
f527e53f EK |
4638 | <td> <input type='TEXT' name='OVPN_MGMT' VALUE='$cgiparams{'OVPN_MGMT'}'size='5' /></td> |
4639 | </tr> | |
49abe7af | 4640 | |
f527e53f EK |
4641 | <tr><td colspan=4><hr /></td></tr><tr> |
4642 | ||
4643 | <tr> | |
4644 | <td class'base'><b>$Lang::tr{'MTU settings'}</b></td> | |
4645 | </tr> | |
49abe7af | 4646 | |
e3edceeb | 4647 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td> |
f527e53f EK |
4648 | <td><input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></td> |
4649 | <td colspan='2'>$Lang::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td> | |
4650 | </tr> | |
4c962356 | 4651 | |
e3edceeb | 4652 | <tr><td class='boldbase' nowrap='nowrap'>fragment:</td> |
f527e53f EK |
4653 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> |
4654 | <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td> | |
4655 | </tr> | |
4c962356 | 4656 | |
e3edceeb | 4657 | <tr><td class='boldbase' nowrap='nowrap'>mssfix:</td> |
f527e53f EK |
4658 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> |
4659 | <td>$Lang::tr{'openvpn default'}: <span class="base">on</span></td> | |
4660 | </tr> | |
4c962356 | 4661 | |
e3edceeb | 4662 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
f527e53f EK |
4663 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> |
4664 | </tr> | |
2ee746be | 4665 | |
f527e53f EK |
4666 | <tr><td colspan=4><hr /></td></tr><tr> |
4667 | <tr> | |
4668 | <td class'base'><b>$Lang::tr{'ovpn crypt options'}:</b></td> | |
4669 | </tr> | |
4670 | ||
4671 | <tr><td class='boldbase'>$Lang::tr{'cipher'}</td> | |
52f61e49 EKD |
4672 | <td><select name='DCIPHER' id="n2ncipher" required> |
4673 | <option value='AES-256-GCM' $selected{'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang::tr{'bit'})</option> | |
4674 | <option value='AES-192-GCM' $selected{'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang::tr{'bit'})</option> | |
4675 | <option value='AES-128-GCM' $selected{'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang::tr{'bit'})</option> | |
f527e53f EK |
4676 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> |
4677 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> | |
4678 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> | |
f7fb5bc5 | 4679 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'}, $Lang::tr{'default'})</option> |
f527e53f EK |
4680 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> |
4681 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
ea6dd5b0 EK |
4682 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
4683 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4684 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4685 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4686 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4687 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
f527e53f EK |
4688 | </select> |
4689 | </td> | |
4690 | ||
4691 | <td class='boldbase'>$Lang::tr{'ovpn ha'}:</td> | |
52f61e49 | 4692 | <td><select name='DAUTH' id="n2nhmac" $hmacdisabled> |
f527e53f EK |
4693 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
4694 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
4695 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
4696 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
f3dfb261 | 4697 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
f527e53f EK |
4698 | </select> |
4699 | </td> | |
4700 | </tr> | |
4701 | <tr><td colspan=4><hr /></td></tr><tr> | |
4702 | ||
ce9abb66 | 4703 | END |
8c877a82 | 4704 | ; |
ce9abb66 | 4705 | } |
52f61e49 EKD |
4706 | |
4707 | #### JAVA SCRIPT #### | |
4708 | # Validate N2N cipher. If GCM will be used, HMAC menu will be disabled onchange | |
4709 | print<<END; | |
4710 | <script> | |
4711 | var disable_options = false; | |
4712 | document.getElementById('n2ncipher').onchange = function () { | |
4713 | if((this.value == "AES-256-GCM"||this.value == "AES-192-GCM"||this.value == "AES-128-GCM")) { | |
4714 | document.getElementById('n2nhmac').setAttribute('disabled', true); | |
4715 | } else { | |
4716 | document.getElementById('n2nhmac').removeAttribute('disabled'); | |
4717 | } | |
4718 | } | |
4719 | </script> | |
4720 | END | |
4721 | ||
2ee746be | 4722 | #jumper |
e3edceeb | 4723 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'}</td>"; |
8c877a82 | 4724 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr></table>"; |
c6c9630e | 4725 | |
ce9abb66 | 4726 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
4727 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>"; |
4728 | } | |
ce9abb66 | 4729 | |
8c877a82 AM |
4730 | print"</tr></table><br><br>"; |
4731 | #A.Marx CCD new client | |
e81be1e1 | 4732 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 | 4733 | 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 |
4734 | my %vpnnet=(); |
4735 | my $vpnip; | |
4736 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); | |
4737 | $vpnip=$vpnnet{'DOVPN_SUBNET'}; | |
4738 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
4739 | my @ccdconf=(); | |
4740 | my $count=0; | |
4741 | my $checked; | |
4742 | $checked{'check1'}{'off'} = ''; | |
4743 | $checked{'check1'}{'on'} = ''; | |
4744 | $checked{'check1'}{$cgiparams{'CHECK1'}} = 'CHECKED'; | |
4745 | 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%'>"; | |
4746 | print"</td></tr></table><br><br>"; | |
4747 | my $name=$cgiparams{'CHECK1'}; | |
4748 | $checked{'RG'}{$cgiparams{'RG'}} = 'CHECKED'; | |
4749 | ||
4750 | if (! -z "${General::swroot}/ovpn/ccd.conf"){ | |
4751 | 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 | 4752 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
4753 | $count++; |
4754 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
4755 | if ($count % 2){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";} | |
4756 | 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%'>"; | |
4757 | &fillselectbox($ccdconf[1],$ccdconf[0],$cgiparams{$name}); | |
4758 | print"</td></tr>"; | |
4759 | } | |
4760 | print "</table><br><br><hr><br><br>"; | |
4761 | } | |
e81be1e1 | 4762 | } |
8c877a82 | 4763 | # ccd end |
6e13d0a5 MT |
4764 | &Header::closebox(); |
4765 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { | |
8c877a82 AM |
4766 | |
4767 | } elsif (! $cgiparams{'KEY'}) { | |
4768 | ||
4769 | ||
6e13d0a5 MT |
4770 | my $disabled=''; |
4771 | my $cakeydisabled=''; | |
4772 | my $cacrtdisabled=''; | |
4773 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
4774 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
8c877a82 | 4775 | |
6e13d0a5 | 4776 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
ce9abb66 AH |
4777 | |
4778 | ||
4779 | if ($cgiparams{'TYPE'} eq 'host') { | |
4780 | ||
49abe7af | 4781 | print <<END; |
6e13d0a5 | 4782 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
54fd0535 | 4783 | |
ce9abb66 AH |
4784 | <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> |
4785 | <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 |
4786 | <tr><td colspan='3'> </td></tr> |
4787 | <tr><td colspan='3'><hr /></td></tr> | |
4788 | <tr><td colspan='3'> </td></tr> | |
ce9abb66 | 4789 | <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 |
4790 | <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> |
4791 | <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> | |
4792 | <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> | |
4793 | <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> | |
4794 | <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> | |
4795 | <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 | 4796 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
6e13d0a5 | 4797 | END |
ce9abb66 AH |
4798 | ; |
4799 | ||
4800 | ### | |
7c1d9faf | 4801 | # m.a.d net2net |
ce9abb66 AH |
4802 | ### |
4803 | ||
4804 | } else { | |
4805 | ||
49abe7af | 4806 | print <<END; |
ce9abb66 AH |
4807 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
4808 | ||
4809 | <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 |
4810 | <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> |
4811 | <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> | |
4812 | <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> | |
4813 | <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> | |
4814 | <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> | |
4815 | <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 | 4816 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
54fd0535 MT |
4817 | |
4818 | ||
ce9abb66 AH |
4819 | END |
4820 | ; | |
4821 | ||
4822 | } | |
4823 | ||
4824 | ### | |
7c1d9faf | 4825 | # m.a.d net2net |
ce9abb66 | 4826 | ### |
c6c9630e | 4827 | |
6e13d0a5 MT |
4828 | foreach my $country (sort keys %{Countries::countries}) { |
4829 | print "<option value='$Countries::countries{$country}'"; | |
4830 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
4831 | print " selected='selected'"; | |
4832 | } | |
4833 | print ">$country</option>"; | |
4834 | } | |
ce9abb66 | 4835 | ### |
7c1d9faf | 4836 | # m.a.d net2net |
ce9abb66 AH |
4837 | ### |
4838 | ||
4839 | if ($cgiparams{'TYPE'} eq 'host') { | |
49abe7af | 4840 | print <<END; |
f4fbb935 | 4841 | </select></td></tr> |
425465ed | 4842 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td> |
f4fbb935 EK |
4843 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4844 | <tr><td> </td> | |
6e13d0a5 MT |
4845 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
4846 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
f4fbb935 | 4847 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<br>($Lang::tr{'confirmation'})</td> |
6e13d0a5 | 4848 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> |
f4fbb935 EK |
4849 | <tr><td colspan='3'> </td></tr> |
4850 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4851 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
f4fbb935 | 4852 | </table> |
ce9abb66 AH |
4853 | END |
4854 | }else{ | |
49abe7af | 4855 | print <<END; |
f4fbb935 | 4856 | </select></td></tr> |
425465ed | 4857 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td> |
f4fbb935 EK |
4858 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4859 | <tr><td> </td><td> </td><td> </td></tr> | |
4860 | <tr><td> </td><td> </td><td> </td></tr> | |
4861 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4862 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
ce9abb66 AH |
4863 | </table> |
4864 | ||
c6c9630e | 4865 | END |
ce9abb66 AH |
4866 | } |
4867 | ||
4868 | ### | |
7c1d9faf | 4869 | # m.a.d net2net |
ce9abb66 | 4870 | ### |
c6c9630e MT |
4871 | ; |
4872 | &Header::closebox(); | |
8c877a82 AM |
4873 | |
4874 | } | |
e81be1e1 AM |
4875 | |
4876 | #A.Marx CCD new client | |
4877 | if ($cgiparams{'TYPE'} eq 'host') { | |
8c877a82 AM |
4878 | print"<br><br>"; |
4879 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); | |
4880 | ||
8c877a82 AM |
4881 | |
4882 | print <<END; | |
4883 | <table border='0' width='100%'> | |
4884 | <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked{'RG'}{'on'} /></td></tr> | |
4885 | <tr><td colspan='4'><b><br>$Lang::tr{'ccd routes'}</b></td></tr> | |
4886 | <tr><td colspan='4'> </td></tr> | |
4887 | <tr><td valign='top'>$Lang::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'> | |
4888 | END | |
4889 | ||
4890 | if ($cgiparams{'IR'} ne ''){ | |
4891 | print $cgiparams{'IR'}; | |
4892 | }else{ | |
4893 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4894 | foreach my $key (keys %ccdroutehash) { | |
4895 | if( $cgiparams{'NAME'} eq $ccdroutehash{$key}[0]){ | |
4896 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
4897 | if ($ccdroutehash{$key}[$i] ne ''){ | |
4898 | print $ccdroutehash{$key}[$i]."\n"; | |
4899 | } | |
4900 | $cgiparams{'IR'} .= $ccdroutehash{$key}[$i]; | |
4901 | } | |
4902 | } | |
4903 | } | |
c6c9630e | 4904 | } |
8c877a82 AM |
4905 | |
4906 | print <<END; | |
4907 | </textarea></td><td valign='top' colspan='2'>$Lang::tr{'ccd iroutehint'}</td></tr> | |
4908 | <tr><td colspan='4'><br></td></tr> | |
4909 | <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> | |
4910 | END | |
52d08bcb AM |
4911 | |
4912 | my $set=0; | |
4913 | my $selorange=0; | |
4914 | my $selblue=0; | |
4915 | my $selgreen=0; | |
4916 | my $helpblue=0; | |
4917 | my $helporange=0; | |
4918 | my $other=0; | |
df9b48b7 | 4919 | my $none=0; |
52d08bcb AM |
4920 | my @temp=(); |
4921 | ||
8c877a82 | 4922 | our @current = (); |
52d08bcb AM |
4923 | open(FILE, "${General::swroot}/main/routing") ; |
4924 | @current = <FILE>; | |
4925 | close (FILE); | |
4926 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
df9b48b7 AM |
4927 | #check for "none" |
4928 | foreach my $key (keys %ccdroute2hash) { | |
4929 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4930 | if ($ccdroute2hash{$key}[1] eq ''){ | |
4931 | $none=1; | |
4932 | last; | |
4933 | } | |
4934 | } | |
4935 | } | |
4936 | if ($none ne '1'){ | |
4937 | print"<option>$Lang::tr{'ccd none'}</option>"; | |
4938 | }else{ | |
4939 | print"<option selected>$Lang::tr{'ccd none'}</option>"; | |
4940 | } | |
52d08bcb AM |
4941 | #check if static routes are defined for client |
4942 | foreach my $line (@current) { | |
4943 | chomp($line); | |
4944 | $line=~s/\s*$//g; # remove newline | |
4945 | @temp=split(/\,/,$line); | |
4946 | $temp[1] = '' unless defined $temp[1]; # not always populated | |
4947 | my ($a,$b) = split(/\//,$temp[1]); | |
4948 | $temp[1] = $a."/".&General::iporsubtocidr($b); | |
4949 | foreach my $key (keys %ccdroute2hash) { | |
4950 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4951 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4952 | if($ccdroute2hash{$key}[$i] eq $a."/".&General::iporsubtodec($b)){ | |
4953 | $set=1; | |
8c877a82 AM |
4954 | } |
4955 | } | |
8c877a82 | 4956 | } |
52d08bcb AM |
4957 | } |
4958 | if ($set == '1' && $#temp != -1){ print"<option selected>$temp[1]</option>";$set=0;}elsif($set == '0' && $#temp != -1){print"<option>$temp[1]</option>";} | |
4959 | } | |
3a445974 MT |
4960 | |
4961 | my %vpnconfig = (); | |
4962 | &General::readhasharray("${General::swroot}/vpn/config", \%vpnconfig); | |
4963 | foreach my $vpn (keys %vpnconfig) { | |
4964 | # Skip all disabled VPN connections | |
4965 | my $enabled = $vpnconfig{$vpn}[0]; | |
4966 | next unless ($enabled eq "on"); | |
4967 | ||
4968 | my $name = $vpnconfig{$vpn}[1]; | |
4969 | ||
4970 | # Remote subnets | |
4971 | my @networks = split(/\|/, $vpnconfig{$vpn}[11]); | |
4972 | foreach my $network (@networks) { | |
4973 | my $selected = ""; | |
4974 | ||
4975 | foreach my $key (keys %ccdroute2hash) { | |
4976 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
4977 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4978 | if ($ccdroute2hash{$key}[$i] eq $network) { | |
4979 | $selected = "selected"; | |
4980 | } | |
4981 | } | |
4982 | } | |
4983 | } | |
4984 | ||
4985 | print "<option value=\"$network\" $selected>$name ($network)</option>\n"; | |
4986 | } | |
4987 | } | |
4988 | ||
52d08bcb AM |
4989 | #check if green,blue,orange are defined for client |
4990 | foreach my $key (keys %ccdroute2hash) { | |
4991 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4992 | $other=1; | |
4993 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4994 | if ($ccdroute2hash{$key}[$i] eq $netsettings{'GREEN_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'GREEN_NETMASK'})){ | |
4995 | $selgreen=1; | |
4996 | } | |
4997 | if (&haveBlueNet()){ | |
4998 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'})) { | |
4999 | $selblue=1; | |
5000 | } | |
5001 | } | |
5002 | if (&haveOrangeNet()){ | |
5003 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'ORANGE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'ORANGE_NETMASK'}) ) { | |
5004 | $selorange=1; | |
5005 | } | |
5006 | } | |
5007 | } | |
5008 | } | |
5009 | } | |
5010 | if (&haveBlueNet() && $selblue == '1'){ print"<option selected>$Lang::tr{'blue'}</option>";$selblue=0;}elsif(&haveBlueNet() && $selblue == '0'){print"<option>$Lang::tr{'blue'}</option>";} | |
5011 | if (&haveOrangeNet() && $selorange == '1'){ print"<option selected>$Lang::tr{'orange'}</option>";$selorange=0;}elsif(&haveOrangeNet() && $selorange == '0'){print"<option>$Lang::tr{'orange'}</option>";} | |
5012 | if ($selgreen == '1' || $other == '0'){ print"<option selected>$Lang::tr{'green'}</option>";$set=0;}else{print"<option>$Lang::tr{'green'}</option>";}; | |
5013 | ||
49abe7af | 5014 | print<<END; |
8c877a82 AM |
5015 | </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value='$cgiparams{'CCD_DNS1'}' size='30' /></td></tr> |
5016 | <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value='$cgiparams{'CCD_DNS2'}' size='30' /></td></tr> | |
5017 | <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> | |
5018 | ||
5019 | END | |
5020 | ; | |
5021 | &Header::closebox(); | |
e81be1e1 | 5022 | } |
c6c9630e MT |
5023 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5024 | if ($cgiparams{'KEY'}) { | |
5025 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
5026 | } | |
5027 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
5028 | &Header::closebigbox(); | |
5029 | &Header::closepage(); | |
5030 | exit (0); | |
6e13d0a5 | 5031 | } |
c6c9630e | 5032 | VPNCONF_END: |
6e13d0a5 | 5033 | } |
c6c9630e MT |
5034 | |
5035 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
5036 | ### |
5037 | ### Default status page | |
5038 | ### | |
c6c9630e MT |
5039 | %cgiparams = (); |
5040 | %cahash = (); | |
5041 | %confighash = (); | |
5042 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
5043 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
5044 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
5045 | ||
87fe47e9 | 5046 | my @status = `/bin/cat /var/run/ovpnserver.log`; |
c6c9630e MT |
5047 | |
5048 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
8c877a82 AM |
5049 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
5050 | my $ipaddr = <IPADDR>; | |
5051 | close IPADDR; | |
5052 | chomp ($ipaddr); | |
5053 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
5054 | if ($cgiparams{'VPN_IP'} eq '') { | |
5055 | $cgiparams{'VPN_IP'} = $ipaddr; | |
5056 | } | |
5057 | } | |
c6c9630e MT |
5058 | } |
5059 | ||
6e13d0a5 | 5060 | #default setzen |
c6c9630e | 5061 | if ($cgiparams{'DCIPHER'} eq '') { |
4c962356 | 5062 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; |
c6c9630e | 5063 | } |
c6c9630e | 5064 | if ($cgiparams{'DDEST_PORT'} eq '') { |
4c962356 | 5065 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
5066 | } |
5067 | if ($cgiparams{'DMTU'} eq '') { | |
4c962356 EK |
5068 | $cgiparams{'DMTU'} = '1400'; |
5069 | } | |
5070 | if ($cgiparams{'MSSFIX'} eq '') { | |
5071 | $cgiparams{'MSSFIX'} = 'off'; | |
5072 | } | |
5073 | if ($cgiparams{'DAUTH'} eq '') { | |
70900745 | 5074 | $cgiparams{'DAUTH'} = 'SHA512'; |
c6c9630e MT |
5075 | } |
5076 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { | |
4c962356 | 5077 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e | 5078 | } |
4c962356 | 5079 | $checked{'ENABLED'}{'off'} = ''; |
c6c9630e MT |
5080 | $checked{'ENABLED'}{'on'} = ''; |
5081 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
5082 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
5083 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
5084 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
5085 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
5086 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
5087 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
5088 | |
5089 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
5090 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
5091 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
4c962356 | 5092 | |
52f61e49 EKD |
5093 | $selected{'DCIPHER'}{'AES-256-GCM'} = ''; |
5094 | $selected{'DCIPHER'}{'AES-192-GCM'} = ''; | |
5095 | $selected{'DCIPHER'}{'AES-128-GCM'} = ''; | |
4c962356 EK |
5096 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
5097 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
5098 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
5099 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
5100 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
5101 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
c6c9630e MT |
5102 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; |
5103 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4c962356 EK |
5104 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; |
5105 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
5106 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
5107 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 5108 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
c6c9630e | 5109 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
4c962356 EK |
5110 | |
5111 | $selected{'DAUTH'}{'whirlpool'} = ''; | |
5112 | $selected{'DAUTH'}{'SHA512'} = ''; | |
5113 | $selected{'DAUTH'}{'SHA384'} = ''; | |
5114 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
5115 | $selected{'DAUTH'}{'SHA1'} = ''; |
5116 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
5117 | ||
c6c9630e MT |
5118 | $checked{'DCOMPLZO'}{'off'} = ''; |
5119 | $checked{'DCOMPLZO'}{'on'} = ''; | |
5120 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
4c962356 | 5121 | |
d96c89eb AH |
5122 | # m.a.d |
5123 | $checked{'MSSFIX'}{'off'} = ''; | |
5124 | $checked{'MSSFIX'}{'on'} = ''; | |
5125 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 5126 | #new settings |
c6c9630e MT |
5127 | &Header::showhttpheaders(); |
5128 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
5129 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 5130 | |
c6c9630e | 5131 | if ($errormessage) { |
6e13d0a5 MT |
5132 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
5133 | print "<class name='base'>$errormessage\n"; | |
5134 | print " </class>\n"; | |
5135 | &Header::closebox(); | |
c6c9630e | 5136 | } |
6e13d0a5 | 5137 | |
b2e75449 MT |
5138 | if ($warnmessage) { |
5139 | &Header::openbox('100%', 'LEFT', $Lang::tr{'warning messages'}); | |
5140 | print "$warnmessage<br>"; | |
5141 | print "$Lang::tr{'fwdfw warn1'}<br>"; | |
5142 | &Header::closebox(); | |
5143 | print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>"; | |
5144 | &Header::closepage(); | |
5145 | exit 0; | |
5146 | } | |
4d81e0f3 | 5147 | |
c6c9630e MT |
5148 | 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>"; |
5149 | my $srunning = "no"; | |
5150 | my $activeonrun = ""; | |
5151 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
5152 | $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>"; |
5153 | $srunning ="yes"; | |
5154 | $activeonrun = ""; | |
c6c9630e | 5155 | } else { |
6e13d0a5 | 5156 | $activeonrun = "disabled='disabled'"; |
c6c9630e | 5157 | } |
afabe9f7 | 5158 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); |
4c962356 | 5159 | print <<END; |
631b67b7 | 5160 | <table width='100%' border='0'> |
c6c9630e MT |
5161 | <form method='post'> |
5162 | <td width='25%'> </td> | |
5163 | <td width='25%'> </td> | |
5164 | <td width='25%'> </td></tr> | |
5165 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
5166 | <td align='left'>$sactive</td> | |
5167 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
8c877a82 | 5168 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> |
c6c9630e MT |
5169 | END |
5170 | ; | |
5171 | if (&haveBlueNet()) { | |
5172 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
5173 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
5174 | } | |
5175 | if (&haveOrangeNet()) { | |
5176 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
5177 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
5178 | } | |
4c962356 | 5179 | print <<END; |
4e17adad CS |
5180 | <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> |
5181 | <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 |
5182 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
5183 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
5184 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
5185 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
5186 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
5187 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
bc2b3e94 | 5188 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}' size='5' /></td> |
f527e53f | 5189 | |
4c962356 EK |
5190 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> |
5191 | <td><select name='DCIPHER'> | |
52f61e49 EKD |
5192 | <option value='AES-256-GCM' $selected{'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang::tr{'bit'})</option> |
5193 | <option value='AES-192-GCM' $selected{'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang::tr{'bit'})</option> | |
5194 | <option value='AES-128-GCM' $selected{'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang::tr{'bit'})</option> | |
4c962356 | 5195 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> |
f527e53f | 5196 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> |
4c962356 EK |
5197 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> |
5198 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'})</option> | |
5199 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> | |
5200 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
4c962356 | 5201 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
ea6dd5b0 EK |
5202 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
5203 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5204 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5205 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5206 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4c962356 EK |
5207 | </select> |
5208 | </td> | |
c6c9630e MT |
5209 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
5210 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
4c962356 | 5211 | </tr> |
f7edf97a | 5212 | <tr><td colspan='4'><br><br></td></tr> |
c6c9630e MT |
5213 | END |
5214 | ; | |
5215 | ||
5216 | if ( $srunning eq "yes" ) { | |
8c877a82 AM |
5217 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' />"; |
5218 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5219 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
5220 | print "<input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td></tr>"; | |
c6c9630e | 5221 | } else{ |
8c877a82 AM |
5222 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5223 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5224 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
c6c9630e MT |
5225 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && |
5226 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
5227 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
5228 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
5229 | (( $cgiparams{'ENABLED'} eq 'on') || | |
5230 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
5231 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
8c877a82 | 5232 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td></tr>"; |
c6c9630e | 5233 | } else { |
8c877a82 | 5234 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td></tr>"; |
c6c9630e MT |
5235 | } |
5236 | } | |
5237 | print "</form></table>"; | |
5238 | &Header::closebox(); | |
6e13d0a5 | 5239 | |
c6c9630e | 5240 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { |
ce9abb66 | 5241 | ### |
7c1d9faf | 5242 | # m.a.d net2net |
54fd0535 | 5243 | #<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 |
5244 | ### |
5245 | ||
4c962356 | 5246 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection status and controlc' }); |
c6c9630e | 5247 | ; |
99bfa85c AM |
5248 | my $id = 0; |
5249 | my $gif; | |
f7edf97a | 5250 | my $col1=""; |
5b942f7f | 5251 | my $lastnet; |
c8b51e28 | 5252 | foreach my $key (sort { ncmp ($confighash{$a}[32],$confighash{$b}[32]) } sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) { |
5b942f7f AM |
5253 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]=$Lang::tr{'fwhost OpenVPN N-2-N'};} |
5254 | if ($confighash{$key}[32] eq "dynamic"){$confighash{$key}[32]=$Lang::tr{'ccd dynrange'};} | |
5255 | if($id == 0){ | |
5256 | print"<b>$confighash{$key}[32]</b>"; | |
5257 | print <<END; | |
5258 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5259 | <tr> | |
5260 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5261 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5262 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5263 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
71af643c | 5264 | <th width='5%' class='boldbase' colspan='7' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5265 | </tr> |
5266 | END | |
5267 | } | |
5268 | if ($id > 0 && $lastnet ne $confighash{$key}[32]){ | |
5269 | print "</table><br>"; | |
5270 | print"<b>$confighash{$key}[32]</b>"; | |
5271 | print <<END; | |
5272 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5273 | <tr> | |
5274 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5275 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5276 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5277 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
71af643c | 5278 | <th width='5%' class='boldbase' colspan='7' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5279 | </tr> |
5280 | END | |
5281 | } | |
eff2dbf8 | 5282 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } |
c6c9630e | 5283 | if ($id % 2) { |
99bfa85c AM |
5284 | print "<tr>"; |
5285 | $col="bgcolor='$color{'color20'}'"; | |
bb89e92a | 5286 | } else { |
99bfa85c AM |
5287 | print "<tr>"; |
5288 | $col="bgcolor='$color{'color22'}'"; | |
c6c9630e | 5289 | } |
99bfa85c AM |
5290 | print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]</td>"; |
5291 | print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
8c877a82 AM |
5292 | #if ($confighash{$key}[4] eq 'cert') { |
5293 | #print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
5294 | #} else { | |
5295 | #print "<td align='left'> </td>"; | |
5296 | #} | |
c6c9630e MT |
5297 | my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; |
5298 | $cavalid =~ /Not After : (.*)[\n]/; | |
5299 | $cavalid = $1; | |
99bfa85c | 5300 | print "<td align='center' $col>$confighash{$key}[25]</td>"; |
f7edf97a AM |
5301 | $col1="bgcolor='${Header::colourred}'"; |
5302 | my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
ce9abb66 | 5303 | |
c6c9630e | 5304 | if ($confighash{$key}[0] eq 'off') { |
f7edf97a AM |
5305 | $col1="bgcolor='${Header::colourblue}'"; |
5306 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
c6c9630e | 5307 | } else { |
ce9abb66 AH |
5308 | |
5309 | ### | |
7c1d9faf | 5310 | # m.a.d net2net |
f7edf97a AM |
5311 | ### |
5312 | ||
b278daf3 | 5313 | if ($confighash{$key}[3] eq 'net') { |
54fd0535 MT |
5314 | |
5315 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
5316 | my @output = ""; | |
5317 | my @tustate = ""; | |
5318 | my $tport = $confighash{$key}[22]; | |
5319 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); | |
5320 | if ($tport ne '') { | |
5321 | $tnet->open('127.0.0.1'); | |
5322 | @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
5323 | @tustate = split(/\,/, $output[1]); | |
5324 | ### | |
5325 | #CONNECTING -- OpenVPN's initial state. | |
5326 | #WAIT -- (Client only) Waiting for initial response from server. | |
5327 | #AUTH -- (Client only) Authenticating with server. | |
5328 | #GET_CONFIG -- (Client only) Downloading configuration options from server. | |
5329 | #ASSIGN_IP -- Assigning IP address to virtual network interface. | |
5330 | #ADD_ROUTES -- Adding routes to system. | |
5331 | #CONNECTED -- Initialization Sequence Completed. | |
5332 | #RECONNECTING -- A restart has occurred. | |
5333 | #EXITING -- A graceful exit is in progress. | |
5334 | #### | |
5335 | ||
ed4b4c19 | 5336 | if (($tustate[1] eq 'CONNECTED') || ($tustate[1] eq 'WAIT')) { |
f7edf97a AM |
5337 | $col1="bgcolor='${Header::colourgreen}'"; |
5338 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5339 | }else { | |
5340 | $col1="bgcolor='${Header::colourred}'"; | |
5341 | $active = "<b><font color='#FFFFFF'>$tustate[1]</font></b>"; | |
5342 | } | |
54fd0535 | 5343 | } |
54fd0535 | 5344 | } |
f7edf97a AM |
5345 | }else { |
5346 | ||
5347 | my $cn; | |
5348 | my @match = (); | |
5349 | foreach my $line (@status) { | |
5350 | chomp($line); | |
5351 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
5352 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
5353 | if ($match[1] ne "Common Name") { | |
5354 | $cn = $match[1]; | |
5355 | } | |
5356 | $cn =~ s/[_]/ /g; | |
5357 | if ($cn eq "$confighash{$key}[2]") { | |
5358 | $col1="bgcolor='${Header::colourgreen}'"; | |
5359 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5360 | } | |
5361 | } | |
5362 | } | |
c6c9630e | 5363 | } |
7c1d9faf | 5364 | } |
ce9abb66 AH |
5365 | |
5366 | ||
4c962356 | 5367 | print <<END; |
f7edf97a | 5368 | <td align='center' $col1>$active</td> |
c6c9630e | 5369 | |
99bfa85c | 5370 | <form method='post' name='frm${key}a'><td align='center' $col> |
96096995 AM |
5371 | <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' /> |
5372 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5373 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
5374 | </td></form> |
5375 | END | |
5376 | ; | |
71af643c MT |
5377 | |
5378 | if ($confighash{$key}[41] eq "no-pass") { | |
5379 | print <<END; | |
5380 | <form method='post' name='frm${key}g'><td align='center' $col> | |
5381 | <input type='image' name='$Lang::tr{'dl client arch insecure'}' src='/images/openvpn.png' | |
5382 | alt='$Lang::tr{'dl client arch insecure'}' title='$Lang::tr{'dl client arch insecure'}' border='0' /> | |
5383 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5384 | <input type='hidden' name='MODE' value='insecure' /> | |
5385 | <input type='hidden' name='KEY' value='$key' /> | |
5386 | </td></form> | |
5387 | END | |
5388 | } else { | |
5389 | print "<td $col> </td>"; | |
5390 | } | |
5391 | ||
c6c9630e | 5392 | if ($confighash{$key}[4] eq 'cert') { |
4c962356 | 5393 | print <<END; |
99bfa85c | 5394 | <form method='post' name='frm${key}b'><td align='center' $col> |
c6c9630e MT |
5395 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> |
5396 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
5397 | <input type='hidden' name='KEY' value='$key' /> | |
5398 | </td></form> | |
5399 | END | |
5400 | ; } else { | |
5401 | print "<td> </td>"; | |
5402 | } | |
5403 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
4c962356 | 5404 | print <<END; |
99bfa85c | 5405 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5406 | <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 |
5407 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
5408 | <input type='hidden' name='KEY' value='$key' /> | |
5409 | </td></form> | |
5410 | END | |
5411 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5412 | print <<END; |
99bfa85c | 5413 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5414 | <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 |
5415 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
5416 | <input type='hidden' name='KEY' value='$key' /> | |
5417 | </td></form> | |
5418 | END | |
5419 | ; } else { | |
5420 | print "<td> </td>"; | |
5421 | } | |
5422 | print <<END | |
99bfa85c | 5423 | <form method='post' name='frm${key}d'><td align='center' $col> |
c6c9630e MT |
5424 | <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' /> |
5425 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
5426 | <input type='hidden' name='KEY' value='$key' /> | |
5427 | </td></form> | |
5428 | ||
99bfa85c | 5429 | <form method='post' name='frm${key}e'><td align='center' $col> |
c6c9630e MT |
5430 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> |
5431 | <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'/> | |
5432 | <input type='hidden' name='KEY' value='$key' /> | |
5433 | </td></form> | |
99bfa85c | 5434 | <form method='post' name='frm${key}f'><td align='center' $col> |
c6c9630e MT |
5435 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> |
5436 | <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' /> | |
5437 | <input type='hidden' name='KEY' value='$key' /> | |
5438 | </td></form> | |
5439 | </tr> | |
5440 | END | |
5441 | ; | |
5442 | $id++; | |
5b942f7f | 5443 | $lastnet = $confighash{$key}[32]; |
c6c9630e | 5444 | } |
5b942f7f | 5445 | print"</table>"; |
c6c9630e MT |
5446 | ; |
5447 | ||
5448 | # If the config file contains entries, print Key to action icons | |
5449 | if ( $id ) { | |
4c962356 | 5450 | print <<END; |
8c877a82 | 5451 | <table border='0'> |
c6c9630e | 5452 | <tr> |
4c962356 EK |
5453 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
5454 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
5455 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
5456 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5457 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5458 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
5459 | <td class='base'>$Lang::tr{'edit'}</td> | |
5460 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
5461 | <td class='base'>$Lang::tr{'remove'}</td> | |
c6c9630e MT |
5462 | </tr> |
5463 | <tr> | |
4c962356 EK |
5464 | <td> </td> |
5465 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
5466 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
5467 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> | |
5468 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5469 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> | |
5470 | <td class='base'>$Lang::tr{'dl client arch'}</td> | |
5471 | </tr> | |
f7edf97a | 5472 | </table><br> |
c6c9630e MT |
5473 | END |
5474 | ; | |
5475 | } | |
5476 | ||
4c962356 | 5477 | print <<END; |
c6c9630e MT |
5478 | <table width='100%'> |
5479 | <form method='post'> | |
4c962356 EK |
5480 | <tr><td align='right'> |
5481 | <input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
5482 | <input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td> | |
5483 | </tr> | |
c6c9630e MT |
5484 | </form> |
5485 | </table> | |
5486 | END | |
4c962356 EK |
5487 | ; |
5488 | &Header::closebox(); | |
5489 | } | |
fd5ccb2d EK |
5490 | |
5491 | # CA/key listing | |
4c962356 EK |
5492 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}"); |
5493 | print <<END; | |
5494 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5495 | <tr> | |
5496 | <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5497 | <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th> | |
5498 | <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th> | |
5499 | </tr> | |
5500 | END | |
5501 | ; | |
5502 | my $col1="bgcolor='$color{'color22'}'"; | |
f7fb5bc5 | 5503 | my $col2="bgcolor='$color{'color20'}'"; |
c8f50356 | 5504 | # DH parameter line |
f7fb5bc5 | 5505 | my $col3="bgcolor='$color{'color22'}'"; |
fd5ccb2d EK |
5506 | # ta.key line |
5507 | my $col4="bgcolor='$color{'color20'}'"; | |
f7fb5bc5 | 5508 | |
4c962356 EK |
5509 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { |
5510 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
5511 | $casubject =~ /Subject: (.*)[\n]/; | |
5512 | $casubject = $1; | |
5513 | $casubject =~ s+/Email+, E+; | |
5514 | $casubject =~ s/ ST=/ S=/; | |
5515 | print <<END; | |
5516 | <tr> | |
5517 | <td class='base' $col1>$Lang::tr{'root certificate'}</td> | |
5518 | <td class='base' $col1>$casubject</td> | |
c8f50356 | 5519 | <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1> |
4c962356 EK |
5520 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> |
5521 | <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 |
5522 | </form> |
5523 | <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1> | |
4c962356 EK |
5524 | <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' /> |
5525 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
c8f50356 EK |
5526 | </form> |
5527 | <td width='4%' $col1> </td> | |
5528 | </tr> | |
4c962356 EK |
5529 | END |
5530 | ; | |
5531 | } else { | |
5532 | # display rootcert generation buttons | |
5533 | print <<END; | |
5534 | <tr> | |
5535 | <td class='base' $col1>$Lang::tr{'root certificate'}:</td> | |
5536 | <td class='base' $col1>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5537 | <td colspan='3' $col1> </td> |
5538 | </tr> | |
4c962356 EK |
5539 | END |
5540 | ; | |
5541 | } | |
5542 | ||
5543 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
5544 | my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
5545 | $hostsubject =~ /Subject: (.*)[\n]/; | |
5546 | $hostsubject = $1; | |
5547 | $hostsubject =~ s+/Email+, E+; | |
5548 | $hostsubject =~ s/ ST=/ S=/; | |
5549 | ||
5550 | print <<END; | |
5551 | <tr> | |
5552 | <td class='base' $col2>$Lang::tr{'host certificate'}</td> | |
5553 | <td class='base' $col2>$hostsubject</td> | |
c8f50356 | 5554 | <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2> |
4c962356 EK |
5555 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> |
5556 | <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 |
5557 | </form> |
5558 | <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2> | |
4c962356 EK |
5559 | <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' /> |
5560 | <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" /> | |
c8f50356 EK |
5561 | </td></form> |
5562 | <td width='4%' $col2> </td> | |
5563 | </tr> | |
4c962356 EK |
5564 | END |
5565 | ; | |
5566 | } else { | |
5567 | # Nothing | |
5568 | print <<END; | |
5569 | <tr> | |
5570 | <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td> | |
5571 | <td class='base' $col2>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5572 | </td><td colspan='3' $col2> </td> |
5573 | </tr> | |
4c962356 EK |
5574 | END |
5575 | ; | |
5576 | } | |
ce9abb66 | 5577 | |
f7fb5bc5 EK |
5578 | # Adding DH parameter to chart |
5579 | if (-f "${General::swroot}/ovpn/ca/dh1024.pem") { | |
5580 | my $dhsubject = `/usr/bin/openssl dhparam -text -in ${General::swroot}/ovpn/ca/dh1024.pem`; | |
c8f50356 | 5581 | $dhsubject =~ / (.*)[\n]/; |
f7fb5bc5 EK |
5582 | $dhsubject = $1; |
5583 | ||
5584 | ||
5585 | print <<END; | |
5586 | <tr> | |
5587 | <td class='base' $col3>$Lang::tr{'dh parameter'}</td> | |
5588 | <td class='base' $col3>$dhsubject</td> | |
c8f50356 | 5589 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> |
f7fb5bc5 EK |
5590 | <input type='hidden' name='ACTION' value='$Lang::tr{'show dh'}' /> |
5591 | <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 |
5592 | </form> |
5593 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> | |
c8f50356 EK |
5594 | </form> |
5595 | <td width='4%' $col3> </td> | |
5596 | </tr> | |
f7fb5bc5 EK |
5597 | END |
5598 | ; | |
5599 | } else { | |
5600 | # Nothing | |
5601 | print <<END; | |
5602 | <tr> | |
5603 | <td width='25%' class='base' $col3>$Lang::tr{'dh parameter'}:</td> | |
5604 | <td class='base' $col3>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5605 | </td><td colspan='3' $col3> </td> |
5606 | </tr> | |
f7fb5bc5 EK |
5607 | END |
5608 | ; | |
5609 | } | |
5610 | ||
fd5ccb2d EK |
5611 | # Adding ta.key to chart |
5612 | if (-f "${General::swroot}/ovpn/certs/ta.key") { | |
5613 | my $tasubject = `/bin/cat ${General::swroot}/ovpn/certs/ta.key`; | |
5614 | $tasubject =~ /# (.*)[\n]/; | |
5615 | $tasubject = $1; | |
5616 | print <<END; | |
5617 | ||
5618 | <tr> | |
5619 | <td class='base' $col4>$Lang::tr{'ta key'}</td> | |
5620 | <td class='base' $col4>$tasubject</td> | |
5621 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5622 | <input type='hidden' name='ACTION' value='$Lang::tr{'show tls-auth key'}' /> | |
5623 | <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' /> | |
5624 | </form> | |
5625 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5626 | <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' /> | |
5627 | <input type='hidden' name='ACTION' value='$Lang::tr{'download tls-auth key'}' /> | |
5628 | </form> | |
5629 | <td width='4%' $col4> </td> | |
5630 | </tr> | |
5631 | END | |
5632 | ; | |
5633 | } else { | |
5634 | # Nothing | |
5635 | print <<END; | |
5636 | <tr> | |
5637 | <td width='25%' class='base' $col4>$Lang::tr{'ta key'}:</td> | |
5638 | <td class='base' $col4>$Lang::tr{'not present'}</td> | |
5639 | <td colspan='3' $col4> </td> | |
5640 | </tr> | |
5641 | END | |
5642 | ; | |
5643 | } | |
5644 | ||
4c962356 EK |
5645 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
5646 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
5647 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; | |
5648 | print "</form></td></tr>\n"; | |
5649 | } | |
5650 | ||
5651 | if (keys %cahash > 0) { | |
5652 | foreach my $key (keys %cahash) { | |
5653 | if (($key + 1) % 2) { | |
5654 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
5655 | } else { | |
5656 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
5657 | } | |
5658 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
5659 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
5660 | print <<END; | |
5661 | <form method='post' name='cafrm${key}a'><td align='center'> | |
5662 | <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' /> | |
5663 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
5664 | <input type='hidden' name='KEY' value='$key' /> | |
5665 | </td></form> | |
5666 | <form method='post' name='cafrm${key}b'><td align='center'> | |
5667 | <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' /> | |
5668 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
5669 | <input type='hidden' name='KEY' value='$key' /> | |
5670 | </td></form> | |
5671 | <form method='post' name='cafrm${key}c'><td align='center'> | |
5672 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
5673 | <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' /> | |
5674 | <input type='hidden' name='KEY' value='$key' /> | |
5675 | </td></form></tr> | |
5676 | END | |
5677 | ; | |
5678 | } | |
5679 | } | |
5680 | ||
5681 | print "</table>"; | |
5682 | ||
5683 | # If the file contains entries, print Key to action icons | |
5684 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
5685 | print <<END; | |
5686 | <table> | |
5687 | <tr> | |
5688 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
5689 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5690 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5691 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> | |
5692 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5693 | </tr> | |
5694 | </table> | |
5695 | END | |
5696 | ; | |
5697 | } | |
ce9abb66 | 5698 | |
4c962356 | 5699 | print <<END |
578f23c8 SS |
5700 | |
5701 | <br><hr><br> | |
5702 | ||
4c962356 | 5703 | <form method='post' enctype='multipart/form-data'> |
578f23c8 SS |
5704 | <table border='0' width='100%'> |
5705 | <tr> | |
5706 | <td colspan='4'><b>$Lang::tr{'upload ca certificate'}</b></td> | |
5707 | </tr> | |
4c962356 | 5708 | |
578f23c8 SS |
5709 | <tr> |
5710 | <td width='10%'>$Lang::tr{'ca name'}:</td> | |
5711 | <td width='30%'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' align='left'></td> | |
5712 | <td width='30%'><input type='file' name='FH' size='25'> | |
5713 | <td width='30%'align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}'></td> | |
5714 | </tr> | |
f527e53f | 5715 | |
578f23c8 SS |
5716 | <tr> |
5717 | <td colspan='3'> </td> | |
5718 | <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> | |
5719 | </tr> | |
5720 | </table> | |
f527e53f | 5721 | |
578f23c8 SS |
5722 | <br> |
5723 | ||
5724 | <table border='0' width='100%'> | |
5725 | <tr> | |
5726 | <td colspan='4'><b>$Lang::tr{'ovpn dh parameters'}</b></td> | |
5727 | </tr> | |
5728 | ||
5729 | <tr> | |
5730 | <td width='40%'>$Lang::tr{'ovpn dh upload'}:</td> | |
5731 | <td width='30%'><input type='file' name='FH' size='25'> | |
5732 | <td width='30%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload dh key'}'></td> | |
5733 | </tr> | |
5734 | ||
5735 | <tr> | |
5736 | <td width='40%'>$Lang::tr{'ovpn dh new key'}:</td> | |
5737 | <td colspan='2' width='60%' align='right'><input type='submit' name='ACTION' value='$Lang::tr{'generate dh key'}' /></td> | |
5738 | </tr> | |
5739 | </table> | |
5740 | </form> | |
f527e53f | 5741 | |
578f23c8 | 5742 | <br><hr> |
4c962356 EK |
5743 | END |
5744 | ; | |
5745 | ||
5746 | if ( $srunning eq "yes" ) { | |
5747 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' disabled='disabled' /></div></form>\n"; | |
5748 | } else { | |
5749 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></div></form>\n"; | |
5750 | } | |
5751 | &Header::closebox(); | |
5752 | END | |
5753 | ; | |
5754 | ||
5755 | &Header::closepage(); | |
ce9abb66 | 5756 |