Advertisement
albspirit86

squidconf-storeid

Dec 14th, 2014
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. # storeid *test*
  2. acl urlrewrite dstdomain .fbcdn.net .akamaihd.net
  3. acl speedtest url_regex -i speedtest\/.*\.(jpg|txt)\?.*
  4. acl reverbnation url_regex -i reverbnation.*audio_player.*ec_stream_song.*$
  5. acl utmgif url_regex -i utm.gif.*
  6. acl playstoreandroid url_regex -i c.android.clients.google.com.market.GetBinary.GetBinary.*
  7. acl idyoutube url_regex -i youtube.*(ptracking|stream_204|player_204).*(v\=|docid\=|video_id\=).*$
  8. acl videoyoutube url_regex -i (youtube|googlevideo).*videoplayback\?
  9. acl videoyoutube url_regex -i (youtube|googlevideo).*videoplayback\?
  10. acl loop_302 http_status 302
  11. acl getmethod method GET
  12.  
  13. store_id_program /usr/bin/perl /etc/squid/storeid
  14. store_id_children 20 startup=0 idle=1 concurrency=5
  15. store_id_access deny !getmethod
  16. store_id_access allow urlrewrite
  17. store_id_access allow speedtest
  18. store_id_access allow reverbnation
  19. store_id_access allow utmgif
  20. store_id_access allow playstoreandroid
  21. store_id_access allow idyoutube
  22. store_id_access allow videoyoutube
  23. store_id_access deny all
  24.  
  25. store_miss deny videoyoutube loop_302
  26. send_hit deny videoyoutube loop_302
  27.  
  28. refresh_pattern (akamaihd|fbcdn)\.net 14400 99% 518400 ignore-no-store ignore-private ignore-reload ignore-must-revalidate store-stale
  29. refresh_pattern -i squid\.internal 14400 99% 518400 ignore-no-store ignore-private ignore-reload ignore-must-revalidate store-stale
  30. refresh_pattern \.(jpg|png|gif|css|ico)($|\?) 14400 99% 518400 ignore-no-store ignore-private reload-into-ims ignore-must-revalidate store-stale
  31. refresh_pattern . 0 99% 518400 ignore-no-store ignore-private reload-into-ims store-stale
  32.  
  33.  
  34.  
  35. #storeid
  36. #!/usr/bin/perl
  37. #
  38. # storeid.pl with debug opt - based on storeurl.pl
  39. # @ http://www2.fh-lausitz.de/launic/comp/misc/squid/projekt_youtube/
  40. #
  41. # mods by cespun and fajar @ ipfire.id
  42. #
  43.  
  44. use IO::File;
  45. $|=1;
  46. STDOUT->autoflush(1);
  47. $debug=0; ## recommended:0
  48. $bypassallrules=0; ## recommended:0
  49. $sucks=""; ## unused
  50. $sucks="sucks" if ($debug>=1);
  51. $timenow="";
  52. $printtimenow=1; ## print timenow: 0|1
  53. my $logfile = '/tmp/storeid.log';
  54.  
  55. open my $logfh, '>>', $logfile
  56. or die "Couldn't open $logfile for appending: $!\n" if $debug;
  57. $logfh->autoflush(1) if $debug;
  58.  
  59. while (<>) {
  60. $timenow=time()." " if ($printtimenow);
  61. print $logfh "$timenow"."in : $_" if ($debug>=1);
  62. chop;
  63. my $myURL = $_;
  64. @X = split(" ",$myURL);
  65. $a = $X[0]; ## channel id
  66. $b = $X[1]; ## url
  67. $c = $X[2]; ## ip address
  68. $u = $b; ## url
  69.  
  70. if ($bypassallrules){
  71. $out="$u"; ## map 1:1
  72.  
  73. } elsif ($u=~ m/http.*\.(fbcdn|akamaihd)\.net\/h(profile|photos).*[\d\w].*\/([\w]\d+x\d+\/.*\.[\d\w]{3}).*/) {
  74. $out="OK store-id=http://fbcdn.net.squid.internal/" . $2 . "/" . $3 ;
  75.  
  76. } elsif ($u=~ m/^http(.*)static(.*)(akamaihd|fbcdn).net\/rsrc.php\/(.*\/.*\/(.*).(js|css|png|gif))(\?(.*)|$)/) {
  77. $out="OK store-id=http://fbcdn.net.squid.internal/static/" . $5 . "." . $6 ;
  78.  
  79. } elsif ($u=~ m/^https?\:\/\/.*utm.gif.*/) {
  80. $out="OK store-id=http://google-analytics.squid.internal/__utm.gif";
  81.  
  82. } elsif ($u=~ m/^https?\:\/\/.*\/speedtest\/(.*\.(jpg|txt)).*/) {
  83. $out="OK store-id=http://speedtest.squid.internal/" . $1;
  84.  
  85. } elsif ($u=~ m/^https?\:\/\/.*\/(.*\..*(mp4|3gp|flv))\?.*/) {
  86. $out="OK store-id=http://video-file.squid.internal/" . $1;
  87.  
  88. } elsif ($u=~ m/^https?\:\/\/c2lo\.reverbnation\.com\/audio_player\/ec_stream_song\/(.*)\?.*/) {
  89. $out="OK store-id=http://reverbnation.squid.internal/" . $1;
  90.  
  91. } elsif ($u=~ m/^https?\:\/\/.*\.c\.android\.clients\.google\.com\/market\/GetBinary\/GetBinary\/(.*\/.*)\?.*/) {
  92. $out="OK store-id=http://playstore-android.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