Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use IO::File;
- $|=1;
- STDOUT->autoflush(1);
- $debug=1; ## recommended:0
- $bypassallrules=0; ## recommended:0
- $sucks=""; ## unused
- $sucks="sucks" if ($debug>=1);
- $timenow="";
- $printtimenow=1; ## print timenow: 0|1
- my $logfile = '/var/log/squid/storeid.log';
- open my $logfh, '>>', $logfile
- or die "Couldn't open $logfile for appending: $!\n" if $debug;
- $logfh->autoflush(1) if $debug;
- while (<>) {
- $timenow=time()." " if ($printtimenow);
- print $logfh "$timenow"."in : input=$_" if ($debug>=1);
- @X = split;
- if ($X[0] =~ m/^http.*/) {
- $url = $X[0];
- $referer = $X[1];
- $urlreferer = $X[0] ." ". $X[1];
- } else {
- $chanel = $X[0];
- $url = $X[1];
- $referer = $X[2];
- $urlreferer = $X[1] ." ". $X[2];
- }
- if ($bypassallrules){
- $out="$url"; ## map 1:1
- #youtube googlevideo
- } elsif ($url =~ m/^https?\:\/\/.*google.*video(playback|goodput).*/){
- @cpn = m/[=%&?\/]cpn[=%&?\/]([^\&\s]*)/;
- @id = m/[=%&?\/]id[=%&?\/]([^\&\s]*)/;
- @itag = m/[=%&?\/]itag[=%&?\/]([\d]*)/;
- @range = m/[=%&?\/]range[=%&?\/]([\d]*-[\d]*)/;
- @mime = m/[=%&?\/]mime[=%&?\/]([^\&\s]*)/;
- if ($referer =~ m/^https?\:\/\/(www|gaming)\.youtube.*\.com\/(watch\?v|embed|v)[=%&?\/]([^\&\s\?]*)/){
- @id = $3;
- } else {
- if (defined(@cpn[0])){
- if (-e "/var/log/squid/@cpn"){
- open FILE, "/var/log/squid/@cpn";
- @id = <FILE>;
- close FILE;
- }
- }
- }
- $out="OK store-id=http://squid/google/video/id=@id/itag=@itag/mime=@mime/range=@range";
- #youtube parameter
- } elsif (
- ($url =~ m/^https?\:\/\/.*youtube.*(stream_204|watchtime|qoe|atr|csi_204|playback).*[=%&?\/]docid[=%&?\/]([^\&\s]*)/) ||
- ($url =~ m/^https?\:\/\/.*youtube.*(ptracking|set_awesome).*[=%&?\/]video_id[=%&?\/]([^\&\s]*)/) ||
- ($url =~ m/^https?\:\/\/.*youtube.*(player_204).*[=%&?\/]v[=%&?\/]([^\&\s]*)/)
- ){
- @id = $2;
- @cpn = m/[=%&?\/]cpn[=%&?\/]([^\&\s]*)/;
- if ($referer !~ m/^https?\:\/\/(www|gaming)\.youtube.*\.com\/(watch\?v|embed|v)[=%&?\/]([^\&\s\?]*)/){
- unless (-e "/var/log/squid/@cpn"){
- open FILE, ">/var/log/squid/@cpn";
- print FILE @id;
- close FILE;
- }
- }
- $out = "ERR";
- if ($X[0] =~ m/^http.*/) {
- print $logfh "$timenow"."in : chanel=$chanel referer=$referer\n" if ($debug>=1);
- print $logfh "$timenow"."in : url=$url\n" if ($debug>=1);
- print $logfh "$timenow"."out: $out\n" if ($debug>=1);
- print $logfh "\n" if ($debug>=1);
- print "$out\n";
- } else {
- print $logfh "$timenow"."in : chanel=$chanel referer=$referer\n" if ($debug>=1);
- print $logfh "$timenow"."in : url=$url\n" if ($debug>=1);
- print $logfh "$timenow"."out: $chanel $out\n" if ($debug>=1);
- print $logfh "\n" if ($debug>=1);
- print "$chanel $out\n";
- }
- }
- close $logfh if ($debug);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement