From: eldy <>
Date: Sun, 28 Mar 2004 17:03:47 +0000 (+0000)
Subject: Add new hooked function for plugin build.
X-Git-Tag: AWSTATS_6_1_BETA~41
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=748a6ca7cd7ef63203c460a72a3dc8344e0906e5;p=thirdparty%2FAWStats.git
Add new hooked function for plugin build.
Better plugin error management.
---
diff --git a/wwwroot/cgi-bin/awstats.pl b/wwwroot/cgi-bin/awstats.pl
index d83a0bcf..3356295f 100644
--- a/wwwroot/cgi-bin/awstats.pl
+++ b/wwwroot/cgi-bin/awstats.pl
@@ -638,6 +638,13 @@ EOF
sub html_end {
my $listplugins=shift||0;
if (scalar keys %HTMLOutput) {
+
+ # Call to plugins' function AddHTMLBodyFooter
+ foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLBodyFooter'}}) {
+ my $function="AddHTMLBodyFooter_$pluginname()";
+ eval("$function");
+ }
+
if ($FrameName ne 'index' && $FrameName ne 'mainleft') {
print "$Center
\n";
print "";
@@ -1841,6 +1848,7 @@ sub Read_Plugins {
my $ret; # To get init return
my $initfunction="\$ret=Init_$pluginname('$pluginparam')";
my $initret=eval("$initfunction");
+ if ($initret eq 'xxx') { $initret='Error: The PluginHooksFunctions variable defined in plugin file does not contain list of hooked functions'; }
if (! $initret || $initret =~ /^error/i) {
# Init function failed, we stop here
error("Plugin init for plugin '$pluginname' failed with return code: ".($initret?"$initret":"$@ (A module required by plugin might be missing)."));
@@ -6758,7 +6766,7 @@ if ($UpdateStats && $FrameName ne 'index' && $FrameName ne 'mainleft') { # Updat
if ($Debug) { debug(" No check on code or code is OK. Now we check other conditions.",5); }
# Check conditions
- my $conditionok=0;
+ $conditionok=0;
foreach my $condnum (0..@{$ExtraConditionType[$extranum]}-1) {
my $conditiontype=$ExtraConditionType[$extranum][$condnum];
my $conditiontypeval=$ExtraConditionTypeVal[$extranum][$condnum];
@@ -7018,14 +7026,15 @@ if (scalar keys %HTMLOutput) {
eval("$function");
}
- # MENU
+ # TOP BAN
#---------------------------------------------------------------------
if ($ShowMenu || $FrameName eq 'mainleft') {
- if ($Debug) { debug("ShowMenu",2); }
my $frame=($FrameName eq 'mainleft');
+ my $WIDTHMENU1=($FrameName eq 'mainleft'?$FRAMEWIDTH:150);
+
+ if ($Debug) { debug("ShowTopBan",2); }
print "$Center \n";
- my $WIDTHMENU1=($FrameName eq 'mainleft'?$FRAMEWIDTH:150);
if ($FrameName ne 'mainleft') {
my $NewLinkParams=${QueryString};
@@ -7148,6 +7157,21 @@ if (scalar keys %HTMLOutput) {
if ($FrameName ne 'mainleft') { print "\n"; }
else { print "
\n"; }
print "\n";
+ }
+
+ # Call to plugins' function AddHTMLMenuHeader
+ foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLMenuHeader'}}) {
+ my $function="AddHTMLMenuHeader_$pluginname()";
+ eval("$function");
+ }
+
+ # MENU
+ #---------------------------------------------------------------------
+ if ($ShowMenu || $FrameName eq 'mainleft') {
+ my $frame=($FrameName eq 'mainleft');
+ my $WIDTHMENU1=($FrameName eq 'mainleft'?$FRAMEWIDTH:150);
+
+ if ($Debug) { debug("ShowMenu",2); }
# Print menu links
if (($HTMLOutput{'main'} && $FrameName ne 'mainright') || $FrameName eq 'mainleft') { # If main page asked
@@ -7372,6 +7396,12 @@ if (scalar keys %HTMLOutput) {
debug("firstdaytoshowtime=$firstdaytoshowtime, lastdaytoshowtime=$lastdaytoshowtime",1);
}
+ # Call to plugins' function AddHTMLContentHeader
+ foreach my $pluginname (keys %{$PluginsLoaded{'AddHTMLContentHeader'}}) {
+ my $function="AddHTMLContentHeader_$pluginname()";
+ eval("$function");
+ }
+
# Output particular part
# if ($HTMLOutput{'alldays'}) {
diff --git a/wwwroot/cgi-bin/plugins/example/example.pm b/wwwroot/cgi-bin/plugins/example/example.pm
index f3285cad..a287cc68 100644
--- a/wwwroot/cgi-bin/plugins/example/example.pm
+++ b/wwwroot/cgi-bin/plugins/example/example.pm
@@ -78,7 +78,7 @@ sub AddHTMLStyles_example {
#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: AddHTMLBodyHeader_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
-# Function called to Add HTML code at beginning of BODY section.
+# Function called to Add HTML code at beginning of BODY section (top of page).
# Parameters: None
#-----------------------------------------------------------------------------
sub AddHTMLBodyHeader_example {
@@ -87,6 +87,54 @@ sub AddHTMLBodyHeader_example {
# ----->
}
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLBodyFooter_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+# Function called to Add HTML code at end of BODY section (bottom of page).
+# Parameters: None
+#-----------------------------------------------------------------------------
+sub AddHTMLBodyFooter_example {
+ # <-----
+ # PERL CODE HERE
+ # ----->
+}
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLMenuHeader_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+# Function called to Add HTML code just before the menu section
+# Parameters: None
+#-----------------------------------------------------------------------------
+sub AddHTMLMenuHeader_example {
+ # <-----
+ # PERL CODE HERE
+ # ----->
+}
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLMenuFooter_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+# Function called to Add HTML code just after the menu section
+# Parameters: None
+#-----------------------------------------------------------------------------
+sub AddHTMLMenuFooter_example {
+ # <-----
+ # PERL CODE HERE
+ # ----->
+}
+
+#-----------------------------------------------------------------------------
+# PLUGIN FUNCTION: AddHTMLContentHeader_pluginname
+# UNIQUE: NO (Several plugins using this function can be loaded)
+# Function called to Add HTML code just before the first report
+# Parameters: None
+#-----------------------------------------------------------------------------
+sub AddHTMLContentHeader_example {
+ # <-----
+ # PERL CODE HERE
+ # ----->
+}
+
#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: ShowInfoHost_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
diff --git a/wwwroot/cgi-bin/plugins/geoip.pm b/wwwroot/cgi-bin/plugins/geoip.pm
index 84a5d19f..391f749e 100644
--- a/wwwroot/cgi-bin/plugins/geoip.pm
+++ b/wwwroot/cgi-bin/plugins/geoip.pm
@@ -79,16 +79,17 @@ sub Init_geoip {
# GetCountryCodeByName is called to translate a host name into a country name.
#-----------------------------------------------------------------------------
sub GetCountryCodeByName_geoip {
+ my $param="$_[0]";
# <-----
- my $res=$TmpDomainLookup{$_[0]}||'';
+ my $res=$TmpDomainLookup{$param}||'';
if (! $res) {
- $res=lc($gi->country_code_by_name($_[0]));
- $TmpDomainLookup{$_[0]}=$res;
- if ($Debug) { debug(" GetCountryCodeByName for $_[0]: [$res]",5); }
+ $res=lc($gi->country_code_by_name($param));
+ $TmpDomainLookup{$param}=$res;
+ if ($Debug) { debug(" GetCountryCodeByName for $param: [$res]",5); }
}
- elsif ($Debug) { debug(" GetCountryCodeByName for $_[0]: Already resolved to $res",5); }
- return $res;
+ elsif ($Debug) { debug(" GetCountryCodeByName for $param: Already resolved to $res",5); }
# ----->
+ return $res;
}
#-----------------------------------------------------------------------------
@@ -97,16 +98,17 @@ sub GetCountryCodeByName_geoip {
# GetCountryCodeByAddr is called to translate an ip into a country name.
#-----------------------------------------------------------------------------
sub GetCountryCodeByAddr_geoip {
+ my $param="$_[0]";
# <-----
- my $res=$TmpDomainLookup{$_[0]}||'';
+ my $res=$TmpDomainLookup{$param}||'';
if (! $res) {
- $res=lc($gi->country_code_by_addr($_[0]));
- $TmpDomainLookup{$_[0]}=$res;
- if ($Debug) { debug(" GetCountryCodeByAddr for $_[0]: $res",5); }
+ $res=lc($gi->country_code_by_addr($param));
+ $TmpDomainLookup{$param}=$res;
+ if ($Debug) { debug(" GetCountryCodeByAddr for $param: $res",5); }
}
- elsif ($Debug) { debug(" GetCountryCodeByAddr for $_[0]: Already resolved to $res",5); }
- return $res;
+ elsif ($Debug) { debug(" GetCountryCodeByAddr for $param: Already resolved to $res",5); }
# ----->
+ return $res;
}
diff --git a/wwwroot/cgi-bin/plugins/geoipfree.pm b/wwwroot/cgi-bin/plugins/geoipfree.pm
index 21b89773..b148cb9d 100644
--- a/wwwroot/cgi-bin/plugins/geoipfree.pm
+++ b/wwwroot/cgi-bin/plugins/geoipfree.pm
@@ -11,8 +11,8 @@
# <-----
-push @INC, "${DIR}/plugins";
# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
+push @INC, "${DIR}/plugins";
if (!eval ('require "Geo/IPfree.pm";')) { return $@?"Error: $@":"Error: Need Perl module Geo::IPfree"; }
# ----->
use strict;no strict "refs";
@@ -64,18 +64,19 @@ sub Init_geoipfree {
# GetCountryCodeByName is called to translate a host name into a country name.
#-----------------------------------------------------------------------------
sub GetCountryCodeByName_geoipfree {
+ my $param="$_[0]";
# <-----
- my $res=$TmpDomainLookup{$_[0]}||'';
+ my $res=$TmpDomainLookup{$param}||'';
if (! $res) {
- ($res,undef)=$gi->LookUp($_[0]);
+ ($res,undef)=$gi->LookUp($param);
if ($res !~ /\w\w/) { $res='ip'; }
else { $res=lc($res); }
- $TmpDomainLookup{$_[0]}=$res;
- if ($Debug) { debug(" GetCountryCodeByName for $_[0]: $res",5); }
+ $TmpDomainLookup{$param}=$res;
+ if ($Debug) { debug(" GetCountryCodeByName for $param: $res",5); }
}
- elsif ($Debug) { debug(" GetCountryCodeByName for $_[0]: Already resolved to $res",5); }
- return $res;
+ elsif ($Debug) { debug(" GetCountryCodeByName for $param: Already resolved to $res",5); }
# ----->
+ return $res;
}
#-----------------------------------------------------------------------------
@@ -84,18 +85,19 @@ sub GetCountryCodeByName_geoipfree {
# GetCountryCodeByAddr is called to translate an ip into a country name.
#-----------------------------------------------------------------------------
sub GetCountryCodeByAddr_geoipfree {
+ my $param="$_[0]";
# <-----
- my $res=$TmpDomainLookup{$_[0]}||'';
+ my $res=$TmpDomainLookup{$param}||'';
if (! $res) {
- ($res,undef)=$gi->LookUp($_[0]);
+ ($res,undef)=$gi->LookUp($param);
if ($res !~ /\w\w/) { $res='ip'; }
else { $res=lc($res); }
- $TmpDomainLookup{$_[0]}=$res;
- if ($Debug) { debug(" GetCountryCodeByAddr for $_[0]: $res",5); }
+ $TmpDomainLookup{$param}=$res;
+ if ($Debug) { debug(" GetCountryCodeByAddr for $param: $res",5); }
}
- elsif ($Debug) { debug(" GetCountryCodeByAddr for $_[0]: Already resolved to $res",5); }
- return $res;
+ elsif ($Debug) { debug(" GetCountryCodeByAddr for $param: Already resolved to $res",5); }
# ----->
+ return $res;
}
1; # Do not remove this line