]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Added urlalias plugin.
authoreldy <>
Tue, 19 Nov 2002 22:12:46 +0000 (22:12 +0000)
committereldy <>
Tue, 19 Nov 2002 22:12:46 +0000 (22:12 +0000)
docs/awstats_changelog.txt
wwwroot/cgi-bin/awstats.model.conf
wwwroot/cgi-bin/awstats.pl
wwwroot/cgi-bin/plugins/urlalias.pm [new file with mode: 0644]

index f87c57bc82c73140b21c03960487ab0e6c67eb5a..13b8ae4632e2f0ac78211133890a17d0b3581537 100644 (file)
@@ -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.
index 80ab571d26a7f49e64579dd7dfabfc22823db606..b8d4d332b0b3b4193dddff84866c6b20c3507778 100644 (file)
@@ -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.
index acebeff6c97fdadb0cc1e47ad8ffcbca015bd64e..bc8795d039ae2d3d4a5608d45ba0431700fda6a2 100644 (file)
@@ -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 = (
-                       '/',                            '<b>HOME PAGE</b>',
-                       '/cgi-bin/awstats.pl',                  '<b>AWStats stats page</b>',
-                       '/cgi-bin/awstats/awstats.pl',  '<b>AWStats stats page</b>',
-                       # Following the same example, you can put here HTML text you want to see in links instead of URL text.
-#                      '/YourRelativeUrl',                             '<b>Your HTML text</b>'
-                       );
-
-
 # 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 (file)
index 0000000..31721dc
--- /dev/null
@@ -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,<URLALIASFILE>);
+               close URLALIASFILE;
+               debug("UrlAlias file loaded: ".(scalar keys %UrlAliases)." aliases found.");
+               $urlaliasloaded=1;      
+       }
+       my $urltoreplace="$_[0]";
+       if ($UrlAliases{$urltoreplace}) { print "<font style=\"color: #$color_link; font-weight: bold\">$UrlAliases{$urltoreplace}</font><br>"; }
+       else { print ""; }
+       return 1;
+       # ----->
+}
+
+
+1;     # Do not remove this line