line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl
|
2
|
|
|
|
|
|
|
# OxdClientSocket.pm, a number as an object
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#####################################
|
5
|
|
|
|
|
|
|
# Client Script:
|
6
|
|
|
|
|
|
|
# Copyright 2016 (c) Ourdesignz
|
7
|
|
|
|
|
|
|
# this program is distributed according to
|
8
|
|
|
|
|
|
|
# the terms of the Perl license
|
9
|
|
|
|
|
|
|
# Use at your own risk
|
10
|
|
|
|
|
|
|
#####################################
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package OxdClientSocket; # This is the "Class"
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
8
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
40
|
|
|
1
|
|
|
|
|
55
|
|
17
|
|
|
|
|
|
|
$VERSION = '0.01';
|
18
|
|
|
|
|
|
|
# makes all attributes available
|
19
|
1
|
|
|
1
|
|
320
|
use Time::Piece;
|
|
1
|
|
|
|
|
7223
|
|
|
1
|
|
|
|
|
3
|
|
20
|
1
|
|
|
1
|
|
440
|
use lib './modules';
|
|
1
|
|
|
|
|
594
|
|
|
1
|
|
|
|
|
5
|
|
21
|
1
|
|
|
1
|
|
402
|
use Attribute::Handlers;
|
|
1
|
|
|
|
|
3807
|
|
|
1
|
|
|
|
|
8
|
|
22
|
|
|
|
|
|
|
#use strict;
|
23
|
1
|
|
|
1
|
|
45
|
use warnings;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
24
|
1
|
|
|
1
|
|
15
|
use 5.010;
|
|
1
|
|
|
|
|
6
|
|
25
|
1
|
|
|
1
|
|
4
|
use JSON::PP;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
26
|
1
|
|
|
1
|
|
411
|
use Data::Dumper qw(Dumper);
|
|
1
|
|
|
|
|
5646
|
|
|
1
|
|
|
|
|
57
|
|
27
|
1
|
|
|
1
|
|
384
|
use utf8;
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
8
|
|
28
|
1
|
|
|
1
|
|
378
|
use Encode;
|
|
1
|
|
|
|
|
9400
|
|
|
1
|
|
|
|
|
97
|
|
29
|
1
|
|
|
1
|
|
11
|
use File::Basename;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
76
|
|
30
|
1
|
|
|
1
|
|
8
|
use warnings;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
31
|
1
|
|
|
1
|
|
8
|
use OxdPackages::OxdConfig;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
32
|
|
|
|
|
|
|
#use IO::Socket::Socks;
|
33
|
1
|
|
|
1
|
|
629
|
use IO::Socket::SSL qw(debug0);
|
|
1
|
|
|
|
|
86375
|
|
|
1
|
|
|
|
|
14
|
|
34
|
|
|
|
|
|
|
#use Sys::Hostname;
|
35
|
|
|
|
|
|
|
#$| = 1;
|
36
|
1
|
|
|
1
|
|
252
|
use constant BUFSIZE => 1024;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
644
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new {
|
39
|
0
|
|
|
0
|
|
|
my $class = shift;
|
40
|
0
|
|
|
|
|
|
my $self = {
|
41
|
|
|
|
|
|
|
# @static
|
42
|
|
|
|
|
|
|
# @var object $socket Socket connection
|
43
|
|
|
|
|
|
|
_socket => shift,
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# @var string $base_url Base url for log file directory and oxd-rp-setting.json file.
|
46
|
|
|
|
|
|
|
_base_url => dirname(__FILE__)
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
};
|
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
bless $self, $class;
|
51
|
0
|
|
|
|
|
|
return $self;
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Sending request to oxd server via socket
|
55
|
|
|
|
|
|
|
#
|
56
|
|
|
|
|
|
|
# @param string $data
|
57
|
|
|
|
|
|
|
# @param int $char_count
|
58
|
|
|
|
|
|
|
# @return object
|
59
|
|
|
|
|
|
|
sub oxd_socket_request{
|
60
|
0
|
|
|
0
|
|
|
my ($self,$data, $char_count) = @_;
|
61
|
0
|
0
|
|
|
|
|
$char_count = $char_count ? $char_count : 8192;
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#print $data;
|
64
|
0
|
|
|
|
|
|
my $oxdConfig = OxdConfig->new();
|
65
|
0
|
|
|
|
|
|
my $op_host = $oxdConfig->{'_op_host'};
|
66
|
0
|
|
|
|
|
|
my $oxd_host_port = $oxdConfig->{'_oxd_host_port'};
|
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
$socket = new IO::Socket::INET ( PeerHost => '127.0.0.1', PeerPort => $oxd_host_port, Proto => 'tcp', Reuse => 1) or die "$!\n";
|
69
|
0
|
0
|
|
|
|
|
if (!$socket) {
|
70
|
0
|
|
|
|
|
|
$self->log("Client: socket::socket_connect is not connected, error: ",$!);
|
71
|
0
|
|
|
|
|
|
die $!;
|
72
|
|
|
|
|
|
|
}else{
|
73
|
0
|
|
|
|
|
|
$self->log("Client: socket::socket_connect ", "socket connected");
|
74
|
|
|
|
|
|
|
}
|
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if(!($socket->syswrite($data, length($data)))){
|
77
|
0
|
|
|
|
|
|
$self->log("Client: socket::socket_connect ", "Error writing");
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->log("Client: oxd_socket_request", $socket->syswrite($data, length($data)));
|
81
|
0
|
|
|
|
|
|
$socket->syswrite($data, length($data));
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
sysread($socket, $result, $char_count);
|
84
|
|
|
|
|
|
|
#print "$result\n";
|
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if($result){
|
87
|
0
|
|
|
|
|
|
$self->log("Client: oxd_socket_response", $result);
|
88
|
|
|
|
|
|
|
}else{
|
89
|
0
|
|
|
|
|
|
$self->log("Client: oxd_socket_response", 'Error socket reading process.');
|
90
|
|
|
|
|
|
|
}
|
91
|
0
|
0
|
|
|
|
|
if(close($socket)){
|
92
|
0
|
|
|
|
|
|
$self->log("Client: oxd_socket_connection", "disconnected.");
|
93
|
|
|
|
|
|
|
}
|
94
|
0
|
|
|
|
|
|
return $result;
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Showing errors and exit.
|
98
|
|
|
|
|
|
|
# @param string $error
|
99
|
|
|
|
|
|
|
# @return void
|
100
|
|
|
|
|
|
|
sub error_message{
|
101
|
0
|
|
|
0
|
|
|
my ($self, $error) = @_;
|
102
|
0
|
|
|
|
|
|
print ' ' . $error.' ';
|
103
|
0
|
|
|
|
|
|
exit($error);
|
104
|
|
|
|
|
|
|
}
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Saving process in log file.
|
107
|
|
|
|
|
|
|
# @param string $process
|
108
|
|
|
|
|
|
|
# @param string $message
|
109
|
|
|
|
|
|
|
# @return void
|
110
|
|
|
|
|
|
|
sub log{
|
111
|
0
|
|
|
0
|
|
|
my ($self, $process, $message) = @_;
|
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $t = localtime;
|
114
|
0
|
|
|
|
|
|
my $timeStamp = $t->mdy("-");# 02/29/2000
|
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $fileName = "oxd-perl-server-$timeStamp.log";
|
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my $datestring = localtime();
|
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
my $filename = "logs/$fileName";
|
121
|
0
|
0
|
|
|
|
|
open(my $fh, '>>', $filename) or die "Could not open file '$filename' $!";
|
122
|
0
|
|
|
|
|
|
my $person = "\n".$datestring."\n".$process." ".$message."\n";
|
123
|
0
|
|
|
|
|
|
say $fh "$person\n";
|
124
|
0
|
|
|
|
|
|
close $fh;
|
125
|
|
|
|
|
|
|
#say "done\n";
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; # this 1; is neccessary for our class to work
|