Advertisement
ujiajah1

srore-id.pl

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