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