]>
Commit | Line | Data |
---|---|---|
6e13d0a5 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2007 Michael Tremer & Christian Schmidt # | |
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 | ############################################################################### | |
6e13d0a5 MT |
21 | |
22 | use CGI; | |
23 | use CGI qw/:standard/; | |
24 | use Net::DNS; | |
ce9abb66 | 25 | use Net::Ping; |
6e13d0a5 MT |
26 | use File::Copy; |
27 | use File::Temp qw/ tempfile tempdir /; | |
28 | use strict; | |
29 | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
6e13d0a5 | 30 | require '/var/ipfire/general-functions.pl'; |
6e13d0a5 MT |
31 | require "${General::swroot}/lang.pl"; |
32 | require "${General::swroot}/header.pl"; | |
33 | require "${General::swroot}/countries.pl"; | |
34 | ||
35 | # enable only the following on debugging purpose | |
ce9abb66 AH |
36 | use warnings; |
37 | use CGI::Carp 'fatalsToBrowser'; | |
6e13d0a5 MT |
38 | #workaround to suppress a warning when a variable is used only once |
39 | my @dummy = ( ${Header::colourgreen} ); | |
40 | undef (@dummy); | |
41 | ||
f2fdd0c1 CS |
42 | my %color = (); |
43 | my %mainsettings = (); | |
44 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
45 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
6e13d0a5 MT |
46 | |
47 | ### | |
48 | ### Initialize variables | |
49 | ### | |
50 | my %netsettings=(); | |
51 | my %cgiparams=(); | |
52 | my %vpnsettings=(); | |
53 | my %checked=(); | |
54 | my %confighash=(); | |
55 | my %cahash=(); | |
56 | my %selected=(); | |
57 | my $warnmessage = ''; | |
58 | my $errormessage = ''; | |
59 | my %settings=(); | |
6e13d0a5 MT |
60 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
61 | $cgiparams{'ENABLED'} = 'off'; | |
62 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
63 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
64 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
65 | $cgiparams{'NAT'} = 'off'; | |
66 | $cgiparams{'COMPRESSION'} = 'off'; | |
67 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
68 | $cgiparams{'ACTION'} = ''; | |
69 | $cgiparams{'CA_NAME'} = ''; | |
70 | $cgiparams{'DHCP_DOMAIN'} = ''; | |
71 | $cgiparams{'DHCP_DNS'} = ''; | |
72 | $cgiparams{'DHCP_WINS'} = ''; | |
73 | $cgiparams{'DCOMPLZO'} = 'off'; | |
a79fa1d6 JPT |
74 | $cgiparams{'MSSFIX'} = ''; |
75 | ||
ce9abb66 | 76 | |
6e13d0a5 MT |
77 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
78 | ||
79 | # prepare openvpn config file | |
80 | ### | |
81 | ### Useful functions | |
82 | ### | |
c6c9630e MT |
83 | sub haveOrangeNet |
84 | { | |
13211b21 CS |
85 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} |
86 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
c6c9630e MT |
87 | return 0; |
88 | } | |
89 | ||
90 | sub haveBlueNet | |
91 | { | |
13211b21 | 92 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} |
c6c9630e | 93 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} |
c6c9630e MT |
94 | return 0; |
95 | } | |
96 | ||
97 | sub sizeformat{ | |
98 | my $bytesize = shift; | |
99 | my $i = 0; | |
100 | ||
101 | while(abs($bytesize) >= 1024){ | |
102 | $bytesize=$bytesize/1024; | |
103 | $i++; | |
104 | last if($i==6); | |
105 | } | |
106 | ||
107 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
108 | my $newsize=(int($bytesize*100 +0.5))/100; | |
109 | return("$newsize $units[$i]"); | |
110 | } | |
111 | ||
112 | sub valid_dns_host { | |
113 | my $hostname = $_[0]; | |
114 | unless ($hostname) { return "No hostname"}; | |
115 | my $res = new Net::DNS::Resolver; | |
116 | my $query = $res->search("$hostname"); | |
117 | if ($query) { | |
118 | foreach my $rr ($query->answer) { | |
119 | ## Potential bug - we are only looking at A records: | |
120 | return 0 if $rr->type eq "A"; | |
121 | } | |
122 | } else { | |
123 | return $res->errorstring; | |
124 | } | |
125 | } | |
126 | ||
127 | sub cleanssldatabase | |
128 | { | |
129 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
130 | print FILE "01"; | |
131 | close FILE; | |
132 | } | |
133 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
134 | print FILE ""; | |
135 | close FILE; | |
136 | } | |
137 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
138 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
139 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
140 | } | |
141 | ||
142 | sub newcleanssldatabase | |
143 | { | |
144 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
145 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
146 | print FILE "01"; | |
147 | close FILE; | |
148 | } | |
149 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
150 | system ("touch ${General::swroot}/ovpn/certs/index.txt"); | |
151 | } | |
152 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); | |
153 | unlink ("${General::swroot}/ovpn/certs/serial.old"); | |
154 | } | |
155 | ||
156 | sub deletebackupcert | |
157 | { | |
158 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
159 | my $hexvalue = <FILE>; | |
160 | chomp $hexvalue; | |
161 | close FILE; | |
162 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
163 | } | |
164 | } | |
165 | ||
166 | sub checkportfw { | |
167 | my $KEY2 = $_[0]; # key2 | |
168 | my $SRC_PORT = $_[1]; # src_port | |
169 | my $PROTOCOL = $_[2]; # protocol | |
170 | my $SRC_IP = $_[3]; # sourceip | |
171 | ||
172 | my $pfwfilename = "${General::swroot}/portfw/config"; | |
173 | open(FILE, $pfwfilename) or die 'Unable to open config file.'; | |
174 | my @pfwcurrent = <FILE>; | |
175 | close(FILE); | |
176 | my $pfwkey1 = 0; # used for finding last sequence number used | |
177 | foreach my $pfwline (@pfwcurrent) | |
178 | { | |
179 | my @pfwtemp = split(/\,/,$pfwline); | |
180 | ||
181 | chomp ($pfwtemp[8]); | |
182 | if ($KEY2 eq "0"){ # if key2 is 0 then it is a portfw addition | |
183 | if ( $SRC_PORT eq $pfwtemp[3] && | |
184 | $PROTOCOL eq $pfwtemp[2] && | |
185 | $SRC_IP eq $pfwtemp[7]) | |
186 | { | |
187 | $errormessage = "$Lang::tr{'source port in use'} $SRC_PORT"; | |
188 | } | |
189 | # Check if key2 = 0, if it is then it is a port forward entry and we want the sequence number | |
190 | if ( $pfwtemp[1] eq "0") { | |
191 | $pfwkey1=$pfwtemp[0]; | |
192 | } | |
193 | # Darren Critchley - Duplicate or overlapping Port range check | |
194 | if ($pfwtemp[1] eq "0" && | |
195 | $PROTOCOL eq $pfwtemp[2] && | |
196 | $SRC_IP eq $pfwtemp[7] && | |
197 | $errormessage eq '') | |
198 | { | |
199 | &portchecks($SRC_PORT, $pfwtemp[5]); | |
200 | # &portchecks($pfwtemp[3], $pfwtemp[5]); | |
201 | # &portchecks($pfwtemp[3], $SRC_IP); | |
202 | } | |
203 | } | |
204 | } | |
205 | # $errormessage="$KEY2 $SRC_PORT $PROTOCOL $SRC_IP"; | |
206 | ||
207 | return; | |
208 | } | |
209 | ||
210 | sub checkportoverlap | |
211 | { | |
212 | my $portrange1 = $_[0]; # New port range | |
213 | my $portrange2 = $_[1]; # existing port range | |
214 | my @tempr1 = split(/\:/,$portrange1); | |
215 | my @tempr2 = split(/\:/,$portrange2); | |
216 | ||
217 | unless (&checkportinc($tempr1[0], $portrange2)){ return 0;} | |
218 | unless (&checkportinc($tempr1[1], $portrange2)){ return 0;} | |
219 | ||
220 | unless (&checkportinc($tempr2[0], $portrange1)){ return 0;} | |
221 | unless (&checkportinc($tempr2[1], $portrange1)){ return 0;} | |
222 | ||
223 | return 1; # Everything checks out! | |
224 | } | |
225 | ||
226 | # Darren Critchley - we want to make sure that a port entry is not within an already existing range | |
227 | sub checkportinc | |
228 | { | |
229 | my $port1 = $_[0]; # Port | |
230 | my $portrange2 = $_[1]; # Port range | |
231 | my @tempr1 = split(/\:/,$portrange2); | |
232 | ||
233 | if ($port1 < $tempr1[0] || $port1 > $tempr1[1]) { | |
234 | return 1; | |
235 | } else { | |
236 | return 0; | |
237 | } | |
238 | } | |
239 | # Darren Critchley - Duplicate or overlapping Port range check | |
240 | sub portchecks | |
241 | { | |
242 | my $p1 = $_[0]; # New port range | |
243 | my $p2 = $_[1]; # existing port range | |
244 | # $_ = $_[0]; | |
245 | our ($prtrange1, $prtrange2); | |
246 | $prtrange1 = 0; | |
247 | # if (m/:/ && $prtrange1 == 1) { # comparing two port ranges | |
248 | # unless (&checkportoverlap($p1,$p2)) { | |
249 | # $errormessage = "$Lang::tr{'source port overlaps'} $p1"; | |
250 | # } | |
251 | # } | |
252 | if (m/:/ && $prtrange1 == 0 && $errormessage eq '') { # compare one port to a range | |
253 | unless (&checkportinc($p2,$p1)) { | |
254 | $errormessage = "$Lang::tr{'srcprt within existing'} $p1"; | |
255 | } | |
256 | } | |
257 | $prtrange1 = 1; | |
258 | if (! m/:/ && $prtrange1 == 1 && $errormessage eq '') { # compare one port to a range | |
259 | unless (&checkportinc($p1,$p2)) { | |
260 | $errormessage = "$Lang::tr{'srcprt range overlaps'} $p2"; | |
261 | } | |
262 | } | |
263 | return; | |
264 | } | |
265 | ||
266 | # Darren Critchley - certain ports are reserved for IPFire | |
267 | # TCP 67,68,81,222,445 | |
268 | # UDP 67,68 | |
269 | # Params passed in -> port, rangeyn, protocol | |
270 | sub disallowreserved | |
271 | { | |
272 | # port 67 and 68 same for tcp and udp, don't bother putting in an array | |
273 | my $msg = ""; | |
274 | my @tcp_reserved = (81,222,445); | |
275 | my $prt = $_[0]; # the port or range | |
276 | my $ryn = $_[1]; # tells us whether or not it is a port range | |
277 | my $prot = $_[2]; # protocol | |
278 | my $srcdst = $_[3]; # source or destination | |
279 | if ($ryn) { # disect port range | |
280 | if ($srcdst eq "src") { | |
281 | $msg = "$Lang::tr{'rsvd src port overlap'}"; | |
282 | } else { | |
283 | $msg = "$Lang::tr{'rsvd dst port overlap'}"; | |
284 | } | |
285 | my @tmprng = split(/\:/,$prt); | |
286 | unless (67 < $tmprng[0] || 67 > $tmprng[1]) { $errormessage="$msg 67"; return; } | |
287 | unless (68 < $tmprng[0] || 68 > $tmprng[1]) { $errormessage="$msg 68"; return; } | |
288 | if ($prot eq "tcp") { | |
289 | foreach my $prange (@tcp_reserved) { | |
290 | unless ($prange < $tmprng[0] || $prange > $tmprng[1]) { $errormessage="$msg $prange"; return; } | |
291 | } | |
292 | } | |
293 | } else { | |
294 | if ($srcdst eq "src") { | |
295 | $msg = "$Lang::tr{'reserved src port'}"; | |
296 | } else { | |
297 | $msg = "$Lang::tr{'reserved dst port'}"; | |
298 | } | |
299 | if ($prt == 67) { $errormessage="$msg 67"; return; } | |
300 | if ($prt == 68) { $errormessage="$msg 68"; return; } | |
301 | if ($prot eq "tcp") { | |
302 | foreach my $prange (@tcp_reserved) { | |
303 | if ($prange == $prt) { $errormessage="$msg $prange"; return; } | |
304 | } | |
305 | } | |
306 | } | |
307 | return; | |
308 | } | |
309 | ||
310 | sub writeserverconf { | |
311 | my %sovpnsettings = (); | |
312 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); | |
313 | ||
314 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; | |
315 | flock CONF, 2; | |
316 | print CONF "#OpenVPN Server conf\n"; | |
317 | print CONF "\n"; | |
318 | print CONF "daemon openvpnserver\n"; | |
319 | print CONF "writepid /var/run/openvpn.pid\n"; | |
afabe9f7 | 320 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; |
c6c9630e MT |
321 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; |
322 | print CONF "dev $sovpnsettings{'DDEVICE'}\n"; | |
323 | print CONF "$sovpnsettings{'DDEVICE'}-mtu $sovpnsettings{'DMTU'}\n"; | |
324 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; | |
325 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
2b29c22e | 326 | print CONF "script-security 3 system\n"; |
07675dc3 | 327 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; |
c6c9630e MT |
328 | print CONF "tls-server\n"; |
329 | print CONF "ca /var/ipfire/ovpn/ca/cacert.pem\n"; | |
330 | print CONF "cert /var/ipfire/ovpn/certs/servercert.pem\n"; | |
331 | print CONF "key /var/ipfire/ovpn/certs/serverkey.pem\n"; | |
332 | print CONF "dh /var/ipfire/ovpn/ca/dh1024.pem\n"; | |
333 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); | |
334 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
335 | print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; | |
336 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { | |
337 | print CONF "client-to-client\n"; | |
338 | } | |
a79fa1d6 JPT |
339 | if ($sovpnsettings{MSSFIX} eq 'on') { |
340 | print CONF "mssfix\n"; | |
341 | } | |
74225cce | 342 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { |
a79fa1d6 JPT |
343 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
344 | } | |
c6c9630e MT |
345 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
346 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; | |
347 | } | |
348 | print CONF "status-version 1\n"; | |
4e17adad | 349 | print CONF "status /var/log/ovpnserver.log 30\n"; |
c6c9630e MT |
350 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
351 | if ($sovpnsettings{DCOMPLZO} eq 'on') { | |
352 | print CONF "comp-lzo\n"; | |
353 | } | |
354 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
355 | print CONF "push \"redirect-gateway def1\"\n"; | |
356 | } | |
357 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
358 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
359 | } | |
360 | ||
361 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
362 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
363 | } | |
364 | ||
365 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
366 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
367 | } | |
368 | ||
369 | if ($sovpnsettings{DHCP_WINS} eq '') { | |
370 | print CONF "max-clients 100\n"; | |
a79fa1d6 | 371 | } |
c6c9630e MT |
372 | if ($sovpnsettings{DHCP_WINS} ne '') { |
373 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; | |
374 | } | |
375 | print CONF "tls-verify /var/ipfire/ovpn/verify\n"; | |
376 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; | |
377 | print CONF "user nobody\n"; | |
378 | print CONF "group nobody\n"; | |
379 | print CONF "persist-key\n"; | |
380 | print CONF "persist-tun\n"; | |
381 | if ($sovpnsettings{LOG_VERB} ne '') { | |
382 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
383 | } else { | |
384 | print CONF "verb 3\n"; | |
385 | } | |
386 | print CONF "\n"; | |
387 | ||
388 | close(CONF); | |
389 | } | |
390 | # | |
391 | sub emptyserverlog{ | |
4e17adad | 392 | if (open(FILE, ">/var/log/ovpnserver.log")) { |
c6c9630e MT |
393 | flock FILE, 2; |
394 | print FILE ""; | |
395 | close FILE; | |
396 | } | |
397 | ||
398 | } | |
399 | ||
7c1d9faf AH |
400 | ### |
401 | # m.a.d net2net | |
402 | ### | |
403 | ||
404 | sub validdotmask | |
405 | { | |
406 | my $ipdotmask = $_[0]; | |
407 | if (&General::validip($ipdotmask)) { return 0; } | |
408 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
409 | my $mask = $2; | |
410 | if (($mask =~ /\./ )) { return 0; } | |
411 | return 1; | |
412 | } | |
413 | ||
414 | ||
415 | ||
c6c9630e MT |
416 | #hier die refresh page |
417 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
418 | my $refresh = ''; | |
419 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
420 | &Header::showhttpheaders(); | |
421 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
422 | &Header::openbigbox('100%', 'center'); | |
423 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
424 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
425 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
426 | &Header::closebox(); | |
427 | &Header::closebigbox(); | |
428 | &Header::closepage(); | |
429 | exit (0); | |
430 | } | |
431 | ##hier die refresh page | |
432 | ||
6e13d0a5 MT |
433 | |
434 | ### | |
435 | ### OpenVPN Server Control | |
436 | ### | |
437 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
438 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
439 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
440 | #start openvpn server |
441 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 442 | &emptyserverlog(); |
6e13d0a5 MT |
443 | system('/usr/local/bin/openvpnctrl', '-s'); |
444 | } | |
445 | #stop openvpn server | |
446 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
6e13d0a5 | 447 | system('/usr/local/bin/openvpnctrl', '-k'); |
c6c9630e | 448 | &emptyserverlog(); |
6e13d0a5 MT |
449 | } |
450 | # #restart openvpn server | |
451 | if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ | |
452 | #workarund, till SIGHUP also works when running as nobody | |
c6c9630e MT |
453 | system('/usr/local/bin/openvpnctrl', '-r'); |
454 | &emptyserverlog(); | |
6e13d0a5 MT |
455 | } |
456 | } | |
457 | ||
458 | ### | |
459 | ### Save Advanced options | |
460 | ### | |
461 | ||
462 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
463 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
464 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
465 | #DAN this value has to leave. | |
466 | #new settings for daemon | |
467 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
468 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
469 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
470 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
471 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
472 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
473 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; | |
474 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
475 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
6e13d0a5 | 476 | |
a79fa1d6 JPT |
477 | if ($cgiparams{'FRAGMENT'} eq '') { |
478 | delete $vpnsettings{'FRAGMENT'}; | |
479 | } else { | |
480 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { | |
481 | $errormessage = "Incorrect value, please insert only numbers."; | |
482 | goto ADV_ERROR; | |
483 | } else { | |
484 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
485 | } | |
486 | } | |
487 | if ($cgiparams{'MSSFIX'} ne 'on') { | |
488 | delete $vpnsettings{'MSSFIX'}; | |
489 | } else { | |
490 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
491 | } | |
6e13d0a5 MT |
492 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
493 | unless (&General::validfqdn($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { | |
494 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; | |
495 | goto ADV_ERROR; | |
496 | } | |
497 | } | |
498 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
499 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
500 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
501 | goto ADV_ERROR; | |
502 | } | |
503 | } | |
504 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
505 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
506 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
507 | goto ADV_ERROR; | |
508 | } | |
509 | } | |
6e13d0a5 MT |
510 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 255 )) { |
511 | $errormessage = $Lang::tr{'invalid input for max clients'}; | |
512 | goto ADV_ERROR; | |
513 | } | |
514 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
515 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { | |
516 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; | |
517 | goto ADV_ERROR; | |
518 | } | |
519 | } | |
520 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
521 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { | |
522 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; | |
523 | goto ADV_ERROR; | |
524 | } | |
525 | } | |
526 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
527 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
528 | goto ADV_ERROR; | |
529 | } | |
530 | ||
531 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 532 | &writeserverconf();#hier ok |
6e13d0a5 MT |
533 | } |
534 | ||
ce9abb66 | 535 | ### |
7c1d9faf | 536 | # m.a.d net2net |
ce9abb66 AH |
537 | ### |
538 | ||
539 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
540 | { | |
c6c9630e | 541 | |
ce9abb66 AH |
542 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
543 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
544 | my $ovsubnet = "@ovsubnettemp[0].@ovsubnettemp[1].@ovsubnettemp[2]"; | |
d96c89eb | 545 | my $tunmtu = ''; |
531f0835 AH |
546 | |
547 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
548 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
549 | |
550 | 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: $!"; | |
551 | ||
552 | flock SERVERCONF, 2; | |
7c1d9faf | 553 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
ce9abb66 | 554 | print SERVERCONF "\n"; |
b278daf3 | 555 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
556 | print SERVERCONF "user nobody\n"; |
557 | print SERVERCONF "group nobody\n"; | |
558 | print SERVERCONF "persist-tun\n"; | |
559 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 560 | print SERVERCONF "script-security 2\n"; |
b278daf3 | 561 | print SERVERCONF "# IP/DNS for the Server Gateway - g2g Mode\n"; |
ce9abb66 | 562 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 AH |
563 | print SERVERCONF "float\n"; |
564 | print SERVERCONF "# IP address of the n2n VPN Subnet\n"; | |
ce9abb66 | 565 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; |
b278daf3 | 566 | print SERVERCONF "# Client gateway network\n"; |
ce9abb66 | 567 | print SERVERCONF "route @remsubnet[0] @remsubnet[1]\n"; |
b278daf3 | 568 | print SERVERCONF "# tun device\n"; |
ce9abb66 | 569 | print SERVERCONF "dev tun\n"; |
b278daf3 | 570 | print SERVERCONF "#Port and protocol\n"; |
ce9abb66 AH |
571 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; |
572 | print SERVERCONF "proto $cgiparams{'PROTOCOL'}\n"; | |
b278daf3 | 573 | print SERVERCONF "# Paketsize\n"; |
d96c89eb | 574 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
ce9abb66 | 575 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb AH |
576 | if ($cgiparams{'PROTOCOL'} eq 'udp') { |
577 | if ($cgiparams{'FRAGMENT'} eq '') { | |
578 | print SERVERCONF "fragment 1300\r\n"; | |
579 | } else { | |
580 | print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n" | |
581 | } | |
582 | if ($cgiparams{'MSSFIX'} eq 'on') { | |
ce9abb66 | 583 | print SERVERCONF "mssfix\n"; |
d96c89eb AH |
584 | } |
585 | } | |
ce9abb66 AH |
586 | print SERVERCONF "# Auth Server\n"; |
587 | print SERVERCONF "tls-server\n"; | |
588 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
589 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
590 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
591 | print SERVERCONF "dh ${General::swroot}/ovpn/ca/dh1024.pem\n"; | |
b278daf3 | 592 | print SERVERCONF "# Cipher\n"; |
ce9abb66 AH |
593 | print SERVERCONF "cipher AES-256-CBC\n"; |
594 | if ($cgiparams{'COMPLZO'} eq 'on') { | |
b278daf3 | 595 | print SERVERCONF "# Enable compession\n"; |
ce9abb66 | 596 | print SERVERCONF "comp-lzo\r\n"; |
b278daf3 AH |
597 | } |
598 | print SERVERCONF "# Debug level\n"; | |
ce9abb66 | 599 | print SERVERCONF "verb 3\n"; |
b278daf3 | 600 | print SERVERCONF "# Tunnel check\n"; |
ce9abb66 | 601 | print SERVERCONF "keepalive 10 60\n"; |
b278daf3 | 602 | print SERVERCONF "# start as daemon\n"; |
ce9abb66 AH |
603 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; |
604 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
b278daf3 | 605 | print SERVERCONF "# Activate Management Interface on Port\n"; |
ce9abb66 AH |
606 | print SERVERCONF "#management localhost 4711\n"; |
607 | close(SERVERCONF); | |
608 | ||
609 | } | |
610 | ||
611 | ### | |
7c1d9faf | 612 | # m.a.d net2net |
ce9abb66 | 613 | ### |
7c1d9faf | 614 | |
ce9abb66 AH |
615 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
616 | { | |
617 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
618 | my $ovsubnet = "@ovsubnettemp[0].@ovsubnettemp[1].@ovsubnettemp[2]"; | |
619 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); | |
d96c89eb AH |
620 | my $tunmtu = ''; |
621 | ||
531f0835 AH |
622 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
623 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
624 | |
625 | 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: $!"; | |
626 | ||
627 | flock CLIENTCONF, 2; | |
7c1d9faf | 628 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 629 | print CLIENTCONF "#\n"; |
b278daf3 | 630 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
631 | print CLIENTCONF "user nobody\n"; |
632 | print CLIENTCONF "group nobody\n"; | |
633 | print CLIENTCONF "persist-tun\n"; | |
634 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 635 | print CLIENTCONF "script-security 2\n"; |
b278daf3 | 636 | print CLIENTCONF "# IP/DNS for the Server Gateway - g2g Mode\n"; |
ce9abb66 | 637 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 AH |
638 | print CLIENTCONF "float\n"; |
639 | print CLIENTCONF "# IP address of the n2n VPN Subnet\n"; | |
ce9abb66 | 640 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 641 | print CLIENTCONF "# Server gateway network\n"; |
7c1d9faf | 642 | print CLIENTCONF "route @remsubnet[0] @remsubnet[1]\n"; |
b278daf3 | 643 | print CLIENTCONF "# tun device\n"; |
ce9abb66 | 644 | print CLIENTCONF "dev tun\n"; |
b278daf3 | 645 | print CLIENTCONF "#Port and protocol\n"; |
ce9abb66 AH |
646 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; |
647 | print CLIENTCONF "proto $cgiparams{'PROTOCOL'}\n"; | |
b278daf3 | 648 | print CLIENTCONF "# Paketsize\n"; |
d96c89eb | 649 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
ce9abb66 | 650 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb AH |
651 | if ($cgiparams{'PROTOCOL'} eq 'udp') { |
652 | if ($cgiparams{'FRAGMENT'} eq '') { | |
653 | print CLIENTCONF "fragment 1300\r\n"; | |
654 | } else { | |
655 | print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n" | |
656 | } | |
657 | if ($cgiparams{'MSSFIX'} eq 'on') { | |
ce9abb66 | 658 | print CLIENTCONF "mssfix\n"; |
d96c89eb AH |
659 | } |
660 | } | |
ce9abb66 AH |
661 | print CLIENTCONF "# Auth. Client\n"; |
662 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 663 | print CLIENTCONF "# Cipher\n"; |
ce9abb66 AH |
664 | print CLIENTCONF "cipher AES-256-CBC\n"; |
665 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; | |
ce9abb66 | 666 | if ($cgiparams{'COMPLZO'} eq 'on') { |
b278daf3 | 667 | print CLIENTCONF "# Enable compession\n"; |
ce9abb66 | 668 | print CLIENTCONF "comp-lzo\r\n"; |
b278daf3 | 669 | } |
ce9abb66 AH |
670 | print CLIENTCONF "# Debug Level\n"; |
671 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 672 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 673 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 674 | print CLIENTCONF "# Start sa daemon\n"; |
ce9abb66 AH |
675 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
676 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
b278daf3 | 677 | print CLIENTCONF "# Activate Management Interface on Port\n"; |
ce9abb66 AH |
678 | print CLIENTCONF "# management localhost 4711\n"; |
679 | close(CLIENTCONF); | |
c6c9630e | 680 | |
ce9abb66 AH |
681 | } |
682 | ||
6e13d0a5 MT |
683 | ### |
684 | ### Save main settings | |
685 | ### | |
ce9abb66 AH |
686 | |
687 | ||
6e13d0a5 MT |
688 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
689 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
690 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
691 | #DAN this value has to leave. | |
692 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
693 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
694 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 695 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
696 | } |
697 | } | |
698 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
c6c9630e | 699 | &disallowreserved($cgiparams{'DDEST_PORT'},0,$cgiparams{'DPROTOCOL'},"dest"); |
6e13d0a5 MT |
700 | } |
701 | if ($errormessage) { goto SETTINGS_ERROR; } | |
702 | ||
703 | ||
704 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
c6c9630e | 705 | &checkportfw(0,$cgiparams{'DDEST_PORT'},$cgiparams{'DPROTOCOL'},'0.0.0.0'); |
6e13d0a5 MT |
706 | } |
707 | ||
708 | if ($errormessage) { goto SETTINGS_ERROR; } | |
709 | ||
710 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { | |
c6c9630e MT |
711 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
712 | goto SETTINGS_ERROR; | |
713 | } | |
714 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
715 | ||
716 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
717 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
718 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
719 | goto SETTINGS_ERROR; | |
720 | } | |
721 | ||
722 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
723 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
724 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
725 | goto SETTINGS_ERROR; | |
726 | } | |
727 | ||
728 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, | |
729 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
730 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
731 | goto SETTINGS_ERROR; | |
732 | } | |
733 | ||
734 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
735 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
736 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
737 | goto SETTINGS_ERROR; | |
738 | } | |
739 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
740 | while (<ALIASES>) | |
741 | { | |
742 | chomp($_); | |
743 | my @tempalias = split(/\,/,$_); | |
744 | if ($tempalias[1] eq 'on') { | |
745 | if (&General::IpInSubnet ($tempalias[0] , | |
746 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { | |
747 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
748 | } | |
749 | } | |
750 | } | |
751 | close(ALIASES); | |
6e13d0a5 | 752 | if ($errormessage ne ''){ |
c6c9630e | 753 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
754 | } |
755 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
756 | $errormessage = $Lang::tr{'invalid input'}; | |
757 | goto SETTINGS_ERROR; | |
758 | } | |
759 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
760 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
761 | goto SETTINGS_ERROR; | |
762 | } | |
763 | ||
764 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { | |
c6c9630e MT |
765 | $errormessage = $Lang::tr{'invalid port'}; |
766 | goto SETTINGS_ERROR; | |
6e13d0a5 | 767 | } |
6e13d0a5 MT |
768 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
769 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
770 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
771 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
772 | #new settings for daemon | |
773 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
774 | $vpnsettings{'DDEVICE'} = $cgiparams{'DDEVICE'}; | |
775 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; | |
776 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
777 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
778 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
779 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
3ffee04b CS |
780 | #wrtie enable |
781 | ||
782 | 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");} | |
783 | 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");} | |
784 | 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 |
785 | #new settings for daemon |
786 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
c6c9630e | 787 | &writeserverconf();#hier ok |
6e13d0a5 MT |
788 | SETTINGS_ERROR: |
789 | ### | |
790 | ### Reset all step 2 | |
791 | ### | |
792 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
793 | my $file = ''; | |
794 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
795 | ||
796 | foreach my $key (keys %confighash) { | |
c6c9630e MT |
797 | if ($confighash{$key}[4] eq 'cert') { |
798 | delete $confighash{$cgiparams{'$key'}}; | |
799 | } | |
6e13d0a5 MT |
800 | } |
801 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
c6c9630e | 802 | unlink $file |
6e13d0a5 MT |
803 | } |
804 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
c6c9630e | 805 | unlink $file |
6e13d0a5 MT |
806 | } |
807 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
c6c9630e | 808 | unlink $file |
6e13d0a5 | 809 | } |
c6c9630e | 810 | &cleanssldatabase(); |
6e13d0a5 MT |
811 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
812 | print FILE ""; | |
813 | close FILE; | |
814 | } | |
815 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 816 | #&writeserverconf(); |
6e13d0a5 MT |
817 | ### |
818 | ### Reset all step 1 | |
819 | ### | |
820 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'reset'}) { | |
821 | &Header::showhttpheaders(); | |
822 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
823 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
824 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
825 | print <<END | |
826 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
827 | <tr><td align='center'> | |
828 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
829 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'} | |
830 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /> | |
831 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
832 | </form></table> | |
833 | END | |
834 | ; | |
835 | &Header::closebox(); | |
836 | &Header::closebigbox(); | |
837 | &Header::closepage(); | |
838 | exit (0); | |
839 | ||
840 | ### | |
841 | ### Upload CA Certificate | |
842 | ### | |
843 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
844 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
845 | ||
846 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
847 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
848 | goto UPLOADCA_ERROR; | |
849 | } | |
850 | ||
851 | if (length($cgiparams{'CA_NAME'}) >60) { | |
852 | $errormessage = $Lang::tr{'name too long'}; | |
853 | goto VPNCONF_ERROR; | |
854 | } | |
855 | ||
856 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
857 | $errormessage = $Lang::tr{'name is invalid'}; | |
858 | goto UPLOAD_CA_ERROR; | |
859 | } | |
860 | ||
861 | # Check if there is no other entry with this name | |
862 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
863 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
864 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
865 | goto UPLOADCA_ERROR; | |
866 | } | |
6e13d0a5 MT |
867 | } |
868 | ||
869 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
c6c9630e MT |
870 | $errormessage = $Lang::tr{'there was no file upload'}; |
871 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
872 | } |
873 | # Move uploaded ca to a temporary file | |
874 | (my $fh, my $filename) = tempfile( ); | |
875 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
876 | $errormessage = $!; |
877 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
878 | } |
879 | my $temp = `/usr/bin/openssl x509 -text -in $filename`; | |
c6c9630e MT |
880 | if ($temp !~ /CA:TRUE/i) { |
881 | $errormessage = $Lang::tr{'not a valid ca certificate'}; | |
882 | unlink ($filename); | |
883 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 884 | } else { |
c6c9630e MT |
885 | move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
886 | if ($? ne 0) { | |
887 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
888 | unlink ($filename); | |
889 | goto UPLOADCA_ERROR; | |
890 | } | |
6e13d0a5 MT |
891 | } |
892 | ||
893 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem`; | |
894 | $casubject =~ /Subject: (.*)[\n]/; | |
895 | $casubject = $1; | |
896 | $casubject =~ s+/Email+, E+; | |
897 | $casubject =~ s/ ST=/ S=/; | |
898 | $casubject = &Header::cleanhtml($casubject); | |
899 | ||
900 | my $key = &General::findhasharraykey (\%cahash); | |
901 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
902 | $cahash{$key}[1] = $casubject; | |
903 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
904 | # system('/usr/local/bin/ipsecctrl', 'R'); |
905 | ||
6e13d0a5 MT |
906 | UPLOADCA_ERROR: |
907 | ||
908 | ### | |
909 | ### Display ca certificate | |
910 | ### | |
911 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
912 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
913 | ||
914 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
915 | &Header::showhttpheaders(); | |
916 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
917 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
918 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
919 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
920 | $output = &Header::cleanhtml($output,"y"); | |
921 | print "<pre>$output</pre>\n"; | |
922 | &Header::closebox(); | |
923 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
924 | &Header::closebigbox(); | |
925 | &Header::closepage(); | |
926 | exit(0); | |
927 | } else { | |
928 | $errormessage = $Lang::tr{'invalid key'}; | |
929 | } | |
930 | ||
6e13d0a5 MT |
931 | ### |
932 | ### Download ca certificate | |
933 | ### | |
934 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
935 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
936 | ||
937 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
938 | print "Content-Type: application/octet-stream\r\n"; | |
939 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
940 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem`; | |
941 | exit(0); | |
942 | } else { | |
943 | $errormessage = $Lang::tr{'invalid key'}; | |
944 | } | |
945 | ||
946 | ### | |
947 | ### Remove ca certificate (step 2) | |
948 | ### | |
949 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
950 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
951 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
952 | ||
953 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
954 | foreach my $key (keys %confighash) { | |
955 | 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`; | |
956 | if ($test =~ /: OK/) { | |
c6c9630e MT |
957 | # Delete connection |
958 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
959 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
960 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
961 | # } | |
6e13d0a5 MT |
962 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
963 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
964 | delete $confighash{$key}; | |
965 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 966 | # &writeipsecfiles(); |
6e13d0a5 MT |
967 | } |
968 | } | |
969 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
970 | delete $cahash{$cgiparams{'KEY'}}; | |
971 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 972 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
973 | } else { |
974 | $errormessage = $Lang::tr{'invalid key'}; | |
975 | } | |
976 | ### | |
977 | ### Remove ca certificate (step 1) | |
978 | ### | |
979 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
980 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
981 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
982 | ||
983 | my $assignedcerts = 0; | |
984 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
985 | foreach my $key (keys %confighash) { | |
986 | 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`; | |
987 | if ($test =~ /: OK/) { | |
988 | $assignedcerts++; | |
989 | } | |
990 | } | |
991 | if ($assignedcerts) { | |
992 | &Header::showhttpheaders(); | |
993 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
994 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
995 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
996 | print <<END | |
997 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> | |
998 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
999 | <tr><td align='center'> | |
1000 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1001 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1002 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1003 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1004 | </form></table> | |
1005 | END | |
1006 | ; | |
1007 | &Header::closebox(); | |
1008 | &Header::closebigbox(); | |
1009 | &Header::closepage(); | |
1010 | exit (0); | |
1011 | } else { | |
1012 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1013 | delete $cahash{$cgiparams{'KEY'}}; | |
1014 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1015 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1016 | } | |
1017 | } else { | |
1018 | $errormessage = $Lang::tr{'invalid key'}; | |
1019 | } | |
1020 | ||
1021 | ### | |
1022 | ### Display root certificate | |
1023 | ### | |
c6c9630e MT |
1024 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1025 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
1026 | my $output; | |
1027 | &Header::showhttpheaders(); | |
1028 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1029 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1030 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1031 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
1032 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1033 | } else { | |
1034 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
1035 | $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1036 | } | |
1037 | $output = &Header::cleanhtml($output,"y"); | |
1038 | print "<pre>$output</pre>\n"; | |
1039 | &Header::closebox(); | |
1040 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1041 | &Header::closebigbox(); | |
1042 | &Header::closepage(); | |
1043 | exit(0); | |
1044 | ||
6e13d0a5 MT |
1045 | ### |
1046 | ### Download root certificate | |
1047 | ### | |
1048 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1049 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1050 | print "Content-Type: application/octet-stream\r\n"; | |
1051 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
1052 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/ca/cacert.pem`; | |
1053 | exit(0); | |
1054 | } | |
1055 | ||
1056 | ### | |
1057 | ### Download host certificate | |
1058 | ### | |
1059 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1060 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1061 | print "Content-Type: application/octet-stream\r\n"; | |
1062 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
1063 | print `/usr/bin/openssl x509 -in ${General::swroot}/ovpn/certs/servercert.pem`; | |
1064 | exit(0); | |
1065 | } | |
1066 | ### | |
1067 | ### Form for generating a root certificate | |
1068 | ### | |
1069 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1070 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1071 | ||
1072 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1073 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1074 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1075 | $cgiparams{'ACTION'} = ''; | |
1076 | goto ROOTCERT_ERROR; | |
1077 | } | |
1078 | ||
1079 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1080 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1081 | my $ipaddr = <IPADDR>; | |
1082 | close IPADDR; | |
1083 | chomp ($ipaddr); | |
1084 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1085 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1086 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1087 | } | |
1088 | } | |
1089 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1090 | ||
1091 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
1092 | $errormessage = $Lang::tr{'there was no file upload'}; | |
1093 | goto ROOTCERT_ERROR; | |
1094 | } | |
1095 | ||
1096 | # Move uploaded certificate request to a temporary file | |
1097 | (my $fh, my $filename) = tempfile( ); | |
1098 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1099 | $errormessage = $!; | |
1100 | goto ROOTCERT_ERROR; | |
1101 | } | |
1102 | ||
1103 | # Create a temporary dirctory | |
1104 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1105 | ||
1106 | # Extract the CA certificate from the file | |
1107 | my $pid = open(OPENSSL, "|-"); | |
1108 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1109 | if ($pid) { # parent | |
1110 | if ($cgiparams{'P12_PASS'} ne '') { | |
1111 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1112 | } | |
1113 | close (OPENSSL); | |
1114 | if ($?) { | |
1115 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1116 | unlink ($filename); | |
1117 | goto ROOTCERT_ERROR; | |
1118 | } | |
1119 | } else { # child | |
1120 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1121 | '-in', $filename, | |
1122 | '-out', "$tempdir/cacert.pem")) { | |
1123 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1124 | unlink ($filename); | |
1125 | goto ROOTCERT_ERROR; | |
1126 | } | |
1127 | } | |
1128 | ||
1129 | # Extract the Host certificate from the file | |
1130 | $pid = open(OPENSSL, "|-"); | |
1131 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1132 | if ($pid) { # parent | |
1133 | if ($cgiparams{'P12_PASS'} ne '') { | |
1134 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1135 | } | |
1136 | close (OPENSSL); | |
1137 | if ($?) { | |
1138 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1139 | unlink ($filename); | |
1140 | goto ROOTCERT_ERROR; | |
1141 | } | |
1142 | } else { # child | |
1143 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1144 | '-in', $filename, | |
1145 | '-out', "$tempdir/hostcert.pem")) { | |
1146 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1147 | unlink ($filename); | |
1148 | goto ROOTCERT_ERROR; | |
1149 | } | |
1150 | } | |
1151 | ||
1152 | # Extract the Host key from the file | |
1153 | $pid = open(OPENSSL, "|-"); | |
1154 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1155 | if ($pid) { # parent | |
1156 | if ($cgiparams{'P12_PASS'} ne '') { | |
1157 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1158 | } | |
1159 | close (OPENSSL); | |
1160 | if ($?) { | |
1161 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1162 | unlink ($filename); | |
1163 | goto ROOTCERT_ERROR; | |
1164 | } | |
1165 | } else { # child | |
1166 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1167 | '-nodes', | |
1168 | '-in', $filename, | |
1169 | '-out', "$tempdir/serverkey.pem")) { | |
1170 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1171 | unlink ($filename); | |
1172 | goto ROOTCERT_ERROR; | |
1173 | } | |
1174 | } | |
1175 | ||
1176 | move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem"); | |
1177 | if ($? ne 0) { | |
1178 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1179 | unlink ($filename); | |
1180 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1181 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1182 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1183 | goto ROOTCERT_ERROR; | |
1184 | } | |
1185 | ||
1186 | move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem"); | |
1187 | if ($? ne 0) { | |
1188 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1189 | unlink ($filename); | |
1190 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1191 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1192 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1193 | goto ROOTCERT_ERROR; | |
1194 | } | |
1195 | ||
1196 | move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem"); | |
1197 | if ($? ne 0) { | |
1198 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
1199 | unlink ($filename); | |
1200 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1201 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1202 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1203 | goto ROOTCERT_ERROR; | |
1204 | } | |
1205 | ||
1206 | goto ROOTCERT_SUCCESS; | |
1207 | ||
1208 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1209 | ||
1210 | # Validate input since the form was submitted | |
1211 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1212 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1213 | goto ROOTCERT_ERROR; | |
1214 | } | |
1215 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1216 | $errormessage = $Lang::tr{'organization too long'}; | |
1217 | goto ROOTCERT_ERROR; | |
1218 | } | |
1219 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1220 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1221 | goto ROOTCERT_ERROR; | |
1222 | } | |
1223 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1224 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1225 | goto ROOTCERT_ERROR; | |
1226 | } | |
1227 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1228 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1229 | goto ROOTCERT_ERROR; | |
1230 | } | |
1231 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1232 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1233 | goto ROOTCERT_ERROR; | |
1234 | } | |
1235 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1236 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1237 | goto ROOTCERT_ERROR; | |
1238 | } | |
1239 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1240 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1241 | goto ROOTCERT_ERROR; | |
1242 | } | |
1243 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1244 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1245 | goto ROOTCERT_ERROR; | |
1246 | } | |
1247 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1248 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1249 | goto ROOTCERT_ERROR; | |
1250 | } | |
1251 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1252 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1253 | goto ROOTCERT_ERROR; | |
1254 | } | |
1255 | ||
1256 | # Copy the cgisettings to vpnsettings and save the configfile | |
1257 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1258 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1259 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1260 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1261 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1262 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1263 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1264 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1265 | ||
1266 | # Replace empty strings with a . | |
1267 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1268 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1269 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1270 | ||
1271 | # refresh | |
c6c9630e | 1272 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
6e13d0a5 MT |
1273 | |
1274 | # Create the CA certificate | |
1275 | my $pid = open(OPENSSL, "|-"); | |
1276 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1277 | if ($pid) { # parent | |
1278 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1279 | print OPENSSL "$state\n"; | |
1280 | print OPENSSL "$city\n"; | |
1281 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1282 | print OPENSSL "$ou\n"; | |
1283 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1284 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1285 | close (OPENSSL); | |
1286 | if ($?) { | |
1287 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1288 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1289 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1290 | goto ROOTCERT_ERROR; | |
1291 | } | |
1292 | } else { # child | |
1293 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1294 | '-days', '999999', '-newkey', 'rsa:2048', | |
1295 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", | |
1296 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1297 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1298 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1299 | goto ROOTCERT_ERROR; | |
1300 | } | |
1301 | } | |
1302 | ||
1303 | # Create the Host certificate request | |
1304 | $pid = open(OPENSSL, "|-"); | |
1305 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1306 | if ($pid) { # parent | |
1307 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1308 | print OPENSSL "$state\n"; | |
1309 | print OPENSSL "$city\n"; | |
1310 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1311 | print OPENSSL "$ou\n"; | |
1312 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1313 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1314 | print OPENSSL ".\n"; | |
1315 | print OPENSSL ".\n"; | |
1316 | close (OPENSSL); | |
1317 | if ($?) { | |
1318 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1319 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1320 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1321 | goto ROOTCERT_ERROR; | |
1322 | } | |
1323 | } else { # child | |
1324 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1325 | '-newkey', 'rsa:1024', | |
1326 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", | |
1327 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1328 | '-extensions', 'server', | |
1329 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1330 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1331 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1332 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1333 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1334 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1335 | goto ROOTCERT_ERROR; | |
1336 | } | |
1337 | } | |
1338 | ||
1339 | # Sign the host certificate request | |
1340 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
1341 | '-batch', '-notext', | |
1342 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1343 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1344 | '-extensions', 'server', | |
1345 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1346 | if ($?) { | |
1347 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1348 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1349 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1350 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1351 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1352 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1353 | &newcleanssldatabase(); |
6e13d0a5 MT |
1354 | goto ROOTCERT_ERROR; |
1355 | } else { | |
1356 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1357 | &deletebackupcert(); |
6e13d0a5 MT |
1358 | } |
1359 | ||
1360 | # Create an empty CRL | |
1361 | system('/usr/bin/openssl', 'ca', '-gencrl', | |
1362 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1363 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1364 | if ($?) { | |
1365 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1366 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1367 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1368 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1369 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
c6c9630e | 1370 | &cleanssldatabase(); |
6e13d0a5 | 1371 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1372 | # } else { |
1373 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1374 | } |
1375 | # Create Diffie Hellmann Parameter | |
1376 | system('/usr/bin/openssl', 'dhparam', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
1377 | '-out', "${General::swroot}/ovpn/ca/dh1024.pem", | |
1378 | '1024' ); | |
1379 | if ($?) { | |
1380 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1381 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1382 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1383 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1384 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); | |
1385 | unlink ("${General::swroot}/ovpn/ca/dh1024.pem"); | |
c6c9630e | 1386 | &cleanssldatabase(); |
6e13d0a5 | 1387 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1388 | # } else { |
1389 | # &cleanssldatabase(); | |
6e13d0a5 MT |
1390 | } |
1391 | goto ROOTCERT_SUCCESS; | |
1392 | } | |
1393 | ROOTCERT_ERROR: | |
1394 | if ($cgiparams{'ACTION'} ne '') { | |
1395 | &Header::showhttpheaders(); | |
1396 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1397 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1398 | if ($errormessage) { | |
1399 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1400 | print "<class name='base'>$errormessage"; | |
1401 | print " </class>"; | |
1402 | &Header::closebox(); | |
1403 | } | |
1404 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
1405 | print <<END | |
1406 | <form method='post' enctype='multipart/form-data'> | |
1407 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
1408 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}:</td> | |
1409 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> | |
1410 | <td width='35%' colspan='2'> </td></tr> | |
1411 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}:</td> | |
1412 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> | |
1413 | <td colspan='2'> </td></tr> | |
1414 | <tr><td class='base'>$Lang::tr{'your e-mail'}: <img src='/blob.gif' alt'*' /></td> | |
1415 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> | |
1416 | <td colspan='2'> </td></tr> | |
1417 | <tr><td class='base'>$Lang::tr{'your department'}: <img src='/blob.gif' alt'*' /></td> | |
1418 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> | |
1419 | <td colspan='2'> </td></tr> | |
1420 | <tr><td class='base'>$Lang::tr{'city'}: <img src='/blob.gif' alt'*' /></td> | |
1421 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> | |
1422 | <td colspan='2'> </td></tr> | |
1423 | <tr><td class='base'>$Lang::tr{'state or province'}: <img src='/blob.gif' alt'*' /></td> | |
1424 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> | |
1425 | <td colspan='2'> </td></tr> | |
1426 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
1427 | <td class='base'><select name='ROOTCERT_COUNTRY'> | |
1428 | ||
1429 | END | |
1430 | ; | |
1431 | foreach my $country (sort keys %{Countries::countries}) { | |
1432 | print "<option value='$Countries::countries{$country}'"; | |
1433 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1434 | print " selected='selected'"; | |
1435 | } | |
1436 | print ">$country</option>"; | |
1437 | } | |
1438 | print <<END | |
1439 | </select></td> | |
1440 | <td colspan='2'> </td></tr> | |
1441 | <tr><td> </td> | |
1442 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
1443 | <td> </td><td> </td></tr> | |
1444 | <tr><td class='base' colspan='4' align='left'> | |
1445 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'this field may be blank'}</td></tr> | |
1446 | <tr><td class='base' colspan='4' align='left'> | |
1447 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: | |
1448 | $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'} | |
1449 | </td></tr> | |
1450 | <tr><td colspan='4' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr> | |
1451 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}:</td> | |
1452 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> | |
1453 | <td colspan='2'> </td></tr> | |
1454 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}: <img src='/blob.gif' alt='*' ></td> | |
1455 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> | |
1456 | <td colspan='2'> </td></tr> | |
1457 | <tr><td> </td> | |
1458 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
1459 | <td colspan='2'> </td></tr> | |
1460 | <tr><td class='base' colspan='4' align='left'> | |
1461 | <img src='/blob.gif' valign='top' al='*' > $Lang::tr{'this field may be blank'}</td></tr> | |
1462 | </form></table> | |
1463 | END | |
1464 | ; | |
1465 | &Header::closebox(); | |
1466 | ||
1467 | &Header::closebigbox(); | |
1468 | &Header::closepage(); | |
1469 | exit(0) | |
1470 | } | |
1471 | ||
1472 | ROOTCERT_SUCCESS: | |
1473 | system ("chmod 600 ${General::swroot}/ovpn/certs/serverkey.pem"); | |
c6c9630e MT |
1474 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
1475 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
1476 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
1477 | # } | |
6e13d0a5 MT |
1478 | |
1479 | ### | |
1480 | ### Enable/Disable connection | |
1481 | ### | |
ce9abb66 AH |
1482 | |
1483 | ### | |
7c1d9faf | 1484 | # m.a.d net2net |
ce9abb66 AH |
1485 | ### |
1486 | ||
6e13d0a5 | 1487 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
c6c9630e MT |
1488 | |
1489 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 | 1490 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 AH |
1491 | # my $n2nactive = ''; |
1492 | my $n2nactive = `/bin/ps ax|grep $confighash{$cgiparams{'KEY'}}[1]|grep -v grep|awk \'{print \$1}\'`; | |
1493 | ||
6e13d0a5 | 1494 | if ($confighash{$cgiparams{'KEY'}}) { |
ce9abb66 AH |
1495 | |
1496 | ||
1497 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { | |
c6c9630e MT |
1498 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
1499 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 AH |
1500 | |
1501 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1502 | system('/usr/local/bin/openvpnctrl', '-sn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
1503 | } | |
1504 | ||
1505 | } else { | |
1506 | ||
c6c9630e | 1507 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
ce9abb66 AH |
1508 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
1509 | ||
1510 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1511 | if ($n2nactive ne ''){ | |
1512 | system('/usr/local/bin/openvpnctrl', '-kn2n', $confighash{$cgiparams{'KEY'}}[1]); | |
1513 | } | |
1514 | ||
1515 | } else { | |
1516 | $errormessage = $Lang::tr{'invalid key'}; | |
1517 | } | |
1518 | } | |
1519 | } | |
6e13d0a5 MT |
1520 | |
1521 | ### | |
1522 | ### Download OpenVPN client package | |
1523 | ### | |
ce9abb66 AH |
1524 | |
1525 | ||
6e13d0a5 MT |
1526 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
1527 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1528 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1529 | my $file = ''; | |
1530 | my $clientovpn = ''; | |
1531 | my @fileholder; | |
1532 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1533 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
1534 | |
1535 | ### | |
7c1d9faf AH |
1536 | # m.a.d net2net |
1537 | ### | |
ce9abb66 AH |
1538 | |
1539 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
1540 | ||
1541 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; | |
1542 | my $zippathname = "$zippath$zipname"; | |
1543 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; | |
1544 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); | |
1545 | my $ovsubnet = "@ovsubnettemp[0].@ovsubnettemp[1].@ovsubnettemp[2]"; | |
1546 | my $tunmtu = ''; | |
7c1d9faf | 1547 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
ce9abb66 AH |
1548 | |
1549 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; | |
1550 | flock CLIENTCONF, 2; | |
1551 | ||
1552 | my $zip = Archive::Zip->new(); | |
7c1d9faf | 1553 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 1554 | print CLIENTCONF "# \n"; |
b278daf3 | 1555 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
1556 | print CLIENTCONF "user nobody\n"; |
1557 | print CLIENTCONF "group nobody\n"; | |
1558 | print CLIENTCONF "persist-tun\n"; | |
1559 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 1560 | print CLIENTCONF "script-security 2\n"; |
b278daf3 | 1561 | print CLIENTCONF "# IP/DNS for the Server Gateway - g2g Mode\n"; |
531f0835 | 1562 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 AH |
1563 | print CLIENTCONF "float\n"; |
1564 | print CLIENTCONF "# IP adress of the VPN Subnet\n"; | |
ce9abb66 | 1565 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; |
b278daf3 | 1566 | print CLIENTCONF "# Server Gateway Network\n"; |
7c1d9faf | 1567 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
b278daf3 | 1568 | print CLIENTCONF "# tun Device\n"; |
ce9abb66 | 1569 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\n"; |
b278daf3 | 1570 | print CLIENTCONF "#Port and Protokoll\n"; |
ce9abb66 AH |
1571 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; |
1572 | print CLIENTCONF "proto $confighash{$cgiparams{'KEY'}}[28]\n"; | |
b278daf3 | 1573 | print CLIENTCONF "# Paketsize\n"; |
d96c89eb | 1574 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
ce9abb66 | 1575 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb AH |
1576 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { |
1577 | if ($cgiparams{'FRAGMENT'} eq '') { | |
1578 | print CLIENTCONF "fragment 1300\r\n"; | |
1579 | } else { | |
1580 | print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n" | |
1581 | } | |
1582 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') { | |
ce9abb66 | 1583 | print CLIENTCONF "mssfix\n"; |
d96c89eb AH |
1584 | } |
1585 | } | |
ce9abb66 AH |
1586 | print CLIENTCONF "# Auth. Client\n"; |
1587 | print CLIENTCONF "tls-client\n"; | |
b278daf3 | 1588 | print CLIENTCONF "# Cipher\n"; |
ce9abb66 AH |
1589 | print CLIENTCONF "cipher AES-256-CBC\n"; |
1590 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
1591 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
1592 | $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"; | |
1593 | } | |
ce9abb66 | 1594 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 1595 | print CLIENTCONF "# Enable Compression\n"; |
ce9abb66 | 1596 | print CLIENTCONF "comp-lzo\r\n"; |
b278daf3 | 1597 | } |
ce9abb66 AH |
1598 | print CLIENTCONF "# Debug Level\n"; |
1599 | print CLIENTCONF "verb 3\n"; | |
b278daf3 | 1600 | print CLIENTCONF "# Tunnel check\n"; |
ce9abb66 | 1601 | print CLIENTCONF "keepalive 10 60\n"; |
b278daf3 | 1602 | print CLIENTCONF "# Start as daemon\n"; |
ce9abb66 AH |
1603 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; |
1604 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
b278daf3 | 1605 | print CLIENTCONF "# Activate Management Interface and Port\n"; |
ce9abb66 AH |
1606 | print CLIENTCONF "# management localhost 4711\n"; |
1607 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; | |
531f0835 | 1608 | |
ce9abb66 AH |
1609 | |
1610 | close(CLIENTCONF); | |
1611 | ||
1612 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; | |
1613 | my $status = $zip->writeToFileNamed($zippathname); | |
1614 | ||
1615 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
1616 | @fileholder = <DLFILE>; | |
1617 | print "Content-Type:application/x-download\n"; | |
1618 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
1619 | print @fileholder; | |
1620 | exit (0); | |
1621 | } | |
1622 | else | |
1623 | { | |
1624 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
1625 | my $zippathname = "$zippath$zipname"; | |
1626 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
1627 | ||
1628 | ### | |
7c1d9faf | 1629 | # m.a.d net2net |
ce9abb66 AH |
1630 | ### |
1631 | ||
c6c9630e | 1632 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 MT |
1633 | flock CLIENTCONF, 2; |
1634 | ||
1635 | my $zip = Archive::Zip->new(); | |
1636 | ||
c6c9630e | 1637 | print CLIENTCONF "#OpenVPN Server conf\r\n"; |
6e13d0a5 MT |
1638 | print CLIENTCONF "tls-client\r\n"; |
1639 | print CLIENTCONF "client\r\n"; | |
1640 | print CLIENTCONF "dev $vpnsettings{'DDEVICE'}\r\n"; | |
c6c9630e | 1641 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
6e13d0a5 MT |
1642 | print CLIENTCONF "$vpnsettings{'DDEVICE'}-mtu $vpnsettings{'DMTU'}\r\n"; |
1643 | if ( $vpnsettings{'ENABLED'} eq 'on'){ | |
1644 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
c6c9630e MT |
1645 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
1646 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Blue interface\r\n"; | |
1647 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1648 | } | |
1649 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
1650 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
1651 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1652 | } | |
1653 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
1654 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1655 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
1656 | print CLIENTCONF "#Coment the above line and uncoment the next line, if you want to connect on the Orange interface\r\n"; | |
1657 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
1658 | } | |
1659 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
1660 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 MT |
1661 | } |
1662 | ||
1663 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { | |
c6c9630e MT |
1664 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; |
1665 | $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 | 1666 | } else { |
c6c9630e MT |
1667 | print CLIENTCONF "ca cacert.pem\r\n"; |
1668 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
1669 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
1670 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
1671 | $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 |
1672 | } |
1673 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
1674 | if ($vpnsettings{DCOMPLZO} eq 'on') { | |
1675 | print CLIENTCONF "comp-lzo\r\n"; | |
1676 | } | |
1677 | print CLIENTCONF "verb 3\r\n"; | |
1678 | print CLIENTCONF "ns-cert-type server\r\n"; | |
a79fa1d6 JPT |
1679 | print CLIENTCONF "tls-remote $vpnsettings{ROOTCERT_HOSTNAME}\r\n"; |
1680 | if ($vpnsettings{MSSFIX} eq 'on') { | |
1681 | print CLIENTCONF "mssfix\r\n"; | |
1682 | } | |
74225cce | 1683 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
1684 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
1685 | } | |
6e13d0a5 | 1686 | close(CLIENTCONF); |
ce9abb66 | 1687 | |
6e13d0a5 MT |
1688 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
1689 | my $status = $zip->writeToFileNamed($zippathname); | |
1690 | ||
1691 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
1692 | @fileholder = <DLFILE>; | |
1693 | print "Content-Type:application/x-download\n"; | |
1694 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
1695 | print @fileholder; | |
1696 | exit (0); | |
ce9abb66 AH |
1697 | } |
1698 | ||
1699 | ||
1700 | ||
6e13d0a5 MT |
1701 | ### |
1702 | ### Remove connection | |
1703 | ### | |
ce9abb66 AH |
1704 | |
1705 | ||
6e13d0a5 MT |
1706 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
1707 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1708 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e MT |
1709 | |
1710 | if ($confighash{$cgiparams{'KEY'}}) { | |
1711 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1712 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1713 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
1714 | # } | |
1715 | # | |
1716 | 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 |
1717 | |
1718 | ### | |
7c1d9faf | 1719 | # m.a.d net2net |
ce9abb66 | 1720 | ### |
7c1d9faf | 1721 | |
ce9abb66 AH |
1722 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
1723 | ||
1724 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
1725 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
1726 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
1727 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
1728 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
1729 | ||
1730 | } | |
ce9abb66 AH |
1731 | |
1732 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
c6c9630e MT |
1733 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); |
1734 | delete $confighash{$cgiparams{'KEY'}}; | |
1735 | my $temp2 = `/usr/bin/openssl ca -gencrl -out ${General::swroot}/ovpn/crls/cacrl.pem -config ${General::swroot}/ovpn/openssl/ovpn.cnf`; | |
1736 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1737 | #&writeserverconf(); | |
6e13d0a5 | 1738 | } else { |
c6c9630e | 1739 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 | 1740 | } |
ce9abb66 AH |
1741 | |
1742 | ||
6e13d0a5 MT |
1743 | ### |
1744 | ### Download PKCS12 file | |
1745 | ### | |
1746 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
1747 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1748 | ||
1749 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
1750 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
1751 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12`; | |
1752 | exit (0); | |
1753 | ||
1754 | ### | |
1755 | ### Display certificate | |
1756 | ### | |
1757 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
1758 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1759 | ||
1760 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e MT |
1761 | &Header::showhttpheaders(); |
1762 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1763 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1764 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
1765 | my $output = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
1766 | $output = &Header::cleanhtml($output,"y"); | |
1767 | print "<pre>$output</pre>\n"; | |
1768 | &Header::closebox(); | |
1769 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1770 | &Header::closebigbox(); | |
1771 | &Header::closepage(); | |
1772 | exit(0); | |
6e13d0a5 MT |
1773 | } |
1774 | ### | |
1775 | ### Display Certificate Revoke List | |
1776 | ### | |
1777 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
1778 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
1779 | ||
6e13d0a5 | 1780 | if ( -f "${General::swroot}/ovpn/crls/cacrl.pem") { |
c6c9630e MT |
1781 | &Header::showhttpheaders(); |
1782 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
1783 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1784 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
1785 | my $output = `/usr/bin/openssl crl -text -noout -in ${General::swroot}/ovpn/crls/cacrl.pem`; | |
1786 | $output = &Header::cleanhtml($output,"y"); | |
1787 | print "<pre>$output</pre>\n"; | |
1788 | &Header::closebox(); | |
1789 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1790 | &Header::closebigbox(); | |
1791 | &Header::closepage(); | |
1792 | exit(0); | |
6e13d0a5 MT |
1793 | } |
1794 | ||
1795 | ### | |
1796 | ### Advanced Server Settings | |
1797 | ### | |
1798 | ||
1799 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
1800 | %cgiparams = (); | |
1801 | %cahash = (); | |
1802 | %confighash = (); | |
1803 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
1804 | ||
c6c9630e MT |
1805 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
1806 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; | |
1807 | # } | |
6e13d0a5 MT |
1808 | ADV_ERROR: |
1809 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
c6c9630e | 1810 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 MT |
1811 | } |
1812 | ||
1813 | if ($cgiparams{'KEEPALIVE_1'} eq '') { | |
c6c9630e | 1814 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
1815 | } |
1816 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
c6c9630e | 1817 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
1818 | } |
1819 | if ($cgiparams{'LOG_VERB'} eq '') { | |
c6c9630e | 1820 | $cgiparams{'LOG_VERB'} = '3'; |
6e13d0a5 | 1821 | } |
6e13d0a5 MT |
1822 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
1823 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
1824 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
1825 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
1826 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
1827 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
a79fa1d6 JPT |
1828 | $selected{'ENGINES'}{$cgiparams{'ENGINES'}} = 'SELECTED'; |
1829 | $checked{'MSSFIX'}{'off'} = ''; | |
1830 | $checked{'MSSFIX'}{'on'} = ''; | |
1831 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 MT |
1832 | $selected{'LOG_VERB'}{'1'} = ''; |
1833 | $selected{'LOG_VERB'}{'2'} = ''; | |
1834 | $selected{'LOG_VERB'}{'3'} = ''; | |
1835 | $selected{'LOG_VERB'}{'4'} = ''; | |
1836 | $selected{'LOG_VERB'}{'5'} = ''; | |
1837 | $selected{'LOG_VERB'}{'6'} = ''; | |
1838 | $selected{'LOG_VERB'}{'7'} = ''; | |
1839 | $selected{'LOG_VERB'}{'8'} = ''; | |
1840 | $selected{'LOG_VERB'}{'9'} = ''; | |
1841 | $selected{'LOG_VERB'}{'10'} = ''; | |
1842 | $selected{'LOG_VERB'}{'11'} = ''; | |
1843 | $selected{'LOG_VERB'}{'0'} = ''; | |
1844 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; | |
a79fa1d6 JPT |
1845 | |
1846 | ||
6e13d0a5 MT |
1847 | |
1848 | &Header::showhttpheaders(); | |
1849 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
1850 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
1851 | if ($errormessage) { | |
c6c9630e MT |
1852 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
1853 | print "<class name='base'>$errormessage\n"; | |
1854 | print " </class>\n"; | |
1855 | &Header::closebox(); | |
6e13d0a5 MT |
1856 | } |
1857 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
1858 | print <<END | |
1859 | <form method='post' enctype='multipart/form-data'> | |
1860 | <table width='100%'> | |
1861 | <tr> | |
1862 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
1863 | </tr> | |
1864 | <tr> | |
1865 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> | |
1866 | </tr> | |
1867 | <tr> | |
1868 | <td class='base'>Domain</td> | |
1869 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> | |
1870 | </tr> | |
1871 | <tr> | |
1872 | <td class='base'>DNS</td> | |
1873 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
1874 | </tr> | |
1875 | <tr> | |
1876 | <td class='base'>WINS</td> | |
1877 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
1878 | </tr> | |
1879 | </table> | |
1880 | <hr size='1'> | |
6e13d0a5 MT |
1881 | <table width='100%'> |
1882 | <tr> | |
1883 | <td class'base'><b>$Lang::tr{'misc-options'}</b></td> | |
1884 | </tr> | |
1885 | <tr> | |
a79fa1d6 | 1886 | <td width='20%'></td> <td width='15%'> </td><td width='15%'> </td><td width='50%'></td> |
6e13d0a5 MT |
1887 | </tr> |
1888 | <tr> | |
1889 | <td class='base'>Client-To-Client</td> | |
1890 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
1891 | </tr> | |
1892 | <tr> | |
1893 | <td class='base'>Redirect-Gateway def1</td> | |
1894 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
1895 | </tr> | |
1896 | <tr> | |
1897 | <td class='base'>Max-Clients</td> | |
a79fa1d6 | 1898 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> |
6e13d0a5 | 1899 | </tr> |
a79fa1d6 JPT |
1900 | <tr> |
1901 | <td class='base'>Keppalive <br /> | |
1902 | (ping/ping-restart)</td> | |
1903 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
1904 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
1905 | </tr> | |
1906 | <tr> | |
1907 | <td class='base'>fragment <br></td> | |
1908 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
1909 | <td>Default: <span class="base">1300</span></td> | |
1910 | </tr> | |
1911 | <tr> | |
1912 | <td class='base'>mssfix</td> | |
1913 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
1914 | <td>Default: on</td> | |
1915 | </tr> | |
1916 | </table> | |
1917 | ||
1918 | <!-- | |
1919 | <hr size='1'> | |
1920 | <table width='100%'> | |
1921 | <tr> | |
1922 | <td class'base'><b>Crypto-Engines</b></td> | |
1923 | </tr> | |
1924 | <tr> | |
1925 | <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td> | |
6e13d0a5 | 1926 | </tr> |
a79fa1d6 JPT |
1927 | <tr><td class='base'>Engines:</td> |
1928 | <td><select name='ENGINES'><option value="none" $selected{'ENGINES'}{'none'}>none</option> | |
1929 | <option value="cryptodev" $selected{'ENGINES'}{'cryptodev'}>cryptodev</option> | |
1930 | <option value="padlock" $selected{'ENGINES'}{'padlock'}>padlock</option> | |
1931 | </select> | |
1932 | </td> | |
6e13d0a5 | 1933 | </table> |
a79fa1d6 | 1934 | --> |
6e13d0a5 MT |
1935 | <hr size='1'> |
1936 | <table width='100%'> | |
1937 | <tr> | |
1938 | <td class'base'><b>$Lang::tr{'log-options'}</b></td> | |
1939 | </tr> | |
1940 | <tr> | |
a79fa1d6 | 1941 | <td width='15%'></td> <td width='30%'> </td><td width='25%'> </td><td width='30%'></td> |
6e13d0a5 MT |
1942 | </tr> |
1943 | ||
1944 | <tr><td class='base'>VERB</td> | |
1945 | <td><select name='LOG_VERB'><option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
1946 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
1947 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
1948 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
1949 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
1950 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
1951 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
1952 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
1953 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
1954 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
1955 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
c6c9630e | 1956 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option></select></td> |
6e13d0a5 MT |
1957 | </table> |
1958 | <hr size='1'> | |
1959 | <table width='100%'> | |
1960 | <tr> | |
1961 | <td> </td> | |
1962 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
1963 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
1964 | <td> </td> | |
1965 | </tr> | |
1966 | </table> | |
1967 | </form> | |
1968 | END | |
1969 | ; | |
1970 | ||
1971 | &Header::closebox(); | |
c6c9630e | 1972 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
1973 | &Header::closebigbox(); |
1974 | &Header::closepage(); | |
1975 | exit(0); | |
1976 | ||
1977 | ### | |
1978 | ### Openvpn Connections Statistics | |
1979 | ### | |
1980 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
1981 | &Header::showhttpheaders(); | |
1982 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
1983 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
1984 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
1985 | ||
1986 | # | |
1987 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
1988 | # protocol temp removed | |
1989 | print <<END | |
1990 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> | |
1991 | <tr> | |
1992 | <td><b>$Lang::tr{'common name'}</b></td> | |
1993 | <td><b>$Lang::tr{'real address'}</b></td> | |
1994 | <td><b>$Lang::tr{'virtual address'}</b></td> | |
1995 | <td><b>$Lang::tr{'loged in at'}</b></td> | |
1996 | <td><b>$Lang::tr{'bytes sent'}</b></td> | |
1997 | <td><b>$Lang::tr{'bytes received'}</b></td> | |
1998 | <td><b>$Lang::tr{'last activity'}</b></td> | |
1999 | </tr> | |
2000 | END | |
2001 | ; | |
4e17adad | 2002 | my $filename = "/var/log/ovpnserver.log"; |
6e13d0a5 MT |
2003 | open(FILE, $filename) or die 'Unable to open config file.'; |
2004 | my @current = <FILE>; | |
2005 | close(FILE); | |
2006 | my @users =(); | |
2007 | my $status; | |
2008 | my $uid = 0; | |
2009 | my $cn; | |
2010 | my @match = (); | |
2011 | my $proto = "udp"; | |
2012 | my $address; | |
2013 | my %userlookup = (); | |
2014 | foreach my $line (@current) | |
2015 | { | |
2016 | chomp($line); | |
2017 | if ( $line =~ /^Updated,(.+)/){ | |
2018 | @match = split( /^Updated,(.+)/, $line); | |
2019 | $status = $match[1]; | |
2020 | } | |
c6c9630e | 2021 | #gian |
6e13d0a5 MT |
2022 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
2023 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
2024 | if ($match[1] ne "Common Name") { | |
2025 | $cn = $match[1]; | |
2026 | $userlookup{$match[2]} = $uid; | |
2027 | $users[$uid]{'CommonName'} = $match[1]; | |
2028 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
2029 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
2030 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
2031 | $users[$uid]{'Since'} = $match[5]; |
2032 | $users[$uid]{'Proto'} = $proto; | |
2033 | $uid++; | |
2034 | } | |
2035 | } | |
2036 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
2037 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
2038 | if ($match[1] ne "Virtual Address") { | |
2039 | $address = $match[3]; | |
2040 | #find the uid in the lookup table | |
2041 | $uid = $userlookup{$address}; | |
2042 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
2043 | $users[$uid]{'LastRef'} = $match[4]; | |
2044 | } | |
2045 | } | |
2046 | } | |
2047 | my $user2 = @users; | |
2048 | if ($user2 >= 1){ | |
2049 | for (my $idx = 1; $idx <= $user2; $idx++){ | |
2050 | if ($idx % 2) { | |
4e17adad | 2051 | print "<tr bgcolor='$color{'color20'}'>\n"; |
6e13d0a5 | 2052 | } else { |
4e17adad | 2053 | print "<tr bgcolor='$color{'color22'}'>\n"; |
6e13d0a5 MT |
2054 | } |
2055 | print "<td align='left'>$users[$idx-1]{'CommonName'}</td>"; | |
2056 | print "<td align='left'>$users[$idx-1]{'RealAddress'}</td>"; | |
2057 | print "<td align='left'>$users[$idx-1]{'VirtualAddress'}</td>"; | |
2058 | print "<td align='left'>$users[$idx-1]{'Since'}</td>"; | |
2059 | print "<td align='left'>$users[$idx-1]{'BytesSent'}</td>"; | |
2060 | print "<td align='left'>$users[$idx-1]{'BytesReceived'}</td>"; | |
2061 | print "<td align='left'>$users[$idx-1]{'LastRef'}</td>"; | |
2062 | # print "<td align='left'>$users[$idx-1]{'Proto'}</td>"; | |
2063 | } | |
2064 | } | |
2065 | ||
2066 | print "</table>"; | |
2067 | print <<END | |
2068 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> | |
2069 | <tr><td></td></tr> | |
2070 | <tr><td></td></tr> | |
2071 | <tr><td></td></tr> | |
2072 | <tr><td></td></tr> | |
2073 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
2074 | </table> | |
2075 | END | |
2076 | ; | |
2077 | &Header::closebox(); | |
2078 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2079 | &Header::closebigbox(); | |
2080 | &Header::closepage(); | |
2081 | exit(0); | |
2082 | ||
2083 | ### | |
2084 | ### Download Certificate | |
2085 | ### | |
2086 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
2087 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 2088 | |
6e13d0a5 | 2089 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
2090 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
2091 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2092 | print `/bin/cat ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem`; | |
2093 | exit (0); | |
2094 | } | |
2095 | ||
2096 | ### | |
2097 | ### Enable/Disable connection | |
2098 | ### | |
ce9abb66 | 2099 | |
c6c9630e MT |
2100 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
2101 | ||
2102 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2103 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2104 | ||
2105 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 2106 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
2107 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
2108 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2109 | #&writeserverconf(); | |
2110 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2111 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2112 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2113 | # } | |
2114 | } else { | |
2115 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
2116 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2117 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2118 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2119 | # } | |
2120 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2121 | #&writeserverconf(); | |
2122 | } | |
2123 | } else { | |
2124 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
2125 | } |
2126 | ||
2127 | ### | |
2128 | ### Restart connection | |
2129 | ### | |
2130 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
2131 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2132 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2133 | ||
2134 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
2135 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
2136 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2137 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
2138 | # } | |
6e13d0a5 | 2139 | } else { |
c6c9630e | 2140 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
2141 | } |
2142 | ||
2143 | ### | |
c6c9630e | 2144 | ### Remove connection |
6e13d0a5 | 2145 | ### |
c6c9630e MT |
2146 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
2147 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2148 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2149 | ||
2150 | if ($confighash{$cgiparams{'KEY'}}) { | |
2151 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
2152 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
2153 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
2154 | # } | |
2155 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
2156 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2157 | delete $confighash{$cgiparams{'KEY'}}; | |
2158 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2159 | #&writeserverconf(); | |
2160 | } else { | |
2161 | $errormessage = $Lang::tr{'invalid key'}; | |
2162 | } | |
ce9abb66 AH |
2163 | #test33 |
2164 | ||
2165 | ### | |
2166 | ### Choose between adding a host-net or net-net connection | |
2167 | ### | |
2168 | ||
2169 | ### | |
7c1d9faf | 2170 | # m.a.d net2net |
ce9abb66 AH |
2171 | ### |
2172 | ||
2173 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
2174 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2175 | &Header::showhttpheaders(); | |
2176 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
2177 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2178 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
2179 | |
2180 | if ( -s "${General::swroot}/ovpn/settings") { | |
2181 | ||
ce9abb66 AH |
2182 | print <<END |
2183 | <b>$Lang::tr{'connection type'}:</b><br /> | |
2184 | <table><form method='post' ENCTYPE="multipart/form-data"> | |
2185 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> | |
2186 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
2187 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
2188 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
2189 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> | |
2190 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> | |
2191 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
2192 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> | |
2193 | </form></table> | |
2194 | END | |
2195 | ; | |
2196 | ||
b278daf3 AH |
2197 | } else { |
2198 | print <<END | |
2199 | <b>$Lang::tr{'connection type'}:</b><br /> | |
2200 | <table><form method='post' ENCTYPE="multipart/form-data"> | |
2201 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
2202 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> | |
2203 | </form></table> | |
2204 | END | |
2205 | ; | |
2206 | ||
2207 | } | |
2208 | ||
ce9abb66 AH |
2209 | &Header::closebox(); |
2210 | &Header::closebigbox(); | |
2211 | &Header::closepage(); | |
2212 | exit (0); | |
2213 | ||
2214 | ### | |
7c1d9faf | 2215 | # m.a.d net2net |
ce9abb66 AH |
2216 | ### |
2217 | ||
2218 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
2219 | ||
2220 | my @firen2nconf; | |
2221 | my @confdetails; | |
2222 | my $uplconffilename =''; | |
2223 | my $uplp12name = ''; | |
ce9abb66 AH |
2224 | my @rem_subnet; |
2225 | my @rem_subnet2; | |
2226 | my @tmposupnet3; | |
2227 | my $key; | |
2228 | ||
2229 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2230 | ||
2231 | # Check if a file is uploaded | |
2232 | ||
2233 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
2234 | $errormessage = $Lang::tr{'there was no file upload'}; | |
2235 | goto N2N_ERROR; | |
2236 | } | |
2237 | ||
2238 | # Move uploaded IPfire n2n package to temporary file | |
2239 | ||
2240 | (my $fh, my $filename) = tempfile( ); | |
2241 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2242 | $errormessage = $!; | |
2243 | goto N2N_ERROR; | |
2244 | } | |
2245 | ||
2246 | my $zip = Archive::Zip->new(); | |
2247 | my $zipName = $filename; | |
2248 | my $status = $zip->read( $zipName ); | |
2249 | if ($status != AZ_OK) { | |
2250 | $errormessage = "Read of $zipName failed\n"; | |
2251 | goto N2N_ERROR; | |
2252 | } | |
2253 | ||
2254 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2255 | my @files = $zip->memberNames(); | |
2256 | for(@files) { | |
2257 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
2258 | } | |
2259 | my $countfiles = @files; | |
2260 | ||
2261 | # Check if we have not more then 2 files | |
2262 | ||
2263 | if ( $countfiles == 2){ | |
2264 | foreach (@files){ | |
2265 | if ( $_ =~ /.conf$/){ | |
2266 | $uplconffilename = $_; | |
2267 | } | |
2268 | if ( $_ =~ /.p12$/){ | |
2269 | $uplp12name = $_; | |
2270 | } | |
2271 | } | |
2272 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
2273 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
2274 | goto N2N_ERROR; | |
2275 | } | |
2276 | ||
2277 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
2278 | @firen2nconf = <FILE>; | |
2279 | close (FILE); | |
2280 | chomp(@firen2nconf); | |
2281 | ||
2282 | } else { | |
2283 | ||
2284 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
2285 | goto N2N_ERROR; | |
2286 | } | |
2287 | ||
7c1d9faf AH |
2288 | ### |
2289 | # m.a.d net2net | |
ce9abb66 AH |
2290 | ### |
2291 | ||
2292 | my @n2nname = split(/\./,$uplconffilename); | |
2293 | $n2nname[0] =~ s/\n|\r//g; | |
2294 | ||
7c1d9faf AH |
2295 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
2296 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} | |
ce9abb66 AH |
2297 | |
2298 | move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename"); | |
2299 | ||
2300 | if ($? ne 0) { | |
2301 | $errormessage = "*.conf move failed: $!"; | |
2302 | unlink ($filename); | |
2303 | goto N2N_ERROR; | |
2304 | } | |
2305 | ||
2306 | move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name"); | |
b278daf3 AH |
2307 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; |
2308 | ||
ce9abb66 AH |
2309 | if ($? ne 0) { |
2310 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
2311 | unlink ($filename); | |
2312 | goto N2N_ERROR; | |
2313 | } | |
2314 | ||
2315 | my $complzoactive; | |
d96c89eb AH |
2316 | my $mssfixactive; |
2317 | my $n2nfragment; | |
ce9abb66 AH |
2318 | my @n2nproto = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
2319 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); | |
2320 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
2321 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
2322 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} | |
d96c89eb AH |
2323 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
2324 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
2325 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); | |
ce9abb66 AH |
2326 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
2327 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
2328 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
2329 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
2330 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); | |
2331 | ||
ce9abb66 AH |
2332 | ### |
2333 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
2334 | ### | |
2335 | ||
ce9abb66 | 2336 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
2337 | $n2novpnsub[0] =~ s/\n|\r//g; |
2338 | $n2novpnsub[1] =~ s/\n|\r//g; | |
2339 | $n2novpnsub[2] =~ s/\n|\r//g; | |
2340 | $n2nproto[1] =~ s/\n|\r//g; | |
2341 | $n2nport[1] =~ s/\n|\r//g; | |
2342 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
2343 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 2344 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 2345 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 2346 | $n2nfragment[1] =~ s/\n|\r//g; |
ce9abb66 | 2347 | chomp ($complzoactive); |
d96c89eb | 2348 | chomp ($mssfixactive); |
ce9abb66 AH |
2349 | |
2350 | ### | |
7c1d9faf | 2351 | # m.a.d net2net |
ce9abb66 AH |
2352 | ### |
2353 | ||
2354 | ### | |
2355 | # Check if there is no other entry with this name | |
2356 | ### | |
2357 | ||
2358 | foreach my $dkey (keys %confighash) { | |
2359 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
2360 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
2361 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
2362 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
2363 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
ce9abb66 AH |
2364 | goto N2N_ERROR; |
2365 | } | |
2366 | } | |
2367 | ||
d96c89eb AH |
2368 | ### |
2369 | # Check if OpenVPN Subnet is valid | |
2370 | ### | |
2371 | ||
2372 | foreach my $dkey (keys %confighash) { | |
2373 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
2374 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
2375 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
2376 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
2377 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2378 | goto N2N_ERROR; |
2379 | } | |
2380 | } | |
2381 | ||
2382 | ### | |
2383 | # Check im Dest Port is vaild | |
2384 | ### | |
2385 | ||
2386 | foreach my $dkey (keys %confighash) { | |
2387 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
2388 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
2389 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
2390 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
2391 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2392 | goto N2N_ERROR; |
2393 | } | |
2394 | } | |
2395 | ||
2396 | ||
2397 | ||
ce9abb66 AH |
2398 | $key = &General::findhasharraykey (\%confighash); |
2399 | ||
2400 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
2401 | $confighash{$key}[0] = 'off'; | |
2402 | $confighash{$key}[1] = $n2nname[0]; | |
2403 | $confighash{$key}[2] = $n2nname[0]; | |
2404 | $confighash{$key}[3] = 'net'; | |
2405 | $confighash{$key}[4] = 'cert'; | |
2406 | $confighash{$key}[6] = 'client'; | |
2407 | $confighash{$key}[8] = $n2nlocalsub[2]; | |
2408 | $confighash{$key}[10] = $n2nremote[1]; | |
b278daf3 | 2409 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; |
d96c89eb AH |
2410 | $confighash{$key}[23] = $mssfixactive; |
2411 | $confighash{$key}[24] = $n2nfragment[1]; | |
2412 | $confighash{$key}[25] = 'IPFire n2n Client'; | |
ce9abb66 AH |
2413 | $confighash{$key}[26] = 'red'; |
2414 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; | |
2415 | $confighash{$key}[28] = $n2nproto[1]; | |
2416 | $confighash{$key}[29] = $n2nport[1]; | |
2417 | $confighash{$key}[30] = $complzoactive; | |
2418 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
2419 | ||
2420 | ||
2421 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
d96c89eb | 2422 | |
ce9abb66 AH |
2423 | N2N_ERROR: |
2424 | ||
2425 | &Header::showhttpheaders(); | |
2426 | &Header::openpage('Validate imported configuration', 1, ''); | |
2427 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
2428 | if ($errormessage) { | |
2429 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2430 | print "<class name='base'>$errormessage"; | |
2431 | print " </class>"; | |
2432 | &Header::closebox(); | |
2433 | ||
2434 | } else | |
2435 | { | |
2436 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); | |
2437 | } | |
2438 | if ($errormessage eq ''){ | |
2439 | print <<END | |
2440 | <!-- ipfire net2net config gui --> | |
2441 | <table width='100%'> | |
2442 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
2443 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
2444 | <tr><td> </td><td> </td></tr> | |
2445 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
2446 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> | |
2447 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
2448 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td><td><b>$confighash{$key}[11]</b></td></tr> | |
2449 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> | |
2450 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
2451 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
2452 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
7c1d9faf AH |
2453 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX </td><td><b>$confighash{$key}[23]</b></td></tr> |
2454 | <tr><td class='boldbase' nowrap='nowrap'>Fragment </td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 AH |
2455 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
2456 | <tr><td> </td><td> </td></tr> | |
2457 | </table> | |
2458 | END | |
2459 | ; | |
2460 | &Header::closebox(); | |
2461 | } | |
2462 | ||
2463 | if ($errormessage) { | |
2464 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2465 | } else { | |
2466 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
2467 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; | |
2468 | print "<input type='hidden' name='KEY' value='$key' />"; | |
2469 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
2470 | } | |
2471 | &Header::closebigbox(); | |
2472 | &Header::closepage(); | |
2473 | exit(0); | |
2474 | ||
2475 | ||
2476 | ## | |
2477 | ### Accept IPFire n2n Package Settings | |
2478 | ### | |
2479 | ||
2480 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
2481 | ||
2482 | ### | |
2483 | ### Discard and Rollback IPFire n2n Package Settings | |
2484 | ### | |
2485 | ||
2486 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
2487 | ||
2488 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2489 | ||
2490 | if ($confighash{$cgiparams{'KEY'}}) { | |
2491 | ||
2492 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
2493 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2494 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
2495 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
2496 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2497 | delete $confighash{$cgiparams{'KEY'}}; | |
2498 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2499 | ||
2500 | } else { | |
2501 | $errormessage = $Lang::tr{'invalid key'}; | |
2502 | } | |
2503 | ||
2504 | ||
2505 | ### | |
7c1d9faf | 2506 | # m.a.d net2net |
ce9abb66 AH |
2507 | ### |
2508 | ||
2509 | ||
2510 | ### | |
2511 | ### Adding a new connection | |
2512 | ### | |
6e13d0a5 MT |
2513 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
2514 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
2515 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
2516 | ||
2517 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2518 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
2519 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2520 | ||
2521 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
c6c9630e MT |
2522 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
2523 | $errormessage = $Lang::tr{'invalid key'}; | |
2524 | goto VPNCONF_END; | |
2525 | } | |
2526 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; | |
2527 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
ce9abb66 | 2528 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; |
c6c9630e MT |
2529 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; |
2530 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
2531 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
2532 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
531f0835 AH |
2533 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; |
2534 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; | |
d96c89eb AH |
2535 | # n2n m.a.d new fields |
2536 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
2537 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
c6c9630e MT |
2538 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; |
2539 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
2540 | #new fields | |
2541 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
2542 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
2543 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
2544 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
2545 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
d96c89eb | 2546 | |
c6c9630e MT |
2547 | #new fields |
2548 | #ab hiere error uebernehmen | |
d96c89eb | 2549 | |
c6c9630e MT |
2550 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
2551 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); | |
2552 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { | |
2553 | $errormessage = $Lang::tr{'connection type is invalid'}; | |
b278daf3 AH |
2554 | if ($cgiparams{'TYPE'} eq 'net') { |
2555 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2556 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2557 | } | |
c6c9630e MT |
2558 | goto VPNCONF_ERROR; |
2559 | } | |
2560 | ||
2561 | ||
2562 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
2563 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
b278daf3 AH |
2564 | if ($cgiparams{'TYPE'} eq 'net') { |
2565 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2566 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2567 | } | |
2568 | goto VPNCONF_ERROR; | |
2569 | } | |
c6c9630e MT |
2570 | |
2571 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
2572 | $errormessage = $Lang::tr{'name is invalid'}; | |
b278daf3 AH |
2573 | if ($cgiparams{'TYPE'} eq 'net') { |
2574 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2575 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2576 | } | |
c6c9630e MT |
2577 | goto VPNCONF_ERROR; |
2578 | } | |
2579 | ||
2580 | if (length($cgiparams{'NAME'}) >60) { | |
2581 | $errormessage = $Lang::tr{'name too long'}; | |
b278daf3 AH |
2582 | if ($cgiparams{'TYPE'} eq 'net') { |
2583 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2584 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2585 | } | |
c6c9630e MT |
2586 | goto VPNCONF_ERROR; |
2587 | } | |
2588 | ||
d96c89eb | 2589 | ### |
7c1d9faf | 2590 | # m.a.d net2net |
d96c89eb AH |
2591 | ### |
2592 | ||
7c1d9faf AH |
2593 | if ($cgiparams{'TYPE'} eq 'net') { |
2594 | ||
2595 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { | |
d96c89eb | 2596 | $errormessage = 'The Destination Port is used by the OpenVPN Server please change'; |
b278daf3 AH |
2597 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2598 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2599 | goto VPNCONF_ERROR; | |
d96c89eb AH |
2600 | } |
2601 | ||
2602 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { | |
2603 | $errormessage = 'The OpenVPN Subnet is used by the OpenVPN Server please change'; | |
b278daf3 AH |
2604 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2605 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2606 | goto VPNCONF_ERROR; |
2607 | } | |
2608 | ||
2609 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
2610 | $errormessage = 'mssfix only allowed with udp'; | |
b278daf3 AH |
2611 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2612 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2613 | goto VPNCONF_ERROR; |
2614 | } | |
2615 | ||
2616 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { | |
2617 | $errormessage = 'fragment only allowed with udp'; | |
b278daf3 AH |
2618 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2619 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
2620 | goto VPNCONF_ERROR; |
2621 | } | |
d96c89eb | 2622 | |
7c1d9faf | 2623 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
b278daf3 AH |
2624 | $errormessage = 'Prefix not allowed for Local Subnet. Please enter Subnet Mask e.g. 255.255.255.0'; |
2625 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2626 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2627 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
2628 | } |
2629 | ||
2630 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { | |
b278daf3 AH |
2631 | $errormessage = 'Prefix not allowed for OpenVPN Subnet. Please enter Subnet Mask e.g. 255.255.255.0'; |
2632 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2633 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2634 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
2635 | } |
2636 | ||
2637 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { | |
b278daf3 AH |
2638 | $errormessage = 'Prefix not allowed for Remote Subnet. Please enter Subnet Mask e.g. 255.255.255.0'; |
2639 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2640 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2641 | goto VPNCONF_ERROR; | |
7c1d9faf AH |
2642 | } |
2643 | } | |
d96c89eb | 2644 | |
ce9abb66 AH |
2645 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
2646 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
2647 | # goto VPNCONF_ERROR; | |
2648 | # } | |
2649 | ||
c6c9630e MT |
2650 | # Check if there is no other entry with this name |
2651 | if (! $cgiparams{'KEY'}) { | |
2652 | foreach my $key (keys %confighash) { | |
2653 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
2654 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
2655 | if ($cgiparams{'TYPE'} eq 'net') { |
2656 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2657 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2658 | } | |
c6c9630e | 2659 | goto VPNCONF_ERROR; |
6e13d0a5 | 2660 | } |
c6c9630e MT |
2661 | } |
2662 | } | |
2663 | ||
ce9abb66 AH |
2664 | if (($cgiparams{'TYPE'} eq 'net') && (! $cgiparams{'REMOTE'})) { |
2665 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
b278daf3 AH |
2666 | if ($cgiparams{'TYPE'} eq 'net') { |
2667 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2668 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2669 | } | |
ce9abb66 AH |
2670 | goto VPNCONF_ERROR; |
2671 | } | |
2672 | ||
c6c9630e MT |
2673 | if ($cgiparams{'REMOTE'}) { |
2674 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
2675 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
2676 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
b278daf3 AH |
2677 | if ($cgiparams{'TYPE'} eq 'net') { |
2678 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2679 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2680 | } | |
c6c9630e | 2681 | goto VPNCONF_ERROR; |
6e13d0a5 | 2682 | } else { |
c6c9630e MT |
2683 | if (&valid_dns_host($cgiparams{'REMOTE'})) { |
2684 | $warnmessage = "$Lang::tr{'check vpn lr'} $cgiparams{'REMOTE'}. $Lang::tr{'dns check failed'}"; | |
b278daf3 AH |
2685 | if ($cgiparams{'TYPE'} eq 'net') { |
2686 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2687 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2688 | } | |
c6c9630e | 2689 | } |
6e13d0a5 | 2690 | } |
c6c9630e MT |
2691 | } |
2692 | } | |
2693 | if ($cgiparams{'TYPE'} ne 'host') { | |
2694 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
2695 | $errormessage = $Lang::tr{'local subnet is invalid'}; | |
b278daf3 AH |
2696 | if ($cgiparams{'TYPE'} eq 'net') { |
2697 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
2698 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2699 | } | |
c6c9630e MT |
2700 | goto VPNCONF_ERROR;} |
2701 | } | |
2702 | # Check if there is no other entry without IP-address and PSK | |
2703 | if ($cgiparams{'REMOTE'} eq '') { | |
2704 | foreach my $key (keys %confighash) { | |
2705 | if(($cgiparams{'KEY'} ne $key) && | |
2706 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
2707 | $confighash{$key}[10] eq '') { | |
2708 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
2709 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2710 | } |
c6c9630e MT |
2711 | } |
2712 | } | |
ce9abb66 AH |
2713 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
2714 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
2715 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
2716 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
2717 | goto VPNCONF_ERROR; | |
ce9abb66 | 2718 | } |
c6c9630e MT |
2719 | |
2720 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
2721 | $errormessage = $Lang::tr{'invalid input'}; | |
2722 | goto VPNCONF_ERROR; | |
2723 | } | |
2724 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
2725 | $errormessage = $Lang::tr{'invalid input'}; | |
2726 | goto VPNCONF_ERROR; | |
2727 | } | |
2728 | ||
2729 | #fixplausi | |
2730 | if ($cgiparams{'AUTH'} eq 'psk') { | |
2731 | # if (! length($cgiparams{'PSK'}) ) { | |
2732 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
2733 | # goto VPNCONF_ERROR; | |
2734 | # } | |
2735 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
2736 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
2737 | # goto VPNCONF_ERROR; | |
2738 | # } | |
2739 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
2740 | if ($cgiparams{'KEY'}) { | |
2741 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2742 | goto VPNCONF_ERROR; | |
2743 | } | |
2744 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
2745 | $errormessage = $Lang::tr{'there was no file upload'}; | |
2746 | goto VPNCONF_ERROR; | |
2747 | } | |
2748 | ||
2749 | # Move uploaded certificate request to a temporary file | |
2750 | (my $fh, my $filename) = tempfile( ); | |
2751 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2752 | $errormessage = $!; | |
2753 | goto VPNCONF_ERROR; | |
2754 | } | |
6e13d0a5 | 2755 | |
c6c9630e MT |
2756 | # Sign the certificate request and move it |
2757 | # Sign the host certificate request | |
2758 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
2759 | '-batch', '-notext', | |
2760 | '-in', $filename, | |
2761 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
2762 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
2763 | if ($?) { | |
2764 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2765 | unlink ($filename); | |
2766 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2767 | &newcleanssldatabase(); | |
2768 | goto VPNCONF_ERROR; | |
2769 | } else { | |
2770 | unlink ($filename); | |
2771 | &deletebackupcert(); | |
2772 | } | |
2773 | ||
2774 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
2775 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
2776 | $temp = $1; | |
2777 | $temp =~ s+/Email+, E+; | |
2778 | $temp =~ s/ ST=/ S=/; | |
2779 | $cgiparams{'CERT_NAME'} = $temp; | |
2780 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
2781 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
2782 | if ($cgiparams{'CERT_NAME'} eq '') { | |
2783 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
2784 | goto VPNCONF_ERROR; | |
2785 | } | |
2786 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
2787 | if ($cgiparams{'KEY'}) { | |
2788 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2789 | goto VPNCONF_ERROR; | |
2790 | } | |
2791 | if (ref ($cgiparams{'FH'}) ne 'Fh') { | |
2792 | $errormessage = $Lang::tr{'there was no file upload'}; | |
2793 | goto VPNCONF_ERROR; | |
2794 | } | |
2795 | # Move uploaded certificate to a temporary file | |
2796 | (my $fh, my $filename) = tempfile( ); | |
2797 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
2798 | $errormessage = $!; | |
2799 | goto VPNCONF_ERROR; | |
2800 | } | |
2801 | ||
2802 | # Verify the certificate has a valid CA and move it | |
2803 | my $validca = 0; | |
2804 | my $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/cacert.pem $filename`; | |
2805 | if ($test =~ /: OK/) { | |
2806 | $validca = 1; | |
2807 | } else { | |
2808 | foreach my $key (keys %cahash) { | |
2809 | $test = `/usr/bin/openssl verify -CAfile ${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem $filename`; | |
2810 | if ($test =~ /: OK/) { | |
2811 | $validca = 1; | |
2812 | } | |
6e13d0a5 | 2813 | } |
c6c9630e MT |
2814 | } |
2815 | if (! $validca) { | |
2816 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
2817 | unlink ($filename); | |
2818 | goto VPNCONF_ERROR; | |
2819 | } else { | |
2820 | move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2821 | if ($? ne 0) { | |
2822 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; | |
2823 | unlink ($filename); | |
2824 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2825 | } |
c6c9630e MT |
2826 | } |
2827 | ||
2828 | my $temp = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem`; | |
2829 | $temp =~ /Subject:.*CN=(.*)[\n]/; | |
2830 | $temp = $1; | |
2831 | $temp =~ s+/Email+, E+; | |
2832 | $temp =~ s/ ST=/ S=/; | |
2833 | $cgiparams{'CERT_NAME'} = $temp; | |
2834 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
2835 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
2836 | if ($cgiparams{'CERT_NAME'} eq '') { | |
2837 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2838 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
2839 | goto VPNCONF_ERROR; | |
2840 | } | |
2841 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
2842 | if ($cgiparams{'KEY'}) { | |
2843 | $errormessage = $Lang::tr{'cant change certificates'}; | |
2844 | goto VPNCONF_ERROR; | |
2845 | } | |
2846 | # Validate input since the form was submitted | |
2847 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
2848 | $errormessage = $Lang::tr{'name too long'}; | |
2849 | goto VPNCONF_ERROR; | |
2850 | } | |
2851 | if ($cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
2852 | $errormessage = $Lang::tr{'invalid input for name'}; | |
2853 | goto VPNCONF_ERROR; | |
2854 | } | |
2855 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
2856 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
2857 | goto VPNCONF_ERROR; | |
2858 | } | |
2859 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
2860 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
2861 | goto VPNCONF_ERROR; | |
2862 | } | |
2863 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2864 | $errormessage = $Lang::tr{'invalid input for department'}; | |
2865 | goto VPNCONF_ERROR; | |
2866 | } | |
2867 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
2868 | $errormessage = $Lang::tr{'organization too long'}; | |
2869 | goto VPNCONF_ERROR; | |
2870 | } | |
2871 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
2872 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
2873 | goto VPNCONF_ERROR; | |
2874 | } | |
2875 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2876 | $errormessage = $Lang::tr{'invalid input for city'}; | |
2877 | goto VPNCONF_ERROR; | |
2878 | } | |
2879 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
2880 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
2881 | goto VPNCONF_ERROR; | |
2882 | } | |
2883 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
2884 | $errormessage = $Lang::tr{'invalid input for country'}; | |
2885 | goto VPNCONF_ERROR; | |
2886 | } | |
2887 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
2888 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
2889 | $errormessage = $Lang::tr{'password too short'}; | |
2890 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2891 | } |
c6c9630e MT |
2892 | } |
2893 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { | |
2894 | $errormessage = $Lang::tr{'passwords do not match'}; | |
2895 | goto VPNCONF_ERROR; | |
2896 | } | |
2897 | ||
2898 | # Replace empty strings with a . | |
2899 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
2900 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
2901 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
2902 | ||
2903 | # Create the Host certificate request client | |
2904 | my $pid = open(OPENSSL, "|-"); | |
2905 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
2906 | if ($pid) { # parent | |
2907 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
2908 | print OPENSSL "$state\n"; | |
2909 | print OPENSSL "$city\n"; | |
2910 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
2911 | print OPENSSL "$ou\n"; | |
2912 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
2913 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
2914 | print OPENSSL ".\n"; | |
2915 | print OPENSSL ".\n"; | |
2916 | close (OPENSSL); | |
2917 | if ($?) { | |
2918 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2919 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2920 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2921 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2922 | } |
c6c9630e MT |
2923 | } else { # child |
2924 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', '-rand', '/proc/interrupts:/proc/net/rt_cache', | |
2925 | '-newkey', 'rsa:1024', | |
2926 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
2927 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
2928 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
2929 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
2930 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2931 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2932 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2933 | } |
c6c9630e MT |
2934 | } |
2935 | ||
2936 | # Sign the host certificate request | |
2937 | system('/usr/bin/openssl', 'ca', '-days', '999999', | |
2938 | '-batch', '-notext', | |
2939 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
2940 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
2941 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
2942 | if ($?) { | |
2943 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2944 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2945 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2946 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2947 | &newcleanssldatabase(); | |
2948 | goto VPNCONF_ERROR; | |
2949 | } else { | |
2950 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
2951 | &deletebackupcert(); | |
2952 | } | |
2953 | ||
2954 | # Create the pkcs12 file | |
2955 | system('/usr/bin/openssl', 'pkcs12', '-export', | |
2956 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", | |
2957 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
2958 | '-name', $cgiparams{'NAME'}, | |
2959 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
2960 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", | |
2961 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", | |
2962 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
2963 | if ($?) { | |
2964 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
2965 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2966 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
2967 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
2968 | goto VPNCONF_ERROR; | |
2969 | } else { | |
2970 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
2971 | } | |
2972 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
2973 | ;# Nothing, just editing | |
2974 | } else { | |
2975 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
2976 | goto VPNCONF_ERROR; | |
2977 | } | |
2978 | ||
2979 | # Check if there is no other entry with this common name | |
2980 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
2981 | foreach my $key (keys %confighash) { | |
2982 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
2983 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
2984 | goto VPNCONF_ERROR; | |
6e13d0a5 | 2985 | } |
c6c9630e MT |
2986 | } |
2987 | } | |
2988 | ||
2989 | # Save the config | |
2990 | my $key = $cgiparams{'KEY'}; | |
2991 | if (! $key) { | |
2992 | $key = &General::findhasharraykey (\%confighash); | |
2993 | foreach my $i (0 .. 31) { $confighash{$key}[$i] = "";} | |
2994 | } | |
2995 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; | |
2996 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
2997 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { | |
2998 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; | |
2999 | } | |
ce9abb66 | 3000 | $confighash{$key}[3] = $cgiparams{'TYPE'}; |
c6c9630e MT |
3001 | if ($cgiparams{'AUTH'} eq 'psk') { |
3002 | $confighash{$key}[4] = 'psk'; | |
3003 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
3004 | } else { | |
3005 | $confighash{$key}[4] = 'cert'; | |
3006 | } | |
ce9abb66 AH |
3007 | if ($cgiparams{'TYPE'} eq 'net') { |
3008 | $confighash{$key}[6] = $cgiparams{'SIDE'}; | |
3009 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
3010 | } | |
c6c9630e MT |
3011 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
3012 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; | |
d96c89eb AH |
3013 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
3014 | if ($cgiparams{'FRAGMENT'} eq '') { | |
3015 | $confighash{$key}[24] = '1300'; | |
3016 | } else { | |
3017 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
3018 | } | |
c6c9630e MT |
3019 | $confighash{$key}[25] = $cgiparams{'REMARK'}; |
3020 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
3021 | # new fields | |
3022 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; | |
3023 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
3024 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
3025 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
3026 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
3027 | # new fileds | |
3028 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3029 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { | |
3030 | $cgiparams{'KEY'} = $key; | |
3031 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
3032 | } | |
3033 | goto VPNCONF_END; | |
6e13d0a5 | 3034 | } else { |
c6c9630e MT |
3035 | $cgiparams{'ENABLED'} = 'on'; |
3036 | $cgiparams{'SIDE'} = 'left'; | |
3037 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { | |
3038 | $cgiparams{'AUTH'} = 'psk'; | |
3039 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
3040 | $cgiparams{'AUTH'} = 'certfile'; | |
3041 | } else { | |
6e13d0a5 | 3042 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
3043 | } |
3044 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
3045 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
3046 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
3047 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
3048 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
6e13d0a5 | 3049 | } |
c6c9630e | 3050 | |
6e13d0a5 | 3051 | VPNCONF_ERROR: |
6e13d0a5 MT |
3052 | $checked{'ENABLED'}{'off'} = ''; |
3053 | $checked{'ENABLED'}{'on'} = ''; | |
3054 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
3055 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
3056 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
3057 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
3058 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
3059 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
3060 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
3061 | |
3062 | ||
6e13d0a5 MT |
3063 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
3064 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
3065 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 3066 | |
6e13d0a5 MT |
3067 | $selected{'SIDE'}{'server'} = ''; |
3068 | $selected{'SIDE'}{'client'} = ''; | |
3069 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
d96c89eb AH |
3070 | |
3071 | $selected{'PROTOCOL'}{'udp'} = ''; | |
3072 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
3073 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
3074 | ||
c6c9630e | 3075 | |
6e13d0a5 MT |
3076 | $checked{'AUTH'}{'psk'} = ''; |
3077 | $checked{'AUTH'}{'certreq'} = ''; | |
3078 | $checked{'AUTH'}{'certgen'} = ''; | |
3079 | $checked{'AUTH'}{'certfile'} = ''; | |
3080 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 3081 | |
6e13d0a5 | 3082 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
c6c9630e | 3083 | |
6e13d0a5 MT |
3084 | $checked{'COMPLZO'}{'off'} = ''; |
3085 | $checked{'COMPLZO'}{'on'} = ''; | |
3086 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 3087 | |
d96c89eb AH |
3088 | $checked{'MSSFIX'}{'off'} = ''; |
3089 | $checked{'MSSFIX'}{'on'} = ''; | |
3090 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
3091 | ||
6e13d0a5 MT |
3092 | |
3093 | if (1) { | |
3094 | &Header::showhttpheaders(); | |
3095 | &Header::openpage($Lang::tr{'vpn configuration main'}, 1, ''); | |
3096 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3097 | if ($errormessage) { | |
3098 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3099 | print "<class name='base'>$errormessage"; | |
3100 | print " </class>"; | |
3101 | &Header::closebox(); | |
3102 | } | |
c6c9630e | 3103 | |
6e13d0a5 MT |
3104 | if ($warnmessage) { |
3105 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
3106 | print "<class name='base'>$warnmessage"; | |
3107 | print " </class>"; | |
3108 | &Header::closebox(); | |
3109 | } | |
c6c9630e | 3110 | |
6e13d0a5 | 3111 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 3112 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 3113 | |
6e13d0a5 MT |
3114 | if ($cgiparams{'KEY'}) { |
3115 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
3116 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 3117 | } |
c6c9630e | 3118 | |
6e13d0a5 MT |
3119 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
3120 | print "<table width='100%'>\n"; | |
3121 | print "<tr><td width='25%' class='boldbase'>$Lang::tr{'name'}:</td>"; | |
ce9abb66 | 3122 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 MT |
3123 | if ($cgiparams{'KEY'}) { |
3124 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>\n"; | |
3125 | } else { | |
3126 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
3127 | } | |
c6c9630e MT |
3128 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
3129 | # print "<td><select name='INTERFACE'>"; | |
3130 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
3131 | # if ($netsettings{'BLUE_DEV'} ne '') { | |
3132 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
3133 | # } | |
3134 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
3135 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
3136 | # print "</select></td></tr>"; | |
3137 | # print <<END | |
ce9abb66 AH |
3138 | } else { |
3139 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
3140 | if ($cgiparams{'KEY'}) { | |
3141 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
3142 | } else { | |
3143 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
3144 | } | |
3145 | print <<END | |
3146 | <td width='25%'> </td> | |
3147 | <td width='25%'> </td></tr> | |
3148 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> | |
3149 | <td><select name='SIDE'><option value='server' $selected{'SIDE'}{'server'}>OpenVPN Server</option> | |
3150 | <option value='client' $selected{'SIDE'}{'client'}>OpenVPN Client</option></select></td> | |
3151 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> | |
3152 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td></tr> | |
3153 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td> | |
3154 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> | |
3155 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}</td> | |
3156 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td></tr> | |
3157 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td> | |
3158 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td></tr> | |
3159 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> | |
d96c89eb AH |
3160 | |
3161 | <td><select name='PROTOCOL'><option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
3162 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
3163 | ||
3164 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
ce9abb66 | 3165 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td></tr> |
d96c89eb | 3166 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'} <img src='/blob.gif'</td> |
ce9abb66 | 3167 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> |
d96c89eb AH |
3168 | |
3169 | <tr><td class='boldbase' nowrap='nowrap'>mssfix <img src='/blob.gif' /></td> | |
3170 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
3171 | ||
3172 | <tr><td class='boldbase' nowrap='nowrap'>Fragment <img src='/blob.gif' /></td> | |
3173 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> | |
3174 | <td>Default: <span class="base">1300</span></td> | |
3175 | ||
ce9abb66 AH |
3176 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} <img src='/blob.gif' /></td> |
3177 | <td> <input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></TD> | |
ce9abb66 AH |
3178 | |
3179 | END | |
3180 | ; | |
3181 | } | |
d96c89eb | 3182 | |
6e13d0a5 MT |
3183 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'} <img src='/blob.gif' /></td>"; |
3184 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr>"; | |
c6c9630e | 3185 | |
ce9abb66 AH |
3186 | if ($cgiparams{'TYPE'} eq 'host') { |
3187 | ||
3188 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>\n"; | |
3189 | } | |
3190 | ||
c6c9630e MT |
3191 | # if ($cgiparams{'KEY'}) { |
3192 | # print "<td colspan='3'> </td></tr></table>"; | |
3193 | # } else { | |
3194 | # print "<td colspan='3'><input type='checkbox' name='EDIT_ADVANCED' $checked{'EDIT_ADVANCED'}{'on'} /> $Lang::tr{'edit advanced settings when done'}</tr></table>"; | |
3195 | # } | |
3196 | # }else{ | |
6e13d0a5 | 3197 | print "<td colspan='3'> </td></tr></table>"; |
c6c9630e MT |
3198 | # } |
3199 | ||
6e13d0a5 MT |
3200 | |
3201 | ||
3202 | &Header::closebox(); | |
c6c9630e | 3203 | |
6e13d0a5 | 3204 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { |
c6c9630e MT |
3205 | # &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
3206 | # print <<END | |
3207 | # <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
3208 | # <tr><td class='base' width='50%'>$Lang::tr{'use a pre-shared key'}</td> | |
3209 | # <td class='base' width='50%'><input type='text' name='PSK' size='30' value='$cgiparams{'PSK'}' /></td></tr> | |
3210 | # </table> | |
3211 | END | |
3212 | # ; | |
3213 | # &Header::closebox(); | |
6e13d0a5 MT |
3214 | } elsif (! $cgiparams{'KEY'}) { |
3215 | my $disabled=''; | |
3216 | my $cakeydisabled=''; | |
3217 | my $cacrtdisabled=''; | |
3218 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
3219 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
3220 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); | |
ce9abb66 AH |
3221 | |
3222 | ||
3223 | if ($cgiparams{'TYPE'} eq 'host') { | |
3224 | ||
3225 | print <<END | |
6e13d0a5 MT |
3226 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
3227 | <tr><td colspan='3' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' border='0' /></td></tr> | |
ce9abb66 AH |
3228 | <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> |
3229 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
6e13d0a5 | 3230 | <tr><td colspan='3' bgcolor='#000000'><img src='/images/null.gif' width='1' height='1' BORDER='0' /></td></tr> |
ce9abb66 AH |
3231 | <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> |
3232 | <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> | |
3233 | <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> | |
3234 | <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> | |
3235 | <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> | |
3236 | <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> | |
3237 | <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> | |
3238 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
6e13d0a5 | 3239 | END |
ce9abb66 AH |
3240 | ; |
3241 | ||
3242 | ### | |
7c1d9faf | 3243 | # m.a.d net2net |
ce9abb66 AH |
3244 | ### |
3245 | ||
3246 | } else { | |
3247 | ||
3248 | print <<END | |
3249 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> | |
3250 | ||
3251 | <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> | |
3252 | <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> | |
3253 | <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> | |
3254 | <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> | |
3255 | <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> | |
3256 | <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> | |
3257 | <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> | |
3258 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> | |
3259 | ||
3260 | END | |
3261 | ; | |
3262 | ||
3263 | } | |
3264 | ||
3265 | ### | |
7c1d9faf | 3266 | # m.a.d net2net |
ce9abb66 | 3267 | ### |
c6c9630e | 3268 | |
6e13d0a5 MT |
3269 | foreach my $country (sort keys %{Countries::countries}) { |
3270 | print "<option value='$Countries::countries{$country}'"; | |
3271 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
3272 | print " selected='selected'"; | |
3273 | } | |
3274 | print ">$country</option>"; | |
3275 | } | |
ce9abb66 | 3276 | ### |
7c1d9faf | 3277 | # m.a.d net2net |
ce9abb66 AH |
3278 | ### |
3279 | ||
3280 | if ($cgiparams{'TYPE'} eq 'host') { | |
6e13d0a5 MT |
3281 | print <<END |
3282 | </select></td></tr> | |
ce9abb66 AH |
3283 | |
3284 | <td class='base'>$Lang::tr{'valid till'} (days):</td> | |
3285 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> | |
3286 | <tr><td> </td> | |
6e13d0a5 MT |
3287 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
3288 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
3289 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<BR>($Lang::tr{'confirmation'})</td> | |
3290 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> | |
ce9abb66 AH |
3291 | </table> |
3292 | END | |
3293 | }else{ | |
3294 | print <<END | |
3295 | </select></td></tr> | |
3296 | <tr><td> </td><td> </td><td> </td></tr> | |
3297 | <tr><td> </td><td> </td><td> </td></tr> | |
3298 | </table> | |
3299 | ||
c6c9630e | 3300 | END |
ce9abb66 AH |
3301 | } |
3302 | ||
3303 | ### | |
7c1d9faf | 3304 | # m.a.d net2net |
ce9abb66 | 3305 | ### |
c6c9630e MT |
3306 | ; |
3307 | &Header::closebox(); | |
3308 | } | |
6e13d0a5 | 3309 | |
c6c9630e MT |
3310 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
3311 | if ($cgiparams{'KEY'}) { | |
3312 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
3313 | } | |
3314 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
3315 | &Header::closebigbox(); | |
3316 | &Header::closepage(); | |
3317 | exit (0); | |
6e13d0a5 | 3318 | } |
c6c9630e | 3319 | VPNCONF_END: |
6e13d0a5 | 3320 | } |
c6c9630e MT |
3321 | |
3322 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
3323 | ### |
3324 | ### Default status page | |
3325 | ### | |
c6c9630e MT |
3326 | %cgiparams = (); |
3327 | %cahash = (); | |
3328 | %confighash = (); | |
3329 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
3330 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3331 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3332 | ||
4e17adad | 3333 | my @status = `/bin/cat /var/log/ovpnserver.log`; |
c6c9630e MT |
3334 | |
3335 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
6e13d0a5 MT |
3336 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
3337 | my $ipaddr = <IPADDR>; | |
3338 | close IPADDR; | |
3339 | chomp ($ipaddr); | |
3340 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
3341 | if ($cgiparams{'VPN_IP'} eq '') { | |
c6c9630e | 3342 | $cgiparams{'VPN_IP'} = $ipaddr; |
6e13d0a5 MT |
3343 | } |
3344 | } | |
c6c9630e MT |
3345 | } |
3346 | ||
6e13d0a5 | 3347 | #default setzen |
c6c9630e | 3348 | if ($cgiparams{'DCIPHER'} eq '') { |
6e13d0a5 | 3349 | $cgiparams{'DCIPHER'} = 'BF-CBC'; |
c6c9630e | 3350 | } |
6e13d0a5 MT |
3351 | # if ($cgiparams{'DCOMPLZO'} eq '') { |
3352 | # $cgiparams{'DCOMPLZO'} = 'on'; | |
3353 | # } | |
c6c9630e | 3354 | if ($cgiparams{'DDEST_PORT'} eq '') { |
6e13d0a5 | 3355 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
3356 | } |
3357 | if ($cgiparams{'DMTU'} eq '') { | |
6e13d0a5 | 3358 | $cgiparams{'DMTU'} = '1400'; |
c6c9630e MT |
3359 | } |
3360 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { | |
6e13d0a5 | 3361 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e MT |
3362 | } |
3363 | ||
3364 | $checked{'ENABLED'}{'off'} = ''; | |
3365 | $checked{'ENABLED'}{'on'} = ''; | |
3366 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
3367 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
3368 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
3369 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
3370 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
3371 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
3372 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
3373 | $selected{'DDEVICE'}{'tun'} = ''; |
3374 | $selected{'DDEVICE'}{'tap'} = ''; | |
3375 | $selected{'DDEVICE'}{$cgiparams{'DDEVICE'}} = 'SELECTED'; | |
3376 | ||
3377 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
3378 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
3379 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
3380 | ||
3381 | $selected{'DCIPHER'}{'DES-CBC'} = ''; | |
3382 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
3383 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
3384 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
3385 | $selected{'DCIPHER'}{'RC2-CBC'} = ''; | |
3386 | $selected{'DCIPHER'}{'RC2-40-CBC'} = ''; | |
3387 | $selected{'DCIPHER'}{'RC2-64-CBC'} = ''; | |
3388 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
3389 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
3390 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
3391 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
3392 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
3393 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; | |
3394 | $checked{'DCOMPLZO'}{'off'} = ''; | |
3395 | $checked{'DCOMPLZO'}{'on'} = ''; | |
3396 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
d96c89eb AH |
3397 | # m.a.d |
3398 | $checked{'MSSFIX'}{'off'} = ''; | |
3399 | $checked{'MSSFIX'}{'on'} = ''; | |
3400 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 3401 | #new settings |
c6c9630e MT |
3402 | &Header::showhttpheaders(); |
3403 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
3404 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 3405 | |
c6c9630e | 3406 | if ($errormessage) { |
6e13d0a5 MT |
3407 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
3408 | print "<class name='base'>$errormessage\n"; | |
3409 | print " </class>\n"; | |
3410 | &Header::closebox(); | |
c6c9630e | 3411 | } |
6e13d0a5 | 3412 | |
c6c9630e MT |
3413 | 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>"; |
3414 | my $srunning = "no"; | |
3415 | my $activeonrun = ""; | |
3416 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
3417 | $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>"; |
3418 | $srunning ="yes"; | |
3419 | $activeonrun = ""; | |
c6c9630e | 3420 | } else { |
6e13d0a5 | 3421 | $activeonrun = "disabled='disabled'"; |
c6c9630e | 3422 | } |
afabe9f7 | 3423 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); |
c6c9630e MT |
3424 | print <<END |
3425 | <table width='100%'> | |
3426 | <form method='post'> | |
3427 | <td width='25%'> </td> | |
3428 | <td width='25%'> </td> | |
3429 | <td width='25%'> </td></tr> | |
3430 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
3431 | <td align='left'>$sactive</td> | |
3432 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
3433 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> | |
3434 | END | |
3435 | ; | |
3436 | if (&haveBlueNet()) { | |
3437 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
3438 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
3439 | } | |
3440 | if (&haveOrangeNet()) { | |
3441 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; | |
3442 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
3443 | } | |
3444 | print <<END | |
4e17adad CS |
3445 | <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> |
3446 | <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 |
3447 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn device'}</td> |
3448 | <td><select name='DDEVICE' ><option value='tun' $selected{'DDEVICE'}{'tun'}>TUN</option> | |
ee79343e JPT |
3449 | <!-- this is still not working |
3450 | <option value='tap' $selected{'DDEVICE'}{'tap'}>TAP</option></select>--> </td> | |
c6c9630e MT |
3451 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
3452 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
3453 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> | |
3454 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> | |
3455 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
3456 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
3457 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}'size='5' /></TD> | |
3458 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> | |
3459 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
3460 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> | |
3461 | <td><select name='DCIPHER'><option value='DES-CBC' $selected{'DCIPHER'}{'DES-CBC'}>DES-CBC</option> | |
3462 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC</option> | |
3463 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC</option> | |
3464 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC</option> | |
3465 | <option value='RC2-CBC' $selected{'DCIPHER'}{'RC2-CBC'}>RC2-CBC</option> | |
3466 | <option value='RC2-40-CBC' $selected{'DCIPHER'}{'RC2-40-CBC'}>RC2-40-CBC</option> | |
3467 | <option value='RC2-64-CBC' $selected{'DCIPHER'}{'RC2-64-CBC'}>RC2-64-CBC</option> | |
3468 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC</option> | |
3469 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC</option> | |
3470 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-128-CBC</option> | |
3471 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-192-CBC</option> | |
3472 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-256-CBC</option></select></td> | |
3473 | END | |
3474 | ; | |
3475 | ||
3476 | if ( $srunning eq "yes" ) { | |
3477 | print "<tr><td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' /></td>"; | |
3478 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' disabled='disabled'/></td>"; | |
3479 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td>"; | |
3480 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'restart ovpn server'}' /></td></tr>"; | |
3481 | } else{ | |
3482 | print "<tr><td align='left'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>"; | |
3483 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' /></td>"; | |
3484 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && | |
3485 | -e "${General::swroot}/ovpn/ca/dh1024.pem" && | |
3486 | -e "${General::swroot}/ovpn/certs/servercert.pem" && | |
3487 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
3488 | (( $cgiparams{'ENABLED'} eq 'on') || | |
3489 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
3490 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
3491 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td>"; | |
3492 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'restart ovpn server'}' /></td></tr>"; | |
3493 | } else { | |
3494 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td>"; | |
3495 | print "<td><input type='submit' name='ACTION' value='$Lang::tr{'restart ovpn server'}' disabled='disabled' /></td></tr>"; | |
3496 | } | |
3497 | } | |
3498 | print "</form></table>"; | |
3499 | &Header::closebox(); | |
3500 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}:"); | |
3501 | print <<EOF#' | |
3502 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
3503 | <tr> | |
3504 | <td width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td> | |
6e13d0a5 MT |
3505 | <td width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></td> |
3506 | <td width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></td> | |
c6c9630e | 3507 | </tr> |
6e13d0a5 MT |
3508 | EOF |
3509 | ; | |
c6c9630e | 3510 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { |
6e13d0a5 MT |
3511 | my $casubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/ca/cacert.pem`; |
3512 | $casubject =~ /Subject: (.*)[\n]/; | |
3513 | $casubject = $1; | |
3514 | $casubject =~ s+/Email+, E+; | |
3515 | $casubject =~ s/ ST=/ S=/; | |
c6c9630e | 3516 | |
6e13d0a5 | 3517 | print <<END |
4e17adad | 3518 | <tr bgcolor='$color{'color22'}'> |
c6c9630e MT |
3519 | <td class='base'>$Lang::tr{'root certificate'}</td> |
3520 | <td class='base'>$casubject</td> | |
3521 | <form method='post' name='frmrootcrta'><td width='3%' align='center'> | |
3522 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> | |
3523 | <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' /> | |
3524 | </td></form> | |
3525 | <form method='post' name='frmrootcrtb'><td width='3%' align='center'> | |
438dd0cc | 3526 | <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 | 3527 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> |
c6c9630e MT |
3528 | </td></form> |
3529 | <td width='4%'> </td></tr> | |
6e13d0a5 MT |
3530 | END |
3531 | ; | |
c6c9630e | 3532 | } else { |
6e13d0a5 MT |
3533 | # display rootcert generation buttons |
3534 | print <<END | |
4e17adad | 3535 | <tr bgcolor='$color{'color22'}'> |
6e13d0a5 MT |
3536 | <td class='base'>$Lang::tr{'root certificate'}:</td> |
3537 | <td class='base'>$Lang::tr{'not present'}</td> | |
3538 | <td colspan='3'> </td></tr> | |
3539 | END | |
3540 | ; | |
c6c9630e | 3541 | } |
6e13d0a5 | 3542 | |
c6c9630e | 3543 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { |
6e13d0a5 MT |
3544 | my $hostsubject = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/servercert.pem`; |
3545 | $hostsubject =~ /Subject: (.*)[\n]/; | |
3546 | $hostsubject = $1; | |
3547 | $hostsubject =~ s+/Email+, E+; | |
3548 | $hostsubject =~ s/ ST=/ S=/; | |
c6c9630e | 3549 | |
6e13d0a5 | 3550 | print <<END |
4e17adad | 3551 | <tr bgcolor='$color{'color20'}'> |
6e13d0a5 MT |
3552 | <td class='base'>$Lang::tr{'host certificate'}</td> |
3553 | <td class='base'>$hostsubject</td> | |
3554 | <form method='post' name='frmhostcrta'><td width='3%' align='center'> | |
c6c9630e MT |
3555 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> |
3556 | <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 |
3557 | </td></form> |
3558 | <form method='post' name='frmhostcrtb'><td width='3%' align='center'> | |
438dd0cc | 3559 | <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 | 3560 | <input type='hidden' name='ACTION' value='$Lang::tr{'download host certificate'}' /> |
6e13d0a5 MT |
3561 | </td></form> |
3562 | <td width='4%'> </td></tr> | |
3563 | END | |
3564 | ; | |
c6c9630e | 3565 | } else { |
6e13d0a5 MT |
3566 | # Nothing |
3567 | print <<END | |
4e17adad | 3568 | <tr bgcolor='$color{'color20'}'> |
6e13d0a5 MT |
3569 | <td width='25%' class='base'>$Lang::tr{'host certificate'}:</td> |
3570 | <td class='base'>$Lang::tr{'not present'}</td> | |
3571 | </td><td colspan='3'> </td></tr> | |
3572 | END | |
3573 | ; | |
c6c9630e | 3574 | } |
6e13d0a5 | 3575 | |
c6c9630e MT |
3576 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
3577 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
6e13d0a5 | 3578 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; |
c6c9630e MT |
3579 | print "</form></td></tr>\n"; |
3580 | } | |
6e13d0a5 | 3581 | |
c6c9630e | 3582 | if (keys %cahash > 0) { |
6e13d0a5 | 3583 | foreach my $key (keys %cahash) { |
c6c9630e | 3584 | if (($key + 1) % 2) { |
4e17adad | 3585 | print "<tr bgcolor='$color{'color20'}'>\n"; |
c6c9630e | 3586 | } else { |
4e17adad | 3587 | print "<tr bgcolor='$color{'color22'}'>\n"; |
c6c9630e MT |
3588 | } |
3589 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
3590 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
3591 | print <<END | |
3592 | <form method='post' name='cafrm${key}a'><td align='center'> | |
6e13d0a5 MT |
3593 | <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' /> |
3594 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
3595 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
3596 | </td></form> |
3597 | <form method='post' name='cafrm${key}b'><td align='center'> | |
438dd0cc | 3598 | <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 |
3599 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> |
3600 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
3601 | </td></form> |
3602 | <form method='post' name='cafrm${key}c'><td align='center'> | |
6e13d0a5 MT |
3603 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> |
3604 | <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' /> | |
3605 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e | 3606 | </td></form></tr> |
6e13d0a5 MT |
3607 | END |
3608 | ; | |
3609 | } | |
c6c9630e MT |
3610 | } |
3611 | ||
3612 | print "</table>"; | |
3613 | ||
3614 | # If the file contains entries, print Key to action icons | |
3615 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
3616 | print <<END | |
3617 | <table> | |
3618 | <tr> | |
6e13d0a5 MT |
3619 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
3620 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
3621 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
438dd0cc | 3622 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> |
6e13d0a5 | 3623 | <td class='base'>$Lang::tr{'download certificate'}</td> |
c6c9630e MT |
3624 | </tr> |
3625 | </table> | |
6e13d0a5 MT |
3626 | END |
3627 | ; | |
c6c9630e MT |
3628 | } |
3629 | print <<END | |
3630 | <form method='post' enctype='multipart/form-data'> | |
3631 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
3632 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'ca name'}:</td> | |
3633 | <td nowrap='nowrap'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' /> | |
3634 | <td nowrap='nowrap'><input type='file' name='FH' size='30' /></td> | |
4e17adad | 3635 | <td nowrap='nowrap'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}' /><br /><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> |
c6c9630e | 3636 | </tr></table></form> |
6e13d0a5 MT |
3637 | END |
3638 | ; | |
c6c9630e MT |
3639 | |
3640 | &Header::closebox(); | |
3641 | if ( $srunning eq "yes" ) { | |
6e13d0a5 | 3642 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' disabled='disabled' /></div></form>\n"; |
c6c9630e MT |
3643 | }else{ |
3644 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'reset'}' /></div></form>\n"; | |
3645 | } | |
3646 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
ce9abb66 AH |
3647 | |
3648 | ### | |
7c1d9faf | 3649 | # m.a.d net2net |
ce9abb66 AH |
3650 | ### |
3651 | ||
c6c9630e MT |
3652 | &Header::openbox('100%', 'LEFT', $Lang::tr{'Client status and controlc' }); |
3653 | print <<END | |
ce9abb66 AH |
3654 | |
3655 | ||
c6c9630e MT |
3656 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> |
3657 | <tr> | |
3658 | <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></td> | |
3659 | <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></td> | |
3660 | <td width='18%' class='boldbase' align='center'><b>$Lang::tr{'common name'}</b></td> | |
3661 | <td width='17%' class='boldbase' align='center'><b>$Lang::tr{'valid till'}</b></td> | |
3662 | <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> | |
3663 | <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></td> | |
3664 | <td width='5%' class='boldbase' colspan='6' align='center'><b>$Lang::tr{'action'}</b></td> | |
3665 | </tr> | |
6e13d0a5 | 3666 | END |
c6c9630e MT |
3667 | ; |
3668 | my $id = 0; | |
3669 | my $gif; | |
3670 | foreach my $key (keys %confighash) { | |
3671 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } | |
3672 | ||
3673 | if ($id % 2) { | |
4e17adad | 3674 | print "<tr bgcolor='$color{'color20'}'>\n"; |
bb89e92a | 3675 | } else { |
4e17adad | 3676 | print "<tr bgcolor='$color{'color22'}'>\n"; |
c6c9630e MT |
3677 | } |
3678 | print "<td align='center' nowrap='nowrap'>$confighash{$key}[1]</td>"; | |
3679 | print "<td align='center' nowrap='nowrap'>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
3680 | if ($confighash{$key}[4] eq 'cert') { | |
3681 | print "<td align='left' nowrap='nowrap'>$confighash{$key}[2]</td>"; | |
3682 | } else { | |
3683 | print "<td align='left'> </td>"; | |
3684 | } | |
3685 | my $cavalid = `/usr/bin/openssl x509 -text -in ${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem`; | |
3686 | $cavalid =~ /Not After : (.*)[\n]/; | |
3687 | $cavalid = $1; | |
3688 | print "<td align='center'>$cavalid</td>"; | |
3689 | print "<td align='center'>$confighash{$key}[25]</td>"; | |
ce9abb66 | 3690 | |
c6c9630e | 3691 | 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 | 3692 | |
c6c9630e MT |
3693 | if ($confighash{$key}[0] eq 'off') { |
3694 | $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>"; | |
3695 | } else { | |
ce9abb66 AH |
3696 | |
3697 | ### | |
7c1d9faf | 3698 | # m.a.d net2net |
b278daf3 AH |
3699 | ### |
3700 | ||
3701 | if ($confighash{$key}[3] eq 'net') { | |
ce9abb66 AH |
3702 | my @tempovpnsubnet = split("\/",$confighash{$key}[27]); |
3703 | my @ovpnip = split /\./,$tempovpnsubnet[0]; | |
3704 | my $pingip = ""; | |
7c1d9faf | 3705 | |
ce9abb66 AH |
3706 | if ($confighash{$key}[6] eq 'server') { |
3707 | $pingip = "$ovpnip[0].$ovpnip[1].$ovpnip[2].2"; | |
3708 | } else { | |
3709 | $pingip = "$ovpnip[0].$ovpnip[1].$ovpnip[2].1"; | |
3710 | } | |
3711 | ||
3712 | my $p = Net::Ping->new("udp",1); | |
3713 | ||
3714 | if ($p->ping($pingip)) { | |
3715 | $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>"; | |
3716 | } | |
3717 | $p->close(); | |
3718 | ||
3719 | } | |
b278daf3 AH |
3720 | |
3721 | my $cn; | |
3722 | my @match = (); | |
3723 | foreach my $line (@status) { | |
3724 | chomp($line); | |
3725 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
3726 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
3727 | if ($match[1] ne "Common Name") { | |
3728 | $cn = $match[1]; | |
3729 | } | |
3730 | $cn =~ s/[_]/ /g; | |
3731 | if ($cn eq "$confighash{$key}[2]") { | |
3732 | $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>"; | |
3733 | } | |
3734 | ||
3735 | ||
c6c9630e | 3736 | } |
7c1d9faf AH |
3737 | } |
3738 | } | |
ce9abb66 AH |
3739 | |
3740 | ||
c6c9630e MT |
3741 | my $disable_clientdl = "disabled='disabled'"; |
3742 | if (( $cgiparams{'ENABLED'} eq 'on') || | |
3743 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || | |
3744 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on')){ | |
3745 | $disable_clientdl = ""; | |
3746 | } | |
3747 | print <<END | |
3748 | <td align='center'>$active</td> | |
3749 | ||
3750 | <form method='post' name='frm${key}a'><td align='center'> | |
3751 | <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' /> | |
3752 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' $disable_clientdl /> | |
3753 | <input type='hidden' name='KEY' value='$key' $disable_clientdl /> | |
3754 | </td></form> | |
3755 | END | |
3756 | ; | |
3757 | if ($confighash{$key}[4] eq 'cert') { | |
3758 | print <<END | |
3759 | <form method='post' name='frm${key}b'><td align='center'> | |
3760 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> | |
3761 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
3762 | <input type='hidden' name='KEY' value='$key' /> | |
3763 | </td></form> | |
3764 | END | |
3765 | ; } else { | |
3766 | print "<td> </td>"; | |
3767 | } | |
3768 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { | |
3769 | print <<END | |
3770 | <form method='post' name='frm${key}c'><td align='center'> | |
438dd0cc | 3771 | <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 |
3772 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
3773 | <input type='hidden' name='KEY' value='$key' /> | |
3774 | </td></form> | |
3775 | END | |
3776 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
3777 | print <<END | |
3778 | <form method='post' name='frm${key}c'><td align='center'> | |
438dd0cc | 3779 | <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 |
3780 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
3781 | <input type='hidden' name='KEY' value='$key' /> | |
3782 | </td></form> | |
3783 | END | |
3784 | ; } else { | |
3785 | print "<td> </td>"; | |
3786 | } | |
3787 | print <<END | |
3788 | <form method='post' name='frm${key}d'><td align='center'> | |
3789 | <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' /> | |
3790 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
3791 | <input type='hidden' name='KEY' value='$key' /> | |
3792 | </td></form> | |
3793 | ||
3794 | <form method='post' name='frm${key}e'><td align='center'> | |
3795 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> | |
3796 | <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'/> | |
3797 | <input type='hidden' name='KEY' value='$key' /> | |
3798 | </td></form> | |
3799 | <form method='post' name='frm${key}f'><td align='center'> | |
3800 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> | |
3801 | <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' /> | |
3802 | <input type='hidden' name='KEY' value='$key' /> | |
3803 | </td></form> | |
3804 | </tr> | |
3805 | END | |
3806 | ; | |
3807 | $id++; | |
3808 | } | |
3809 | ; | |
3810 | ||
3811 | # If the config file contains entries, print Key to action icons | |
3812 | if ( $id ) { | |
3813 | print <<END | |
3814 | <table> | |
3815 | <tr> | |
3816 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
3817 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
3818 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
3819 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
3820 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
3821 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
3822 | <td class='base'>$Lang::tr{'edit'}</td> | |
3823 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
3824 | <td class='base'>$Lang::tr{'remove'}</td> | |
3825 | </tr> | |
3826 | <tr> | |
3827 | <td> </td> | |
3828 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
3829 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
aa7eb426 | 3830 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> |
c6c9630e | 3831 | <td class='base'>$Lang::tr{'download certificate'}</td> |
aa7eb426 | 3832 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> |
c6c9630e MT |
3833 | <td class='base'>$Lang::tr{'dl client arch'}</td> |
3834 | </tr> | |
3835 | </table> | |
3836 | END | |
3837 | ; | |
3838 | } | |
3839 | ||
3840 | print <<END | |
3841 | <table width='100%'> | |
3842 | <form method='post'> | |
3843 | <tr><td width='50%' ><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td> | |
3844 | <td width='50%' ><input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td></tr> | |
3845 | </form> | |
3846 | </table> | |
3847 | END | |
3848 | ; | |
3849 | &Header::closebox(); | |
bb89e92a | 3850 | } |
115340d2 | 3851 | &Header::closepage(); |
ce9abb66 AH |
3852 | |
3853 | ||
3854 |