-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvpn.pl
executable file
·67 lines (59 loc) · 1.13 KB
/
vpn.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/perl
use v5.14;
use Expect;
# NOTE run as sudo!!!
# Define following properties!!!
my $config_path = undef; # set the ovpn file path here
my $user = undef; # set your username here
my $pass = undef; # set your password here
my $command = "openvpn";
my @params = ("--config", $config_path);
my $timeout = 10; # in sec
sub run {
my $exp = Expect->spawn($command, @params);
$exp->expect(
$timeout,
[
qr/Enter Auth Username/i,
sub {
my $self = shift;
$self->send($user . "\n");
exp_continue;
}
],
[
qr/Enter Auth Password/i,
sub {
my $self = shift;
$self->send($pass . "\n");
exp_continue;
}
],
[
qr/killed expiring key/i,
sub {
say "Expired. Exiting";
$exp->soft_close();
}
],
[
eof => sub {
say "Got EOF";
}
],
[
timeout => sub {
#say "TIMEOUT";
exp_continue;
}
]
);
#$exp->soft_close();
}
#######################
# Main
#######################
while (1) {
run;
say "=============== RESTART ==============="
}