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