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