File: example.pm

package info (click to toggle)
awstats 8.0-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 13,244 kB
  • sloc: perl: 40,711; xml: 1,785; javascript: 1,493; java: 359; sh: 152; makefile: 40; php: 29
file content (326 lines) | stat: -rw-r--r-- 12,370 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/usr/bin/perl
#-----------------------------------------------------------------------------
# Example AWStats plugin
# <-----
# THIS IS A SAMPLE OF AN EMPTY PLUGIN FILE WITH INSTRUCTIONS TO HELP YOU TO
# WRITE YOUR OWN WORKING PLUGIN. REPLACE THIS SENTENCE WITH THE PLUGIN GOAL.
# NOTE THAT A PLUGIN FILE example.pm MUST BE IN LOWER CASE.
# ----->
#-----------------------------------------------------------------------------
# Perl Required Modules: Put here list of all required plugins
#-----------------------------------------------------------------------------


# <-----
# ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
#if (!eval ('require "TheModule.pm";')) { return $@?"Error: $@":"Error: Need Perl module TheModule"; }
# ----->
#use strict;
no strict "refs";



#-----------------------------------------------------------------------------
# PLUGIN VARIABLES
#-----------------------------------------------------------------------------
# <-----
# ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
# AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
# EACH POSSIBLE FUNCTION AND GOAL ARE DESCRIBED LATER.
my $PluginNeedAWStatsVersion="6.7";
my $PluginHooksFunctions="xxx";
# ----->

# <-----
# IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
use vars qw/
$PluginVariable1
/;
# ----->



#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: Init_pluginname
#-----------------------------------------------------------------------------
sub Init_example {
	my $InitParams=shift;
	my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);

	# <-----
	# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
	debug(" InitParams=$InitParams",1);
	$PluginVariable1="";
	# ----->

	return ($checkversion?$checkversion:"$PluginHooksFunctions");
}



# HERE ARE ALL POSSIBLE HOOK FUNCTIONS. YOU MUST CHANGE THE NAME OF THE
# FUNCTION xxx_example INTO xxx_pluginname (pluginname in lower case).
# NOTE THAT IN PLUGINS' FUNCTIONS, YOU CAN USE ANY AWSTATS GLOBAL VARIALES.


#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: AddHTMLStyles_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
# Function called to Add HTML styles at beginning of BODY section.
# Parameters: None
#-----------------------------------------------------------------------------
sub AddHTMLStyles_example {
	# <-----
	# PERL CODE HERE
	# ----->
}

#-----------------------------------------------------------------------------
# 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 (top of page).
# Parameters: None
#-----------------------------------------------------------------------------
sub AddHTMLBodyHeader_example {
	# <-----
	# PERL CODE HERE
	# ----->
}

#-----------------------------------------------------------------------------
# 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: BuildFullHTMLOutput_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
# Function called to output an HTML page completely built by plugin instead
# of AWStats output
#-----------------------------------------------------------------------------
sub BuildFullHTMLOutput_example {
	# <-----
	print "This is an output for plugin example<br />\n";
	return 1;
	# ----->
}

#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: ShowInfoHost_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
# Function called to add additionnal columns to the Hosts report.
# This function is called when building rows of the report (One call for each
# row). So it allows you to add a column in report, for example with code :
#   print "<TD>This is a new cell for $param</TD>";
# Parameters: Host name or ip
#-----------------------------------------------------------------------------
sub ShowInfoHost_example {
    my $param="$_[0]";
	# <-----
	# PERL CODE HERE
	# ----->
}

#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: ShowPagesAddField_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
# Function used to add additionnal columns to the Top Pages-URL report.
# This function is called when building rows of the report (One call for each
# row). So it allows you to add a column in report, for example with code :
#   print "<TD>This is a new cell for $param</TD>";
# Parameters: URL
#-----------------------------------------------------------------------------
sub ShowPagesAddField_example {
    my $param="$_[0]";
	# <-----
	# PERL CODE HERE
	# ----->
}

#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: ShowInfoURL_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
# Function called to add additionnal information for URLs in URLs' report.
# This function is called after writing the URL value in the URL cell of the
# Top Pages-URL report.
# Parameters: URL
#-----------------------------------------------------------------------------
sub ShowInfoURL_example {
    my $param="$_[0]";
	# <-----
	# PERL CODE HERE
	# ----->
}

#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: ShowInfoUser_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
# Function called to add additionnal columns to Authenticated users report.
# This function is called when building rows of the report (One call for each
# row). So it allows you to add a column in report, for example with code :
#   print "<TD>This is a new cell for $param</TD>";
# Parameters: User
#-----------------------------------------------------------------------------
sub ShowInfoUser_example {
    my $param="$_[0]";
	# <-----
	# PERL CODE HERE
	# ----->
}



#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: SectionInitHashArray_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
#-----------------------------------------------------------------------------
sub SectionInitHashArray_example {
	# <-----
	if ($Debug) { debug(" Plugin example: Init_HashArray"); }
	%_myarray_p = %_myarray_h = %_myarray_k = %_myarray_l = ();
	# ----->
	return 0;
}


