-
Notifications
You must be signed in to change notification settings - Fork 4
/
check-setup.pl
executable file
·159 lines (126 loc) · 6.53 KB
/
check-setup.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/perl
print "LightSquid Config Checker, (c) 2005-9 Sergey Erokhin GNU GPL\n\n";
die "perl module File::Basename not found, please install !\n" if (!eval { require File::Basename });
use File::Basename;push (@INC,(fileparse($0))[1]);
die "can't access to lightsquid.cfg !!!\n" if (!eval { require "lightsquid.cfg" });
die "can't access to common.pl !!!\n" if (!eval { require "common.pl" });
die "no: CGI.PM found, please install\n" if (!eval { require CGI });
die "can't access to $logpath `access.log` file\ncheck \$logpath variable or privilege\n" unless (-f "$logpath/access.log");
die "Invalid access.log format or can't check format type ...\n" if (CheckLogType("$logpath/access.log"));
print "LogPath : $logpath\n";
open F,"<$logpath/access.log" or die "can't access to `access.log` file, check privilege\n";
close F;
print "reportpath: $reportpath\n";
die "can't found report folder `$reportpath`\nplease check \$reportpath variable, create if need\n" unless (-d "$reportpath");
open F,">$reportpath/test.txt" or die "can't create file in $reportpath folder, check privilege\n";
close F;
unlink "$reportpath/test.txt";
print "Lang : $langpath/$lang\n";
open F,"<$langpath/$lang.lng" or die "can't open language file $langpath/$lang.lng, check \$lang variable\n";
close F;
print "Template : $tplpath/$templatename\n";
open F,"<$tplpath/$templatename/index.html" or die "can't open template $tplpath/$templatename folder, check \$templatename variable\n";
close F;
print "Ip2Name : $ip2namepath/ip2name.$ip2name\n";
open F,"<$ip2namepath/ip2name.$ip2name" or die "can't open file $ip2namepath/ip2name.$ip2name file, check \$ip2name variable\n";
close F;
print "\n";
die "\$skipurl variable empty !, read documentation !!!\n" if ($skipurl eq "");
if ($graphreport) {
die "no: GD.PM found, please install or set \$graphreport=0 to disable\n" if (!eval { require GD });
require GD;
die "no: GD::Polygon modules, please install or set \$graphreport=0 to disable\n" if (!eval { my $poly1 = new GD::Polygon });
die "no: GD trouble, please install or set \$graphreport=0 to disable\n" if (!eval { $im = new GD::Image(720,480) });
if ($ttffont ne "") {
die "can't access to TTF font $font file, check \$font variable or set \$ttffont = \"\" to disable\n" unless (-f $ttffont);
die "no: TTF support in GD, please install, or set \$ttffont = \"\" to disable\n" if (!eval { $im = new GD::Image(720,480) ;$im->stringFT(0,$ttffont,7,0.0,0,437,"Hello World") });
}
die "Variable \$graphmaxuser should be >0 !!!\n" if ($graphmaxuser == 0);
die "Variable \$graphmaxall should be >0 !!!\n" if ($graphmaxall == 0);
}
#check $skipurl, warning if they contain . char
if ($skipurl =~ m/\./) {
$tmp=$skipurl;
$skipurl =~ s/\\\.//gs;
if ($skipurl =~ m/\./) {
print "WARNING: \$skipurl variable contain unescaped '.' char !!!\n";
print "WARNING: if you use \. as regular expression metacharacter please use '' instead \"\" and escape . via \\\. \n";
print "WARNING: \$skipurl now ->$tmp<\n";
}
}
print "\nall check passed, now try access to cgi part in browser\n";
sub CheckLogType($) {
my $LogFile = shift;
my @a;
my $EmulatedFormat1 = 0;
my $EmulatedFormat2 = 0;
my $NativeFormat1 = 0;
my $NativeFormat2 = 0;
my $TestedLine = 0;
my $ret = 0;
my @LogName;
$LogName[0] ="Native";
$LogName[1] ="Emulated";
my $warning;
# print "FILE: $LogFile\n";
unless ( -z $LogFile ) {
open FLOG, "<", "$LogFile";
while (<FLOG>) {
chomp;
$line=$_;
next if ( $line eq "" );
$TestedLine++;
@a = split /\s+/, $line;
$NativeFormat1++ if ( ( $a[0] = ~ m/\d+\.\d+/ ) and ( $a[1] =~ m/\d+/ ) and ( $a[4] =~ m/\d+/ ) );
# 0 1 2 3 4 5
#970313965.619 1249 denis.local TCP_MISS/200 2598 GET http://www.emalecentral.com/tasha/thm_4374x013.jpg - DIRECT/www.emalecentral.com image/jpeg
# timestamp elapsed host type size method url user hierarechy type
#1125191043.218 3 192.168.1.240 TCP_DENIED/403 1411 GET http://ar.atwola.com/image/93159194/icq - NONE/- text/html
#1125191043.219 0 192.168.1.240 TCP_DENIED/403 1403 GET http://ar.atwola.com/file/adsEnd.js - NONE/- text/html
$NativeFormat2++ if ( ($#a == 9) );
#emulated httpd log
# 0 1 2 3 4 5
#192.168.3.40 - - [15/Apr/2005:11:46:35 +0300] "GET http://mail.yandex.ru/mboxjscript? HTTP/1.0" 200 2262 TCP_MISS :DIRECT
$EmulatedFormat1++ if ( ( $a[3] = ~ m/\[\d{1,2}\// ) and ( $a[4] =~ m/\d{1,4}\]/ ) and ( $a[5] =~ m/\"/ ) );
# 192.168.3.40 - - [15 /Apr /2005 :11 :46 :35 +0300] "GET http://mail.yandex.ru/mboxjscript? HTTP/1.0" 200 2262 TCP_MISS :DIRECT
$EmulatedFormat2++ if ( $line =~ m/^(\d{1,3}\.){3}\d{1,3}\s+\S+\s+\S+\s\[\d{1,2}\/\S{1,3}\/\d{4}\:\d{1,2}\:\d{1,2}\:\d{1,2}\s[+-]\d{1,4}\] \".*\S+\:\S+$/);
}
close FLOG;
if ( $TestedLine == 0 ) {
die "WARNING: log file is empty!, can't check log file format !!!!!\n";
}
$n1 = Percent( $TestedLine, $NativeFormat1 );
$n2 = Percent( $TestedLine, $NativeFormat2 );
$e1 = Percent( $TestedLine, $EmulatedFormat1 );
$e2 = Percent( $TestedLine, $EmulatedFormat2 );
if ($debug) {
print "dbg: tested : $TestedLine\n";
print "dbg: native1 : $NativeFormat1 :: $n1\n";
print "dbg: native2 : $NativeFormat2 :: $n2\n";
print "dbg: emulate1: $EmulatedFormat1 :: $e1\n";
print "dbg: emulate2: $EmulatedFormat2 :: $e2\n";
}
if ( $e1 > 90 ) {
$detected = 1;
$warning = "Log format Look like CUSTOM log, Lightsquid can't parse this format! Please check documentation !" if ( $e2 < 60 );
}
if ( $n1 > 90 ) {
$detected = 0;
$warning = "Log format Look like CUSTOM log, Lightsquid can't parse this format! Please check documentation !" if ( $n2 < 60 ) ;
}
} else {
$warning="log file is empty!, can't check log file format !!!!!\n";
}
if ( $detected != $squidlogtype ) {
print "WARNING: \$squidlogtype=$squidlogtype in lightsquid.conf, it's mean expected log type is '$LogName[$squidlogtype]'\n";
print "WARNING: but your access.log look like `$type`, please correct config file -> `\$squidlogtype=$detected`\n";
$ret=1;
}
if ( $warning ne "" ) { $ret=1;print "WARNING: $warning\n"};
return $ret;
}
sub Percent($$) {
my $total = shift;
my $val1 = shift;
return sprintf( "%.2f", ( $val1 * 100 ) / $total );
}