line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Netgear::WGT624; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25976
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
62
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1289
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
80688
|
|
|
1
|
|
|
|
|
1028
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
1
|
|
|
1
|
0
|
11
|
my $self = {}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Credentials necessary for connecting to router web interface. |
16
|
1
|
|
|
|
|
3
|
$self->{USERNAME} = undef; |
17
|
1
|
|
|
|
|
2
|
$self->{PASSWORD} = undef; |
18
|
1
|
|
|
|
|
3
|
$self->{ADDRESS} = undef; |
19
|
1
|
|
|
|
|
2
|
$self->{STATS} = undef; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
2
|
bless($self); |
22
|
1
|
|
|
|
|
4
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
###### BEGIN Private methods. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# _query_device - Wraps another function that uses LWP to query |
29
|
|
|
|
|
|
|
# router. This method just sorts the results into an internal |
30
|
|
|
|
|
|
|
# associative array. |
31
|
|
|
|
|
|
|
sub _query_device { |
32
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
my $resref = $self->_fetch_html; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
my @vals = grep( //, @$resref ); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
my @retvals = (); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
foreach my $val (@vals) { |
41
|
0
|
0
|
|
|
|
0
|
if ($val =~ m/span class="ttext">(.*?)<\/span>/) { |
42
|
0
|
|
|
|
|
0
|
push (@retvals, $1); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Put array elements into hash based on position. |
47
|
0
|
|
|
|
|
0
|
$self->{STATS} = { |
48
|
|
|
|
|
|
|
WAN_Status => $retvals[0], |
49
|
|
|
|
|
|
|
WAN_TxPkts => $retvals[1], |
50
|
|
|
|
|
|
|
WAN_RxPkts => $retvals[2], |
51
|
|
|
|
|
|
|
WAN_Collisions => $retvals[3], |
52
|
|
|
|
|
|
|
WAN_TxRate => $retvals[4], |
53
|
|
|
|
|
|
|
WAN_RxRate => $retvals[5], |
54
|
|
|
|
|
|
|
WAN_UpTime => $retvals[6], |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
LAN_Status => $retvals[7], |
57
|
|
|
|
|
|
|
LAN_TxPkts => $retvals[8], |
58
|
|
|
|
|
|
|
LAN_RxPkts => $retvals[9], |
59
|
|
|
|
|
|
|
LAN_Collisions => $retvals[10], |
60
|
|
|
|
|
|
|
LAN_TxRate => $retvals[11], |
61
|
|
|
|
|
|
|
LAN_RxRate => $retvals[12], |
62
|
|
|
|
|
|
|
LAN_UpTime => $retvals[13], |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
WLAN_Status => $retvals[14], |
65
|
|
|
|
|
|
|
WLAN_TxPkts => $retvals[15], |
66
|
|
|
|
|
|
|
WLAN_RxPkts => $retvals[16], |
67
|
|
|
|
|
|
|
WLAN_Collisions => $retvals[17], |
68
|
|
|
|
|
|
|
WLAN_TxRate => $retvals[18], |
69
|
|
|
|
|
|
|
WLAN_RxRate => $retvals[19], |
70
|
|
|
|
|
|
|
WLAN_UpTime => $retvals[20], |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# _get_server_address - Make sure that address is really a |
76
|
|
|
|
|
|
|
# server address, i.e., chop off prepending http:// and |
77
|
|
|
|
|
|
|
# slashes if found. Return the default port of 80 |
78
|
|
|
|
|
|
|
# for the netgear device. |
79
|
|
|
|
|
|
|
sub _get_server_address { |
80
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
3
|
my $address = $self->{ADDRESS}; |
83
|
2
|
|
|
|
|
5
|
$address =~ s/^http:\/\///; |
84
|
2
|
|
|
|
|
5
|
$address =~ s/\/$//; |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
3
|
$address .= ':80'; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
7
|
return $address; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# _fetch_html - gets the HTML from Netgear router using LWP. |
92
|
|
|
|
|
|
|
sub _fetch_html { |
93
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
my $username = $self->{USERNAME}; |
96
|
0
|
|
|
|
|
0
|
my $password = $self->{PASSWORD}; |
97
|
0
|
|
|
|
|
0
|
my $address = $self->{ADDRESS}; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
0
|
my $url = $self->_make_url; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Use the LWP library to download the HTML page into array @html. |
102
|
0
|
|
|
|
|
0
|
my $ua = LWP::UserAgent->new(); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
$ua->timeout(10); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
$ua->env_proxy; # Use proxy environment vars, if defined. |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
$ua->credentials($self->_get_server_address, |
109
|
|
|
|
|
|
|
'WGT624', |
110
|
|
|
|
|
|
|
$username, |
111
|
|
|
|
|
|
|
$password); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
my $response = $ua->get($url); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
my @html = (); |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
0
|
if ($response->is_success) { |
118
|
0
|
|
|
|
|
0
|
@html = split(/\n/, $response->content); |
119
|
|
|
|
|
|
|
} else { |
120
|
0
|
|
|
|
|
0
|
die "Error: Server returned error message: " . $response->status_line; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
0
|
return \@html; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# _make_url - generates the URL from input address. |
127
|
|
|
|
|
|
|
sub _make_url { |
128
|
3
|
|
|
3
|
|
8
|
my $self = shift; |
129
|
|
|
|
|
|
|
|
130
|
3
|
|
|
|
|
6
|
my $url = $self->{ADDRESS}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# If the address doesn't have http:// prepended, add it. |
133
|
3
|
50
|
|
|
|
10
|
if (!($url =~ m/^http:\/\//)) { |
134
|
3
|
|
|
|
|
6
|
$url = 'http://' . $url; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# If the address ends in a slash, chop it off because it |
138
|
|
|
|
|
|
|
# won't be necessary after next op. |
139
|
3
|
|
|
|
|
10
|
$url =~ s/\/$//; |
140
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
4
|
$url = $url . "/RST_stattbl.htm"; |
142
|
|
|
|
|
|
|
|
143
|
3
|
|
|
|
|
17
|
return $url; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
###### END Private methods |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub username($) { |
149
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
0
|
if (@_) { $self->{USERNAME} = shift; } |
|
0
|
|
|
|
|
0
|
|
152
|
0
|
|
|
|
|
0
|
return $self->{USERNAME}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub password($) { |
156
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
0
|
if (@_) { $self->{PASSWORD} = shift; } |
|
0
|
|
|
|
|
0
|
|
159
|
0
|
|
|
|
|
0
|
return $self->{PASSWORD}; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub address($) { |
163
|
3
|
|
|
3
|
1
|
9
|
my $self = shift; |
164
|
|
|
|
|
|
|
|
165
|
3
|
50
|
|
|
|
8
|
if (@_) { $self->{ADDRESS} = shift; } |
|
3
|
|
|
|
|
8
|
|
166
|
3
|
|
|
|
|
6
|
return $self->{ADDRESS}; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub getStatus($$) { |
170
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
171
|
0
|
|
|
|
|
|
my $param = shift; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Refresh our data structure containing the TxRate. |
174
|
0
|
|
|
|
|
|
$self->_query_device; |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
return $self->{STATS}->{$param}; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# getStatistic - this method is deprecated, and only |
180
|
|
|
|
|
|
|
# included to maintain compatibility with the now-removed |
181
|
|
|
|
|
|
|
# get-wgt624-statistics test script. It will be removed |
182
|
|
|
|
|
|
|
# in future versions. |
183
|
|
|
|
|
|
|
sub getStatistic($$) { |
184
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
185
|
0
|
|
|
|
|
|
my $param = shift; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $self->getStatus($param); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
__END__ |