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