forked from poppyred/1.6.x
/
dnsperfs.php
executable file
·204 lines (168 loc) · 6.65 KB
/
dnsperfs.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
if(isset($_GET["verbose"])){$GLOBALS["VERBOSE"]=true;ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);ini_set('error_append_string',null);}
header("Pragma: no-cache");
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.groups.inc');
include_once('ressources/class.artica.inc');
include_once('ressources/class.ini.inc');
include_once('ressources/class.squid.inc');
include_once('ressources/class.system.network.inc');
include_once('ressources/class.ccurl.inc');
include_once('ressources/class.ActiveDirectory.inc');
include_once('ressources/class.system.nics.inc');
include_once('ressources/class.highcharts.inc');
if(isset($_GET["tabs"])){tabs();exit;}
if(isset($_GET["status"])){status();exit;}
if(isset($_GET["graph1"])){graph1();exit;}
if(isset($_GET["graph2"])){graph2();exit;}
if(isset($_GET["history"])){history();exit;}
if(isset($_GET["history-week"])){history_week();exit;}
js();
function js(){
header("content-type: application/x-javascript");
$page=CurrentPageName();
$tpl=new templates();
$title=$tpl->_ENGINE_parse_body("{dns_performance}");
echo "YahooWin6('900','$page?tabs=yes','$title')";
}
function tabs(){
$sock=new sockets();
$page=CurrentPageName();
$tpl=new templates();
$users=new usersMenus();
$q=new mysql();
$array["status"]='{status}';
$array["history"]='{history} {this_hour}';
$array["history-week"]='{history} {this_week}';
$fontsize=14;
while (list ($num, $ligne) = each ($array) ){
$tab[]="<li><a href=\"$page?$num=yes\"><span style='font-size:{$fontsize}px'>$ligne</span></a></li>\n";
}
echo build_artica_tabs($tab, "dnsperf-tabs");
}
function status(){
$sock=new sockets();
$page=CurrentPageName();
$tpl=new templates();
$minperf=$sock->GET_INFO("DNSPerfsPointer");
if(!is_numeric($minperf)){$minperf=301450;}
$minperfFloat=$minperf/10000;
$explain=$tpl->_ENGINE_parse_body("{dnsperf_explain}");
$explain=str_replace("%s", $minperfFloat, $explain);
$html="<div style='font-size:14px' class=explain>$explain</div>
<div style='width:97%' class=form>
";
$sql="SELECT * FROM dnsperfs";
$q=new mysql();
$results=$q->QUERY_SQL($sql,"artica_events");
while ($ligne = mysql_fetch_assoc($results)) {
$time=strtotime($ligne["zDate"]);
$took=distanceOfTimeInWords($time,time());
$html=$html."<div style='font-size:16px;margin:10px'><strong>{$ligne["dnsserver"]}</strong> {response_time} {$ligne["performance"]}ms/{$minperfFloat}ms ({$ligne["percent"]}% ) $took</div>";
}
$html=$html."</div>";
echo $tpl->_ENGINE_parse_body($html);
}
function history(){
$page=CurrentPageName();
$tpl=new templates();
$sql="SELECT * FROM dnsperfs";
$q=new mysql();
$results=$q->QUERY_SQL($sql,"artica_events");
while ($ligne = mysql_fetch_assoc($results)) {
$dnsserver=$ligne["dnsserver"];
$id=md5($dnsserver);
$f1[]="<div style='width:95%;height:230px' id='$id-1'></div>";
$f2[]="function FOne$id(){AnimateDiv('$id-1');Loadjs('$page?graph1=yes&container=$id-1&dnsserver=$dnsserver&graph1=yes',true);} setTimeout(\"FOne$id()\",500);";
}
echo @implode("\n", $f1)."<script>".@implode("\n", $f2)."</script>";
}
function history_week(){
$page=CurrentPageName();
$tpl=new templates();
$sql="SELECT * FROM dnsperfs";
$q=new mysql();
$results=$q->QUERY_SQL($sql,"artica_events");
while ($ligne = mysql_fetch_assoc($results)) {
$dnsserver=$ligne["dnsserver"];
$id=md5($dnsserver.time());
$f1[]="<div style='width:95%;height:230px' id='$id-2'></div>";
$f2[]="function FOne$id(){AnimateDiv('$id-2');Loadjs('$page?graph2=yes&container=$id-2&dnsserver=$dnsserver',true);} setTimeout(\"FOne$id()\",500);";
}
echo @implode("\n", $f1)."<script>".@implode("\n", $f2)."</script>";
}
function graph1(){
if(!class_exists("highcharts")){return ;}
$tpl=new templates();
$dnsserver=$_GET["dnsserver"];
$q=new mysql();
$sql="SELECT AVG(percent) as value,min,tdate
FROM (SELECT DATE_FORMAT(zDate,'%Y-%m-%d %H:00:00') as tdate,DATE_FORMAT(zDate,'%i') as `min`,
dnsserver,percent FROM `dnsperfs_week` WHERE zDate>DATE_SUB(NOW(),INTERVAL 1 HOUR) AND dnsserver='$dnsserver') as t
GROUP BY min,tdate ORDER BY tdate,min";
//echo "<H1>$sql</H1>";
$title="$dnsserver: {dnsperf_this_hour}";
$timetext="{minutes}";
$results=$q->QUERY_SQL($sql,"artica_events");
$count=mysql_num_rows($results);
if($count<2){
$sql="SELECT DATE_FORMAT(zDate,'%Y-%m-%d %H:00:00') as tdate,DATE_FORMAT(zDate,'%i') as `min`,
dnsserver, AVG(percent) as value FROM `dnsperfs_week` GROUP BY `min`,dnsserver HAVING
tdate=DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %H:00:00') AND dnsserver='$dnsserver' ORDER BY `min`";
}
while ($ligne = mysql_fetch_assoc($results)) {
$xdata[]=$ligne["min"];
$ydata[]=$ligne["value"];
$tdate=date("H",strtotime($ligne["tdate"]));
}
$timetext="{minutes}";
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->xAxis=$xdata;
$highcharts->Title=$title;
$highcharts->TitleFontSize="14px";
$highcharts->AxisFontsize="12px";
$highcharts->yAxisTtitle="{percent}";
$highcharts->xAxis_labels=false;
$highcharts->LegendPrefix="{$tdate}h";
$highcharts->xAxisTtitle=$timetext;
$highcharts->LegendSuffix="%";
$highcharts->datas=array($dnsserver=>$ydata);
$highcharts->OnErrorEvent=$sql;
echo $highcharts->BuildChart();
}
function graph2(){
if(!class_exists("highcharts")){return ;}
$tpl=new templates();
$dnsserver=$_GET["dnsserver"];
$q=new mysql();
$sql="SELECT DATE_FORMAT(zDate,'%Y-%m-%d') as tdate,DATE_FORMAT(zDate,'%d') as tday,DATE_FORMAT(zDate,'%H') as `min`,dnsserver,
AVG(percent) as value FROM `dnsperfs_week` GROUP BY `min`,dnsserver,tday
HAVING tdate<DATE_FORMAT(NOW(),'%Y-%m-%d') AND dnsserver='$dnsserver' ORDER BY tdate,`min`";
$title="$dnsserver: {this_week}";
$timetext="{minutes}";
$results=$q->QUERY_SQL($sql,"artica_events");
while ($ligne = mysql_fetch_assoc($results)) {
$xdata[]=$ligne["tday"]."/".$ligne["min"]."h";
$ydata[]=round($ligne["value"]);
}
$timetext="{hours}";
$highcharts=new highcharts();
$highcharts->container=$_GET["container"];
$highcharts->xAxis=$xdata;
$highcharts->Title=$title;
$highcharts->TitleFontSize="14px";
$highcharts->AxisFontsize="12px";
$highcharts->yAxisTtitle="{percent}";
$highcharts->xAxis_labels=false;
$highcharts->LegendPrefix="{day}";
$highcharts->xAxisTtitle=$timetext;
$highcharts->LegendSuffix="%";
$highcharts->datas=array($dnsserver=>$ydata);
echo $highcharts->BuildChart();
}