/u is working

This commit is contained in:
Difrex(Denis Zheleztsov) 2014-06-16 12:02:34 +04:00
parent 7dc08d0742
commit f82196013f
2 changed files with 37 additions and 13 deletions

View File

@ -18,6 +18,24 @@ sub new {
return $self; 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 { sub encode {
my ($self) = @_; my ($self) = @_;
my $config = $self->{_config}; my $config = $self->{_config};
@ -26,10 +44,10 @@ sub encode {
my $hash = II::Enc->new_hash(); my $hash = II::Enc->new_hash();
# Make base64 message # Make base64 message
my $message = $data->{echo}."\n"; my $message = $data->{echo} . "\n";
$message .= $data->{to}."\n"; $message .= $data->{to} . "\n";
$message .= $data->{subg}."\n\n"; $message .= $data->{subg} . "\n\n";
$message .= '@repto:'.$data->{hash}."\n" if defined($data->{hash}); $message .= '@repto:' . $data->{hash} . "\n" if defined( $data->{hash} );
$message .= $data->{post}; $message .= $data->{post};
my $encoded = `echo "$message" | base64`; my $encoded = `echo "$message" | base64`;

View File

@ -2,6 +2,7 @@ package II::Get;
use LWP::Simple; use LWP::Simple;
use II::DB; use II::DB;
use II::Enc;
use Data::Dumper; use Data::Dumper;
@ -22,8 +23,8 @@ sub get_echo {
my $db = II::DB->new(); my $db = II::DB->new();
my $echo_url = 'e/'; my $echo_url = 'u/e/';
my $msg_url = 'm/'; my $msg_url = 'u/m/';
my $msgs; my $msgs;
foreach my $echo (@$echoareas) { foreach my $echo (@$echoareas) {
@ -43,12 +44,14 @@ sub get_echo {
or die "Cannot open file: $!\n"; or die "Cannot open file: $!\n";
while (<$echo_fh>) { while (<$echo_fh>) {
chomp($_); chomp($_);
if ( !( -e "./msg/$_" ) ) { if ($_ =~ /.{20}/) {
$msgs .= $_ . "\n"; if ( !( -e "./msg/$_" ) ) {
# @w_cmd = ( 'wget', '-O', $msgs .= $_ . "\n";
# "./msg/$_", "$host" . "$msg_url" . "$_" ); # @w_cmd = ( 'wget', '-O',
`curl $host$msg_url$_ > ./msg/$_`; # "./msg/$_", "$host" . "$msg_url" . "$_" );
# system(@w_cmd) == 0 or die "Cannot download file: $!\n"; `curl $host$msg_url$_ > ./msg/$_`;
# system(@w_cmd) == 0 or die "Cannot download file: $!\n";
}
} }
} }
close $echo_fh; close $echo_fh;
@ -62,7 +65,10 @@ sub get_echo {
my @msg_list = split /\n/, $msgs; my @msg_list = split /\n/, $msgs;
while (<@msg_list>) { while (<@msg_list>) {
my $mes_hash = $_; 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"; or die "Cannot open message: $!\n";
my @mes; my @mes;