2 # Stefan Tomanek <stefan@pico.ruhr.de>
3 # updated by Wolfram Sang <ninja@the-dreams.de> on 21.10.06 and on 26.06.07
5 # pcf2vpnc <pcf file> [vpnc file]
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 2 of the License, or
10 # (at your option) any later version.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 my %authmode = ( 1 => 'psk', 3 => 'cert', 5 => 'hybrid' );
30 if (system("cisco-decrypt", "q") == -1) {
32 print STDERR
"cisco-decrypt not in search path,\n";
33 print STDERR
" adding passwords in obfuscated form\n";
40 # Filter unnecessary chars at beginning & end of line
42 if (/^(.*?)=(.*?)$/) {
43 # We don't need emtpy config strings
46 $config{IPSec
}{gateway
} = $2;
47 } elsif ($1 eq "GroupName") {
48 $config{IPSec
}{ID
} = $2;
49 } elsif ($1 eq "GroupPwd") {
50 $config{IPSec
}{secret
} = $2;
51 } elsif ($1 eq "enc_GroupPwd") {
53 $config{IPSec
}{obfuscated
} = "secret $2";
55 $config{IPSec
}{secret
} = `cisco-decrypt $2`;
57 } elsif ($1 eq "AuthType") {
58 $config{IKE
}{Authmode
} = $authmode{$2};
59 if ($2 == 3 || $2 == 5) {
62 } elsif ($1 eq "DHGroup") {
63 $config{IKE
}{DH
} = "Group dh$2";
64 } elsif ($1 eq "Username") {
65 $config{Xauth
}{username
} = $2;
66 } elsif ($1 eq "UserPassword") {
67 $config{Xauth
}{password
} = $2;
68 } elsif ($1 eq "enc_UserPassword") {
70 $config{Xauth
}{obfuscated
} = "password $2";
72 $config{Xauth
}{password
} = `cisco-decrypt $2`;
74 } elsif ($1 eq "NTDomain") {
75 $config{Domain
}{""} = $2;
84 my $text = "## generated by pcf2vpnc\n";
85 foreach my $section (keys %$config) {
86 foreach my $item (keys %{ $config->{$section} }) {
87 $text .= "$section ".($item ?
"$item " : '').$config->{$section}{$item}."\n";
90 unless (defined $config->{Xauth
}) {
91 $text .= "\n## To add your username and password,\n";
92 $text .= "## use the following lines:\n";
93 $text .= "# Xauth username <your username>\n";
94 $text .= "# Xauth password <your password>\n";
99 if (defined $ARGV[0]) {
100 my $src = new IO
::File
($ARGV[0]) || die "Unable to open file ".$ARGV[0]."\n";
101 if (defined $ARGV[1]) {
102 my $dst = new IO
::File
($ARGV[1], "w") || die "Unable to open file ".$ARGV[1]."\n";
103 $dst->write( writeVPNC
(readPCF
($src)) ) || die "Unable to write to file ".$ARGV[1]."\n";
104 $dst->close() || die "Unable to close file ".$ARGV[1]."\n";
105 printf STDERR
"vpnc config written to '%s' with permissions '%04o'.\n", $ARGV[1], (stat($ARGV[1]))[2];
106 print STDERR
"Please take care of permissions.\n";
108 print writeVPNC
(readPCF
($src));
110 $src->close() || die "Unable to close file ".$ARGV[0]."\n";
112 print STDERR
"\nDon't forget to copy the needed certificate(s).\n\n";
115 print STDERR
"$0 converts VPN-config files from pcf to vpnc-format.\n";
116 print STDERR
"Usage: $0 <pcf file> [vpnc file]\n";