line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bayonne::Server; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30667
|
use 5.008004; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
80
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
53
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
1
|
|
|
1
|
|
1307
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
2218
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
4603
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
173564
|
|
|
1
|
|
|
|
|
42
|
|
10
|
1
|
|
|
1
|
|
734
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use URI::Escape; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
15
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
16
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# This allows declaration use Bayonne::Libexec ':all'; |
19
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
20
|
|
|
|
|
|
|
# will save memory. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
) ] ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT = qw( |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
|
|
|
|
|
|
my $invocant = shift; |
36
|
|
|
|
|
|
|
my ($class) = ref($invocant) || $invocant; |
37
|
|
|
|
|
|
|
my $self = { |
38
|
|
|
|
|
|
|
hostid => undef, |
39
|
|
|
|
|
|
|
userid => "server", |
40
|
|
|
|
|
|
|
secret => undef, |
41
|
|
|
|
|
|
|
@_, |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
$self->{_session} = LWP::UserAgent->new(env_proxy => 1, timeout => 30); |
44
|
|
|
|
|
|
|
return bless $self, $class; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub xmlreply($$) { |
48
|
|
|
|
|
|
|
my ($self, $query) = @_; |
49
|
|
|
|
|
|
|
my $host = $self->{hostid}; |
50
|
|
|
|
|
|
|
my $user = $self->{userid}; |
51
|
|
|
|
|
|
|
my $secret = $self->{secret}; |
52
|
|
|
|
|
|
|
my $session = $self->{_session}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if(index($host, ":") < 1) { |
55
|
|
|
|
|
|
|
$host .= ":8055";}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $reply = undef; |
58
|
|
|
|
|
|
|
my $document = "http://" . $host . "/" . $query; |
59
|
|
|
|
|
|
|
my $request = new HTTP::Request 'GET', $document; |
60
|
|
|
|
|
|
|
if($secret) { |
61
|
|
|
|
|
|
|
$request->authorization_basic($user, $secret);}; |
62
|
|
|
|
|
|
|
my $response = $session->request($request); |
63
|
|
|
|
|
|
|
my $parser = XML::Simple->new(); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if($response->is_success()) { |
66
|
|
|
|
|
|
|
$reply = $parser->XMLin($response->{_content});}; |
67
|
|
|
|
|
|
|
return $reply; |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub reload($) { |
71
|
|
|
|
|
|
|
my($self) = @_; |
72
|
|
|
|
|
|
|
my $reply = $self->xmlreply("reload.xml"); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
if($reply) { |
75
|
|
|
|
|
|
|
return $reply->{results}->{result}->{value};}; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return "failure"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub uptime($) { |
81
|
|
|
|
|
|
|
my($self) = @_; |
82
|
|
|
|
|
|
|
my $reply = $self->xmlreply("uptime.xml"); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
if($reply) { |
85
|
|
|
|
|
|
|
return $reply->{results}->{result}->{value};}; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return undef; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub status($) { |
91
|
|
|
|
|
|
|
my($self) = @_; |
92
|
|
|
|
|
|
|
my $reply = $self->xmlreply("status.xml"); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if($reply) { |
95
|
|
|
|
|
|
|
return $reply->{results}->{result}->{value};}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return undef; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub traffic($) { |
101
|
|
|
|
|
|
|
my($self) = @_; |
102
|
|
|
|
|
|
|
my $reply = $self->xmlreply("traffic.xml"); |
103
|
|
|
|
|
|
|
my $result = undef; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
if($reply) { |
106
|
|
|
|
|
|
|
$result->{timestamp} = |
107
|
|
|
|
|
|
|
$reply->{results}->{result}->{timestamp}->{value}; |
108
|
|
|
|
|
|
|
$result->{active} = |
109
|
|
|
|
|
|
|
$reply->{results}->{result}->{activeCalls}->{value}; |
110
|
|
|
|
|
|
|
$result->{completed}->{incoming} = |
111
|
|
|
|
|
|
|
$reply->{results}->{result}->{incomingComplete}->{value}; |
112
|
|
|
|
|
|
|
$result->{completed}->{outgoing} = |
113
|
|
|
|
|
|
|
$reply->{results}->{result}->{outgoingComplete}->{value}; |
114
|
|
|
|
|
|
|
$result->{attempted}->{incoming} = |
115
|
|
|
|
|
|
|
$reply->{results}->{result}->{incomingAttempts}->{value}; |
116
|
|
|
|
|
|
|
$result->{attempted}->{outgoing} = |
117
|
|
|
|
|
|
|
$reply->{results}->{result}->{outgoingAttempts}->{value}; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
return $result; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub stop($$) { |
123
|
|
|
|
|
|
|
my($self,$sid) = @_; |
124
|
|
|
|
|
|
|
my $result = "failure"; |
125
|
|
|
|
|
|
|
$sid = uri_escape($sid); |
126
|
|
|
|
|
|
|
my $reply = $self->xmlreply("stop.xml?session=$sid"); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
if($reply) { |
129
|
|
|
|
|
|
|
$result = $reply->{results}->{result}->{value};}; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
if($result) { |
132
|
|
|
|
|
|
|
return $result;}; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
return "invalid"; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub session($$) { |
138
|
|
|
|
|
|
|
my($self,$sid) = @_; |
139
|
|
|
|
|
|
|
my $result = "failure"; |
140
|
|
|
|
|
|
|
$sid = uri_escape($sid); |
141
|
|
|
|
|
|
|
my $reply = $self->xmlreply("status.xml?session=$sid"); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
if($reply) { |
144
|
|
|
|
|
|
|
$result = $reply->{results}->{result}->{value};}; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
if($result eq "success") { |
147
|
|
|
|
|
|
|
return "active";}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
if($result) { |
150
|
|
|
|
|
|
|
return $result;}; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
return "invalid"; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub start($$$$$) { |
156
|
|
|
|
|
|
|
my($self, $target, $script, $caller, $display) = @_; |
157
|
|
|
|
|
|
|
my $query = "start.xml"; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
if(length($caller) < 1) { |
160
|
|
|
|
|
|
|
$caller = "unknown";}; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
if(length($display) < 1) { |
163
|
|
|
|
|
|
|
$display = $caller;}; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
$query .= "?target=" . uri_escape($target); |
166
|
|
|
|
|
|
|
$query .= "&script=" . uri_escape($script); |
167
|
|
|
|
|
|
|
$query .= "&caller=" . uri_escape($caller); |
168
|
|
|
|
|
|
|
$query .= "&display=" . uri_escape($display); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $reply = $self->xmlreply($query); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
if($reply){ |
173
|
|
|
|
|
|
|
return $reply->{results}->{result}->{value};}; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
return undef; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
__END__ |