[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] cisco vpn script



I thought I would paste this hack for you all to laugh at.  I run this
program out of init like so:
vp::respawn:/usr/local/bin/check-vpn

So, when your timeout hits, the script will automagically reconnect or
if the script dies, init will restart it.

<<BRAINDUMP;
One could argue about storing your VPN password in a script
file....wonder if you could store it differently.....has to be passed
to vpnclient in the clear.....can't reverse a hash....mmm...
BRAINDUMP


#!/usr/bin/perl

use Expect;

$username = 'terry';
$password = 'password';
$profile = 'ciscoprofile';

while( foo == foo )
{
        $output = `/usr/local/bin/vpnclient stat`;
        if ( $output =~ /Your VPN connection is not active/ )
        {
                my $exp = Expect->spawn("/usr/local/bin/vpnclient
connect $profile")
                        or die "Cannot spawn vpnclient: $!\n";;
                my $spawn_ok;
                $exp->expect($timeout,
                        [
                                qr/Username \[\w+\]\: $/,
                                        sub {
                                                $spawn_ok = 1;
                                                my $fh = shift;
                                                $fh->send("$username\n");
                                                exp_continue;
                                        }
                        ],
                        [
                                qr/Password \[\]\: $/,
                                sub {
                                        $spawn_ok = 1;
                                        my $fh = shift;
                                        $fh->send("$password\n");
                                        exp_continue;
                                }
                        ],
                        [
                                qr/Do you wish to continue\? \(y\/n\)\: $/,
                                sub {
                                        my $fh = shift;
                                        $fh->send("y^M");
                                        exp_continue;
                                }
                        ],
                );
                $exp->soft_close();
        }
        else
        {
                print "All is good\n";
        }
        sleep 5;
}