]> git.ipfire.org Git - thirdparty/AWStats.git/commitdiff
Add new hooked function for plugin build.
authoreldy <>
Sun, 28 Mar 2004 17:03:47 +0000 (17:03 +0000)
committereldy <>
Sun, 28 Mar 2004 17:03:47 +0000 (17:03 +0000)
Better plugin error management.

wwwroot/cgi-bin/awstats.pl
wwwroot/cgi-bin/plugins/example/example.pm
wwwroot/cgi-bin/plugins/geoip.pm
wwwroot/cgi-bin/plugins/geoipfree.pm

index d83a0bcf5b39d3e20e50b8d36af852fc47dfe547..3356295f6ad0bd0ec55563fc1f7558038b9df08f 100644 (file)
@@ -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<br /><br />\n";
                        print "<span dir=\"ltr\" style=\"font: 11px verdana, arial, helvetica; color: #$color_text;\">";
@@ -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<a name=\"menu\">&nbsp;</a>\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 "</form>\n"; }
                else { print "<br />\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'}) {
index f3285cad03532e3b4ac19157480f47cc03849007..a287cc68253c46a57e6f2f9ae36785ab23936bd4 100644 (file)
@@ -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)
index 84a5d19f27efc2aa85fd459cfc2d7e03d8bd2390..391f749e60f8d58a3040893e84dfb8238f8a8c4a 100644 (file)
@@ -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;
 }
 
 
index 21b89773fbc922781950a9648d8e68e99c3230a1..b148cb9d0352a64da92d0a9ec1079a8138032016 100644 (file)
@@ -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