]>
Commit | Line | Data |
---|---|---|
6e13d0a5 | 1 | #!/usr/bin/perl |
70df8302 MT |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
818dde8e | 5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # |
70df8302 MT |
6 | # # |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
818dde8e | 21 | |
6e13d0a5 MT |
22 | use CGI; |
23 | use CGI qw/:standard/; | |
c63a54f0 MT |
24 | use Imager::QRCode; |
25 | use MIME::Base32; | |
26 | use MIME::Base64; | |
3740b7ad | 27 | use URI::Encode qw(uri_encode uri_decode);; |
6e13d0a5 | 28 | use Net::DNS; |
ce9abb66 | 29 | use Net::Ping; |
54fd0535 | 30 | use Net::Telnet; |
6e13d0a5 MT |
31 | use File::Copy; |
32 | use File::Temp qw/ tempfile tempdir /; | |
33 | use strict; | |
34 | use Archive::Zip qw(:ERROR_CODES :CONSTANTS); | |
eff2dbf8 | 35 | use Sort::Naturally; |
498134e5 | 36 | use Date::Parse; |
6e13d0a5 | 37 | require '/var/ipfire/general-functions.pl'; |
6e13d0a5 MT |
38 | require "${General::swroot}/lang.pl"; |
39 | require "${General::swroot}/header.pl"; | |
40 | require "${General::swroot}/countries.pl"; | |
e2e270e1 | 41 | require "${General::swroot}/location-functions.pl"; |
6e13d0a5 MT |
42 | |
43 | # enable only the following on debugging purpose | |
2050be20 MT |
44 | #use warnings; |
45 | #use CGI::Carp 'fatalsToBrowser'; | |
46 | ||
6e13d0a5 | 47 | #workaround to suppress a warning when a variable is used only once |
8c877a82 | 48 | my @dummy = ( ${Header::colourgreen}, ${Header::colourblue} ); |
6e13d0a5 MT |
49 | undef (@dummy); |
50 | ||
f2fdd0c1 CS |
51 | my %color = (); |
52 | my %mainsettings = (); | |
53 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 54 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
6e13d0a5 MT |
55 | |
56 | ### | |
57 | ### Initialize variables | |
58 | ### | |
e81be1e1 AM |
59 | my %ccdconfhash=(); |
60 | my %ccdroutehash=(); | |
61 | my %ccdroute2hash=(); | |
6e13d0a5 MT |
62 | my %netsettings=(); |
63 | my %cgiparams=(); | |
64 | my %vpnsettings=(); | |
65 | my %checked=(); | |
66 | my %confighash=(); | |
67 | my %cahash=(); | |
68 | my %selected=(); | |
69 | my $warnmessage = ''; | |
70 | my $errormessage = ''; | |
400c8afd EK |
71 | my $cryptoerror = ''; |
72 | my $cryptowarning = ''; | |
6e13d0a5 | 73 | my %settings=(); |
54fd0535 | 74 | my $routes_push_file = ''; |
df9b48b7 AM |
75 | my $confighost="${General::swroot}/fwhosts/customhosts"; |
76 | my $configgrp="${General::swroot}/fwhosts/customgroups"; | |
77 | my $customnet="${General::swroot}/fwhosts/customnetworks"; | |
78 | my $name; | |
99bfa85c | 79 | my $col=""; |
ffbe77c8 EK |
80 | my $local_serverconf = "${General::swroot}/ovpn/scripts/server.conf.local"; |
81 | my $local_clientconf = "${General::swroot}/ovpn/scripts/client.conf.local"; | |
35494eac | 82 | my $dhparameter = "/etc/ssl/ffdhe4096.pem"; |
ffbe77c8 | 83 | |
6e13d0a5 MT |
84 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
85 | $cgiparams{'ENABLED'} = 'off'; | |
86 | $cgiparams{'ENABLED_BLUE'} = 'off'; | |
87 | $cgiparams{'ENABLED_ORANGE'} = 'off'; | |
88 | $cgiparams{'EDIT_ADVANCED'} = 'off'; | |
89 | $cgiparams{'NAT'} = 'off'; | |
90 | $cgiparams{'COMPRESSION'} = 'off'; | |
91 | $cgiparams{'ONLY_PROPOSED'} = 'off'; | |
92 | $cgiparams{'ACTION'} = ''; | |
93 | $cgiparams{'CA_NAME'} = ''; | |
94 | $cgiparams{'DHCP_DOMAIN'} = ''; | |
95 | $cgiparams{'DHCP_DNS'} = ''; | |
96 | $cgiparams{'DHCP_WINS'} = ''; | |
54fd0535 | 97 | $cgiparams{'ROUTES_PUSH'} = ''; |
6e13d0a5 | 98 | $cgiparams{'DCOMPLZO'} = 'off'; |
a79fa1d6 | 99 | $cgiparams{'MSSFIX'} = ''; |
8c877a82 | 100 | $cgiparams{'number'} = ''; |
4c962356 | 101 | $cgiparams{'DCIPHER'} = ''; |
49abe7af EK |
102 | $cgiparams{'DAUTH'} = ''; |
103 | $cgiparams{'TLSAUTH'} = ''; | |
54fd0535 | 104 | $routes_push_file = "${General::swroot}/ovpn/routes_push"; |
400c8afd EK |
105 | # Perform crypto and configration test |
106 | &pkiconfigcheck; | |
ffbe77c8 EK |
107 | |
108 | # Add CCD files if not already presant | |
109 | unless (-e $routes_push_file) { | |
110 | open(RPF, ">$routes_push_file"); | |
111 | close(RPF); | |
112 | } | |
113 | unless (-e "${General::swroot}/ovpn/ccd.conf") { | |
114 | open(CCDC, ">${General::swroot}/ovpn/ccd.conf"); | |
115 | close (CCDC); | |
116 | } | |
117 | unless (-e "${General::swroot}/ovpn/ccdroute") { | |
118 | open(CCDR, ">${General::swroot}/ovpn/ccdroute"); | |
119 | close (CCDR); | |
120 | } | |
121 | unless (-e "${General::swroot}/ovpn/ccdroute2") { | |
122 | open(CCDRT, ">${General::swroot}/ovpn/ccdroute2"); | |
123 | close (CCDRT); | |
124 | } | |
125 | # Add additional configs if not already presant | |
126 | unless (-e "$local_serverconf") { | |
127 | open(LSC, ">$local_serverconf"); | |
128 | close (LSC); | |
129 | } | |
130 | unless (-e "$local_clientconf") { | |
131 | open(LCC, ">$local_clientconf"); | |
132 | close (LCC); | |
133 | } | |
ce9abb66 | 134 | |
6e13d0a5 MT |
135 | &Header::getcgihash(\%cgiparams, {'wantfile' => 1, 'filevar' => 'FH'}); |
136 | ||
137 | # prepare openvpn config file | |
138 | ### | |
139 | ### Useful functions | |
140 | ### | |
c6c9630e MT |
141 | sub haveOrangeNet |
142 | { | |
13211b21 CS |
143 | if ($netsettings{'CONFIG_TYPE'} == 2) {return 1;} |
144 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} | |
c6c9630e MT |
145 | return 0; |
146 | } | |
147 | ||
148 | sub haveBlueNet | |
149 | { | |
13211b21 | 150 | if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;} |
c6c9630e | 151 | if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;} |
c6c9630e MT |
152 | return 0; |
153 | } | |
154 | ||
155 | sub sizeformat{ | |
156 | my $bytesize = shift; | |
157 | my $i = 0; | |
158 | ||
159 | while(abs($bytesize) >= 1024){ | |
160 | $bytesize=$bytesize/1024; | |
161 | $i++; | |
162 | last if($i==6); | |
163 | } | |
164 | ||
165 | my @units = ("Bytes","KB","MB","GB","TB","PB","EB"); | |
166 | my $newsize=(int($bytesize*100 +0.5))/100; | |
167 | return("$newsize $units[$i]"); | |
168 | } | |
169 | ||
c6c9630e MT |
170 | sub cleanssldatabase |
171 | { | |
172 | if (open(FILE, ">${General::swroot}/ovpn/certs/serial")) { | |
173 | print FILE "01"; | |
174 | close FILE; | |
175 | } | |
176 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt")) { | |
177 | print FILE ""; | |
178 | close FILE; | |
179 | } | |
e6f7f8e7 EK |
180 | if (open(FILE, ">${General::swroot}/ovpn/certs/index.txt.attr")) { |
181 | print FILE ""; | |
182 | close FILE; | |
183 | } | |
c6c9630e | 184 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); |
e6f7f8e7 | 185 | unlink ("${General::swroot}/ovpn/certs/index.txt.attr.old"); |
c6c9630e MT |
186 | unlink ("${General::swroot}/ovpn/certs/serial.old"); |
187 | unlink ("${General::swroot}/ovpn/certs/01.pem"); | |
188 | } | |
189 | ||
190 | sub newcleanssldatabase | |
191 | { | |
192 | if (! -s "${General::swroot}/ovpn/certs/serial" ) { | |
193 | open(FILE, ">${General::swroot}(ovpn/certs/serial"); | |
194 | print FILE "01"; | |
195 | close FILE; | |
196 | } | |
197 | if (! -s ">${General::swroot}/ovpn/certs/index.txt") { | |
2feacd98 | 198 | &General::system("touch", "${General::swroot}/ovpn/certs/index.txt"); |
c6c9630e | 199 | } |
e6f7f8e7 | 200 | if (! -s ">${General::swroot}/ovpn/certs/index.txt.attr") { |
2feacd98 | 201 | &General::system("touch", "${General::swroot}/ovpn/certs/index.txt.attr"); |
e6f7f8e7 | 202 | } |
c6c9630e | 203 | unlink ("${General::swroot}/ovpn/certs/index.txt.old"); |
e6f7f8e7 | 204 | unlink ("${General::swroot}/ovpn/certs/index.txt.attr.old"); |
c6c9630e MT |
205 | unlink ("${General::swroot}/ovpn/certs/serial.old"); |
206 | } | |
207 | ||
208 | sub deletebackupcert | |
209 | { | |
210 | if (open(FILE, "${General::swroot}/ovpn/certs/serial.old")) { | |
211 | my $hexvalue = <FILE>; | |
212 | chomp $hexvalue; | |
213 | close FILE; | |
214 | unlink ("${General::swroot}/ovpn/certs/$hexvalue.pem"); | |
215 | } | |
216 | } | |
4c962356 | 217 | |
400c8afd EK |
218 | ### |
219 | ### Check for PKI and configure problems | |
220 | ### | |
221 | ||
222 | sub pkiconfigcheck | |
223 | { | |
400c8afd EK |
224 | # Warning if md5 is in usage |
225 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
2feacd98 SS |
226 | my @signature = &General::system_output("/usr/bin/openssl", "x509", "-noout", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
227 | if (grep(/md5WithRSAEncryption/, @signature) ) { | |
400c8afd EK |
228 | $cryptoerror = "$Lang::tr{'ovpn error md5'}"; |
229 | goto CRYPTO_ERROR; | |
230 | } | |
231 | } | |
232 | ||
233 | CRYPTO_ERROR: | |
234 | ||
235 | # Warning if certificate is not compliant to RFC3280 TLS rules | |
236 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
2feacd98 SS |
237 | my @extendkeyusage = &General::system_output("/usr/bin/openssl", "x509", "-noout", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
238 | if ( ! grep(/TLS Web Server Authentication/, @extendkeyusage)) { | |
400c8afd EK |
239 | $cryptowarning = "$Lang::tr{'ovpn warning rfc3280'}"; |
240 | goto CRYPTO_WARNING; | |
241 | } | |
242 | } | |
243 | ||
244 | CRYPTO_WARNING: | |
245 | } | |
246 | ||
c6c9630e | 247 | sub writeserverconf { |
66c36198 PM |
248 | my %sovpnsettings = (); |
249 | my @temp = (); | |
c6c9630e | 250 | &General::readhash("${General::swroot}/ovpn/settings", \%sovpnsettings); |
54fd0535 | 251 | &read_routepushfile; |
66c36198 | 252 | |
c6c9630e MT |
253 | open(CONF, ">${General::swroot}/ovpn/server.conf") or die "Unable to open ${General::swroot}/ovpn/server.conf: $!"; |
254 | flock CONF, 2; | |
255 | print CONF "#OpenVPN Server conf\n"; | |
256 | print CONF "\n"; | |
257 | print CONF "daemon openvpnserver\n"; | |
258 | print CONF "writepid /var/run/openvpn.pid\n"; | |
afabe9f7 | 259 | print CONF "#DAN prepare OpenVPN for listening on blue and orange\n"; |
c6c9630e | 260 | print CONF ";local $sovpnsettings{'VPN_IP'}\n"; |
79e7688b | 261 | print CONF "dev tun\n"; |
c6c9630e MT |
262 | print CONF "proto $sovpnsettings{'DPROTOCOL'}\n"; |
263 | print CONF "port $sovpnsettings{'DDEST_PORT'}\n"; | |
a4fd2325 | 264 | print CONF "script-security 3\n"; |
07675dc3 | 265 | print CONF "ifconfig-pool-persist /var/ipfire/ovpn/ovpn-leases.db 3600\n"; |
6140e7e0 | 266 | print CONF "client-config-dir /var/ipfire/ovpn/ccd\n"; |
c6c9630e | 267 | print CONF "tls-server\n"; |
4c962356 EK |
268 | print CONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; |
269 | print CONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
270 | print CONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
35494eac | 271 | print CONF "dh $dhparameter\n"; |
c6c9630e MT |
272 | my @tempovpnsubnet = split("\/",$sovpnsettings{'DOVPN_SUBNET'}); |
273 | print CONF "server $tempovpnsubnet[0] $tempovpnsubnet[1]\n"; | |
8c877a82 | 274 | #print CONF "push \"route $netsettings{'GREEN_NETADDRESS'} $netsettings{'GREEN_NETMASK'}\"\n"; |
4c962356 | 275 | |
d6989b4b | 276 | print CONF "tun-mtu $sovpnsettings{'DMTU'}\n"; |
2ee746be | 277 | |
54fd0535 | 278 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { |
8c877a82 AM |
279 | @temp = split(/\n/,$vpnsettings{'ROUTES_PUSH'}); |
280 | foreach (@temp) | |
281 | { | |
282 | @tempovpnsubnet = split("\/",&General::ipcidr2msk($_)); | |
283 | print CONF "push \"route " . $tempovpnsubnet[0]. " " . $tempovpnsubnet[1] . "\"\n"; | |
284 | } | |
54fd0535 | 285 | } |
8c877a82 AM |
286 | # a.marx ccd |
287 | my %ccdconfhash=(); | |
288 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
289 | foreach my $key (keys %ccdconfhash) { | |
290 | my $a=$ccdconfhash{$key}[1]; | |
291 | my ($b,$c) = split (/\//, $a); | |
292 | print CONF "route $b ".&General::cidrtosub($c)."\n"; | |
293 | } | |
294 | my %ccdroutehash=(); | |
295 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
296 | foreach my $key (keys %ccdroutehash) { | |
297 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
298 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
299 | print CONF "route $a $b\n"; | |
300 | } | |
301 | } | |
302 | # ccd end | |
54fd0535 | 303 | |
8c877a82 | 304 | if ($sovpnsettings{CLIENT2CLIENT} eq 'on') { |
c6c9630e MT |
305 | print CONF "client-to-client\n"; |
306 | } | |
1de5c945 | 307 | if ($sovpnsettings{MSSFIX} eq 'on') { |
4c962356 | 308 | print CONF "mssfix\n"; |
d6989b4b MT |
309 | } else { |
310 | print CONF "mssfix 0\n"; | |
1de5c945 EK |
311 | } |
312 | if ($sovpnsettings{FRAGMENT} ne '' && $sovpnsettings{'DPROTOCOL'} ne 'tcp') { | |
4c962356 | 313 | print CONF "fragment $sovpnsettings{'FRAGMENT'}\n"; |
a79fa1d6 | 314 | } |
2ee746be | 315 | |
66c36198 | 316 | if ($sovpnsettings{KEEPALIVE_1} > 0 && $sovpnsettings{KEEPALIVE_2} > 0) { |
c6c9630e | 317 | print CONF "keepalive $sovpnsettings{'KEEPALIVE_1'} $sovpnsettings{'KEEPALIVE_2'}\n"; |
66c36198 | 318 | } |
c6c9630e | 319 | print CONF "status-version 1\n"; |
87fe47e9 | 320 | print CONF "status /var/run/ovpnserver.log 30\n"; |
a4fd2325 | 321 | print CONF "ncp-disable\n"; |
c6c9630e | 322 | print CONF "cipher $sovpnsettings{DCIPHER}\n"; |
49abe7af | 323 | print CONF "auth $sovpnsettings{'DAUTH'}\n"; |
942446b5 EK |
324 | # Set TLSv2 as minimum |
325 | print CONF "tls-version-min 1.2\n"; | |
86308adb | 326 | |
49abe7af | 327 | if ($sovpnsettings{'TLSAUTH'} eq 'on') { |
4be45949 | 328 | print CONF "tls-auth ${General::swroot}/ovpn/certs/ta.key\n"; |
49abe7af | 329 | } |
c6c9630e MT |
330 | if ($sovpnsettings{DCOMPLZO} eq 'on') { |
331 | print CONF "comp-lzo\n"; | |
332 | } | |
333 | if ($sovpnsettings{REDIRECT_GW_DEF1} eq 'on') { | |
334 | print CONF "push \"redirect-gateway def1\"\n"; | |
335 | } | |
336 | if ($sovpnsettings{DHCP_DOMAIN} ne '') { | |
337 | print CONF "push \"dhcp-option DOMAIN $sovpnsettings{DHCP_DOMAIN}\"\n"; | |
338 | } | |
339 | ||
340 | if ($sovpnsettings{DHCP_DNS} ne '') { | |
341 | print CONF "push \"dhcp-option DNS $sovpnsettings{DHCP_DNS}\"\n"; | |
342 | } | |
343 | ||
344 | if ($sovpnsettings{DHCP_WINS} ne '') { | |
345 | print CONF "push \"dhcp-option WINS $sovpnsettings{DHCP_WINS}\"\n"; | |
346 | } | |
66c36198 | 347 | |
fa527476 | 348 | if ($sovpnsettings{MAX_CLIENTS} eq '') { |
c6c9630e | 349 | print CONF "max-clients 100\n"; |
a79fa1d6 | 350 | } |
fa527476 | 351 | if ($sovpnsettings{MAX_CLIENTS} ne '') { |
c6c9630e | 352 | print CONF "max-clients $sovpnsettings{MAX_CLIENTS}\n"; |
66c36198 | 353 | } |
1d0a260a | 354 | print CONF "tls-verify /usr/lib/openvpn/verify\n"; |
c6c9630e | 355 | print CONF "crl-verify /var/ipfire/ovpn/crls/cacrl.pem\n"; |
e1e10515 TE |
356 | print CONF "auth-user-pass-optional\n"; |
357 | print CONF "reneg-sec 86400\n"; | |
c6c9630e MT |
358 | print CONF "user nobody\n"; |
359 | print CONF "group nobody\n"; | |
360 | print CONF "persist-key\n"; | |
361 | print CONF "persist-tun\n"; | |
362 | if ($sovpnsettings{LOG_VERB} ne '') { | |
363 | print CONF "verb $sovpnsettings{LOG_VERB}\n"; | |
364 | } else { | |
365 | print CONF "verb 3\n"; | |
ffbe77c8 | 366 | } |
708f2b73 MT |
367 | |
368 | print CONF "# Log clients connecting/disconnecting\n"; | |
369 | print CONF "client-connect \"/usr/sbin/openvpn-metrics client-connect\"\n"; | |
370 | print CONF "client-disconnect \"/usr/sbin/openvpn-metrics client-disconnect\"\n"; | |
5111dc3d MT |
371 | print CONF "\n"; |
372 | ||
373 | print CONF "# Enable Management Socket\n"; | |
374 | print CONF "management /var/run/openvpn.sock unix\n"; | |
375 | print CONF "management-client-auth\n"; | |
708f2b73 | 376 | |
ffbe77c8 EK |
377 | # Print server.conf.local if entries exist to server.conf |
378 | if ( !-z $local_serverconf && $sovpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
379 | open (LSC, "$local_serverconf"); | |
380 | print CONF "\n#---------------------------\n"; | |
381 | print CONF "# Start of custom directives\n"; | |
382 | print CONF "# from server.conf.local\n"; | |
383 | print CONF "#---------------------------\n\n"; | |
384 | while (<LSC>) { | |
385 | print CONF $_; | |
386 | } | |
387 | print CONF "\n#-----------------------------\n"; | |
388 | print CONF "# End of custom directives\n"; | |
389 | print CONF "#-----------------------------\n"; | |
390 | close (LSC); | |
391 | } | |
c6c9630e | 392 | print CONF "\n"; |
66c36198 | 393 | |
c6c9630e | 394 | close(CONF); |
66c36198 | 395 | } |
8c877a82 | 396 | |
c6c9630e | 397 | sub emptyserverlog{ |
87fe47e9 | 398 | if (open(FILE, ">/var/run/ovpnserver.log")) { |
c6c9630e MT |
399 | flock FILE, 2; |
400 | print FILE ""; | |
401 | close FILE; | |
402 | } | |
403 | ||
404 | } | |
405 | ||
66c36198 | 406 | sub delccdnet |
8c877a82 AM |
407 | { |
408 | my %ccdconfhash = (); | |
409 | my %ccdhash = (); | |
410 | my $ccdnetname=$_[0]; | |
411 | if (-f "${General::swroot}/ovpn/ovpnconfig"){ | |
412 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
413 | foreach my $key (keys %ccdhash) { | |
414 | if ($ccdhash{$key}[32] eq $ccdnetname) { | |
415 | $errormessage=$Lang::tr{'ccd err hostinnet'}; | |
416 | return; | |
417 | } | |
418 | } | |
419 | } | |
420 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
421 | foreach my $key (keys %ccdconfhash) { | |
422 | if ($ccdconfhash{$key}[0] eq $ccdnetname){ | |
423 | delete $ccdconfhash{$key}; | |
424 | } | |
425 | } | |
426 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
66c36198 | 427 | |
8c877a82 AM |
428 | &writeserverconf; |
429 | return 0; | |
430 | } | |
431 | ||
432 | sub addccdnet | |
433 | { | |
434 | my %ccdconfhash=(); | |
435 | my @ccdconf=(); | |
436 | my $ccdname=$_[0]; | |
437 | my $ccdnet=$_[1]; | |
8c877a82 AM |
438 | my $subcidr; |
439 | my @ip2=(); | |
440 | my $checkup; | |
441 | my $ccdip; | |
442 | my $baseaddress; | |
66c36198 PM |
443 | |
444 | ||
445 | #check name | |
446 | if ($ccdname eq '') | |
290007b3 AM |
447 | { |
448 | $errormessage=$errormessage.$Lang::tr{'ccd err name'}."<br>"; | |
449 | return | |
450 | } | |
66c36198 | 451 | |
dcc2f7e0 | 452 | if(!&General::validccdname($ccdname)) |
290007b3 | 453 | { |
8c877a82 AM |
454 | $errormessage=$Lang::tr{'ccd err invalidname'}; |
455 | return; | |
456 | } | |
66c36198 | 457 | |
290007b3 AM |
458 | ($ccdip,$subcidr) = split (/\//,$ccdnet); |
459 | $subcidr=&General::iporsubtocidr($subcidr); | |
460 | #check subnet | |
461 | if ($subcidr > 30) | |
462 | { | |
8c877a82 AM |
463 | $errormessage=$Lang::tr{'ccd err invalidnet'}; |
464 | return; | |
465 | } | |
290007b3 AM |
466 | #check ip |
467 | if (!&General::validipandmask($ccdnet)){ | |
468 | $errormessage=$Lang::tr{'ccd err invalidnet'}; | |
469 | return; | |
8c877a82 | 470 | } |
b6c60092 | 471 | |
8c877a82 AM |
472 | if (!$errormessage) { |
473 | my %ccdconfhash=(); | |
474 | $baseaddress=&General::getnetworkip($ccdip,$subcidr); | |
475 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
476 | my $key = &General::findhasharraykey (\%ccdconfhash); | |
477 | foreach my $i (0 .. 1) { $ccdconfhash{$key}[$i] = "";} | |
478 | $ccdconfhash{$key}[0] = $ccdname; | |
479 | $ccdconfhash{$key}[1] = $baseaddress."/".$subcidr; | |
480 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
481 | &writeserverconf; | |
482 | $cgiparams{'ccdname'}=''; | |
483 | $cgiparams{'ccdsubnet'}=''; | |
484 | return 1; | |
485 | } | |
486 | } | |
487 | ||
488 | sub modccdnet | |
489 | { | |
66c36198 | 490 | |
8c877a82 AM |
491 | my $newname=$_[0]; |
492 | my $oldname=$_[1]; | |
493 | my %ccdconfhash=(); | |
494 | my %ccdhash=(); | |
7ad653cc SS |
495 | |
496 | # Check if the new name is valid. | |
497 | if(!&General::validhostname($newname)) { | |
498 | $errormessage=$Lang::tr{'ccd err invalidname'}; | |
499 | return; | |
500 | } | |
501 | ||
8c877a82 AM |
502 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); |
503 | foreach my $key (keys %ccdconfhash) { | |
504 | if ($ccdconfhash{$key}[0] eq $oldname) { | |
505 | foreach my $key1 (keys %ccdconfhash) { | |
506 | if ($ccdconfhash{$key1}[0] eq $newname){ | |
507 | $errormessage=$errormessage.$Lang::tr{'ccd err netadrexist'}; | |
508 | return; | |
509 | }else{ | |
510 | $ccdconfhash{$key}[0]= $newname; | |
511 | &General::writehasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
512 | last; | |
513 | } | |
514 | } | |
515 | } | |
516 | } | |
66c36198 | 517 | |
8c877a82 AM |
518 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); |
519 | foreach my $key (keys %ccdhash) { | |
520 | if ($ccdhash{$key}[32] eq $oldname) { | |
521 | $ccdhash{$key}[32]=$newname; | |
522 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
523 | last; | |
524 | } | |
525 | } | |
66c36198 | 526 | |
8c877a82 AM |
527 | return 0; |
528 | } | |
529 | sub ccdmaxclients | |
530 | { | |
531 | my $ccdnetwork=$_[0]; | |
532 | my @octets=(); | |
533 | my @subnet=(); | |
534 | @octets=split("\/",$ccdnetwork); | |
535 | @subnet= split /\./, &General::cidrtosub($octets[1]); | |
536 | my ($a,$b,$c,$d,$e); | |
537 | $a=256-$subnet[0]; | |
538 | $b=256-$subnet[1]; | |
539 | $c=256-$subnet[2]; | |
540 | $d=256-$subnet[3]; | |
541 | $e=($a*$b*$c*$d)/4; | |
542 | return $e-1; | |
543 | } | |
544 | ||
66c36198 | 545 | sub getccdadresses |
8c877a82 AM |
546 | { |
547 | my $ipin=$_[0]; | |
548 | my ($ip1,$ip2,$ip3,$ip4)=split /\./, $ipin; | |
549 | my $cidr=$_[1]; | |
550 | chomp($cidr); | |
551 | my $count=$_[2]; | |
552 | my $hasip=$_[3]; | |
553 | chomp($hasip); | |
554 | my @iprange=(); | |
555 | my %ccdhash=(); | |
556 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
d9fe5693 | 557 | $iprange[0]=$ip1.".".$ip2.".".$ip3.".".($ip4+2); |
ac87f371 | 558 | for (my $i=1;$i<=$count;$i++) { |
8c877a82 AM |
559 | my $tmpip=$iprange[$i-1]; |
560 | my $stepper=$i*4; | |
561 | $iprange[$i]= &General::getnextip($tmpip,4); | |
562 | } | |
563 | my $r=0; | |
564 | foreach my $key (keys %ccdhash) { | |
565 | $r=0; | |
566 | foreach my $tmp (@iprange){ | |
567 | my ($net,$sub) = split (/\//,$ccdhash{$key}[33]); | |
568 | if ($net eq $tmp) { | |
569 | if ( $hasip ne $ccdhash{$key}[33] ){ | |
570 | splice (@iprange,$r,1); | |
571 | } | |
572 | } | |
573 | $r++; | |
574 | } | |
575 | } | |
576 | return @iprange; | |
577 | } | |
578 | ||
579 | sub fillselectbox | |
580 | { | |
581 | my $boxname=$_[1]; | |
66c36198 | 582 | my ($ccdip,$subcidr) = split("/",$_[0]); |
8c877a82 AM |
583 | my $tz=$_[2]; |
584 | my @allccdips=&getccdadresses($ccdip,$subcidr,&ccdmaxclients($ccdip."/".$subcidr),$tz); | |
585 | print"<select name='$boxname' STYLE='font-family : arial; font-size : 9pt; width:130px;' >"; | |
586 | foreach (@allccdips) { | |
587 | my $ip=$_."/30"; | |
588 | chomp($ip); | |
589 | print "<option value='$ip' "; | |
590 | if ( $ip eq $cgiparams{$boxname} ){ | |
591 | print"selected"; | |
592 | } | |
593 | print ">$ip</option>"; | |
594 | } | |
595 | print "</select>"; | |
596 | } | |
597 | ||
598 | sub hostsinnet | |
599 | { | |
600 | my $name=$_[0]; | |
601 | my %ccdhash=(); | |
602 | my $i=0; | |
603 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
604 | foreach my $key (keys %ccdhash) { | |
605 | if ($ccdhash{$key}[32] eq $name){ $i++;} | |
606 | } | |
607 | return $i; | |
608 | } | |
609 | ||
610 | sub check_routes_push | |
611 | { | |
612 | my $val=$_[0]; | |
613 | my ($ip,$cidr) = split (/\//, $val); | |
614 | ##check for existing routes in routes_push | |
615 | if (-e "${General::swroot}/ovpn/routes_push") { | |
616 | open(FILE,"${General::swroot}/ovpn/routes_push"); | |
617 | while (<FILE>) { | |
618 | $_=~s/\s*$//g; | |
66c36198 | 619 | |
8c877a82 AM |
620 | my ($ip2,$cidr2) = split (/\//,"$_"); |
621 | my $val2=$ip2."/".&General::iporsubtodec($cidr2); | |
66c36198 | 622 | |
8c877a82 AM |
623 | if($val eq $val2){ |
624 | return 0; | |
625 | } | |
626 | #subnetcheck | |
627 | if (&General::IpInSubnet ($ip,$ip2,&General::iporsubtodec($cidr2))){ | |
628 | return 0; | |
629 | } | |
630 | }; | |
631 | close(FILE); | |
632 | } | |
633 | return 1; | |
634 | } | |
635 | ||
636 | sub check_ccdroute | |
637 | { | |
638 | my %ccdroutehash=(); | |
639 | my $val=$_[0]; | |
640 | my ($ip,$cidr) = split (/\//, $val); | |
641 | #check for existing routes in ccdroute | |
642 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
643 | foreach my $key (keys %ccdroutehash) { | |
644 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
645 | if (&General::iporsubtodec($val) eq $ccdroutehash{$key}[$i] && $ccdroutehash{$key}[0] ne $cgiparams{'NAME'}){ | |
646 | return 0; | |
647 | } | |
648 | my ($ip2,$cidr2) = split (/\//,$ccdroutehash{$key}[$i]); | |
649 | #subnetcheck | |
650 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)&& $ccdroutehash{$key}[0] ne $cgiparams{'NAME'} ){ | |
651 | return 0; | |
652 | } | |
653 | } | |
654 | } | |
655 | return 1; | |
656 | } | |
657 | sub check_ccdconf | |
658 | { | |
659 | my %ccdconfhash=(); | |
660 | my $val=$_[0]; | |
661 | my ($ip,$cidr) = split (/\//, $val); | |
662 | #check for existing routes in ccdroute | |
663 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
664 | foreach my $key (keys %ccdconfhash) { | |
665 | if (&General::iporsubtocidr($val) eq $ccdconfhash{$key}[1]){ | |
666 | return 0; | |
667 | } | |
668 | my ($ip2,$cidr2) = split (/\//,$ccdconfhash{$key}[1]); | |
669 | #subnetcheck | |
670 | if (&General::IpInSubnet ($ip,$ip2,&General::cidrtosub($cidr2))){ | |
671 | return 0; | |
672 | } | |
66c36198 | 673 | |
8c877a82 AM |
674 | } |
675 | return 1; | |
676 | } | |
677 | ||
7c1d9faf AH |
678 | ### |
679 | # m.a.d net2net | |
680 | ### | |
681 | ||
682 | sub validdotmask | |
683 | { | |
684 | my $ipdotmask = $_[0]; | |
685 | if (&General::validip($ipdotmask)) { return 0; } | |
686 | if (!($ipdotmask =~ /^(.*?)\/(.*?)$/)) { } | |
687 | my $mask = $2; | |
66c36198 | 688 | if (($mask =~ /\./ )) { return 0; } |
7c1d9faf AH |
689 | return 1; |
690 | } | |
54fd0535 MT |
691 | |
692 | # ------------------------------------------------------------------- | |
693 | ||
694 | sub write_routepushfile | |
695 | { | |
696 | open(FILE, ">$routes_push_file"); | |
697 | flock(FILE, 2); | |
698 | if ($vpnsettings{'ROUTES_PUSH'} ne '') { | |
699 | print FILE $vpnsettings{'ROUTES_PUSH'}; | |
700 | } | |
66c36198 | 701 | close(FILE); |
54fd0535 MT |
702 | } |
703 | ||
704 | sub read_routepushfile | |
705 | { | |
706 | if (-e "$routes_push_file") { | |
707 | open(FILE,"$routes_push_file"); | |
708 | delete $vpnsettings{'ROUTES_PUSH'}; | |
709 | while (<FILE>) { $vpnsettings{'ROUTES_PUSH'} .= $_ }; | |
710 | close(FILE); | |
711 | $cgiparams{'ROUTES_PUSH'} = $vpnsettings{'ROUTES_PUSH'}; | |
66c36198 | 712 | |
54fd0535 MT |
713 | } |
714 | } | |
7c1d9faf | 715 | |
775b4494 AM |
716 | sub writecollectdconf { |
717 | my $vpncollectd; | |
718 | my %ccdhash=(); | |
719 | ||
720 | open(COLLECTDVPN, ">${General::swroot}/ovpn/collectd.vpn") or die "Unable to open collectd.vpn: $!"; | |
721 | print COLLECTDVPN "Loadplugin openvpn\n"; | |
722 | print COLLECTDVPN "\n"; | |
723 | print COLLECTDVPN "<Plugin openvpn>\n"; | |
724 | print COLLECTDVPN "Statusfile \"/var/run/ovpnserver.log\"\n"; | |
725 | ||
726 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%ccdhash); | |
727 | foreach my $key (keys %ccdhash) { | |
728 | if ($ccdhash{$key}[0] eq 'on' && $ccdhash{$key}[3] eq 'net') { | |
729 | print COLLECTDVPN "Statusfile \"/var/run/openvpn/$ccdhash{$key}[1]-n2n\"\n"; | |
730 | } | |
731 | } | |
732 | ||
733 | print COLLECTDVPN "</Plugin>\n"; | |
734 | close(COLLECTDVPN); | |
735 | ||
736 | # Reload collectd afterwards | |
2feacd98 | 737 | &General::system("/usr/local/bin/collectdctrl", "restart"); |
775b4494 | 738 | } |
7c1d9faf | 739 | |
c6c9630e MT |
740 | #hier die refresh page |
741 | if ( -e "${General::swroot}/ovpn/gencanow") { | |
742 | my $refresh = ''; | |
743 | $refresh = "<meta http-equiv='refresh' content='15;' />"; | |
744 | &Header::showhttpheaders(); | |
745 | &Header::openpage($Lang::tr{'OVPN'}, 1, $refresh); | |
746 | &Header::openbigbox('100%', 'center'); | |
747 | &Header::openbox('100%', 'left', "$Lang::tr{'generate root/host certificates'}:"); | |
748 | print "<tr>\n<td align='center'><img src='/images/clock.gif' alt='' /></td>\n"; | |
749 | print "<td colspan='2'><font color='red'>Please be patient this realy can take some time on older hardware...</font></td></tr>\n"; | |
750 | &Header::closebox(); | |
751 | &Header::closebigbox(); | |
752 | &Header::closepage(); | |
753 | exit (0); | |
754 | } | |
755 | ##hier die refresh page | |
756 | ||
6e13d0a5 MT |
757 | |
758 | ### | |
759 | ### OpenVPN Server Control | |
760 | ### | |
761 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'} || | |
762 | $cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'} || | |
763 | $cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}) { | |
6e13d0a5 MT |
764 | #start openvpn server |
765 | if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}){ | |
c6c9630e | 766 | &emptyserverlog(); |
2feacd98 | 767 | &General::system("/usr/local/bin/openvpnctrl", "-s"); |
66c36198 | 768 | } |
6e13d0a5 MT |
769 | #stop openvpn server |
770 | if ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}){ | |
2feacd98 | 771 | &General::system("/usr/local/bin/openvpnctrl", "-k"); |
66c36198 PM |
772 | &emptyserverlog(); |
773 | } | |
6e13d0a5 | 774 | # #restart openvpn server |
8c877a82 | 775 | # if ($cgiparams{'ACTION'} eq $Lang::tr{'restart ovpn server'}){ |
66c36198 PM |
776 | #workarund, till SIGHUP also works when running as nobody |
777 | # system('/usr/local/bin/openvpnctrl', '-r'); | |
778 | # &emptyserverlog(); | |
779 | # } | |
6e13d0a5 MT |
780 | } |
781 | ||
782 | ### | |
783 | ### Save Advanced options | |
784 | ### | |
785 | ||
786 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save-adv-options'}) { | |
787 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
788 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, | |
789 | #DAN this value has to leave. | |
790 | #new settings for daemon | |
791 | $vpnsettings{'LOG_VERB'} = $cgiparams{'LOG_VERB'}; | |
792 | $vpnsettings{'KEEPALIVE_1'} = $cgiparams{'KEEPALIVE_1'}; | |
793 | $vpnsettings{'KEEPALIVE_2'} = $cgiparams{'KEEPALIVE_2'}; | |
794 | $vpnsettings{'MAX_CLIENTS'} = $cgiparams{'MAX_CLIENTS'}; | |
795 | $vpnsettings{'REDIRECT_GW_DEF1'} = $cgiparams{'REDIRECT_GW_DEF1'}; | |
796 | $vpnsettings{'CLIENT2CLIENT'} = $cgiparams{'CLIENT2CLIENT'}; | |
6a9d9ff4 | 797 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; |
ffbe77c8 | 798 | $vpnsettings{'ADDITIONAL_CONFIGS'} = $cgiparams{'ADDITIONAL_CONFIGS'}; |
6e13d0a5 MT |
799 | $vpnsettings{'DHCP_DOMAIN'} = $cgiparams{'DHCP_DOMAIN'}; |
800 | $vpnsettings{'DHCP_DNS'} = $cgiparams{'DHCP_DNS'}; | |
801 | $vpnsettings{'DHCP_WINS'} = $cgiparams{'DHCP_WINS'}; | |
54fd0535 MT |
802 | $vpnsettings{'ROUTES_PUSH'} = $cgiparams{'ROUTES_PUSH'}; |
803 | my @temp=(); | |
66c36198 | 804 | |
a79fa1d6 JPT |
805 | if ($cgiparams{'FRAGMENT'} eq '') { |
806 | delete $vpnsettings{'FRAGMENT'}; | |
807 | } else { | |
66c36198 | 808 | if ($cgiparams{'FRAGMENT'} !~ /^[0-9]+$/) { |
a79fa1d6 JPT |
809 | $errormessage = "Incorrect value, please insert only numbers."; |
810 | goto ADV_ERROR; | |
811 | } else { | |
812 | $vpnsettings{'FRAGMENT'} = $cgiparams{'FRAGMENT'}; | |
813 | } | |
814 | } | |
49abe7af | 815 | |
a79fa1d6 | 816 | if ($cgiparams{'MSSFIX'} ne 'on') { |
1de5c945 | 817 | delete $vpnsettings{'MSSFIX'}; |
a79fa1d6 JPT |
818 | } else { |
819 | $vpnsettings{'MSSFIX'} = $cgiparams{'MSSFIX'}; | |
820 | } | |
2ee746be | 821 | |
6e13d0a5 | 822 | if ($cgiparams{'DHCP_DOMAIN'} ne ''){ |
81da1b01 | 823 | unless (&General::validdomainname($cgiparams{'DHCP_DOMAIN'}) || &General::validip($cgiparams{'DHCP_DOMAIN'})) { |
6e13d0a5 MT |
824 | $errormessage = $Lang::tr{'invalid input for dhcp domain'}; |
825 | goto ADV_ERROR; | |
826 | } | |
827 | } | |
828 | if ($cgiparams{'DHCP_DNS'} ne ''){ | |
829 | unless (&General::validfqdn($cgiparams{'DHCP_DNS'}) || &General::validip($cgiparams{'DHCP_DNS'})) { | |
830 | $errormessage = $Lang::tr{'invalid input for dhcp dns'}; | |
831 | goto ADV_ERROR; | |
832 | } | |
833 | } | |
834 | if ($cgiparams{'DHCP_WINS'} ne ''){ | |
835 | unless (&General::validfqdn($cgiparams{'DHCP_WINS'}) || &General::validip($cgiparams{'DHCP_WINS'})) { | |
836 | $errormessage = $Lang::tr{'invalid input for dhcp wins'}; | |
54fd0535 MT |
837 | goto ADV_ERROR; |
838 | } | |
839 | } | |
840 | if ($cgiparams{'ROUTES_PUSH'} ne ''){ | |
841 | @temp = split(/\n/,$cgiparams{'ROUTES_PUSH'}); | |
842 | undef $vpnsettings{'ROUTES_PUSH'}; | |
66c36198 | 843 | |
8c877a82 | 844 | foreach my $tmpip (@temp) |
54fd0535 MT |
845 | { |
846 | s/^\s+//g; s/\s+$//g; | |
66c36198 | 847 | |
8c877a82 | 848 | if ($tmpip) |
54fd0535 | 849 | { |
66c36198 | 850 | $tmpip=~s/\s*$//g; |
8c877a82 AM |
851 | unless (&General::validipandmask($tmpip)) { |
852 | $errormessage = "$tmpip ".$Lang::tr{'ovpn errmsg invalid ip or mask'}; | |
853 | goto ADV_ERROR; | |
54fd0535 | 854 | } |
8c877a82 | 855 | my ($ip, $cidr) = split("\/",&General::ipcidr2msk($tmpip)); |
66c36198 | 856 | |
54fd0535 MT |
857 | if ($ip eq $netsettings{'GREEN_NETADDRESS'} && $cidr eq $netsettings{'GREEN_NETMASK'}) { |
858 | $errormessage = $Lang::tr{'ovpn errmsg green already pushed'}; | |
8c877a82 AM |
859 | goto ADV_ERROR; |
860 | } | |
66c36198 | 861 | # a.marx ccd |
8c877a82 AM |
862 | my %ccdroutehash=(); |
863 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
864 | foreach my $key (keys %ccdroutehash) { | |
66c36198 | 865 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { |
8c877a82 AM |
866 | if ( $ip."/".$cidr eq $ccdroutehash{$key}[$i] ){ |
867 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
868 | goto ADV_ERROR; | |
869 | } | |
870 | my ($ip2,$cidr2) = split(/\//,$ccdroutehash{$key}[$i]); | |
871 | if (&General::IpInSubnet ($ip,$ip2,$cidr2)){ | |
872 | $errormessage="Route $ip\/$cidr ".$Lang::tr{'ccd err inuse'}." $ccdroutehash{$key}[0]" ; | |
873 | goto ADV_ERROR; | |
874 | } | |
875 | } | |
54fd0535 | 876 | } |
66c36198 | 877 | |
8c877a82 | 878 | # ccd end |
66c36198 | 879 | |
8c877a82 | 880 | $vpnsettings{'ROUTES_PUSH'} .= $tmpip."\n"; |
54fd0535 | 881 | } |
8c877a82 AM |
882 | } |
883 | &write_routepushfile; | |
54fd0535 | 884 | undef $vpnsettings{'ROUTES_PUSH'}; |
8e148dc3 NP |
885 | } |
886 | else { | |
887 | undef $vpnsettings{'ROUTES_PUSH'}; | |
888 | &write_routepushfile; | |
6e13d0a5 | 889 | } |
ba50f66d | 890 | if ((length($cgiparams{'MAX_CLIENTS'}) == 0) || (($cgiparams{'MAX_CLIENTS'}) < 1 ) || (($cgiparams{'MAX_CLIENTS'}) > 1024 )) { |
6e13d0a5 MT |
891 | $errormessage = $Lang::tr{'invalid input for max clients'}; |
892 | goto ADV_ERROR; | |
893 | } | |
894 | if ($cgiparams{'KEEPALIVE_1'} ne '') { | |
66c36198 | 895 | if ($cgiparams{'KEEPALIVE_1'} !~ /^[0-9]+$/) { |
6e13d0a5 MT |
896 | $errormessage = $Lang::tr{'invalid input for keepalive 1'}; |
897 | goto ADV_ERROR; | |
898 | } | |
899 | } | |
900 | if ($cgiparams{'KEEPALIVE_2'} ne ''){ | |
66c36198 | 901 | if ($cgiparams{'KEEPALIVE_2'} !~ /^[0-9]+$/) { |
6e13d0a5 MT |
902 | $errormessage = $Lang::tr{'invalid input for keepalive 2'}; |
903 | goto ADV_ERROR; | |
904 | } | |
905 | } | |
906 | if ($cgiparams{'KEEPALIVE_2'} < ($cgiparams{'KEEPALIVE_1'} * 2)){ | |
907 | $errormessage = $Lang::tr{'invalid input for keepalive 1:2'}; | |
66c36198 | 908 | goto ADV_ERROR; |
6e13d0a5 | 909 | } |
6e13d0a5 | 910 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); |
c6c9630e | 911 | &writeserverconf();#hier ok |
6e13d0a5 MT |
912 | } |
913 | ||
ce9abb66 | 914 | ### |
7c1d9faf | 915 | # m.a.d net2net |
ce9abb66 AH |
916 | ### |
917 | ||
918 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'server') | |
919 | { | |
c6c9630e | 920 | |
ce9abb66 AH |
921 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
922 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); | |
54fd0535 | 923 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
d96c89eb | 924 | my $tunmtu = ''; |
531f0835 AH |
925 | |
926 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} | |
66c36198 | 927 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} |
ce9abb66 AH |
928 | |
929 | 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: $!"; | |
66c36198 | 930 | |
ce9abb66 | 931 | flock SERVERCONF, 2; |
66c36198 PM |
932 | print SERVERCONF "# IPFire n2n Open VPN Server Config by ummeegge und m.a.d\n"; |
933 | print SERVERCONF "\n"; | |
b278daf3 | 934 | print SERVERCONF "# User Security\n"; |
ce9abb66 AH |
935 | print SERVERCONF "user nobody\n"; |
936 | print SERVERCONF "group nobody\n"; | |
937 | print SERVERCONF "persist-tun\n"; | |
938 | print SERVERCONF "persist-key\n"; | |
7c1d9faf | 939 | print SERVERCONF "script-security 2\n"; |
66c36198 | 940 | print SERVERCONF "# IP/DNS for remote Server Gateway\n"; |
c125d8a2 SS |
941 | |
942 | if ($cgiparams{'REMOTE'} ne '') { | |
ce9abb66 | 943 | print SERVERCONF "remote $cgiparams{'REMOTE'}\n"; |
c125d8a2 SS |
944 | } |
945 | ||
b278daf3 | 946 | print SERVERCONF "float\n"; |
66c36198 PM |
947 | print SERVERCONF "# IP adresses of the VPN Subnet\n"; |
948 | print SERVERCONF "ifconfig $ovsubnet.1 $ovsubnet.2\n"; | |
949 | print SERVERCONF "# Client Gateway Network\n"; | |
54fd0535 | 950 | print SERVERCONF "route $remsubnet[0] $remsubnet[1]\n"; |
2913185a | 951 | print SERVERCONF "up \"/etc/init.d/static-routes start\"\n"; |
66c36198 PM |
952 | print SERVERCONF "# tun Device\n"; |
953 | print SERVERCONF "dev tun\n"; | |
5795fc1b AM |
954 | print SERVERCONF "#Logfile for statistics\n"; |
955 | print SERVERCONF "status-version 1\n"; | |
87fe47e9 | 956 | print SERVERCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; |
66c36198 PM |
957 | print SERVERCONF "# Port and Protokol\n"; |
958 | print SERVERCONF "port $cgiparams{'DEST_PORT'}\n"; | |
5795fc1b | 959 | |
60f396d7 | 960 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { |
1580d3b1 | 961 | print SERVERCONF "proto tcp4-server\n"; |
60f396d7 | 962 | print SERVERCONF "# Packet size\n"; |
d96c89eb | 963 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 964 | print SERVERCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 965 | } |
66c36198 | 966 | |
60f396d7 | 967 | if ($cgiparams{'PROTOCOL'} eq 'udp') { |
1580d3b1 | 968 | print SERVERCONF "proto udp4\n"; |
60f396d7 AH |
969 | print SERVERCONF "# Paketsize\n"; |
970 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
971 | print SERVERCONF "tun-mtu $tunmtu\n"; | |
66c36198 | 972 | if ($cgiparams{'FRAGMENT'} ne '') {print SERVERCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
d6989b4b | 973 | if ($cgiparams{'MSSFIX'} eq 'on') {print SERVERCONF "mssfix\n"; } else { print SERVERCONF "mssfix 0\n" }; |
d96c89eb | 974 | } |
1647059d | 975 | |
66c36198 PM |
976 | print SERVERCONF "# Auth. Server\n"; |
977 | print SERVERCONF "tls-server\n"; | |
978 | print SERVERCONF "ca ${General::swroot}/ovpn/ca/cacert.pem\n"; | |
979 | print SERVERCONF "cert ${General::swroot}/ovpn/certs/servercert.pem\n"; | |
980 | print SERVERCONF "key ${General::swroot}/ovpn/certs/serverkey.pem\n"; | |
19a417c2 | 981 | print SERVERCONF "dh $dhparameter\n"; |
66c36198 | 982 | print SERVERCONF "# Cipher\n"; |
4c962356 | 983 | print SERVERCONF "cipher $cgiparams{'DCIPHER'}\n"; |
52f61e49 EKD |
984 | |
985 | # If GCM cipher is used, do not use --auth | |
986 | if (($cgiparams{'DCIPHER'} eq 'AES-256-GCM') || | |
987 | ($cgiparams{'DCIPHER'} eq 'AES-192-GCM') || | |
988 | ($cgiparams{'DCIPHER'} eq 'AES-128-GCM')) { | |
989 | print SERVERCONF unless "# HMAC algorithm\n"; | |
990 | print SERVERCONF unless "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 991 | } else { |
52f61e49 EKD |
992 | print SERVERCONF "# HMAC algorithm\n"; |
993 | print SERVERCONF "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 994 | } |
52f61e49 | 995 | |
942446b5 EK |
996 | # Set TLSv1.2 as minimum |
997 | print SERVERCONF "tls-version-min 1.2\n"; | |
998 | ||
ce9abb66 | 999 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1000 | print SERVERCONF "# Enable Compression\n"; |
66298ef2 | 1001 | print SERVERCONF "comp-lzo\n"; |
b278daf3 | 1002 | } |
66c36198 PM |
1003 | print SERVERCONF "# Debug Level\n"; |
1004 | print SERVERCONF "verb 3\n"; | |
1005 | print SERVERCONF "# Tunnel check\n"; | |
1006 | print SERVERCONF "keepalive 10 60\n"; | |
1007 | print SERVERCONF "# Start as daemon\n"; | |
1008 | print SERVERCONF "daemon $cgiparams{'NAME'}n2n\n"; | |
1009 | print SERVERCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; | |
1010 | print SERVERCONF "# Activate Management Interface and Port\n"; | |
54fd0535 MT |
1011 | if ($cgiparams{'OVPN_MGMT'} eq '') {print SERVERCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1012 | else {print SERVERCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 AH |
1013 | close(SERVERCONF); |
1014 | ||
1015 | } | |
1016 | ||
1017 | ### | |
7c1d9faf | 1018 | # m.a.d net2net |
ce9abb66 | 1019 | ### |
7c1d9faf | 1020 | |
ce9abb66 AH |
1021 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq 'net' && $cgiparams{'SIDE'} eq 'client') |
1022 | { | |
4c962356 | 1023 | |
ce9abb66 | 1024 | my @ovsubnettemp = split(/\./,$cgiparams{'OVPN_SUBNET'}); |
54fd0535 | 1025 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
ce9abb66 | 1026 | my @remsubnet = split(/\//,$cgiparams{'REMOTE_SUBNET'}); |
d96c89eb | 1027 | my $tunmtu = ''; |
66c36198 | 1028 | |
531f0835 AH |
1029 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
1030 | unless(-d "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}"){mkdir "${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}", 0770 or die "Unable to create dir $!";} | |
66c36198 | 1031 | |
ce9abb66 | 1032 | 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: $!"; |
66c36198 | 1033 | |
ce9abb66 | 1034 | flock CLIENTCONF, 2; |
7c1d9faf | 1035 | print CLIENTCONF "# IPFire rewritten n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
66c36198 | 1036 | print CLIENTCONF "#\n"; |
b278daf3 | 1037 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
1038 | print CLIENTCONF "user nobody\n"; |
1039 | print CLIENTCONF "group nobody\n"; | |
1040 | print CLIENTCONF "persist-tun\n"; | |
1041 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 1042 | print CLIENTCONF "script-security 2\n"; |
66c36198 | 1043 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
ce9abb66 | 1044 | print CLIENTCONF "remote $cgiparams{'REMOTE'}\n"; |
b278daf3 | 1045 | print CLIENTCONF "float\n"; |
66c36198 PM |
1046 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
1047 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; | |
1048 | print CLIENTCONF "# Server Gateway Network\n"; | |
1049 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; | |
ebcecb4b | 1050 | print CLIENTCONF "up \"/etc/init.d/static-routes start\"\n"; |
66c36198 PM |
1051 | print CLIENTCONF "# tun Device\n"; |
1052 | print CLIENTCONF "dev tun\n"; | |
35a21a25 AM |
1053 | print CLIENTCONF "#Logfile for statistics\n"; |
1054 | print CLIENTCONF "status-version 1\n"; | |
1055 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
66c36198 PM |
1056 | print CLIENTCONF "# Port and Protokol\n"; |
1057 | print CLIENTCONF "port $cgiparams{'DEST_PORT'}\n"; | |
60f396d7 AH |
1058 | |
1059 | if ($cgiparams{'PROTOCOL'} eq 'tcp') { | |
1580d3b1 | 1060 | print CLIENTCONF "proto tcp4-client\n"; |
60f396d7 | 1061 | print CLIENTCONF "# Packet size\n"; |
d96c89eb | 1062 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1400'} else {$tunmtu = $cgiparams{'MTU'}}; |
60f396d7 | 1063 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 1064 | } |
66c36198 | 1065 | |
60f396d7 | 1066 | if ($cgiparams{'PROTOCOL'} eq 'udp') { |
1580d3b1 | 1067 | print CLIENTCONF "proto udp4\n"; |
60f396d7 AH |
1068 | print CLIENTCONF "# Paketsize\n"; |
1069 | if ($cgiparams{'MTU'} eq '') {$tunmtu = '1500'} else {$tunmtu = $cgiparams{'MTU'}}; | |
1070 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 1071 | if ($cgiparams{'FRAGMENT'} ne '') {print CLIENTCONF "fragment $cgiparams{'FRAGMENT'}\n";} |
d6989b4b | 1072 | if ($cgiparams{'MSSFIX'} eq 'on') {print CLIENTCONF "mssfix\n"; } else { print CLIENTCONF "mssfix 0\n" }; |
d96c89eb | 1073 | } |
1647059d | 1074 | |
b66b02ab EK |
1075 | # Check host certificate if X509 is RFC3280 compliant. |
1076 | # If not, old --ns-cert-type directive will be used. | |
1077 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2feacd98 SS |
1078 | my @hostcert = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
1079 | if ( ! grep(/TLS Web Server Authentication/, @hostcert)) { | |
b66b02ab EK |
1080 | print CLIENTCONF "ns-cert-type server\n"; |
1081 | } else { | |
1082 | print CLIENTCONF "remote-cert-tls server\n"; | |
1083 | } | |
66c36198 PM |
1084 | print CLIENTCONF "# Auth. Client\n"; |
1085 | print CLIENTCONF "tls-client\n"; | |
1086 | print CLIENTCONF "# Cipher\n"; | |
4c962356 | 1087 | print CLIENTCONF "cipher $cgiparams{'DCIPHER'}\n"; |
ce9abb66 | 1088 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12\r\n"; |
52f61e49 EKD |
1089 | |
1090 | # If GCM cipher is used, do not use --auth | |
1091 | if (($cgiparams{'DCIPHER'} eq 'AES-256-GCM') || | |
1092 | ($cgiparams{'DCIPHER'} eq 'AES-192-GCM') || | |
1093 | ($cgiparams{'DCIPHER'} eq 'AES-128-GCM')) { | |
1094 | print CLIENTCONF unless "# HMAC algorithm\n"; | |
1095 | print CLIENTCONF unless "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1096 | } else { |
52f61e49 EKD |
1097 | print CLIENTCONF "# HMAC algorithm\n"; |
1098 | print CLIENTCONF "auth $cgiparams{'DAUTH'}\n"; | |
49abe7af | 1099 | } |
52f61e49 | 1100 | |
942446b5 EK |
1101 | # Set TLSv1.2 as minimum |
1102 | print CLIENTCONF "tls-version-min 1.2\n"; | |
1103 | ||
ce9abb66 | 1104 | if ($cgiparams{'COMPLZO'} eq 'on') { |
60f396d7 | 1105 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 1106 | print CLIENTCONF "comp-lzo\n"; |
4c962356 | 1107 | } |
66c36198 PM |
1108 | print CLIENTCONF "# Debug Level\n"; |
1109 | print CLIENTCONF "verb 3\n"; | |
1110 | print CLIENTCONF "# Tunnel check\n"; | |
1111 | print CLIENTCONF "keepalive 10 60\n"; | |
1112 | print CLIENTCONF "# Start as daemon\n"; | |
ce9abb66 | 1113 | print CLIENTCONF "daemon $cgiparams{'NAME'}n2n\n"; |
66c36198 PM |
1114 | print CLIENTCONF "writepid /var/run/$cgiparams{'NAME'}n2n.pid\n"; |
1115 | print CLIENTCONF "# Activate Management Interface and Port\n"; | |
54fd0535 MT |
1116 | if ($cgiparams{'OVPN_MGMT'} eq '') {print CLIENTCONF "management localhost $cgiparams{'DEST_PORT'}\n"} |
1117 | else {print CLIENTCONF "management localhost $cgiparams{'OVPN_MGMT'}\n"}; | |
ce9abb66 | 1118 | close(CLIENTCONF); |
c6c9630e | 1119 | |
ce9abb66 | 1120 | } |
400c8afd | 1121 | |
6e13d0a5 MT |
1122 | ### |
1123 | ### Save main settings | |
1124 | ### | |
ce9abb66 | 1125 | |
6e13d0a5 MT |
1126 | if ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'TYPE'} eq '' && $cgiparams{'KEY'} eq '') { |
1127 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
6e13d0a5 MT |
1128 | #DAN do we really need (to to check) this value? Besides if we listen on blue and orange too, |
1129 | #DAN this value has to leave. | |
1130 | if ($cgiparams{'ENABLED'} eq 'on'){ | |
1131 | unless (&General::validfqdn($cgiparams{'VPN_IP'}) || &General::validip($cgiparams{'VPN_IP'})) { | |
1132 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
c6c9630e | 1133 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1134 | } |
1135 | } | |
f7fb5bc5 | 1136 | |
6e13d0a5 | 1137 | if (! &General::validipandmask($cgiparams{'DOVPN_SUBNET'})) { |
c6c9630e | 1138 | $errormessage = $Lang::tr{'ovpn subnet is invalid'}; |
4c962356 | 1139 | goto SETTINGS_ERROR; |
c6c9630e MT |
1140 | } |
1141 | my @tmpovpnsubnet = split("\/",$cgiparams{'DOVPN_SUBNET'}); | |
66c36198 PM |
1142 | |
1143 | if (&General::IpInSubnet ( $netsettings{'RED_ADDRESS'}, | |
c6c9630e MT |
1144 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { |
1145 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire RED Network $netsettings{'RED_ADDRESS'}"; | |
1146 | goto SETTINGS_ERROR; | |
1147 | } | |
66c36198 PM |
1148 | |
1149 | if (&General::IpInSubnet ( $netsettings{'GREEN_ADDRESS'}, | |
c6c9630e MT |
1150 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { |
1151 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Green Network $netsettings{'GREEN_ADDRESS'}"; | |
1152 | goto SETTINGS_ERROR; | |
1153 | } | |
1154 | ||
66c36198 | 1155 | if (&General::IpInSubnet ( $netsettings{'BLUE_ADDRESS'}, |
c6c9630e MT |
1156 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { |
1157 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Blue Network $netsettings{'BLUE_ADDRESS'}"; | |
1158 | goto SETTINGS_ERROR; | |
1159 | } | |
66c36198 PM |
1160 | |
1161 | if (&General::IpInSubnet ( $netsettings{'ORANGE_ADDRESS'}, | |
c6c9630e MT |
1162 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { |
1163 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire Orange Network $netsettings{'ORANGE_ADDRESS'}"; | |
1164 | goto SETTINGS_ERROR; | |
1165 | } | |
1166 | open(ALIASES, "${General::swroot}/ethernet/aliases") or die 'Unable to open aliases file.'; | |
1167 | while (<ALIASES>) | |
1168 | { | |
1169 | chomp($_); | |
1170 | my @tempalias = split(/\,/,$_); | |
1171 | if ($tempalias[1] eq 'on') { | |
66c36198 | 1172 | if (&General::IpInSubnet ($tempalias[0] , |
c6c9630e MT |
1173 | $tmpovpnsubnet[0], $tmpovpnsubnet[1])) { |
1174 | $errormessage = "$Lang::tr{'ovpn subnet overlap'} IPFire alias entry $tempalias[0]"; | |
66c36198 | 1175 | } |
c6c9630e MT |
1176 | } |
1177 | } | |
1178 | close(ALIASES); | |
6e13d0a5 | 1179 | if ($errormessage ne ''){ |
c6c9630e | 1180 | goto SETTINGS_ERROR; |
6e13d0a5 MT |
1181 | } |
1182 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { | |
1183 | $errormessage = $Lang::tr{'invalid input'}; | |
1184 | goto SETTINGS_ERROR; | |
1185 | } | |
1186 | if ((length($cgiparams{'DMTU'})==0) || (($cgiparams{'DMTU'}) < 1000 )) { | |
1187 | $errormessage = $Lang::tr{'invalid mtu input'}; | |
1188 | goto SETTINGS_ERROR; | |
1189 | } | |
66c36198 | 1190 | |
6e13d0a5 | 1191 | unless (&General::validport($cgiparams{'DDEST_PORT'})) { |
c6c9630e MT |
1192 | $errormessage = $Lang::tr{'invalid port'}; |
1193 | goto SETTINGS_ERROR; | |
6e13d0a5 | 1194 | } |
8c252e6a | 1195 | |
b21a6319 EK |
1196 | # Create ta.key for tls-auth if not presant |
1197 | if ($cgiparams{'TLSAUTH'} eq 'on') { | |
1198 | if ( ! -e "${General::swroot}/ovpn/certs/ta.key") { | |
2feacd98 | 1199 | # This system call is safe, because all arguements are passed as an array. |
acbd6ff4 | 1200 | system("/usr/sbin/openvpn", "--genkey", "secret", "${General::swroot}/ovpn/certs/ta.key"); |
b21a6319 EK |
1201 | if ($?) { |
1202 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1203 | goto SETTINGS_ERROR; | |
1204 | } | |
1205 | } | |
1206 | } | |
1207 | ||
6e13d0a5 MT |
1208 | $vpnsettings{'ENABLED_BLUE'} = $cgiparams{'ENABLED_BLUE'}; |
1209 | $vpnsettings{'ENABLED_ORANGE'} =$cgiparams{'ENABLED_ORANGE'}; | |
1210 | $vpnsettings{'ENABLED'} = $cgiparams{'ENABLED'}; | |
1211 | $vpnsettings{'VPN_IP'} = $cgiparams{'VPN_IP'}; | |
1212 | #new settings for daemon | |
1213 | $vpnsettings{'DOVPN_SUBNET'} = $cgiparams{'DOVPN_SUBNET'}; | |
6e13d0a5 MT |
1214 | $vpnsettings{'DPROTOCOL'} = $cgiparams{'DPROTOCOL'}; |
1215 | $vpnsettings{'DDEST_PORT'} = $cgiparams{'DDEST_PORT'}; | |
1216 | $vpnsettings{'DMTU'} = $cgiparams{'DMTU'}; | |
1217 | $vpnsettings{'DCOMPLZO'} = $cgiparams{'DCOMPLZO'}; | |
1218 | $vpnsettings{'DCIPHER'} = $cgiparams{'DCIPHER'}; | |
86308adb | 1219 | $vpnsettings{'DAUTH'} = $cgiparams{'DAUTH'}; |
0c4ffc69 | 1220 | $vpnsettings{'TLSAUTH'} = $cgiparams{'TLSAUTH'}; |
3ffee04b CS |
1221 | #wrtie enable |
1222 | ||
2feacd98 SS |
1223 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' ) { |
1224 | &General::system("touch", "${General::swroot}/ovpn/enable_blue"); | |
1225 | } else { | |
274ca65b | 1226 | unlink("${General::swroot}/ovpn/enable_blue"); |
2feacd98 SS |
1227 | } |
1228 | ||
1229 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' ) { | |
1230 | &General::system("touch", "${General::swroot}/ovpn/enable_orange"); | |
1231 | } else { | |
1232 | unlink("${General::swroot}/ovpn/enable_orange"); | |
1233 | } | |
1234 | ||
1235 | if ( $vpnsettings{'ENABLED'} eq 'on' ) { | |
1236 | &General::system("touch", "${General::swroot}/ovpn/enable"); | |
1237 | } else { | |
1238 | unlink("${General::swroot}/ovpn/enable"); | |
1239 | } | |
1240 | ||
66c36198 | 1241 | #new settings for daemon |
6e13d0a5 | 1242 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); |
c6c9630e | 1243 | &writeserverconf();#hier ok |
6e13d0a5 MT |
1244 | SETTINGS_ERROR: |
1245 | ### | |
1246 | ### Reset all step 2 | |
1247 | ### | |
4c962356 | 1248 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'} && $cgiparams{'AREUSURE'} eq 'yes') { |
6e13d0a5 MT |
1249 | my $file = ''; |
1250 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1251 | ||
1e499e90 | 1252 | # Kill all N2N connections |
2feacd98 | 1253 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n"); |
1e499e90 | 1254 | |
6e13d0a5 | 1255 | foreach my $key (keys %confighash) { |
2f36a7b4 MT |
1256 | my $name = $confighash{$cgiparams{'$key'}}[1]; |
1257 | ||
c6c9630e MT |
1258 | if ($confighash{$key}[4] eq 'cert') { |
1259 | delete $confighash{$cgiparams{'$key'}}; | |
1260 | } | |
2f36a7b4 | 1261 | |
2feacd98 | 1262 | &General::system("/usr/local/bin/openvpnctrl", "-drrd", "$name"); |
6e13d0a5 MT |
1263 | } |
1264 | while ($file = glob("${General::swroot}/ovpn/ca/*")) { | |
49abe7af | 1265 | unlink $file; |
6e13d0a5 MT |
1266 | } |
1267 | while ($file = glob("${General::swroot}/ovpn/certs/*")) { | |
49abe7af | 1268 | unlink $file; |
6e13d0a5 MT |
1269 | } |
1270 | while ($file = glob("${General::swroot}/ovpn/crls/*")) { | |
49abe7af | 1271 | unlink $file; |
6e13d0a5 | 1272 | } |
4c962356 | 1273 | &cleanssldatabase(); |
6e13d0a5 MT |
1274 | if (open(FILE, ">${General::swroot}/ovpn/caconfig")) { |
1275 | print FILE ""; | |
1276 | close FILE; | |
1277 | } | |
49abe7af EK |
1278 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute")) { |
1279 | print FILE ""; | |
1280 | close FILE; | |
1281 | } | |
1282 | if (open(FILE, ">${General::swroot}/ovpn/ccdroute2")) { | |
1283 | print FILE ""; | |
1284 | close FILE; | |
1285 | } | |
1286 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { | |
1287 | unlink $file | |
1288 | } | |
5795fc1b AM |
1289 | while ($file = glob("${General::swroot}/ovpn/ccd/*")) { |
1290 | unlink $file | |
1291 | } | |
49abe7af EK |
1292 | if (open(FILE, ">${General::swroot}/ovpn/ovpn-leases.db")) { |
1293 | print FILE ""; | |
1294 | close FILE; | |
1295 | } | |
1296 | if (open(FILE, ">${General::swroot}/ovpn/ovpnconfig")) { | |
1297 | print FILE ""; | |
1298 | close FILE; | |
1299 | } | |
1300 | while ($file = glob("${General::swroot}/ovpn/n2nconf/*")) { | |
2feacd98 | 1301 | unlink($file); |
49abe7af EK |
1302 | } |
1303 | ||
2f36a7b4 MT |
1304 | # Remove everything from the collectd configuration |
1305 | &writecollectdconf(); | |
1306 | ||
c6c9630e | 1307 | #&writeserverconf(); |
6e13d0a5 MT |
1308 | ### |
1309 | ### Reset all step 1 | |
1310 | ### | |
4c962356 | 1311 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove x509'}) { |
6e13d0a5 | 1312 | &Header::showhttpheaders(); |
4c962356 EK |
1313 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
1314 | &Header::openbigbox('100%', 'left', '', ''); | |
1315 | &Header::openbox('100%', 'left', $Lang::tr{'are you sure'}); | |
1316 | print <<END; | |
1317 | <form method='post'> | |
1318 | <table width='100%'> | |
1319 | <tr> | |
1320 | <td align='center'> | |
1321 | <input type='hidden' name='AREUSURE' value='yes' /> | |
49abe7af | 1322 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: |
4c962356 EK |
1323 | $Lang::tr{'resetting the vpn configuration will remove the root ca, the host certificate and all certificate based connections'}</td> |
1324 | </tr> | |
1325 | <tr> | |
1326 | <td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /> | |
1327 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td> | |
1328 | </tr> | |
1329 | </table> | |
1330 | </form> | |
6e13d0a5 MT |
1331 | END |
1332 | ; | |
1333 | &Header::closebox(); | |
1334 | &Header::closebigbox(); | |
1335 | &Header::closepage(); | |
1336 | exit (0); | |
1337 | ||
4c962356 | 1338 | ### |
6e13d0a5 MT |
1339 | ### Upload CA Certificate |
1340 | ### | |
1341 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload ca certificate'}) { | |
1342 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1343 | ||
1344 | if ($cgiparams{'CA_NAME'} !~ /^[a-zA-Z0-9]+$/) { | |
1345 | $errormessage = $Lang::tr{'name must only contain characters'}; | |
1346 | goto UPLOADCA_ERROR; | |
1347 | } | |
1348 | ||
1349 | if (length($cgiparams{'CA_NAME'}) >60) { | |
1350 | $errormessage = $Lang::tr{'name too long'}; | |
1351 | goto VPNCONF_ERROR; | |
1352 | } | |
1353 | ||
1354 | if ($cgiparams{'CA_NAME'} eq 'ca') { | |
1355 | $errormessage = $Lang::tr{'name is invalid'}; | |
4c962356 | 1356 | goto UPLOADCA_ERROR; |
6e13d0a5 MT |
1357 | } |
1358 | ||
1359 | # Check if there is no other entry with this name | |
1360 | foreach my $key (keys %cahash) { | |
c6c9630e MT |
1361 | if ($cahash{$key}[0] eq $cgiparams{'CA_NAME'}) { |
1362 | $errormessage = $Lang::tr{'a ca certificate with this name already exists'}; | |
1363 | goto UPLOADCA_ERROR; | |
1364 | } | |
6e13d0a5 MT |
1365 | } |
1366 | ||
2ad1b18b | 1367 | unless (ref ($cgiparams{'FH'})) { |
c6c9630e MT |
1368 | $errormessage = $Lang::tr{'there was no file upload'}; |
1369 | goto UPLOADCA_ERROR; | |
6e13d0a5 MT |
1370 | } |
1371 | # Move uploaded ca to a temporary file | |
1372 | (my $fh, my $filename) = tempfile( ); | |
1373 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
c6c9630e MT |
1374 | $errormessage = $!; |
1375 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1376 | } |
2feacd98 SS |
1377 | my @temp = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "$filename"); |
1378 | if ( ! grep(/CA:TRUE/i, @temp )) { | |
c6c9630e MT |
1379 | $errormessage = $Lang::tr{'not a valid ca certificate'}; |
1380 | unlink ($filename); | |
1381 | goto UPLOADCA_ERROR; | |
6e13d0a5 | 1382 | } else { |
cc79d281 | 1383 | unless(move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem")) { |
c6c9630e MT |
1384 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; |
1385 | unlink ($filename); | |
1386 | goto UPLOADCA_ERROR; | |
1387 | } | |
6e13d0a5 MT |
1388 | } |
1389 | ||
274ca65b | 1390 | my @casubject = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem"); |
2feacd98 SS |
1391 | my $casubject; |
1392 | ||
1393 | foreach my $line (@casubject) { | |
1394 | if ($line =~ /Subject: (.*)[\n]/) { | |
1395 | $casubject = $1; | |
1396 | $casubject =~ s+/Email+, E+; | |
1397 | $casubject =~ s/ ST=/ S=/; | |
1398 | ||
1399 | last; | |
1400 | } | |
1401 | } | |
1402 | ||
6e13d0a5 MT |
1403 | $casubject = &Header::cleanhtml($casubject); |
1404 | ||
1405 | my $key = &General::findhasharraykey (\%cahash); | |
1406 | $cahash{$key}[0] = $cgiparams{'CA_NAME'}; | |
1407 | $cahash{$key}[1] = $casubject; | |
1408 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e MT |
1409 | # system('/usr/local/bin/ipsecctrl', 'R'); |
1410 | ||
6e13d0a5 MT |
1411 | UPLOADCA_ERROR: |
1412 | ||
1413 | ### | |
1414 | ### Display ca certificate | |
1415 | ### | |
1416 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show ca certificate'}) { | |
c6c9630e MT |
1417 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); |
1418 | ||
1419 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem") { | |
1420 | &Header::showhttpheaders(); | |
4c962356 | 1421 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1422 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1423 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ca certificate'}:"); | |
2feacd98 | 1424 | my @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); |
8c946d1c MT |
1425 | my $output = &Header::cleanhtml(join("", @output),"y"); |
1426 | print "<pre>$output</pre>\n"; | |
c6c9630e MT |
1427 | &Header::closebox(); |
1428 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1429 | &Header::closebigbox(); | |
1430 | &Header::closepage(); | |
1431 | exit(0); | |
1432 | } else { | |
1433 | $errormessage = $Lang::tr{'invalid key'}; | |
1434 | } | |
1435 | ||
6e13d0a5 MT |
1436 | ### |
1437 | ### Download ca certificate | |
1438 | ### | |
1439 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download ca certificate'}) { | |
1440 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1441 | ||
1442 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1443 | print "Content-Type: application/octet-stream\r\n"; | |
1444 | print "Content-Disposition: filename=$cahash{$cgiparams{'KEY'}}[0]cert.pem\r\n\r\n"; | |
2feacd98 SS |
1445 | |
1446 | my @tmp = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
f158e71e | 1447 | print @tmp; |
2feacd98 | 1448 | |
6e13d0a5 MT |
1449 | exit(0); |
1450 | } else { | |
1451 | $errormessage = $Lang::tr{'invalid key'}; | |
1452 | } | |
1453 | ||
1454 | ### | |
1455 | ### Remove ca certificate (step 2) | |
1456 | ### | |
1457 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'} && $cgiparams{'AREUSURE'} eq 'yes') { | |
1458 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1459 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1460 | ||
1461 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1462 | foreach my $key (keys %confighash) { | |
2feacd98 SS |
1463 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem", "${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem"); |
1464 | if (grep(/: OK/, @test)) { | |
c6c9630e MT |
1465 | # Delete connection |
1466 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
1467 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
1468 | # system('/usr/local/bin/ipsecctrl', 'D', $key); | |
1469 | # } | |
6e13d0a5 MT |
1470 | unlink ("${General::swroot}/ovpn//certs/$confighash{$key}[1]cert.pem"); |
1471 | unlink ("${General::swroot}/ovpn/certs/$confighash{$key}[1].p12"); | |
1472 | delete $confighash{$key}; | |
1473 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 1474 | # &writeipsecfiles(); |
6e13d0a5 MT |
1475 | } |
1476 | } | |
1477 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1478 | delete $cahash{$cgiparams{'KEY'}}; | |
1479 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
c6c9630e | 1480 | # system('/usr/local/bin/ipsecctrl', 'R'); |
6e13d0a5 MT |
1481 | } else { |
1482 | $errormessage = $Lang::tr{'invalid key'}; | |
1483 | } | |
1484 | ### | |
1485 | ### Remove ca certificate (step 1) | |
1486 | ### | |
1487 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove ca certificate'}) { | |
1488 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
1489 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1490 | ||
1491 | my $assignedcerts = 0; | |
1492 | if ( -f "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem" ) { | |
1493 | foreach my $key (keys %confighash) { | |
2feacd98 SS |
1494 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem", "${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem"); |
1495 | if (grep(/: OK/, @test)) { | |
6e13d0a5 MT |
1496 | $assignedcerts++; |
1497 | } | |
1498 | } | |
1499 | if ($assignedcerts) { | |
1500 | &Header::showhttpheaders(); | |
4c962356 | 1501 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1502 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
1503 | &Header::openbox('100%', 'LEFT', $Lang::tr{'are you sure'}); | |
4c962356 | 1504 | print <<END; |
6e13d0a5 MT |
1505 | <table><form method='post'><input type='hidden' name='AREUSURE' value='yes' /> |
1506 | <input type='hidden' name='KEY' value='$cgiparams{'KEY'}' /> | |
1507 | <tr><td align='center'> | |
1508 | <b><font color='${Header::colourred}'>$Lang::tr{'capswarning'}</font></b>: $assignedcerts | |
1509 | $Lang::tr{'connections are associated with this ca. deleting the ca will delete these connections as well.'} | |
1510 | <tr><td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
1511 | <input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></td></tr> | |
1512 | </form></table> | |
1513 | END | |
1514 | ; | |
1515 | &Header::closebox(); | |
1516 | &Header::closebigbox(); | |
1517 | &Header::closepage(); | |
1518 | exit (0); | |
1519 | } else { | |
1520 | unlink ("${General::swroot}/ovpn/ca/$cahash{$cgiparams{'KEY'}}[0]cert.pem"); | |
1521 | delete $cahash{$cgiparams{'KEY'}}; | |
1522 | &General::writehasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
1523 | # system('/usr/local/bin/ipsecctrl', 'R'); | |
1524 | } | |
1525 | } else { | |
1526 | $errormessage = $Lang::tr{'invalid key'}; | |
1527 | } | |
1528 | ||
1529 | ### | |
1530 | ### Display root certificate | |
1531 | ### | |
c6c9630e MT |
1532 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'} || |
1533 | $cgiparams{'ACTION'} eq $Lang::tr{'show host certificate'}) { | |
2feacd98 | 1534 | my @output; |
c6c9630e | 1535 | &Header::showhttpheaders(); |
4c962356 | 1536 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
1537 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1538 | if ($cgiparams{'ACTION'} eq $Lang::tr{'show root certificate'}) { | |
1539 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'root certificate'}:"); | |
2feacd98 | 1540 | @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/cacert.pem"); |
c6c9630e MT |
1541 | } else { |
1542 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'host certificate'}:"); | |
2feacd98 | 1543 | @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
c6c9630e | 1544 | } |
8c946d1c MT |
1545 | my $output = &Header::cleanhtml(join("", @output), "y"); |
1546 | print "<pre>$output</pre>\n"; | |
c6c9630e MT |
1547 | &Header::closebox(); |
1548 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
1549 | &Header::closebigbox(); | |
1550 | &Header::closepage(); | |
1551 | exit(0); | |
1552 | ||
6e13d0a5 MT |
1553 | ### |
1554 | ### Download root certificate | |
1555 | ### | |
1556 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download root certificate'}) { | |
1557 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { | |
1558 | print "Content-Type: application/octet-stream\r\n"; | |
1559 | print "Content-Disposition: filename=cacert.pem\r\n\r\n"; | |
2feacd98 SS |
1560 | |
1561 | my @tmp = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ovpn/ca/cacert.pem"); | |
f158e71e | 1562 | print @tmp; |
2feacd98 | 1563 | |
6e13d0a5 MT |
1564 | exit(0); |
1565 | } | |
66c36198 | 1566 | |
6e13d0a5 MT |
1567 | ### |
1568 | ### Download host certificate | |
1569 | ### | |
1570 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download host certificate'}) { | |
1571 | if ( -f "${General::swroot}/ovpn/certs/servercert.pem" ) { | |
1572 | print "Content-Type: application/octet-stream\r\n"; | |
1573 | print "Content-Disposition: filename=servercert.pem\r\n\r\n"; | |
2feacd98 SS |
1574 | |
1575 | my @tmp = &General::system_output("/usr/bin/openssl", "x509", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); | |
f158e71e | 1576 | print @tmp; |
2feacd98 | 1577 | |
6e13d0a5 MT |
1578 | exit(0); |
1579 | } | |
f7fb5bc5 | 1580 | |
fd5ccb2d EK |
1581 | ### |
1582 | ### Download tls-auth key | |
1583 | ### | |
1584 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download tls-auth key'}) { | |
1585 | if ( -f "${General::swroot}/ovpn/certs/ta.key" ) { | |
1586 | print "Content-Type: application/octet-stream\r\n"; | |
1587 | print "Content-Disposition: filename=ta.key\r\n\r\n"; | |
2feacd98 SS |
1588 | |
1589 | open(FILE, "${General::swroot}/ovpn/certs/ta.key"); | |
1590 | my @tmp = <FILE>; | |
1591 | close(FILE); | |
1592 | ||
f158e71e | 1593 | print @tmp; |
2feacd98 | 1594 | |
fd5ccb2d EK |
1595 | exit(0); |
1596 | } | |
1597 | ||
6e13d0a5 MT |
1598 | ### |
1599 | ### Form for generating a root certificate | |
1600 | ### | |
1601 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'generate root/host certificates'} || | |
1602 | $cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
1603 | ||
1604 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1605 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { | |
1606 | $errormessage = $Lang::tr{'valid root certificate already exists'}; | |
1607 | $cgiparams{'ACTION'} = ''; | |
1608 | goto ROOTCERT_ERROR; | |
1609 | } | |
1610 | ||
1611 | if (($cgiparams{'ROOTCERT_HOSTNAME'} eq '') && -e "${General::swroot}/red/active") { | |
1612 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { | |
1613 | my $ipaddr = <IPADDR>; | |
1614 | close IPADDR; | |
1615 | chomp ($ipaddr); | |
1616 | $cgiparams{'ROOTCERT_HOSTNAME'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
1617 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq '') { | |
1618 | $cgiparams{'ROOTCERT_HOSTNAME'} = $ipaddr; | |
1619 | } | |
1620 | } | |
1621 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'upload p12 file'}) { | |
2ad1b18b | 1622 | unless (ref ($cgiparams{'FH'})) { |
6e13d0a5 MT |
1623 | $errormessage = $Lang::tr{'there was no file upload'}; |
1624 | goto ROOTCERT_ERROR; | |
1625 | } | |
1626 | ||
1627 | # Move uploaded certificate request to a temporary file | |
1628 | (my $fh, my $filename) = tempfile( ); | |
1629 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
1630 | $errormessage = $!; | |
1631 | goto ROOTCERT_ERROR; | |
1632 | } | |
1633 | ||
1634 | # Create a temporary dirctory | |
1635 | my $tempdir = tempdir( CLEANUP => 1 ); | |
1636 | ||
1637 | # Extract the CA certificate from the file | |
1638 | my $pid = open(OPENSSL, "|-"); | |
1639 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1640 | if ($pid) { # parent | |
1641 | if ($cgiparams{'P12_PASS'} ne '') { | |
1642 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1643 | } | |
1644 | close (OPENSSL); | |
1645 | if ($?) { | |
1646 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1647 | unlink ($filename); | |
1648 | goto ROOTCERT_ERROR; | |
1649 | } | |
1650 | } else { # child | |
1651 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-cacerts', '-nokeys', | |
1652 | '-in', $filename, | |
1653 | '-out', "$tempdir/cacert.pem")) { | |
1654 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1655 | unlink ($filename); | |
1656 | goto ROOTCERT_ERROR; | |
1657 | } | |
1658 | } | |
1659 | ||
1660 | # Extract the Host certificate from the file | |
1661 | $pid = open(OPENSSL, "|-"); | |
1662 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1663 | if ($pid) { # parent | |
1664 | if ($cgiparams{'P12_PASS'} ne '') { | |
1665 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1666 | } | |
1667 | close (OPENSSL); | |
1668 | if ($?) { | |
1669 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1670 | unlink ($filename); | |
1671 | goto ROOTCERT_ERROR; | |
1672 | } | |
1673 | } else { # child | |
1674 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-clcerts', '-nokeys', | |
1675 | '-in', $filename, | |
1676 | '-out', "$tempdir/hostcert.pem")) { | |
1677 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1678 | unlink ($filename); | |
1679 | goto ROOTCERT_ERROR; | |
1680 | } | |
1681 | } | |
1682 | ||
1683 | # Extract the Host key from the file | |
1684 | $pid = open(OPENSSL, "|-"); | |
1685 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1686 | if ($pid) { # parent | |
1687 | if ($cgiparams{'P12_PASS'} ne '') { | |
1688 | print OPENSSL "$cgiparams{'P12_PASS'}\n"; | |
1689 | } | |
1690 | close (OPENSSL); | |
1691 | if ($?) { | |
1692 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1693 | unlink ($filename); | |
1694 | goto ROOTCERT_ERROR; | |
1695 | } | |
1696 | } else { # child | |
1697 | unless (exec ('/usr/bin/openssl', 'pkcs12', '-nocerts', | |
1698 | '-nodes', | |
1699 | '-in', $filename, | |
1700 | '-out', "$tempdir/serverkey.pem")) { | |
1701 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1702 | unlink ($filename); | |
1703 | goto ROOTCERT_ERROR; | |
1704 | } | |
1705 | } | |
1706 | ||
cc79d281 | 1707 | unless(move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem")) { |
6e13d0a5 MT |
1708 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; |
1709 | unlink ($filename); | |
1710 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1711 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1712 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1713 | goto ROOTCERT_ERROR; | |
1714 | } | |
1715 | ||
cc79d281 | 1716 | unless(move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem")) { |
6e13d0a5 MT |
1717 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; |
1718 | unlink ($filename); | |
1719 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1720 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1721 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1722 | goto ROOTCERT_ERROR; | |
1723 | } | |
1724 | ||
cc79d281 | 1725 | unless(move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem")) { |
6e13d0a5 MT |
1726 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; |
1727 | unlink ($filename); | |
1728 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1729 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1730 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1731 | goto ROOTCERT_ERROR; | |
1732 | } | |
1733 | ||
1734 | goto ROOTCERT_SUCCESS; | |
1735 | ||
1736 | } elsif ($cgiparams{'ROOTCERT_COUNTRY'} ne '') { | |
1737 | ||
1738 | # Validate input since the form was submitted | |
1739 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} eq ''){ | |
1740 | $errormessage = $Lang::tr{'organization cant be empty'}; | |
1741 | goto ROOTCERT_ERROR; | |
1742 | } | |
1743 | if (length($cgiparams{'ROOTCERT_ORGANIZATION'}) >60) { | |
1744 | $errormessage = $Lang::tr{'organization too long'}; | |
1745 | goto ROOTCERT_ERROR; | |
1746 | } | |
1747 | if ($cgiparams{'ROOTCERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1748 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
1749 | goto ROOTCERT_ERROR; | |
1750 | } | |
1751 | if ($cgiparams{'ROOTCERT_HOSTNAME'} eq ''){ | |
1752 | $errormessage = $Lang::tr{'hostname cant be empty'}; | |
1753 | goto ROOTCERT_ERROR; | |
1754 | } | |
1755 | unless (&General::validfqdn($cgiparams{'ROOTCERT_HOSTNAME'}) || &General::validip($cgiparams{'ROOTCERT_HOSTNAME'})) { | |
1756 | $errormessage = $Lang::tr{'invalid input for hostname'}; | |
1757 | goto ROOTCERT_ERROR; | |
1758 | } | |
1759 | if ($cgiparams{'ROOTCERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'ROOTCERT_EMAIL'}))) { | |
1760 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
1761 | goto ROOTCERT_ERROR; | |
1762 | } | |
1763 | if (length($cgiparams{'ROOTCERT_EMAIL'}) > 40) { | |
1764 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
1765 | goto ROOTCERT_ERROR; | |
1766 | } | |
1767 | if ($cgiparams{'ROOTCERT_OU'} ne '' && $cgiparams{'ROOTCERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1768 | $errormessage = $Lang::tr{'invalid input for department'}; | |
1769 | goto ROOTCERT_ERROR; | |
1770 | } | |
1771 | if ($cgiparams{'ROOTCERT_CITY'} ne '' && $cgiparams{'ROOTCERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1772 | $errormessage = $Lang::tr{'invalid input for city'}; | |
1773 | goto ROOTCERT_ERROR; | |
1774 | } | |
1775 | if ($cgiparams{'ROOTCERT_STATE'} ne '' && $cgiparams{'ROOTCERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
1776 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
1777 | goto ROOTCERT_ERROR; | |
1778 | } | |
1779 | if ($cgiparams{'ROOTCERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
1780 | $errormessage = $Lang::tr{'invalid input for country'}; | |
1781 | goto ROOTCERT_ERROR; | |
1782 | } | |
1783 | ||
1784 | # Copy the cgisettings to vpnsettings and save the configfile | |
1785 | $vpnsettings{'ROOTCERT_ORGANIZATION'} = $cgiparams{'ROOTCERT_ORGANIZATION'}; | |
1786 | $vpnsettings{'ROOTCERT_HOSTNAME'} = $cgiparams{'ROOTCERT_HOSTNAME'}; | |
1787 | $vpnsettings{'ROOTCERT_EMAIL'} = $cgiparams{'ROOTCERT_EMAIL'}; | |
1788 | $vpnsettings{'ROOTCERT_OU'} = $cgiparams{'ROOTCERT_OU'}; | |
1789 | $vpnsettings{'ROOTCERT_CITY'} = $cgiparams{'ROOTCERT_CITY'}; | |
1790 | $vpnsettings{'ROOTCERT_STATE'} = $cgiparams{'ROOTCERT_STATE'}; | |
1791 | $vpnsettings{'ROOTCERT_COUNTRY'} = $cgiparams{'ROOTCERT_COUNTRY'}; | |
1792 | &General::writehash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
1793 | ||
1794 | # Replace empty strings with a . | |
1795 | (my $ou = $cgiparams{'ROOTCERT_OU'}) =~ s/^\s*$/\./; | |
1796 | (my $city = $cgiparams{'ROOTCERT_CITY'}) =~ s/^\s*$/\./; | |
1797 | (my $state = $cgiparams{'ROOTCERT_STATE'}) =~ s/^\s*$/\./; | |
1798 | ||
1799 | # refresh | |
c6c9630e | 1800 | #system ('/bin/touch', "${General::swroot}/ovpn/gencanow"); |
66c36198 | 1801 | |
6e13d0a5 MT |
1802 | # Create the CA certificate |
1803 | my $pid = open(OPENSSL, "|-"); | |
1804 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1805 | if ($pid) { # parent | |
1806 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1807 | print OPENSSL "$state\n"; | |
1808 | print OPENSSL "$city\n"; | |
1809 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1810 | print OPENSSL "$ou\n"; | |
1811 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'} CA\n"; | |
1812 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1813 | close (OPENSSL); | |
1814 | if ($?) { | |
1815 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1816 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1817 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1818 | goto ROOTCERT_ERROR; | |
1819 | } | |
1820 | } else { # child | |
badd8c1c | 1821 | unless (exec ('/usr/bin/openssl', 'req', '-x509', '-nodes', |
49abe7af | 1822 | '-days', '999999', '-newkey', 'rsa:4096', '-sha512', |
6e13d0a5 MT |
1823 | '-keyout', "${General::swroot}/ovpn/ca/cakey.pem", |
1824 | '-out', "${General::swroot}/ovpn/ca/cacert.pem", | |
1825 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
1826 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1827 | goto ROOTCERT_ERROR; | |
1828 | } | |
1829 | } | |
1830 | ||
1831 | # Create the Host certificate request | |
1832 | $pid = open(OPENSSL, "|-"); | |
1833 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto ROOTCERT_ERROR;}; | |
1834 | if ($pid) { # parent | |
1835 | print OPENSSL "$cgiparams{'ROOTCERT_COUNTRY'}\n"; | |
1836 | print OPENSSL "$state\n"; | |
1837 | print OPENSSL "$city\n"; | |
1838 | print OPENSSL "$cgiparams{'ROOTCERT_ORGANIZATION'}\n"; | |
1839 | print OPENSSL "$ou\n"; | |
1840 | print OPENSSL "$cgiparams{'ROOTCERT_HOSTNAME'}\n"; | |
1841 | print OPENSSL "$cgiparams{'ROOTCERT_EMAIL'}\n"; | |
1842 | print OPENSSL ".\n"; | |
1843 | print OPENSSL ".\n"; | |
1844 | close (OPENSSL); | |
1845 | if ($?) { | |
1846 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1847 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1848 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1849 | goto ROOTCERT_ERROR; | |
1850 | } | |
1851 | } else { # child | |
badd8c1c | 1852 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
818dde8e | 1853 | '-newkey', 'rsa:4096', |
6e13d0a5 MT |
1854 | '-keyout', "${General::swroot}/ovpn/certs/serverkey.pem", |
1855 | '-out', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1856 | '-extensions', 'server', | |
1857 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" )) { | |
1858 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
1859 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1860 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1861 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1862 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1863 | goto ROOTCERT_ERROR; | |
1864 | } | |
1865 | } | |
66c36198 | 1866 | |
6e13d0a5 | 1867 | # Sign the host certificate request |
2feacd98 | 1868 | # This system call is safe, because all argeuments are passed as an array. |
6e13d0a5 MT |
1869 | system('/usr/bin/openssl', 'ca', '-days', '999999', |
1870 | '-batch', '-notext', | |
1871 | '-in', "${General::swroot}/ovpn/certs/serverreq.pem", | |
1872 | '-out', "${General::swroot}/ovpn/certs/servercert.pem", | |
1873 | '-extensions', 'server', | |
1874 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
1875 | if ($?) { | |
1876 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1877 | unlink ("${General::swroot}/ovpn/ca/cakey.pem"); | |
1878 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
1879 | unlink ("${General::swroot}/ovpn/serverkey.pem"); | |
1880 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
1881 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
c6c9630e | 1882 | &newcleanssldatabase(); |
6e13d0a5 MT |
1883 | goto ROOTCERT_ERROR; |
1884 | } else { | |
1885 | unlink ("${General::swroot}/ovpn/certs/serverreq.pem"); | |
c6c9630e | 1886 | &deletebackupcert(); |
6e13d0a5 MT |
1887 | } |
1888 | ||
1889 | # Create an empty CRL | |
2feacd98 | 1890 | # System call is safe, because all arguments are passed as array. |
6e13d0a5 MT |
1891 | system('/usr/bin/openssl', 'ca', '-gencrl', |
1892 | '-out', "${General::swroot}/ovpn/crls/cacrl.pem", | |
1893 | '-config', "${General::swroot}/ovpn/openssl/ovpn.cnf" ); | |
1894 | if ($?) { | |
1895 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1896 | unlink ("${General::swroot}/ovpn/certs/serverkey.pem"); | |
1897 | unlink ("${General::swroot}/ovpn/certs/servercert.pem"); | |
1898 | unlink ("${General::swroot}/ovpn/ca/cacert.pem"); | |
66c36198 | 1899 | unlink ("${General::swroot}/ovpn/crls/cacrl.pem"); |
c6c9630e | 1900 | &cleanssldatabase(); |
6e13d0a5 | 1901 | goto ROOTCERT_ERROR; |
c6c9630e MT |
1902 | # } else { |
1903 | # &cleanssldatabase(); | |
6e13d0a5 | 1904 | } |
ae04d0a3 | 1905 | # Create ta.key for tls-auth |
2feacd98 | 1906 | # This system call is safe, because all arguments are passed as an array. |
acbd6ff4 | 1907 | system('/usr/sbin/openvpn', '--genkey', 'secret', "${General::swroot}/ovpn/certs/ta.key"); |
ae04d0a3 EK |
1908 | if ($?) { |
1909 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
1910 | &cleanssldatabase(); | |
1911 | goto ROOTCERT_ERROR; | |
1912 | } | |
6e13d0a5 MT |
1913 | goto ROOTCERT_SUCCESS; |
1914 | } | |
1915 | ROOTCERT_ERROR: | |
1916 | if ($cgiparams{'ACTION'} ne '') { | |
1917 | &Header::showhttpheaders(); | |
4c962356 | 1918 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
1919 | &Header::openbigbox('100%', 'LEFT', '', ''); |
1920 | if ($errormessage) { | |
1921 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
1922 | print "<class name='base'>$errormessage"; | |
1923 | print " </class>"; | |
1924 | &Header::closebox(); | |
1925 | } | |
1926 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'generate root/host certificates'}:"); | |
49abe7af | 1927 | print <<END; |
6e13d0a5 MT |
1928 | <form method='post' enctype='multipart/form-data'> |
1929 | <table width='100%' border='0' cellspacing='1' cellpadding='0'> | |
e3edceeb | 1930 | <tr><td width='30%' class='base'>$Lang::tr{'organization name'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
1931 | <td width='35%' class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_ORGANIZATION' value='$cgiparams{'ROOTCERT_ORGANIZATION'}' size='32' /></td> |
1932 | <td width='35%' colspan='2'> </td></tr> | |
e3edceeb | 1933 | <tr><td class='base'>$Lang::tr{'ipfires hostname'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
1934 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_HOSTNAME' value='$cgiparams{'ROOTCERT_HOSTNAME'}' size='32' /></td> |
1935 | <td colspan='2'> </td></tr> | |
e3edceeb | 1936 | <tr><td class='base'>$Lang::tr{'your e-mail'}:</td> |
6e13d0a5 MT |
1937 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_EMAIL' value='$cgiparams{'ROOTCERT_EMAIL'}' size='32' /></td> |
1938 | <td colspan='2'> </td></tr> | |
e3edceeb | 1939 | <tr><td class='base'>$Lang::tr{'your department'}:</td> |
6e13d0a5 MT |
1940 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_OU' value='$cgiparams{'ROOTCERT_OU'}' size='32' /></td> |
1941 | <td colspan='2'> </td></tr> | |
e3edceeb | 1942 | <tr><td class='base'>$Lang::tr{'city'}:</td> |
6e13d0a5 MT |
1943 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_CITY' value='$cgiparams{'ROOTCERT_CITY'}' size='32' /></td> |
1944 | <td colspan='2'> </td></tr> | |
e3edceeb | 1945 | <tr><td class='base'>$Lang::tr{'state or province'}:</td> |
6e13d0a5 MT |
1946 | <td class='base' nowrap='nowrap'><input type='text' name='ROOTCERT_STATE' value='$cgiparams{'ROOTCERT_STATE'}' size='32' /></td> |
1947 | <td colspan='2'> </td></tr> | |
1948 | <tr><td class='base'>$Lang::tr{'country'}:</td> | |
66c36198 | 1949 | <td class='base'><select name='ROOTCERT_COUNTRY'> |
6e13d0a5 MT |
1950 | |
1951 | END | |
1952 | ; | |
1953 | foreach my $country (sort keys %{Countries::countries}) { | |
1954 | print "<option value='$Countries::countries{$country}'"; | |
1955 | if ( $Countries::countries{$country} eq $cgiparams{'ROOTCERT_COUNTRY'} ) { | |
1956 | print " selected='selected'"; | |
1957 | } | |
1958 | print ">$country</option>"; | |
1959 | } | |
49abe7af | 1960 | print <<END; |
6e13d0a5 | 1961 | </select></td> |
4c962356 | 1962 | |
6e13d0a5 MT |
1963 | <tr><td> </td> |
1964 | <td><input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' /></td> | |
66c36198 | 1965 | <td> </td><td> </td></tr> |
6e13d0a5 | 1966 | <tr><td class='base' colspan='4' align='left'> |
e3edceeb | 1967 | <img src='/blob.gif' valign='top' alt='*' /> $Lang::tr{'required field'}</td></tr> |
49abe7af | 1968 | <tr><td colspan='2'><br></td></tr> |
49abe7af | 1969 | </table> |
4c962356 | 1970 | |
49abe7af | 1971 | <table width='100%'> |
4c962356 | 1972 | <tr><td colspan='4'><hr></td></tr> |
e3edceeb | 1973 | <tr><td class='base' nowrap='nowrap'>$Lang::tr{'upload p12 file'}: <img src='/blob.gif' alt='*' /></td> |
6e13d0a5 MT |
1974 | <td nowrap='nowrap'><input type='file' name='FH' size='32'></td> |
1975 | <td colspan='2'> </td></tr> | |
e3edceeb | 1976 | <tr><td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
6e13d0a5 MT |
1977 | <td class='base' nowrap='nowrap'><input type='password' name='P12_PASS' value='$cgiparams{'P12_PASS'}' size='32' /></td> |
1978 | <td colspan='2'> </td></tr> | |
1979 | <tr><td> </td> | |
1980 | <td><input type='submit' name='ACTION' value='$Lang::tr{'upload p12 file'}' /></td> | |
1981 | <td colspan='2'> </td></tr> | |
1982 | <tr><td class='base' colspan='4' align='left'> | |
e3edceeb | 1983 | <img src='/blob.gif' valign='top' alt='*' > $Lang::tr{'required field'}</td> |
4c962356 | 1984 | </tr> |
6e13d0a5 MT |
1985 | </form></table> |
1986 | END | |
1987 | ; | |
1988 | &Header::closebox(); | |
4c962356 | 1989 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
1990 | &Header::closebigbox(); |
1991 | &Header::closepage(); | |
1992 | exit(0) | |
1993 | } | |
1994 | ||
1995 | ROOTCERT_SUCCESS: | |
2feacd98 | 1996 | &General::system("chmod", "600", "${General::swroot}/ovpn/certs/serverkey.pem"); |
c6c9630e MT |
1997 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
1998 | # $vpnsettings{'ENABLE_BLUE'} eq 'on') { | |
1999 | # system('/usr/local/bin/ipsecctrl', 'S'); | |
2000 | # } | |
6e13d0a5 MT |
2001 | |
2002 | ### | |
2003 | ### Enable/Disable connection | |
2004 | ### | |
ce9abb66 AH |
2005 | |
2006 | ### | |
7c1d9faf | 2007 | # m.a.d net2net |
ce9abb66 AH |
2008 | ### |
2009 | ||
6e13d0a5 | 2010 | }elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
66c36198 | 2011 | |
c6c9630e | 2012 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
6e13d0a5 | 2013 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2feacd98 SS |
2014 | my $n2nactive = ''; |
2015 | my @ps = &General::system_output("/bin/ps", "ax"); | |
2016 | ||
2017 | if(grep(/$confighash{$cgiparams{'KEY'}}[1]/, @ps)) { | |
2018 | $n2nactive = "1"; | |
2019 | } | |
66c36198 | 2020 | |
6e13d0a5 | 2021 | if ($confighash{$cgiparams{'KEY'}}) { |
8c877a82 AM |
2022 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
2023 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; | |
2024 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2025 | |
8c877a82 | 2026 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
2feacd98 | 2027 | &General::system("/usr/local/bin/openvpnctrl", "-sn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
775b4494 | 2028 | &writecollectdconf(); |
8c877a82 AM |
2029 | } |
2030 | } else { | |
ce9abb66 | 2031 | |
8c877a82 AM |
2032 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; |
2033 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
ce9abb66 | 2034 | |
8c877a82 | 2035 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ |
775b4494 | 2036 | if ($n2nactive ne '') { |
2feacd98 | 2037 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
775b4494 AM |
2038 | &writecollectdconf(); |
2039 | } | |
8c877a82 | 2040 | } |
775b4494 | 2041 | } |
ce9abb66 | 2042 | } |
6e13d0a5 MT |
2043 | |
2044 | ### | |
2045 | ### Download OpenVPN client package | |
2046 | ### | |
ce9abb66 AH |
2047 | |
2048 | ||
6e13d0a5 MT |
2049 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'dl client arch'}) { |
2050 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
2051 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2052 | my $file = ''; | |
2053 | my $clientovpn = ''; | |
2054 | my @fileholder; | |
2055 | my $tempdir = tempdir( CLEANUP => 1 ); | |
2056 | my $zippath = "$tempdir/"; | |
ce9abb66 AH |
2057 | |
2058 | ### | |
7c1d9faf AH |
2059 | # m.a.d net2net |
2060 | ### | |
ce9abb66 AH |
2061 | |
2062 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ | |
66c36198 | 2063 | |
ce9abb66 AH |
2064 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-Client.zip"; |
2065 | my $zippathname = "$zippath$zipname"; | |
66c36198 | 2066 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1].conf"; |
ce9abb66 | 2067 | my @ovsubnettemp = split(/\./,$confighash{$cgiparams{'KEY'}}[27]); |
54fd0535 | 2068 | my $ovsubnet = "$ovsubnettemp[0].$ovsubnettemp[1].$ovsubnettemp[2]"; |
66c36198 | 2069 | my $tunmtu = ''; |
7c1d9faf | 2070 | my @remsubnet = split(/\//,$confighash{$cgiparams{'KEY'}}[8]); |
54fd0535 | 2071 | my $n2nfragment = ''; |
66c36198 | 2072 | |
ce9abb66 AH |
2073 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
2074 | flock CLIENTCONF, 2; | |
66c36198 | 2075 | |
ce9abb66 | 2076 | my $zip = Archive::Zip->new(); |
7c1d9faf | 2077 | print CLIENTCONF "# IPFire n2n Open VPN Client Config by ummeegge und m.a.d\n"; |
ce9abb66 | 2078 | print CLIENTCONF "# \n"; |
b278daf3 | 2079 | print CLIENTCONF "# User Security\n"; |
ce9abb66 AH |
2080 | print CLIENTCONF "user nobody\n"; |
2081 | print CLIENTCONF "group nobody\n"; | |
2082 | print CLIENTCONF "persist-tun\n"; | |
2083 | print CLIENTCONF "persist-key\n"; | |
7c1d9faf | 2084 | print CLIENTCONF "script-security 2\n"; |
66c36198 | 2085 | print CLIENTCONF "# IP/DNS for remote Server Gateway\n"; |
531f0835 | 2086 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'}\n"; |
b278daf3 | 2087 | print CLIENTCONF "float\n"; |
66c36198 PM |
2088 | print CLIENTCONF "# IP adresses of the VPN Subnet\n"; |
2089 | print CLIENTCONF "ifconfig $ovsubnet.2 $ovsubnet.1\n"; | |
2090 | print CLIENTCONF "# Server Gateway Network\n"; | |
7c1d9faf | 2091 | print CLIENTCONF "route $remsubnet[0] $remsubnet[1]\n"; |
66c36198 PM |
2092 | print CLIENTCONF "# tun Device\n"; |
2093 | print CLIENTCONF "dev tun\n"; | |
35a21a25 AM |
2094 | print CLIENTCONF "#Logfile for statistics\n"; |
2095 | print CLIENTCONF "status-version 1\n"; | |
2096 | print CLIENTCONF "status /var/run/openvpn/$cgiparams{'NAME'}-n2n 10\n"; | |
66c36198 PM |
2097 | print CLIENTCONF "# Port and Protokoll\n"; |
2098 | print CLIENTCONF "port $confighash{$cgiparams{'KEY'}}[29]\n"; | |
2099 | ||
60f396d7 | 2100 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'tcp') { |
1580d3b1 | 2101 | print CLIENTCONF "proto tcp4-client\n"; |
60f396d7 | 2102 | print CLIENTCONF "# Packet size\n"; |
d96c89eb | 2103 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1400'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; |
60f396d7 | 2104 | print CLIENTCONF "tun-mtu $tunmtu\n"; |
d96c89eb | 2105 | } |
66c36198 | 2106 | |
60f396d7 | 2107 | if ($confighash{$cgiparams{'KEY'}}[28] eq 'udp') { |
1580d3b1 | 2108 | print CLIENTCONF "proto udp4\n"; |
60f396d7 AH |
2109 | print CLIENTCONF "# Paketsize\n"; |
2110 | if ($confighash{$cgiparams{'KEY'}}[31] eq '') {$tunmtu = '1500'} else {$tunmtu = $confighash{$cgiparams{'KEY'}}[31]}; | |
2111 | print CLIENTCONF "tun-mtu $tunmtu\n"; | |
54fd0535 | 2112 | if ($confighash{$cgiparams{'KEY'}}[24] ne '') {print CLIENTCONF "fragment $confighash{$cgiparams{'KEY'}}[24]\n";} |
d6989b4b | 2113 | if ($confighash{$cgiparams{'KEY'}}[23] eq 'on') {print CLIENTCONF "mssfix\n";} else { print CLIENTCONF "mssfix 0\n"; } |
d96c89eb | 2114 | } |
b66b02ab EK |
2115 | # Check host certificate if X509 is RFC3280 compliant. |
2116 | # If not, old --ns-cert-type directive will be used. | |
2117 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2feacd98 SS |
2118 | my @hostcert = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
2119 | if (! grep(/TLS Web Server Authentication/, @hostcert)) { | |
b66b02ab EK |
2120 | print CLIENTCONF "ns-cert-type server\n"; |
2121 | } else { | |
2122 | print CLIENTCONF "remote-cert-tls server\n"; | |
2123 | } | |
66c36198 PM |
2124 | print CLIENTCONF "# Auth. Client\n"; |
2125 | print CLIENTCONF "tls-client\n"; | |
49abe7af | 2126 | print CLIENTCONF "# Cipher\n"; |
4c962356 | 2127 | print CLIENTCONF "cipher $confighash{$cgiparams{'KEY'}}[40]\n"; |
66c36198 | 2128 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
ce9abb66 AH |
2129 | print CLIENTCONF "pkcs12 ${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12\r\n"; |
2130 | $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"; | |
49abe7af | 2131 | } |
52f61e49 EKD |
2132 | |
2133 | # If GCM cipher is used, do not use --auth | |
2134 | if (($confighash{$cgiparams{'KEY'}}[40] eq 'AES-256-GCM') || | |
2135 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-192-GCM') || | |
2136 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-128-GCM')) { | |
2137 | print CLIENTCONF unless "# HMAC algorithm\n"; | |
2138 | print CLIENTCONF unless "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
49abe7af | 2139 | } else { |
52f61e49 EKD |
2140 | print CLIENTCONF "# HMAC algorithm\n"; |
2141 | print CLIENTCONF "auth $confighash{$cgiparams{'KEY'}}[39]\n"; | |
49abe7af | 2142 | } |
52f61e49 | 2143 | |
4c962356 | 2144 | if ($confighash{$cgiparams{'KEY'}}[30] eq 'on') { |
b278daf3 | 2145 | print CLIENTCONF "# Enable Compression\n"; |
66298ef2 | 2146 | print CLIENTCONF "comp-lzo\n"; |
b278daf3 | 2147 | } |
66c36198 PM |
2148 | print CLIENTCONF "# Debug Level\n"; |
2149 | print CLIENTCONF "verb 3\n"; | |
2150 | print CLIENTCONF "# Tunnel check\n"; | |
2151 | print CLIENTCONF "keepalive 10 60\n"; | |
2152 | print CLIENTCONF "# Start as daemon\n"; | |
2153 | print CLIENTCONF "daemon $confighash{$cgiparams{'KEY'}}[1]n2n\n"; | |
2154 | print CLIENTCONF "writepid /var/run/$confighash{$cgiparams{'KEY'}}[1]n2n.pid\n"; | |
2155 | print CLIENTCONF "# Activate Management Interface and Port\n"; | |
54fd0535 MT |
2156 | if ($confighash{$cgiparams{'KEY'}}[22] eq '') {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[29]\n"} |
2157 | else {print CLIENTCONF "management localhost $confighash{$cgiparams{'KEY'}}[22]\n"}; | |
ce9abb66 | 2158 | print CLIENTCONF "# remsub $confighash{$cgiparams{'KEY'}}[11]\n"; |
66c36198 | 2159 | |
ce9abb66 AH |
2160 | |
2161 | close(CLIENTCONF); | |
66c36198 | 2162 | |
ce9abb66 AH |
2163 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
2164 | my $status = $zip->writeToFileNamed($zippathname); | |
2165 | ||
2166 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2167 | @fileholder = <DLFILE>; | |
2168 | print "Content-Type:application/x-download\n"; | |
2169 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2170 | print @fileholder; | |
2171 | exit (0); | |
2172 | } | |
2173 | else | |
2174 | { | |
2175 | my $zipname = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.zip"; | |
2176 | my $zippathname = "$zippath$zipname"; | |
2177 | $clientovpn = "$confighash{$cgiparams{'KEY'}}[1]-TO-IPFire.ovpn"; | |
2178 | ||
2179 | ### | |
7c1d9faf | 2180 | # m.a.d net2net |
ce9abb66 | 2181 | ### |
66c36198 | 2182 | |
c6c9630e | 2183 | open(CLIENTCONF, ">$tempdir/$clientovpn") or die "Unable to open tempfile: $!"; |
6e13d0a5 | 2184 | flock CLIENTCONF, 2; |
66c36198 | 2185 | |
6e13d0a5 | 2186 | my $zip = Archive::Zip->new(); |
66c36198 | 2187 | |
8c877a82 | 2188 | print CLIENTCONF "#OpenVPN Client conf\r\n"; |
6e13d0a5 MT |
2189 | print CLIENTCONF "tls-client\r\n"; |
2190 | print CLIENTCONF "client\r\n"; | |
4f6e3ae3 | 2191 | print CLIENTCONF "nobind\r\n"; |
79e7688b | 2192 | print CLIENTCONF "dev tun\r\n"; |
c6c9630e | 2193 | print CLIENTCONF "proto $vpnsettings{'DPROTOCOL'}\r\n"; |
d6989b4b | 2194 | print CLIENTCONF "tun-mtu $vpnsettings{'DMTU'}\r\n"; |
2ee746be | 2195 | |
6e13d0a5 MT |
2196 | if ( $vpnsettings{'ENABLED'} eq 'on'){ |
2197 | print CLIENTCONF "remote $vpnsettings{'VPN_IP'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
66c36198 | 2198 | if ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ |
574f4538 | 2199 | print CLIENTCONF "#comment the above line and uncomment the next line, if you want to connect on the Blue interface\r\n"; |
c6c9630e MT |
2200 | print CLIENTCONF ";remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; |
2201 | } | |
2202 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
574f4538 | 2203 | print CLIENTCONF "#comment the above line and uncomment the next line, if you want to connect on the Orange interface\r\n"; |
c6c9630e MT |
2204 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; |
2205 | } | |
2206 | } elsif ( $vpnsettings{'ENABLED_BLUE'} eq 'on' && (&haveBlueNet())){ | |
2207 | print CLIENTCONF "remote $netsettings{'BLUE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
2208 | if ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
574f4538 | 2209 | print CLIENTCONF "#comment the above line and uncomment the next line, if you want to connect on the Orange interface\r\n"; |
c6c9630e MT |
2210 | print CLIENTCONF ";remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; |
2211 | } | |
2212 | } elsif ( $vpnsettings{'ENABLED_ORANGE'} eq 'on' && (&haveOrangeNet())){ | |
2213 | print CLIENTCONF "remote $netsettings{'ORANGE_ADDRESS'} $vpnsettings{'DDEST_PORT'}\r\n"; | |
6e13d0a5 | 2214 | } |
66c36198 | 2215 | |
71af643c MT |
2216 | my $file_crt = new File::Temp( UNLINK => 1 ); |
2217 | my $file_key = new File::Temp( UNLINK => 1 ); | |
b22d8aaf | 2218 | my $include_certs = 0; |
71af643c | 2219 | |
66c36198 | 2220 | if ($confighash{$cgiparams{'KEY'}}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12") { |
71af643c | 2221 | if ($cgiparams{'MODE'} eq 'insecure') { |
b22d8aaf MT |
2222 | $include_certs = 1; |
2223 | ||
71af643c | 2224 | # Add the CA |
b22d8aaf | 2225 | print CLIENTCONF ";ca cacert.pem\r\n"; |
71af643c MT |
2226 | $zip->addFile("${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; |
2227 | ||
2228 | # Extract the certificate | |
2feacd98 | 2229 | # This system call is safe, because all arguments are passed as an array. |
71af643c MT |
2230 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", |
2231 | '-clcerts', '-nokeys', '-nodes', '-out', "$file_crt" , '-passin', 'pass:'); | |
2232 | if ($?) { | |
2233 | die "openssl error: $?"; | |
2234 | } | |
2235 | ||
2236 | $zip->addFile("$file_crt", "$confighash{$cgiparams{'KEY'}}[1].pem") or die; | |
b22d8aaf | 2237 | print CLIENTCONF ";cert $confighash{$cgiparams{'KEY'}}[1].pem\r\n"; |
71af643c MT |
2238 | |
2239 | # Extract the key | |
2feacd98 | 2240 | # This system call is safe, because all arguments are passed as an array. |
71af643c MT |
2241 | system('/usr/bin/openssl', 'pkcs12', '-in', "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12", |
2242 | '-nocerts', '-nodes', '-out', "$file_key", '-passin', 'pass:'); | |
2243 | if ($?) { | |
2244 | die "openssl error: $?"; | |
2245 | } | |
2246 | ||
2247 | $zip->addFile("$file_key", "$confighash{$cgiparams{'KEY'}}[1].key") or die; | |
b22d8aaf | 2248 | print CLIENTCONF ";key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; |
71af643c MT |
2249 | } else { |
2250 | print CLIENTCONF "pkcs12 $confighash{$cgiparams{'KEY'}}[1].p12\r\n"; | |
2251 | $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"; | |
2252 | } | |
6e13d0a5 | 2253 | } else { |
c6c9630e MT |
2254 | print CLIENTCONF "ca cacert.pem\r\n"; |
2255 | print CLIENTCONF "cert $confighash{$cgiparams{'KEY'}}[1]cert.pem\r\n"; | |
2256 | print CLIENTCONF "key $confighash{$cgiparams{'KEY'}}[1].key\r\n"; | |
2257 | $zip->addFile( "${General::swroot}/ovpn/ca/cacert.pem", "cacert.pem") or die "Can't add file cacert.pem\n"; | |
66c36198 | 2258 | $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 |
2259 | } |
2260 | print CLIENTCONF "cipher $vpnsettings{DCIPHER}\r\n"; | |
49abe7af | 2261 | print CLIENTCONF "auth $vpnsettings{'DAUTH'}\r\n"; |
86308adb | 2262 | |
49abe7af | 2263 | if ($vpnsettings{'TLSAUTH'} eq 'on') { |
b22d8aaf MT |
2264 | if ($cgiparams{'MODE'} eq 'insecure') { |
2265 | print CLIENTCONF ";"; | |
2266 | } | |
4be45949 EK |
2267 | print CLIENTCONF "tls-auth ta.key\r\n"; |
2268 | $zip->addFile( "${General::swroot}/ovpn/certs/ta.key", "ta.key") or die "Can't add file ta.key\n"; | |
49abe7af | 2269 | } |
6e13d0a5 MT |
2270 | if ($vpnsettings{DCOMPLZO} eq 'on') { |
2271 | print CLIENTCONF "comp-lzo\r\n"; | |
2272 | } | |
2273 | print CLIENTCONF "verb 3\r\n"; | |
b66b02ab EK |
2274 | # Check host certificate if X509 is RFC3280 compliant. |
2275 | # If not, old --ns-cert-type directive will be used. | |
2276 | # If appropriate key usage extension exists, new --remote-cert-tls directive will be used. | |
2feacd98 SS |
2277 | my @hostcert = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
2278 | if (! grep(/TLS Web Server Authentication/, @hostcert)) { | |
b66b02ab EK |
2279 | print CLIENTCONF "ns-cert-type server\r\n"; |
2280 | } else { | |
2281 | print CLIENTCONF "remote-cert-tls server\r\n"; | |
2282 | } | |
964700d4 | 2283 | print CLIENTCONF "verify-x509-name $vpnsettings{ROOTCERT_HOSTNAME} name\r\n"; |
a79fa1d6 JPT |
2284 | if ($vpnsettings{MSSFIX} eq 'on') { |
2285 | print CLIENTCONF "mssfix\r\n"; | |
d6989b4b MT |
2286 | } else { |
2287 | print CLIENTCONF "mssfix 0\r\n"; | |
a79fa1d6 | 2288 | } |
74225cce | 2289 | if ($vpnsettings{FRAGMENT} ne '' && $vpnsettings{DPROTOCOL} ne 'tcp' ) { |
a79fa1d6 JPT |
2290 | print CLIENTCONF "fragment $vpnsettings{'FRAGMENT'}\r\n"; |
2291 | } | |
a9998867 MT |
2292 | |
2293 | # Disable storing any credentials in memory | |
2294 | print CLIENTCONF "auth-nocache\r\n"; | |
2295 | ||
2296 | # Set a fake user name for authentication | |
2297 | print CLIENTCONF "auth-token-user USER\r\n"; | |
2298 | print CLIENTCONF "auth-token TOTP\r\n"; | |
2299 | ||
2300 | # If the server is asking for TOTP this needs to happen interactively | |
2301 | print CLIENTCONF "auth-retry interact\r\n"; | |
1647059d | 2302 | |
b22d8aaf MT |
2303 | if ($include_certs) { |
2304 | print CLIENTCONF "\r\n"; | |
2305 | ||
2306 | # CA | |
2307 | open(FILE, "<${General::swroot}/ovpn/ca/cacert.pem"); | |
2308 | print CLIENTCONF "<ca>\r\n"; | |
2309 | while (<FILE>) { | |
2310 | chomp($_); | |
2311 | print CLIENTCONF "$_\r\n"; | |
2312 | } | |
2313 | print CLIENTCONF "</ca>\r\n\r\n"; | |
2314 | close(FILE); | |
2315 | ||
2316 | # Cert | |
2317 | open(FILE, "<$file_crt"); | |
2318 | print CLIENTCONF "<cert>\r\n"; | |
2319 | while (<FILE>) { | |
2320 | chomp($_); | |
2321 | print CLIENTCONF "$_\r\n"; | |
2322 | } | |
2323 | print CLIENTCONF "</cert>\r\n\r\n"; | |
2324 | close(FILE); | |
2325 | ||
2326 | # Key | |
2327 | open(FILE, "<$file_key"); | |
2328 | print CLIENTCONF "<key>\r\n"; | |
2329 | while (<FILE>) { | |
2330 | chomp($_); | |
2331 | print CLIENTCONF "$_\r\n"; | |
2332 | } | |
2333 | print CLIENTCONF "</key>\r\n\r\n"; | |
2334 | close(FILE); | |
2335 | ||
2336 | # TLS auth | |
2337 | if ($vpnsettings{'TLSAUTH'} eq 'on') { | |
2338 | open(FILE, "<${General::swroot}/ovpn/certs/ta.key"); | |
2339 | print CLIENTCONF "<tls-auth>\r\n"; | |
2340 | while (<FILE>) { | |
2341 | chomp($_); | |
2342 | print CLIENTCONF "$_\r\n"; | |
2343 | } | |
2344 | print CLIENTCONF "</tls-auth>\r\n\r\n"; | |
2345 | close(FILE); | |
2346 | } | |
2347 | } | |
2348 | ||
ffbe77c8 EK |
2349 | # Print client.conf.local if entries exist to client.ovpn |
2350 | if (!-z $local_clientconf && $vpnsettings{'ADDITIONAL_CONFIGS'} eq 'on') { | |
2351 | open (LCC, "$local_clientconf"); | |
2352 | print CLIENTCONF "\n#---------------------------\n"; | |
2353 | print CLIENTCONF "# Start of custom directives\n"; | |
2354 | print CLIENTCONF "# from client.conf.local\n"; | |
2355 | print CLIENTCONF "#---------------------------\n\n"; | |
2356 | while (<LCC>) { | |
2357 | print CLIENTCONF $_; | |
2358 | } | |
2359 | print CLIENTCONF "\n#---------------------------\n"; | |
2360 | print CLIENTCONF "# End of custom directives\n"; | |
2361 | print CLIENTCONF "#---------------------------\n\n"; | |
2362 | close (LCC); | |
2363 | } | |
6e13d0a5 | 2364 | close(CLIENTCONF); |
66c36198 | 2365 | |
6e13d0a5 MT |
2366 | $zip->addFile( "$tempdir/$clientovpn", $clientovpn) or die "Can't add file $clientovpn\n"; |
2367 | my $status = $zip->writeToFileNamed($zippathname); | |
2368 | ||
2369 | open(DLFILE, "<$zippathname") or die "Unable to open $zippathname: $!"; | |
2370 | @fileholder = <DLFILE>; | |
2371 | print "Content-Type:application/x-download\n"; | |
2372 | print "Content-Disposition:attachment;filename=$zipname\n\n"; | |
2373 | print @fileholder; | |
2374 | exit (0); | |
ce9abb66 | 2375 | } |
66c36198 PM |
2376 | |
2377 | ||
2378 | ||
6e13d0a5 MT |
2379 | ### |
2380 | ### Remove connection | |
2381 | ### | |
ce9abb66 AH |
2382 | |
2383 | ||
6e13d0a5 | 2384 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'remove'}) { |
323be7c4 AM |
2385 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
2386 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 2387 | |
323be7c4 | 2388 | if ($confighash{$cgiparams{'KEY'}}) { |
fde9c9dd | 2389 | # Revoke certificate if certificate was deleted and rewrite the CRL |
274ca65b | 2390 | &General::system("/usr/bin/openssl", "ca", "-revoke", "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem", "-config", "${General::swroot}/ovpn/openssl/ovpn.cnf"); |
2feacd98 | 2391 | &General::system("/usr/bin/openssl", "ca", "-gencrl", "-out", "${General::swroot}/ovpn/crls/cacrl.pem", "-config", "${General::swroot}/ovpn/openssl/ovpn.cnf"); |
ce9abb66 AH |
2392 | |
2393 | ### | |
7c1d9faf | 2394 | # m.a.d net2net |
ce9abb66 | 2395 | ### |
7c1d9faf | 2396 | |
323be7c4 | 2397 | if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { |
1e499e90 | 2398 | # Stop the N2N connection before it is removed |
2feacd98 | 2399 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
1e499e90 | 2400 | |
323be7c4 AM |
2401 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); |
2402 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2403 | unlink ($certfile); | |
2404 | unlink ($conffile); | |
8e6a8fd5 | 2405 | |
323be7c4 AM |
2406 | if (-e "${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") { |
2407 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
2408 | } | |
323be7c4 | 2409 | } |
ce9abb66 | 2410 | |
323be7c4 AM |
2411 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
2412 | unlink ("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
8c877a82 AM |
2413 | |
2414 | # A.Marx CCD delete ccd files and routes | |
2415 | ||
323be7c4 AM |
2416 | if (-f "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]") |
2417 | { | |
2418 | unlink "${General::swroot}/ovpn/ccd/$confighash{$cgiparams{'KEY'}}[2]"; | |
8c877a82 | 2419 | } |
66c36198 | 2420 | |
323be7c4 AM |
2421 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
2422 | foreach my $key (keys %ccdroutehash) { | |
2423 | if ($ccdroutehash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2424 | delete $ccdroutehash{$key}; | |
2425 | } | |
8c877a82 | 2426 | } |
323be7c4 | 2427 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
66c36198 | 2428 | |
323be7c4 AM |
2429 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
2430 | foreach my $key (keys %ccdroute2hash) { | |
2431 | if ($ccdroute2hash{$key}[0] eq $confighash{$cgiparams{'KEY'}}[1]){ | |
2432 | delete $ccdroute2hash{$key}; | |
2433 | } | |
2434 | } | |
2435 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); | |
2436 | &writeserverconf; | |
8c877a82 | 2437 | |
323be7c4 AM |
2438 | # CCD end |
2439 | # Update collectd configuration and delete all RRD files of the removed connection | |
2440 | &writecollectdconf(); | |
2feacd98 | 2441 | &General::system("/usr/local/bin/openvpnctrl", "-drrd", "$confighash{$cgiparams{'KEY'}}[1]"); |
8c877a82 | 2442 | |
323be7c4 | 2443 | delete $confighash{$cgiparams{'KEY'}}; |
2feacd98 | 2444 | &General::system("/usr/bin/openssl", "ca", "-gencrl", "-out", "${General::swroot}/ovpn/crls/cacrl.pem", "-config", "${General::swroot}/ovpn/openssl/ovpn.cnf"); |
323be7c4 AM |
2445 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2446 | ||
2447 | } else { | |
2448 | $errormessage = $Lang::tr{'invalid key'}; | |
2449 | } | |
b2e75449 | 2450 | &General::firewall_reload(); |
ce9abb66 | 2451 | |
6e13d0a5 MT |
2452 | ### |
2453 | ### Download PKCS12 file | |
2454 | ### | |
2455 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download pkcs12 file'}) { | |
2456 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2457 | ||
2458 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . ".p12\r\n"; | |
2459 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2feacd98 SS |
2460 | |
2461 | open(FILE, "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
2462 | my @tmp = <FILE>; | |
2463 | close(FILE); | |
2464 | ||
f158e71e | 2465 | print @tmp; |
6e13d0a5 MT |
2466 | exit (0); |
2467 | ||
2468 | ### | |
2469 | ### Display certificate | |
2470 | ### | |
2471 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show certificate'}) { | |
2472 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2473 | ||
2474 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { | |
c6c9630e | 2475 | &Header::showhttpheaders(); |
4c962356 | 2476 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
c6c9630e MT |
2477 | &Header::openbigbox('100%', 'LEFT', '', ''); |
2478 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate'}:"); | |
2feacd98 | 2479 | my @output = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); |
8c946d1c MT |
2480 | my $output = &Header::cleanhtml(join("", @output), "y"); |
2481 | print "<pre>$output</pre>\n"; | |
c6c9630e MT |
2482 | &Header::closebox(); |
2483 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2484 | &Header::closebigbox(); | |
2485 | &Header::closepage(); | |
2486 | exit(0); | |
6e13d0a5 | 2487 | } |
4c962356 | 2488 | |
e1e10515 TE |
2489 | ### |
2490 | ### Display OTP QRCode | |
2491 | ### | |
2492 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show otp qrcode'}) { | |
2493 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
2494 | ||
e1e10515 TE |
2495 | my $qrcode = Imager::QRCode->new( |
2496 | size => 6, | |
2497 | margin => 0, | |
2498 | version => 0, | |
2499 | level => 'M', | |
2500 | mode => '8-bit', | |
2501 | casesensitive => 1, | |
2502 | lightcolor => Imager::Color->new(255, 255, 255), | |
2503 | darkcolor => Imager::Color->new(0, 0, 0), | |
2504 | ); | |
3740b7ad | 2505 | my $cn = uri_encode($confighash{$cgiparams{'KEY'}}[2]); |
10b32d38 | 2506 | my $secret = encode_base32(pack('H*', $confighash{$cgiparams{'KEY'}}[44])); |
3740b7ad | 2507 | my $issuer = uri_encode("$mainsettings{'HOSTNAME'}.$mainsettings{'DOMAINNAME'}"); |
e1e10515 TE |
2508 | my $qrcodeimg = $qrcode->plot("otpauth://totp/$cn?secret=$secret&issuer=$issuer"); |
2509 | my $qrcodeimgdata; | |
2510 | $qrcodeimg->write(data => \$qrcodeimgdata, type=> 'png') | |
2511 | or die $qrcodeimg->errstr; | |
2512 | $qrcodeimgdata = encode_base64($qrcodeimgdata, ''); | |
2513 | ||
2514 | &Header::showhttpheaders(); | |
2515 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2516 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2517 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'otp qrcode'}:"); | |
2518 | print <<END; | |
2519 | $Lang::tr{'secret'}: $secret</br></br> | |
2520 | <img alt="$Lang::tr{'otp qrcode'}" src="data:image/png;base64,$qrcodeimgdata"> | |
2521 | END | |
2522 | &Header::closebox(); | |
2523 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2524 | &Header::closebigbox(); | |
2525 | &Header::closepage(); | |
2526 | exit(0); | |
2527 | ||
4c962356 EK |
2528 | ### |
2529 | ### Display Diffie-Hellman key | |
2530 | ### | |
2531 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show dh'}) { | |
2532 | ||
35494eac | 2533 | if (! -e "$dhparameter") { |
49abe7af | 2534 | $errormessage = $Lang::tr{'not present'}; |
4c962356 EK |
2535 | } else { |
2536 | &Header::showhttpheaders(); | |
2537 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2538 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2539 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'dh'}:"); | |
35494eac | 2540 | my @output = &General::system_output("/usr/bin/openssl", "dhparam", "-text", "-in", "$dhparameter"); |
8c946d1c MT |
2541 | my $output = &Header::cleanhtml(join("", @output) ,"y"); |
2542 | print "<pre>$output</pre>\n"; | |
4c962356 EK |
2543 | &Header::closebox(); |
2544 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2545 | &Header::closebigbox(); | |
2546 | &Header::closepage(); | |
2547 | exit(0); | |
2548 | } | |
2549 | ||
fd5ccb2d EK |
2550 | ### |
2551 | ### Display tls-auth key | |
2552 | ### | |
2553 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show tls-auth key'}) { | |
2554 | ||
2555 | if (! -e "${General::swroot}/ovpn/certs/ta.key") { | |
2556 | $errormessage = $Lang::tr{'not present'}; | |
2557 | } else { | |
2558 | &Header::showhttpheaders(); | |
2559 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2560 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2561 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ta key'}:"); | |
2feacd98 SS |
2562 | |
2563 | open(FILE, "${General::swroot}/ovpn/certs/ta.key"); | |
2564 | my @output = <FILE>; | |
2565 | close(FILE); | |
2566 | ||
8c946d1c MT |
2567 | my $output = &Header::cleanhtml(join("", @output),"y"); |
2568 | print "<pre>$output</pre>\n"; | |
fd5ccb2d EK |
2569 | &Header::closebox(); |
2570 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2571 | &Header::closebigbox(); | |
2572 | &Header::closepage(); | |
2573 | exit(0); | |
2574 | } | |
2575 | ||
6e13d0a5 MT |
2576 | ### |
2577 | ### Display Certificate Revoke List | |
2578 | ### | |
2579 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'show crl'}) { | |
c6c9630e MT |
2580 | # &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
2581 | ||
49abe7af EK |
2582 | if (! -e "${General::swroot}/ovpn/crls/cacrl.pem") { |
2583 | $errormessage = $Lang::tr{'not present'}; | |
2584 | } else { | |
b2e75449 MT |
2585 | &Header::showhttpheaders(); |
2586 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); | |
2587 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2588 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'crl'}:"); | |
2feacd98 | 2589 | my @output = &General::system_output("/usr/bin/openssl", "crl", "-text", "-noout", "-in", "${General::swroot}/ovpn/crls/cacrl.pem"); |
8c946d1c MT |
2590 | my $output = &Header::cleanhtml(join("", @output), "y"); |
2591 | print "<pre>$output</pre>\n"; | |
b2e75449 MT |
2592 | &Header::closebox(); |
2593 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2594 | &Header::closebigbox(); | |
2595 | &Header::closepage(); | |
2596 | exit(0); | |
6e13d0a5 MT |
2597 | } |
2598 | ||
2599 | ### | |
2600 | ### Advanced Server Settings | |
2601 | ### | |
2602 | ||
2603 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'advanced server'}) { | |
2604 | %cgiparams = (); | |
2605 | %cahash = (); | |
2606 | %confighash = (); | |
8c877a82 | 2607 | my $disabled; |
6e13d0a5 | 2608 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); |
54fd0535 | 2609 | read_routepushfile; |
66c36198 PM |
2610 | |
2611 | ||
c6c9630e | 2612 | # if ($cgiparams{'CLIENT2CLIENT'} eq '') { |
66c36198 | 2613 | # $cgiparams{'CLIENT2CLIENT'} = 'on'; |
c6c9630e | 2614 | # } |
6e13d0a5 MT |
2615 | ADV_ERROR: |
2616 | if ($cgiparams{'MAX_CLIENTS'} eq '') { | |
4c962356 | 2617 | $cgiparams{'MAX_CLIENTS'} = '100'; |
6e13d0a5 | 2618 | } |
6e13d0a5 | 2619 | if ($cgiparams{'KEEPALIVE_1'} eq '') { |
4c962356 | 2620 | $cgiparams{'KEEPALIVE_1'} = '10'; |
6e13d0a5 MT |
2621 | } |
2622 | if ($cgiparams{'KEEPALIVE_2'} eq '') { | |
4c962356 | 2623 | $cgiparams{'KEEPALIVE_2'} = '60'; |
6e13d0a5 MT |
2624 | } |
2625 | if ($cgiparams{'LOG_VERB'} eq '') { | |
4c962356 | 2626 | $cgiparams{'LOG_VERB'} = '3'; |
ae9f6139 | 2627 | } |
f527e53f | 2628 | if ($cgiparams{'TLSAUTH'} eq '') { |
754066e6 | 2629 | $cgiparams{'TLSAUTH'} = 'off'; |
f527e53f | 2630 | } |
6e13d0a5 MT |
2631 | $checked{'CLIENT2CLIENT'}{'off'} = ''; |
2632 | $checked{'CLIENT2CLIENT'}{'on'} = ''; | |
2633 | $checked{'CLIENT2CLIENT'}{$cgiparams{'CLIENT2CLIENT'}} = 'CHECKED'; | |
2634 | $checked{'REDIRECT_GW_DEF1'}{'off'} = ''; | |
2635 | $checked{'REDIRECT_GW_DEF1'}{'on'} = ''; | |
2636 | $checked{'REDIRECT_GW_DEF1'}{$cgiparams{'REDIRECT_GW_DEF1'}} = 'CHECKED'; | |
13389777 EK |
2637 | $checked{'DCOMPLZO'}{'off'} = ''; |
2638 | $checked{'DCOMPLZO'}{'on'} = ''; | |
2639 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
ffbe77c8 EK |
2640 | $checked{'ADDITIONAL_CONFIGS'}{'off'} = ''; |
2641 | $checked{'ADDITIONAL_CONFIGS'}{'on'} = ''; | |
2642 | $checked{'ADDITIONAL_CONFIGS'}{$cgiparams{'ADDITIONAL_CONFIGS'}} = 'CHECKED'; | |
a79fa1d6 JPT |
2643 | $checked{'MSSFIX'}{'off'} = ''; |
2644 | $checked{'MSSFIX'}{'on'} = ''; | |
2645 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
49abe7af | 2646 | $selected{'LOG_VERB'}{'0'} = ''; |
6e13d0a5 MT |
2647 | $selected{'LOG_VERB'}{'1'} = ''; |
2648 | $selected{'LOG_VERB'}{'2'} = ''; | |
2649 | $selected{'LOG_VERB'}{'3'} = ''; | |
2650 | $selected{'LOG_VERB'}{'4'} = ''; | |
2651 | $selected{'LOG_VERB'}{'5'} = ''; | |
2652 | $selected{'LOG_VERB'}{'6'} = ''; | |
2653 | $selected{'LOG_VERB'}{'7'} = ''; | |
2654 | $selected{'LOG_VERB'}{'8'} = ''; | |
2655 | $selected{'LOG_VERB'}{'9'} = ''; | |
2656 | $selected{'LOG_VERB'}{'10'} = ''; | |
2657 | $selected{'LOG_VERB'}{'11'} = ''; | |
6e13d0a5 | 2658 | $selected{'LOG_VERB'}{$cgiparams{'LOG_VERB'}} = 'SELECTED'; |
66c36198 | 2659 | |
6e13d0a5 MT |
2660 | &Header::showhttpheaders(); |
2661 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
66c36198 | 2662 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
6e13d0a5 | 2663 | if ($errormessage) { |
c6c9630e MT |
2664 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
2665 | print "<class name='base'>$errormessage\n"; | |
2666 | print " </class>\n"; | |
2667 | &Header::closebox(); | |
6e13d0a5 MT |
2668 | } |
2669 | &Header::openbox('100%', 'LEFT', $Lang::tr{'advanced server'}); | |
4c962356 | 2670 | print <<END; |
b376fae4 | 2671 | <form method='post' enctype='multipart/form-data'> |
b2e75449 | 2672 | <table width='100%' border=0> |
4c962356 EK |
2673 | <tr> |
2674 | <td colspan='4'><b>$Lang::tr{'dhcp-options'}</b></td> | |
6e13d0a5 MT |
2675 | </tr> |
2676 | <tr> | |
4c962356 | 2677 | <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td> |
66c36198 PM |
2678 | </tr> |
2679 | <tr> | |
4c962356 | 2680 | <td class='base'>Domain</td> |
8c877a82 | 2681 | <td><input type='TEXT' name='DHCP_DOMAIN' value='$cgiparams{'DHCP_DOMAIN'}' size='30' /></td> |
6e13d0a5 | 2682 | </tr> |
66c36198 | 2683 | <tr> |
4c962356 EK |
2684 | <td class='base'>DNS</td> |
2685 | <td><input type='TEXT' name='DHCP_DNS' value='$cgiparams{'DHCP_DNS'}' size='30' /></td> | |
66c36198 PM |
2686 | </tr> |
2687 | <tr> | |
4c962356 EK |
2688 | <td class='base'>WINS</td> |
2689 | <td><input type='TEXT' name='DHCP_WINS' value='$cgiparams{'DHCP_WINS'}' size='30' /></td> | |
2690 | </tr> | |
54fd0535 | 2691 | <tr> |
4c962356 | 2692 | <td colspan='4'><b>$Lang::tr{'ovpn routes push options'}</b></td> |
54fd0535 | 2693 | </tr> |
66c36198 | 2694 | <tr> |
4c962356 EK |
2695 | <td class='base'>$Lang::tr{'ovpn routes push'}</td> |
2696 | <td colspan='2'> | |
2697 | <textarea name='ROUTES_PUSH' cols='26' rows='6' wrap='off'> | |
54fd0535 MT |
2698 | END |
2699 | ; | |
2700 | ||
2701 | if ($cgiparams{'ROUTES_PUSH'} ne '') | |
2702 | { | |
2703 | print $cgiparams{'ROUTES_PUSH'}; | |
2704 | } | |
2705 | ||
8c877a82 | 2706 | print <<END; |
54fd0535 MT |
2707 | </textarea></td> |
2708 | </tr> | |
6e13d0a5 MT |
2709 | </tr> |
2710 | </table> | |
2711 | <hr size='1'> | |
4c962356 | 2712 | <table width='100%'> |
ffbe77c8 | 2713 | <tr> |
f99ed824 | 2714 | <td class='base'><b>$Lang::tr{'misc-options'}</b></td> |
ffbe77c8 EK |
2715 | </tr> |
2716 | ||
2717 | <tr> | |
d2de0a00 | 2718 | <td width='20%'></td> <td width='15%'> </td><td width='35%'> </td><td width='20%'></td><td width='35%'></td> |
ffbe77c8 EK |
2719 | </tr> |
2720 | ||
2721 | <tr> | |
4c962356 EK |
2722 | <td class='base'>Client-To-Client</td> |
2723 | <td><input type='checkbox' name='CLIENT2CLIENT' $checked{'CLIENT2CLIENT'}{'on'} /></td> | |
ffbe77c8 EK |
2724 | </tr> |
2725 | ||
2726 | <tr> | |
4c962356 EK |
2727 | <td class='base'>Redirect-Gateway def1</td> |
2728 | <td><input type='checkbox' name='REDIRECT_GW_DEF1' $checked{'REDIRECT_GW_DEF1'}{'on'} /></td> | |
ffbe77c8 EK |
2729 | </tr> |
2730 | ||
13389777 EK |
2731 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
2732 | <td><input type='checkbox' name='DCOMPLZO' $checked{'DCOMPLZO'}{'on'} /></td> | |
2733 | <td>$Lang::tr{'openvpn default'}: off <font color='red'>($Lang::tr{'attention'} exploitable via Voracle)</font></td> | |
2734 | </tr> | |
2735 | ||
4c962356 | 2736 | <tr> |
ffbe77c8 EK |
2737 | <td class='base'>$Lang::tr{'ovpn add conf'}</td> |
2738 | <td><input type='checkbox' name='ADDITIONAL_CONFIGS' $checked{'ADDITIONAL_CONFIGS'}{'on'} /></td> | |
2739 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2740 | </tr> | |
2741 | ||
2742 | <tr> | |
2743 | <td class='base'>mssfix</td> | |
2744 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> | |
2745 | <td>$Lang::tr{'openvpn default'}: off</td> | |
2746 | </tr> | |
2747 | ||
4c962356 | 2748 | <tr> |
ffbe77c8 EK |
2749 | <td class='base'>fragment <br></td> |
2750 | <td><input type='TEXT' name='FRAGMENT' value='$cgiparams{'FRAGMENT'}' size='10' /></td> | |
2751 | </tr> | |
2752 | ||
2753 | ||
2754 | <tr> | |
2755 | <td class='base'>Max-Clients</td> | |
2756 | <td><input type='text' name='MAX_CLIENTS' value='$cgiparams{'MAX_CLIENTS'}' size='10' /></td> | |
2757 | </tr> | |
2758 | <tr> | |
2759 | <td class='base'>Keepalive <br /> | |
2760 | (ping/ping-restart)</td> | |
2761 | <td><input type='TEXT' name='KEEPALIVE_1' value='$cgiparams{'KEEPALIVE_1'}' size='10' /></td> | |
2762 | <td><input type='TEXT' name='KEEPALIVE_2' value='$cgiparams{'KEEPALIVE_2'}' size='10' /></td> | |
2763 | </tr> | |
a79fa1d6 JPT |
2764 | </table> |
2765 | ||
a79fa1d6 | 2766 | <hr size='1'> |
4c962356 | 2767 | <table width='100%'> |
a79fa1d6 | 2768 | <tr> |
f99ed824 | 2769 | <td class='base'><b>$Lang::tr{'log-options'}</b></td> |
a79fa1d6 JPT |
2770 | </tr> |
2771 | <tr> | |
49abe7af | 2772 | <td width='20%'></td> <td width='30%'> </td><td width='25%'> </td><td width='25%'></td> |
4c962356 EK |
2773 | </tr> |
2774 | ||
2775 | <tr><td class='base'>VERB</td> | |
2776 | <td><select name='LOG_VERB'> | |
49abe7af EK |
2777 | <option value='0' $selected{'LOG_VERB'}{'0'}>0</option> |
2778 | <option value='1' $selected{'LOG_VERB'}{'1'}>1</option> | |
2779 | <option value='2' $selected{'LOG_VERB'}{'2'}>2</option> | |
2780 | <option value='3' $selected{'LOG_VERB'}{'3'}>3</option> | |
2781 | <option value='4' $selected{'LOG_VERB'}{'4'}>4</option> | |
2782 | <option value='5' $selected{'LOG_VERB'}{'5'}>5</option> | |
2783 | <option value='6' $selected{'LOG_VERB'}{'6'}>6</option> | |
2784 | <option value='7' $selected{'LOG_VERB'}{'7'}>7</option> | |
2785 | <option value='8' $selected{'LOG_VERB'}{'8'}>8</option> | |
2786 | <option value='9' $selected{'LOG_VERB'}{'9'}>9</option> | |
2787 | <option value='10' $selected{'LOG_VERB'}{'10'}>10</option> | |
2788 | <option value='11' $selected{'LOG_VERB'}{'11'}>11</option> | |
2789 | </td></select> | |
2790 | </table> | |
4c962356 | 2791 | |
6e13d0a5 | 2792 | <hr size='1'> |
8c877a82 AM |
2793 | END |
2794 | ||
2795 | if ( -e "/var/run/openvpn.pid"){ | |
2796 | print" <br><b><font color='#990000'>$Lang::tr{'attention'}:</b></font><br> | |
2797 | $Lang::tr{'server restart'}<br><br> | |
2798 | <hr>"; | |
49abe7af | 2799 | print<<END; |
52d08bcb AM |
2800 | <table width='100%'> |
2801 | <tr> | |
2802 | <td> </td> | |
2803 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' disabled='disabled' /></td> | |
2804 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
66c36198 | 2805 | <td> </td> |
52d08bcb | 2806 | </tr> |
66c36198 | 2807 | </table> |
52d08bcb AM |
2808 | </form> |
2809 | END | |
66c36198 PM |
2810 | ; |
2811 | ||
2812 | ||
52d08bcb | 2813 | }else{ |
8c877a82 | 2814 | |
49abe7af | 2815 | print<<END; |
6e13d0a5 MT |
2816 | <table width='100%'> |
2817 | <tr> | |
2818 | <td> </td> | |
2819 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'save-adv-options'}' /></td> | |
2820 | <td allign='center'><input type='submit' name='ACTION' value='$Lang::tr{'cancel-adv-options'}' /></td> | |
66c36198 | 2821 | <td> </td> |
6e13d0a5 | 2822 | </tr> |
66c36198 | 2823 | </table> |
6e13d0a5 MT |
2824 | </form> |
2825 | END | |
66c36198 | 2826 | ; |
52d08bcb | 2827 | } |
6e13d0a5 | 2828 | &Header::closebox(); |
c6c9630e | 2829 | # print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
6e13d0a5 MT |
2830 | &Header::closebigbox(); |
2831 | &Header::closepage(); | |
2832 | exit(0); | |
66c36198 | 2833 | |
8c877a82 AM |
2834 | |
2835 | # A.Marx CCD Add,delete or edit CCD net | |
2836 | ||
66c36198 PM |
2837 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ccd net'} || |
2838 | $cgiparams{'ACTION'} eq $Lang::tr{'ccd add'} || | |
2839 | $cgiparams{'ACTION'} eq "kill" || | |
8c877a82 AM |
2840 | $cgiparams{'ACTION'} eq "edit" || |
2841 | $cgiparams{'ACTION'} eq 'editsave'){ | |
2842 | &Header::showhttpheaders(); | |
2843 | &Header::openpage($Lang::tr{'ccd net'}, 1, ''); | |
2844 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2845 | ||
2846 | if ($cgiparams{'ACTION'} eq "kill"){ | |
2847 | &delccdnet($cgiparams{'net'}); | |
2848 | } | |
66c36198 | 2849 | |
8c877a82 AM |
2850 | if ($cgiparams{'ACTION'} eq 'editsave'){ |
2851 | my ($a,$b) =split (/\|/,$cgiparams{'ccdname'}); | |
2852 | if ( $a ne $b){ &modccdnet($a,$b);} | |
5068ac38 AM |
2853 | $cgiparams{'ccdname'}=''; |
2854 | $cgiparams{'ccdsubnet'}=''; | |
8c877a82 | 2855 | } |
66c36198 | 2856 | |
8c877a82 | 2857 | if ($cgiparams{'ACTION'} eq $Lang::tr{'ccd add'}) { |
e2429e8d | 2858 | &addccdnet($cgiparams{'ccdname'},$cgiparams{'ccdsubnet'}); |
8c877a82 AM |
2859 | } |
2860 | if ($errormessage) { | |
2861 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
2862 | print "<class name='base'>$errormessage"; | |
2863 | print " </class>"; | |
66c36198 | 2864 | &Header::closebox(); |
8c877a82 AM |
2865 | } |
2866 | if ($cgiparams{'ACTION'} eq "edit"){ | |
66c36198 | 2867 | |
8c877a82 AM |
2868 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd modify'}); |
2869 | ||
49abe7af | 2870 | print <<END; |
631b67b7 | 2871 | <table width='100%' border='0'> |
8c877a82 AM |
2872 | <tr><form method='post'> |
2873 | <td width='10%' nowrap='nowrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
a9fb14d0 | 2874 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' readonly='readonly' /></td></tr> |
8c877a82 AM |
2875 | <tr><td colspan='4' align='right'><hr><input type='submit' value='$Lang::tr{'save'}' /><input type='hidden' name='ACTION' value='editsave'/> |
2876 | <input type='hidden' name='ccdname' value='$cgiparams{'ccdname'}'/><input type='submit' value='$Lang::tr{'cancel'}' /> | |
2877 | </td></tr> | |
2878 | </table></form> | |
2879 | END | |
2880 | ; | |
2881 | &Header::closebox(); | |
2882 | ||
2883 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
49abe7af | 2884 | print <<END; |
8c877a82 AM |
2885 | <table width='100%' border='0' cellpadding='0' cellspacing='1'> |
2886 | <tr> | |
2887 | <td class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' width='15%' align='center'><b>$Lang::tr{'ccd used'}</td><td width='3%'></td><td width='3%'></td></tr> | |
2888 | END | |
2889 | ; | |
2890 | } | |
2891 | else{ | |
2892 | if (! -e "/var/run/openvpn.pid"){ | |
2893 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ccd add'}); | |
49abe7af | 2894 | print <<END; |
8c877a82 AM |
2895 | <table width='100%' border='0'> |
2896 | <tr><form method='post'> | |
2897 | <td colspan='4'>$Lang::tr{'ccd hint'}<br><br></td></tr> | |
2898 | <tr> | |
2899 | <td width='10%' nowrap='nwrap'>$Lang::tr{'ccd name'}:</td><td><input type='TEXT' name='ccdname' value='$cgiparams{'ccdname'}' /></td> | |
2900 | <td width='8%'>$Lang::tr{'ccd subnet'}:</td><td><input type='TEXT' name='ccdsubnet' value='$cgiparams{'ccdsubnet'}' /></td></tr> | |
2901 | <tr><td colspan=4><hr /></td></tr><tr> | |
2902 | <td colspan='4' align='right'><input type='hidden' name='ACTION' value='$Lang::tr{'ccd add'}' /><input type='submit' value='$Lang::tr{'add'}' /><input type='hidden' name='DOVPN_SUBNET' value='$cgiparams{'DOVPN_SUBNET'}'/></td></tr> | |
2903 | </table></form> | |
2904 | END | |
66c36198 | 2905 | |
8c877a82 AM |
2906 | &Header::closebox(); |
2907 | } | |
2908 | &Header::openbox('100%', 'LEFT',$Lang::tr{'ccd net'} ); | |
5068ac38 AM |
2909 | if ( -e "/var/run/openvpn.pid"){ |
2910 | print "<b>$Lang::tr{'attention'}:</b><br>"; | |
2911 | print "$Lang::tr{'ccd noaddnet'}<br><hr>"; | |
2912 | } | |
66c36198 | 2913 | |
4c962356 | 2914 | print <<END; |
99bfa85c | 2915 | <table width='100%' cellpadding='0' cellspacing='1'> |
8c877a82 AM |
2916 | <tr> |
2917 | <td class='boldbase' align='center' nowrap='nowrap' width='20%'><b>$Lang::tr{'ccd name'}</td><td class='boldbase' align='center' width='8%'><b>$Lang::tr{'network'}</td><td class='boldbase' width='8%' align='center' nowrap='nowrap'><b>$Lang::tr{'ccd used'}</td><td width='1%' align='center'></td><td width='1%' align='center'></td></tr> | |
2918 | END | |
2919 | ; | |
2920 | } | |
66c36198 PM |
2921 | my %ccdconfhash=(); |
2922 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
8c877a82 AM |
2923 | my @ccdconf=(); |
2924 | my $count=0; | |
df9b48b7 | 2925 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
2926 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); |
2927 | $count++; | |
2928 | my $ccdhosts = &hostsinnet($ccdconf[0]); | |
2929 | if ($count % 2){ print" <tr bgcolor='$color{'color22'}'>";} | |
2930 | else{ print" <tr bgcolor='$color{'color20'}'>";} | |
2931 | print"<td>$ccdconf[0]</td><td align='center'>$ccdconf[1]</td><td align='center'>$ccdhosts/".(&ccdmaxclients($ccdconf[1])+1)."</td><td>"; | |
4c962356 | 2932 | print <<END; |
8c877a82 | 2933 | <form method='post' /> |
1638682b | 2934 | <input type='image' src='/images/edit.gif' align='middle' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' /> |
8c877a82 AM |
2935 | <input type='hidden' name='ACTION' value='edit'/> |
2936 | <input type='hidden' name='ccdname' value='$ccdconf[0]' /> | |
2937 | <input type='hidden' name='ccdsubnet' value='$ccdconf[1]' /> | |
2938 | </form></td> | |
2939 | <form method='post' /> | |
2940 | <td><input type='hidden' name='ACTION' value='kill'/> | |
2941 | <input type='hidden' name='number' value='$count' /> | |
2942 | <input type='hidden' name='net' value='$ccdconf[0]' /> | |
1638682b | 2943 | <input type='image' src='/images/delete.gif' align='middle' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' /></form></td></tr> |
8c877a82 AM |
2944 | END |
2945 | ; | |
66c36198 | 2946 | } |
8c877a82 AM |
2947 | print "</table></form>"; |
2948 | &Header::closebox(); | |
2949 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
2950 | &Header::closebigbox(); | |
2951 | &Header::closepage(); | |
2952 | exit(0); | |
66c36198 | 2953 | |
8c877a82 AM |
2954 | #END CCD |
2955 | ||
6e13d0a5 MT |
2956 | ### |
2957 | ### Openvpn Connections Statistics | |
2958 | ### | |
2959 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'ovpn con stat'}) { | |
2960 | &Header::showhttpheaders(); | |
2961 | &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); | |
2962 | &Header::openbigbox('100%', 'LEFT', '', ''); | |
2963 | &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); | |
2964 | ||
2965 | # | |
2966 | # <td><b>$Lang::tr{'protocol'}</b></td> | |
66c36198 | 2967 | # protocol temp removed |
4c962356 | 2968 | print <<END; |
99bfa85c | 2969 | <table width='100%' cellpadding='2' cellspacing='0' class='tbl'> |
6e13d0a5 | 2970 | <tr> |
99bfa85c AM |
2971 | <th><b>$Lang::tr{'common name'}</b></th> |
2972 | <th><b>$Lang::tr{'real address'}</b></th> | |
d8ef6a95 | 2973 | <th><b>$Lang::tr{'country'}</b></th> |
99bfa85c AM |
2974 | <th><b>$Lang::tr{'virtual address'}</b></th> |
2975 | <th><b>$Lang::tr{'loged in at'}</b></th> | |
2976 | <th><b>$Lang::tr{'bytes sent'}</b></th> | |
2977 | <th><b>$Lang::tr{'bytes received'}</b></th> | |
2978 | <th><b>$Lang::tr{'last activity'}</b></th> | |
6e13d0a5 MT |
2979 | </tr> |
2980 | END | |
2981 | ; | |
87fe47e9 | 2982 | my $filename = "/var/run/ovpnserver.log"; |
6e13d0a5 MT |
2983 | open(FILE, $filename) or die 'Unable to open config file.'; |
2984 | my @current = <FILE>; | |
2985 | close(FILE); | |
2986 | my @users =(); | |
2987 | my $status; | |
2988 | my $uid = 0; | |
2989 | my $cn; | |
2990 | my @match = (); | |
2991 | my $proto = "udp"; | |
2992 | my $address; | |
2993 | my %userlookup = (); | |
2994 | foreach my $line (@current) | |
2995 | { | |
2996 | chomp($line); | |
2997 | if ( $line =~ /^Updated,(.+)/){ | |
66c36198 | 2998 | @match = split( /^Updated,(.+)/, $line); |
6e13d0a5 MT |
2999 | $status = $match[1]; |
3000 | } | |
66c36198 | 3001 | #gian |
6e13d0a5 MT |
3002 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { |
3003 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
3004 | if ($match[1] ne "Common Name") { | |
3005 | $cn = $match[1]; | |
3006 | $userlookup{$match[2]} = $uid; | |
3007 | $users[$uid]{'CommonName'} = $match[1]; | |
3008 | $users[$uid]{'RealAddress'} = $match[2]; | |
c6c9630e MT |
3009 | $users[$uid]{'BytesReceived'} = &sizeformat($match[3]); |
3010 | $users[$uid]{'BytesSent'} = &sizeformat($match[4]); | |
6e13d0a5 MT |
3011 | $users[$uid]{'Since'} = $match[5]; |
3012 | $users[$uid]{'Proto'} = $proto; | |
d8ef6a95 PM |
3013 | |
3014 | # get country code for "RealAddress"... | |
07e42be9 | 3015 | my $ccode = &Location::Functions::lookup_country_code((split ':', $users[$uid]{'RealAddress'})[0]); |
e2e270e1 | 3016 | my $flag_icon = &Location::Functions::get_flag_icon($ccode); |
d8ef6a95 | 3017 | $users[$uid]{'Country'} = "<a href='country.cgi#$ccode'><img src='$flag_icon' border='0' align='absmiddle' alt='$ccode' title='$ccode' /></a>"; |
6e13d0a5 | 3018 | $uid++; |
66c36198 | 3019 | } |
6e13d0a5 MT |
3020 | } |
3021 | if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { | |
3022 | @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); | |
3023 | if ($match[1] ne "Virtual Address") { | |
3024 | $address = $match[3]; | |
3025 | #find the uid in the lookup table | |
3026 | $uid = $userlookup{$address}; | |
3027 | $users[$uid]{'VirtualAddress'} = $match[1]; | |
3028 | $users[$uid]{'LastRef'} = $match[4]; | |
3029 | } | |
3030 | } | |
3031 | } | |
3032 | my $user2 = @users; | |
3033 | if ($user2 >= 1){ | |
99bfa85c | 3034 | for (my $idx = 1; $idx <= $user2; $idx++){ |
6e13d0a5 | 3035 | if ($idx % 2) { |
99bfa85c AM |
3036 | print "<tr>"; |
3037 | $col="bgcolor='$color{'color22'}'"; | |
3038 | } else { | |
3039 | print "<tr>"; | |
3040 | $col="bgcolor='$color{'color20'}'"; | |
6e13d0a5 | 3041 | } |
99bfa85c AM |
3042 | print "<td align='left' $col>$users[$idx-1]{'CommonName'}</td>"; |
3043 | print "<td align='left' $col>$users[$idx-1]{'RealAddress'}</td>"; | |
d8ef6a95 PM |
3044 | print "<td align='center' $col>$users[$idx-1]{'Country'}</td>"; |
3045 | print "<td align='center' $col>$users[$idx-1]{'VirtualAddress'}</td>"; | |
99bfa85c AM |
3046 | print "<td align='left' $col>$users[$idx-1]{'Since'}</td>"; |
3047 | print "<td align='left' $col>$users[$idx-1]{'BytesSent'}</td>"; | |
3048 | print "<td align='left' $col>$users[$idx-1]{'BytesReceived'}</td>"; | |
3049 | print "<td align='left' $col>$users[$idx-1]{'LastRef'}</td>"; | |
3050 | } | |
3051 | } | |
66c36198 | 3052 | |
6e13d0a5 | 3053 | print "</table>"; |
49abe7af | 3054 | print <<END; |
6e13d0a5 MT |
3055 | <table width='100%' border='0' cellpadding='2' cellspacing='0'> |
3056 | <tr><td></td></tr> | |
3057 | <tr><td></td></tr> | |
3058 | <tr><td></td></tr> | |
3059 | <tr><td></td></tr> | |
3060 | <tr><td align='center' >$Lang::tr{'the statistics were last updated at'} <b>$status</b></td></tr> | |
3061 | </table> | |
3062 | END | |
66c36198 | 3063 | ; |
6e13d0a5 MT |
3064 | &Header::closebox(); |
3065 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
3066 | &Header::closebigbox(); | |
3067 | &Header::closepage(); | |
3068 | exit(0); | |
3069 | ||
3070 | ### | |
3071 | ### Download Certificate | |
3072 | ### | |
3073 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'download certificate'}) { | |
3074 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
c6c9630e | 3075 | |
6e13d0a5 | 3076 | if ( -f "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem") { |
c6c9630e MT |
3077 | print "Content-Disposition: filename=" . $confighash{$cgiparams{'KEY'}}[1] . "cert.pem\r\n"; |
3078 | print "Content-Type: application/octet-stream\r\n\r\n"; | |
2feacd98 SS |
3079 | |
3080 | open(FILE, "${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1]cert.pem"); | |
3081 | my @tmp = <FILE>; | |
3082 | close(FILE); | |
3083 | ||
f158e71e | 3084 | print @tmp; |
c6c9630e MT |
3085 | exit (0); |
3086 | } | |
3087 | ||
3088 | ### | |
3089 | ### Enable/Disable connection | |
3090 | ### | |
ce9abb66 | 3091 | |
c6c9630e | 3092 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'toggle enable disable'}) { |
66c36198 | 3093 | |
c6c9630e MT |
3094 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
3095 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3096 | ||
3097 | if ($confighash{$cgiparams{'KEY'}}) { | |
ce9abb66 | 3098 | if ($confighash{$cgiparams{'KEY'}}[0] eq 'off') { |
c6c9630e MT |
3099 | $confighash{$cgiparams{'KEY'}}[0] = 'on'; |
3100 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3101 | #&writeserverconf(); | |
3102 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3103 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3104 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3105 | # } | |
3106 | } else { | |
3107 | $confighash{$cgiparams{'KEY'}}[0] = 'off'; | |
3108 | # if ($vpnsettings{'ENABLED'} eq 'on' || | |
3109 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3110 | # system('/usr/local/bin/ipsecctrl', 'D', $cgiparams{'KEY'}); | |
3111 | # } | |
3112 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3113 | #&writeserverconf(); | |
3114 | } | |
3115 | } else { | |
3116 | $errormessage = $Lang::tr{'invalid key'}; | |
6e13d0a5 MT |
3117 | } |
3118 | ||
3119 | ### | |
3120 | ### Restart connection | |
3121 | ### | |
3122 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'restart'}) { | |
3123 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3124 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3125 | ||
3126 | if ($confighash{$cgiparams{'KEY'}}) { | |
c6c9630e MT |
3127 | # if ($vpnsettings{'ENABLED'} eq 'on' || |
3128 | # $vpnsettings{'ENABLED_BLUE'} eq 'on') { | |
3129 | # system('/usr/local/bin/ipsecctrl', 'S', $cgiparams{'KEY'}); | |
3130 | # } | |
6e13d0a5 | 3131 | } else { |
c6c9630e | 3132 | $errormessage = $Lang::tr{'invalid key'}; |
6e13d0a5 MT |
3133 | } |
3134 | ||
ce9abb66 | 3135 | ### |
7c1d9faf | 3136 | # m.a.d net2net |
ce9abb66 AH |
3137 | ### |
3138 | ||
3139 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'add'} && $cgiparams{'TYPE'} eq '') { | |
3140 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); | |
3141 | &Header::showhttpheaders(); | |
4c962356 | 3142 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
ce9abb66 AH |
3143 | &Header::openbigbox('100%', 'LEFT', '', ''); |
3144 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection type'}); | |
b278daf3 AH |
3145 | |
3146 | if ( -s "${General::swroot}/ovpn/settings") { | |
3147 | ||
49abe7af | 3148 | print <<END; |
ce9abb66 | 3149 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3150 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
ce9abb66 AH |
3151 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> |
3152 | <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> | |
3153 | <tr><td><input type='radio' name='TYPE' value='net' /></td> | |
3154 | <td class='base'>$Lang::tr{'net to net vpn'}</td></tr> | |
66c36198 | 3155 | <tr><td><input type='radio' name='TYPE' value='net2net' /></td> |
ce9abb66 AH |
3156 | <td class='base'>$Lang::tr{'net to net vpn'} (Upload Client Package)</td></tr> |
3157 | <tr><td> </td><td class='base'><input type='file' name='FH' size='30'></td></tr> | |
e3edceeb | 3158 | <tr><td> </td><td>Import Connection Name</td></tr> |
040b8b0c | 3159 | <tr><td> </td><td class='base'><input type='text' name='n2nname' size='30'>$Lang::tr{'openvpn default'}: Client Packagename</td></tr> |
54fd0535 | 3160 | <tr><td colspan='3'><hr /></td></tr> |
8c877a82 | 3161 | <tr><td align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
ce9abb66 AH |
3162 | </form></table> |
3163 | END | |
3164 | ; | |
66c36198 | 3165 | |
ce9abb66 | 3166 | |
b278daf3 | 3167 | } else { |
49abe7af | 3168 | print <<END; |
b278daf3 | 3169 | <b>$Lang::tr{'connection type'}:</b><br /> |
8c877a82 | 3170 | <table border='0' width='100%'><form method='post' ENCTYPE="multipart/form-data"> |
b278daf3 | 3171 | <tr><td><input type='radio' name='TYPE' value='host' checked /></td> <td class='base'>$Lang::tr{'host to net vpn'}</td></tr> |
8c877a82 | 3172 | <tr><td align='right' colspan'3'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' /></td></tr> |
b278daf3 AH |
3173 | </form></table> |
3174 | END | |
3175 | ; | |
3176 | ||
3177 | } | |
3178 | ||
ce9abb66 | 3179 | &Header::closebox(); |
4c962356 | 3180 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; |
ce9abb66 AH |
3181 | &Header::closebigbox(); |
3182 | &Header::closepage(); | |
3183 | exit (0); | |
3184 | ||
3185 | ### | |
7c1d9faf | 3186 | # m.a.d net2net |
ce9abb66 AH |
3187 | ### |
3188 | ||
3189 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2net')){ | |
3190 | ||
3191 | my @firen2nconf; | |
3192 | my @confdetails; | |
3193 | my $uplconffilename =''; | |
54fd0535 | 3194 | my $uplconffilename2 =''; |
ce9abb66 | 3195 | my $uplp12name = ''; |
54fd0535 | 3196 | my $uplp12name2 = ''; |
ce9abb66 AH |
3197 | my @rem_subnet; |
3198 | my @rem_subnet2; | |
66c36198 | 3199 | my @tmposupnet3; |
ce9abb66 | 3200 | my $key; |
54fd0535 | 3201 | my @n2nname; |
ce9abb66 | 3202 | |
66c36198 | 3203 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 | 3204 | |
2ad1b18b MT |
3205 | # Check if a file is uploaded |
3206 | unless (ref ($cgiparams{'FH'})) { | |
ce9abb66 AH |
3207 | $errormessage = $Lang::tr{'there was no file upload'}; |
3208 | goto N2N_ERROR; | |
3209 | } | |
3210 | ||
3211 | # Move uploaded IPfire n2n package to temporary file | |
3212 | ||
3213 | (my $fh, my $filename) = tempfile( ); | |
3214 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
3215 | $errormessage = $!; | |
3216 | goto N2N_ERROR; | |
3217 | } | |
3218 | ||
3219 | my $zip = Archive::Zip->new(); | |
3220 | my $zipName = $filename; | |
3221 | my $status = $zip->read( $zipName ); | |
66c36198 | 3222 | if ($status != AZ_OK) { |
ce9abb66 AH |
3223 | $errormessage = "Read of $zipName failed\n"; |
3224 | goto N2N_ERROR; | |
3225 | } | |
3226 | ||
3227 | my $tempdir = tempdir( CLEANUP => 1 ); | |
3228 | my @files = $zip->memberNames(); | |
3229 | for(@files) { | |
3230 | $zip->extractMemberWithoutPaths($_,"$tempdir/$_"); | |
3231 | } | |
3232 | my $countfiles = @files; | |
3233 | ||
3234 | # Check if we have not more then 2 files | |
3235 | ||
3236 | if ( $countfiles == 2){ | |
3237 | foreach (@files){ | |
3238 | if ( $_ =~ /.conf$/){ | |
3239 | $uplconffilename = $_; | |
3240 | } | |
3241 | if ( $_ =~ /.p12$/){ | |
3242 | $uplp12name = $_; | |
66c36198 | 3243 | } |
ce9abb66 AH |
3244 | } |
3245 | if (($uplconffilename eq '') || ($uplp12name eq '')){ | |
3246 | $errormessage = "Either no *.conf or no *.p12 file found\n"; | |
3247 | goto N2N_ERROR; | |
3248 | } | |
3249 | ||
3250 | open(FILE, "$tempdir/$uplconffilename") or die 'Unable to open*.conf file'; | |
3251 | @firen2nconf = <FILE>; | |
3252 | close (FILE); | |
3253 | chomp(@firen2nconf); | |
ce9abb66 AH |
3254 | } else { |
3255 | ||
3256 | $errormessage = "Filecount does not match only 2 files are allowed\n"; | |
3257 | goto N2N_ERROR; | |
3258 | } | |
3259 | ||
7c1d9faf AH |
3260 | ### |
3261 | # m.a.d net2net | |
ce9abb66 | 3262 | ### |
66c36198 | 3263 | |
54fd0535 MT |
3264 | if ($cgiparams{'n2nname'} ne ''){ |
3265 | ||
66c36198 PM |
3266 | $uplconffilename2 = "$cgiparams{'n2nname'}.conf"; |
3267 | $uplp12name2 = "$cgiparams{'n2nname'}.p12"; | |
54fd0535 MT |
3268 | $n2nname[0] = $cgiparams{'n2nname'}; |
3269 | my @n2nname2 = split(/\./,$uplconffilename); | |
3270 | $n2nname2[0] =~ s/\n|\r//g; | |
3271 | my $input1 = "${General::swroot}/ovpn/certs/$uplp12name"; | |
3272 | my $output1 = "${General::swroot}/ovpn/certs/$uplp12name2"; | |
3273 | my $input2 = "$n2nname2[0]n2n"; | |
3274 | my $output2 = "$n2nname[0]n2n"; | |
3275 | my $filename = "$tempdir/$uplconffilename"; | |
3276 | open(FILE, "< $filename") or die 'Unable to open config file.'; | |
3277 | my @current = <FILE>; | |
3278 | close(FILE); | |
3279 | foreach (@current) {s/$input1/$output1/g;} | |
3280 | foreach (@current) {s/$input2/$output2/g;} | |
3281 | open (OUT, "> $filename") || die 'Unable to open config file.'; | |
3282 | print OUT @current; | |
3283 | close OUT; | |
ce9abb66 | 3284 | |
54fd0535 MT |
3285 | }else{ |
3286 | $uplconffilename2 = $uplconffilename; | |
3287 | $uplp12name2 = $uplp12name; | |
3288 | @n2nname = split(/\./,$uplconffilename); | |
ce9abb66 | 3289 | $n2nname[0] =~ s/\n|\r//g; |
66c36198 | 3290 | } |
7c1d9faf | 3291 | unless(-d "${General::swroot}/ovpn/n2nconf/"){mkdir "${General::swroot}/ovpn/n2nconf", 0755 or die "Unable to create dir $!";} |
66c36198 | 3292 | unless(-d "${General::swroot}/ovpn/n2nconf/$n2nname[0]"){mkdir "${General::swroot}/ovpn/n2nconf/$n2nname[0]", 0770 or die "Unable to create dir $!";} |
ce9abb66 | 3293 | |
7dfcaef0 AM |
3294 | #Add collectd settings to configfile |
3295 | open(FILE, ">> $tempdir/$uplconffilename") or die 'Unable to open config file.'; | |
3296 | print FILE "# Logfile\n"; | |
3297 | print FILE "status-version 1\n"; | |
3298 | print FILE "status /var/run/openvpn/$n2nname[0]-n2n 10\n"; | |
3299 | close FILE; | |
3300 | ||
cc79d281 | 3301 | unless(move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2")) { |
ce9abb66 AH |
3302 | $errormessage = "*.conf move failed: $!"; |
3303 | unlink ($filename); | |
3304 | goto N2N_ERROR; | |
3305 | } | |
66c36198 | 3306 | |
cc79d281 | 3307 | unless(move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2")) { |
ce9abb66 AH |
3308 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; |
3309 | unlink ($filename); | |
3310 | goto N2N_ERROR; | |
cc79d281 SS |
3311 | } |
3312 | ||
3313 | chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; | |
66c36198 | 3314 | |
ce9abb66 | 3315 | my $complzoactive; |
d96c89eb | 3316 | my $mssfixactive; |
4c962356 | 3317 | my $authactive; |
d96c89eb | 3318 | my $n2nfragment; |
60f396d7 | 3319 | my @n2nproto2 = split(/ /, (grep { /^proto/ } @firen2nconf)[0]); |
54fd0535 | 3320 | my @n2nproto = split(/-/, $n2nproto2[1]); |
ce9abb66 AH |
3321 | my @n2nport = split(/ /, (grep { /^port/ } @firen2nconf)[0]); |
3322 | my @n2ntunmtu = split(/ /, (grep { /^tun-mtu/ } @firen2nconf)[0]); | |
3323 | my @n2ncomplzo = grep { /^comp-lzo/ } @firen2nconf; | |
66c36198 | 3324 | if ($n2ncomplzo[0] =~ /comp-lzo/){$complzoactive = "on";} else {$complzoactive = "off";} |
d96c89eb AH |
3325 | my @n2nmssfix = grep { /^mssfix/ } @firen2nconf; |
3326 | if ($n2nmssfix[0] =~ /mssfix/){$mssfixactive = "on";} else {$mssfixactive = "off";} | |
54fd0535 | 3327 | #my @n2nmssfix = split(/ /, (grep { /^mssfix/ } @firen2nconf)[0]); |
d96c89eb | 3328 | my @n2nfragment = split(/ /, (grep { /^fragment/ } @firen2nconf)[0]); |
ce9abb66 AH |
3329 | my @n2nremote = split(/ /, (grep { /^remote/ } @firen2nconf)[0]); |
3330 | my @n2novpnsuball = split(/ /, (grep { /^ifconfig/ } @firen2nconf)[0]); | |
3331 | my @n2novpnsub = split(/\./,$n2novpnsuball[1]); | |
3332 | my @n2nremsub = split(/ /, (grep { /^route/ } @firen2nconf)[0]); | |
54fd0535 | 3333 | my @n2nmgmt = split(/ /, (grep { /^management/ } @firen2nconf)[0]); |
ce9abb66 | 3334 | my @n2nlocalsub = split(/ /, (grep { /^# remsub/ } @firen2nconf)[0]); |
4c962356 | 3335 | my @n2ncipher = split(/ /, (grep { /^cipher/ } @firen2nconf)[0]); |
f527e53f | 3336 | my @n2nauth = split(/ /, (grep { /^auth/ } @firen2nconf)[0]);; |
60f396d7 | 3337 | |
ce9abb66 AH |
3338 | ### |
3339 | # m.a.d delete CR and LF from arrays for this chomp doesnt work | |
3340 | ### | |
3341 | ||
ce9abb66 | 3342 | $n2nremote[1] =~ s/\n|\r//g; |
ce9abb66 AH |
3343 | $n2novpnsub[0] =~ s/\n|\r//g; |
3344 | $n2novpnsub[1] =~ s/\n|\r//g; | |
3345 | $n2novpnsub[2] =~ s/\n|\r//g; | |
60f396d7 | 3346 | $n2nproto[0] =~ s/\n|\r//g; |
ce9abb66 AH |
3347 | $n2nport[1] =~ s/\n|\r//g; |
3348 | $n2ntunmtu[1] =~ s/\n|\r//g; | |
3349 | $n2nremsub[1] =~ s/\n|\r//g; | |
b278daf3 | 3350 | $n2nremsub[2] =~ s/\n|\r//g; |
ce9abb66 | 3351 | $n2nlocalsub[2] =~ s/\n|\r//g; |
d96c89eb | 3352 | $n2nfragment[1] =~ s/\n|\r//g; |
54fd0535 | 3353 | $n2nmgmt[2] =~ s/\n|\r//g; |
4c962356 EK |
3354 | $n2ncipher[1] =~ s/\n|\r//g; |
3355 | $n2nauth[1] =~ s/\n|\r//g; | |
ce9abb66 | 3356 | chomp ($complzoactive); |
d96c89eb | 3357 | chomp ($mssfixactive); |
ce9abb66 AH |
3358 | |
3359 | ### | |
7c1d9faf | 3360 | # m.a.d net2net |
ce9abb66 AH |
3361 | ### |
3362 | ||
3363 | ### | |
3364 | # Check if there is no other entry with this name | |
3365 | ### | |
3366 | ||
3367 | foreach my $dkey (keys %confighash) { | |
3368 | if ($confighash{$dkey}[1] eq $n2nname[0]) { | |
3369 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3370 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3371 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3372 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
66c36198 | 3373 | goto N2N_ERROR; |
ce9abb66 AH |
3374 | } |
3375 | } | |
3376 | ||
d96c89eb AH |
3377 | ### |
3378 | # Check if OpenVPN Subnet is valid | |
3379 | ### | |
3380 | ||
3381 | foreach my $dkey (keys %confighash) { | |
3382 | if ($confighash{$dkey}[27] eq "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0") { | |
3383 | $errormessage = 'The OpenVPN Subnet is already in use'; | |
b278daf3 AH |
3384 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3385 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3386 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
66c36198 | 3387 | goto N2N_ERROR; |
d96c89eb AH |
3388 | } |
3389 | } | |
3390 | ||
3391 | ### | |
4c962356 | 3392 | # Check if Dest Port is vaild |
d96c89eb AH |
3393 | ### |
3394 | ||
3395 | foreach my $dkey (keys %confighash) { | |
3396 | if ($confighash{$dkey}[29] eq $n2nport[1] ) { | |
3397 | $errormessage = 'The OpenVPN Port is already in use'; | |
b278daf3 AH |
3398 | unlink ("${General::swroot}/ovpn/n2nconf/$n2nname[0]/$n2nname[0].conf") or die "Removing Configfile fail: $!"; |
3399 | unlink ("${General::swroot}/ovpn/certs/$n2nname[0].p12") or die "Removing Certfile fail: $!"; | |
3400 | rmdir ("${General::swroot}/ovpn/n2nconf/$n2nname[0]") || die "Removing Directory fail: $!"; | |
66c36198 | 3401 | goto N2N_ERROR; |
d96c89eb AH |
3402 | } |
3403 | } | |
66c36198 PM |
3404 | |
3405 | ||
3406 | ||
ce9abb66 AH |
3407 | $key = &General::findhasharraykey (\%confighash); |
3408 | ||
49abe7af | 3409 | foreach my $i (0 .. 42) { $confighash{$key}[$i] = "";} |
350f2980 | 3410 | |
ce9abb66 AH |
3411 | $confighash{$key}[0] = 'off'; |
3412 | $confighash{$key}[1] = $n2nname[0]; | |
66c36198 | 3413 | $confighash{$key}[2] = $n2nname[0]; |
ce9abb66 | 3414 | $confighash{$key}[3] = 'net'; |
66c36198 PM |
3415 | $confighash{$key}[4] = 'cert'; |
3416 | $confighash{$key}[6] = 'client'; | |
ce9abb66 | 3417 | $confighash{$key}[8] = $n2nlocalsub[2]; |
350f2980 | 3418 | $confighash{$key}[10] = $n2nremote[1]; |
66c36198 | 3419 | $confighash{$key}[11] = "$n2nremsub[1]/$n2nremsub[2]"; |
54fd0535 | 3420 | $confighash{$key}[22] = $n2nmgmt[2]; |
350f2980 | 3421 | $confighash{$key}[23] = $mssfixactive; |
d96c89eb | 3422 | $confighash{$key}[24] = $n2nfragment[1]; |
350f2980 | 3423 | $confighash{$key}[25] = 'IPFire n2n Client'; |
ce9abb66 | 3424 | $confighash{$key}[26] = 'red'; |
350f2980 SS |
3425 | $confighash{$key}[27] = "$n2novpnsub[0].$n2novpnsub[1].$n2novpnsub[2].0/255.255.255.0"; |
3426 | $confighash{$key}[28] = $n2nproto[0]; | |
3427 | $confighash{$key}[29] = $n2nport[1]; | |
3428 | $confighash{$key}[30] = $complzoactive; | |
3429 | $confighash{$key}[31] = $n2ntunmtu[1]; | |
4c962356 EK |
3430 | $confighash{$key}[39] = $n2nauth[1]; |
3431 | $confighash{$key}[40] = $n2ncipher[1]; | |
49abe7af | 3432 | $confighash{$key}[41] = 'disabled'; |
ce9abb66 AH |
3433 | |
3434 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
66c36198 | 3435 | |
ce9abb66 | 3436 | N2N_ERROR: |
66c36198 | 3437 | |
ce9abb66 AH |
3438 | &Header::showhttpheaders(); |
3439 | &Header::openpage('Validate imported configuration', 1, ''); | |
3440 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
3441 | if ($errormessage) { | |
3442 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
3443 | print "<class name='base'>$errormessage"; | |
3444 | print " </class>"; | |
66c36198 | 3445 | &Header::closebox(); |
ce9abb66 | 3446 | |
66c36198 PM |
3447 | } else |
3448 | { | |
ce9abb66 AH |
3449 | &Header::openbox('100%', 'LEFT', 'import ipfire net2net config'); |
3450 | } | |
3451 | if ($errormessage eq ''){ | |
49abe7af | 3452 | print <<END; |
ce9abb66 AH |
3453 | <!-- ipfire net2net config gui --> |
3454 | <table width='100%'> | |
3455 | <tr><td width='25%'> </td><td width='25%'> </td></tr> | |
3456 | <tr><td class='boldbase'>$Lang::tr{'name'}:</td><td><b>$n2nname[0]</b></td></tr> | |
66c36198 PM |
3457 | <tr><td> </td><td> </td></tr> |
3458 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td><td><b>$confighash{$key}[6]</b></td></tr> | |
ce9abb66 AH |
3459 | <tr><td class='boldbase' nowrap='nowrap'>Remote Host </td><td><b>$confighash{$key}[10]</b></td></tr> |
3460 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'}</td><td><b>$confighash{$key}[8]</b></td></tr> | |
4c962356 | 3461 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'}:</td><td><b>$confighash{$key}[11]</b></td></tr> |
ce9abb66 AH |
3462 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'}</td><td><b>$confighash{$key}[27]</b></td></tr> |
3463 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td><td><b>$confighash{$key}[28]</b></td></tr> | |
3464 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'destination port'}:</td><td><b>$confighash{$key}[29]</b></td></tr> | |
3465 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td><td><b>$confighash{$key}[30]</b></td></tr> | |
4c962356 EK |
3466 | <tr><td class='boldbase' nowrap='nowrap'>MSSFIX:</td><td><b>$confighash{$key}[23]</b></td></tr> |
3467 | <tr><td class='boldbase' nowrap='nowrap'>Fragment:</td><td><b>$confighash{$key}[24]</b></td></tr> | |
ce9abb66 | 3468 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td><td><b>$confighash{$key}[31]</b></td></tr> |
54fd0535 | 3469 | <tr><td class='boldbase' nowrap='nowrap'>Management Port </td><td><b>$confighash{$key}[22]</b></td></tr> |
0c4ffc69 | 3470 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn tls auth'}:</td><td><b>$confighash{$key}[39]</b></td></tr> |
4c962356 | 3471 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td><td><b>$confighash{$key}[40]</b></td></tr> |
66c36198 | 3472 | <tr><td> </td><td> </td></tr> |
ce9abb66 AH |
3473 | </table> |
3474 | END | |
66c36198 | 3475 | ; |
ce9abb66 AH |
3476 | &Header::closebox(); |
3477 | } | |
3478 | ||
3479 | if ($errormessage) { | |
3480 | print "<div align='center'><a href='/cgi-bin/ovpnmain.cgi'>$Lang::tr{'back'}</a></div>"; | |
66c36198 PM |
3481 | } else { |
3482 | print "<div align='center'><form method='post' ENCTYPE='multipart/form-data'><input type='submit' name='ACTION' value='$Lang::tr{'add'}' />"; | |
ce9abb66 | 3483 | print "<input type='hidden' name='TYPE' value='net2netakn' />"; |
66c36198 | 3484 | print "<input type='hidden' name='KEY' value='$key' />"; |
ce9abb66 | 3485 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; |
66c36198 | 3486 | } |
ce9abb66 AH |
3487 | &Header::closebigbox(); |
3488 | &Header::closepage(); | |
4c962356 | 3489 | exit(0); |
ce9abb66 AH |
3490 | |
3491 | ||
3492 | ## | |
3493 | ### Accept IPFire n2n Package Settings | |
3494 | ### | |
3495 | ||
3496 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
3497 | ||
3498 | ### | |
3499 | ### Discard and Rollback IPFire n2n Package Settings | |
3500 | ### | |
3501 | ||
3502 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'cancel'}) && ($cgiparams{'TYPE'} eq 'net2netakn')){ | |
66c36198 | 3503 | |
ce9abb66 AH |
3504 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
3505 | ||
3506 | if ($confighash{$cgiparams{'KEY'}}) { | |
3507 | ||
3508 | my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); | |
3509 | my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); | |
3510 | unlink ($certfile) or die "Removing $certfile fail: $!"; | |
3511 | unlink ($conffile) or die "Removing $conffile fail: $!"; | |
3512 | rmdir ("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]") || die "Kann Verzeichnis nicht loeschen: $!"; | |
3513 | delete $confighash{$cgiparams{'KEY'}}; | |
66c36198 | 3514 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
ce9abb66 AH |
3515 | |
3516 | } else { | |
3517 | $errormessage = $Lang::tr{'invalid key'}; | |
66c36198 PM |
3518 | } |
3519 | ||
ce9abb66 AH |
3520 | |
3521 | ### | |
7c1d9faf | 3522 | # m.a.d net2net |
ce9abb66 AH |
3523 | ### |
3524 | ||
3525 | ||
3526 | ### | |
3527 | ### Adding a new connection | |
3528 | ### | |
6e13d0a5 MT |
3529 | } elsif (($cgiparams{'ACTION'} eq $Lang::tr{'add'}) || |
3530 | ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) || | |
3531 | ($cgiparams{'ACTION'} eq $Lang::tr{'save'} && $cgiparams{'ADVANCED'} eq '')) { | |
66c36198 | 3532 | |
6e13d0a5 MT |
3533 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnsettings); |
3534 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
3535 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
3536 | ||
3537 | if ($cgiparams{'ACTION'} eq $Lang::tr{'edit'}) { | |
8c877a82 AM |
3538 | if (! $confighash{$cgiparams{'KEY'}}[0]) { |
3539 | $errormessage = $Lang::tr{'invalid key'}; | |
3540 | goto VPNCONF_END; | |
3541 | } | |
4c962356 EK |
3542 | $cgiparams{'ENABLED'} = $confighash{$cgiparams{'KEY'}}[0]; |
3543 | $cgiparams{'NAME'} = $confighash{$cgiparams{'KEY'}}[1]; | |
3544 | $cgiparams{'TYPE'} = $confighash{$cgiparams{'KEY'}}[3]; | |
3545 | $cgiparams{'AUTH'} = $confighash{$cgiparams{'KEY'}}[4]; | |
3546 | $cgiparams{'PSK'} = $confighash{$cgiparams{'KEY'}}[5]; | |
3547 | $cgiparams{'SIDE'} = $confighash{$cgiparams{'KEY'}}[6]; | |
3548 | $cgiparams{'LOCAL_SUBNET'} = $confighash{$cgiparams{'KEY'}}[8]; | |
3549 | $cgiparams{'REMOTE'} = $confighash{$cgiparams{'KEY'}}[10]; | |
8c877a82 | 3550 | $cgiparams{'REMOTE_SUBNET'} = $confighash{$cgiparams{'KEY'}}[11]; |
4c962356 EK |
3551 | $cgiparams{'OVPN_MGMT'} = $confighash{$cgiparams{'KEY'}}[22]; |
3552 | $cgiparams{'MSSFIX'} = $confighash{$cgiparams{'KEY'}}[23]; | |
3553 | $cgiparams{'FRAGMENT'} = $confighash{$cgiparams{'KEY'}}[24]; | |
3554 | $cgiparams{'REMARK'} = $confighash{$cgiparams{'KEY'}}[25]; | |
3555 | $cgiparams{'INTERFACE'} = $confighash{$cgiparams{'KEY'}}[26]; | |
3556 | $cgiparams{'OVPN_SUBNET'} = $confighash{$cgiparams{'KEY'}}[27]; | |
3557 | $cgiparams{'PROTOCOL'} = $confighash{$cgiparams{'KEY'}}[28]; | |
3558 | $cgiparams{'DEST_PORT'} = $confighash{$cgiparams{'KEY'}}[29]; | |
3559 | $cgiparams{'COMPLZO'} = $confighash{$cgiparams{'KEY'}}[30]; | |
3560 | $cgiparams{'MTU'} = $confighash{$cgiparams{'KEY'}}[31]; | |
3561 | $cgiparams{'CHECK1'} = $confighash{$cgiparams{'KEY'}}[32]; | |
df9b48b7 | 3562 | $name=$cgiparams{'CHECK1'} ; |
4c962356 EK |
3563 | $cgiparams{$name} = $confighash{$cgiparams{'KEY'}}[33]; |
3564 | $cgiparams{'RG'} = $confighash{$cgiparams{'KEY'}}[34]; | |
3565 | $cgiparams{'CCD_DNS1'} = $confighash{$cgiparams{'KEY'}}[35]; | |
3566 | $cgiparams{'CCD_DNS2'} = $confighash{$cgiparams{'KEY'}}[36]; | |
3567 | $cgiparams{'CCD_WINS'} = $confighash{$cgiparams{'KEY'}}[37]; | |
4c962356 EK |
3568 | $cgiparams{'DAUTH'} = $confighash{$cgiparams{'KEY'}}[39]; |
3569 | $cgiparams{'DCIPHER'} = $confighash{$cgiparams{'KEY'}}[40]; | |
49abe7af | 3570 | $cgiparams{'TLSAUTH'} = $confighash{$cgiparams{'KEY'}}[41]; |
e1e10515 | 3571 | $cgiparams{'OTP_STATE'} = $confighash{$cgiparams{'KEY'}}[43]; |
8c877a82 | 3572 | } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'save'}) { |
c6c9630e | 3573 | $cgiparams{'REMARK'} = &Header::cleanhtml($cgiparams{'REMARK'}); |
66c36198 | 3574 | |
8c877a82 | 3575 | #A.Marx CCD check iroute field and convert it to decimal |
52d08bcb | 3576 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
3577 | my @temp=(); |
3578 | my %ccdroutehash=(); | |
3579 | my $keypoint=0; | |
5068ac38 AM |
3580 | my $ip; |
3581 | my $cidr; | |
8c877a82 AM |
3582 | if ($cgiparams{'IR'} ne ''){ |
3583 | @temp = split("\n",$cgiparams{'IR'}); | |
3584 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3585 | #find key to use | |
3586 | foreach my $key (keys %ccdroutehash) { | |
3587 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3588 | $keypoint=$key; | |
3589 | delete $ccdroutehash{$key}; | |
3590 | }else{ | |
3591 | $keypoint = &General::findhasharraykey (\%ccdroutehash); | |
3592 | } | |
3593 | } | |
3594 | $ccdroutehash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3595 | my $i=1; | |
3596 | my $val=0; | |
3597 | foreach $val (@temp){ | |
3598 | chomp($val); | |
66c36198 | 3599 | $val=~s/\s*$//g; |
5068ac38 | 3600 | #check if iroute exists in ccdroute or if new iroute is part of an existing one |
8c877a82 AM |
3601 | foreach my $key (keys %ccdroutehash) { |
3602 | foreach my $oldiroute ( 1 .. $#{$ccdroutehash{$key}}){ | |
5068ac38 AM |
3603 | if ($ccdroutehash{$key}[$oldiroute] eq "$val") { |
3604 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3605 | goto VPNCONF_ERROR; | |
3606 | } | |
3607 | my ($ip1,$cidr1) = split (/\//, $val); | |
82c809c7 | 3608 | $ip1 = &General::getnetworkip($ip1,&General::iporsubtocidr($cidr1)); |
5068ac38 AM |
3609 | my ($ip2,$cidr2) = split (/\//, $ccdroutehash{$key}[$oldiroute]); |
3610 | if (&General::IpInSubnet ($ip1,$ip2,$cidr2)){ | |
3611 | $errormessage=$errormessage.$Lang::tr{'ccd err irouteexist'}; | |
3612 | goto VPNCONF_ERROR; | |
66c36198 PM |
3613 | } |
3614 | ||
8c877a82 AM |
3615 | } |
3616 | } | |
5068ac38 AM |
3617 | if (!&General::validipandmask($val)){ |
3618 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3619 | goto VPNCONF_ERROR; | |
3620 | }else{ | |
3621 | ($ip,$cidr) = split(/\//,$val); | |
3622 | $ip=&General::getnetworkip($ip,&General::iporsubtocidr($cidr)); | |
3623 | $cidr=&General::iporsubtodec($cidr); | |
3624 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
66c36198 | 3625 | |
5068ac38 | 3626 | } |
66c36198 | 3627 | |
8c877a82 | 3628 | #check for existing network IP's |
52d08bcb AM |
3629 | if (&General::IpInSubnet ($ip,$netsettings{GREEN_NETADDRESS},$netsettings{GREEN_NETMASK}) && $netsettings{GREEN_NETADDRESS} ne '0.0.0.0') |
3630 | { | |
3631 | $errormessage=$Lang::tr{'ccd err green'}; | |
3632 | goto VPNCONF_ERROR; | |
3633 | }elsif(&General::IpInSubnet ($ip,$netsettings{RED_NETADDRESS},$netsettings{RED_NETMASK}) && $netsettings{RED_NETADDRESS} ne '0.0.0.0') | |
3634 | { | |
3635 | $errormessage=$Lang::tr{'ccd err red'}; | |
3636 | goto VPNCONF_ERROR; | |
3637 | }elsif(&General::IpInSubnet ($ip,$netsettings{BLUE_NETADDRESS},$netsettings{BLUE_NETMASK}) && $netsettings{BLUE_NETADDRESS} ne '0.0.0.0' && $netsettings{BLUE_NETADDRESS} gt '') | |
3638 | { | |
3639 | $errormessage=$Lang::tr{'ccd err blue'}; | |
3640 | goto VPNCONF_ERROR; | |
3641 | }elsif(&General::IpInSubnet ($ip,$netsettings{ORANGE_NETADDRESS},$netsettings{ORANGE_NETMASK}) && $netsettings{ORANGE_NETADDRESS} ne '0.0.0.0' && $netsettings{ORANGE_NETADDRESS} gt '' ) | |
3642 | { | |
3643 | $errormessage=$Lang::tr{'ccd err orange'}; | |
8c877a82 AM |
3644 | goto VPNCONF_ERROR; |
3645 | } | |
66c36198 | 3646 | |
8c877a82 AM |
3647 | if (&General::validipandmask($val)){ |
3648 | $ccdroutehash{$keypoint}[$i] = $ip."/".$cidr; | |
3649 | }else{ | |
3650 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($ip/$cidr)"; | |
3651 | goto VPNCONF_ERROR; | |
3652 | } | |
3653 | $i++; | |
3654 | } | |
3655 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3656 | &writeserverconf; | |
3657 | }else{ | |
3658 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3659 | foreach my $key (keys %ccdroutehash) { | |
3660 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}) { | |
3661 | delete $ccdroutehash{$key}; | |
3662 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3663 | &writeserverconf; | |
3664 | } | |
66c36198 | 3665 | } |
8c877a82 AM |
3666 | } |
3667 | undef @temp; | |
3668 | #check route field and convert it to decimal | |
8c877a82 AM |
3669 | my $val=0; |
3670 | my $i=1; | |
8c877a82 | 3671 | &General::readhasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
52d08bcb AM |
3672 | #find key to use |
3673 | foreach my $key (keys %ccdroute2hash) { | |
3674 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
3675 | $keypoint=$key; | |
3676 | delete $ccdroute2hash{$key}; | |
3677 | }else{ | |
3678 | $keypoint = &General::findhasharraykey (\%ccdroute2hash); | |
3679 | &General::writehasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
3680 | &writeserverconf; | |
8c877a82 | 3681 | } |
52d08bcb AM |
3682 | } |
3683 | $ccdroute2hash{$keypoint}[0]=$cgiparams{'NAME'}; | |
3684 | if ($cgiparams{'IFROUTE'} eq ''){$cgiparams{'IFROUTE'} = $Lang::tr{'ccd none'};} | |
3685 | @temp = split(/\|/,$cgiparams{'IFROUTE'}); | |
3686 | my %ownnet=(); | |
3687 | &General::readhash("${General::swroot}/ethernet/settings", \%ownnet); | |
3688 | foreach $val (@temp){ | |
3689 | chomp($val); | |
66c36198 | 3690 | $val=~s/\s*$//g; |
52d08bcb AM |
3691 | if ($val eq $Lang::tr{'green'}) |
3692 | { | |
3693 | $val=$ownnet{GREEN_NETADDRESS}."/".$ownnet{GREEN_NETMASK}; | |
3694 | } | |
3695 | if ($val eq $Lang::tr{'blue'}) | |
3696 | { | |
3697 | $val=$ownnet{BLUE_NETADDRESS}."/".$ownnet{BLUE_NETMASK}; | |
3698 | } | |
3699 | if ($val eq $Lang::tr{'orange'}) | |
3700 | { | |
3701 | $val=$ownnet{ORANGE_NETADDRESS}."/".$ownnet{ORANGE_NETMASK}; | |
3702 | } | |
3703 | my ($ip,$cidr) = split (/\//, $val); | |
66c36198 | 3704 | |
52d08bcb | 3705 | if ($val ne $Lang::tr{'ccd none'}) |
66c36198 | 3706 | { |
8c877a82 AM |
3707 | if (! &check_routes_push($val)){$errormessage=$errormessage."Route $val ".$Lang::tr{'ccd err routeovpn2'}." ($val)";goto VPNCONF_ERROR;} |
3708 | if (! &check_ccdroute($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err inuse'}." ($val)" ;goto VPNCONF_ERROR;} | |
3709 | if (! &check_ccdconf($val)){$errormessage=$errormessage."<br>Route $val ".$Lang::tr{'ccd err routeovpn'}." ($val)";goto VPNCONF_ERROR;} | |
3710 | if (&General::validipandmask($val)){ | |
3711 | $val=$ip."/".&General::iporsubtodec($cidr); | |
3712 | $ccdroute2hash{$keypoint}[$i] = $val; | |
3713 | }else{ | |
3714 | $errormessage=$errormessage."Route ".$Lang::tr{'ccd invalid'}." ($val)"; | |
3715 | goto VPNCONF_ERROR; | |
3716 | } | |
52d08bcb AM |
3717 | }else{ |
3718 | $ccdroute2hash{$keypoint}[$i]=''; | |
3719 | } | |
3720 | $i++; | |
66c36198 | 3721 | } |
52d08bcb AM |
3722 | &General::writehasharray("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
3723 | ||
8c877a82 AM |
3724 | #check dns1 ip |
3725 | if ($cgiparams{'CCD_DNS1'} ne '' && ! &General::validip($cgiparams{'CCD_DNS1'})) { | |
3726 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 1"; | |
3727 | goto VPNCONF_ERROR; | |
3728 | } | |
3729 | #check dns2 ip | |
3730 | if ($cgiparams{'CCD_DNS2'} ne '' && ! &General::validip($cgiparams{'CCD_DNS2'})) { | |
3731 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp dns'}." 2"; | |
3732 | goto VPNCONF_ERROR; | |
3733 | } | |
3734 | #check wins ip | |
3735 | if ($cgiparams{'CCD_WINS'} ne '' && ! &General::validip($cgiparams{'CCD_WINS'})) { | |
3736 | $errormessage=$errormessage."<br>".$Lang::tr{'invalid input for dhcp wins'}; | |
3737 | goto VPNCONF_ERROR; | |
3738 | } | |
52d08bcb | 3739 | } |
8c877a82 AM |
3740 | |
3741 | #CCD End | |
52d08bcb | 3742 | |
66c36198 | 3743 | |
73735ad9 EK |
3744 | if ($cgiparams{'TYPE'} !~ /^(host|net)$/) { |
3745 | $errormessage = $Lang::tr{'connection type is invalid'}; | |
3746 | if ($cgiparams{'TYPE'} eq 'net') { | |
3747 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3748 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3749 | goto VPNCONF_ERROR; | |
3750 | } | |
3751 | goto VPNCONF_ERROR; | |
c6c9630e MT |
3752 | } |
3753 | ||
c6c9630e | 3754 | if ($cgiparams{'NAME'} !~ /^[a-zA-Z0-9]+$/) { |
73735ad9 EK |
3755 | $errormessage = $Lang::tr{'name must only contain characters'}; |
3756 | if ($cgiparams{'TYPE'} eq 'net') { | |
3757 | goto VPNCONF_ERROR; | |
3758 | } | |
3759 | goto VPNCONF_ERROR; | |
3760 | } | |
c6c9630e MT |
3761 | |
3762 | if ($cgiparams{'NAME'} =~ /^(host|01|block|private|clear|packetdefault)$/) { | |
73735ad9 EK |
3763 | $errormessage = $Lang::tr{'name is invalid'}; |
3764 | if ($cgiparams{'TYPE'} eq 'net') { | |
3765 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3766 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3767 | goto VPNCONF_ERROR; | |
3768 | } | |
3769 | goto VPNCONF_ERROR; | |
c6c9630e MT |
3770 | } |
3771 | ||
3772 | if (length($cgiparams{'NAME'}) >60) { | |
73735ad9 EK |
3773 | $errormessage = $Lang::tr{'name too long'}; |
3774 | if ($cgiparams{'TYPE'} eq 'net') { | |
3775 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3776 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3777 | goto VPNCONF_ERROR; | |
3778 | } | |
3779 | goto VPNCONF_ERROR; | |
c6c9630e MT |
3780 | } |
3781 | ||
d96c89eb | 3782 | ### |
7c1d9faf | 3783 | # m.a.d net2net |
d96c89eb AH |
3784 | ### |
3785 | ||
7c1d9faf | 3786 | if ($cgiparams{'TYPE'} eq 'net') { |
ab4cf06c | 3787 | if ($cgiparams{'DEST_PORT'} eq $vpnsettings{'DDEST_PORT'}) { |
cd0c0a0d | 3788 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
b278daf3 AH |
3789 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3790 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
66c36198 | 3791 | goto VPNCONF_ERROR; |
d96c89eb | 3792 | } |
ab4cf06c AM |
3793 | #Bugfix 10357 |
3794 | foreach my $key (sort keys %confighash){ | |
3795 | if ( ($confighash{$key}[22] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1]) || ($confighash{$key}[29] eq $cgiparams{'DEST_PORT'} && $cgiparams{'NAME'} ne $confighash{$key}[1])){ | |
54fd0535 MT |
3796 | $errormessage = $Lang::tr{'openvpn destination port used'}; |
3797 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3798 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
66c36198 | 3799 | goto VPNCONF_ERROR; |
ab4cf06c AM |
3800 | } |
3801 | } | |
3802 | if ($cgiparams{'DEST_PORT'} eq '') { | |
3803 | $errormessage = $Lang::tr{'invalid port'}; | |
3804 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3805 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
66c36198 | 3806 | goto VPNCONF_ERROR; |
54fd0535 | 3807 | } |
d96c89eb | 3808 | |
f48074ba SS |
3809 | # Check if the input for the transfer net is valid. |
3810 | if (!&General::validipandmask($cgiparams{'OVPN_SUBNET'})){ | |
3811 | $errormessage = $Lang::tr{'ccd err invalidnet'}; | |
3812 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3813 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3814 | goto VPNCONF_ERROR; | |
3815 | } | |
3816 | ||
d96c89eb | 3817 | if ($cgiparams{'OVPN_SUBNET'} eq $vpnsettings{'DOVPN_SUBNET'}) { |
cd0c0a0d | 3818 | $errormessage = $Lang::tr{'openvpn subnet is used'}; |
b278daf3 AH |
3819 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3820 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
66c36198 | 3821 | goto VPNCONF_ERROR; |
d96c89eb AH |
3822 | } |
3823 | ||
3824 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'MSSFIX'} eq 'on')) { | |
cd0c0a0d | 3825 | $errormessage = $Lang::tr{'openvpn mssfix allowed with udp'}; |
b278daf3 AH |
3826 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3827 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3828 | goto VPNCONF_ERROR; |
3829 | } | |
66c36198 | 3830 | |
d96c89eb | 3831 | if (($cgiparams{'PROTOCOL'} eq 'tcp') && ($cgiparams{'FRAGMENT'} ne '')) { |
cd0c0a0d | 3832 | $errormessage = $Lang::tr{'openvpn fragment allowed with udp'}; |
b278daf3 AH |
3833 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3834 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
d96c89eb AH |
3835 | goto VPNCONF_ERROR; |
3836 | } | |
d96c89eb | 3837 | |
7c1d9faf | 3838 | if ( &validdotmask ($cgiparams{'LOCAL_SUBNET'})) { |
cd0c0a0d | 3839 | $errormessage = $Lang::tr{'openvpn prefix local subnet'}; |
b278daf3 AH |
3840 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3841 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3842 | goto VPNCONF_ERROR; | |
66c36198 PM |
3843 | } |
3844 | ||
7c1d9faf | 3845 | if ( &validdotmask ($cgiparams{'OVPN_SUBNET'})) { |
cd0c0a0d | 3846 | $errormessage = $Lang::tr{'openvpn prefix openvpn subnet'}; |
b278daf3 AH |
3847 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3848 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3849 | goto VPNCONF_ERROR; | |
66c36198 PM |
3850 | } |
3851 | ||
7c1d9faf | 3852 | if ( &validdotmask ($cgiparams{'REMOTE_SUBNET'})) { |
cd0c0a0d | 3853 | $errormessage = $Lang::tr{'openvpn prefix remote subnet'}; |
b278daf3 AH |
3854 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3855 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3856 | goto VPNCONF_ERROR; | |
8c252e6a | 3857 | } |
66c36198 | 3858 | |
8c252e6a EK |
3859 | if ($cgiparams{'DEST_PORT'} <= 1023) { |
3860 | $errormessage = $Lang::tr{'ovpn port in root range'}; | |
3861 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3862 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3863 | goto VPNCONF_ERROR; | |
3864 | } | |
54fd0535 | 3865 | |
4c962356 | 3866 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
66c36198 | 3867 | $cgiparams{'OVPN_MGMT'} = $cgiparams{'DEST_PORT'}; |
8c252e6a | 3868 | } |
66c36198 | 3869 | |
8c252e6a EK |
3870 | if ($cgiparams{'OVPN_MGMT'} <= 1023) { |
3871 | $errormessage = $Lang::tr{'ovpn mgmt in root range'}; | |
3872 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3873 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3874 | goto VPNCONF_ERROR; | |
b2e75449 MT |
3875 | } |
3876 | #Check if remote subnet is used elsewhere | |
3877 | my ($n2nip,$n2nsub)=split("/",$cgiparams{'REMOTE_SUBNET'}); | |
3878 | $warnmessage=&General::checksubnets('',$n2nip,'ovpn'); | |
3879 | if ($warnmessage){ | |
3880 | $warnmessage=$Lang::tr{'remote subnet'}." ($cgiparams{'REMOTE_SUBNET'}) <br>".$warnmessage; | |
3881 | } | |
7c1d9faf | 3882 | } |
d96c89eb | 3883 | |
ce9abb66 AH |
3884 | # if (($cgiparams{'TYPE'} eq 'net') && ($cgiparams{'SIDE'} !~ /^(left|right)$/)) { |
3885 | # $errormessage = $Lang::tr{'ipfire side is invalid'}; | |
3886 | # goto VPNCONF_ERROR; | |
3887 | # } | |
3888 | ||
c6c9630e MT |
3889 | # Check if there is no other entry with this name |
3890 | if (! $cgiparams{'KEY'}) { | |
3891 | foreach my $key (keys %confighash) { | |
3892 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
3893 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
b278daf3 AH |
3894 | if ($cgiparams{'TYPE'} eq 'net') { |
3895 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3896 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3897 | } | |
c6c9630e | 3898 | goto VPNCONF_ERROR; |
6e13d0a5 | 3899 | } |
c6c9630e MT |
3900 | } |
3901 | } | |
3902 | ||
c125d8a2 | 3903 | # Check if a remote host/IP has been set for the client. |
86228a56 MT |
3904 | if ($cgiparams{'TYPE'} eq 'net') { |
3905 | if ($cgiparams{'SIDE'} ne 'server' && $cgiparams{'REMOTE'} eq '') { | |
3906 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3907 | |
86228a56 MT |
3908 | # Check if this is a N2N connection and drop temporary config. |
3909 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3910 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
ce9abb66 | 3911 | |
86228a56 MT |
3912 | goto VPNCONF_ERROR; |
3913 | } | |
c125d8a2 | 3914 | |
86228a56 MT |
3915 | # Check if a remote host/IP has been configured - the field can be empty on the server side. |
3916 | if ($cgiparams{'REMOTE'} ne '') { | |
3917 | # Check if the given IP is valid - otherwise check if it is a valid domain. | |
3918 | if (! &General::validip($cgiparams{'REMOTE'})) { | |
3919 | # Check for a valid domain. | |
3920 | if (! &General::validfqdn ($cgiparams{'REMOTE'})) { | |
3921 | $errormessage = $Lang::tr{'invalid input for remote host/ip'}; | |
c125d8a2 | 3922 | |
86228a56 MT |
3923 | # Check if this is a N2N connection and drop temporary config. |
3924 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3925 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
c125d8a2 | 3926 | |
86228a56 MT |
3927 | goto VPNCONF_ERROR; |
3928 | } | |
3929 | } | |
6e13d0a5 | 3930 | } |
c6c9630e | 3931 | } |
c125d8a2 | 3932 | |
c6c9630e MT |
3933 | if ($cgiparams{'TYPE'} ne 'host') { |
3934 | unless (&General::validipandmask($cgiparams{'LOCAL_SUBNET'})) { | |
66c36198 | 3935 | $errormessage = $Lang::tr{'local subnet is invalid'}; |
b278daf3 AH |
3936 | if ($cgiparams{'TYPE'} eq 'net') { |
3937 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3938 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3939 | } | |
c6c9630e MT |
3940 | goto VPNCONF_ERROR;} |
3941 | } | |
3942 | # Check if there is no other entry without IP-address and PSK | |
3943 | if ($cgiparams{'REMOTE'} eq '') { | |
3944 | foreach my $key (keys %confighash) { | |
66c36198 PM |
3945 | if(($cgiparams{'KEY'} ne $key) && |
3946 | ($confighash{$key}[4] eq 'psk' || $cgiparams{'AUTH'} eq 'psk') && | |
c6c9630e MT |
3947 | $confighash{$key}[10] eq '') { |
3948 | $errormessage = $Lang::tr{'you can only define one roadwarrior connection when using pre-shared key authentication'}; | |
3949 | goto VPNCONF_ERROR; | |
6e13d0a5 | 3950 | } |
c6c9630e MT |
3951 | } |
3952 | } | |
ce9abb66 AH |
3953 | if (($cgiparams{'TYPE'} eq 'net') && (! &General::validipandmask($cgiparams{'REMOTE_SUBNET'}))) { |
3954 | $errormessage = $Lang::tr{'remote subnet is invalid'}; | |
b278daf3 AH |
3955 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; |
3956 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3957 | goto VPNCONF_ERROR; | |
ce9abb66 | 3958 | } |
c6c9630e | 3959 | |
425465ed EK |
3960 | # Check for N2N that OpenSSL maximum of valid days will not be exceeded |
3961 | if ($cgiparams{'TYPE'} eq 'net') { | |
3962 | if ($cgiparams{'DAYS_VALID'} >= '999999') { | |
3963 | $errormessage = $Lang::tr{'invalid input for valid till days'}; | |
3964 | unlink ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}/$cgiparams{'NAME'}.conf") or die "Removing Configfile fail: $!"; | |
3965 | rmdir ("${General::swroot}/ovpn/n2nconf/$cgiparams{'NAME'}") || die "Removing Directory fail: $!"; | |
3966 | goto VPNCONF_ERROR; | |
3967 | } | |
3968 | } | |
3969 | ||
c6c9630e MT |
3970 | if ($cgiparams{'ENABLED'} !~ /^(on|off)$/) { |
3971 | $errormessage = $Lang::tr{'invalid input'}; | |
3972 | goto VPNCONF_ERROR; | |
3973 | } | |
3974 | if ($cgiparams{'EDIT_ADVANCED'} !~ /^(on|off)$/) { | |
3975 | $errormessage = $Lang::tr{'invalid input'}; | |
3976 | goto VPNCONF_ERROR; | |
3977 | } | |
3978 | ||
3979 | #fixplausi | |
3980 | if ($cgiparams{'AUTH'} eq 'psk') { | |
3981 | # if (! length($cgiparams{'PSK'}) ) { | |
3982 | # $errormessage = $Lang::tr{'pre-shared key is too short'}; | |
3983 | # goto VPNCONF_ERROR; | |
3984 | # } | |
3985 | # if ($cgiparams{'PSK'} =~ /['",&]/) { | |
3986 | # $errormessage = $Lang::tr{'invalid characters found in pre-shared key'}; | |
3987 | # goto VPNCONF_ERROR; | |
3988 | # } | |
3989 | } elsif ($cgiparams{'AUTH'} eq 'certreq') { | |
3990 | if ($cgiparams{'KEY'}) { | |
3991 | $errormessage = $Lang::tr{'cant change certificates'}; | |
3992 | goto VPNCONF_ERROR; | |
3993 | } | |
2ad1b18b | 3994 | unless (ref ($cgiparams{'FH'})) { |
c6c9630e MT |
3995 | $errormessage = $Lang::tr{'there was no file upload'}; |
3996 | goto VPNCONF_ERROR; | |
3997 | } | |
3998 | ||
3999 | # Move uploaded certificate request to a temporary file | |
4000 | (my $fh, my $filename) = tempfile( ); | |
4001 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4002 | $errormessage = $!; | |
4003 | goto VPNCONF_ERROR; | |
4004 | } | |
6e13d0a5 | 4005 | |
c6c9630e MT |
4006 | # Sign the certificate request and move it |
4007 | # Sign the host certificate request | |
2feacd98 | 4008 | # The system call is safe, because all arguments are passed as an array. |
f6e12093 | 4009 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4010 | '-batch', '-notext', |
4011 | '-in', $filename, | |
4012 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4013 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4014 | if ($?) { | |
4015 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4016 | unlink ($filename); | |
4017 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4018 | &newcleanssldatabase(); | |
4019 | goto VPNCONF_ERROR; | |
4020 | } else { | |
4021 | unlink ($filename); | |
4022 | &deletebackupcert(); | |
4023 | } | |
4024 | ||
2feacd98 SS |
4025 | my @temp = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); |
4026 | my $temp; | |
4027 | ||
4028 | foreach my $line (@temp) { | |
4029 | if ($line =~ /Subject:.*CN\s?=\s?(.*)[\n]/) { | |
4030 | $temp = $1; | |
4031 | $temp =~ s+/Email+, E+; | |
4032 | $temp =~ s/ ST=/ S=/; | |
4033 | ||
4034 | last; | |
4035 | } | |
4036 | } | |
66c36198 | 4037 | |
c6c9630e MT |
4038 | $cgiparams{'CERT_NAME'} = $temp; |
4039 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4040 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4041 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4042 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4043 | goto VPNCONF_ERROR; | |
4044 | } | |
4045 | } elsif ($cgiparams{'AUTH'} eq 'certfile') { | |
4046 | if ($cgiparams{'KEY'}) { | |
4047 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4048 | goto VPNCONF_ERROR; | |
4049 | } | |
2ad1b18b | 4050 | unless (ref ($cgiparams{'FH'})) { |
c6c9630e MT |
4051 | $errormessage = $Lang::tr{'there was no file upload'}; |
4052 | goto VPNCONF_ERROR; | |
4053 | } | |
4054 | # Move uploaded certificate to a temporary file | |
4055 | (my $fh, my $filename) = tempfile( ); | |
4056 | if (copy ($cgiparams{'FH'}, $fh) != 1) { | |
4057 | $errormessage = $!; | |
4058 | goto VPNCONF_ERROR; | |
4059 | } | |
4060 | ||
4061 | # Verify the certificate has a valid CA and move it | |
4062 | my $validca = 0; | |
2feacd98 SS |
4063 | my @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/cacert.pem", "$filename"); |
4064 | if (grep(/: OK/, @test)) { | |
c6c9630e MT |
4065 | $validca = 1; |
4066 | } else { | |
4067 | foreach my $key (keys %cahash) { | |
2feacd98 SS |
4068 | @test = &General::system_output("/usr/bin/openssl", "verify", "-CAfile", "${General::swroot}/ovpn/ca/$cahash{$key}[0]cert.pem", "$filename"); |
4069 | if (grep(/: OK/, @test)) { | |
c6c9630e MT |
4070 | $validca = 1; |
4071 | } | |
6e13d0a5 | 4072 | } |
c6c9630e MT |
4073 | } |
4074 | if (! $validca) { | |
4075 | $errormessage = $Lang::tr{'certificate does not have a valid ca associated with it'}; | |
4076 | unlink ($filename); | |
4077 | goto VPNCONF_ERROR; | |
4078 | } else { | |
cc79d281 | 4079 | unless(move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem")) { |
c6c9630e MT |
4080 | $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; |
4081 | unlink ($filename); | |
4082 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4083 | } |
c6c9630e MT |
4084 | } |
4085 | ||
2feacd98 SS |
4086 | my @temp = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); |
4087 | my $temp; | |
4088 | ||
4089 | foreach my $line (@temp) { | |
4090 | if ($line =~ /Subject:.*CN\s?=\s?(.*)[\n]/) { | |
4091 | $temp = $1; | |
4092 | $temp =~ s+/Email+, E+; | |
4093 | $temp =~ s/ ST=/ S=/; | |
4094 | ||
4095 | last; | |
4096 | } | |
4097 | } | |
4098 | ||
c6c9630e MT |
4099 | $cgiparams{'CERT_NAME'} = $temp; |
4100 | $cgiparams{'CERT_NAME'} =~ s/,//g; | |
4101 | $cgiparams{'CERT_NAME'} =~ s/\'//g; | |
4102 | if ($cgiparams{'CERT_NAME'} eq '') { | |
4103 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4104 | $errormessage = $Lang::tr{'could not retrieve common name from certificate'}; | |
4105 | goto VPNCONF_ERROR; | |
4106 | } | |
4107 | } elsif ($cgiparams{'AUTH'} eq 'certgen') { | |
4108 | if ($cgiparams{'KEY'}) { | |
4109 | $errormessage = $Lang::tr{'cant change certificates'}; | |
4110 | goto VPNCONF_ERROR; | |
4111 | } | |
4112 | # Validate input since the form was submitted | |
4113 | if (length($cgiparams{'CERT_NAME'}) >60) { | |
4114 | $errormessage = $Lang::tr{'name too long'}; | |
4115 | goto VPNCONF_ERROR; | |
4116 | } | |
194314b2 | 4117 | if ($cgiparams{'CERT_NAME'} eq '' || $cgiparams{'CERT_NAME'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { |
c6c9630e MT |
4118 | $errormessage = $Lang::tr{'invalid input for name'}; |
4119 | goto VPNCONF_ERROR; | |
4120 | } | |
4121 | if ($cgiparams{'CERT_EMAIL'} ne '' && (! &General::validemail($cgiparams{'CERT_EMAIL'}))) { | |
4122 | $errormessage = $Lang::tr{'invalid input for e-mail address'}; | |
4123 | goto VPNCONF_ERROR; | |
4124 | } | |
4125 | if (length($cgiparams{'CERT_EMAIL'}) > 40) { | |
4126 | $errormessage = $Lang::tr{'e-mail address too long'}; | |
4127 | goto VPNCONF_ERROR; | |
4128 | } | |
4129 | if ($cgiparams{'CERT_OU'} ne '' && $cgiparams{'CERT_OU'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4130 | $errormessage = $Lang::tr{'invalid input for department'}; | |
4131 | goto VPNCONF_ERROR; | |
4132 | } | |
4133 | if (length($cgiparams{'CERT_ORGANIZATION'}) >60) { | |
4134 | $errormessage = $Lang::tr{'organization too long'}; | |
4135 | goto VPNCONF_ERROR; | |
4136 | } | |
4137 | if ($cgiparams{'CERT_ORGANIZATION'} !~ /^[a-zA-Z0-9 ,\.\-_]+$/) { | |
4138 | $errormessage = $Lang::tr{'invalid input for organization'}; | |
4139 | goto VPNCONF_ERROR; | |
4140 | } | |
4141 | if ($cgiparams{'CERT_CITY'} ne '' && $cgiparams{'CERT_CITY'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4142 | $errormessage = $Lang::tr{'invalid input for city'}; | |
4143 | goto VPNCONF_ERROR; | |
4144 | } | |
4145 | if ($cgiparams{'CERT_STATE'} ne '' && $cgiparams{'CERT_STATE'} !~ /^[a-zA-Z0-9 ,\.\-_]*$/) { | |
4146 | $errormessage = $Lang::tr{'invalid input for state or province'}; | |
4147 | goto VPNCONF_ERROR; | |
4148 | } | |
4149 | if ($cgiparams{'CERT_COUNTRY'} !~ /^[A-Z]*$/) { | |
4150 | $errormessage = $Lang::tr{'invalid input for country'}; | |
4151 | goto VPNCONF_ERROR; | |
4152 | } | |
4153 | if ($cgiparams{'CERT_PASS1'} ne '' && $cgiparams{'CERT_PASS2'} ne ''){ | |
4154 | if (length($cgiparams{'CERT_PASS1'}) < 5) { | |
4155 | $errormessage = $Lang::tr{'password too short'}; | |
4156 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4157 | } |
66c36198 | 4158 | } |
c6c9630e MT |
4159 | if ($cgiparams{'CERT_PASS1'} ne $cgiparams{'CERT_PASS2'}) { |
4160 | $errormessage = $Lang::tr{'passwords do not match'}; | |
4161 | goto VPNCONF_ERROR; | |
4162 | } | |
425465ed | 4163 | if ($cgiparams{'DAYS_VALID'} eq '' && $cgiparams{'DAYS_VALID'} !~ /^[0-9]+$/) { |
f4fbb935 EK |
4164 | $errormessage = $Lang::tr{'invalid input for valid till days'}; |
4165 | goto VPNCONF_ERROR; | |
4166 | } | |
c6c9630e | 4167 | |
425465ed EK |
4168 | # Check for RW that OpenSSL maximum of valid days will not be exceeded |
4169 | if ($cgiparams{'TYPE'} eq 'host') { | |
4170 | if ($cgiparams{'DAYS_VALID'} >= '999999') { | |
4171 | $errormessage = $Lang::tr{'invalid input for valid till days'}; | |
4172 | goto VPNCONF_ERROR; | |
4173 | } | |
4174 | } | |
4175 | ||
beac479f EK |
4176 | # Check for RW if client name is already set |
4177 | if ($cgiparams{'TYPE'} eq 'host') { | |
4178 | foreach my $key (keys %confighash) { | |
4179 | if ($confighash{$key}[1] eq $cgiparams{'NAME'}) { | |
4180 | $errormessage = $Lang::tr{'a connection with this name already exists'}; | |
4181 | goto VPNCONF_ERROR; | |
4182 | } | |
4183 | } | |
4184 | } | |
4185 | ||
c6c9630e MT |
4186 | # Replace empty strings with a . |
4187 | (my $ou = $cgiparams{'CERT_OU'}) =~ s/^\s*$/\./; | |
4188 | (my $city = $cgiparams{'CERT_CITY'}) =~ s/^\s*$/\./; | |
4189 | (my $state = $cgiparams{'CERT_STATE'}) =~ s/^\s*$/\./; | |
4190 | ||
4191 | # Create the Host certificate request client | |
4192 | my $pid = open(OPENSSL, "|-"); | |
4193 | $SIG{ALRM} = sub { $errormessage = $Lang::tr{'broken pipe'}; goto VPNCONF_ERROR;}; | |
4194 | if ($pid) { # parent | |
4195 | print OPENSSL "$cgiparams{'CERT_COUNTRY'}\n"; | |
4196 | print OPENSSL "$state\n"; | |
4197 | print OPENSSL "$city\n"; | |
4198 | print OPENSSL "$cgiparams{'CERT_ORGANIZATION'}\n"; | |
4199 | print OPENSSL "$ou\n"; | |
4200 | print OPENSSL "$cgiparams{'CERT_NAME'}\n"; | |
4201 | print OPENSSL "$cgiparams{'CERT_EMAIL'}\n"; | |
4202 | print OPENSSL ".\n"; | |
4203 | print OPENSSL ".\n"; | |
4204 | close (OPENSSL); | |
4205 | if ($?) { | |
4206 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4207 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4208 | unlink ("${General::swroot}ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4209 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4210 | } |
c6c9630e | 4211 | } else { # child |
badd8c1c | 4212 | unless (exec ('/usr/bin/openssl', 'req', '-nodes', |
818dde8e | 4213 | '-newkey', 'rsa:4096', |
c6c9630e MT |
4214 | '-keyout', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", |
4215 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4216 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf")) { | |
4217 | $errormessage = "$Lang::tr{'cant start openssl'}: $!"; | |
4218 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4219 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4220 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4221 | } |
c6c9630e | 4222 | } |
66c36198 | 4223 | |
c6c9630e | 4224 | # Sign the host certificate request |
2feacd98 | 4225 | # The system call is safe, because all arguments are passed as an array. |
f6e12093 | 4226 | system('/usr/bin/openssl', 'ca', '-days', "$cgiparams{'DAYS_VALID'}", |
c6c9630e MT |
4227 | '-batch', '-notext', |
4228 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem", | |
4229 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4230 | '-config',"${General::swroot}/ovpn/openssl/ovpn.cnf"); | |
4231 | if ($?) { | |
4232 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4233 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4234 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4235 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4236 | &newcleanssldatabase(); | |
4237 | goto VPNCONF_ERROR; | |
4238 | } else { | |
4239 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}req.pem"); | |
4240 | &deletebackupcert(); | |
4241 | } | |
4242 | ||
4243 | # Create the pkcs12 file | |
2feacd98 | 4244 | # The system call is safe, because all arguments are passed as an array. |
66c36198 | 4245 | system('/usr/bin/openssl', 'pkcs12', '-export', |
c6c9630e MT |
4246 | '-inkey', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem", |
4247 | '-in', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem", | |
4248 | '-name', $cgiparams{'NAME'}, | |
4249 | '-passout', "pass:$cgiparams{'CERT_PASS1'}", | |
66c36198 | 4250 | '-certfile', "${General::swroot}/ovpn/ca/cacert.pem", |
c6c9630e MT |
4251 | '-caname', "$vpnsettings{'ROOTCERT_ORGANIZATION'} CA", |
4252 | '-out', "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4253 | if ($?) { | |
4254 | $errormessage = "$Lang::tr{'openssl produced an error'}: $?"; | |
4255 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4256 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem"); | |
4257 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}.p12"); | |
4258 | goto VPNCONF_ERROR; | |
4259 | } else { | |
4260 | unlink ("${General::swroot}/ovpn/certs/$cgiparams{'NAME'}key.pem"); | |
4261 | } | |
4262 | } elsif ($cgiparams{'AUTH'} eq 'cert') { | |
4263 | ;# Nothing, just editing | |
4264 | } else { | |
4265 | $errormessage = $Lang::tr{'invalid input for authentication method'}; | |
4266 | goto VPNCONF_ERROR; | |
4267 | } | |
4268 | ||
4269 | # Check if there is no other entry with this common name | |
4270 | if ((! $cgiparams{'KEY'}) && ($cgiparams{'AUTH'} ne 'psk')) { | |
4271 | foreach my $key (keys %confighash) { | |
4272 | if ($confighash{$key}[2] eq $cgiparams{'CERT_NAME'}) { | |
4273 | $errormessage = $Lang::tr{'a connection with this common name already exists'}; | |
4274 | goto VPNCONF_ERROR; | |
6e13d0a5 | 4275 | } |
c6c9630e MT |
4276 | } |
4277 | } | |
4278 | ||
ab4cf06c | 4279 | # Save the config |
c6c9630e | 4280 | my $key = $cgiparams{'KEY'}; |
66c36198 | 4281 | |
c6c9630e MT |
4282 | if (! $key) { |
4283 | $key = &General::findhasharraykey (\%confighash); | |
49abe7af | 4284 | foreach my $i (0 .. 43) { $confighash{$key}[$i] = "";} |
c6c9630e | 4285 | } |
8c877a82 AM |
4286 | $confighash{$key}[0] = $cgiparams{'ENABLED'}; |
4287 | $confighash{$key}[1] = $cgiparams{'NAME'}; | |
c6c9630e | 4288 | if ((! $cgiparams{'KEY'}) && $cgiparams{'AUTH'} ne 'psk') { |
8c877a82 | 4289 | $confighash{$key}[2] = $cgiparams{'CERT_NAME'}; |
c6c9630e | 4290 | } |
66c36198 | 4291 | |
8c877a82 | 4292 | $confighash{$key}[3] = $cgiparams{'TYPE'}; |
c6c9630e | 4293 | if ($cgiparams{'AUTH'} eq 'psk') { |
8c877a82 AM |
4294 | $confighash{$key}[4] = 'psk'; |
4295 | $confighash{$key}[5] = $cgiparams{'PSK'}; | |
c6c9630e | 4296 | } else { |
8c877a82 | 4297 | $confighash{$key}[4] = 'cert'; |
c6c9630e | 4298 | } |
ce9abb66 | 4299 | if ($cgiparams{'TYPE'} eq 'net') { |
8c877a82 AM |
4300 | $confighash{$key}[6] = $cgiparams{'SIDE'}; |
4301 | $confighash{$key}[11] = $cgiparams{'REMOTE_SUBNET'}; | |
ce9abb66 | 4302 | } |
4c962356 | 4303 | $confighash{$key}[8] = $cgiparams{'LOCAL_SUBNET'}; |
8c877a82 | 4304 | $confighash{$key}[10] = $cgiparams{'REMOTE'}; |
4c962356 | 4305 | if ($cgiparams{'OVPN_MGMT'} eq '') { |
8c877a82 | 4306 | $confighash{$key}[22] = $confighash{$key}[29]; |
4c962356 | 4307 | } else { |
8c877a82 | 4308 | $confighash{$key}[22] = $cgiparams{'OVPN_MGMT'}; |
4c962356 | 4309 | } |
8c877a82 AM |
4310 | $confighash{$key}[23] = $cgiparams{'MSSFIX'}; |
4311 | $confighash{$key}[24] = $cgiparams{'FRAGMENT'}; | |
4312 | $confighash{$key}[25] = $cgiparams{'REMARK'}; | |
4313 | $confighash{$key}[26] = $cgiparams{'INTERFACE'}; | |
66c36198 | 4314 | # new fields |
8c877a82 AM |
4315 | $confighash{$key}[27] = $cgiparams{'OVPN_SUBNET'}; |
4316 | $confighash{$key}[28] = $cgiparams{'PROTOCOL'}; | |
4317 | $confighash{$key}[29] = $cgiparams{'DEST_PORT'}; | |
4318 | $confighash{$key}[30] = $cgiparams{'COMPLZO'}; | |
4319 | $confighash{$key}[31] = $cgiparams{'MTU'}; | |
4320 | $confighash{$key}[32] = $cgiparams{'CHECK1'}; | |
df9b48b7 | 4321 | $name=$cgiparams{'CHECK1'}; |
8c877a82 AM |
4322 | $confighash{$key}[33] = $cgiparams{$name}; |
4323 | $confighash{$key}[34] = $cgiparams{'RG'}; | |
4324 | $confighash{$key}[35] = $cgiparams{'CCD_DNS1'}; | |
4325 | $confighash{$key}[36] = $cgiparams{'CCD_DNS2'}; | |
4326 | $confighash{$key}[37] = $cgiparams{'CCD_WINS'}; | |
4c962356 EK |
4327 | $confighash{$key}[39] = $cgiparams{'DAUTH'}; |
4328 | $confighash{$key}[40] = $cgiparams{'DCIPHER'}; | |
350f2980 | 4329 | |
71af643c MT |
4330 | if (($cgiparams{'TYPE'} eq 'host') && ($cgiparams{'CERT_PASS1'} eq "")) { |
4331 | $confighash{$key}[41] = "no-pass"; | |
4332 | } | |
4333 | ||
e1e10515 TE |
4334 | $confighash{$key}[42] = 'HOTP/T30/6'; |
4335 | $confighash{$key}[43] = $cgiparams{'OTP_STATE'}; | |
16d4a5c2 | 4336 | if (($confighash{$key}[43] eq 'on') && ($confighash{$key}[44] eq '')) { |
e1e10515 | 4337 | my @otp_secret = &General::system_output("/usr/bin/openssl", "rand", "-hex", "20"); |
209d62f0 | 4338 | chomp($otp_secret[0]); |
e1e10515 | 4339 | $confighash{$key}[44] = $otp_secret[0]; |
16d4a5c2 | 4340 | } elsif ($confighash{$key}[43] eq '') { |
e1e10515 TE |
4341 | $confighash{$key}[44] = ''; |
4342 | } | |
4343 | ||
c6c9630e | 4344 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
66c36198 | 4345 | |
8c877a82 | 4346 | if ($cgiparams{'CHECK1'} ){ |
66c36198 | 4347 | |
8c877a82 AM |
4348 | my ($ccdip,$ccdsub)=split "/",$cgiparams{$name}; |
4349 | my ($a,$b,$c,$d) = split (/\./,$ccdip); | |
df9b48b7 AM |
4350 | if ( -e "${General::swroot}/ovpn/ccd/$confighash{$key}[2]"){ |
4351 | unlink "${General::swroot}/ovpn/ccd/$cgiparams{'CERT_NAME'}"; | |
4352 | } | |
8c877a82 | 4353 | open ( CCDRWCONF,'>',"${General::swroot}/ovpn/ccd/$confighash{$key}[2]") or die "Unable to create clientconfigfile $!"; |
82c809c7 | 4354 | print CCDRWCONF "# OpenVPN clientconfig from ccd extension by Copymaster#\n\n"; |
8c877a82 AM |
4355 | if($cgiparams{'CHECK1'} eq 'dynamic'){ |
4356 | print CCDRWCONF "#This client uses the dynamic pool\n"; | |
4357 | }else{ | |
82c809c7 | 4358 | print CCDRWCONF "#Ip address client and server\n"; |
8c877a82 AM |
4359 | print CCDRWCONF "ifconfig-push $ccdip ".&General::getlastip($ccdip,1)."\n"; |
4360 | } | |
4361 | if ($confighash{$key}[34] eq 'on'){ | |
4362 | print CCDRWCONF "\n#Redirect Gateway: \n#All IP traffic is redirected through the vpn \n"; | |
4363 | print CCDRWCONF "push redirect-gateway\n"; | |
4364 | } | |
52d08bcb | 4365 | &General::readhasharray("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); |
8c877a82 | 4366 | if ($cgiparams{'IR'} ne ''){ |
82c809c7 | 4367 | print CCDRWCONF "\n#Client routes these networks (behind Client)\n"; |
8c877a82 AM |
4368 | foreach my $key (keys %ccdroutehash){ |
4369 | if ($ccdroutehash{$key}[0] eq $cgiparams{'NAME'}){ | |
4370 | foreach my $i ( 1 .. $#{$ccdroutehash{$key}}){ | |
4371 | my ($a,$b)=split (/\//,$ccdroutehash{$key}[$i]); | |
4372 | print CCDRWCONF "iroute $a $b\n"; | |
4373 | } | |
4374 | } | |
4375 | } | |
4376 | } | |
52d08bcb | 4377 | if ($cgiparams{'IFROUTE'} eq $Lang::tr{'ccd none'} ){$cgiparams{'IFROUTE'}='';} |
8c877a82 | 4378 | if ($cgiparams{'IFROUTE'} ne ''){ |
82c809c7 | 4379 | print CCDRWCONF "\n#Client gets routes to these networks (behind IPFire)\n"; |
8c877a82 AM |
4380 | foreach my $key (keys %ccdroute2hash){ |
4381 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4382 | foreach my $i ( 1 .. $#{$ccdroute2hash{$key}}){ | |
4383 | if($ccdroute2hash{$key}[$i] eq $Lang::tr{'blue'}){ | |
4384 | my %blue=(); | |
4385 | &General::readhash("${General::swroot}/ethernet/settings", \%blue); | |
52d08bcb | 4386 | print CCDRWCONF "push \"route $blue{BLUE_ADDRESS} $blue{BLUE_NETMASK}\n"; |
8c877a82 AM |
4387 | }elsif($ccdroute2hash{$key}[$i] eq $Lang::tr{'orange'}){ |
4388 | my %orange=(); | |
4389 | &General::readhash("${General::swroot}/ethernet/settings", \%orange); | |
4390 | print CCDRWCONF "push \"route $orange{ORANGE_ADDRESS} $orange{ORANGE_NETMASK}\n"; | |
4391 | }else{ | |
4392 | my ($a,$b)=split (/\//,$ccdroute2hash{$key}[$i]); | |
4393 | print CCDRWCONF "push \"route $a $b\"\n"; | |
4394 | } | |
4395 | } | |
4396 | } | |
4397 | } | |
4398 | } | |
4399 | if(($cgiparams{'CCD_DNS1'} eq '') && ($cgiparams{'CCD_DNS1'} ne '')){ $cgiparams{'CCD_DNS1'} = $cgiparams{'CCD_DNS2'};$cgiparams{'CCD_DNS2'}='';} | |
4400 | if($cgiparams{'CCD_DNS1'} ne ''){ | |
82c809c7 | 4401 | print CCDRWCONF "\n#Client gets these nameservers\n"; |
8c877a82 AM |
4402 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS1'}\" \n"; |
4403 | } | |
4404 | if($cgiparams{'CCD_DNS2'} ne ''){ | |
4405 | print CCDRWCONF "push \"dhcp-option DNS $cgiparams{'CCD_DNS2'}\" \n"; | |
4406 | } | |
4407 | if($cgiparams{'CCD_WINS'} ne ''){ | |
4408 | print CCDRWCONF "\n#Client gets this WINS server\n"; | |
4409 | print CCDRWCONF "push \"dhcp-option WINS $cgiparams{'CCD_WINS'}\" \n"; | |
4410 | } | |
4411 | close CCDRWCONF; | |
4412 | } | |
18837a6a AH |
4413 | |
4414 | ### | |
4415 | # m.a.d n2n begin | |
4416 | ### | |
66c36198 | 4417 | |
18837a6a | 4418 | if ($cgiparams{'TYPE'} eq 'net') { |
66c36198 | 4419 | |
2feacd98 SS |
4420 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { |
4421 | &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); | |
66c36198 | 4422 | |
2feacd98 SS |
4423 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); |
4424 | my $key = $cgiparams{'KEY'}; | |
4425 | if (! $key) { | |
4426 | $key = &General::findhasharraykey (\%confighash); | |
4427 | foreach my $i (0 .. 31) { | |
4428 | $confighash{$key}[$i] = ""; | |
4429 | } | |
4430 | } | |
4431 | ||
4432 | $confighash{$key}[0] = 'on'; | |
4433 | &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
66c36198 | 4434 | |
2feacd98 SS |
4435 | &General::system("/usr/local/bin/openvpnctrl", "-sn2n", "$confighash{$cgiparams{'KEY'}}[1]"); |
4436 | } | |
4437 | } | |
18837a6a AH |
4438 | |
4439 | ### | |
4440 | # m.a.d n2n end | |
66c36198 | 4441 | ### |
18837a6a | 4442 | |
c6c9630e MT |
4443 | if ($cgiparams{'EDIT_ADVANCED'} eq 'on') { |
4444 | $cgiparams{'KEY'} = $key; | |
4445 | $cgiparams{'ACTION'} = $Lang::tr{'advanced'}; | |
4446 | } | |
4447 | goto VPNCONF_END; | |
6e13d0a5 | 4448 | } else { |
c6c9630e | 4449 | $cgiparams{'ENABLED'} = 'on'; |
54fd0535 MT |
4450 | ### |
4451 | # m.a.d n2n begin | |
66c36198 | 4452 | ### |
54fd0535 MT |
4453 | $cgiparams{'MSSFIX'} = 'on'; |
4454 | $cgiparams{'FRAGMENT'} = '1300'; | |
70900745 | 4455 | $cgiparams{'DAUTH'} = 'SHA512'; |
54fd0535 MT |
4456 | ### |
4457 | # m.a.d n2n end | |
66c36198 | 4458 | ### |
4c962356 | 4459 | $cgiparams{'SIDE'} = 'left'; |
c6c9630e MT |
4460 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { |
4461 | $cgiparams{'AUTH'} = 'psk'; | |
4462 | } elsif ( ! -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
4463 | $cgiparams{'AUTH'} = 'certfile'; | |
4464 | } else { | |
6e13d0a5 | 4465 | $cgiparams{'AUTH'} = 'certgen'; |
c6c9630e MT |
4466 | } |
4467 | $cgiparams{'LOCAL_SUBNET'} ="$netsettings{'GREEN_NETADDRESS'}/$netsettings{'GREEN_NETMASK'}"; | |
4468 | $cgiparams{'CERT_ORGANIZATION'} = $vpnsettings{'ROOTCERT_ORGANIZATION'}; | |
4469 | $cgiparams{'CERT_CITY'} = $vpnsettings{'ROOTCERT_CITY'}; | |
4470 | $cgiparams{'CERT_STATE'} = $vpnsettings{'ROOTCERT_STATE'}; | |
4471 | $cgiparams{'CERT_COUNTRY'} = $vpnsettings{'ROOTCERT_COUNTRY'}; | |
c0a7c9b2 | 4472 | $cgiparams{'DAYS_VALID'} = $vpnsettings{'DAYS_VALID'} = '730'; |
6e13d0a5 | 4473 | } |
c6c9630e | 4474 | |
6e13d0a5 | 4475 | VPNCONF_ERROR: |
6e13d0a5 MT |
4476 | $checked{'ENABLED'}{'off'} = ''; |
4477 | $checked{'ENABLED'}{'on'} = ''; | |
4478 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
4479 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
4480 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
4481 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
4482 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
4483 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
4484 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
4485 | |
4486 | ||
6e13d0a5 MT |
4487 | $checked{'EDIT_ADVANCED'}{'off'} = ''; |
4488 | $checked{'EDIT_ADVANCED'}{'on'} = ''; | |
4489 | $checked{'EDIT_ADVANCED'}{$cgiparams{'EDIT_ADVANCED'}} = 'CHECKED'; | |
c6c9630e | 4490 | |
6e13d0a5 MT |
4491 | $selected{'SIDE'}{'server'} = ''; |
4492 | $selected{'SIDE'}{'client'} = ''; | |
4493 | $selected{'SIDE'}{$cgiparams{'SIDE'}} = 'SELECTED'; | |
66c36198 | 4494 | |
d96c89eb AH |
4495 | $selected{'PROTOCOL'}{'udp'} = ''; |
4496 | $selected{'PROTOCOL'}{'tcp'} = ''; | |
4497 | $selected{'PROTOCOL'}{$cgiparams{'PROTOCOL'}} = 'SELECTED'; | |
4498 | ||
c6c9630e | 4499 | |
6e13d0a5 MT |
4500 | $checked{'AUTH'}{'psk'} = ''; |
4501 | $checked{'AUTH'}{'certreq'} = ''; | |
4502 | $checked{'AUTH'}{'certgen'} = ''; | |
4503 | $checked{'AUTH'}{'certfile'} = ''; | |
4504 | $checked{'AUTH'}{$cgiparams{'AUTH'}} = 'CHECKED'; | |
c6c9630e | 4505 | |
6e13d0a5 | 4506 | $selected{'INTERFACE'}{$cgiparams{'INTERFACE'}} = 'SELECTED'; |
66c36198 | 4507 | |
6e13d0a5 MT |
4508 | $checked{'COMPLZO'}{'off'} = ''; |
4509 | $checked{'COMPLZO'}{'on'} = ''; | |
4510 | $checked{'COMPLZO'}{$cgiparams{'COMPLZO'}} = 'CHECKED'; | |
c6c9630e | 4511 | |
d96c89eb AH |
4512 | $checked{'MSSFIX'}{'off'} = ''; |
4513 | $checked{'MSSFIX'}{'on'} = ''; | |
4514 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
4515 | ||
52f61e49 EKD |
4516 | $selected{'DCIPHER'}{'AES-256-GCM'} = ''; |
4517 | $selected{'DCIPHER'}{'AES-192-GCM'} = ''; | |
4518 | $selected{'DCIPHER'}{'AES-128-GCM'} = ''; | |
4c962356 EK |
4519 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
4520 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
4521 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
4522 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
4523 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
4524 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
4525 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4526 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; | |
4527 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; | |
4528 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
4529 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
4530 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 4531 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
49abe7af EK |
4532 | # If no cipher has been chossen yet, select |
4533 | # the old default (AES-256-CBC) for compatiblity reasons. | |
4534 | if ($cgiparams{'DCIPHER'} eq '') { | |
4535 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; | |
4536 | } | |
4c962356 | 4537 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
49abe7af EK |
4538 | $selected{'DAUTH'}{'whirlpool'} = ''; |
4539 | $selected{'DAUTH'}{'SHA512'} = ''; | |
4540 | $selected{'DAUTH'}{'SHA384'} = ''; | |
4541 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4542 | $selected{'DAUTH'}{'SHA1'} = ''; | |
49abe7af | 4543 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; |
0c4ffc69 EK |
4544 | $checked{'TLSAUTH'}{'off'} = ''; |
4545 | $checked{'TLSAUTH'}{'on'} = ''; | |
4546 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
49abe7af | 4547 | |
6e13d0a5 MT |
4548 | if (1) { |
4549 | &Header::showhttpheaders(); | |
4c962356 | 4550 | &Header::openpage($Lang::tr{'ovpn'}, 1, ''); |
6e13d0a5 MT |
4551 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); |
4552 | if ($errormessage) { | |
4553 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); | |
4554 | print "<class name='base'>$errormessage"; | |
4555 | print " </class>"; | |
4556 | &Header::closebox(); | |
4557 | } | |
c6c9630e | 4558 | |
6e13d0a5 MT |
4559 | if ($warnmessage) { |
4560 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:"); | |
4561 | print "<class name='base'>$warnmessage"; | |
4562 | print " </class>"; | |
4563 | &Header::closebox(); | |
4564 | } | |
c6c9630e | 4565 | |
6e13d0a5 | 4566 | print "<form method='post' enctype='multipart/form-data'>"; |
ce9abb66 | 4567 | print "<input type='hidden' name='TYPE' value='$cgiparams{'TYPE'}' />"; |
c6c9630e | 4568 | |
6e13d0a5 MT |
4569 | if ($cgiparams{'KEY'}) { |
4570 | print "<input type='hidden' name='KEY' value='$cgiparams{'KEY'}' />"; | |
4571 | print "<input type='hidden' name='AUTH' value='$cgiparams{'AUTH'}' />"; | |
6e13d0a5 | 4572 | } |
c6c9630e | 4573 | |
6e13d0a5 | 4574 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'connection'}:"); |
8c877a82 | 4575 | print "<table width='100%' border='0'>\n"; |
4c962356 | 4576 | |
e3edceeb | 4577 | print "<tr><td width='14%' class='boldbase'>$Lang::tr{'name'}: <img src='/blob.gif' alt='*' /></td>"; |
66c36198 | 4578 | |
ce9abb66 | 4579 | if ($cgiparams{'TYPE'} eq 'host') { |
6e13d0a5 | 4580 | if ($cgiparams{'KEY'}) { |
8c877a82 | 4581 | print "<td width='35%' class='base'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; |
6e13d0a5 MT |
4582 | } else { |
4583 | print "<td width='35%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' size='30' /></td>"; | |
4584 | } | |
c6c9630e MT |
4585 | # print "<tr><td>$Lang::tr{'interface'}</td>"; |
4586 | # print "<td><select name='INTERFACE'>"; | |
4587 | # print "<option value='RED' $selected{'INTERFACE'}{'RED'}>RED</option>"; | |
4c962356 EK |
4588 | # if ($netsettings{'BLUE_DEV'} ne '') { |
4589 | # print "<option value='BLUE' $selected{'INTERFACE'}{'BLUE'}>BLUE</option>"; | |
4590 | # } | |
4591 | # print "<option value='GREEN' $selected{'INTERFACE'}{'GREEN'}>GREEN</option>"; | |
4592 | # print "<option value='ORANGE' $selected{'INTERFACE'}{'ORANGE'}>ORANGE</option>"; | |
4593 | # print "</select></td></tr>"; | |
4594 | # print <<END; | |
ce9abb66 AH |
4595 | } else { |
4596 | print "<input type='hidden' name='INTERFACE' value='red' />"; | |
4597 | if ($cgiparams{'KEY'}) { | |
4598 | print "<td width='25%' class='base' nowrap='nowrap'><input type='hidden' name='NAME' value='$cgiparams{'NAME'}' />$cgiparams{'NAME'}</td>"; | |
4599 | } else { | |
4600 | print "<td width='25%'><input type='text' name='NAME' value='$cgiparams{'NAME'}' maxlength='20' /></td>"; | |
4601 | } | |
52f61e49 EKD |
4602 | |
4603 | # If GCM ciphers are in usage, HMAC menu is disabled | |
4604 | my $hmacdisabled; | |
4605 | if (($confighash{$cgiparams{'KEY'}}[40] eq 'AES-256-GCM') || | |
4606 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-192-GCM') || | |
4607 | ($confighash{$cgiparams{'KEY'}}[40] eq 'AES-128-GCM')) { | |
4608 | $hmacdisabled = "disabled='disabled'"; | |
4609 | }; | |
4610 | ||
4c962356 | 4611 | print <<END; |
ce9abb66 | 4612 | <td width='25%'> </td> |
66c36198 | 4613 | <td width='25%'> </td></tr> |
f527e53f EK |
4614 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'Act as'}</td> |
4615 | <td><select name='SIDE'> | |
4616 | <option value='server' $selected{'SIDE'}{'server'}>$Lang::tr{'openvpn server'}</option> | |
4617 | <option value='client' $selected{'SIDE'}{'client'}>$Lang::tr{'openvpn client'}</option> | |
4618 | </select> | |
4619 | </td> | |
4c962356 | 4620 | |
f527e53f EK |
4621 | <td class='boldbase'>$Lang::tr{'remote host/ip'}:</td> |
4622 | <td><input type='TEXT' name='REMOTE' value='$cgiparams{'REMOTE'}' /></td> | |
4623 | </tr> | |
4c962356 | 4624 | |
e3edceeb | 4625 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'local subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4626 | <td><input type='TEXT' name='LOCAL_SUBNET' value='$cgiparams{'LOCAL_SUBNET'}' /></td> |
4c962356 | 4627 | |
e3edceeb | 4628 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'remote subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f EK |
4629 | <td><input type='text' name='REMOTE_SUBNET' value='$cgiparams{'REMOTE_SUBNET'}' /></td> |
4630 | </tr> | |
4c962356 | 4631 | |
e3edceeb | 4632 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'ovpn subnet'} <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4633 | <td><input type='TEXT' name='OVPN_SUBNET' value='$cgiparams{'OVPN_SUBNET'}' /></td> |
49abe7af | 4634 | |
f527e53f EK |
4635 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
4636 | <td><select name='PROTOCOL'> | |
4637 | <option value='udp' $selected{'PROTOCOL'}{'udp'}>UDP</option> | |
4638 | <option value='tcp' $selected{'PROTOCOL'}{'tcp'}>TCP</option></select></td> | |
4639 | </tr> | |
66c36198 | 4640 | |
f527e53f | 4641 | <tr> |
e3edceeb | 4642 | <td class='boldbase'>$Lang::tr{'destination port'}: <img src='/blob.gif' alt='*' /></td> |
f527e53f | 4643 | <td><input type='TEXT' name='DEST_PORT' value='$cgiparams{'DEST_PORT'}' size='5' /></td> |
4c962356 | 4644 | |
e3edceeb | 4645 | <td class='boldbase' nowrap='nowrap'>Management Port ($Lang::tr{'openvpn default'}: <span class="base">$Lang::tr{'destination port'}):</td> |
f527e53f EK |
4646 | <td> <input type='TEXT' name='OVPN_MGMT' VALUE='$cgiparams{'OVPN_MGMT'}'size='5' /></td> |
4647 | </tr> | |
49abe7af | 4648 | |
f527e53f | 4649 | <tr><td colspan=4><hr /></td></tr><tr> |
66c36198 | 4650 | |
f527e53f | 4651 | <tr> |
f99ed824 | 4652 | <td class='base'><b>$Lang::tr{'MTU settings'}</b></td> |
f527e53f | 4653 | </tr> |
49abe7af | 4654 | |
e3edceeb | 4655 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'}</td> |
f527e53f EK |
4656 | <td><input type='TEXT' name='MTU' VALUE='$cgiparams{'MTU'}'size='5' /></td> |
4657 | <td colspan='2'>$Lang::tr{'openvpn default'}: udp/tcp <span class="base">1500/1400</span></td> | |
4658 | </tr> | |
4c962356 | 4659 | |
e3edceeb | 4660 | <tr><td class='boldbase' nowrap='nowrap'>fragment:</td> |
f527e53f EK |
4661 | <td><input type='TEXT' name='FRAGMENT' VALUE='$cgiparams{'FRAGMENT'}'size='5' /></td> |
4662 | <td>$Lang::tr{'openvpn default'}: <span class="base">1300</span></td> | |
4663 | </tr> | |
4c962356 | 4664 | |
e3edceeb | 4665 | <tr><td class='boldbase' nowrap='nowrap'>mssfix:</td> |
f527e53f EK |
4666 | <td><input type='checkbox' name='MSSFIX' $checked{'MSSFIX'}{'on'} /></td> |
4667 | <td>$Lang::tr{'openvpn default'}: <span class="base">on</span></td> | |
4668 | </tr> | |
4c962356 | 4669 | |
e3edceeb | 4670 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'comp-lzo'}</td> |
f527e53f EK |
4671 | <td><input type='checkbox' name='COMPLZO' $checked{'COMPLZO'}{'on'} /></td> |
4672 | </tr> | |
2ee746be | 4673 | |
f527e53f EK |
4674 | <tr><td colspan=4><hr /></td></tr><tr> |
4675 | <tr> | |
f99ed824 | 4676 | <td class='base'><b>$Lang::tr{'ovpn crypt options'}:</b></td> |
f527e53f EK |
4677 | </tr> |
4678 | ||
4679 | <tr><td class='boldbase'>$Lang::tr{'cipher'}</td> | |
52f61e49 EKD |
4680 | <td><select name='DCIPHER' id="n2ncipher" required> |
4681 | <option value='AES-256-GCM' $selected{'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang::tr{'bit'})</option> | |
4682 | <option value='AES-192-GCM' $selected{'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang::tr{'bit'})</option> | |
4683 | <option value='AES-128-GCM' $selected{'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang::tr{'bit'})</option> | |
f527e53f EK |
4684 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> |
4685 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> | |
4686 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> | |
f7fb5bc5 | 4687 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'}, $Lang::tr{'default'})</option> |
f527e53f EK |
4688 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> |
4689 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
ea6dd5b0 EK |
4690 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
4691 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4692 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4693 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4694 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4695 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
f527e53f EK |
4696 | </select> |
4697 | </td> | |
4698 | ||
4699 | <td class='boldbase'>$Lang::tr{'ovpn ha'}:</td> | |
52f61e49 | 4700 | <td><select name='DAUTH' id="n2nhmac" $hmacdisabled> |
f527e53f EK |
4701 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> |
4702 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
4703 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
4704 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
f3dfb261 | 4705 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
f527e53f EK |
4706 | </select> |
4707 | </td> | |
4708 | </tr> | |
4709 | <tr><td colspan=4><hr /></td></tr><tr> | |
4710 | ||
ce9abb66 | 4711 | END |
8c877a82 | 4712 | ; |
ce9abb66 | 4713 | } |
52f61e49 EKD |
4714 | |
4715 | #### JAVA SCRIPT #### | |
4716 | # Validate N2N cipher. If GCM will be used, HMAC menu will be disabled onchange | |
4717 | print<<END; | |
4718 | <script> | |
4719 | var disable_options = false; | |
4720 | document.getElementById('n2ncipher').onchange = function () { | |
4721 | if((this.value == "AES-256-GCM"||this.value == "AES-192-GCM"||this.value == "AES-128-GCM")) { | |
4722 | document.getElementById('n2nhmac').setAttribute('disabled', true); | |
4723 | } else { | |
4724 | document.getElementById('n2nhmac').removeAttribute('disabled'); | |
4725 | } | |
4726 | } | |
4727 | </script> | |
4728 | END | |
4729 | ||
2ee746be | 4730 | #jumper |
e3edceeb | 4731 | print "<tr><td class='boldbase'>$Lang::tr{'remark title'}</td>"; |
8c877a82 | 4732 | print "<td colspan='3'><input type='text' name='REMARK' value='$cgiparams{'REMARK'}' size='55' maxlength='50' /></td></tr></table>"; |
66c36198 | 4733 | |
ce9abb66 | 4734 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 | 4735 | print "<tr><td>$Lang::tr{'enabled'} <input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td>"; |
66c36198 | 4736 | } |
ce9abb66 | 4737 | |
8c877a82 | 4738 | print"</tr></table><br><br>"; |
66c36198 PM |
4739 | #A.Marx CCD new client |
4740 | if ($cgiparams{'TYPE'} eq 'host') { | |
8c877a82 | 4741 | print "<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td colspan='3'><hr><br><b>$Lang::tr{'ccd choose net'}</td></tr><tr><td height='20' colspan='3'></td></tr>"; |
8c877a82 AM |
4742 | my %vpnnet=(); |
4743 | my $vpnip; | |
4744 | &General::readhash("${General::swroot}/ovpn/settings", \%vpnnet); | |
4745 | $vpnip=$vpnnet{'DOVPN_SUBNET'}; | |
4746 | &General::readhasharray("${General::swroot}/ovpn/ccd.conf", \%ccdconfhash); | |
4747 | my @ccdconf=(); | |
4748 | my $count=0; | |
4749 | my $checked; | |
4750 | $checked{'check1'}{'off'} = ''; | |
4751 | $checked{'check1'}{'on'} = ''; | |
4752 | $checked{'check1'}{$cgiparams{'CHECK1'}} = 'CHECKED'; | |
4753 | print"<tr><td align='center' width='1%' valign='top'><input type='radio' name='CHECK1' value='dynamic' checked /></td><td align='left' valign='top' width='35%'>$Lang::tr{'ccd dynrange'} ($vpnip)</td><td width='30%'>"; | |
4754 | print"</td></tr></table><br><br>"; | |
4755 | my $name=$cgiparams{'CHECK1'}; | |
4756 | $checked{'RG'}{$cgiparams{'RG'}} = 'CHECKED'; | |
e1e10515 | 4757 | $checked{'OTP_STATE'}{$cgiparams{'OTP_STATE'}} = 'CHECKED'; |
66c36198 PM |
4758 | |
4759 | if (! -z "${General::swroot}/ovpn/ccd.conf"){ | |
8c877a82 | 4760 | print"<table border='0' width='100%' cellspacing='1' cellpadding='0'><tr><td width='1%'></td><td width='30%' class='boldbase' align='center'><b>$Lang::tr{'ccd name'}</td><td width='15%' class='boldbase' align='center'><b>$Lang::tr{'network'}</td><td class='boldbase' align='center' width='18%'><b>$Lang::tr{'ccd clientip'}</td></tr>"; |
df9b48b7 | 4761 | foreach my $key (sort { uc($ccdconfhash{$a}[0]) cmp uc($ccdconfhash{$b}[0]) } keys %ccdconfhash) { |
8c877a82 AM |
4762 | $count++; |
4763 | @ccdconf=($ccdconfhash{$key}[0],$ccdconfhash{$key}[1]); | |
4764 | if ($count % 2){print"<tr bgcolor='$color{'color22'}'>";}else{print"<tr bgcolor='$color{'color20'}'>";} | |
4765 | print"<td align='center' width='1%'><input type='radio' name='CHECK1' value='$ccdconf[0]' $checked{'check1'}{$ccdconf[0]}/></td><td>$ccdconf[0]</td><td width='40%' align='center'>$ccdconf[1]</td><td align='left' width='10%'>"; | |
4766 | &fillselectbox($ccdconf[1],$ccdconf[0],$cgiparams{$name}); | |
4767 | print"</td></tr>"; | |
4768 | } | |
4769 | print "</table><br><br><hr><br><br>"; | |
4770 | } | |
e81be1e1 | 4771 | } |
8c877a82 | 4772 | # ccd end |
6e13d0a5 MT |
4773 | &Header::closebox(); |
4774 | if ($cgiparams{'KEY'} && $cgiparams{'AUTH'} eq 'psk') { | |
66c36198 | 4775 | |
8c877a82 | 4776 | } elsif (! $cgiparams{'KEY'}) { |
66c36198 PM |
4777 | |
4778 | ||
6e13d0a5 MT |
4779 | my $disabled=''; |
4780 | my $cakeydisabled=''; | |
4781 | my $cacrtdisabled=''; | |
4782 | if ( ! -f "${General::swroot}/ovpn/ca/cakey.pem" ) { $cakeydisabled = "disabled='disabled'" } else { $cakeydisabled = "" }; | |
4783 | if ( ! -f "${General::swroot}/ovpn/ca/cacert.pem" ) { $cacrtdisabled = "disabled='disabled'" } else { $cacrtdisabled = "" }; | |
66c36198 | 4784 | |
6e13d0a5 | 4785 | &Header::openbox('100%', 'LEFT', $Lang::tr{'authentication'}); |
66c36198 PM |
4786 | |
4787 | ||
ce9abb66 AH |
4788 | if ($cgiparams{'TYPE'} eq 'host') { |
4789 | ||
49abe7af | 4790 | print <<END; |
6e13d0a5 | 4791 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
66c36198 | 4792 | |
ce9abb66 AH |
4793 | <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> |
4794 | <tr><td><input type='radio' name='AUTH' value='certfile' $checked{'AUTH'}{'certfile'} $cacrtdisabled /></td><td class='base'>$Lang::tr{'upload a certificate'}</td></tr> | |
54fd0535 MT |
4795 | <tr><td colspan='3'> </td></tr> |
4796 | <tr><td colspan='3'><hr /></td></tr> | |
4797 | <tr><td colspan='3'> </td></tr> | |
ce9abb66 | 4798 | <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> |
e3edceeb LS |
4799 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> |
4800 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4801 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4802 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4803 | <tr><td> </td><td class='base'>$Lang::tr{'city'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4804 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
ce9abb66 | 4805 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
6e13d0a5 | 4806 | END |
ce9abb66 AH |
4807 | ; |
4808 | ||
4809 | ### | |
7c1d9faf | 4810 | # m.a.d net2net |
ce9abb66 AH |
4811 | ### |
4812 | ||
4813 | } else { | |
4814 | ||
49abe7af | 4815 | print <<END; |
ce9abb66 | 4816 | <table width='100%' cellpadding='0' cellspacing='5' border='0'> |
66c36198 | 4817 | |
ce9abb66 | 4818 | <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> |
e3edceeb LS |
4819 | <tr><td> </td><td class='base'>$Lang::tr{'users fullname or system hostname'}: <img src='/blob.gif' alt='*' /></td><td class='base' nowrap='nowrap'><input type='text' name='CERT_NAME' value='$cgiparams{'CERT_NAME'}' SIZE='32' $cakeydisabled /></td></tr> |
4820 | <tr><td> </td><td class='base'>$Lang::tr{'users email'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_EMAIL' value='$cgiparams{'CERT_EMAIL'}' SIZE='32' $cakeydisabled /></td></tr> | |
4821 | <tr><td> </td><td class='base'>$Lang::tr{'users department'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_OU' value='$cgiparams{'CERT_OU'}' SIZE='32' $cakeydisabled /></td></tr> | |
4822 | <tr><td> </td><td class='base'>$Lang::tr{'organization name'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_ORGANIZATION' value='$cgiparams{'CERT_ORGANIZATION'}' SIZE='32' $cakeydisabled /></td></tr> | |
4823 | <tr><td> </td><td class='base'>$Lang::tr{'city'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_CITY' value='$cgiparams{'CERT_CITY'}' SIZE='32' $cakeydisabled /></td></tr> | |
4824 | <tr><td> </td><td class='base'>$Lang::tr{'state or province'}:</td><td class='base' nowrap='nowrap'><input type='text' name='CERT_STATE' value='$cgiparams{'CERT_STATE'}' SIZE='32' $cakeydisabled /></td></tr> | |
ce9abb66 | 4825 | <tr><td> </td><td class='base'>$Lang::tr{'country'}:</td><td class='base'><select name='CERT_COUNTRY' $cakeydisabled> |
66c36198 PM |
4826 | |
4827 | ||
ce9abb66 AH |
4828 | END |
4829 | ; | |
4830 | ||
4831 | } | |
4832 | ||
4833 | ### | |
7c1d9faf | 4834 | # m.a.d net2net |
ce9abb66 | 4835 | ### |
c6c9630e | 4836 | |
6e13d0a5 MT |
4837 | foreach my $country (sort keys %{Countries::countries}) { |
4838 | print "<option value='$Countries::countries{$country}'"; | |
4839 | if ( $Countries::countries{$country} eq $cgiparams{'CERT_COUNTRY'} ) { | |
4840 | print " selected='selected'"; | |
4841 | } | |
4842 | print ">$country</option>"; | |
4843 | } | |
ce9abb66 | 4844 | ### |
7c1d9faf | 4845 | # m.a.d net2net |
ce9abb66 AH |
4846 | ### |
4847 | ||
4848 | if ($cgiparams{'TYPE'} eq 'host') { | |
49abe7af | 4849 | print <<END; |
f4fbb935 | 4850 | </select></td></tr> |
425465ed | 4851 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td> |
f4fbb935 EK |
4852 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4853 | <tr><td> </td> | |
6e13d0a5 MT |
4854 | <td class='base'>$Lang::tr{'pkcs12 file password'}:</td> |
4855 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS1' value='$cgiparams{'CERT_PASS1'}' size='32' $cakeydisabled /></td></tr> | |
f4fbb935 | 4856 | <tr><td> </td><td class='base'>$Lang::tr{'pkcs12 file password'}:<br>($Lang::tr{'confirmation'})</td> |
6e13d0a5 | 4857 | <td class='base' nowrap='nowrap'><input type='password' name='CERT_PASS2' value='$cgiparams{'CERT_PASS2'}' size='32' $cakeydisabled /></td></tr> |
f4fbb935 EK |
4858 | <tr><td colspan='3'> </td></tr> |
4859 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4860 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
f4fbb935 | 4861 | </table> |
ce9abb66 AH |
4862 | END |
4863 | }else{ | |
49abe7af | 4864 | print <<END; |
f4fbb935 | 4865 | </select></td></tr> |
425465ed | 4866 | <td> </td><td class='base'>$Lang::tr{'valid till'} (days): <img src='/blob.gif' alt='*' /</td> |
f4fbb935 EK |
4867 | <td class='base' nowrap='nowrap'><input type='text' name='DAYS_VALID' value='$cgiparams{'DAYS_VALID'}' size='32' $cakeydisabled /></td></tr> |
4868 | <tr><td> </td><td> </td><td> </td></tr> | |
4869 | <tr><td> </td><td> </td><td> </td></tr> | |
4870 | <tr><td colspan='3'><hr /></td></tr> | |
e3edceeb | 4871 | <tr><td class='base' colspan='3' align='left'><img src='/blob.gif' alt='*' /> $Lang::tr{'required field'}</td></tr> |
ce9abb66 | 4872 | </table> |
66c36198 | 4873 | |
c6c9630e | 4874 | END |
ce9abb66 AH |
4875 | } |
4876 | ||
4877 | ### | |
7c1d9faf | 4878 | # m.a.d net2net |
ce9abb66 | 4879 | ### |
c6c9630e MT |
4880 | ; |
4881 | &Header::closebox(); | |
66c36198 | 4882 | |
8c877a82 | 4883 | } |
e81be1e1 | 4884 | |
66c36198 | 4885 | #A.Marx CCD new client |
e81be1e1 | 4886 | if ($cgiparams{'TYPE'} eq 'host') { |
8c877a82 AM |
4887 | print"<br><br>"; |
4888 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'ccd client options'}:"); | |
4889 | ||
66c36198 | 4890 | |
8c877a82 AM |
4891 | print <<END; |
4892 | <table border='0' width='100%'> | |
e1e10515 | 4893 | <tr><td width='20%'>$Lang::tr{'enable otp'}:</td><td colspan='3'><input type='checkbox' name='OTP_STATE' $checked{'OTP_STATE'}{'on'} /></td></tr> |
8c877a82 AM |
4894 | <tr><td width='20%'>Redirect Gateway:</td><td colspan='3'><input type='checkbox' name='RG' $checked{'RG'}{'on'} /></td></tr> |
4895 | <tr><td colspan='4'><b><br>$Lang::tr{'ccd routes'}</b></td></tr> | |
4896 | <tr><td colspan='4'> </td></tr> | |
4897 | <tr><td valign='top'>$Lang::tr{'ccd iroute'}</td><td align='left' width='30%'><textarea name='IR' cols='26' rows='6' wrap='off'> | |
4898 | END | |
66c36198 | 4899 | |
8c877a82 AM |
4900 | if ($cgiparams{'IR'} ne ''){ |
4901 | print $cgiparams{'IR'}; | |
4902 | }else{ | |
4903 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute", \%ccdroutehash); | |
4904 | foreach my $key (keys %ccdroutehash) { | |
4905 | if( $cgiparams{'NAME'} eq $ccdroutehash{$key}[0]){ | |
4906 | foreach my $i (1 .. $#{$ccdroutehash{$key}}) { | |
4907 | if ($ccdroutehash{$key}[$i] ne ''){ | |
4908 | print $ccdroutehash{$key}[$i]."\n"; | |
4909 | } | |
4910 | $cgiparams{'IR'} .= $ccdroutehash{$key}[$i]; | |
4911 | } | |
4912 | } | |
4913 | } | |
c6c9630e | 4914 | } |
66c36198 | 4915 | |
8c877a82 AM |
4916 | print <<END; |
4917 | </textarea></td><td valign='top' colspan='2'>$Lang::tr{'ccd iroutehint'}</td></tr> | |
4918 | <tr><td colspan='4'><br></td></tr> | |
4919 | <tr><td valign='top' rowspan='3'>$Lang::tr{'ccd iroute2'}</td><td align='left' valign='top' rowspan='3'><select name='IFROUTE' style="width: 205px"; size='6' multiple> | |
4920 | END | |
66c36198 | 4921 | |
52d08bcb AM |
4922 | my $set=0; |
4923 | my $selorange=0; | |
4924 | my $selblue=0; | |
4925 | my $selgreen=0; | |
4926 | my $helpblue=0; | |
4927 | my $helporange=0; | |
4928 | my $other=0; | |
df9b48b7 | 4929 | my $none=0; |
52d08bcb | 4930 | my @temp=(); |
66c36198 | 4931 | |
8c877a82 | 4932 | our @current = (); |
52d08bcb AM |
4933 | open(FILE, "${General::swroot}/main/routing") ; |
4934 | @current = <FILE>; | |
4935 | close (FILE); | |
66c36198 | 4936 | &General::readhasharray ("${General::swroot}/ovpn/ccdroute2", \%ccdroute2hash); |
df9b48b7 AM |
4937 | #check for "none" |
4938 | foreach my $key (keys %ccdroute2hash) { | |
4939 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4940 | if ($ccdroute2hash{$key}[1] eq ''){ | |
4941 | $none=1; | |
4942 | last; | |
4943 | } | |
4944 | } | |
4945 | } | |
4946 | if ($none ne '1'){ | |
4947 | print"<option>$Lang::tr{'ccd none'}</option>"; | |
4948 | }else{ | |
4949 | print"<option selected>$Lang::tr{'ccd none'}</option>"; | |
4950 | } | |
52d08bcb AM |
4951 | #check if static routes are defined for client |
4952 | foreach my $line (@current) { | |
66c36198 | 4953 | chomp($line); |
52d08bcb AM |
4954 | $line=~s/\s*$//g; # remove newline |
4955 | @temp=split(/\,/,$line); | |
4956 | $temp[1] = '' unless defined $temp[1]; # not always populated | |
4957 | my ($a,$b) = split(/\//,$temp[1]); | |
4958 | $temp[1] = $a."/".&General::iporsubtocidr($b); | |
4959 | foreach my $key (keys %ccdroute2hash) { | |
4960 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
4961 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4962 | if($ccdroute2hash{$key}[$i] eq $a."/".&General::iporsubtodec($b)){ | |
4963 | $set=1; | |
8c877a82 AM |
4964 | } |
4965 | } | |
8c877a82 | 4966 | } |
52d08bcb AM |
4967 | } |
4968 | if ($set == '1' && $#temp != -1){ print"<option selected>$temp[1]</option>";$set=0;}elsif($set == '0' && $#temp != -1){print"<option>$temp[1]</option>";} | |
66c36198 | 4969 | } |
3a445974 MT |
4970 | |
4971 | my %vpnconfig = (); | |
4972 | &General::readhasharray("${General::swroot}/vpn/config", \%vpnconfig); | |
4973 | foreach my $vpn (keys %vpnconfig) { | |
4974 | # Skip all disabled VPN connections | |
4975 | my $enabled = $vpnconfig{$vpn}[0]; | |
4976 | next unless ($enabled eq "on"); | |
4977 | ||
4978 | my $name = $vpnconfig{$vpn}[1]; | |
4979 | ||
4980 | # Remote subnets | |
4981 | my @networks = split(/\|/, $vpnconfig{$vpn}[11]); | |
4982 | foreach my $network (@networks) { | |
4983 | my $selected = ""; | |
4984 | ||
4985 | foreach my $key (keys %ccdroute2hash) { | |
4986 | if ($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}) { | |
4987 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
4988 | if ($ccdroute2hash{$key}[$i] eq $network) { | |
4989 | $selected = "selected"; | |
4990 | } | |
4991 | } | |
4992 | } | |
4993 | } | |
4994 | ||
4995 | print "<option value=\"$network\" $selected>$name ($network)</option>\n"; | |
4996 | } | |
4997 | } | |
4998 | ||
52d08bcb AM |
4999 | #check if green,blue,orange are defined for client |
5000 | foreach my $key (keys %ccdroute2hash) { | |
5001 | if($ccdroute2hash{$key}[0] eq $cgiparams{'NAME'}){ | |
5002 | $other=1; | |
5003 | foreach my $i (1 .. $#{$ccdroute2hash{$key}}) { | |
5004 | if ($ccdroute2hash{$key}[$i] eq $netsettings{'GREEN_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'GREEN_NETMASK'})){ | |
5005 | $selgreen=1; | |
5006 | } | |
5007 | if (&haveBlueNet()){ | |
5008 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'BLUE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'BLUE_NETMASK'})) { | |
5009 | $selblue=1; | |
5010 | } | |
5011 | } | |
5012 | if (&haveOrangeNet()){ | |
5013 | if( $ccdroute2hash{$key}[$i] eq $netsettings{'ORANGE_NETADDRESS'}."/".&General::iporsubtodec($netsettings{'ORANGE_NETMASK'}) ) { | |
5014 | $selorange=1; | |
5015 | } | |
5016 | } | |
5017 | } | |
5018 | } | |
5019 | } | |
5020 | if (&haveBlueNet() && $selblue == '1'){ print"<option selected>$Lang::tr{'blue'}</option>";$selblue=0;}elsif(&haveBlueNet() && $selblue == '0'){print"<option>$Lang::tr{'blue'}</option>";} | |
66c36198 | 5021 | if (&haveOrangeNet() && $selorange == '1'){ print"<option selected>$Lang::tr{'orange'}</option>";$selorange=0;}elsif(&haveOrangeNet() && $selorange == '0'){print"<option>$Lang::tr{'orange'}</option>";} |
52d08bcb | 5022 | if ($selgreen == '1' || $other == '0'){ print"<option selected>$Lang::tr{'green'}</option>";$set=0;}else{print"<option>$Lang::tr{'green'}</option>";}; |
66c36198 | 5023 | |
49abe7af | 5024 | print<<END; |
8c877a82 AM |
5025 | </select></td><td valign='top'>DNS1:</td><td valign='top'><input type='TEXT' name='CCD_DNS1' value='$cgiparams{'CCD_DNS1'}' size='30' /></td></tr> |
5026 | <tr valign='top'><td>DNS2:</td><td><input type='TEXT' name='CCD_DNS2' value='$cgiparams{'CCD_DNS2'}' size='30' /></td></tr> | |
5027 | <tr valign='top'><td valign='top'>WINS:</td><td><input type='TEXT' name='CCD_WINS' value='$cgiparams{'CCD_WINS'}' size='30' /></td></tr></table><br><hr> | |
66c36198 | 5028 | |
8c877a82 AM |
5029 | END |
5030 | ; | |
5031 | &Header::closebox(); | |
e81be1e1 | 5032 | } |
c6c9630e MT |
5033 | print "<div align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5034 | if ($cgiparams{'KEY'}) { | |
5035 | # print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced'}' />"; | |
5036 | } | |
5037 | print "<input type='submit' name='ACTION' value='$Lang::tr{'cancel'}' /></div></form>"; | |
5038 | &Header::closebigbox(); | |
5039 | &Header::closepage(); | |
5040 | exit (0); | |
6e13d0a5 | 5041 | } |
c6c9630e | 5042 | VPNCONF_END: |
6e13d0a5 | 5043 | } |
c6c9630e MT |
5044 | |
5045 | # SETTINGS_ERROR: | |
6e13d0a5 MT |
5046 | ### |
5047 | ### Default status page | |
5048 | ### | |
c6c9630e MT |
5049 | %cgiparams = (); |
5050 | %cahash = (); | |
5051 | %confighash = (); | |
5052 | &General::readhash("${General::swroot}/ovpn/settings", \%cgiparams); | |
5053 | &General::readhasharray("${General::swroot}/ovpn/caconfig", \%cahash); | |
5054 | &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); | |
5055 | ||
2feacd98 SS |
5056 | open(FILE, "/var/run/ovpnserver.log"); |
5057 | my @status = <FILE>; | |
5058 | close(FILE); | |
c6c9630e MT |
5059 | |
5060 | if ($cgiparams{'VPN_IP'} eq '' && -e "${General::swroot}/red/active") { | |
8c877a82 AM |
5061 | if (open(IPADDR, "${General::swroot}/red/local-ipaddress")) { |
5062 | my $ipaddr = <IPADDR>; | |
5063 | close IPADDR; | |
5064 | chomp ($ipaddr); | |
5065 | $cgiparams{'VPN_IP'} = (gethostbyaddr(pack("C4", split(/\./, $ipaddr)), 2))[0]; | |
5066 | if ($cgiparams{'VPN_IP'} eq '') { | |
5067 | $cgiparams{'VPN_IP'} = $ipaddr; | |
5068 | } | |
5069 | } | |
c6c9630e | 5070 | } |
66c36198 | 5071 | |
6e13d0a5 | 5072 | #default setzen |
c6c9630e | 5073 | if ($cgiparams{'DCIPHER'} eq '') { |
4c962356 | 5074 | $cgiparams{'DCIPHER'} = 'AES-256-CBC'; |
c6c9630e | 5075 | } |
c6c9630e | 5076 | if ($cgiparams{'DDEST_PORT'} eq '') { |
4c962356 | 5077 | $cgiparams{'DDEST_PORT'} = '1194'; |
c6c9630e MT |
5078 | } |
5079 | if ($cgiparams{'DMTU'} eq '') { | |
4c962356 EK |
5080 | $cgiparams{'DMTU'} = '1400'; |
5081 | } | |
5082 | if ($cgiparams{'MSSFIX'} eq '') { | |
5083 | $cgiparams{'MSSFIX'} = 'off'; | |
5084 | } | |
5085 | if ($cgiparams{'DAUTH'} eq '') { | |
86308adb EK |
5086 | if (-z "${General::swroot}/ovpn/ovpnconfig") { |
5087 | $cgiparams{'DAUTH'} = 'SHA512'; | |
5088 | } | |
5089 | foreach my $key (keys %confighash) { | |
5090 | if ($confighash{$key}[3] ne 'host') { | |
5091 | $cgiparams{'DAUTH'} = 'SHA512'; | |
5092 | } else { | |
5093 | $cgiparams{'DAUTH'} = 'SHA1'; | |
5094 | } | |
5095 | } | |
5096 | } | |
0c4ffc69 EK |
5097 | if ($cgiparams{'TLSAUTH'} eq '') { |
5098 | $cgiparams{'TLSAUTH'} = 'off'; | |
5099 | } | |
c6c9630e | 5100 | if ($cgiparams{'DOVPN_SUBNET'} eq '') { |
4c962356 | 5101 | $cgiparams{'DOVPN_SUBNET'} = '10.' . int(rand(256)) . '.' . int(rand(256)) . '.0/255.255.255.0'; |
c6c9630e | 5102 | } |
4c962356 | 5103 | $checked{'ENABLED'}{'off'} = ''; |
c6c9630e MT |
5104 | $checked{'ENABLED'}{'on'} = ''; |
5105 | $checked{'ENABLED'}{$cgiparams{'ENABLED'}} = 'CHECKED'; | |
5106 | $checked{'ENABLED_BLUE'}{'off'} = ''; | |
5107 | $checked{'ENABLED_BLUE'}{'on'} = ''; | |
5108 | $checked{'ENABLED_BLUE'}{$cgiparams{'ENABLED_BLUE'}} = 'CHECKED'; | |
5109 | $checked{'ENABLED_ORANGE'}{'off'} = ''; | |
5110 | $checked{'ENABLED_ORANGE'}{'on'} = ''; | |
5111 | $checked{'ENABLED_ORANGE'}{$cgiparams{'ENABLED_ORANGE'}} = 'CHECKED'; | |
c6c9630e MT |
5112 | |
5113 | $selected{'DPROTOCOL'}{'udp'} = ''; | |
5114 | $selected{'DPROTOCOL'}{'tcp'} = ''; | |
5115 | $selected{'DPROTOCOL'}{$cgiparams{'DPROTOCOL'}} = 'SELECTED'; | |
4c962356 | 5116 | |
52f61e49 EKD |
5117 | $selected{'DCIPHER'}{'AES-256-GCM'} = ''; |
5118 | $selected{'DCIPHER'}{'AES-192-GCM'} = ''; | |
5119 | $selected{'DCIPHER'}{'AES-128-GCM'} = ''; | |
4c962356 EK |
5120 | $selected{'DCIPHER'}{'CAMELLIA-256-CBC'} = ''; |
5121 | $selected{'DCIPHER'}{'CAMELLIA-192-CBC'} = ''; | |
5122 | $selected{'DCIPHER'}{'CAMELLIA-128-CBC'} = ''; | |
5123 | $selected{'DCIPHER'}{'AES-256-CBC'} = ''; | |
5124 | $selected{'DCIPHER'}{'AES-192-CBC'} = ''; | |
5125 | $selected{'DCIPHER'}{'AES-128-CBC'} = ''; | |
c6c9630e MT |
5126 | $selected{'DCIPHER'}{'DES-EDE3-CBC'} = ''; |
5127 | $selected{'DCIPHER'}{'DESX-CBC'} = ''; | |
4c962356 EK |
5128 | $selected{'DCIPHER'}{'SEED-CBC'} = ''; |
5129 | $selected{'DCIPHER'}{'DES-EDE-CBC'} = ''; | |
5130 | $selected{'DCIPHER'}{'CAST5-CBC'} = ''; | |
5131 | $selected{'DCIPHER'}{'BF-CBC'} = ''; | |
4c962356 | 5132 | $selected{'DCIPHER'}{'DES-CBC'} = ''; |
c6c9630e | 5133 | $selected{'DCIPHER'}{$cgiparams{'DCIPHER'}} = 'SELECTED'; |
4c962356 EK |
5134 | |
5135 | $selected{'DAUTH'}{'whirlpool'} = ''; | |
5136 | $selected{'DAUTH'}{'SHA512'} = ''; | |
5137 | $selected{'DAUTH'}{'SHA384'} = ''; | |
5138 | $selected{'DAUTH'}{'SHA256'} = ''; | |
4c962356 EK |
5139 | $selected{'DAUTH'}{'SHA1'} = ''; |
5140 | $selected{'DAUTH'}{$cgiparams{'DAUTH'}} = 'SELECTED'; | |
5141 | ||
0c4ffc69 EK |
5142 | $checked{'TLSAUTH'}{'off'} = ''; |
5143 | $checked{'TLSAUTH'}{'on'} = ''; | |
5144 | $checked{'TLSAUTH'}{$cgiparams{'TLSAUTH'}} = 'CHECKED'; | |
5145 | ||
c6c9630e MT |
5146 | $checked{'DCOMPLZO'}{'off'} = ''; |
5147 | $checked{'DCOMPLZO'}{'on'} = ''; | |
5148 | $checked{'DCOMPLZO'}{$cgiparams{'DCOMPLZO'}} = 'CHECKED'; | |
4c962356 | 5149 | |
d96c89eb AH |
5150 | # m.a.d |
5151 | $checked{'MSSFIX'}{'off'} = ''; | |
5152 | $checked{'MSSFIX'}{'on'} = ''; | |
5153 | $checked{'MSSFIX'}{$cgiparams{'MSSFIX'}} = 'CHECKED'; | |
6e13d0a5 | 5154 | #new settings |
c6c9630e MT |
5155 | &Header::showhttpheaders(); |
5156 | &Header::openpage($Lang::tr{'status ovpn'}, 1, ''); | |
5157 | &Header::openbigbox('100%', 'LEFT', '', $errormessage); | |
6e13d0a5 | 5158 | |
c6c9630e | 5159 | if ($errormessage) { |
6e13d0a5 MT |
5160 | &Header::openbox('100%', 'LEFT', $Lang::tr{'error messages'}); |
5161 | print "<class name='base'>$errormessage\n"; | |
5162 | print " </class>\n"; | |
5163 | &Header::closebox(); | |
c6c9630e | 5164 | } |
6e13d0a5 | 5165 | |
400c8afd EK |
5166 | if ($cryptoerror) { |
5167 | &Header::openbox('100%', 'LEFT', $Lang::tr{'crypto error'}); | |
5168 | print "<class name='base'>$cryptoerror"; | |
5169 | print " </class>"; | |
5170 | &Header::closebox(); | |
5171 | } | |
5172 | ||
5173 | if ($cryptowarning) { | |
5174 | &Header::openbox('100%', 'LEFT', $Lang::tr{'crypto warning'}); | |
5175 | print "<class name='base'>$cryptowarning"; | |
5176 | print " </class>"; | |
5177 | &Header::closebox(); | |
5178 | } | |
5179 | ||
b2e75449 MT |
5180 | if ($warnmessage) { |
5181 | &Header::openbox('100%', 'LEFT', $Lang::tr{'warning messages'}); | |
5182 | print "$warnmessage<br>"; | |
5183 | print "$Lang::tr{'fwdfw warn1'}<br>"; | |
5184 | &Header::closebox(); | |
5185 | print"<center><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'ok'}' style='width: 5em;'></form>"; | |
5186 | &Header::closepage(); | |
5187 | exit 0; | |
5188 | } | |
4d81e0f3 | 5189 | |
c6c9630e MT |
5190 | 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>"; |
5191 | my $srunning = "no"; | |
5192 | my $activeonrun = ""; | |
5193 | if ( -e "/var/run/openvpn.pid"){ | |
6e13d0a5 MT |
5194 | $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>"; |
5195 | $srunning ="yes"; | |
5196 | $activeonrun = ""; | |
c6c9630e | 5197 | } else { |
6e13d0a5 | 5198 | $activeonrun = "disabled='disabled'"; |
66c36198 PM |
5199 | } |
5200 | &Header::openbox('100%', 'LEFT', $Lang::tr{'global settings'}); | |
4c962356 | 5201 | print <<END; |
631b67b7 | 5202 | <table width='100%' border='0'> |
c6c9630e MT |
5203 | <form method='post'> |
5204 | <td width='25%'> </td> | |
5205 | <td width='25%'> </td> | |
5206 | <td width='25%'> </td></tr> | |
5207 | <tr><td class='boldbase'>$Lang::tr{'ovpn server status'}</td> | |
5208 | <td align='left'>$sactive</td> | |
5209 | <tr><td class='boldbase'>$Lang::tr{'ovpn on red'}</td> | |
8c877a82 | 5210 | <td><input type='checkbox' name='ENABLED' $checked{'ENABLED'}{'on'} /></td> |
c6c9630e MT |
5211 | END |
5212 | ; | |
5213 | if (&haveBlueNet()) { | |
5214 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on blue'}</td>"; | |
5215 | print "<td><input type='checkbox' name='ENABLED_BLUE' $checked{'ENABLED_BLUE'}{'on'} /></td>"; | |
5216 | } | |
66c36198 | 5217 | if (&haveOrangeNet()) { |
c6c9630e MT |
5218 | print "<tr><td class='boldbase'>$Lang::tr{'ovpn on orange'}</td>"; |
5219 | print "<td><input type='checkbox' name='ENABLED_ORANGE' $checked{'ENABLED_ORANGE'}{'on'} /></td>"; | |
86308adb EK |
5220 | } |
5221 | ||
5222 | print <<END; | |
5223 | ||
5224 | <tr><td colspan='4'><br></td></tr> | |
5225 | <tr> | |
f99ed824 | 5226 | <td class='base'><b>$Lang::tr{'net config'}:</b></td> |
86308adb EK |
5227 | </tr> |
5228 | <tr><td colspan='1'><br></td></tr> | |
5229 | ||
4e17adad CS |
5230 | <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> |
5231 | <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 |
5232 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'protocol'}</td> |
5233 | <td><select name='DPROTOCOL'><option value='udp' $selected{'DPROTOCOL'}{'udp'}>UDP</option> | |
66c36198 | 5234 | <option value='tcp' $selected{'DPROTOCOL'}{'tcp'}>TCP</option></select></td> |
c6c9630e MT |
5235 | <td class='boldbase'>$Lang::tr{'destination port'}:</td> |
5236 | <td><input type='TEXT' name='DDEST_PORT' value='$cgiparams{'DDEST_PORT'}' size='5' /></td></tr> | |
5237 | <tr><td class='boldbase' nowrap='nowrap'>$Lang::tr{'MTU'} </td> | |
bc2b3e94 | 5238 | <td> <input type='TEXT' name='DMTU' VALUE='$cgiparams{'DMTU'}' size='5' /></td> |
86308adb EK |
5239 | </tr> |
5240 | ||
5241 | <tr><td colspan='4'><br></td></tr> | |
5242 | <tr> | |
f99ed824 | 5243 | <td class='base'><b>$Lang::tr{'ovpn crypt options'}:</b></td> |
86308adb EK |
5244 | </tr> |
5245 | <tr><td colspan='1'><br></td></tr> | |
5246 | ||
5247 | <tr> | |
5248 | <td class='base'>$Lang::tr{'ovpn ha'}</td> | |
5249 | <td><select name='DAUTH'> | |
5250 | <option value='whirlpool' $selected{'DAUTH'}{'whirlpool'}>Whirlpool (512 $Lang::tr{'bit'})</option> | |
5251 | <option value='SHA512' $selected{'DAUTH'}{'SHA512'}>SHA2 (512 $Lang::tr{'bit'})</option> | |
5252 | <option value='SHA384' $selected{'DAUTH'}{'SHA384'}>SHA2 (384 $Lang::tr{'bit'})</option> | |
5253 | <option value='SHA256' $selected{'DAUTH'}{'SHA256'}>SHA2 (256 $Lang::tr{'bit'})</option> | |
5254 | <option value='SHA1' $selected{'DAUTH'}{'SHA1'}>SHA1 (160 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5255 | </select> | |
5256 | </td> | |
f527e53f | 5257 | |
4c962356 EK |
5258 | <td class='boldbase' nowrap='nowrap'>$Lang::tr{'cipher'}</td> |
5259 | <td><select name='DCIPHER'> | |
52f61e49 EKD |
5260 | <option value='AES-256-GCM' $selected{'DCIPHER'}{'AES-256-GCM'}>AES-GCM (256 $Lang::tr{'bit'})</option> |
5261 | <option value='AES-192-GCM' $selected{'DCIPHER'}{'AES-192-GCM'}>AES-GCM (192 $Lang::tr{'bit'})</option> | |
5262 | <option value='AES-128-GCM' $selected{'DCIPHER'}{'AES-128-GCM'}>AES-GCM (128 $Lang::tr{'bit'})</option> | |
4c962356 | 5263 | <option value='CAMELLIA-256-CBC' $selected{'DCIPHER'}{'CAMELLIA-256-CBC'}>CAMELLIA-CBC (256 $Lang::tr{'bit'})</option> |
f527e53f | 5264 | <option value='CAMELLIA-192-CBC' $selected{'DCIPHER'}{'CAMELLIA-192-CBC'}>CAMELLIA-CBC (192 $Lang::tr{'bit'})</option> |
4c962356 EK |
5265 | <option value='CAMELLIA-128-CBC' $selected{'DCIPHER'}{'CAMELLIA-128-CBC'}>CAMELLIA-CBC (128 $Lang::tr{'bit'})</option> |
5266 | <option value='AES-256-CBC' $selected{'DCIPHER'}{'AES-256-CBC'}>AES-CBC (256 $Lang::tr{'bit'})</option> | |
5267 | <option value='AES-192-CBC' $selected{'DCIPHER'}{'AES-192-CBC'}>AES-CBC (192 $Lang::tr{'bit'})</option> | |
5268 | <option value='AES-128-CBC' $selected{'DCIPHER'}{'AES-128-CBC'}>AES-CBC (128 $Lang::tr{'bit'})</option> | |
4c962356 | 5269 | <option value='SEED-CBC' $selected{'DCIPHER'}{'SEED-CBC'}>SEED-CBC (128 $Lang::tr{'bit'})</option> |
ea6dd5b0 EK |
5270 | <option value='DES-EDE3-CBC' $selected{'DCIPHER'}{'DES-EDE3-CBC'}>DES-EDE3-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> |
5271 | <option value='DESX-CBC' $selected{'DCIPHER'}{'DESX-CBC'}>DESX-CBC (192 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5272 | <option value='DES-EDE-CBC' $selected{'DCIPHER'}{'DES-EDE-CBC'}>DES-EDE-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5273 | <option value='BF-CBC' $selected{'DCIPHER'}{'BF-CBC'}>BF-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
5274 | <option value='CAST5-CBC' $selected{'DCIPHER'}{'CAST5-CBC'}>CAST5-CBC (128 $Lang::tr{'bit'}, $Lang::tr{'vpn weak'})</option> | |
4c962356 EK |
5275 | </select> |
5276 | </td> | |
4c962356 | 5277 | </tr> |
0c4ffc69 EK |
5278 | |
5279 | <tr><td colspan='4'><br></td></tr> | |
5280 | <tr> | |
5281 | <td class='base'>$Lang::tr{'ovpn tls auth'}</td> | |
5282 | <td><input type='checkbox' name='TLSAUTH' $checked{'TLSAUTH'}{'on'} /></td> | |
5283 | </tr> | |
5284 | ||
f7edf97a | 5285 | <tr><td colspan='4'><br><br></td></tr> |
c6c9630e | 5286 | END |
66c36198 PM |
5287 | ; |
5288 | ||
c6c9630e | 5289 | if ( $srunning eq "yes" ) { |
8c877a82 AM |
5290 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' disabled='disabled' />"; |
5291 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
66c36198 | 5292 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; |
8c877a82 | 5293 | print "<input type='submit' name='ACTION' value='$Lang::tr{'stop ovpn server'}' /></td></tr>"; |
c6c9630e | 5294 | } else{ |
8c877a82 AM |
5295 | print "<tr><td align='right' colspan='4'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' />"; |
5296 | print "<input type='submit' name='ACTION' value='$Lang::tr{'ccd net'}' />"; | |
5297 | print "<input type='submit' name='ACTION' value='$Lang::tr{'advanced server'}' />"; | |
c6c9630e | 5298 | if (( -e "${General::swroot}/ovpn/ca/cacert.pem" && |
35494eac | 5299 | -e "$dhparameter" && |
c6c9630e MT |
5300 | -e "${General::swroot}/ovpn/certs/servercert.pem" && |
5301 | -e "${General::swroot}/ovpn/certs/serverkey.pem") && | |
66c36198 | 5302 | (( $cgiparams{'ENABLED'} eq 'on') || |
c6c9630e MT |
5303 | ( $cgiparams{'ENABLED_BLUE'} eq 'on') || |
5304 | ( $cgiparams{'ENABLED_ORANGE'} eq 'on'))){ | |
8c877a82 | 5305 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' /></td></tr>"; |
c6c9630e | 5306 | } else { |
66c36198 PM |
5307 | print "<input type='submit' name='ACTION' value='$Lang::tr{'start ovpn server'}' disabled='disabled' /></td></tr>"; |
5308 | } | |
c6c9630e MT |
5309 | } |
5310 | print "</form></table>"; | |
5311 | &Header::closebox(); | |
6e13d0a5 | 5312 | |
c6c9630e | 5313 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem" ) { |
ce9abb66 | 5314 | ### |
7c1d9faf | 5315 | # m.a.d net2net |
54fd0535 | 5316 | #<td width='25%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b><br /><img src='/images/null.gif' width='125' height='1' border='0' alt='L2089' /></td> |
ce9abb66 AH |
5317 | ### |
5318 | ||
4c962356 | 5319 | &Header::openbox('100%', 'LEFT', $Lang::tr{'connection status and controlc' }); |
c6c9630e | 5320 | ; |
99bfa85c AM |
5321 | my $id = 0; |
5322 | my $gif; | |
f7edf97a | 5323 | my $col1=""; |
5b942f7f | 5324 | my $lastnet; |
c8b51e28 | 5325 | foreach my $key (sort { ncmp ($confighash{$a}[32],$confighash{$b}[32]) } sort { ncmp ($confighash{$a}[1],$confighash{$b}[1]) } keys %confighash) { |
5b942f7f AM |
5326 | if ($confighash{$key}[32] eq "" && $confighash{$key}[3] eq 'net' ){$confighash{$key}[32]=$Lang::tr{'fwhost OpenVPN N-2-N'};} |
5327 | if ($confighash{$key}[32] eq "dynamic"){$confighash{$key}[32]=$Lang::tr{'ccd dynrange'};} | |
5328 | if($id == 0){ | |
5329 | print"<b>$confighash{$key}[32]</b>"; | |
5330 | print <<END; | |
5331 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5332 | <tr> | |
5333 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5334 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5335 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5336 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
e1e10515 | 5337 | <th width='5%' class='boldbase' colspan='8' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5338 | </tr> |
5339 | END | |
5340 | } | |
5341 | if ($id > 0 && $lastnet ne $confighash{$key}[32]){ | |
5342 | print "</table><br>"; | |
5343 | print"<b>$confighash{$key}[32]</b>"; | |
5344 | print <<END; | |
5345 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5346 | <tr> | |
5347 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5348 | <th width='15%' class='boldbase' align='center'><b>$Lang::tr{'type'}</b></th> | |
5349 | <th width='20%' class='boldbase' align='center'><b>$Lang::tr{'remark'}</b></th> | |
5350 | <th width='10%' class='boldbase' align='center'><b>$Lang::tr{'status'}</b></th> | |
e1e10515 | 5351 | <th width='5%' class='boldbase' colspan='8' align='center'><b>$Lang::tr{'action'}</b></th> |
5b942f7f AM |
5352 | </tr> |
5353 | END | |
5354 | } | |
eff2dbf8 | 5355 | if ($confighash{$key}[0] eq 'on') { $gif = 'on.gif'; } else { $gif = 'off.gif'; } |
2feacd98 | 5356 | |
498134e5 MT |
5357 | # Fetch information about the certificate |
5358 | my @cavalid = &General::system_output("/usr/bin/openssl", "x509", "-text", | |
5359 | "-in", "${General::swroot}/ovpn/certs/$confighash{$key}[1]cert.pem"); | |
5360 | ||
5361 | my $expiryDate = 0; | |
5362 | ||
5363 | # Parse the certificate information | |
2feacd98 SS |
5364 | foreach my $line (@cavalid) { |
5365 | if ($line =~ /Not After : (.*)[\n]/) { | |
498134e5 | 5366 | $expiryDate = &Date::Parse::str2time($1); |
2feacd98 SS |
5367 | last; |
5368 | } | |
5369 | } | |
5370 | ||
498134e5 MT |
5371 | # Calculate the remaining time |
5372 | my $remainingTime = $expiryDate - time(); | |
5373 | ||
5374 | # Create some simple booleans to check the status | |
5375 | my $hasExpired = ($remainingTime <= 0); | |
5376 | my $expiresSoon = ($remainingTime <= 30 * 24 * 3600); | |
5377 | ||
5378 | print "<tr>"; | |
5379 | ||
5380 | if ($hasExpired || $expiresSoon) { | |
5381 | $col="bgcolor='$color{'color14'}'"; | |
5382 | } elsif ($id % 2) { | |
5383 | $col="bgcolor='$color{'color20'}'"; | |
5384 | } else { | |
5385 | $col="bgcolor='$color{'color22'}'"; | |
5386 | } | |
5387 | print "<td align='center' nowrap='nowrap' $col>$confighash{$key}[1]"; | |
5388 | if ($hasExpired) { | |
5389 | print " ($Lang::tr{'openvpn cert has expired'})"; | |
5390 | } elsif ($expiresSoon) { | |
5391 | print " ($Lang::tr{'openvpn cert expires soon'})"; | |
5392 | } | |
5393 | print "</td>"; | |
5394 | print "<td align='center' nowrap='nowrap' $col>" . $Lang::tr{"$confighash{$key}[3]"} . " (" . $Lang::tr{"$confighash{$key}[4]"} . ")</td>"; | |
99bfa85c | 5395 | print "<td align='center' $col>$confighash{$key}[25]</td>"; |
f7edf97a AM |
5396 | $col1="bgcolor='${Header::colourred}'"; |
5397 | my $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
ce9abb66 | 5398 | |
c6c9630e | 5399 | if ($confighash{$key}[0] eq 'off') { |
f7edf97a AM |
5400 | $col1="bgcolor='${Header::colourblue}'"; |
5401 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsclosed'}</font></b>"; | |
c6c9630e | 5402 | } else { |
ce9abb66 AH |
5403 | |
5404 | ### | |
7c1d9faf | 5405 | # m.a.d net2net |
f7edf97a AM |
5406 | ### |
5407 | ||
b278daf3 | 5408 | if ($confighash{$key}[3] eq 'net') { |
54fd0535 MT |
5409 | |
5410 | if (-e "/var/run/$confighash{$key}[1]n2n.pid") { | |
5411 | my @output = ""; | |
5412 | my @tustate = ""; | |
5413 | my $tport = $confighash{$key}[22]; | |
66c36198 | 5414 | my $tnet = new Net::Telnet ( Timeout=>5, Errmode=>'return', Port=>$tport); |
54fd0535 MT |
5415 | if ($tport ne '') { |
5416 | $tnet->open('127.0.0.1'); | |
5417 | @output = $tnet->cmd(String => 'state', Prompt => '/(END.*\n|ERROR:.*\n)/'); | |
5418 | @tustate = split(/\,/, $output[1]); | |
5419 | ### | |
5420 | #CONNECTING -- OpenVPN's initial state. | |
5421 | #WAIT -- (Client only) Waiting for initial response from server. | |
5422 | #AUTH -- (Client only) Authenticating with server. | |
5423 | #GET_CONFIG -- (Client only) Downloading configuration options from server. | |
5424 | #ASSIGN_IP -- Assigning IP address to virtual network interface. | |
5425 | #ADD_ROUTES -- Adding routes to system. | |
5426 | #CONNECTED -- Initialization Sequence Completed. | |
5427 | #RECONNECTING -- A restart has occurred. | |
5428 | #EXITING -- A graceful exit is in progress. | |
5429 | #### | |
5430 | ||
ed4b4c19 | 5431 | if (($tustate[1] eq 'CONNECTED') || ($tustate[1] eq 'WAIT')) { |
f7edf97a AM |
5432 | $col1="bgcolor='${Header::colourgreen}'"; |
5433 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5434 | }else { | |
5435 | $col1="bgcolor='${Header::colourred}'"; | |
5436 | $active = "<b><font color='#FFFFFF'>$tustate[1]</font></b>"; | |
5437 | } | |
54fd0535 | 5438 | } |
54fd0535 | 5439 | } |
f7edf97a AM |
5440 | }else { |
5441 | ||
5442 | my $cn; | |
5443 | my @match = (); | |
5444 | foreach my $line (@status) { | |
5445 | chomp($line); | |
5446 | if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { | |
5447 | @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); | |
5448 | if ($match[1] ne "Common Name") { | |
5449 | $cn = $match[1]; | |
5450 | } | |
5451 | $cn =~ s/[_]/ /g; | |
5452 | if ($cn eq "$confighash{$key}[2]") { | |
5453 | $col1="bgcolor='${Header::colourgreen}'"; | |
5454 | $active = "<b><font color='#FFFFFF'>$Lang::tr{'capsopen'}</font></b>"; | |
5455 | } | |
5456 | } | |
5457 | } | |
c6c9630e | 5458 | } |
7c1d9faf | 5459 | } |
ce9abb66 AH |
5460 | |
5461 | ||
4c962356 | 5462 | print <<END; |
f7edf97a | 5463 | <td align='center' $col1>$active</td> |
66c36198 | 5464 | |
99bfa85c | 5465 | <form method='post' name='frm${key}a'><td align='center' $col> |
96096995 AM |
5466 | <input type='image' name='$Lang::tr{'dl client arch'}' src='/images/openvpn.png' alt='$Lang::tr{'dl client arch'}' title='$Lang::tr{'dl client arch'}' border='0' /> |
5467 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5468 | <input type='hidden' name='KEY' value='$key' /> | |
c6c9630e MT |
5469 | </td></form> |
5470 | END | |
5471 | ; | |
71af643c MT |
5472 | |
5473 | if ($confighash{$key}[41] eq "no-pass") { | |
5474 | print <<END; | |
5475 | <form method='post' name='frm${key}g'><td align='center' $col> | |
5476 | <input type='image' name='$Lang::tr{'dl client arch insecure'}' src='/images/openvpn.png' | |
5477 | alt='$Lang::tr{'dl client arch insecure'}' title='$Lang::tr{'dl client arch insecure'}' border='0' /> | |
5478 | <input type='hidden' name='ACTION' value='$Lang::tr{'dl client arch'}' /> | |
5479 | <input type='hidden' name='MODE' value='insecure' /> | |
5480 | <input type='hidden' name='KEY' value='$key' /> | |
5481 | </td></form> | |
5482 | END | |
5483 | } else { | |
5484 | print "<td $col> </td>"; | |
5485 | } | |
5486 | ||
c6c9630e | 5487 | if ($confighash{$key}[4] eq 'cert') { |
4c962356 | 5488 | print <<END; |
99bfa85c | 5489 | <form method='post' name='frm${key}b'><td align='center' $col> |
c6c9630e MT |
5490 | <input type='image' name='$Lang::tr{'show certificate'}' src='/images/info.gif' alt='$Lang::tr{'show certificate'}' title='$Lang::tr{'show certificate'}' border='0' /> |
5491 | <input type='hidden' name='ACTION' value='$Lang::tr{'show certificate'}' /> | |
5492 | <input type='hidden' name='KEY' value='$key' /> | |
5493 | </td></form> | |
5494 | END | |
5495 | ; } else { | |
5496 | print "<td> </td>"; | |
5497 | } | |
e1e10515 TE |
5498 | |
5499 | if ($confighash{$key}[43] eq 'on') { | |
5500 | print <<END; | |
5501 | <form method='post' name='frm${key}o'><td align='center' $col> | |
5502 | <input type='image' name='$Lang::tr{'show otp qrcode'}' src='/images/qr-code.png' alt='$Lang::tr{'show otp qrcode'}' title='$Lang::tr{'show otp qrcode'}' border='0' /> | |
5503 | <input type='hidden' name='ACTION' value='$Lang::tr{'show otp qrcode'}' /> | |
5504 | <input type='hidden' name='KEY' value='$key' /> | |
5505 | </td></form> | |
5506 | END | |
5507 | ; } else { | |
5508 | print "<td $col> </td>"; | |
5509 | } | |
5510 | ||
66c36198 | 5511 | if ($confighash{$key}[4] eq 'cert' && -f "${General::swroot}/ovpn/certs/$confighash{$key}[1].p12") { |
4c962356 | 5512 | print <<END; |
99bfa85c | 5513 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5514 | <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 |
5515 | <input type='hidden' name='ACTION' value='$Lang::tr{'download pkcs12 file'}' /> |
5516 | <input type='hidden' name='KEY' value='$key' /> | |
5517 | </td></form> | |
5518 | END | |
5519 | ; } elsif ($confighash{$key}[4] eq 'cert') { | |
4c962356 | 5520 | print <<END; |
99bfa85c | 5521 | <form method='post' name='frm${key}c'><td align='center' $col> |
438dd0cc | 5522 | <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 |
5523 | <input type='hidden' name='ACTION' value='$Lang::tr{'download certificate'}' /> |
5524 | <input type='hidden' name='KEY' value='$key' /> | |
5525 | </td></form> | |
5526 | END | |
5527 | ; } else { | |
5528 | print "<td> </td>"; | |
5529 | } | |
5530 | print <<END | |
99bfa85c | 5531 | <form method='post' name='frm${key}d'><td align='center' $col> |
c6c9630e MT |
5532 | <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' /> |
5533 | <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' /> | |
5534 | <input type='hidden' name='KEY' value='$key' /> | |
5535 | </td></form> | |
5536 | ||
99bfa85c | 5537 | <form method='post' name='frm${key}e'><td align='center' $col> |
c6c9630e MT |
5538 | <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' /> |
5539 | <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'/> | |
5540 | <input type='hidden' name='KEY' value='$key' /> | |
5541 | </td></form> | |
99bfa85c | 5542 | <form method='post' name='frm${key}f'><td align='center' $col> |
c6c9630e MT |
5543 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' /> |
5544 | <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' /> | |
5545 | <input type='hidden' name='KEY' value='$key' /> | |
5546 | </td></form> | |
5547 | </tr> | |
5548 | END | |
5549 | ; | |
5550 | $id++; | |
5b942f7f | 5551 | $lastnet = $confighash{$key}[32]; |
c6c9630e | 5552 | } |
5b942f7f | 5553 | print"</table>"; |
c6c9630e MT |
5554 | ; |
5555 | ||
5556 | # If the config file contains entries, print Key to action icons | |
5557 | if ( $id ) { | |
4c962356 | 5558 | print <<END; |
8c877a82 | 5559 | <table border='0'> |
c6c9630e | 5560 | <tr> |
4c962356 EK |
5561 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> |
5562 | <td> <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td> | |
5563 | <td class='base'>$Lang::tr{'click to disable'}</td> | |
5564 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5565 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5566 | <td> <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td> | |
5567 | <td class='base'>$Lang::tr{'edit'}</td> | |
5568 | <td> <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td> | |
5569 | <td class='base'>$Lang::tr{'remove'}</td> | |
c6c9630e MT |
5570 | </tr> |
5571 | <tr> | |
4c962356 EK |
5572 | <td> </td> |
5573 | <td> <img src='/images/off.gif' alt='?OFF' /></td> | |
5574 | <td class='base'>$Lang::tr{'click to enable'}</td> | |
5575 | <td> <img src='/images/media-floppy.png' alt='?FLOPPY' /></td> | |
5576 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5577 | <td> <img src='/images/openvpn.png' alt='?RELOAD'/></td> | |
5578 | <td class='base'>$Lang::tr{'dl client arch'}</td> | |
e1e10515 TE |
5579 | <td> <img src='/images/qr-code.png' alt='$Lang::tr{'show otp qrcode'}'/></td> |
5580 | <td class='base'>$Lang::tr{'show otp qrcode'}</td> | |
4c962356 | 5581 | </tr> |
f7edf97a | 5582 | </table><br> |
c6c9630e MT |
5583 | END |
5584 | ; | |
5585 | } | |
5586 | ||
4c962356 | 5587 | print <<END; |
c6c9630e MT |
5588 | <table width='100%'> |
5589 | <form method='post'> | |
4c962356 EK |
5590 | <tr><td align='right'> |
5591 | <input type='submit' name='ACTION' value='$Lang::tr{'add'}' /> | |
5592 | <input type='submit' name='ACTION' value='$Lang::tr{'ovpn con stat'}' $activeonrun /></td> | |
5593 | </tr> | |
c6c9630e MT |
5594 | </form> |
5595 | </table> | |
5596 | END | |
4c962356 EK |
5597 | ; |
5598 | &Header::closebox(); | |
5599 | } | |
fd5ccb2d EK |
5600 | |
5601 | # CA/key listing | |
4c962356 EK |
5602 | &Header::openbox('100%', 'LEFT', "$Lang::tr{'certificate authorities'}"); |
5603 | print <<END; | |
5604 | <table width='100%' cellspacing='1' cellpadding='0' class='tbl'> | |
5605 | <tr> | |
5606 | <th width='25%' class='boldbase' align='center'><b>$Lang::tr{'name'}</b></th> | |
5607 | <th width='65%' class='boldbase' align='center'><b>$Lang::tr{'subject'}</b></th> | |
5608 | <th width='10%' class='boldbase' colspan='3' align='center'><b>$Lang::tr{'action'}</b></th> | |
5609 | </tr> | |
5610 | END | |
5611 | ; | |
5612 | my $col1="bgcolor='$color{'color22'}'"; | |
f7fb5bc5 | 5613 | my $col2="bgcolor='$color{'color20'}'"; |
c8f50356 | 5614 | # DH parameter line |
f7fb5bc5 | 5615 | my $col3="bgcolor='$color{'color22'}'"; |
fd5ccb2d EK |
5616 | # ta.key line |
5617 | my $col4="bgcolor='$color{'color20'}'"; | |
f7fb5bc5 | 5618 | |
4c962356 | 5619 | if (-f "${General::swroot}/ovpn/ca/cacert.pem") { |
2feacd98 SS |
5620 | my @casubject = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/ca/cacert.pem"); |
5621 | my $casubject; | |
5622 | ||
5623 | foreach my $line (@casubject) { | |
5624 | if ($line =~ /Subject: (.*)[\n]/) { | |
5625 | $casubject = $1; | |
5626 | $casubject =~ s+/Email+, E+; | |
5627 | $casubject =~ s/ ST=/ S=/; | |
5628 | ||
5629 | last; | |
5630 | } | |
5631 | } | |
5632 | ||
4c962356 EK |
5633 | print <<END; |
5634 | <tr> | |
5635 | <td class='base' $col1>$Lang::tr{'root certificate'}</td> | |
5636 | <td class='base' $col1>$casubject</td> | |
c8f50356 | 5637 | <form method='post' name='frmrootcrta'><td width='3%' align='center' $col1> |
4c962356 EK |
5638 | <input type='hidden' name='ACTION' value='$Lang::tr{'show root certificate'}' /> |
5639 | <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' /> | |
c8f50356 EK |
5640 | </form> |
5641 | <form method='post' name='frmrootcrtb'><td width='3%' align='center' $col1> | |
4c962356 EK |
5642 | <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' /> |
5643 | <input type='hidden' name='ACTION' value='$Lang::tr{'download root certificate'}' /> | |
c8f50356 EK |
5644 | </form> |
5645 | <td width='4%' $col1> </td> | |
5646 | </tr> | |
4c962356 EK |
5647 | END |
5648 | ; | |
5649 | } else { | |
5650 | # display rootcert generation buttons | |
5651 | print <<END; | |
5652 | <tr> | |
5653 | <td class='base' $col1>$Lang::tr{'root certificate'}:</td> | |
5654 | <td class='base' $col1>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5655 | <td colspan='3' $col1> </td> |
5656 | </tr> | |
4c962356 EK |
5657 | END |
5658 | ; | |
5659 | } | |
5660 | ||
5661 | if (-f "${General::swroot}/ovpn/certs/servercert.pem") { | |
2feacd98 SS |
5662 | my @hostsubject = &General::system_output("/usr/bin/openssl", "x509", "-text", "-in", "${General::swroot}/ovpn/certs/servercert.pem"); |
5663 | my $hostsubject; | |
5664 | ||
5665 | foreach my $line (@hostsubject) { | |
5666 | if ($line =~ /Subject: (.*)[\n]/) { | |
5667 | $hostsubject = $1; | |
5668 | $hostsubject =~ s+/Email+, E+; | |
5669 | $hostsubject =~ s/ ST=/ S=/; | |
5670 | ||
5671 | last; | |
5672 | } | |
5673 | } | |
4c962356 EK |
5674 | |
5675 | print <<END; | |
5676 | <tr> | |
5677 | <td class='base' $col2>$Lang::tr{'host certificate'}</td> | |
5678 | <td class='base' $col2>$hostsubject</td> | |
c8f50356 | 5679 | <form method='post' name='frmhostcrta'><td width='3%' align='center' $col2> |
4c962356 EK |
5680 | <input type='hidden' name='ACTION' value='$Lang::tr{'show host certificate'}' /> |
5681 | <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' /> | |
c8f50356 EK |
5682 | </form> |
5683 | <form method='post' name='frmhostcrtb'><td width='3%' align='center' $col2> | |
4c962356 EK |
5684 | <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' /> |
5685 | <input type='hidden' name='ACTION' value="$Lang::tr{'download host certificate'}" /> | |
c8f50356 EK |
5686 | </td></form> |
5687 | <td width='4%' $col2> </td> | |
5688 | </tr> | |
4c962356 EK |
5689 | END |
5690 | ; | |
5691 | } else { | |
5692 | # Nothing | |
5693 | print <<END; | |
5694 | <tr> | |
5695 | <td width='25%' class='base' $col2>$Lang::tr{'host certificate'}:</td> | |
5696 | <td class='base' $col2>$Lang::tr{'not present'}</td> | |
c8f50356 EK |
5697 | </td><td colspan='3' $col2> </td> |
5698 | </tr> | |
4c962356 EK |
5699 | END |
5700 | ; | |
5701 | } | |
ce9abb66 | 5702 | |
f7fb5bc5 | 5703 | # Adding DH parameter to chart |
35494eac PM |
5704 | if (-f "$dhparameter") { |
5705 | my @dhsubject = &General::system_output("/usr/bin/openssl", "dhparam", "-text", "-in", "$dhparameter"); | |
2feacd98 | 5706 | my $dhsubject; |
f7fb5bc5 | 5707 | |
2feacd98 SS |
5708 | foreach my $line (@dhsubject) { |
5709 | if ($line =~ / (.*)[\n]/) { | |
5710 | $dhsubject = $1; | |
5711 | ||
5712 | last; | |
5713 | } | |
5714 | } | |
f7fb5bc5 EK |
5715 | |
5716 | print <<END; | |
5717 | <tr> | |
19a417c2 | 5718 | <td class='base' $col3>$Lang::tr{'dh'}</td> |
f7fb5bc5 | 5719 | <td class='base' $col3>$dhsubject</td> |
c8f50356 | 5720 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> |
f7fb5bc5 EK |
5721 | <input type='hidden' name='ACTION' value='$Lang::tr{'show dh'}' /> |
5722 | <input type='image' name='$Lang::tr{'show dh'}' src='/images/info.gif' alt='$Lang::tr{'show dh'}' title='$Lang::tr{'show dh'}' width='20' height='20' border='0' /> | |
c8f50356 EK |
5723 | </form> |
5724 | <form method='post' name='frmdhparam'><td width='3%' align='center' $col3> | |
c8f50356 EK |
5725 | </form> |
5726 | <td width='4%' $col3> </td> | |
5727 | </tr> | |
f7fb5bc5 EK |
5728 | END |
5729 | ; | |
5730 | } else { | |
5731 | # Nothing | |
5732 | print <<END; | |
5733 | <tr> | |
a3e8b9bb | 5734 | <td width='25%' class='base' $col3>$Lang::tr{'dh'}:</td> |
f7fb5bc5 | 5735 | <td class='base' $col3>$Lang::tr{'not present'}</td> |
c8f50356 EK |
5736 | </td><td colspan='3' $col3> </td> |
5737 | </tr> | |
f7fb5bc5 EK |
5738 | END |
5739 | ; | |
5740 | } | |
5741 | ||
fd5ccb2d EK |
5742 | # Adding ta.key to chart |
5743 | if (-f "${General::swroot}/ovpn/certs/ta.key") { | |
2feacd98 SS |
5744 | open(FILE, "${General::swroot}/ovpn/certs/ta.key"); |
5745 | my @tasubject = <FILE>; | |
5746 | close(FILE); | |
5747 | ||
5748 | my $tasubject; | |
5749 | foreach my $line (@tasubject) { | |
5750 | if($line =~ /# (.*)[\n]/) { | |
5751 | $tasubject = $1; | |
5752 | ||
5753 | last; | |
5754 | } | |
5755 | } | |
5756 | ||
fd5ccb2d EK |
5757 | print <<END; |
5758 | ||
5759 | <tr> | |
5760 | <td class='base' $col4>$Lang::tr{'ta key'}</td> | |
5761 | <td class='base' $col4>$tasubject</td> | |
5762 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5763 | <input type='hidden' name='ACTION' value='$Lang::tr{'show tls-auth key'}' /> | |
5764 | <input type='image' name='$Lang::tr{'edit'}' src='/images/info.gif' alt='$Lang::tr{'show tls-auth key'}' title='$Lang::tr{'show tls-auth key'}' width='20' height='20' border='0' /> | |
5765 | </form> | |
5766 | <form method='post' name='frmtakey'><td width='3%' align='center' $col4> | |
5767 | <input type='image' name='$Lang::tr{'download tls-auth key'}' src='/images/media-floppy.png' alt='$Lang::tr{'download tls-auth key'}' title='$Lang::tr{'download tls-auth key'}' border='0' /> | |
5768 | <input type='hidden' name='ACTION' value='$Lang::tr{'download tls-auth key'}' /> | |
5769 | </form> | |
5770 | <td width='4%' $col4> </td> | |
5771 | </tr> | |
5772 | END | |
5773 | ; | |
5774 | } else { | |
5775 | # Nothing | |
5776 | print <<END; | |
5777 | <tr> | |
5778 | <td width='25%' class='base' $col4>$Lang::tr{'ta key'}:</td> | |
5779 | <td class='base' $col4>$Lang::tr{'not present'}</td> | |
5780 | <td colspan='3' $col4> </td> | |
5781 | </tr> | |
5782 | END | |
5783 | ; | |
5784 | } | |
5785 | ||
4c962356 EK |
5786 | if (! -f "${General::swroot}/ovpn/ca/cacert.pem") { |
5787 | print "<tr><td colspan='5' align='center'><form method='post'>"; | |
5788 | print "<input type='submit' name='ACTION' value='$Lang::tr{'generate root/host certificates'}' />"; | |
5789 | print "</form></td></tr>\n"; | |
5790 | } | |
5791 | ||
5792 | if (keys %cahash > 0) { | |
5793 | foreach my $key (keys %cahash) { | |
5794 | if (($key + 1) % 2) { | |
5795 | print "<tr bgcolor='$color{'color20'}'>\n"; | |
5796 | } else { | |
5797 | print "<tr bgcolor='$color{'color22'}'>\n"; | |
5798 | } | |
5799 | print "<td class='base'>$cahash{$key}[0]</td>\n"; | |
5800 | print "<td class='base'>$cahash{$key}[1]</td>\n"; | |
5801 | print <<END; | |
5802 | <form method='post' name='cafrm${key}a'><td align='center'> | |
5803 | <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' /> | |
5804 | <input type='hidden' name='ACTION' value='$Lang::tr{'show ca certificate'}' /> | |
5805 | <input type='hidden' name='KEY' value='$key' /> | |
5806 | </td></form> | |
5807 | <form method='post' name='cafrm${key}b'><td align='center'> | |
5808 | <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' /> | |
5809 | <input type='hidden' name='ACTION' value='$Lang::tr{'download ca certificate'}' /> | |
5810 | <input type='hidden' name='KEY' value='$key' /> | |
5811 | </td></form> | |
5812 | <form method='post' name='cafrm${key}c'><td align='center'> | |
5813 | <input type='hidden' name='ACTION' value='$Lang::tr{'remove ca certificate'}' /> | |
5814 | <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' /> | |
5815 | <input type='hidden' name='KEY' value='$key' /> | |
5816 | </td></form></tr> | |
5817 | END | |
5818 | ; | |
5819 | } | |
5820 | } | |
5821 | ||
5822 | print "</table>"; | |
5823 | ||
5824 | # If the file contains entries, print Key to action icons | |
5825 | if ( -f "${General::swroot}/ovpn/ca/cacert.pem") { | |
5826 | print <<END; | |
5827 | <table> | |
5828 | <tr> | |
5829 | <td class='boldbase'> <b>$Lang::tr{'legend'}:</b></td> | |
5830 | <td> <img src='/images/info.gif' alt='$Lang::tr{'show certificate'}' /></td> | |
5831 | <td class='base'>$Lang::tr{'show certificate'}</td> | |
5832 | <td> <img src='/images/media-floppy.png' alt='$Lang::tr{'download certificate'}' /></td> | |
5833 | <td class='base'>$Lang::tr{'download certificate'}</td> | |
5834 | </tr> | |
5835 | </table> | |
5836 | END | |
5837 | ; | |
5838 | } | |
ce9abb66 | 5839 | |
4c962356 | 5840 | print <<END |
578f23c8 SS |
5841 | |
5842 | <br><hr><br> | |
5843 | ||
4c962356 | 5844 | <form method='post' enctype='multipart/form-data'> |
578f23c8 SS |
5845 | <table border='0' width='100%'> |
5846 | <tr> | |
5847 | <td colspan='4'><b>$Lang::tr{'upload ca certificate'}</b></td> | |
5848 | </tr> | |
4c962356 | 5849 | |
578f23c8 SS |
5850 | <tr> |
5851 | <td width='10%'>$Lang::tr{'ca name'}:</td> | |
5852 | <td width='30%'><input type='text' name='CA_NAME' value='$cgiparams{'CA_NAME'}' size='15' align='left'></td> | |
5853 | <td width='30%'><input type='file' name='FH' size='25'> | |
5854 | <td width='30%'align='right'><input type='submit' name='ACTION' value='$Lang::tr{'upload ca certificate'}'></td> | |
5855 | </tr> | |
f527e53f | 5856 | |
578f23c8 SS |
5857 | <tr> |
5858 | <td colspan='3'> </td> | |
5859 | <td align='right'><input type='submit' name='ACTION' value='$Lang::tr{'show crl'}' /></td> | |
5860 | </tr> | |
5861 | </table> | |
578f23c8 | 5862 | </form> |
66c36198 | 5863 | |
578f23c8 | 5864 | <br><hr> |
4c962356 EK |
5865 | END |
5866 | ; | |
5867 | ||
5868 | if ( $srunning eq "yes" ) { | |
5869 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' disabled='disabled' /></div></form>\n"; | |
5870 | } else { | |
5871 | print "<div align='center'><form method='post'><input type='submit' name='ACTION' value='$Lang::tr{'remove x509'}' /></div></form>\n"; | |
5872 | } | |
5873 | &Header::closebox(); | |
5874 | END | |
5875 | ; | |
5876 | ||
5877 | &Header::closepage(); | |
ce9abb66 | 5878 |