/
iptaccount.stats.php
370 lines (305 loc) · 14 KB
/
iptaccount.stats.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
include_once('ressources/class.artica.graphs.inc');
include_once('ressources/class.templates.inc');
include_once('ressources/class.html.pages.inc');
include_once('ressources/class.system.network.inc');
include_once('ressources/class.mysql.inc');
include_once('ressources/class.tcpip.inc');
$users=new usersMenus();
if(!$users->AsSystemAdministrator){die();}
if(isset($_GET["stats-tabs"])){tabs();exit;}
if(isset($_GET["stats-hour"])){stats_gen_hour();exit;}
if(isset($_GET["stats-day"])){stats_gen_day();exit;}
if(isset($_GET["stats-week"])){stats_gen_week();exit;}
if(isset($_GET["stats-month"])){stats_gen_month();exit;}
if(isset($_GET["detail-ipaddr"])){details_addr_js();exit;}
if(isset($_GET["detail-ipaddr-show"])){details_addr_popup();exit;}
page();
function details_addr_js(){
$array_src["src_bytes"]="{outgoing}";
$array_src["dst_bytes"]="{tcp_incoming}";
$array_T["H"]="{this_hour}";
$array_T["D"]="{last_24h}";
$array_T["W"]="{this_week}";
$array_T["M"]="{this_month}";
$t1=$array_src[$_GET["flow"]];
$t2=$array_T[$_GET["t"]];
$title="{$_GET["ipaddr"]}»$t1»$t2";
$page=CurrentPageName();
$tpl=new templates();
$title=$tpl->_ENGINE_parse_body($title);
$html="YahooWin2(700,'$page?detail-ipaddr-show=yes&rule-id={$_GET["rule-id"]}&t={$_GET["t"]}&flow={$_GET["flow"]}&ipaddr={$_GET["ipaddr"]}','$title');";
echo $html;
}
function details_addr_popup(){
$page=CurrentPageName();
$tpl=new templates();
$array_src["src_bytes"]="{outgoing}";
$array_src["dst_bytes"]="{tcp_incoming}";
$array_T["H"]="{this_hour}";
$array_T["D"]="{last_24h}";
$array_T["W"]="{this_week}";
$array_T["M"]="{this_month}";
$t1=$array_src[$_GET["flow"]];
$t2=$array_T[$_GET["t"]];
$title="{$_GET["ipaddr"]}»$t1»$t2";
if($_GET["t"]=="H"){
$sql="SELECT {$_GET["flow"]} AS tflow,
ipaddr,
DATE_FORMAT(zDate,'%H:%i') as tdate
FROM tcp_account_events
WHERE ipaddr='{$_GET["ipaddr"]}' AND zDate>=DATE_SUB(NOW(),INTERVAL 1 HOUR) AND rule_id={$_GET["rule-id"]} ORDER by tdate";
$label_title="{minutes}";
}
if($_GET["t"]=="D"){
$sql="SELECT SUM({$_GET["flow"]}) AS tflow, ipaddr,
DATE_FORMAT(zDate,'%d/%Hh') as tdate FROM tcp_account_events
WHERE ipaddr='{$_GET["ipaddr"]}' AND zDate>=DATE_SUB(NOW(),INTERVAL 24 HOUR) AND rule_id={$_GET["rule-id"]}
GROUP BY ipaddr,DATE_FORMAT(zDate,'%Hh') ORDER by tdate";
$label_title="{hours}";
}
if($_GET["t"]=="W"){
$sql="SELECT SUM({$_GET["flow"]}) AS tflow, ipaddr,
DATE_FORMAT(zDate,'%d') as tdate FROM tcp_account_events
WHERE ipaddr='{$_GET["ipaddr"]}' AND WEEK(zDate)=WEEK(NOW()) AND rule_id={$_GET["rule-id"]}
GROUP BY ipaddr,DATE_FORMAT(zDate,'%d') ORDER by tdate";
$label_title="{days}";
}
if($_GET["t"]=="M"){
$sql="SELECT SUM({$_GET["flow"]}) AS tflow, ipaddr,
DATE_FORMAT(zDate,'%d') as tdate FROM tcp_account_events
WHERE ipaddr='{$_GET["ipaddr"]}' AND MONTH(zDate)=MONTH(NOW()) AND rule_id={$_GET["rule-id"]}
GROUP BY ipaddr,DATE_FORMAT(zDate,'%d') ORDER by tdate";
$label_title="{days}";
}
$q=new mysql();
$results=$q->QUERY_SQL($sql,"artica_events");
$count=mysql_num_rows($results);
writelogs($count." rows",__FUNCTION__,__FILE__,__LINE__);
echo $tpl->_ENGINE_parse_body("<center style='font-size:16px;margin:5px'>$title</center>");
if(mysql_num_rows($results)<2){
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("<H2>{NO_DATA_COME_BACK_LATER}</H2>");
return;
}
$filename="iptaccount.{$_GET["rule-id"]}.{$_GET["t"]}.{$_GET["flow"]}.{$_GET["ipaddr"]}.png";
$gp=new artica_graphs(dirname(__FILE__)."/ressources/logs/web/$filename",0);
if(!$q->ok){echo $q->mysql_error;}
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$xdata[]=$ligne["tdate"];
$ziz=round($ligne["tflow"]/1024);
$ziz=$ziz/1000;
$ydata[]=$ziz;
}
$gp->xdata=$xdata;
$gp->width=600;
$gp->height=550;
$gp->ydata=$ydata;
$gp->y_title="MB";
$gp->x_title=$label_title;
$gp->title=null;
$gp->Fillcolor="blue@0.9";
$gp->color="146497";
$gp->line_green();
echo "<img src='ressources/logs/web/$filename'>";
}
function page(){
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql();
$sql="SELECT rulename,ID FROM tcp_account_rules";
$results=$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){$rules[$ligne["ID"]]=$ligne["rulename"];}
$array_src["src_bytes"]="{outgoing}";
$array_src["dst_bytes"]="{tcp_incoming}";
$html="
<center>
<table style='width:60%' class=form>
<tr>
<td class=legend>{rules}</td>
<td>". Field_array_Hash($rules, "rule-selected","script:font-size:16px;padding:3px")."</td>
<td>". Field_array_Hash($array_src, "flow","script:font-size:16px;padding:3px")."</td>
<td>". button("{view}","RefreshIptAccountStats()")."</td>
</tr>
</table>
</center>
<div id='iptaccount-stats' style='width:100%;height:550px;overflow:auto'></div>
<script>
function RefreshIptAccountStats(){
LoadAjax('iptaccount-stats','$page?stats-tabs=yes&rule-id='+document.getElementById('rule-selected').value+'&flow='+document.getElementById('flow').value);
}
RefreshIptAccountStats();
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
function tabs(){
$array_src["dst_bytes"]="{tcp_incoming}";
$array_src["src_bytes"]="{outgoing}";
$flow_text=$array_src[$_GET["flow"]];
$rule_id=$_GET["rule-id"];
$page=CurrentPageName();
$tpl=new templates();
$array["stats-hour"]="$flow_text:{this_hour}";
$array["stats-day"]="$flow_text:{last_24h}";
$array["stats-week"]="$flow_text:{this_week}";
$array["stats-month"]="$flow_text:{this_month}";
while (list ($num, $ligne) = each ($array) ){
$html[]= $tpl->_ENGINE_parse_body("<li><a href=\"$page?$num=yes&rule-id=$rule_id&flow={$_GET["flow"]}\"><span>$ligne</span></a></li>\n");
}
echo "
<div id=main_config_iptaccount_stats_$rule_id style='width:99%;height:500px;overflow:auto'><ul>". implode("\n",$html)."</ul></div>
<script>
$(document).ready(function() {
$(\"#main_config_iptaccount_stats_$rule_id\").tabs();});
</script>";
}
function stats_gen_hour(){
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql();
$array_src["dst_bytes"]="{tcp_incoming}";
$array_src["src_bytes"]="{outgoing}";
$flow_text=$array_src[$_GET["flow"]];
//dst_bytes = statistics in bytes for "incoming" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
// src_bytes =statistics in bytes for "outgoing" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
$sql="SELECT SUM({$_GET["flow"]}) as tflow,ipaddr FROM tcp_account_events
WHERE zDate>=DATE_SUB(NOW(),INTERVAL 1 HOUR) AND rule_id={$_GET["rule-id"]} GROUP BY ipaddr ORDER BY tflow DESC";
$results=$q->QUERY_SQL($sql,"artica_events");
if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
$html="<center>
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:50%'>
<thead class='thead'>
<tr>
<th colspan=2 >{ipaddr}</th>
<th colspan=4>$flow_text</th>
</tr>
</thead>
<tbody class='tbody'>";
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
if($ligne["tflow"]==0){continue;}
$k=$ligne["tflow"]/1024;
$size=FormatBytes($k);
$href="<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('$page?detail-ipaddr=yes&rule-id={$_GET["rule-id"]}&t=H&flow={$_GET["flow"]}&ipaddr={$ligne["ipaddr"]}');\" style='font-size:14px;font-weight:bold;text-decoration:underline'>";
$html=$html."<tr class=$classtr>
<td width=1%><img src='img/folder-network-32.png'></td>
<td width=1%><strong style='font-size:14px'>$href{$ligne["ipaddr"]}</a></td>
<td width=99%><strong style='font-size:14px'>$size</td>
</tr>";
}
$html=$html."</table>";
echo $tpl->_ENGINE_parse_body($html);
}
function stats_gen_day(){
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql();
$array_src["dst_bytes"]="{tcp_incoming}";
$array_src["src_bytes"]="{outgoing}";
$flow_text=$array_src[$_GET["flow"]];
//dst_bytes = statistics in bytes for "incoming" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
// src_bytes =statistics in bytes for "outgoing" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
$sql="SELECT SUM({$_GET["flow"]}) as tflow,ipaddr FROM tcp_account_events
WHERE DATE_FORMAT(zDate,'%Y-%m-%d')=DATE_FORMAT(NOW(),'%Y-%m-%d') AND rule_id={$_GET["rule-id"]} GROUP BY ipaddr ORDER BY tflow DESC";
$results=$q->QUERY_SQL($sql,"artica_events");
if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
$html="<center>
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:50%'>
<thead class='thead'>
<tr>
<th colspan=2 >{ipaddr}</th>
<th colspan=4>$flow_text</th>
</tr>
</thead>
<tbody class='tbody'>";
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
if($ligne["tflow"]==0){continue;}
$k=$ligne["tflow"]/1024;
$size=FormatBytes($k);
$href="<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('$page?detail-ipaddr=yes&rule-id={$_GET["rule-id"]}&t=D&flow={$_GET["flow"]}&ipaddr={$ligne["ipaddr"]}');\" style='font-size:14px;font-weight:bold;text-decoration:underline'>";
$html=$html."<tr class=$classtr>
<td width=1%><img src='img/folder-network-32.png'></td>
<td width=1%><strong style='font-size:14px'>$href{$ligne["ipaddr"]}</a></td>
<td width=99%><strong style='font-size:14px'>$size</td>
</tr>";
}
$html=$html."</table>";
echo $tpl->_ENGINE_parse_body($html);
}
function stats_gen_week(){
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql();
$array_src["dst_bytes"]="{tcp_incoming}";
$array_src["src_bytes"]="{outgoing}";
$flow_text=$array_src[$_GET["flow"]];
//dst_bytes = statistics in bytes for "incoming" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
// src_bytes =statistics in bytes for "outgoing" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
$sql="SELECT SUM({$_GET["flow"]}) as tflow,ipaddr FROM tcp_account_events
WHERE WEEK(zDate)=WEEK(NOW()) AND rule_id={$_GET["rule-id"]} GROUP BY ipaddr ORDER BY tflow DESC";
$results=$q->QUERY_SQL($sql,"artica_events");
if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
$html="<center>
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:50%'>
<thead class='thead'>
<tr>
<th colspan=2 >{ipaddr}</th>
<th colspan=4>$flow_text</th>
</tr>
</thead>
<tbody class='tbody'>";
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
if($ligne["tflow"]==0){continue;}
$k=$ligne["tflow"]/1024;
$size=FormatBytes($k);
$href="<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('$page?detail-ipaddr=yes&rule-id={$_GET["rule-id"]}&t=W&flow={$_GET["flow"]}&ipaddr={$ligne["ipaddr"]}');\" style='font-size:14px;font-weight:bold;text-decoration:underline'>";
$html=$html."<tr class=$classtr>
<td width=1%><img src='img/folder-network-32.png'></td>
<td width=1%><strong style='font-size:14px'>$href{$ligne["ipaddr"]}</a></td>
<td width=99%><strong style='font-size:14px'>$size</td>
</tr>";
}
$html=$html."</table>";
echo $tpl->_ENGINE_parse_body($html);
}
function stats_gen_month(){
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql();
$array_src["dst_bytes"]="{tcp_incoming}";
$array_src["src_bytes"]="{outgoing}";
$flow_text=$array_src[$_GET["flow"]];
//dst_bytes = statistics in bytes for "incoming" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
// src_bytes =statistics in bytes for "outgoing" traffic of that host. Field is followed by five numbers. The first number is the total, the second one is TCP, the third one UDP, the fourth one is ICMP and finally the fifth one is traffic for all other protocols
$sql="SELECT SUM({$_GET["flow"]}) as tflow,ipaddr FROM tcp_account_events
WHERE MONTH(zDate)=MONTH(NOW()) AND rule_id={$_GET["rule-id"]} GROUP BY ipaddr ORDER BY tflow DESC";
$results=$q->QUERY_SQL($sql,"artica_events");
if(!$q->ok){echo "<H2>$q->mysql_error</H2>";}
$html="<center>
<table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:50%'>
<thead class='thead'>
<tr>
<th colspan=2 >{ipaddr}</th>
<th colspan=4>$flow_text</th>
</tr>
</thead>
<tbody class='tbody'>";
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
if($ligne["tflow"]==0){continue;}
$k=$ligne["tflow"]/1024;
$href="<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('$page?detail-ipaddr=yes&rule-id={$_GET["rule-id"]}&t=M&flow={$_GET["flow"]}&ipaddr={$ligne["ipaddr"]}');\" style='font-size:14px;font-weight:bold;text-decoration:underline'>";
$size=FormatBytes($k);
$html=$html."<tr class=$classtr>
<td width=1%><img src='img/folder-network-32.png'></td>
<td width=1%><strong style='font-size:14px'>$href{$ligne["ipaddr"]}</a></td>
<td width=99%><strong style='font-size:14px'>$size</td>
</tr>";
}
$html=$html."</table>";
echo $tpl->_ENGINE_parse_body($html);
}