#!/usr/bin/perl my $client = "/usr/local/sbin/vpnc"; my $disconnect = "/usr/local/sbin/vpnc-disconnect"; my $profile_dir = "/etc/vpnc"; my @vpn_locations; print "\nPlease select to [c]onnect or [d]isconnect VPN, or e[x]it: "; my $action = ; chomp($action); if ($action eq "d" or $action eq "D") { exec("sudo $disconnect"); exit 0; } if ($action ne "c" and $action ne "C") { printf "Exiting.\n"; exit 0; } print "Available VPN Servers:\n\n"; opendir(DIR, $profile_dir); while (defined(my $location = readdir(DIR))) { #if ( $location =~ /^[^default]\.vpnc$/i) { if ($location ne "default.conf" and $location =~ /\.vpnc/i) { $location =~ s/.vpnc$//; push(@vpn_locations, $location); } } closedir(DIR); my $number_of_locations = @vpn_locations; if ($number_of_locations <= 0) { printf "[ERROR] No vpnc configurations found.\n"; exit 254; } else { for($i = 0; $i < $number_of_locations; $i++) { $number = $i+1; print "[$number] $vpn_locations[$i]\n"; } print "\nPlease select a VPN to connect to, or e[x]it: "; my $entry = ; chomp($entry); if ($entry <= 0 or $entry > $number) { printf "Exiting.\n"; exit 0; } print "\nConnecting to " . $vpn_locations[$entry-1] . "...\n"; my $command = "sudo $client --local-port 0 \"$vpn_locations[$entry-1]\".vpnc"; exec($command); print "$command\n"; }