From f82196013f6c1848cb5f607ac5654aa34c2c9612 Mon Sep 17 00:00:00 2001 From: "Difrex(Denis Zheleztsov)" Date: Mon, 16 Jun 2014 12:02:34 +0400 Subject: [PATCH] /u is working --- II/Enc.pm | 26 ++++++++++++++++++++++---- II/Get.pm | 24 +++++++++++++++--------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/II/Enc.pm b/II/Enc.pm index a6484f9..77e2065 100644 --- a/II/Enc.pm +++ b/II/Enc.pm @@ -18,6 +18,24 @@ sub new { return $self; } +sub decrypt { + my ( $self, $file ) = @_; + + open my $fh, "<", $file or die "Cannot open file $file: $!\n"; + my $message; + while (<$fh>) { + $message .= $_; + } + close $fh; + + my @enc = split /:/, $message; + + # Decrypt message + my $dec = `echo "$enc[1]" | base64 -d`; + + return $dec; +} + sub encode { my ($self) = @_; my $config = $self->{_config}; @@ -26,10 +44,10 @@ sub encode { my $hash = II::Enc->new_hash(); # Make base64 message - my $message = $data->{echo}."\n"; - $message .= $data->{to}."\n"; - $message .= $data->{subg}."\n\n"; - $message .= '@repto:'.$data->{hash}."\n" if defined($data->{hash}); + my $message = $data->{echo} . "\n"; + $message .= $data->{to} . "\n"; + $message .= $data->{subg} . "\n\n"; + $message .= '@repto:' . $data->{hash} . "\n" if defined( $data->{hash} ); $message .= $data->{post}; my $encoded = `echo "$message" | base64`; diff --git a/II/Get.pm b/II/Get.pm index c619b45..a1e1843 100644 --- a/II/Get.pm +++ b/II/Get.pm @@ -2,6 +2,7 @@ package II::Get; use LWP::Simple; use II::DB; +use II::Enc; use Data::Dumper; @@ -22,8 +23,8 @@ sub get_echo { my $db = II::DB->new(); - my $echo_url = 'e/'; - my $msg_url = 'm/'; + my $echo_url = 'u/e/'; + my $msg_url = 'u/m/'; my $msgs; foreach my $echo (@$echoareas) { @@ -43,12 +44,14 @@ sub get_echo { or die "Cannot open file: $!\n"; while (<$echo_fh>) { chomp($_); - if ( !( -e "./msg/$_" ) ) { - $msgs .= $_ . "\n"; - # @w_cmd = ( 'wget', '-O', - # "./msg/$_", "$host" . "$msg_url" . "$_" ); - `curl $host$msg_url$_ > ./msg/$_`; - # system(@w_cmd) == 0 or die "Cannot download file: $!\n"; + if ($_ =~ /.{20}/) { + if ( !( -e "./msg/$_" ) ) { + $msgs .= $_ . "\n"; + # @w_cmd = ( 'wget', '-O', + # "./msg/$_", "$host" . "$msg_url" . "$_" ); + `curl $host$msg_url$_ > ./msg/$_`; + # system(@w_cmd) == 0 or die "Cannot download file: $!\n"; + } } } close $echo_fh; @@ -62,7 +65,10 @@ sub get_echo { my @msg_list = split /\n/, $msgs; while (<@msg_list>) { my $mes_hash = $_; - open my $m, "<", "./msg/$mes_hash" + + my $text = II::Enc->decrypt("./msg/$mes_hash"); + + open my $m, "<", \$text or die "Cannot open message: $!\n"; my @mes;