init III
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
# LocalSubnet definiert in welchen Netzen keine VPN Verbindung aufgebaut werden soll
|
||||
# e.g. LocalSubnet=1.1.1.0/24
|
||||
# Befindet sich der Rechner im Netzwerk 1.1.1.0/24 wird keine VPN Verbindung aufgebaut
|
||||
# Default none
|
||||
LocalSubnet=192.168.100.0/24
|
||||
|
||||
# Angabe des Verzeichnisses in das Logfiles abgelegt werden
|
||||
# Default c:\VPNConnectSVC
|
||||
LogPath=c:\VPNConnect
|
||||
|
||||
# Pfad in dem der VPN Client liegt
|
||||
# Default c:\program files\cisco systems\vpn client
|
||||
VPNClientPath=C:\Program Files\Cisco Systems\VPN Client\
|
||||
|
||||
# Userprofil im VPN Client
|
||||
# Default none
|
||||
# wird nur benötigt als Variable für VPNStatus und VPNStartCmdLine
|
||||
VPNProfile=AW
|
||||
|
||||
# Xauth Username
|
||||
# Default none
|
||||
# wird nur benötigt als Variable für VPNStatus und VPNStartCmdLine
|
||||
VPNXauthUser=Andre
|
||||
|
||||
# Xauth Password
|
||||
# Default none
|
||||
# wird nur benötigt als Variable für VPNStatus und VPNStartCmdLine
|
||||
VPNXauthPassword=K01v1kk0!
|
||||
|
||||
# Kommandozeile um den VPN Status abzufragen
|
||||
# keine Pfadangabe davor setzen, wird im Verzeichnis VPNClientPath ausgeführt
|
||||
# Es können die Variablen $VPNProfile $VPNXauthUser $VPNXauthPassword verwendet werden
|
||||
VPNStatusCmdLine=vpnclient stat
|
||||
|
||||
# Hier wird eingestellt ob VPNStatusString eine aufgebaute oder nicht aufgebaute Verbindung anzeigt
|
||||
# default 0
|
||||
# 1 wenn VPNStatusString gefunden wird ist EINE VPN Verbindung aufgebaut
|
||||
# 0 wenn VPNStatusString gefunden wird ist KEINE VPN Verbindung aufgebaut
|
||||
VPNStatus=0
|
||||
|
||||
# Nach diesem Text wird gesucht wenn Status abgefragt wird
|
||||
# Default No connection exists
|
||||
# Ist VPNStatus auf 0 wird bei finden dieser Zeile eine Verbindung aufgebaut
|
||||
# Ist VPNStatus auf 1 ist die Verbindung bereits aufgebaut wenn diese Zeile gefunden wird
|
||||
VPNStatusString=No connection exists
|
||||
|
||||
# Kommandozeile um den VPN anzustarten
|
||||
# keine Pfadangabe davor setzen, wird im Verzeichnis VPNClientPath ausgeführt
|
||||
# Es können die Variablen $VPNProfile $VPNXauthUser $VPNXauthPassword verwendet werden
|
||||
VPNStartCmdLine=vpnclient.exe connect $VPNProfile user $VPNXauthUser pwd $VPNXauthPassword
|
||||
|
||||
# Kommandozeile um den VPN zu stoppen
|
||||
# siehe VPNStartCmdLine
|
||||
# wird benötigt um den VPN Tunnel zu stoppen sollte der Dienst angehalten werden
|
||||
VPNStoppCmdLine=vpnclient.exe disconnect
|
||||
@@ -0,0 +1,55 @@
|
||||
# LocalSubnet definiert in welchen Netzen keine VPN Verbindung aufgebaut werden soll
|
||||
# e.g. LocalSubnet=1.1.1.0/24
|
||||
# Befindet sich der Rechner im Netzwerk 1.1.1.0/24 wird keine VPN Verbindung aufgebaut
|
||||
# Default none
|
||||
LocalSubnet=192.168.101.0/24
|
||||
|
||||
# Angabe des Verzeichnisses in das Logfiles abgelegt werden
|
||||
# Default c:\VPNConnectSVC
|
||||
LogPath=c:\VPNConnectSVC\
|
||||
|
||||
# Pfad in dem der VPN Client liegt
|
||||
# Default c:\program files\cisco systems\vpn client
|
||||
VPNClientPath=c:\program files\cisco systems\vpn client
|
||||
|
||||
# Userprofil im VPN Client
|
||||
# Default none
|
||||
# wird nur benötigt als Variable für VPNStatus und VPNStartCmdLine
|
||||
VPNProfile=AW
|
||||
|
||||
# Xauth Username
|
||||
# Default none
|
||||
# wird nur benötigt als Variable für VPNStatus und VPNStartCmdLine
|
||||
VPNXauthUser=Andre
|
||||
|
||||
# Xauth Password
|
||||
# Default none
|
||||
# wird nur benötigt als Variable für VPNStatus und VPNStartCmdLine
|
||||
VPNXauthPassword=K01v1kk0!
|
||||
|
||||
# Kommandozeile um den VPN Status abzufragen
|
||||
# keine Pfadangabe davor setzen, wird im Verzeichnis VPNClientPath ausgeführt
|
||||
# Es können die Variablen $VPNProfile $VPNXauthUser $VPNXauthPassword verwendet werden
|
||||
VPNStatus=vpnclient.exe stat
|
||||
|
||||
# Hier wird eingestellt ob VPNStatusString eine aufgebaute oder nicht aufgebaute Verbindung anzeigt
|
||||
# default 0
|
||||
# 1 wenn VPNStatusString gefunden wird ist EINE VPN Verbindung aufgebaut
|
||||
# 0 wenn VPNStatusString gefunden wird ist KEINE VPN Verbindung aufgebaut
|
||||
VPNStatus=0
|
||||
|
||||
# Nach diesem Text wird gesucht wenn Status abgefragt wird
|
||||
# Default No connection exists
|
||||
# Ist VPNStatus auf 0 wird bei finden dieser Zeile eine Verbindung aufgebaut
|
||||
# Ist VPNStatus auf 1 ist die Verbindung bereits aufgebaut wenn diese Zeile gefunden wird
|
||||
VPNStatusString=No connection exists
|
||||
|
||||
# Kommandozeile um den VPN anzustarten
|
||||
# keine Pfadangabe davor setzen, wird im Verzeichnis VPNClientPath ausgeführt
|
||||
# Es können die Variablen $VPNProfile $VPNXauthUser $VPNXauthPassword verwendet werden
|
||||
VPNStartCmdLine=vpnclient.exe connect $VPNProfile user $VPNXauthUser pwd $VPNXauthPassword
|
||||
|
||||
# Kommandozeile um den VPN zu stoppen
|
||||
# siehe VPNStartCmdLine
|
||||
# wird benötigt um den VPN Tunnel zu stoppen sollte der Dienst angehalten werden
|
||||
VPNStoppCmdLine=vpnclient.exe disconnect
|
||||
BIN
Perl WIndows Cisco vpn connect Service/perlsvc v2/vpnconnect.exe
Normal file
BIN
Perl WIndows Cisco vpn connect Service/perlsvc v2/vpnconnect.exe
Normal file
Binary file not shown.
@@ -0,0 +1,32 @@
|
||||
#!C:\Program Files\ActiveState Perl Dev Kit 9.0\bin\perlsvc-gui.exe
|
||||
PAP-Version: 1.0
|
||||
Packer: C:\Program Files\ActiveState Perl Dev Kit 9.0\bin\perlsvc.exe
|
||||
Script: vpnconnect.pl
|
||||
Cwd: F:\Skripte\cisco vpn connect\perlsvc v2
|
||||
Clean: 1
|
||||
Date: 2011-04-10 13:57:12
|
||||
Debug:
|
||||
Dependent: 0
|
||||
Dyndll: 0
|
||||
Exe: vpnconnect.exe
|
||||
Force: 1
|
||||
Hostname: Andre-W7
|
||||
Manifest:
|
||||
No-Compress: 0
|
||||
No-Logo: 0
|
||||
Runlib:
|
||||
Shared: none
|
||||
Tmpdir:
|
||||
Verbose: 0
|
||||
Version-Comments:
|
||||
Version-CompanyName:
|
||||
Version-FileDescription: Automatically connect to given VPN Gateway
|
||||
Version-FileVersion: 2.1
|
||||
Version-InternalName: VPNConnect
|
||||
Version-LegalCopyright: Andre Wisniewski
|
||||
Version-LegalTrademarks:
|
||||
Version-OriginalFilename: VPNConnect.exe
|
||||
Version-ProductName: VPNConnect
|
||||
Version-ProductVersion: 2.1
|
||||
Warnings: 0
|
||||
Xclude: 0
|
||||
217
Perl WIndows Cisco vpn connect Service/perlsvc v2/vpnconnect.pl
Normal file
217
Perl WIndows Cisco vpn connect Service/perlsvc v2/vpnconnect.pl
Normal file
@@ -0,0 +1,217 @@
|
||||
#!/bin/perl
|
||||
|
||||
package PerlSvc;
|
||||
|
||||
use strict;
|
||||
#no strict 'refs';
|
||||
use Net::IP::AddrRanges;
|
||||
use Sys::HostAddr;
|
||||
|
||||
my $VPNStoppCmdLine="";
|
||||
my $service = 'VPNConnect';
|
||||
my $configfile = 'c:\VPNConnect\VPNConnect.conf';
|
||||
my $delay = 30;
|
||||
my @CONF;
|
||||
my $LOG;
|
||||
|
||||
my @options = ('config=s' => \$configfile );
|
||||
|
||||
# turn on autoflush
|
||||
$|=1;
|
||||
|
||||
(my $progname = $0) =~ s/.*?([^\\]+?)(\.\w+)$/$1/;
|
||||
our(%Config,$Verbose);
|
||||
|
||||
#open FH, "<$configfile";
|
||||
#@CONF=<FH>;
|
||||
#close FH;
|
||||
#Main();
|
||||
|
||||
sub get_options {
|
||||
require Getopt::Long;
|
||||
my @options = @_;
|
||||
my $usage = pop @options;
|
||||
$SIG{__WARN__} = sub { print "$usage\n$_[0]"; exit 1 };
|
||||
Getopt::Long::GetOptions(@options);
|
||||
$SIG{__WARN__} = 'DEFAULT';
|
||||
}
|
||||
sub configure {
|
||||
%Config = (ServiceName => "$service",
|
||||
DisplayName => "$service",
|
||||
Parameters => "--config $configfile",
|
||||
Description => "Automatically connect to given VPN Gateway");
|
||||
}
|
||||
sub Startup {
|
||||
get_options(@options, <<__USAGE__);
|
||||
Try `$progname --help` to get a list of valid options.
|
||||
__USAGE__
|
||||
|
||||
#Log("\n$Config{DisplayName} starting at: ".localtime);
|
||||
open FH, "<$configfile";
|
||||
@CONF=<FH>;
|
||||
close FH;
|
||||
while (ContinueRun($delay)) {
|
||||
Main();
|
||||
}
|
||||
DLog("$service and connection stopped");
|
||||
ServiceStopp();
|
||||
#Log("$Config{DisplayName} stopped at: ".localtime);
|
||||
}
|
||||
sub Install {
|
||||
#get_options('name=s' => \$service, @options, <<__USAGE__);
|
||||
get_options(@options, <<__INSTALL__);
|
||||
Valid --install suboptions are:
|
||||
|
||||
auto automatically start service
|
||||
--config config file name [$configfile]
|
||||
|
||||
For example:
|
||||
|
||||
$progname --install auto --config configfile
|
||||
|
||||
__INSTALL__
|
||||
|
||||
configure();
|
||||
}
|
||||
sub Help {
|
||||
print <<__HELP__;
|
||||
|
||||
Automatically connects to VPN Gateway given in configfile
|
||||
|
||||
Install it as a service:
|
||||
|
||||
$progname --install auto --config configfile
|
||||
net start $service
|
||||
|
||||
You can pause and resume the service with:
|
||||
|
||||
net pause $service
|
||||
net continue $service
|
||||
|
||||
To remove the service from your system, stop und uninstall it:
|
||||
|
||||
net stop $service
|
||||
$progname --remove
|
||||
|
||||
configfile defaults to c:\\VPNConnect\\VPNConnect.conf
|
||||
__HELP__
|
||||
|
||||
# Don't display standard PerlSvc help text
|
||||
$Verbose = 0;
|
||||
}
|
||||
sub Pause {
|
||||
#Log("$Config{ServiceName} is about to pause at ".localtime);
|
||||
}
|
||||
sub Continue {
|
||||
#Log("$Config{ServiceName} is continuing at ".localtime);
|
||||
}
|
||||
sub Remove {
|
||||
get_options('service=s' => \$service, <<__REMOVE__);
|
||||
No valid --remove suboptions
|
||||
|
||||
For example:
|
||||
|
||||
$progname --remove
|
||||
__REMOVE__
|
||||
$Config{ServiceName} = "$service";
|
||||
$Config{DisplayName} = "$service";
|
||||
}
|
||||
sub Main {
|
||||
my @LocalSubnets;
|
||||
my $LogPath;
|
||||
my $VPNClientPath;
|
||||
my $VPNProfile;
|
||||
my $VPNXauthUser;
|
||||
my $VPNXauthPassword;
|
||||
my $VPNStatusCmdLine;
|
||||
my $VPNStatus;
|
||||
my $VPNStatusString;
|
||||
my $VPNStartCmdLine;
|
||||
|
||||
foreach my $line (@CONF) {
|
||||
chomp $line;
|
||||
next if ($line =~ /^#/);
|
||||
my($k,$v) = split (/=/,$line);
|
||||
if ($k eq "LocalSubnet") { push @LocalSubnets,$v; }
|
||||
if ($k eq "LogPath") { $LogPath = $v; }
|
||||
if ($k eq "VPNClientPath") { $VPNClientPath = $v; }
|
||||
if ($k eq "VPNProfile") { $VPNProfile = $v; }
|
||||
if ($k eq "VPNXauthUser") { $VPNXauthUser = $v; }
|
||||
if ($k eq "VPNXauthPassword") { $VPNXauthPassword = $v; }
|
||||
if ($k eq "VPNStatusCmdLine") { $VPNStatusCmdLine = $v; }
|
||||
if ($k eq "VPNStatus") { $VPNStatus = $v; }
|
||||
if ($k eq "VPNStatusString") { $VPNStatusString = $v; }
|
||||
if ($k eq "VPNStartCmdLine") { $VPNStartCmdLine = $v; }
|
||||
if ($k eq "VPNStoppCmdLine") { $VPNStoppCmdLine = $v; }
|
||||
}
|
||||
$LOG=$LogPath;
|
||||
# Variablen in Commandlinestrings ersetzen
|
||||
my @Vars = qw /VPNProfile VPNXauthUser VPNXauthPassword/;
|
||||
|
||||
foreach my $v (@Vars) {
|
||||
my $a;
|
||||
$a=$VPNProfile if ($v eq "VPNProfile");
|
||||
$a=$VPNXauthUser if ($v eq "VPNXauthUser");
|
||||
$a=$VPNXauthPassword if ($v eq "VPNXauthPassword");
|
||||
|
||||
$VPNStatusCmdLine =~ s/\$$v/$a/;
|
||||
$VPNStartCmdLine =~ s/\$$v/$a/;
|
||||
$VPNStoppCmdLine =~ s/\$$v/$a/;
|
||||
}
|
||||
# lokale adresse ermitteln
|
||||
my $sysaddr = Sys::HostAddr->new();
|
||||
my $ip;
|
||||
my $noiperr=eval {
|
||||
$ip = $sysaddr->main_ip('route');
|
||||
};
|
||||
if ($noiperr) {
|
||||
# in einem netz in LocalSubnets?
|
||||
my $ranges = Net::IP::AddrRanges->new();
|
||||
$ranges->add(@LocalSubnets);
|
||||
if (!$ranges->find($ip)) {
|
||||
# nein
|
||||
# vpn status abfragen
|
||||
chdir($VPNClientPath);
|
||||
my @ret=`$VPNStatusCmdLine`;
|
||||
# Statusmeldung durchlaufen
|
||||
my $found=0;
|
||||
foreach (@ret) {
|
||||
# und nach Suchstring suchen
|
||||
if ($_ =~ /$VPNStatusString/) {
|
||||
# gefunden!
|
||||
$found=1;
|
||||
}
|
||||
}
|
||||
# Suchstring gefunden?
|
||||
my $connected;
|
||||
if ($found == 1) {
|
||||
# ja
|
||||
$connected = 1 if ($VPNStatus == 1); # Suchstring zeigt aufgebaute Verbindung an
|
||||
$connected = 0 if ($VPNStatus == 0); # Suchstring zeigt abgebaute Verbindung an
|
||||
if (!$connected) {
|
||||
# verbindung nicht hergestellt, aufbauen!
|
||||
DLog("Connection start");
|
||||
`$VPNStartCmdLine`;
|
||||
}
|
||||
else {
|
||||
# verbunden!
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
DLog("In range, no connection will be built");
|
||||
}
|
||||
}
|
||||
else {
|
||||
DLog ("No IP found");
|
||||
}
|
||||
}
|
||||
sub ServiceStopp {
|
||||
`$VPNStoppCmdLine`;
|
||||
}
|
||||
sub DLog {
|
||||
my $path="$LOG"."vpnconnect.debug.log";
|
||||
open FH, ">>$path";
|
||||
print FH "$_[0]\n";
|
||||
close FH;
|
||||
}
|
||||
22
Perl WIndows Cisco vpn connect Service/perlsvc v2/vpntest.pl
Normal file
22
Perl WIndows Cisco vpn connect Service/perlsvc v2/vpntest.pl
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/perl
|
||||
use Net::IP::AddrRanges;
|
||||
use Sys::HostAddr;
|
||||
my @LocalSubnets;
|
||||
push @LocalSubnets, "192.168.100.0/24";
|
||||
|
||||
# lokale adresse ermitteln
|
||||
my $sysaddr = Sys::HostAddr->new();
|
||||
my $ip;
|
||||
my $noiperr=eval { $ip = $sysaddr->main_ip('route'); };
|
||||
# in einem netz in LocalSubnets?
|
||||
if ($noiperr) {
|
||||
my $ranges = Net::IP::AddrRanges->new();
|
||||
$ranges->add(@LocalSubnets);
|
||||
if (!$ranges->find($ip)) {
|
||||
print "in\n";
|
||||
}
|
||||
print "out\n";
|
||||
}
|
||||
else {
|
||||
print "no ip!\n";
|
||||
}
|
||||
Reference in New Issue
Block a user