Advertisement
Guest User

kareharedis

a guest
Apr 10th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.79 KB | None | 0 0
  1. ######## load your kareha logs into redis with this script in the kareha folder (where your log file is)
  2.  
  3. #!/usr/bin/perl
  4.  
  5. use Redis;
  6. use strict;
  7.  
  8. BEGIN { require 'config.pl'; }
  9.  
  10. my $redis = Redis->new(sock => '/tmp/redis.sock');
  11.  
  12. my $file = "log.txt";
  13. open(LOGFILE, $file) or die("nope");
  14.  
  15. my @lines = reverse <LOGFILE>;
  16.  
  17. foreach my $line (@lines)
  18. {
  19. chomp($line);
  20. my @data=split(/\s*,\s*/, $line);
  21.  
  22. $redis->set( TITLE . ":$data[5]" => "$data[0],$data[1],$data[6]");
  23. }
  24.  
  25. close $file;
  26.  
  27. ######## make these changes to kareha
  28.  
  29. ######import the module
  30. use Redis;
  31.  
  32. ######establish redis connection
  33. my $redis = Redis->new(sock => '/tmp/redis.sock');
  34.  
  35. if($md5) # if we managed to generate an md5 checksum, check for duplicate files
  36. {
  37.         ######remove $log from find_md5
  38.         my ($thread,$post)=find_md5($md5);
  39.         if($thread)
  40.         {
  41.                 unlink $filename; # make sure to remove the file
  42.                 make_error(sprintf S_DUPE,"$path\kareha.pl/$thread/$post");
  43.         }
  44. }
  45.  
  46.  
  47. sub add_log($$$$$$$)
  48. {
  49.         my ($log,$thread,$post,$password,$ip,$key,$md5,$file)=@_;
  50.  
  51.         ######add this
  52.         $redis->set( TITLE . ":$md5" => "$thread,$post,$file");
  53.  
  54.         $password=encrypt_string(hide_password($password),"cryptpass");
  55.         $ip=encrypt_string($ip,"ip");
  56.  
  57.         unshift @$log,"$thread,$post,$password,$ip,$key,$md5,$file";
  58. }
  59.  
  60.  
  61.  
  62. ######switch out find_md5 with this
  63. sub find_md5($)
  64. {
  65.         my ($md5)=@_;
  66.        
  67.         my $keycheck = $redis->keys( TITLE . ":$md5" );
  68.        
  69.         if ($keycheck)
  70.         {
  71.                 my $getkey = $redis->get( TITLE . ":$md5" );      
  72.                 my @data=split(/\s*,\s*/, $getkey);        
  73.                 return ($data[0],$data[1]) if(-e $data[2]);
  74.         }
  75.         return ();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement