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