From: eldy <>
Date: Tue, 19 Nov 2002 22:12:46 +0000 (+0000)
Subject: Added urlalias plugin.
X-Git-Tag: AWSTATS_5_2_RELEASE~14
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64c12eb746ce888f8f356c05e0a333ebfca7ece9;p=thirdparty%2FAWStats.git
Added urlalias plugin.
---
diff --git a/docs/awstats_changelog.txt b/docs/awstats_changelog.txt
index f87c57bc..13b8ae46 100644
--- a/docs/awstats_changelog.txt
+++ b/docs/awstats_changelog.txt
@@ -4,6 +4,7 @@ AWStats Changelog
5.2
+- Added urlalias plugin to replace URL values in URL reports by a text.
- Added geoip plugin to track countries from IP location instead of domain
value.
- Support for postfix mail log.
diff --git a/wwwroot/cgi-bin/awstats.model.conf b/wwwroot/cgi-bin/awstats.model.conf
index 80ab571d..b8d4d332 100644
--- a/wwwroot/cgi-bin/awstats.model.conf
+++ b/wwwroot/cgi-bin/awstats.model.conf
@@ -927,7 +927,6 @@ color_x="C1B2E2" # Background color for number of exit pages (Default = "C1B2
# Plugin files must be .pm files stored in 'plugins' directory.
# Uncomment LoadPlugin lines to enable a plugin after checking that perl
# modules required by the plugin are installed.
-#
# Plugin: HashFiles
# Perl modules required: Storable
@@ -959,6 +958,14 @@ color_x="C1B2E2" # Background color for number of exit pages (Default = "C1B2
#
#LoadPlugin="geoip"
+# Plugin: UrlAliases
+# Perl modules required: None
+# Show a text in all URL reports instead of URL value.
+# A text files called urlalias.txt, with two fields (first is URL, second is
+# text to show) separated by a tab char. must be created in plugin directory.
+#
+#LoadPlugin="urlalias"
+
# Plugin: Graph3D
# Perl modules required: Graph3D
# Some reported charts are nice 3D graphics.
diff --git a/wwwroot/cgi-bin/awstats.pl b/wwwroot/cgi-bin/awstats.pl
index acebeff6..bc8795d0 100644
--- a/wwwroot/cgi-bin/awstats.pl
+++ b/wwwroot/cgi-bin/awstats.pl
@@ -40,8 +40,9 @@ $NOTSORTEDRECORDTOLERANCE=10000; # Laps of time to accept a record if not in cor
$MAXDIFFEXTRA=500;
$WIDTHCOLICON=32;
# Plugins variable
-use vars qw/ %PluginsLoaded /;
+use vars qw/ %PluginsLoaded $PluginDir /;
%PluginsLoaded=();
+$PluginDir='';
# Running variables
use vars qw/
$DIR $PROG $Extension
@@ -301,17 +302,6 @@ use vars qw/
#tie %_host_p, 'Tie::StdHash';
#tie %TmpOS, 'Tie::Cache::LRU';
-# Those addresses are shown with those lib (First column is full exact relative URL, second column is text to show instead of URL)
-use vars qw/ %Aliases /;
-%Aliases = (
- '/', 'HOME PAGE',
- '/cgi-bin/awstats.pl', 'AWStats stats page',
- '/cgi-bin/awstats/awstats.pl', 'AWStats stats page',
- # Following the same example, you can put here HTML text you want to see in links instead of URL text.
-# '/YourRelativeUrl', 'Your HTML text'
- );
-
-
# PROTOCOL CODES
# HTTP codes
@@ -1516,6 +1506,7 @@ sub Check_Config {
if ($EnableLockForUpdate !~ /[0-1]/) { $EnableLockForUpdate=0; }
if (! $DNSStaticCacheFile) { $DNSStaticCacheFile="dnscache.txt"; }
if (! $DNSLastUpdateCacheFile) { $DNSLastUpdateCacheFile="dnscachelastupdate.txt"; }
+ if ($DNSStaticCacheFile eq $DNSLastUpdateCacheFile) { error("Error: DNSStaticCacheFile and DNSLastUpdateCacheFile must have different values."); }
if ($AllowAccessFromWebToAuthenticatedUsersOnly !~ /[0-1]/) { $AllowAccessFromWebToAuthenticatedUsersOnly=0; }
if ($CreateDirDataIfNotExists !~ /[0-1]/) { $CreateDirDataIfNotExists=0; }
if ($SaveDatabaseFilesWithPermissionsForEveryone !~ /[0-1]/) { $SaveDatabaseFilesWithPermissionsForEveryone=1; }
@@ -1700,6 +1691,7 @@ sub Read_Plugins {
if ($searchdir && (!($searchdir =~ /\/$/)) && (!($searchdir =~ /\\$/)) ) { $searchdir .= "/"; }
my $pluginpath="${searchdir}${pluginfile}.pm";
if (-s "$pluginpath") {
+ $PluginDir="${searchdir}"; # Set plugin dir
if ($Debug) { debug(" Try to init plugin '$pluginname' ($pluginpath) with param '$pluginparam'",1); }
my $loadret=require "$pluginpath";
if (! $loadret || $loadret =~ /^error/i) {
@@ -4160,7 +4152,14 @@ sub ShowFormFilter() {
#--------------------------------------------------------------------
sub ShowURL() {
my $url=shift;
- my $nompage=$Aliases{$url}?$Aliases{$url}:CleanFromCSSA($url);
+ my $nompage=CleanFromCSSA($url);
+
+ # Call to plugin function ReplaceURL
+ foreach my $pluginname (keys %{$PluginsLoaded{'ReplaceURL'}}) {
+ my $function="ReplaceURL_$pluginname('$url')";
+ eval("$function");
+ }
+
if (length($nompage)>$MaxLengthOfURL) { $nompage=substr($nompage,0,$MaxLengthOfURL)."..."; }
if ($ShowLinksOnUrl) {
my $newkey=CleanFromCSSA($url);
diff --git a/wwwroot/cgi-bin/plugins/urlalias.pm b/wwwroot/cgi-bin/plugins/urlalias.pm
new file mode 100644
index 00000000..31721dcb
--- /dev/null
+++ b/wwwroot/cgi-bin/plugins/urlalias.pm
@@ -0,0 +1,89 @@
+#!/usr/bin/perl
+#-----------------------------------------------------------------------------
+# UrlAlias AWStats plugin
+# This plugin allow you to report all URL links with a text title instead of
+# URL value.
+# You must create a file called urlalias.cnfigvalue.txt and store it in
+# plugin directory that contains 2 columns separated by a tab char.
+# First column is URL value and second column is text title to use instead of.
+#-----------------------------------------------------------------------------
+# Perl Required Modules: None
+#-----------------------------------------------------------------------------
+# $Revision$ - $Author$ - $Date$
+
+
+# <-----
+# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
+# ----->
+use strict;no strict "refs";
+
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN VARIABLES
+#-----------------------------------------------------------------------------
+# <-----
+# ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
+# SHOULD BE AT LEAST 5.1
+my $PluginNeedAWStatsVersion="5.2";
+# ----->
+
+# <-----
+# THIS VARIABLE MUST CONTAINS THE NAME OF ALL FUNCTIONS THAT MANAGE THE PLUGIN
+my $PluginHooksFunctions="ReplaceURL";
+# ----->
+
+# <-----
+# IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE
+use vars qw/
+$urlaliasloaded
+%UrlAliases
+/;
+# ----->
+
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNTION Init_pluginname
+#-----------------------------------------------------------------------------
+sub Init_urlalias {
+ my $InitParams=shift;
+ my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
+
+ # <-----
+ # YOU CAN ENTER HERE CODE TO INIT PLUGIN GLOBAL VARIABLES
+ debug("InitParams=$InitParams",1);
+ $urlaliasloaded=0;
+ %UrlAliases=();
+ # ----->
+ return ($checkversion?$checkversion:"$PluginHooksFunctions");
+}
+
+
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNTION GetCountryCodeByName_pluginname
+# UNIQUE: YES (Only one function GetCountryName can exists for all loaded plugins)
+# GetCountryName is called to translate a host name or ip to a country name.
+#-----------------------------------------------------------------------------
+sub ReplaceURL_urlalias {
+ # <-----
+ if (! $urlaliasloaded) {
+ my $filetoload="$PluginDir/urlalias.txt";
+ # Load urlalias file
+ open(URLALIASFILE,"$filetoload") or error("Error: Couldn't open UrlAlias file \"$filetoload\": $!");
+ # This is the fastest way to load with regexp that I know
+ %UrlAliases = map(/^([^\s]+)\s+([^\s]+)$/o,);
+ close URLALIASFILE;
+ debug("UrlAlias file loaded: ".(scalar keys %UrlAliases)." aliases found.");
+ $urlaliasloaded=1;
+ }
+ my $urltoreplace="$_[0]";
+ if ($UrlAliases{$urltoreplace}) { print "$UrlAliases{$urltoreplace}
"; }
+ else { print ""; }
+ return 1;
+ # ----->
+}
+
+
+1; # Do not remove this line