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