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:
- 5497 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/perl |
2 | #------------------------------------------------------------------------------ |
3 | # Launch update process for all config files found in a particular directory. |
4 | # See COPYING.TXT file about AWStats GNU General Public License. |
5 | #------------------------------------------------------------------------------ |
6 | # $Revision: 1.15 $ - $Author: eldy $ - $Date: 2006/07/23 22:57:48 $ |
7 | |
8 | |
9 | #------------------------------------------------------------------------------ |
10 | # Defines |
11 | #------------------------------------------------------------------------------ |
12 | my $REVISION='$Revision: 1.15 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1; |
13 | my $VERSION="1.0 (build $REVISION)"; |
14 | |
15 | # Default value of DIRCONFIG |
16 | my $DIRCONFIG = "/etc/awstats"; |
17 | |
18 | my $Debug=0; |
19 | |
20 | my $Awstats='awstats.pl'; |
21 | |
22 | my $AwstatsDir=''; |
23 | my $AwstatsProg=''; |
24 | my $LastLine=''; |
25 | |
26 | |
27 | |
28 | #------------------------------------------------------------------------------ |
29 | # Functions |
30 | #------------------------------------------------------------------------------ |
31 | |
32 | #------------------------------------------------------------------------------ |
33 | # Function: Write error message and exit |
34 | # Parameters: $message |
35 | # Input: None |
36 | # Output: None |
37 | # Return: None |
38 | #------------------------------------------------------------------------------ |
39 | sub error { |
40 | print "Error: $_[0].\n"; |
41 | exit 1; |
42 | } |
43 | |
44 | |
45 | #------------------------------------------------------------------------------ |
46 | # Function: Write debug message and exit |
47 | # Parameters: $string $level |
48 | # Input: %HTMLOutput $Debug=required level $DEBUGFORCED=required level forced |
49 | # Output: None |
50 | # Return: None |
51 | #------------------------------------------------------------------------------ |
52 | sub debug { |
53 | my $level = $_[1] || 1; |
54 | if ($Debug >= $level) { |
55 | my $debugstring = $_[0]; |
56 | if ($ENV{"GATEWAY_INTERFACE"}) { $debugstring =~ s/^ /   /; $debugstring .= "<br />"; } |
57 | print localtime(time)." - DEBUG $level - $debugstring\n"; |
58 | } |
59 | } |
60 | |
61 | |
62 | #------------------------------------------------------------------------------ |
63 | # MAIN |
64 | #------------------------------------------------------------------------------ |
65 | |
66 | # Change default value if options are used |
67 | my $helpfound=0;my $nowfound=0; |
68 | my %confexcluded=(); |
69 | for (0..@ARGV-1) { |
70 | if ($ARGV[$_] =~ /^-*h/i) { $helpfound=1; last; } |
71 | if ($ARGV[$_] =~ /^-*awstatsprog=(.*)/i) { $Awstats="$1"; next; } |
72 | if ($ARGV[$_] =~ /^-*configdir=(.*)/i) { $DIRCONFIG="$1"; next; } |
73 | if ($ARGV[$_] =~ /^-*excludeconf=(.*)/i) { |
74 | #try to get the different files to exclude |
75 | @conftoexclude = split(/,/, $1); |
76 | foreach (@conftoexclude) { |
77 | $confexcluded{"$_"}=1; |
78 | } |
79 | next; |
80 | } |
81 | if ($ARGV[$_] =~ /^-*debug=(\d+)/i) { $Debug=$1; next; } |
82 | if ($ARGV[$_] =~ /^-*lastline=(\d+)/i) { $LastLine=$1; next; } |
83 | if ($ARGV[$_] =~ /^now/i) { $nowfound=1; next; } |
84 | } |
85 | |
86 | # Show usage help |
87 | my $DIR; my $PROG; my $Extension; |
88 | ($DIR=$0) =~ s/([^\/\\]*)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1; |
89 | if (!$nowfound || $helpfound || ! @ARGV) { |
90 | print "----- $PROG $VERSION (c) Laurent Destailleur -----\n"; |
91 | print "awstats_updateall launches update process for all AWStats config files (except\n"; |
92 | print "awstats.model.conf) found in a particular directory, so you can easily setup a\n"; |
93 | print "cron/scheduler job. The scanned directory is by default $DIRCONFIG.\n"; |
94 | print "\n"; |
95 | print "Usage: $PROG.$Extension now [options]\n"; |
96 | print "\n"; |
97 | print "Where options are:\n"; |
98 | print " -awstatsprog=pathtoawstatspl\n"; |
99 | print " -configdir=directorytoscan\n"; |
100 | print " -excludeconf=conftoexclude[,conftoexclude2,...] (Note: awstats.model.conf is always excluded)\n"; |
101 | print "\n"; |
102 | exit 0; |
103 | } |
104 | |
105 | debug("Scan directory $DIRCONFIG"); |
106 | |
107 | # Scan directory $DIRCONFIG |
108 | opendir(DIR, $DIRCONFIG) || error("Can't scan directory $DIRCONFIG"); |
109 | my @filesindir = grep { /^awstats\.(.*)conf$/ } sort readdir(DIR); |
110 | closedir(DIR); |
111 | |
112 | debug("List of files found :".join(",",@filesindir)); |
113 | |
114 | # Build file list |
115 | my @files=(); |
116 | foreach my $file (@filesindir) { |
117 | if ($confexcluded{$file}) { next; } # Should be useless |
118 | if ($file =~ /^awstats\.(.*)conf$/) { |
119 | my $conf=$1; $conf =~ s/\.$//; |
120 | if ($conf eq 'model') { next; } |
121 | if ($confexcluded{$conf}) { next; } |
122 | } |
123 | push @files, $file; |
124 | } |
125 | |
126 | debug("List of files qualified :".join(",",@files)); |
127 | |
128 | # Run update process for each config file found |
129 | if (@files) { |
130 | # Check if AWSTATS prog is found |
131 | my $AwstatsFound=0; |
132 | if (-s "$Awstats") { $AwstatsFound=1; } |
133 | elsif (-s "/usr/local/awstats/wwwroot/cgi-bin/awstats.pl") { |
134 | $Awstats="/usr/local/awstats/wwwroot/cgi-bin/awstats.pl"; |
135 | $AwstatsFound=1; |
136 | } |
137 | if (! $AwstatsFound) { |
138 | error("Can't find AWStats program ('$Awstats').\nUse -awstatsprog option to solve this"); |
139 | exit 1; |
140 | } |
141 | # Define AwstatsDir and AwstatsProg |
142 | ($AwstatsDir=$Awstats) =~ s/([^\/\\]+)$//; $AwstatsProg=$1; |
143 | $AwstatsDir||='.'; $AwstatsDir =~ s/([^\/\\])[\\\/]+$/$1/; |
144 | debug("AwstatsDir=$AwstatsDir"); |
145 | debug("AwstatsProg=$AwstatsProg"); |
146 | |
147 | foreach (@files) { |
148 | if ($_ =~ /^awstats\.(.*)conf$/) { |
149 | my $domain = $1||"default"; $domain =~ s/\.$//; |
150 | # Define command line |
151 | my $command="\"$AwstatsDir/$AwstatsProg\" -update -config=$domain"; |
152 | $command.=" -configdir=\"$DIRCONFIG\""; |
153 | if ($LastLine) |
154 | { |
155 | $command.=" -lastline=$LastLine"; |
156 | } |
157 | # Run command line |
158 | print "Running '$command' to update config $domain\n"; |
159 | my $output = `$command 2>&1`; |
160 | print "$output\n"; |
161 | } |
162 | } |
163 | } else { |
164 | print "No AWStats config file found in $DIRCONFIG\n"; |
165 | } |
166 | |
167 | 0; # Do not remove this line |
168 |