Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 297
- Log:
Updated to AWStats 7.0.
- Author:
- rool
- Date:
- Fri Mar 18 13:33:29 +0000 2011
- Size:
- 7122 Bytes
- Properties:
- Property svn:executable is set
1 | #!/bin/perl |
2 | #------------------------------------------------------- |
3 | # Save the click done on managed hits into a trace file |
4 | # and return to browser a redirector to tell browser to visit this URL. |
5 | # Ex: <a href="http://athena/cgi-bin/awredir/awredir.pl?tag=TAGFORLOG&key=ABCDEFGH&url=http://212.43.217.240/%7Eforumgp/forum/list.php3?f=11">XXX</a> |
6 | # Where ABCDEFGH is md5(YOURKEYFORMD5.url) |
7 | #------------------------------------------------------- |
8 | |
9 | #use DBD::mysql; |
10 | use Digest::MD5 qw(md5 md5_hex md5_base64); |
11 | |
12 | |
13 | #------------------------------------------------------- |
14 | # Defines |
15 | #------------------------------------------------------- |
16 | use vars qw/ $REVISION $VERSION /; |
17 | $REVISION='$Revision: 1.12 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1; |
18 | $VERSION="1.2 (build $REVISION)"; |
19 | |
20 | use vars qw / $DIR $PROG $Extension $DEBUG $DEBUGFILE $REPLOG $DEBUGRESET $SITE $REPCONF /; |
21 | ($DIR=$0) =~ s/([^\/\\]*)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1; |
22 | $DEBUG=0; # Debug level |
23 | $DEBUGFILE="$PROG.log"; # Debug output (A log file name or "screen" to have debug on screen) |
24 | $REPLOG="$DIR"; # Debug directory |
25 | |
26 | $TRACEBASE=0; # Set to 1 to track click on links that point to extern site into a database |
27 | $TRACEFILE=0; # Set to 1 to track click on links that point to extern site into a file |
28 | $TXTDIR="$DIR/../../../logs"; # Directory where to write tracking file (if TRACEFILE=1) |
29 | $TXTFILE="awredir.trc"; # Tracking file (if TRACEFILE=1) |
30 | $EXCLUDEIP="127.0.0.1"; |
31 | |
32 | # Put here a personalised value. |
33 | # If you dont want to use the security key in link to avoid use of awredir by an external web |
34 | # site you can set this to empty string, but warning this is a security hole as everybody |
35 | # can use awredir on your site to redirect to any web site (even non legal web sites). |
36 | $KEYFORMD5='YOURKEYFORMD5'; |
37 | |
38 | #------------------------------------------------------- |
39 | # Functions |
40 | #------------------------------------------------------- |
41 | |
42 | sub error { |
43 | print "Content-type: text/html; charset=iso-8859-1\n"; |
44 | print "\n"; |
45 | print "<html>\n"; |
46 | print "<head>\n"; |
47 | print "</head>\n"; |
48 | print "\n"; |
49 | print "<body>\n"; |
50 | print "<center><br>\n"; |
51 | print "<font size=2><b>AWRedir</b></font><br>\n\n"; |
52 | print "<font color=#880000>$_[0].</font><br><br>\n"; |
53 | print "Setup (setup or logfile permissions) may be wrong.\n"; |
54 | $date=localtime(); |
55 | print "<CENTER><br><font size=1>$date - <b>Advanced Web Redirector $VERSION</b><br>\n"; |
56 | print "<br>\n"; |
57 | print "</body>"; |
58 | print "</html>"; |
59 | die; |
60 | } |
61 | |
62 | #------------------------------------------------------------------------------ |
63 | # Function: Decode an URL encoded string |
64 | # Parameters: stringtodecode |
65 | # Input: None |
66 | # Output: None |
67 | # Return: decodedstring |
68 | #-------------------------------------------------------------------- |
69 | sub DecodeEncodedString { |
70 | my $stringtodecode=shift; |
71 | $stringtodecode =~ s/\+/ /g; |
72 | $stringtodecode =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Decode encoded URL |
73 | return $stringtodecode; |
74 | } |
75 | |
76 | |
77 | #------------------------------------------------------- |
78 | # MAIN |
79 | #------------------------------------------------------- |
80 | |
81 | if ($DEBUG) { |
82 | open(LOGFILE,">$REPLOG/$PROG.log"); |
83 | print LOGFILE "----- $PROG $VERSION -----\n"; |
84 | } |
85 | |
86 | if (! $ENV{'GATEWAY_INTERFACE'}) { # Run from command line |
87 | print "----- $PROG $VERSION (c) Laurent Destailleur -----\n"; |
88 | print "This script is absolutely not required to use AWStats.\n"; |
89 | print "It's a third tool that can help webmaster in their tracking tasks but is\n"; |
90 | print "not used by AWStats engine.\n"; |
91 | print "\n"; |
92 | print "This tools must be used as a CGI script. When called as a CGI, it returns to\n"; |
93 | print "browser a redirector to tell it to show the page provided in 'url' parameter.\n"; |
94 | print "So, to use this script, you must replace HTML code for external links onto your\n"; |
95 | print "HTML pages from\n"; |
96 | print "<a href=\"http://externalsite/pagelinked\">Link</a>\n"; |
97 | print "to\n"; |
98 | print "<a href=\"http://mysite/cgi-bin/awredir.pl?key=ABCDEFGH&url=http://externalsite/pagelinked\">Link</a>\n"; |
99 | print "\n"; |
100 | print "For your web visitor, there is no difference. However this allow you to track\n"; |
101 | print "clicks done on links onto your web pages that point to external web sites,\n"; |
102 | print "because an entry will be seen in your own server log, to awredir.pl script\n"; |
103 | print "with url parameter, even if link was pointing to another external web server.\n"; |
104 | print "\n"; |
105 | sleep 2; |
106 | exit 0; |
107 | } |
108 | |
109 | if ($KEYFORMD5 eq 'YOURKEYFORMD5') { |
110 | error("Error: You must change value of constant KEYFORMD5 in awredir.pl script."); |
111 | } |
112 | |
113 | # Extract tag |
114 | $Tag='NOTAG'; |
115 | if ($ENV{QUERY_STRING} =~ /tag=\"?([^\"&]+)\"?/) { $Tag=$1; } |
116 | |
117 | $Key='NOKEY'; |
118 | if ($ENV{QUERY_STRING} =~ /key=\"?([^\"&]+)\"?/) { $Key=$1; } |
119 | |
120 | # Extract url to redirect to |
121 | $Url=$ENV{QUERY_STRING}; |
122 | if ($Url =~ /url=\"([^\"]+)\"/) { $Url=$1; } |
123 | elsif ($Url =~ /url=(.+)$/) { $Url=$1; } |
124 | $Url = DecodeEncodedString($Url); |
125 | $UrlParam=$Url; |
126 | |
127 | if (! $UrlParam) { |
128 | error("Error: Bad use of $PROG. To redirect an URL with $PROG, use the following syntax:<br><i>/cgi-bin/$PROG.pl?url=http://urltogo</i>"); |
129 | } |
130 | |
131 | if ($Url !~ /^http/i) { $Url = "http://".$Url; } |
132 | if ($DEBUG) { print LOGFILE "Url=$Url\n"; } |
133 | |
134 | if ($KEYFORMD5 && ($Key ne md5_hex($KEYFORMD5.$UrlParam))) { |
135 | # error("Error: Bad value for parameter key=".$Key." to allow a redirect to ".$UrlParam." - ".$KEYFORMD5." - ".md5_hex($KEYFORMD5.$UrlParam) ); |
136 | error("Error: Bad value for parameter key=".$Key." to allow a redirect to ".$UrlParam.". Key must be hexadecimal md5(KEYFORMD5.".$UrlParam.") where KEYFORMD5 is value hardcoded into awredir.pl. Note: You can remove use of key by setting KEYFORMD5 to empty string in script awredir.pl"); |
137 | } |
138 | |
139 | |
140 | # Get date |
141 | ($nowsec,$nowmin,$nowhour,$nowday,$nowmonth,$nowyear,$nowwday,$nowyday,$nowisdst) = localtime(time); |
142 | if ($nowyear < 100) { $nowyear+=2000; } else { $nowyear+=1900; } |
143 | $nowsmallyear=$nowyear;$nowsmallyear =~ s/^..//; |
144 | if (++$nowmonth < 10) { $nowmonth = "0$nowmonth"; } |
145 | if ($nowday < 10) { $nowday = "0$nowday"; } |
146 | if ($nowhour < 10) { $nowhour = "0$nowhour"; } |
147 | if ($nowmin < 10) { $nowmin = "0$nowmin"; } |
148 | if ($nowsec < 10) { $nowsec = "0$nowsec"; } |
149 | |
150 | if ($TRACEBASE == 1) { |
151 | if ($ENV{REMOTE_ADDR} !~ /$EXCLUDEIP/) { |
152 | if ($DEBUG == 1) { print LOGFILE "Execution requete Update sur BASE=$BASE, USER=$USER, PASS=$PASS\n"; } |
153 | my $dbh = DBI->connect("DBI:mysql:$BASE", $USER, $PASS) || die "Can't connect to DBI:mysql:$BASE: $dbh->errstr\n"; |
154 | my $sth = $dbh->prepare("UPDATE T_LINKS set HITS_LINKS = HIT_LINKS+1 where URL_LINKS = '$Url'"); |
155 | $sth->execute || error("Error: Unable execute query:$dbh->err, $dbh->errstr"); |
156 | $sth->finish; |
157 | $dbh->disconnect; |
158 | if ($DEBUG == 1) { print LOGFILE "Execution requete Update - OK\n"; } |
159 | } |
160 | } |
161 | |
162 | if ($TRACEFILE == 1) { |
163 | if ($ENV{REMOTE_ADDR} !~ /$EXCLUDEIP/) { |
164 | open(FICHIER,">>$TXTDIR/$TXTFILE") || error("Error: Enable to open trace file $TXTDIR/$TXTFILE: $!"); |
165 | print FICHIER "$nowyear-$nowmonth-$nowday $nowhour:$nowmin:$nowsec\t$ENV{REMOTE_ADDR}\t$Tag\t$Url\n"; |
166 | close(FICHIER); |
167 | } |
168 | } |
169 | |
170 | # Redir html instructions |
171 | print "Location: $Url\n\n"; |
172 | |
173 | if ($DEBUG) { |
174 | print LOGFILE "Redirect to $Url\n"; |
175 | close(LOGFILE); |
176 | } |
177 | |
178 | 0; |