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