Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 269
- Log:
Overdue upgrade to AWStats v6.9, the most recent version
available at the time of writing.
- Author:
- rool
- Date:
- Wed May 27 23:57:15 +0100 2009
- Size:
- 5346 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/perl |
2 | #----------------------------------------------------------------------------- |
3 | # HashFiles AWStats plugin |
4 | # Allows AWStats to read/save its data file as native hash files. |
5 | # This increase read andwrite files operations. |
6 | #----------------------------------------------------------------------------- |
7 | # Perl Required Modules: Storable |
8 | #----------------------------------------------------------------------------- |
9 | # $Revision: 1.12 $ - $Author: eldy $ - $Date: 2005/10/09 14:49:42 $ |
10 | |
11 | |
12 | # <----- |
13 | # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES |
14 | if (!eval ('require "Storable.pm";')) { return $@?"Error: $@":"Error: Need Perl module Storable"; } |
15 | # -----> |
16 | use strict;no strict "refs"; |
17 | |
18 | |
19 | |
20 | #----------------------------------------------------------------------------- |
21 | # PLUGIN VARIABLES |
22 | #----------------------------------------------------------------------------- |
23 | # <----- |
24 | # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN |
25 | # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE. |
26 | my $PluginNeedAWStatsVersion="5.1"; |
27 | my $PluginHooksFunctions="SearchFile LoadCache SaveHash"; |
28 | # -----> |
29 | |
30 | # <----- |
31 | # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE. |
32 | use vars qw/ |
33 | $PluginHashfilesUpToDate |
34 | /; |
35 | # -----> |
36 | |
37 | |
38 | |
39 | #----------------------------------------------------------------------------- |
40 | # PLUGIN FUNCTION: Init_pluginname |
41 | #----------------------------------------------------------------------------- |
42 | sub Init_hashfiles { |
43 | my $InitParams=shift; |
44 | |
45 | # <----- |
46 | # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS |
47 | $PluginHashfilesUpToDate=1; |
48 | # -----> |
49 | |
50 | my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion); |
51 | return ($checkversion?$checkversion:"$PluginHooksFunctions"); |
52 | } |
53 | |
54 | |
55 | |
56 | #----------------------------------------------------------------------------- |
57 | # PLUGIN FUNTION: SearchFile_pluginname |
58 | # UNIQUE: YES (Only one plugin using this function can be loaded) |
59 | #----------------------------------------------------------------------------- |
60 | sub SearchFile_hashfiles { |
61 | my ($searchdir,$dnscachefile,$filesuffix,$dnscacheext,$filetoload)=@_; # Get params sent by ref |
62 | if (-f "${searchdir}$dnscachefile$filesuffix.hash") { |
63 | my ($tmp1a,$tmp2a,$tmp3a,$tmp4a,$tmp5a,$tmp6a,$tmp7a,$tmp8a,$tmp9a,$datesource,$tmp10a,$tmp11a,$tmp12a) = stat("${searchdir}$dnscachefile$filesuffix$dnscacheext"); |
64 | my ($tmp1b,$tmp2b,$tmp3b,$tmp4b,$tmp5b,$tmp6b,$tmp7b,$tmp8b,$tmp9b,$datehash,$tmp10b,$tmp11b,$tmp12b) = stat("${searchdir}$dnscachefile$filesuffix.hash"); |
65 | if ($datesource && $datehash < $datesource) { |
66 | $PluginHashfilesUpToDate=0; |
67 | debug(" Plugin hashfiles: Hash file not up to date. Will use source file $filetoload instead."); |
68 | } |
69 | else { |
70 | # There is no source file or there is and hash file is up to date. We can just load hash file |
71 | $filetoload="${searchdir}$dnscachefile$filesuffix.hash"; |
72 | } |
73 | } |
74 | elsif ($filetoload) { |
75 | $PluginHashfilesUpToDate=0; |
76 | debug(" Plugin hashfiles: Hash file not found. Will use source file $filetoload instead."); |
77 | } |
78 | # Change calling params |
79 | $_[4]=$filetoload; |
80 | } |
81 | |
82 | |
83 | #----------------------------------------------------------------------------- |
84 | # PLUGIN FUNCTION: LoadCache_pluginname |
85 | # UNIQUE: YES (Only one plugin using this function can be loaded) |
86 | #----------------------------------------------------------------------------- |
87 | sub LoadCache_hashfiles { |
88 | my ($filetoload,$hashtoload)=@_; |
89 | if ($filetoload =~ /\.hash$/) { |
90 | # There is no source file or there is and hash file is up to date. We can just load hash file |
91 | eval('%$hashtoload = %{ Storable::retrieve("$filetoload") };') || warning("Warning: Error while retrieving hashfile: $@"); |
92 | } |
93 | } |
94 | |
95 | |
96 | #----------------------------------------------------------------------------- |
97 | # PLUGIN FUNCTION: SaveHash_pluginname |
98 | # UNIQUE: YES (Only one plugin using this function can be loaded) |
99 | #----------------------------------------------------------------------------- |
100 | sub SaveHash_hashfiles { |
101 | my ($filetosave,$hashtosave,$testifuptodate,$nbmaxofelemtosave,$nbofelemsaved)=@_; |
102 | if (! $testifuptodate || ! $PluginHashfilesUpToDate) { |
103 | $filetosave =~ s/(\.\w+)$//; $filetosave.=".hash"; |
104 | debug(" Plugin hashfiles: Save data ".($nbmaxofelemtosave?"($nbmaxofelemtosave records max)":"(all records)")." into hash file $filetosave"); |
105 | if (! $nbmaxofelemtosave || (scalar keys %$hashtosave <= $nbmaxofelemtosave)) { |
106 | # Save all hash array |
107 | unless ( eval('Storable::store(\%$hashtosave, "$filetosave");') ) { |
108 | $_[4] = 0; |
109 | warning("Warning: Error while storing hashfile: $@"); |
110 | return; |
111 | } |
112 | $_[4]=scalar keys %$hashtosave; |
113 | |
114 | } |
115 | else { |
116 | debug(" Plugin hashfiles: We need to resize hash to save from ".(scalar keys %$hashtosave)." to $nbmaxofelemtosave"); |
117 | # Save part of hash array |
118 | my $counter=0; |
119 | my %newhashtosave=(); |
120 | foreach my $key (keys %$hashtosave) { |
121 | $newhashtosave{$key}=$hashtosave->{$key}; |
122 | if (++$counter >= $nbmaxofelemtosave) { last; } |
123 | } |
124 | |
125 | unless ( eval('Storable::store(\%newhashtosave, "$filetosave");') ) { |
126 | $_[4] = 0; |
127 | warning("Warning: Error while storing hashfile: $@"); |
128 | return; |
129 | } |
130 | $_[4]=scalar keys %newhashtosave; |
131 | } |
132 | $_[0]=$filetosave; |
133 | } |
134 | else { |
135 | $_[4]=0; |
136 | } |
137 | } |
138 | |
139 | |
140 | 1; # Do not remove this line |