Advertisement
punces

storeid.pl-170617

Jun 17th, 2017
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use IO::File;
  3. $|=1;
  4. STDOUT->autoflush(1);
  5. $debug=1; ## recommended:0
  6. $bypassallrules=0; ## recommended:0
  7. $sucks=""; ## unused
  8. $sucks="sucks" if ($debug>=1);
  9. $timenow="";
  10. $printtimenow=1; ## print timenow: 0|1
  11. my $logfile = '/var/log/squid/storeid.log';
  12.  
  13. open my $logfh, '>>', $logfile
  14. or die "Couldn't open $logfile for appending: $!\n" if $debug;
  15. $logfh->autoflush(1) if $debug;
  16. while (<>) {
  17. $timenow=time()." " if ($printtimenow);
  18. print $logfh "$timenow"."in : input=$_" if ($debug>=1);
  19. @X = split;
  20. if ($X[0] =~ m/^http.*/) {
  21. $url = $X[0];
  22. $referer = $X[1];
  23. $urlreferer = $X[0] ." ". $X[1];
  24. } else {
  25. $chanel = $X[0];
  26. $url = $X[1];
  27. $referer = $X[2];
  28. $urlreferer = $X[1] ." ". $X[2];
  29. }
  30.  
  31. if ($bypassallrules){
  32. $out="$url"; ## map 1:1
  33.  
  34. #youtube googlevideo
  35. } elsif ($url =~ m/^https?\:\/\/.*google.*video(playback|goodput).*/){
  36. @cpn = m/[=%&?\/]cpn[=%&?\/]([^\&\s]*)/;
  37. @id = m/[=%&?\/]id[=%&?\/]([^\&\s]*)/;
  38. @itag = m/[=%&?\/]itag[=%&?\/]([\d]*)/;
  39. @range = m/[=%&?\/]range[=%&?\/]([\d]*-[\d]*)/;
  40. @mime = m/[=%&?\/]mime[=%&?\/]([^\&\s]*)/;
  41. if ($referer =~ m/^https?\:\/\/(www|gaming)\.youtube.*\.com\/(watch\?v|embed|v)[=%&?\/]([^\&\s\?]*)/){
  42. @id = $3;
  43. } else {
  44. if (defined(@cpn[0])){
  45. if (-e "/var/log/squid/@cpn"){
  46. open FILE, "/var/log/squid/@cpn";
  47. @id = <FILE>;
  48. close FILE;
  49. }
  50. }
  51. }
  52. $out="OK store-id=http://squid/google/video/id=@id/itag=@itag/mime=@mime/range=@range";
  53.  
  54. #youtube parameter
  55. } elsif (
  56. ($url =~ m/^https?\:\/\/.*youtube.*(stream_204|watchtime|qoe|atr|csi_204|playback).*[=%&?\/]docid[=%&?\/]([^\&\s]*)/) ||
  57. ($url =~ m/^https?\:\/\/.*youtube.*(ptracking|set_awesome).*[=%&?\/]video_id[=%&?\/]([^\&\s]*)/) ||
  58. ($url =~ m/^https?\:\/\/.*youtube.*(player_204).*[=%&?\/]v[=%&?\/]([^\&\s]*)/)
  59. ){
  60. @id = $2;
  61. @cpn = m/[=%&?\/]cpn[=%&?\/]([^\&\s]*)/;
  62. if ($referer !~ m/^https?\:\/\/(www|gaming)\.youtube.*\.com\/(watch\?v|embed|v)[=%&?\/]([^\&\s\?]*)/){
  63. unless (-e "/var/log/squid/@cpn"){
  64. open FILE, ">/var/log/squid/@cpn";
  65. print FILE @id;
  66. close FILE;
  67. }
  68. }
  69. $out = "ERR";
  70.  
  71. #utmgif
  72. } elsif ($url =~ m/^https?\:\/\/www\.google-analytics\.com\/__utm\.gif\?.*/) {
  73. $out="OK store-id=http://squid/google-analytics/__utm.gif";
  74.  
  75. #fbcdn.net or akamaihd.net video range
  76. } elsif ($url =~ m/^https?\:\/\/.*(fbcdn\.net|akamaihd\.net).*\/([\w-]+\.[\w]{2,4}).*(bytestart[=%&?\/][\d]+[&\/]byteend[=%&?\/][\d]+)/) {
  77. $out="OK store-id=http://squid/$1/$2/$3";
  78.  
  79. #fbcdn.net or akamaihd.net with size
  80. } elsif ($url =~ m/^https?\:\/\/.*(fbcdn\.net|akamaihd\.net).*\/([a-zA-Z][\d]+[x][\d]+\/[\w-]+\.[\w]{2,4})($|\?)/) {
  81. $out="OK store-id=http://squid/$1/$2";
  82.  
  83. #fbcdn.net or akamaihd.net safe_image.php
  84. } elsif ($url =~ m/^https?\:\/\/.*(fbcdn\.net|akamaihd\.net).*\/safe_image\.php\?(.*)/) {
  85. $out="OK store-id=http://squid/$1/$2";
  86.  
  87. #reverbnation
  88. } elsif ($url =~ m/^https?\:\/\/c2lo\.reverbnation\.com\/audio_player\/ec_stream_song\/(.*)\?.*/) {
  89. $out="OK store-id=http://squid/reverbnation/$1";
  90.  
  91. #playstore
  92. } elsif ($url =~ m/^https?\:\/\/.*\.c\.android\.clients\.google\.com\/market\/GetBinary\/GetBinary\/(.*\/.*)\?.*/) {
  93. $out="OK store-id=http://squid/android/market/$1";
  94.  
  95.  
  96. #filehost
  97. } elsif ($url =~ m/^https?\:\/\/.*datafilehost.*\/get\.php.*file\=(.*)/) {
  98. $out="OK store-id=http://squid/datafilehost/$1";
  99.  
  100.  
  101. #speedtest
  102. #} elsif ($url =~ m/^https?\:\/\/.*([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|speedtest|espeed|api\.ookla).*\/(speedtest\.swf|speedtest-long\.swf|latency\.txt|upload\.php|speedtest-config\.php|ipaddress\.php|random.*\.jpg)/) {
  103. } elsif ($url =~ m/^https?\:\/\/.*([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|speedtest|espeed|api\.ookla).*\/(speedtest\.swf|speedtest-long\.swf)/) {
  104. $out="OK store-id=http://squid/speedtest/$2";
  105.  
  106.  
  107. #filehippo
  108. } elsif ($url =~ m/^https?\:\/\/.*\.filehippo\.com\/.*\/([\w-]+\.[\w]{2,4})\?.*/) {
  109. $out="OK store-id=http://squid/filehippo/$1";
  110.  
  111.  
  112. #4shared preview.mp3
  113. } elsif ($url =~ m/^https?\:\/\/.*\.4shared\.com\/.*\/(.*\/.*)\/dlink.*preview.mp3/) {
  114. $out="OK store-id=http://squid/4shared/preview/$1";
  115.  
  116. #4shared
  117. } elsif ($url =~ m/^https?\:\/\/.*\.4shared\.com\/download\/(.*\/.*)\?tsid.*/) {
  118. $out="OK store-id=http://squid/4shared/download/$1";
  119.  
  120. #savefile-animeindo.tv
  121. } elsif ($url =~ m/^https?:\/\/www\.savefile\.co\:[0-9]{2,5}\/.*\/(.*\.(mp4|flv|3gp)).*/) {
  122. $out="OK store-id=http://squid/savefile:182/$1";
  123.  
  124. #imdb
  125. } elsif ($url =~ m/^https?\:\/\/video\-http\.media\-imdb\.com\/(.*\.mp4)\?.*/) {
  126. $out="OK store-id=http://squid/imdb/$1";
  127.  
  128. #sourceforge
  129. } elsif ($url =~ m/^https?\:\/\/.*\.dl\.sourceforge\.net\/([\w-]+\.[\w]{2,3})/) {
  130. $out="OK store-id=http://squid/sourceforge/$1";
  131.  
  132. #steampowered dota 2
  133. } elsif ($url =~ m/^https?\:\/\/.*steam(powered|content).*\/((client|depot)\/.*\/(chunk|manifest)\/.*)\?.*/) {
  134. $out="OK store-id=http://squid/steam/$2";
  135.  
  136. #patch gemscool lsaga
  137. } elsif ($url =~ m/^https?\:\/\/(patch\.gemscool\.com\/lsaga.*\.iop.*)\?.*/) {
  138. $out="OK store-id=http://squid/$1";
  139.  
  140. #youtubeinmp3
  141. } elsif ($url =~ m/^https?:\/\/.*\youtubeinmp3\.com\/download\/get\/.*/) {
  142. @id = m/[=%&?\/]id[=%&?\/]([^\&\s]*)/;
  143. @t = m/[=%&?\/]t[=%&?\/]([^\&\s]*)/;
  144. $out="OK store-id=http://squid/youtubeinmp3/id=@id/t=@t";
  145.  
  146. #googleusercontent
  147. } elsif ($url =~ m/^https?\:\/.*\.(googleusercontent\.com\/.*\/[^\?\&\%\=\/\s]*)/) {
  148. $out="OK store-id=http://squid/$1";
  149.  
  150. #mp4upload
  151. } elsif ($url =~ m/^https?\:\/\/.*mp4upload\.com\:[0-9]{2,5}\/(.*\.[\w]{2,5})/) {
  152. @id = $1;
  153. if (
  154. ($referer =~ m/^https?\:\/\/.*mp4upload\.com\/embed-(.*)\.[\w]{2,4}/) ||
  155. ($referer =~ m/^https?\:\/\/.*mp4upload\.com\/(.*)/)
  156. )
  157. {@id = $1;}
  158. $out="OK store-id=http://squid/mp4upload/@id";
  159.  
  160. } else {
  161. $out="ERR";
  162. }
  163.  
  164. if ($X[0] =~ m/^http.*/) {
  165. print $logfh "$timenow"."in : chanel=$chanel referer=$referer\n" if ($debug>=1);
  166. print $logfh "$timenow"."in : url=$url\n" if ($debug>=1);
  167. print $logfh "$timenow"."out: $out\n" if ($debug>=1);
  168. print $logfh "\n" if ($debug>=1);
  169. print "$out\n";
  170. } else {
  171. print $logfh "$timenow"."in : chanel=$chanel referer=$referer\n" if ($debug>=1);
  172. print $logfh "$timenow"."in : url=$url\n" if ($debug>=1);
  173. print $logfh "$timenow"."out: $chanel $out\n" if ($debug>=1);
  174. print $logfh "\n" if ($debug>=1);
  175. print "$chanel $out\n";
  176. }
  177. }
  178. close $logfh if ($debug);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement