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