Advertisement
ujiajah1

store-id.pl squid4

Feb 25th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 5.06 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # storeid.pl with debug opt - based on storeurl.pl
  3. # @ http://www2.fh-lausitz.de/
  4.  
  5. use IO::File;
  6. $|=1;
  7. STDOUT->autoflush(1);
  8. $debug=0;           ## recommended:0
  9. $bypassallrules=0;      ## recommended:0
  10. $sucks="";          ## unused
  11. $sucks="sucks" if ($debug>=1);
  12. $timenow="";
  13. $printtimenow=1;        ## print timenow: 0|1
  14. my $logfile = '/tmp/storeid.log';
  15.  
  16. open my $logfh, '>>', $logfile
  17.     or die "Couldn't open $logfile for appending: $!\n" if $debug;
  18. $logfh->autoflush(1) if $debug;
  19.  
  20. while (<>) {
  21. $timenow=time()." " if ($printtimenow);
  22. print $logfh "$timenow"."in : $_" if ($debug>=1);
  23. chop;
  24. my $myURL = $_;
  25. @X = split(" ",$myURL);
  26. $a = $X[0]; ## channel id
  27. $b = $X[1]; ## url
  28. $c = $X[2]; ## ip address
  29. $u = $b; ## url
  30.  
  31. if ($bypassallrules){
  32.  $out="$u"; ## map 1:1
  33.  
  34. } elsif ($u=~ m/^https?\:\/\/.*youtube.*ptracking.*/){
  35.     @video_id = m/[&?]video_id\=([^\&\s]*)/;
  36.     @cpn = m/[&?]cpn\=([^\&\s]*)/;
  37.     unless (-e "/tmp/@cpn"){
  38.     open FILE, ">/tmp/@cpn";
  39.     print FILE "@video_id";
  40.     close FILE;
  41.     }
  42.     $out="ERR";
  43.  
  44. } elsif ($u=~ m/^https?\:\/\/.*youtube.*stream_204.*/){
  45.     @docid = m/[&?]docid\=([^\&\s]*)/;
  46.     @cpn = m/[&?]cpn\=([^\&\s]*)/;
  47.     unless (-e "/tmp/@cpn"){
  48.     open FILE, ">/tmp/@cpn";
  49.     print FILE "@docid";
  50.     close FILE;
  51.     }
  52.     $out="ERR";
  53.  
  54. } elsif ($u=~ m/^https?\:\/\/.*youtube.*player_204.*/){
  55.     @v = m/[&?]v\=([^\&\s]*)/;
  56.     @cpn = m/[&?]cpn\=([^\&\s]*)/;
  57.     unless (-e "/tmp/@cpn"){
  58.     open FILE, ">/tmp/@cpn";
  59.     print FILE "@v";
  60.     close FILE;
  61.     }
  62.     $out="ERR";
  63.  
  64. } elsif ($u=~ m/^https?\:\/\/.*(youtube|googlevideo).*videoplayback.*/){
  65.     @itag = m/[&?](itag\=[0-9]*)/;
  66.     @range = m/[&?](range\=[^\&\s]*)/;
  67.     @cpn = m/[&?]cpn\=([^\&\s]*)/;
  68.     @mime = m/[&?](mime\=[^\&\s]*)/;
  69.     @id = m/[&?]id\=([^\&\s]*)/;
  70.  
  71.     if (defined(@cpn[0])){
  72.         if (-e "/tmp/@cpn"){
  73.         open FILE, "/tmp/@cpn";
  74.         @id = <FILE>;
  75.         close FILE;}
  76.     }
  77.     $out="OK store-id=http://video-srv.squid.internal/id=@id@mime@range";
  78.  
  79. } elsif ($u =~ m/^https?\:\/\/video\-http\.media\-imdb\.com\/(.*\.mp4)\?.*/) {
  80.         $out="OK store-id=http://imdb.squid.internal/" . $1;
  81.  
  82. } elsif ($u =~ m/^https?:\/\/www\.savefile\.co\:182\/.*\/(.*\.(mp4|flv|3gp)).*/) {
  83.         $out="OK store-id=http://animenindo.squid.internal/" . $1;
  84.  
  85. } elsif ($u=~ m/http.*\.(fbcdn|akamaihd)\.net\/h(profile|photos).*[\d\w].*\/([\w]\d+x\d+\/.*\.[\d\w]{3}).*/) {
  86.     $out="OK store-id=http://fbcdn.net.squid.internal/" . $2 . "/" . $3 ;
  87.  
  88. } elsif ($u=~ m/^http(.*)static(.*)(akamaihd|fbcdn).net\/rsrc.php\/(.*\/.*\/(.*).(js|css|png|gif))(\?(.*)|$)/) {
  89.     $out="OK store-id=http://fbcdn.net.squid.internal/static/" . $5 . "." . $6 ;
  90.  
  91. } elsif ($u=~ m/^https?\:\/\/.*utm.gif.*/) {
  92.     $out="OK store-id=http://google-analytics.squid.internal/__utm.gif";
  93.  
  94. } elsif ($u=~ m/^https?\:\/\/.*\/speedtest\/(.*\.(jpg|txt)).*/) {
  95.     $out="OK store-id=http://speedtest.squid.internal/" . $1;
  96.  
  97. } elsif ($u=~ m/^https?\:\/\/.*\/(.*\..*(mp4|3gp|flv))\?.*/) {
  98.     $out="OK store-id=http://video-file.squid.internal/" . $1;
  99.  
  100. } elsif ($u=~ m/^https?\:\/\/c2lo\.reverbnation\.com\/audio_player\/ec_stream_song\/(.*)\?.*/) {
  101.     $out="OK store-id=http://reverbnation.squid.internal/" . $1;
  102.  
  103. } elsif ($u=~ m/^https?\:\/\/.*\.c\.android\.clients\.google\.com\/market\/GetBinary\/GetBinary\/(.*\/.*)\?.*/) {
  104.     $out="OK store-id=http://playstore-android.squid.internal/" . $1;
  105.  
  106. } elsif ($u =~ m/^http:\/\/([a-z])[0-9]?(\.gstatic\.com.*|\.wikimapia\.org.*)/) {
  107.     $out="OK store-id=http://gstatic.squid.internal/" . $2;
  108.  
  109. } elsif ($u =~ m/^https?:\/\/.*(googleusercontent.com|blogspot.com)\/(.*)\/([a-z0-9]+)(-[a-z]-[a-z]-[a-z]+)?\/(.*\.(jpg|png))/){
  110.     $out="OK store-id=http://googleusercontent.squid.internal/" . $5;
  111.  
  112. } elsif ($_ =~ m/^https?:\/\/([a-z0-9.]*)(\.doubleclick\.net|\.quantserve\.com|.exoclick\.com|interclick.\com|\.googlesyndication\.com|\.auditude\.com|.visiblemeasures\.com|yieldmanager|cpxinteractive)(.*)/){
  113.     $out="OK store-id=http://ads.squid.internal/" . $3;
  114.  
  115. } elsif ($url=~ m/^https?\:\/\/.*\.4shared\.com\/.*\/(.*\/.*)\/dlink.*preview.mp3/) {
  116.         $out="OK store-id=http://4shared.squid.internal/preview/" . $1;
  117.  
  118. } elsif ($u=~ m/^https?\:\/\/.*\.4shared\.com\/download\/(.*)\/.*/) {
  119.     $out="OK store-id=http://4shared.squid.internal/download/" . $1;
  120.  
  121. } elsif ($u =~ m/^http:\/\/(www\.ziddu\.com.*\.[^\/]{3,4})\/(.*?)/) {
  122.     $out="OK store-id=http://ziddu.squid.internal/" . $1;
  123.  
  124. } elsif ($u =~ m/^http:\/\/(.*?)\.yimg\.com\/(.*?)\.yimg\.com\/(.*?)\?(.*)/) {
  125.     $out="OK store-id=http://cdn.yimg.squid.internal/" . $3;
  126.  
  127. } elsif (($u =~ /filehippo/) && (m/^https?:\/\/(.*?)\.(.*?)\/(.*?)\/(.*)\.([a-z0-9]{3,4})(\?.*)?/)) {
  128.     @y = ($1,$2,$4,$5); $y[0] =~ s/[a-z0-9]{2,5}/cdn./;
  129.     $out="OK store-id=http://filehippo.squid.internal/" . $3;
  130.    
  131. } elsif ($u[1] =~ m/^http:\/\/.*dlink__[23]Fdownload_[23]F([\w\d-]+)_3Ftsid.*/) {
  132.     $1 =~ s/_5F/_/g;
  133.     $out="OK store-id=http://4shared.squid.internal/" . $1;
  134.  
  135. } else {
  136.     $out="ERR";
  137. }
  138.     print $logfh "$timenow"."out: $a $out\n" if ($debug>=1);
  139.     print "$a $out\n";
  140. }
  141. close $logfh if ($debug);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement