Advertisement
d3v1lg0

store-id.pl

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