This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1 @@
c:\program files\cisco systems\vpn client\|AW|Andre|K01v1kk0!

View File

@@ -0,0 +1,32 @@
#!C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlsvc-gui.exe
PAP-Version: 1.0
Packer: C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlsvc.exe
Script: vpnconnect.pl
Cwd: F:\Skripte\cisco vpn connect
Clean: 0
Date: 2011-04-02 14:40:54
Debug:
Dependent: 0
Dyndll: 0
Exe: vpnconnect.exe
Force: 0
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: 1
Version-InternalName: VPNConnectSVC
Version-LegalCopyright:
Version-LegalTrademarks:
Version-OriginalFilename: VPNConnectSVC
Version-ProductName: VPNConnectSVC
Version-ProductVersion: 1
Warnings: 0
Xclude: 0

View File

@@ -0,0 +1,138 @@
#!perl -w
package PerlSvc;
use strict;
use warnings;
my $service = 'VPNConnect';
my $logfile = 'c:/VPNConnectSVC.log';
my $configfile = 'c:/VPNConnectSVC.conf';
my $delay = 30;
my @options = ( 'log=s' => \$logfile,
'config=s' => \$configfile,
);
# turn on autoflush
$|=1;
(my $progname = $0) =~ s/.*?([^\\]+?)(\.\w+)$/$1/;
our(%Config,$Verbose);
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 => "--log $logfile --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";
my @CONF=<FH>;
close FH;
while (ContinueRun($delay)) {
foreach my $line (@CONF) {
chomp;
next if ($line =~ /^#/);
my ($DIR,$PROFILE,$USR,$PWD)=split /\|/,$line;
chdir("$DIR");
`vpnclient.exe stat>c:\\vpnconnect.log`;
my $est=1;
open RETF, "<c:\\vpnconnect.log";
my @ret=<RETF>;
close RETF;
foreach (@ret) {
if ($_ =~ /No connection exists/) {
$est=0;
}
}
if ($est==0) {
Log("Versuche Verbindungsaufbau");
`vpnclient.exe connect $PROFILE user $USR pwd $PWD>vpnconnect.log`;
}
}
}
Log("$Config{DisplayName} stopped at: ".localtime);
}
sub Log {
my $msg = shift;
open(my $f, ">>$logfile") or die $!;
print $f "$msg\n";
close $f;
}
sub Install {
#get_options('name=s' => \$service, @options, <<__USAGE__);
get_options(@options, <<__INSTALL__);
Valid --install suboptions are:
auto automatically start service
--log log file name [$logfile]
--config config file name [$configfile]
For example:
$progname --install auto --log logfile --config configfile
__INSTALL__
configure();
}
sub Help {
print <<__HELP__;
Automatically connects to VPN Gateway given in configfile
Install it as a service:
$progname --install auto --log logfile --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
logfile defaults to c:\\VPNConnectSVC.log
configfile defaults to c:\\VPNConnectSVC.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";
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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;
}

View 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";
}