#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: SectionProcessIP_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
#-----------------------------------------------------------------------------
sub SectionProcessIp_example {
    my $param="$_[0]";      # Param is IP of record
	# <-----
	# PERL CODE HERE
	# ----->
	return;
}


#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: SectionProcessHostname_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
#-----------------------------------------------------------------------------
sub SectionProcessHostname_example {
    my $param="$_[0]";      # Param is hostname of record
	# <-----
	# PERL CODE HERE
	# ----->
	return;
}


#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: SectionReadHistory_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
#-----------------------------------------------------------------------------
sub SectionReadHistory_example {
    my $issectiontoload=shift;
    my $xmlold=shift;
    my $xmleb=shift;
	my $countlines=shift;
	# <-----
#	if ($Debug) { debug(" Plugin example: Begin of PLUGIN_example section"); }
#	my @field=();
#	my $count=0;my $countloaded=0;
#	do {
#		if ($field[0]) {
#			$count++;
#			if ($issectiontoload) {
#				$countloaded++;
#				if ($field[1]) { $_myarray_p{$field[0]}+=$field[1]; }
#				if ($field[2]) { $_myarray_h{$field[0]}+=$field[2]; }
#				if ($field[3]) { $_myarray_k{$field[0]}+=$field[3]; }
#				if ($field[4]) { $_myarray_l{$field[0]}+=$field[4]; }
#			}
#		}
#		$_=<HISTORY>;
#		chomp $_; s/\r//;
#		@field=split(/\s+/,($xmlold?XMLDecodeFromHisto($_):$_));
#		$countlines++;
#	}
#	until ($field[0] eq 'END_PLUGIN_example' || $field[0] eq "${xmleb}END_PLUGIN_example" || ! $_);
#	if ($field[0] ne 'END_PLUGIN_example' && $field[0] ne "${xmleb}END_PLUGIN_example") { error("History file is corrupted (End of section PLUGIN not found).\nRestore a recent backup of this file (data for this month will be restored to backup date), remove it (data for month will be lost), or remove the corrupted section in file (data for at least this section will be lost).","","",1); }
#	if ($Debug) { debug(" Plugin example: End of PLUGIN_example section ($count entries, $countloaded loaded)"); }
	# ----->
	return 0;
}

#-----------------------------------------------------------------------------
# PLUGIN FUNCTION: SectionWriteHistory_pluginname
# UNIQUE: NO (Several plugins using this function can be loaded)
#-----------------------------------------------------------------------------
sub SectionWriteHistory_example {
    my ($xml,$xmlbb,$xmlbs,$xmlbe,$xmlrb,$xmlrs,$xmlre,$xmleb,$xmlee)=(shift,shift,shift,shift,shift,shift,shift,shift,shift);
    if ($Debug) { debug(" Plugin example: SectionWriteHistory_example start - ".(scalar keys %_myarray_h)); }
	# <-----
#	print HISTORYTMP "\n";
#	if ($xml) { print HISTORYTMP "<section id='plugin_example'><sortfor>$MAXNBOFSECTIONGIR</sortfor><comment>\n"; }
#	print HISTORYTMP "# Plugin key - Pages - Hits - Bandwidth - Last access\n";
#	$ValueInFile{'plugin_example'}=tell HISTORYTMP;
#	print HISTORYTMP "${xmlbb}BEGIN_PLUGIN_example${xmlbs}".(scalar keys %_myarray_h)."${xmlbe}\n";
#	&BuildKeyList($MAXNBOFSECTIONGIR,1,\%_myarray_h,\%_myarray_h);
#	my %keysinkeylist=();
#	foreach (@keylist) {
#		$keysinkeylist{$_}=1;
#		my $page=$_myarray_p{$_}||0;
#		my $bytes=$_myarray_k{$_}||0;
#		my $lastaccess=$_myarray_l{$_}||'';
#		print HISTORYTMP "${xmlrb}$_${xmlrs}", $_myarray_p{$_}, "${xmlrs}", $_myarray_h{$_}, "${xmlrs}", $_myarray_k{$_}, "${xmlrs}", $_myarray_l{$_}, "${xmlre}\n"; next;
#	}
#	foreach (keys %_myarray_h) {
#		if ($keysinkeylist{$_}) { next; }
#		my $page=$_myarray_p{$_}||0;
#		my $bytes=$_myarray_k{$_}||0;
#		my $lastaccess=$_myarray_l{$_}||'';
#		print HISTORYTMP "${xmlrb}$_${xmlrs}", $_myarray_p{$_}, "${xmlrs}", $_myarray_h{$_}, "${xmlrs}", $_myarray_k{$_}, "${xmlrs}", $_myarray_l{$_}, "${xmlre}\n"; next;
#	}
#	print HISTORYTMP "${xmleb}END_PLUGIN_example${xmlee}\n";
	# ----->
	return 0;
}


1;	# Do not remove this line