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