~ubuntu-branches/ubuntu/edgy/awstats/edgy

« back to all changes in this revision

Viewing changes to tools/configure.pl

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2005-02-05 17:13:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050205171348-h8uy32bhbcnhciie
Tags: 6.3-1
* New upstream release. Closes: bug#293702, #293668 (thanks to Nelson
  A. de Oliveira <naoliv@biolinux.df.ibilce.unesp.br>).
  + Includes upstream fix for security bug fixed in 6.2-1.1.
  + Includes upstream fix for most of security bug fixed in 6.2-1.1.
* Acknowledge NMUs. Closes: bug#291064, #294488 (thanks to Martin
  Schulze <joey@infodrom.org>, Martin Pitt <mpitt@debian.org>, Ubuntu,
  Joey Hess <joeyh@debian.org>, Frank Lichtenheld <djpig@debian.org> and Steve
  Langasek <vorlon@debian.org>).
* Include patch for last parts of security bug fixed in 6.2-1.1:
  01_sanitize_more.patch.
* Patch (02) to include snapshot of recent development:
  + Fix security hole that allowed a user to read log file content
    even when plugin rawlog was not enabled.
  + Fix a possible use of AWStats for a DoS attack.
  + configdir option was broken on windows servers.
  + DebugMessages is by default set to 0 for security reasons.
  + Minor fixes.
* References:
  CAN-2005-0435 - read server logs via loadplugin and pluginmode
  CAN-2005-0436 - code injection via PluginMode
  CAN-2005-0437 - directory traversal via loadplugin
  CAN-2005-0438 - information leak via debug

Show diffs side-by-side

added added

removed removed

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