line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UTM5::URFAClient::Daemon; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20637
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
458
|
use RPC::XML::Server; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use RPC::XML::Function; |
8
|
|
|
|
|
|
|
use XML::Writer; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
UTM5::URFAClient::Daemon - Daemon for L<UTM5::URFAClient> |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.20 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.20'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Quick summary of what the module does. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Perhaps a little code snippet. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use UTM5::URFAClient::Daemon; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $foo = UTM5::URFAClient::Daemon->new(<options>); |
32
|
|
|
|
|
|
|
... |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 new |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Starts daemon |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Params: |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
port |
43
|
|
|
|
|
|
|
path |
44
|
|
|
|
|
|
|
user |
45
|
|
|
|
|
|
|
pass |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
|
|
|
|
|
|
my ($class, $self) = @_; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
bless $self, $class; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $methods = { 'query' => sub { $self->_query(@_) } }; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->{port} ||= '39238'; |
60
|
|
|
|
|
|
|
$self->{path} ||= '/netup/utm5'; |
61
|
|
|
|
|
|
|
$self->{user} ||= 'init'; |
62
|
|
|
|
|
|
|
$self->{pass} ||= 'init'; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
warn "Starting URFA XML-RPC daemon at port $self->{port}...\n"; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $query = RPC::XML::Function->new({ |
67
|
|
|
|
|
|
|
name => 'query', |
68
|
|
|
|
|
|
|
code => sub { |
69
|
|
|
|
|
|
|
return $self->_query(@_) |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
}); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $server = RPC::XML::Server->new(port => $self->{port}) |
74
|
|
|
|
|
|
|
or die "Couldn't start HTTP server: $!"; |
75
|
|
|
|
|
|
|
$server->add_method($query); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return ($server, $server->server_loop); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _t { |
82
|
|
|
|
|
|
|
return $_[1] if ref $_[0] ne 'ARRAY'; |
83
|
|
|
|
|
|
|
t($_[0]->[0], ++$_[1]); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _create_xml { |
88
|
|
|
|
|
|
|
my ($self, $cmd, $params, $data) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$self->{_fname} = 'tmp'.int((time * (rand() * 10000)) / 1000); |
92
|
|
|
|
|
|
|
open FILE, ">".$self->{path}."/xml/".$self->{_fname}.".xml"; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $writer = new XML::Writer(OUTPUT => \*FILE, ENCODING => 'utf-8'); |
96
|
|
|
|
|
|
|
$writer->startTag('urfa'); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if(!$params) { |
100
|
|
|
|
|
|
|
$writer->emptyTag('call', function => $cmd); |
101
|
|
|
|
|
|
|
} else { |
102
|
|
|
|
|
|
|
$writer->startTag('call', function => $cmd); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
while(my ($key, $value) = each %$params) { |
105
|
|
|
|
|
|
|
$writer->emptyTag('parameter', name => $key, value => $value); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$writer->endTag('call'); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$writer->endTag('urfa'); |
112
|
|
|
|
|
|
|
$writer->end(); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
close FILE; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
if($data) { |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$self->{_dname} = 'dat'.int((time * (rand() * 10101)) / 1000); |
122
|
|
|
|
|
|
|
open DATA, ">".$self->{path}."/xml/".$self->{_dname}.".xml"; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
print DATA $data; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
close DATA; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
return ($self->{_fname}, $self->{_dname}); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _query { |
133
|
|
|
|
|
|
|
my ($self, $cmd, $params, $data) = @_; |
134
|
|
|
|
|
|
|
my $stdout; |
135
|
|
|
|
|
|
|
warn " * Query received: $cmd\n"; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my ($action, $datafile) = $self->_create_xml($cmd, $params, $data); |
138
|
|
|
|
|
|
|
warn "\tPATH: $self->{path}\n"; |
139
|
|
|
|
|
|
|
warn "\tUSER: $self->{user}\n"; |
140
|
|
|
|
|
|
|
warn "\tPASS: $self->{pass}\n"; |
141
|
|
|
|
|
|
|
warn "\tFNME: $self->{_fname}\n"; |
142
|
|
|
|
|
|
|
warn "\tCMND: $cmd\n"; |
143
|
|
|
|
|
|
|
warn "\tACTN: $action\n\n"; |
144
|
|
|
|
|
|
|
my $run = "$self->{path}/bin/utm5_urfaclient -l '$self->{user}' -P '$self->{pass}' -a $action ".($data ? " -datafile $self->{path}/xml/$datafile.xml" : ''); |
145
|
|
|
|
|
|
|
print "\nDEBUG: $run\n\n"; |
146
|
|
|
|
|
|
|
$stdout = `$run`; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
print "="x77; |
149
|
|
|
|
|
|
|
print "\n\n".$stdout."\n\n"; |
150
|
|
|
|
|
|
|
print "="x77, "\n"; |
151
|
|
|
|
|
|
|
unlink $self->{path}.'/xml/'.$self->{_fname}.'.xml'; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
return $stdout; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Nikita Melikhov, C<< <ver at 0xff.su> >> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 BUGS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-utm5-urfaclient-daemon at rt.cpan.org>, or through |
163
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=UTM5-URFAClient-Daemon>. |
164
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 SUPPORT |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
perldoc UTM5::URFAClient::Daemon |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
You can also look for information at: |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 4 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * Netup official site |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
L<http://www.netup.ru/> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=UTM5-URFAClient-Daemon> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Copyright 2011 Nikita Melikhov. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
195
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
196
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |
204
|
|
|
|
|
|
|
|