line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Simple::Confvpn; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
46699
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
505
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw(vpn_status vpn_start vpn_stop route_configuration); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.09'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub vpn_status |
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
# Function: To check vpn status |
19
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
20
|
0
|
|
|
0
|
0
|
|
my $ppp_result=`ifconfig | grep ppp.`; |
21
|
0
|
0
|
|
|
|
|
if($? != 0) |
22
|
|
|
|
|
|
|
{ |
23
|
0
|
|
|
|
|
|
print "please check the ifconfig command"; |
24
|
0
|
|
|
|
|
|
exit 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else |
27
|
|
|
|
|
|
|
{ |
28
|
0
|
0
|
|
|
|
|
if(length($ppp_result)>0) |
29
|
|
|
|
|
|
|
{ |
30
|
0
|
|
|
|
|
|
my @lines = split /\n/, $ppp_result; |
31
|
0
|
|
|
|
|
|
foreach my $line (@lines) |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
|
|
|
my $ppp=substr($line,0,4); |
34
|
0
|
|
|
|
|
|
my $ppp_inet=`ifconfig $ppp | grep -e "inet adr" -e"inet addr"`; |
35
|
0
|
0
|
|
|
|
|
if($? != 0) |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
|
|
|
print "please check the ifconfig command"; |
38
|
0
|
|
|
|
|
|
exit 1; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
0
|
|
|
|
|
if(length($ppp_inet)>0) |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
|
|
|
print "virtual private network[VPN] connection is running.."; |
45
|
0
|
|
|
|
|
|
return 0; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub vpn_start |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
58
|
|
|
|
|
|
|
# Function: To start the vpn |
59
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
60
|
0
|
|
|
0
|
0
|
|
my $csa=system("pppd call pure-ru1"); |
61
|
0
|
0
|
|
|
|
|
die "pppd rule call is failing.." if($csa!=0); |
62
|
0
|
|
|
|
|
|
my $cpt=0; |
63
|
0
|
|
|
|
|
|
my $timeOut=30; #default |
64
|
0
|
|
0
|
|
|
|
while(length(`ifconfig ppp0 | grep -e "inet adr" -e"inet addr"`)<=0 && $cpt<$timeOut) |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
|
|
|
|
|
$cpt++; |
67
|
0
|
|
|
|
|
|
print "Waited $cpt/$timeOut sec for the vpn to set up..."; |
68
|
0
|
|
|
|
|
|
sleep 1; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
0
|
|
|
|
|
if($cpt<$timeOut) |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
|
|
|
print "Started the service.."; |
73
|
0
|
|
|
|
|
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
|
print "A vpn connection was not set after $timeOut sec."; |
78
|
0
|
|
|
|
|
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub route_configuration |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
#----------------------------------------- |
87
|
|
|
|
|
|
|
##cpt route 0 for destination |
88
|
|
|
|
|
|
|
##cpt route 1 for gateway |
89
|
|
|
|
|
|
|
##cpt route 7 for interface |
90
|
|
|
|
|
|
|
#------------------------------------------ |
91
|
0
|
|
|
0
|
0
|
|
my $cptRoute=shift; |
92
|
0
|
|
|
|
|
|
my $csa =system("route add default dev ppp0"); |
93
|
0
|
0
|
|
|
|
|
die "adding route command is failing.." if($csa!=0); |
94
|
0
|
|
|
|
|
|
my $route_result=`route -n`; |
95
|
0
|
0
|
|
|
|
|
if($route_result ne 0) |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
|
|
|
print "please check 'route -n' command after adding the default route"; |
98
|
0
|
|
|
|
|
|
exit 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
|
|
|
my @linesRoute = split /\n/, $route_result; |
103
|
0
|
|
|
|
|
|
foreach my $lineRoute (@linesRoute) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
|
my @dataRoute = split / /, $lineRoute; |
106
|
0
|
|
|
|
|
|
my $destination=""; |
107
|
0
|
|
|
|
|
|
my $gateway=""; |
108
|
0
|
|
|
|
|
|
my $interface=""; |
109
|
0
|
|
|
|
|
|
foreach my $dataRoute (@dataRoute) |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
0
|
|
|
|
|
if(length($dataRoute)>0) |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
0
|
|
|
|
|
if($cptRoute==0) {$destination=$dataRoute;} |
|
0
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
if($cptRoute==1) {$gateway=$dataRoute;} |
|
0
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if($cptRoute==7) {$interface=$dataRoute;} |
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$cptRoute++; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
0
|
0
|
0
|
|
|
|
if($destination eq '0.0.0.0' && index($interface, 'ppp') == -1) |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
|
|
|
my $csg=system("route del -net $destination gw $gateway"); |
122
|
0
|
0
|
|
|
|
|
die "deleting route command is failing.." if($csg!=0); |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
$cptRoute=0; |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
|
print "route configuration is done.."; |
127
|
0
|
|
|
|
|
|
return 0; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub vpn_stop |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
135
|
|
|
|
|
|
|
# Function: To stop vpn |
136
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
137
|
0
|
|
|
0
|
0
|
|
`ps -ef | grep ppp | awk '{print $2}' | xargs kill`; |
138
|
0
|
0
|
|
|
|
|
if($? ne 0) |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
|
|
|
print "couldnot stop the Vpn service.."; |
141
|
0
|
|
|
|
|
|
exit 1; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
|
|
|
print "service vpn stopped"; |
146
|
0
|
|
|
|
|
|
return 0; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |