-
Notifications
You must be signed in to change notification settings - Fork 3
/
sqstat.php
105 lines (92 loc) · 2.72 KB
/
sqstat.php
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
<?php
/* *** sqstat - Squid Proxy Server realtime stat ***
(c) Alex Samorukov, [email protected]
*/
error_reporting(E_ALL);
DEFINE("SQSTAT_VERSION","1.20");
// loading sqstat class
include_once("sqstat.class.php");
$squidclass=new squidstat();
// loading configuration
if(is_file("config.inc.php")) {
include_once "config.inc.php";
// checking configuration. We need to have at least one
// squidhost/squid pair
if(!isset($_GET["config"])) $config=0;
else $config=(int)$_GET["config"];
if(!isset($squidhost[$config]) || !isset($squidport[$config])) {
$squidclass->errno=4;
$squidclass->errstr="Error in the configuration file.".
'Please, specify $squidhost['.$config.']/$squidport['.$config.']';
$squidclass->showError();
exit(4);
}
for($i=0;$i<count($squidhost);$i ){
$configs[$i]=$squidhost[$i].':'.$squidport[$i];
}
@$squidhost=$squidhost[$config];
@$squidport=$squidport[$config];
@$cachemgr_passwd=$cachemgr_passwd[$config];
@$resolveip=$resolveip[$config];
@$hosts_file=$hosts_file[$config];
if(isset($group_by[$config])) $group_by=$group_by[$config];
else $group_by="ip";
if(isset($group_by[$config]) && !preg_match('/^(host|username|username_or_host|username_and_host)$/',$group_by)) {
$squidclass->errno=4;
$squidclass->errstr="Error in the configuration file.<br>".
'"group_by" can be only "username", "username_or_host", "username_and_host" or "host"';
$squidclass->showError();
exit(4);
}
}
else{
$squidclass->errno=4;
$squidclass->errstr="Configuration file not found.".
"Please copy file <tt>config.inc.php.defauts</tt> to <tt>config.inc.php</tt> and edit configuration settings.";
$squidclass->showError();
exit(4);
}
// loading hosts file
$hosts_array=array();
if(isset($hosts_file)){
if(is_file($hosts_file)){
$handle = @fopen($hosts_file, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
unset($matches);
if(preg_match('/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})[ \t] (. )$/i',$buffer,$matches)){
$hosts_array[$matches[1]]=$matches[2];
}
}
fclose($handle);
}
else {
$squidclass->errno=4;
$squidclass->errstr="Hosts file not found.".
"Cant read <tt>'$hosts_file'</tt>.";
$squidclass->showError();
exit(4);
}
}
else {
$squidclass->errno=4;
$squidclass->errstr="Hosts file not found.".
"Cant read <tt>'$hosts_file'</tt>.";
$squidclass->showError();
exit(4);
}
}
if(!$squidclass->connect($squidhost,$squidport)) {
$squidclass->showError();
exit(1);
}
$data=$squidclass->makeQuery($cachemgr_passwd);
if($data==false){
$squidclass->showError();
exit(2);
}
// print_r($data);
if(!isset($use_js)) $use_js=true;
echo $squidclass->makeHtmlReport($data,$resolveip,$hosts_array,$use_js);
?>