-
Notifications
You must be signed in to change notification settings - Fork 9
/
entrypoint.pl
executable file
·138 lines (123 loc) · 3.76 KB
/
entrypoint.pl
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
#!/usr/bin/perl
use strict;
use warnings;
sub env_default {
return defined $ENV{$_[0]} ? $ENV{$_[0]} : $_[1];
}
sub aw_re_ip {
my $re = '';
foreach my $r (@_) {
$re = $re . "REGEX[$r] "
}
return "$re"
}
my $log_files = join(' ', @ARGV);
chomp($log_files);
my $log_format = env_default('LOG_FORMAT', '');
my $site_domain = env_default('SITE_DOMAIN', 'localhost');
my $skip_user_agents = env_default('SKIP_USER_AGENTS', 'Travis Hudson');
my @skip_hosts_re = ();
if (defined $ENV{'SKIP_HOSTS'}) {
unless ($ENV{'SKIP_HOSTS'} =~ /^\s*$/) {
@skip_hosts_re = split / /, $ENV{'SKIP_HOSTS'};
}
}
else {
@skip_hosts_re = (
'^127\.',
'^192\.168\.',
'^172\.(1[6-9]|2[0-9]|3[01])\.',
'^10\.',
'^54\.172\.141\.90$',
'^52\.3\.133\.20$',
'^52\.45\.220\.64$',
'^52\.54\.40\.118$',
'^54\.89\.89\.104$',
'^54\.82\.137\.203$',
'^52\.0\.240\.122$',
'^52\.22\.60\.255$',
'^52\.45\.185\.117$',
'^52\.54\.31\.11$',
'^54\.87\.185\.35$',
'^54\.87\.141\.246$',
'^208\.78\.110\.19[2-9]$',
'^208\.78\.110\.20[01][0-9]$',
'^208\.78\.110\.22[0-3]$',
);
}
if (defined $ENV{'SKIP_HOSTS_ADDITIONAL'}) {
unless ($ENV{'SKIP_HOSTS_ADDITIONAL'} =~ /^\s*$/) {
my @skip_hosts_re_additional = split / /, $ENV{'SKIP_HOSTS_ADDITIONAL'};
@skip_hosts_re = (@skip_hosts_re, @skip_hosts_re_additional);
}
}
my $filein = "/etc/awstats/awstats.model.conf";
my $fileout = "/etc/awstats/awstats.$site_domain.conf";
if (-e $fileout) {
print "Configuration already exists: $fileout\n";
}
else {
print "Creating configuration $fileout\n";
open(my $IN, $filein) or die "Failed to open $filein for reading";
open(my $OUT, '>', $fileout) or die "Failed to open $fileout for writing";;
while (<$IN>) {
if (/^LogFile=/) {
print $OUT "LogFile=/dev/null\n";
}
elsif ($log_format && /^LogFormat=/) {
print $OUT "LogFormat = $log_format\n";
}
elsif (/^SiteDomain=/) {
print $OUT "SiteDomain=\"$site_domain\"\n";
}
elsif (/^AllowFullYearView=/) {
print $OUT "AllowFullYearView=3\n";
}
elsif (/^BuildReportFormat=/) {
print $OUT "BuildReportFormat=xhtml\n";
}
elsif (/^Expires=/) {
print $OUT "Expires=3600\n";
}
elsif (/^FirstDayOfWeek=/) {
print $OUT "FirstDayOfWeek=1\n";
}
elsif (/^SkipHosts=/) {
print $OUT "SkipHosts=\"" . aw_re_ip(@skip_hosts_re) . "\"\n";
}
elsif (/^SkipUserAgents=/) {
print $OUT "SkipUserAgents=\"$skip_user_agents\"\n";
}
# AllowToUpdateStatsFromBrowser=1
else {
print $OUT $_;
}
}
print $OUT "LoadPlugin=\"geoip GEOIP_STANDARD /opt/GeoIP/GeoIP.dat\"\n";
print $OUT "LoadPlugin=\"geoip_city_maxmind GEOIP_STANDARD /opt/GeoIP/GeoLiteCity.dat\"\n";
}
if ($log_files eq 'httpd') {
print "Starting httpd awstats\n";
exec "/usr/sbin/httpd", "-DFOREGROUND";
}
else {
print "Updating log statistics\n";
# See /usr/share/awstats/wwwroot/cgi-bin/awstats.pl --help
my @args = (
"/usr/share/awstats/wwwroot/cgi-bin/awstats.pl",
"-config=$site_domain",
"-update",
"-showsteps",
"-showcorrupted",
"-showdropped",
"-showunknownorigin"
);
if ($log_files) {
# If using an external configuration file it may define LogFile
push @args, "-LogFile=/usr/share/awstats/tools/logresolvemerge.pl $log_files |"
}
else {
print "No logfiles on command line, using LogFile from $site_domain configuration file \n"
}
exec @args;
}