#!/usr/bin/perl use Net::OpenSSH; use strict; use warnings; $Net::OpenSSH::debug=-1; # Define varilables my $vpntype=$ARGV[2]; my $requestor=$ARGV[1]; my $user='username'; my $password='password'; my $peerIP=$ARGV[0]; my $log_file="/share/www/vpndb/tunnel_clear.log"; my $host; my $datestring; my $message; # Determine which host to connect to if($vpntype eq 'ASP VPN') { $host='192.168.254.1'; } else { $host='192.168.254.2'; } # Connect to host print "Connecting to $host\n"; #my $ssh = Net::OpenSSH->new($host, user => $user, password => $password, master_opts => '-vv'); my $ssh = Net::OpenSSH->new($host, user => $user, password => $password); $ssh->error and die "Unable to connect: " . $ssh->error; print "Connected to $host\n"; # Clear the VPN tunnel my $cmd = "vpn-sessiondb logoff ipaddress $peerIP noconfirm"; my $sshen = "\nen\n$password\n$cmd\nexit\n"; my @output = $ssh->capture("$sshen"); # Check to make sure VPN was cleared successfully $datestring = localtime(); if ( grep( /logged off : 1/, @output ) ) { print "\nFound!\n\n"; $message = "Tunnel SUCCESSFULLY cleared for peer $peerIP, requested by $requestor with service: $vpntype"; } else { print "\nNot Found!\n\n"; $message = "Tunnel NOT SUCCESSFULLY cleared for peer $peerIP, requested by $requestor with service: $vpntype"; } # Write to log file open my $log_fh, ">>", $log_file; print "Output = @output\n\n"; write_to_log ($log_fh, $message); print $log_fh "Output = @output\n\n"; # Clean up close $log_fh; undef $ssh; # Sub Routines sub write_to_log { my $file_handle = shift; $message = shift; my $time = localtime(); return print $file_handle "$time: $message\n"; }