Fixes
This commit is contained in:
parent
6ef1553a84
commit
b4463e7605
@ -22,7 +22,8 @@ sub decrypt {
|
|||||||
my ( $self, $base64 ) = @_;
|
my ( $self, $base64 ) = @_;
|
||||||
|
|
||||||
# Decrypt message
|
# Decrypt message
|
||||||
my $dec = `echo "$base64" | base64 -d`;
|
my $dec = decode_base64($base64);
|
||||||
|
# my $dec = `echo "$base64" | base64 -d`;
|
||||||
|
|
||||||
return $dec;
|
return $dec;
|
||||||
}
|
}
|
||||||
|
21
II/Get.pm
21
II/Get.pm
@ -36,6 +36,7 @@ sub get_echo {
|
|||||||
|
|
||||||
my $msgs;
|
my $msgs;
|
||||||
my $base64;
|
my $base64;
|
||||||
|
my @messages_hash;
|
||||||
foreach my $echo (@$echoareas) {
|
foreach my $echo (@$echoareas) {
|
||||||
|
|
||||||
# Get echo message hashes
|
# Get echo message hashes
|
||||||
@ -60,7 +61,7 @@ sub get_echo {
|
|||||||
|
|
||||||
# Write new echo message
|
# Write new echo message
|
||||||
$db->write_echo(%e_write);
|
$db->write_echo(%e_write);
|
||||||
|
$msgs .= $_ . "\n";
|
||||||
push( @new, $echo_hash );
|
push( @new, $echo_hash );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,12 +96,15 @@ sub get_echo {
|
|||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Populate $msgs and $base64
|
# Populate hash
|
||||||
while (<@msg_con>) {
|
while (<@msg_con>) {
|
||||||
my @message = split /:/, $_;
|
my @message = split /:/, $_;
|
||||||
if ( defined( $message[1] ) ) {
|
if ( defined( $message[1] ) ) {
|
||||||
$msgs .= $message[0] . "\n";
|
my $h = {
|
||||||
$base64 .= $message[1] . "\n";
|
hash => $message[0],
|
||||||
|
base64 => $message[1],
|
||||||
|
};
|
||||||
|
push( @messages_hash, $h );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,15 +112,15 @@ sub get_echo {
|
|||||||
my $new_messages
|
my $new_messages
|
||||||
= "<!DOCTYPE html><meta charset=utf8><body><h1>Новые сообщения</h1>\n";
|
= "<!DOCTYPE html><meta charset=utf8><body><h1>Новые сообщения</h1>\n";
|
||||||
if ( defined($msgs) ) {
|
if ( defined($msgs) ) {
|
||||||
my @msg_list = split /\n/, $base64;
|
|
||||||
|
|
||||||
# Begin transaction
|
# Begin transaction
|
||||||
print localtime() . ": writing messages\n";
|
print localtime() . ": writing messages\n";
|
||||||
$db->begin();
|
$db->begin();
|
||||||
while (<@msg_list>) {
|
|
||||||
my $mes_hash = $_;
|
|
||||||
|
|
||||||
my $text = II::Enc->decrypt($mes_hash);
|
my $c = 0;
|
||||||
|
while ( $c < @messages_hash ) {
|
||||||
|
my $mes_hash = $messages_hash[$c]->{hash};
|
||||||
|
my $text = II::Enc->decrypt( $messages_hash[$c]->{base64} );
|
||||||
|
|
||||||
open my $m, "<", \$text
|
open my $m, "<", \$text
|
||||||
or die "Cannot open message: $!\n";
|
or die "Cannot open message: $!\n";
|
||||||
@ -154,6 +158,7 @@ sub get_echo {
|
|||||||
|
|
||||||
# Write message to DB
|
# Write message to DB
|
||||||
$db->write(%data);
|
$db->write(%data);
|
||||||
|
$c++;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Commit transaction
|
# Commit transaction
|
||||||
|
11
II/Send.pm
11
II/Send.pm
@ -8,10 +8,12 @@ use Data::Dumper;
|
|||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
|
|
||||||
|
my $db = II::DB->new();
|
||||||
my $self = {
|
my $self = {
|
||||||
_config => shift,
|
_config => shift,
|
||||||
_echo => shift,
|
_echo => shift,
|
||||||
_base64 => shift,
|
_base64 => shift,
|
||||||
|
_db => $db,
|
||||||
};
|
};
|
||||||
|
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
@ -19,20 +21,21 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub send {
|
sub send {
|
||||||
my ($self, $hash) = @_;
|
my ( $self, $hash ) = @_;
|
||||||
my $config = $self->{_config};
|
my $config = $self->{_config};
|
||||||
my $echo = $self->{_echo};
|
my $echo = $self->{_echo};
|
||||||
my $base64 = $self->{_base64};
|
my $base64 = $self->{_base64};
|
||||||
|
my $db = $self->{_db};
|
||||||
|
|
||||||
# Push message to server
|
# Push message to server
|
||||||
my $host = $config->{host};
|
my $host = $config->{host};
|
||||||
my $auth = $config->{key};
|
my $auth = $config->{key};
|
||||||
$host .= "u/point";
|
$host .= "u/point";
|
||||||
my $ua = LWP::UserAgent->new();
|
my $ua = LWP::UserAgent->new();
|
||||||
my $response = $ua->post( $host, { 'pauth' => $auth, 'tmsg' => $base64 } );
|
my $response
|
||||||
|
= $ua->post( $host, { 'pauth' => $auth, 'tmsg' => $base64 } );
|
||||||
|
|
||||||
my $db = II::DB->new();
|
if ( $response->{_rc} == 200 ) {
|
||||||
if ($response->{_rc} == 200) {
|
|
||||||
$db->update_out($hash);
|
$db->update_out($hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user