Advertisement
Guest User

r.sine.com

a guest
May 30th, 2015
2,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.54 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4.  
  5. use File::Type;
  6. use File::stat qw(:FIELDS);
  7. use CGI qw/:standard/;
  8.  
  9. my $base = "/sites/r.sine.com";
  10. my @pictures;
  11. my $period = time() - 604800 ; # new equals the last two weeks
  12.  
  13. my @seenPics = cookie('seen'); my $seen;
  14. my $q=new CGI;
  15.  
  16. opendir DIR, "$base"; my $file;
  17.  
  18. while ( defined ($file = readdir DIR) ) { unless ($file =~ /^\./) {
  19.  
  20.     my $show++ if ($file =~ /\.(jpg|jpeg|gif|png)$/);
  21.     my $step;
  22.     while ( !$seen and ($step <= scalar(@seenPics)) ) {
  23.         $seen++ if $file eq $seenPics[$step];
  24.         $step++;
  25.     }
  26.     undef $step;
  27.    
  28.     if ($q->param('new')) {
  29.         my $st = stat("$base/$file");
  30.         push @pictures, $file
  31.         if ( $st_ctime ge $period and $show and !$seen ) ;
  32.        
  33.     } else {
  34.         push @pictures, $file if $show and !$seen ; }
  35.        
  36.     undef $show; undef $seen;
  37.     undef $file;
  38.    
  39. } } closedir DIR;
  40.  
  41.  
  42. srand();
  43. my $this = $pictures[int(rand(scalar(@pictures)))];
  44. push @seenPics, $this if !$seen;
  45.  
  46. open HISTORY, ">> $base/HISTORY";
  47. print HISTORY "$ENV{REMOTE_ADDR}\t$this\n";
  48. close HISTORY;
  49.  
  50. my $ft = File::Type->new();
  51. my $type = $ft->mime_type("$base/$this");
  52.  
  53. my $c = cookie(-name    =>  'seen',
  54.             -value   =>  \@seenPics,
  55.             -domain  =>  'r.sine.com',
  56.             );
  57. print "Set-Cookie: ",$c->as_string,"\n";
  58.  
  59. if ($q->param('html')) {
  60.     print header();
  61.     print "<body><img src=\"$this\"></body><p>http://r.sine.com/$this</p>";
  62. } else {
  63.  
  64.     print header(-type => "$type");
  65.     open FILE, "$base/$this";
  66.     foreach (<FILE>) { print $_; }
  67.     close FILE;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement