forked from nidebr/as-stats-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkgraph.php
122 lines (98 loc) · 2.96 KB
/
linkgraph.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
<?php
/*
* $Id$
*
* written by Manuel Kasper <[email protected]> for Monzoon Networks AG
*/
require_once('func.inc');
$numtop = 10;
$ascolors = get_palette();
$link = $_GET['link'];
if (!preg_match("/^[0-9a-zA-Z][0-9a-zA-Z\-_]+$/", $link))
die("Invalid link");
$v6_el = "";
if (@$_GET['v'] == 6)
$v6_el = "v6_";
$hours = 24;
if (@$_GET['numhours'])
$hours = (int)$_GET['numhours'];
$statsfile = statsFileForHours($hours);
if (@$_GET['v'] == 6) {
$topas = getasstats_top($numtop, $statsfile, array($_GET['link']), $list_asn = NULL, $v=6);
}else {
$topas = getasstats_top($numtop, $statsfile, array($_GET['link']));
}
/* now make a beautiful graph :) */
header("Content-Type: image/png");
$width = $default_graph_width;
$height = $default_graph_height;
if (@$_GET['width'])
$width = (int)$_GET['width'];
if (@$_GET['height'])
$height = (int)$_GET['height'];
$knownlinks = getknownlinks();
if ($compat_rrdtool12) {
/* cannot use full-size-mode - must estimate height/width */
$height -= 205;
$width -= 81;
}
$start = time() - $hours*3600;
$end = time();
$cmd = "$rrdtool graph - " .
"--slope-mode --alt-autoscale -u 0 -l 0 --imgformat=PNG --base=1000 --height=$height --width=$width " .
"--color BACK#ffffffff --color SHADEA#ffffff00 --color SHADEB#ffffff00 " .
"--start " . $start . " --end " . $end . " ";
if (!$compat_rrdtool12)
$cmd .= "--full-size-mode ";
if ($vertical_label) {
if($outispositive)
$cmd .= "--vertical-label '<- IN | OUT ->' ";
else
$cmd .= "--vertical-label '<- OUT | IN ->' ";
}
if($showtitledetail && @$_GET['dname'] != "")
$cmd .= "--title " . escapeshellarg($_GET['dname']) . " ";
else
if (isset($_GET['v']) && is_numeric($_GET['v']))
$cmd .= "--title IPv" . $_GET['v'] . " ";
/* geneate RRD DEFs */
foreach ($topas as $as => $traffic) {
$rrdfile = getRRDFileForAS($as);
$cmd .= "DEF:as{$as}_{$v6_el}in=\"$rrdfile\":{$link}_{$v6_el}in:AVERAGE ";
$cmd .= "DEF:as{$as}_{$v6_el}out=\"$rrdfile\":{$link}_{$v6_el}out:AVERAGE ";
}
/* generate a CDEF for each DEF to multiply by 8 (bytes to bits), and reverse for outbound */
foreach ($topas as $as => $traffic) {
if ($outispositive) {
$cmd .= "CDEF:as{$as}_{$v6_el}in_bits=as{$as}_{$v6_el}in,-8,* ";
$cmd .= "CDEF:as{$as}_{$v6_el}out_bits=as{$as}_{$v6_el}out,8,* ";
} else {
$cmd .= "CDEF:as{$as}_{$v6_el}in_bits=as{$as}_{$v6_el}in,8,* ";
$cmd .= "CDEF:as{$as}_{$v6_el}out_bits=as{$as}_{$v6_el}out,-8,* ";
}
}
/* generate graph area/stack for inbound */
$i = 0;
foreach ($topas as $as => $traffic) {
$asinfo = getASInfo($as);
$descr = str_replace(":", "\\:", utf8_decode($asinfo['descr']));
$cmd .= "AREA:as{$as}_{$v6_el}in_bits#{$ascolors[$i]}:\"AS{$as} ({$descr})\\n\"";
if ($i > 0)
$cmd .= ":STACK";
$cmd .= " ";
$i++;
}
/* generate graph area/stack for outbound */
$i = 0;
foreach ($topas as $as => $traffic) {
$cmd .= "AREA:as{$as}_{$v6_el}out_bits#{$ascolors[$i]}:";
if ($i > 0)
$cmd .= ":STACK";
$cmd .= " ";
$i++;
}
# zero line
$cmd .= "HRULE:0#00000080";
passthru($cmd);
exit;
?>