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
|
|
4
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
412
|
|
17
|
|
|
|
|
|
|
$VERSION = '0.01'; |
18
|
|
|
|
|
|
|
# makes all attributes available |
19
|
1
|
|
|
1
|
|
577
|
use Time::Piece; |
|
1
|
|
|
|
|
10051
|
|
|
1
|
|
|
|
|
8
|
|
20
|
1
|
|
|
1
|
|
668
|
use lib './modules'; |
|
1
|
|
|
|
|
711
|
|
|
1
|
|
|
|
|
6
|
|
21
|
1
|
|
|
1
|
|
915
|
use Attribute::Handlers; |
|
1
|
|
|
|
|
5645
|
|
|
1
|
|
|
|
|
6
|
|
22
|
|
|
|
|
|
|
#use strict; |
23
|
1
|
|
|
1
|
|
39
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
24
|
1
|
|
|
1
|
|
18
|
use 5.010; |
|
1
|
|
|
|
|
7
|
|
25
|
1
|
|
|
1
|
|
6
|
use JSON::PP; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
91
|
|
26
|
1
|
|
|
1
|
|
959
|
use Data::Dumper qw(Dumper); |
|
1
|
|
|
|
|
7029
|
|
|
1
|
|
|
|
|
80
|
|
27
|
1
|
|
|
1
|
|
780
|
use utf8; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
6
|
|
28
|
1
|
|
|
1
|
|
723
|
use Encode; |
|
1
|
|
|
|
|
10294
|
|
|
1
|
|
|
|
|
100
|
|
29
|
1
|
|
|
1
|
|
8
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
30
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
31
|
1
|
|
|
1
|
|
6
|
use OxdPackages::OxdConfig; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
32
|
|
|
|
|
|
|
#use IO::Socket::Socks; |
33
|
1
|
|
|
1
|
|
383
|
use IO::Socket::SSL qw(debug0); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#use Sys::Hostname; |
35
|
|
|
|
|
|
|
#$| = 1; |
36
|
|
|
|
|
|
|
use constant BUFSIZE => 1024; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
|
|
|
|
|
|
my $class = shift; |
40
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
bless $self, $class; |
51
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my ($self,$data, $char_count) = @_; |
61
|
|
|
|
|
|
|
$char_count = $char_count ? $char_count : 8192; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#print $data; |
64
|
|
|
|
|
|
|
my $oxdConfig = OxdConfig->new(); |
65
|
|
|
|
|
|
|
my $op_host = $oxdConfig->{'_op_host'}; |
66
|
|
|
|
|
|
|
my $oxd_host_port = $oxdConfig->{'_oxd_host_port'}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$socket = new IO::Socket::INET ( PeerHost => '127.0.0.1', PeerPort => $oxd_host_port, Proto => 'tcp', Reuse => 1) or die "$!\n"; |
69
|
|
|
|
|
|
|
if (!$socket) { |
70
|
|
|
|
|
|
|
$self->log("Client: socket::socket_connect is not connected, error: ",$!); |
71
|
|
|
|
|
|
|
die $!; |
72
|
|
|
|
|
|
|
}else{ |
73
|
|
|
|
|
|
|
$self->log("Client: socket::socket_connect ", "socket connected"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
if(!($socket->syswrite($data, length($data)))){ |
77
|
|
|
|
|
|
|
$self->log("Client: socket::socket_connect ", "Error writing"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$self->log("Client: oxd_socket_request", $socket->syswrite($data, length($data))); |
81
|
|
|
|
|
|
|
$socket->syswrite($data, length($data)); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sysread($socket, $result, $char_count); |
84
|
|
|
|
|
|
|
#print "$result\n"; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
if($result){ |
87
|
|
|
|
|
|
|
$self->log("Client: oxd_socket_response", $result); |
88
|
|
|
|
|
|
|
}else{ |
89
|
|
|
|
|
|
|
$self->log("Client: oxd_socket_response", 'Error socket reading process.'); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
if(close($socket)){ |
92
|
|
|
|
|
|
|
$self->log("Client: oxd_socket_connection", "disconnected."); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
return $result; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Showing errors and exit. |
98
|
|
|
|
|
|
|
# @param string $error |
99
|
|
|
|
|
|
|
# @return void |
100
|
|
|
|
|
|
|
sub error_message{ |
101
|
|
|
|
|
|
|
my ($self, $error) = @_; |
102
|
|
|
|
|
|
|
print ' ' . $error.' '; |
103
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my ($self, $process, $message) = @_; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $t = localtime; |
114
|
|
|
|
|
|
|
my $timeStamp = $t->mdy("-");# 02/29/2000 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $fileName = "oxd-perl-server-$timeStamp.log"; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $datestring = localtime(); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $filename = "logs/$fileName"; |
121
|
|
|
|
|
|
|
open(my $fh, '>>', $filename) or die "Could not open file '$filename' $!"; |
122
|
|
|
|
|
|
|
my $person = "\n".$datestring."\n".$process." ".$message."\n"; |
123
|
|
|
|
|
|
|
say $fh "$person\n"; |
124
|
|
|
|
|
|
|
close $fh; |
125
|
|
|
|
|
|
|
#say "done\n"; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; # this 1; is neccessary for our class to work |