Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 297
- Log:
Updated to AWStats 7.0.
- Author:
- rool
- Date:
- Fri Mar 18 13:33:29 +0000 2011
- Size:
- 26094 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/perl |
2 | #------------------------------------------------------- |
3 | # This script configures AWStats so that it works immediately. |
4 | # - Get Apache config file from registry (ask if not found) |
5 | # - Change common log to combined (ask to confirm) |
6 | # - Add AWStats directives |
7 | # - Restart web server |
8 | # - Create AWStats config file |
9 | # See COPYING.TXT file about AWStats GNU General Public License. |
10 | #------------------------------------------------------- |
11 | # $Revision: 1.9 $ - $Author: eldy $ - $Date: 2009/12/28 00:52:13 $ |
12 | require 5.005; |
13 | |
14 | use strict; |
15 | |
16 | |
17 | #------------------------------------------------------- |
18 | # IF YOU ARE A PACKAGE BUILDER, CHANGE THIS TO MATCH YOUR PATH |
19 | # SO THAT THE CONFIGURE WILL WORK ON YOUR DISTRIB !!! |
20 | # Following path are the one |
21 | #------------------------------------------------------- |
22 | use vars qw/ |
23 | $AWSTATS_PATH |
24 | $AWSTATS_ICON_PATH |
25 | $AWSTATS_CSS_PATH |
26 | $AWSTATS_CLASSES_PATH |
27 | $AWSTATS_CGI_PATH |
28 | $AWSTATS_MODEL_CONFIG |
29 | $AWSTATS_DIRDATA_PATH |
30 | /; |
31 | $AWSTATS_PATH=''; |
32 | $AWSTATS_ICON_PATH='/usr/local/awstats/wwwroot/icon'; |
33 | $AWSTATS_CSS_PATH='/usr/local/awstats/wwwroot/css'; |
34 | $AWSTATS_CLASSES_PATH='/usr/local/awstats/wwwroot/classes'; |
35 | $AWSTATS_CGI_PATH='/usr/local/awstats/wwwroot/cgi-bin'; |
36 | $AWSTATS_MODEL_CONFIG='/etc/awstats/awstats.model.conf'; # Used only when configure ran on linux |
37 | $AWSTATS_DIRDATA_PATH='/var/lib/awstats'; # Used only when configure ran on linux |
38 | |
39 | |
40 | |
41 | #------------------------------------------------------- |
42 | # Defines |
43 | #------------------------------------------------------- |
44 | # For windows registry management |
45 | my $reg; |
46 | eval('use Win32::TieRegistry ( Delimiter=>"/", TiedRef=>\$reg )'); |
47 | |
48 | use vars qw/ $REVISION $VERSION /; |
49 | $REVISION='$Revision: 1.9 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1; |
50 | $VERSION="1.0 (build $REVISION)"; |
51 | |
52 | use vars qw/ |
53 | $DIR $PROG $Extension $Debug |
54 | /; |
55 | |
56 | use vars qw/ |
57 | @WEBCONF |
58 | /; |
59 | # Possible dirs for Apache conf files |
60 | @WEBCONF=( |
61 | 'C:/Program Files/Apache Group/Apache2/conf/httpd.conf', |
62 | 'C:/Program Files/Apache Group/Apache/conf/httpd.conf', |
63 | '/Applications/MAMP/conf/apache/httpd.conf', |
64 | '/etc/httpd/httpd.conf', |
65 | '/usr/local/apache/conf/httpd.conf', |
66 | '/usr/local/apache2/conf/httpd.conf', |
67 | ); |
68 | |
69 | use vars qw/ |
70 | $WebServerChanged $UseAlias $Step |
71 | %LogFormat %ConfToChange |
72 | %OSLib |
73 | /; |
74 | $WebServerChanged=0; |
75 | $UseAlias=0; |
76 | %LogFormat=(); |
77 | %ConfToChange=(); |
78 | %OSLib=('linux'=>'Linux, BSD or Unix','macosx'=>'Mac OS','windows'=>'Windows'); |
79 | $Step=0; |
80 | |
81 | |
82 | |
83 | #------------------------------------------------------- |
84 | # Functions |
85 | #------------------------------------------------------- |
86 | |
87 | #------------------------------------------------------- |
88 | # error |
89 | #------------------------------------------------------- |
90 | sub error { |
91 | print "Error: $_[0].\n"; |
92 | exit 1; |
93 | } |
94 | |
95 | #------------------------------------------------------- |
96 | # debug |
97 | #------------------------------------------------------- |
98 | sub debug { |
99 | my $level = $_[1] || 1; |
100 | if ($Debug >= $level) { |
101 | my $debugstring = $_[0]; |
102 | if ($ENV{"GATEWAY_INTERFACE"}) { $debugstring =~ s/^ /   /; $debugstring .= "<br />"; } |
103 | print "DEBUG $level - ".time." : $debugstring\n"; |
104 | } |
105 | 0; |
106 | } |
107 | |
108 | #------------------------------------------------------- |
109 | # update_httpd_config |
110 | # Replace common to combined in Apache config file |
111 | #------------------------------------------------------- |
112 | sub update_httpd_config |
113 | { |
114 | my $file=shift; |
115 | if (! $file) { error("Call to update_httpd_config with wrong parameter"); } |
116 | |
117 | open(FILE, $file) || error("Failed to open $file for update"); |
118 | open(FILETMP, ">$file.tmp") || error("Failed to open $file.tmp for writing"); |
119 | |
120 | # $%conf contains param and values |
121 | my %confchanged=(); |
122 | my $conflinenb = 0; |
123 | |
124 | # First, change values that are already present in old config file |
125 | while(<FILE>) { |
126 | my $savline=$_; |
127 | |
128 | chomp $_; s/\r//; |
129 | $conflinenb++; |
130 | |
131 | # Remove comments not at beginning of line |
132 | $_ =~ s/\s#.*$//; |
133 | |
134 | # Change line |
135 | if ($_ =~ /^(\s*)CustomLog\s(.*)\scommon$/i) { $savline="$1CustomLog $2 combined"; } |
136 | |
137 | # Write line |
138 | print FILETMP "$savline"; |
139 | } |
140 | |
141 | close(FILE); |
142 | close(FILETMP); |
143 | |
144 | # Move file to file.sav |
145 | if (rename("$file","$file.old")==0) { |
146 | error("Failed to make backup of current config file to $file.old"); |
147 | } |
148 | |
149 | # Move tmp file into config file |
150 | if (rename("$file.tmp","$file")==0) { |
151 | error("Failed to move tmp config file $file.tmp to $file"); |
152 | } |
153 | |
154 | return 0; |
155 | } |
156 | |
157 | #------------------------------------------------------- |
158 | # update_awstats_config |
159 | # Update an awstats model [to another one] |
160 | #------------------------------------------------------- |
161 | sub update_awstats_config |
162 | { |
163 | my $file=shift; |
164 | my $fileto=shift||"$file.tmp"; |
165 | |
166 | if (! $file) { error("Call to update_awstats_config with wrong parameter"); } |
167 | if ($file =~ /Developpements[\\\/]awstats/i) { |
168 | print " This is my dev area. Don't touch.\n"; |
169 | return; |
170 | } # To avoid script working in my dev area |
171 | |
172 | open(FILE, $file) || error("Failed to open '$file' for read"); |
173 | open(FILETMP, ">$fileto") || error("Failed to open '$fileto' for writing"); |
174 | |
175 | # $%conf contains param and values |
176 | my %confchanged=(); |
177 | my $conflinenb = 0; |
178 | |
179 | # First, change values that are already present in old config file |
180 | while(<FILE>) { |
181 | my $savline=$_; |
182 | |
183 | chomp $_; s/\r//; |
184 | $conflinenb++; |
185 | |
186 | # Remove comments not at beginning of line |
187 | $_ =~ s/\s#.*$//; |
188 | |
189 | # Extract param and value |
190 | my ($param,$value)=split(/=/,$_,2); |
191 | $param =~ s/^\s+//; $param =~ s/\s+$//; |
192 | $value =~ s/#.*$//; |
193 | $value =~ s/^[\s\'\"]+//; $value =~ s/[\s\'\"]+$//; |
194 | |
195 | if ($param) { |
196 | # cleanparam is param without begining # |
197 | my $cleanparam=$param; my $wascleaned=0; |
198 | if ($cleanparam =~ s/^#//) { $wascleaned=1; } |
199 | if (defined($ConfToChange{"$cleanparam"}) && $ConfToChange{"$cleanparam"}) { $savline = ($wascleaned?"#":"")."$cleanparam=\"".$ConfToChange{"$cleanparam"}."\"\n"; } |
200 | } |
201 | # Write line |
202 | print FILETMP "$savline"; |
203 | } |
204 | |
205 | close(FILE); |
206 | close(FILETMP); |
207 | |
208 | if ($fileto eq "$file.tmp") { |
209 | # Move file to file.sav |
210 | if (rename("$file","$file.old")==0) { |
211 | error("Failed to make backup of current config file to $file.old"); |
212 | } |
213 | |
214 | # Move tmp file into config file |
215 | if (rename("$fileto","$file")==0) { |
216 | error("Failed to move tmp config file $fileto to $file"); |
217 | } |
218 | # Remove .old file |
219 | unlink "$file.old"; |
220 | } |
221 | else { |
222 | print " Config file $fileto created.\n"; |
223 | } |
224 | return 0; |
225 | } |
226 | |
227 | |
228 | |
229 | #------------------------------------------------------- |
230 | # MAIN |
231 | #------------------------------------------------------- |
232 | ($DIR=$0) =~ s/([^\/\\]+)$//; ($PROG=$1) =~ s/\.([^\.]*)$//; $Extension=$1; |
233 | $DIR||='.'; $DIR =~ s/([^\/\\])[\\\/]+$/$1/; |
234 | |
235 | my $QueryString=""; for (0..@ARGV-1) { $QueryString .= "$ARGV[$_] "; } |
236 | if ($QueryString =~ /debug=/i) { $Debug=$QueryString; $Debug =~ s/.*debug=//; $Debug =~ s/&.*//; $Debug =~ s/ .*//; } |
237 | |
238 | my $helpfound=0; |
239 | my $OS=''; |
240 | my $CR=''; |
241 | for (0..@ARGV-1) { |
242 | if ($ARGV[$_] =~ /^-*h/i) { $helpfound=1; last; } |
243 | if ($ARGV[$_] =~ /^-*awstatspath=([^\s\"]+)/i) { $AWSTATS_PATH=$1; last; } |
244 | } |
245 | # If AWSTATS_PATH was not forced on command line |
246 | if (! $AWSTATS_PATH) { |
247 | $AWSTATS_PATH=($DIR eq '.'?'..':$DIR); |
248 | $AWSTATS_PATH=~s/tools[\\\/]?$//; |
249 | $AWSTATS_PATH=~s/[\\\/]$//; |
250 | } |
251 | # On utilise le format de spearateur / partout (dans Apache et appels Perl) |
252 | $AWSTATS_PATH =~ s/\\/\//g; |
253 | |
254 | # Show usage help |
255 | if ($helpfound) { |
256 | print "----- AWStats $PROG $VERSION (c) Laurent Destailleur -----\n"; |
257 | print "$PROG is a tool to setup AWStats. It works with Apache only.\n"; |
258 | print " - Detect Apache config file (ask if not found)\n"; |
259 | print " - Change common log to combined (ask to confirm)\n"; |
260 | print " - Add AWStats directives\n"; |
261 | print " - Restart web server\n"; |
262 | print " - Create one AWStats config file (if asked)\n"; |
263 | print "\n"; |
264 | print "Usage: $PROG.$Extension\n"; |
265 | print "\n"; |
266 | exit 0; |
267 | } |
268 | |
269 | # Get current time |
270 | my $nowtime=time; |
271 | my ($nowsec,$nowmin,$nowhour,$nowday,$nowmonth,$nowyear) = localtime($nowtime); |
272 | if ($nowyear < 100) { $nowyear+=2000; } else { $nowyear+=1900; } |
273 | my $nowsmallyear=$nowyear;$nowsmallyear =~ s/^..//; |
274 | if (++$nowmonth < 10) { $nowmonth = "0$nowmonth"; } |
275 | if ($nowday < 10) { $nowday = "0$nowday"; } |
276 | if ($nowhour < 10) { $nowhour = "0$nowhour"; } |
277 | if ($nowmin < 10) { $nowmin = "0$nowmin"; } |
278 | if ($nowsec < 10) { $nowsec = "0$nowsec"; } |
279 | |
280 | print "\n"; |
281 | print "----- AWStats $PROG $VERSION (c) Laurent Destailleur -----\n"; |
282 | print "This tool will help you to configure AWStats to analyze statistics for\n"; |
283 | print "one web server. You can try to use it to let it do all that is possible\n"; |
284 | print "in AWStats setup, however following the step by step manual setup\n"; |
285 | print "documentation (docs/index.html) is often a better idea. Above all if:\n"; |
286 | print "- You are not an administrator user,\n"; |
287 | print "- You want to analyze downloaded log files without web server,\n"; |
288 | print "- You want to analyze mail or ftp log files instead of web log files,\n"; |
289 | print "- You need to analyze load balanced servers log files,\n"; |
290 | print "- You want to 'understand' all possible ways to use AWStats...\n"; |
291 | print "Read the AWStats documentation (docs/index.html).\n"; |
292 | |
293 | # Detect OS type |
294 | # -------------- |
295 | if ("$^O" =~ /linux/i || (-d "/etc" && -d "/var" && "$^O" !~ /cygwin/i)) { $OS='linux'; $CR=''; } |
296 | if ("$^O" !~ /linux/i && -d "/etc" && -d "/Users") { $OS='macosx'; $CR=''; } |
297 | if ("$^O" =~ /cygwin/i || "$^O" =~ /win32/i) { $OS='windows'; $CR="\r"; } |
298 | if (! $OS) { |
299 | print "configure.pl was not able to detect your OS. You must configure AWStats\n"; |
300 | print "manually following the setup documentation (docs/index.html).\n"; |
301 | print "configure.pl aborted.\n"; |
302 | exit 1; |
303 | } |
304 | |
305 | #print "Running OS detected: $OS (Perl $^[)\n"; |
306 | print "\n-----> Running OS detected: $OSLib{$OS}\n"; |
307 | |
308 | if ($OS eq 'linux') { |
309 | $AWSTATS_PATH=`pwd`; $AWSTATS_PATH =~ s/[\r\n]//; |
310 | $AWSTATS_PATH=~s/tools[\\\/]?$//; |
311 | $AWSTATS_PATH=~s/[\\\/]$//; |
312 | if ($AWSTATS_PATH ne '/usr/local/awstats') { |
313 | print "Warning: AWStats standard directory on Linux OS is '/usr/local/awstats'.\n"; |
314 | print "If you want to use standard directory, you should first move all content\n"; |
315 | print "of AWStats distribution from current directory:\n"; |
316 | print "$AWSTATS_PATH\n"; |
317 | print "to standard directory:\n"; |
318 | print "/usr/local/awstats\n"; |
319 | print "And then, run configure.pl from this location.\n"; |
320 | print "Do you want to continue setup from this NON standard directory [yN] ? "; |
321 | my $bidon=''; |
322 | while ($bidon !~ /^[yN]/i) { $bidon=<STDIN>; } |
323 | if ($bidon !~ /^y/i) { |
324 | print "configure.pl aborted.\n"; |
325 | exit 1; |
326 | } |
327 | $AWSTATS_ICON_PATH="$AWSTATS_PATH/wwwroot/icon"; |
328 | $AWSTATS_CSS_PATH="$AWSTATS_PATH/wwwroot/css"; |
329 | $AWSTATS_CLASSES_PATH="$AWSTATS_PATH/wwwroot/classes"; |
330 | $AWSTATS_CGI_PATH="$AWSTATS_PATH/wwwroot/cgi-bin"; |
331 | } |
332 | } |
333 | elsif ($OS eq 'macosx') { |
334 | $AWSTATS_PATH=`pwd`; $AWSTATS_PATH =~ s/[\r\n]//; |
335 | $AWSTATS_PATH=~s/tools[\\\/]?$//; |
336 | $AWSTATS_PATH=~s/[\\\/]$//; |
337 | if ($AWSTATS_PATH ne '/Library/WebServer/awstats') { |
338 | print "Warning: AWStats standard directory on Mac OS X is '/Library/WebServer/awstats'.\n"; |
339 | print "If you want to use standard directory, you should first move all content\n"; |
340 | print "of AWStats distribution from current directory:\n"; |
341 | print "$AWSTATS_PATH\n"; |
342 | print "to standard directory:\n"; |
343 | print "/Library/WebServer/awstats\n"; |
344 | print "And then, run configure.pl from this location.\n"; |
345 | print "Do you want to continue setup from this NON standard directory [yN] ? "; |
346 | my $bidon=''; |
347 | while ($bidon !~ /^[yN]/i) { $bidon=<STDIN>; } |
348 | if ($bidon !~ /^y/i) { |
349 | print "configure.pl aborted.\n"; |
350 | exit 1; |
351 | } |
352 | $AWSTATS_ICON_PATH="$AWSTATS_PATH/wwwroot/icon"; |
353 | $AWSTATS_CSS_PATH="$AWSTATS_PATH/wwwroot/css"; |
354 | $AWSTATS_CLASSES_PATH="$AWSTATS_PATH/wwwroot/classes"; |
355 | $AWSTATS_CGI_PATH="$AWSTATS_PATH/wwwroot/cgi-bin"; |
356 | } |
357 | } |
358 | elsif ($OS eq 'windows') { |
359 | # We do not use default values for awstats directives |
360 | # but thoose defined from AWSTATS_PATH |
361 | $AWSTATS_ICON_PATH="$AWSTATS_PATH/wwwroot/icon"; |
362 | $AWSTATS_CSS_PATH="$AWSTATS_PATH/wwwroot/css"; |
363 | $AWSTATS_CLASSES_PATH="$AWSTATS_PATH/wwwroot/classes"; |
364 | $AWSTATS_CGI_PATH="$AWSTATS_PATH/wwwroot/cgi-bin"; |
365 | } |
366 | |
367 | |
368 | |
369 | # Detect web server path |
370 | # ---------------------- |
371 | print "\n-----> Check for web server install\n"; |
372 | my %ApachePath=(); # All Apache path found (used on windows only) |
373 | my %ApacheConfPath=(); # All Apache config found |
374 | my $tips; |
375 | if ($OS eq 'linux' || $OS eq 'macosx') { |
376 | my $found=0; |
377 | foreach my $conf (@WEBCONF) { |
378 | if (-s "$conf") { |
379 | print " Found Web server Apache config file '$conf'\n"; |
380 | $ApacheConfPath{"$conf"}=++$found; |
381 | } |
382 | } |
383 | } |
384 | if ($OS eq 'windows' && "$^O" !~ /cygwin/i) { |
385 | $reg->Delimiter("/"); |
386 | if ($tips=$reg->{"LMachine/Software/Apache Group/Apache/"}) { |
387 | # If Apache registry call successfull |
388 | my $found=0; |
389 | foreach( sort keys %$tips ) { |
390 | my $path=$reg->{"LMachine/Software/Apache Group/Apache/$_/ServerRoot"}; |
391 | $path=~s/[\\\/]$//; |
392 | if (-d "$path" && -s "$path/conf/httpd.conf") { |
393 | print " Found a Web server Apache install in '$path'\n"; |
394 | $ApachePath{"$path"}=++$found; |
395 | $ApacheConfPath{"$path/conf/httpd.conf"}=++$found; |
396 | } |
397 | } |
398 | } |
399 | } |
400 | if (! scalar keys %ApacheConfPath) { |
401 | my $bidon=''; |
402 | |
403 | if ($OS eq 'windows') { |
404 | # Ask web server path (need to restart on windows) |
405 | print "$PROG did not find your Apache web main runtime.\n"; |
406 | |
407 | print "\nPlease, enter full directory path of your Apache web server or\n"; |
408 | print "'none' to skip this step if you don't have local web server or\n"; |
409 | print "don't have permission to change its setup.\n"; |
410 | print "Example: c:\\Program files\\apache group\\apache\n"; |
411 | while ($bidon ne 'none' && ! -d "$bidon") { |
412 | print "Apache Web server path ('none' to skip):\n> "; |
413 | $bidon=<STDIN>; chomp $bidon; |
414 | if ($bidon && ! -d "$bidon" && $bidon ne 'none') { print "- The directory '$bidon' does not exists.\n"; } |
415 | } |
416 | } |
417 | |
418 | if ($bidon ne 'none') { |
419 | if ($bidon) { $ApachePath{"$bidon"}=1; } |
420 | |
421 | print "\n".($bidon?"Now, enter":"Enter")." full config file path of your Web server.\n"; |
422 | print "Example: /etc/httpd/httpd.conf\n"; |
423 | print "Example: /usr/local/apache2/conf/httpd.conf\n"; |
424 | print "Example: c:\\Program files\\apache group\\apache\\conf\\httpd.conf\n"; |
425 | $bidon=''; |
426 | while ($bidon ne 'none' && ! -f "$bidon") { |
427 | print "Config file path ('none' to skip web server setup):\n> "; |
428 | $bidon=<STDIN>; chomp $bidon; |
429 | if ($bidon && ! -f "$bidon" && $bidon ne 'none') { print "- This file does not exists.\n"; } |
430 | } |
431 | if ($bidon ne 'none') { |
432 | $ApacheConfPath{"$bidon"}=1; |
433 | } |
434 | } |
435 | |
436 | } |
437 | |
438 | if (! scalar keys %ApacheConfPath) { |
439 | print "\n"; |
440 | print "Your web server config file(s) could not be found.\n"; |
441 | print "You will need to setup your web server manually to declare AWStats\n"; |
442 | print "script as a CGI, if you want to build reports dynamically.\n"; |
443 | print "See AWStats setup documentation (file docs/index.html)"; |
444 | print "\n"; |
445 | } |
446 | |
447 | # Open Apache config file |
448 | # ----------------------- |
449 | foreach my $key (keys %ApacheConfPath) { |
450 | print "\n-----> Check and complete web server config file '$key'\n"; |
451 | # Read config file to search for awstats directives |
452 | my $commonchangedtocombined=0; |
453 | READ: |
454 | $LogFormat{$key}=4; |
455 | open(CONF,"<$key") || error("Failed to open config file '$key' for reading"); |
456 | binmode CONF; |
457 | my $awstatsjsfound=0; |
458 | my $awstatsclassesfound=0; |
459 | my $awstatscssfound=0; |
460 | my $awstatsiconsfound=0; |
461 | my $awstatscgifound=0; |
462 | my $awstatsdirectoryfound=0; |
463 | while(<CONF>) |
464 | { |
465 | if ($_ =~ /^\s*CustomLog\s(.*)\scommon$/i) |
466 | { |
467 | print "Warning: You Apache config file contains directives to write 'common' log files\n"; |
468 | print "This means that some features can't work (os, browsers and keywords detection).\n"; |
469 | print "Do you want me to setup Apache to write 'combined' log files [y/N] ? "; |
470 | my $bidon=''; |
471 | while ($bidon !~ /^[yN]/i) { $bidon=<STDIN>; } |
472 | if ($bidon =~ /^y/i) { |
473 | close CONF; |
474 | update_httpd_config("$key"); |
475 | $WebServerChanged=1; |
476 | $commonchangedtocombined=1; |
477 | goto READ; |
478 | } |
479 | } |
480 | if ($_ =~ /^\s*CustomLog\s(.*)\scombined$/i) { $LogFormat{$key}=1; } |
481 | if ($_ =~ /Alias \/awstatsclasses/) { $awstatsclassesfound=1; } |
482 | if ($_ =~ /Alias \/awstatscss/) { $awstatscssfound=1; } |
483 | if ($_ =~ /Alias \/awstatsicons/) { $awstatsiconsfound=1; } |
484 | if ($_ =~ /ScriptAlias \/awstats\//) { $awstatscgifound=1; } |
485 | my $awstats_path_quoted=quotemeta($AWSTATS_PATH); |
486 | if ($_ =~ /Directory "$awstats_path_quoted\/wwwroot"/) { $awstatsdirectoryfound=1; } |
487 | } |
488 | close CONF; |
489 | |
490 | if ($awstatsclassesfound && $awstatscssfound && $awstatsiconsfound && $awstatscgifound && $awstatsdirectoryfound) |
491 | { |
492 | $UseAlias=1; |
493 | if ($commonchangedtocombined) { print " Common log files changed to combined.\n"; } |
494 | print " All AWStats directives are already present.\n"; |
495 | next; |
496 | } |
497 | |
498 | # Add awstats directives |
499 | open(CONF,">>$key") || error("Failed to open config file '$key' for adding AWStats directives"); |
500 | binmode CONF; |
501 | if (! $awstatsclassesfound || ! $awstatscssfound || ! $awstatsiconsfound || ! $awstatscgifound) { |
502 | print CONF "$CR\n"; |
503 | print CONF "#$CR\n"; |
504 | print CONF "# Directives to allow use of AWStats as a CGI$CR\n"; |
505 | print CONF "#$CR\n"; |
506 | } |
507 | if (! $awstatsclassesfound) { |
508 | print " Add 'Alias \/awstatsclasses \"$AWSTATS_CLASSES_PATH\/\"'\n"; |
509 | print CONF "Alias \/awstatsclasses \"$AWSTATS_CLASSES_PATH\/\"$CR\n"; |
510 | } |
511 | if (! $awstatscssfound) { |
512 | print " Add 'Alias \/awstatscss \"$AWSTATS_CSS_PATH\/\"'\n"; |
513 | print CONF "Alias \/awstatscss \"$AWSTATS_CSS_PATH\/\"$CR\n"; |
514 | } |
515 | if (! $awstatsiconsfound) { |
516 | print " Add 'Alias \/awstatsicons \"$AWSTATS_ICON_PATH\/\"'\n"; |
517 | print CONF "Alias \/awstatsicons \"$AWSTATS_ICON_PATH\/\"$CR\n"; |
518 | } |
519 | if (! $awstatscgifound) { |
520 | print " Add 'ScriptAlias \/awstats\/ \"$AWSTATS_CGI_PATH\/\"'\n"; |
521 | print CONF "ScriptAlias \/awstats\/ \"$AWSTATS_CGI_PATH\/\"$CR\n"; |
522 | } |
523 | if (! $awstatsdirectoryfound) { |
524 | print " Add '<Directory>' directive\n"; |
525 | print CONF "$CR\n"; |
526 | print CONF <<EOF; |
527 | # |
528 | # This is to permit URL access to scripts/files in AWStats directory. |
529 | # |
530 | <Directory "$AWSTATS_PATH/wwwroot"> |
531 | Options None |
532 | AllowOverride None |
533 | Order allow,deny |
534 | Allow from all |
535 | </Directory> |
536 | |
537 | EOF |
538 | } |
539 | close CONF; |
540 | $UseAlias=1; |
541 | $WebServerChanged=1; |
542 | print " AWStats directives added to Apache config file.\n"; |
543 | } |
544 | |
545 | # Define model config file path |
546 | # ----------------------------- |
547 | my $modelfile=''; |
548 | if ($OS eq 'linux') { |
549 | if (-f "$AWSTATS_PATH/wwwroot/cgi-bin/awstats.model.conf") { |
550 | $modelfile="$AWSTATS_PATH/wwwroot/cgi-bin/awstats.model.conf"; |
551 | } |
552 | else { |
553 | $modelfile="$AWSTATS_MODEL_CONFIG"; |
554 | if (! -s $modelfile || ! -w $modelfile) { $modelfile="$AWSTATS_PATH/wwwroot/cgi-bin/awstats.model.conf"; } |
555 | } |
556 | } |
557 | elsif ($OS eq "macosx") { |
558 | $modelfile="$AWSTATS_PATH/wwwroot/cgi-bin/awstats.model.conf"; |
559 | } |
560 | elsif ($OS eq 'windows') { $modelfile="$AWSTATS_PATH\\wwwroot\\cgi-bin\\awstats.model.conf"; } |
561 | else { $modelfile="$AWSTATS_PATH\\wwwroot\\cgi-bin\\awstats.model.conf"; } |
562 | |
563 | # Update model config file |
564 | # ------------------------ |
565 | if (-s $modelfile && -w $modelfile) { |
566 | print "\n-----> Update model config file '$modelfile'\n"; |
567 | %ConfToChange=(); |
568 | if ($OS eq 'linux' || $OS eq "macosx") { $ConfToChange{'DirData'}="$AWSTATS_DIRDATA_PATH"; } |
569 | elsif ($OS eq 'windows') { $ConfToChange{'DirData'}='.'; } |
570 | else { $ConfToChange{'DirData'}='.'; } |
571 | if ($UseAlias) { |
572 | $ConfToChange{'DirCgi'}='/awstats'; |
573 | $ConfToChange{'DirIcons'}='/awstatsicons'; |
574 | } |
575 | update_awstats_config("$modelfile"); |
576 | print " File awstats.model.conf updated.\n"; |
577 | } |
578 | |
579 | # Ask if we need to create a config file |
580 | #--------------------------------------- |
581 | my $site=''; |
582 | my $configfile=''; |
583 | print "\n-----> Need to create a new config file ?\n"; |
584 | print "Do you want me to build a new AWStats config/profile\n"; |
585 | print "file (required if first install) [y/N] ? "; |
586 | my $bidon=''; |
587 | while ($bidon !~ /^[yN]/i) { $bidon=<STDIN>; } |
588 | if ($bidon =~ /^y/i) { |
589 | |
590 | # Ask value for web site name |
591 | #---------------------------- |
592 | print "\n-----> Define config file name to create\n"; |
593 | print "What is the name of your web site or profile analysis ?\n"; |
594 | print "Example: www.mysite.com\n"; |
595 | print "Example: demo\n"; |
596 | ASKCONFIG: |
597 | my $bidon=''; |
598 | while (! $bidon) { |
599 | print "Your web site, virtual server or profile name:\n> "; |
600 | $bidon=<STDIN>; chomp $bidon; |
601 | if ($bidon =~ /\s/) { print " Space chars are not allowed.\n"; $bidon=''; } |
602 | } |
603 | $site=$bidon; |
604 | |
605 | # Define config file path |
606 | # ----------------------- |
607 | if ($OS eq 'linux') { |
608 | print "\n-----> Define config file path\n"; |
609 | print "In which directory do you plan to store your config file(s) ?\n"; |
610 | print "Default: /etc/awstats\n"; |
611 | my $bidon=''; |
612 | print "Directory path to store config file(s) (Enter for default):\n> "; |
613 | $bidon=<STDIN>; chomp $bidon; |
614 | if (! $bidon) { $bidon = "/etc/awstats"; } |
615 | my $configdir=$bidon; |
616 | if (! -d $configdir) { |
617 | # Create the directory for config files |
618 | my $mkdirok=mkdir "$configdir", 0755; |
619 | if (! $mkdirok) { error("Failed to create directory '$configdir', required to store config files."); } |
620 | } |
621 | $configfile="$configdir/awstats.$site.conf"; |
622 | } |
623 | elsif ($OS eq "macosx") { $configfile="$AWSTATS_PATH/wwwroot/cgi-bin/awstats.$site.conf"; } |
624 | elsif ($OS eq 'windows') { $configfile="$AWSTATS_PATH\\wwwroot\\cgi-bin\\awstats.$site.conf"; } |
625 | else { $configfile="$AWSTATS_PATH\\wwwroot\\cgi-bin\\awstats.$site.conf"; } |
626 | |
627 | if (-s "$configfile") { |
628 | print "Warning: A config file for this name already exists. Choose another one.\n"; |
629 | goto ASKCONFIG; |
630 | } |
631 | |
632 | # Create awstats.conf file |
633 | # ------------------------ |
634 | print "\n-----> Create config file '$configfile'\n"; |
635 | if (-s $configfile) { print " Config file already exists. No overwrite possible on existing config files.\n"; } |
636 | else { |
637 | %ConfToChange=(); |
638 | if ($OS eq 'linux' || $OS eq "macosx") { $ConfToChange{'DirData'}="$AWSTATS_DIRDATA_PATH"; } |
639 | if ($OS eq 'windows') { $ConfToChange{'DirData'}='.'; } |
640 | if ($UseAlias) { |
641 | $ConfToChange{'DirCgi'}='/awstats'; |
642 | $ConfToChange{'DirIcons'}='/awstatsicons'; |
643 | } |
644 | $ConfToChange{'SiteDomain'}="$site"; |
645 | my $sitewithoutwww=lc($site); $sitewithoutwww =~ s/^www\.//i; |
646 | $ConfToChange{'HostAliases'}="$sitewithoutwww www.$sitewithoutwww 127.0.0.1 localhost"; |
647 | update_awstats_config("$modelfile","$configfile"); |
648 | } |
649 | |
650 | } |
651 | |
652 | |
653 | # Restart Apache if change were made |
654 | # ---------------------------------- |
655 | if ($WebServerChanged) { |
656 | if ($OS eq 'linux') { |
657 | if (-f "/etc/debian_version") { |
658 | # We are on debian |
659 | my $command="/etc/init.d/apache restart"; |
660 | print "\n-----> Restart Web server with '$command'\n"; |
661 | my $ret=`$command`; |
662 | print "$ret"; |
663 | } elsif (-x "/sbin/service") { |
664 | # We are not on debian |
665 | my $command="/sbin/service httpd restart"; |
666 | print "\n-----> Restart Web server with '$command'\n"; |
667 | my $ret=`$command`; |
668 | print "$ret"; |
669 | } else { |
670 | print "\n-----> Don't forget to restart manually your web server\n"; |
671 | } |
672 | } |
673 | elsif ($OS eq 'macosx') { |
674 | print "\n-----> Restart Web server with '/usr/sbin/apachectl restart'\n"; |
675 | my $ret=`/usr/sbin/apachectl restart`; |
676 | print "$ret"; |
677 | } |
678 | elsif ($OS eq 'windows') { |
679 | foreach my $key (keys %ApachePath) { |
680 | if (-f "$key/bin/Apache.exe") { |
681 | print "\n-----> Restart Apache with '\"$key/bin/Apache.exe\" -k restart'\n"; |
682 | my $ret=`"$key/bin/Apache.exe" -k restart`; |
683 | } |
684 | } |
685 | } |
686 | else { |
687 | foreach my $key (keys %ApachePath) { |
688 | if (-f "$key/bin/Apache.exe") { |
689 | print "\n-----> Restart Apache with '\"$key/bin/Apache.exe\" -k restart'\n"; |
690 | my $ret=`"$key/bin/Apache.exe" -k restart`; |
691 | } |
692 | } |
693 | } |
694 | } |
695 | |
696 | |
697 | # TODO |
698 | # Scan logorate for a log file |
699 | # If apache log has a logrotate log found, we create a config and add line in prerotate |
700 | # prerotate |
701 | # ... |
702 | # endscript |
703 | # If not found |
704 | |
705 | |
706 | # Schedule awstats update process |
707 | # ------------------------------- |
708 | print "\n-----> Add update process inside a scheduler\n"; |
709 | if ($OS eq 'linux' || $OS eq "macosx") { |
710 | print "Sorry, configure.pl does not support automatic add to cron yet.\n"; |
711 | print "You can do it manually by adding the following command to your cron:\n"; |
712 | print "$AWSTATS_CGI_PATH/awstats.pl -update -config=".($site?$site:"myvirtualserver")."\n"; |
713 | print "Or if you have several config files and prefer having only one command:\n"; |
714 | print "$AWSTATS_PATH/tools/awstats_updateall.pl now\n"; |
715 | print "Press ENTER to continue... "; |
716 | $bidon=<STDIN>; |
717 | } |
718 | elsif ($OS eq 'windows') { |
719 | print "Sorry, for Windows users, if you want to have statistics to be\n"; |
720 | print "updated on a regular basis, you have to add the update process\n"; |
721 | print "in a scheduler task manually (See AWStats docs/index.html).\n"; |
722 | print "Press ENTER to continue... "; |
723 | $bidon=<STDIN>; |
724 | } |
725 | else { |
726 | print "Sorry, if you want to have statistics to be\n"; |
727 | print "updated on a regular basis, you have to add the update process\n"; |
728 | print "in a scheduler task manually (See AWStats docs/index.html).\n"; |
729 | print "Press ENTER to continue... "; |
730 | $bidon=<STDIN>; |
731 | } |
732 | |
733 | #print "\n-----> End of configuration\n"; |
734 | print "\n\n"; |
735 | if ($site) { |
736 | print "A SIMPLE config file has been created: $configfile\n"; |
737 | print "You should have a look inside to check and change manually main parameters.\n"; |
738 | print "You can then manually update your statistics for '$site' with command:\n"; |
739 | print "> perl awstats.pl -update -config=$site\n"; |
740 | if (scalar keys %ApacheConfPath) { |
741 | print "You can also read your statistics for '$site' with URL:\n"; |
742 | print "> http://localhost/awstats/awstats.pl?config=$site\n"; |
743 | } |
744 | else { |
745 | print "You can also build static report pages for '$site' with command:\n"; |
746 | print "> perl awstats.pl -output=pagetype -config=$site\n"; |
747 | } |
748 | print "\n"; |
749 | } |
750 | else { |
751 | print "No config file was built. You can run this tool later to build as\n"; |
752 | print "much config/profile files as you want.\n"; |
753 | print "Once you have a config/profile file, for example 'awstats.demo.conf',\n"; |
754 | print "You can manually update your statistics for 'demo' with command:\n"; |
755 | print "> perl awstats.pl -update -config=demo\n"; |
756 | if (scalar keys %ApacheConfPath) { |
757 | print "You can also read your statistics for 'demo' with URL:\n"; |
758 | print "> http://localhost/awstats/awstats.pl?config=demo\n"; |
759 | } |
760 | else { |
761 | print "You can also build static report pages for 'demo' with command:\n"; |
762 | print "> perl awstats.pl -output=pagetype -config=demo\n"; |
763 | } |
764 | print "\n"; |
765 | } |
766 | print "Press ENTER to finish...\n"; |
767 | $bidon=<STDIN>; |
768 | |
769 | |
770 | 0; # Do not remove this line |