1 rizwank 1.1 #!/usr/bin/perl
2 #-----------------------------------------------------------------------------
3 # UserInfo AWStats plugin
4 # This plugin allow you to add information on authenticated users chart from
5 # a text file. Like full user name and lastname.
6 # You must create a file called userinfo.configvalue.txt wich contains 2
7 # columns separated by a tab char, and store it in DirData directory.
8 # First column is authenticated user login and second column is text you want
9 # to add.
10 #-----------------------------------------------------------------------------
11 # Perl Required Modules: None
12 #-----------------------------------------------------------------------------
13 # $Revision: 1.8 $ - $Author: eldy $ - $Date: 2004/06/11 21:34:32 $
14
15
16 # <-----
17 # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
18 #if (!eval ('require "TheModule.pm";')) { return $@?"Error: $@":"Error: Need Perl module TheModule"; }
19 # ----->
20 use strict;no strict "refs";
21
22 rizwank 1.1
23
24 #-----------------------------------------------------------------------------
25 # PLUGIN VARIABLES
26 #-----------------------------------------------------------------------------
27 # <-----
28 # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
29 # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
30 my $PluginNeedAWStatsVersion="5.5";
31 my $PluginHooksFunctions="ShowInfoUser";
32 # ----->
33
34 # <-----
35 # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
36 use vars qw/
37 $userinfoloaded
38 %UserInfo
39 /;
40 # ----->
41
42
43 rizwank 1.1
44 #-----------------------------------------------------------------------------
45 # PLUGIN FUNCTION: Init_pluginname
46 #-----------------------------------------------------------------------------
47 sub Init_userinfo {
48 my $InitParams=shift;
49 my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
50
51 # <-----
52 # ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
53 debug(" Plugin userinfo: InitParams=$InitParams",1);
54 $userinfoloaded=0;
55 %UserInfo=();
56 # ----->
57
58 return ($checkversion?$checkversion:"$PluginHooksFunctions");
59 }
60
61
62
63 #-----------------------------------------------------------------------------
64 rizwank 1.1 # PLUGIN FUNCTION: ShowInfoUser_pluginname
65 # UNIQUE: NO (Several plugins using this function can be loaded)
66 # Function called to add additionnal columns to Authenticated users report.
67 # This function is called when building rows of the report (One call for each
68 # row). So it allows you to add a column in report, for example with code :
69 # print "<TD>This is a new cell</TD>";
70 # Parameters: User
71 #-----------------------------------------------------------------------------
72 sub ShowInfoUser_userinfo {
73 my $param="$_[0]";
74 # <-----
75 my $filetoload='';
76 if ($param && $param ne '__title__' && ! $userinfoloaded) {
77 # Load userinfo file
78 if ($SiteConfig && open(USERINFOFILE,"$DirData/userinfo.$SiteConfig.txt")) { $filetoload="$DirData/userinfo.$SiteConfig.txt"; }
79 elsif (open(USERINFOFILE,"$DirData/userinfo.txt")) { $filetoload="$DirData/userinfo.txt"; }
80 else { error("Couldn't open UserInfo file \"$DirData/userinfo.txt\": $!"); }
81 # This is the fastest way to load with regexp that I know
82 %UserInfo = map(/^([^\t]+)\t+([^\t]+)/o,<USERINFOFILE>);
83 close USERINFOFILE;
84 debug(" Plugin userinfo: UserInfo file loaded: ".(scalar keys %UserInfo)." entries found.");
85 rizwank 1.1 $userinfoloaded=1;
86 }
87 if ($param eq '__title__') {
88 print "<th width=\"80\">$Message[114]</th>";
89 }
90 elsif ($param) {
91 print "<td>";
92 if ($UserInfo{$param}) { print "$UserInfo{$param}"; }
93 else { print " "; } # Undefined user info
94 print "</td>";
95 }
96 else {
97 print "<td> </td>";
98 }
99 return 1;
100 # ----->
101 }
102
103
104 1; # Do not remove this line
|