Advertisement
ujiajah1

store-id

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