Skip to content

Commit 902d626

Browse files
author
Nicolas Debrigode
committed
Add old linkusage page (at the request of users)
1 parent b57ba64 commit 902d626

File tree

5 files changed

+244
-4
lines changed

5 files changed

+244
-4
lines changed

func.inc

+28
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ function menu($selected_links) {
277277
$active_searchas = $dpagename == "history" ? 'class="active"' : "";
278278
$active_searchasset = $dpagename == "asset" ? 'class="active"' : "";
279279
$active_ix = $dpagename == "ix" ? 'class="active"' : "";
280+
$active_linkusage = $dpagename == "linkusage" ? 'class="active"' : "";
280281

281282
$return = '<header class="main-header">';
282283
$return .= '<nav class="navbar navbar-static-top">';
@@ -308,6 +309,20 @@ function menu($selected_links) {
308309
$return .='<li '.$active_searchas.'><a href="history.php">View AS</a></li>';
309310
$return .='<li '.$active_searchasset.'><a href="asset.php">View AS-SET</a></li>';
310311
$return .='<li '.$active_ix.'><a href="ix.php">View IX Stats</a></li>';
312+
//$return .='<li '.$active_linkusage.'><a href="linkusage.php">Link Usage</a></li>';
313+
314+
if ( count($top_intervals) < 2 ) {
315+
$return .= '<li '.$active_linkusage.'><a href="linkusage.php">Link Usage</a></li>';
316+
} else {
317+
$return .= '<li class="dropdown '.$active_linkusage.'">';
318+
$return .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Link Usage <span class="caret"></span></a>';
319+
$return .= '<ul class="dropdown-menu" role="menu">';
320+
foreach ($top_intervals as $interval) {
321+
$return .= '<li><a href="linkusage.php?numhours=' . $interval['hours'] . '">Link Usage - ' . $interval['label'] . '</a></li>';
322+
}
323+
$return .= '</ul>';
324+
$return .= '</li>';
325+
}
311326

312327
$return .='</ul>';
313328

@@ -379,4 +394,17 @@ function content_header($titre, $small) {
379394

380395
return $header;
381396
}
397+
398+
function box_linkusage ($title, $img) {
399+
$return = '<div class="box box-primary">';
400+
$return .= '<div class="box-header with-border">';
401+
$return .= '<i class="fa fa-bar-chart-o"></i>';
402+
$return .= '<h3 class="box-title">'.$title.'</h3>';
403+
$return .= '</div>';
404+
$return .= '<div class="box-body">';
405+
$return .= '<center>'.$img.'</center>';
406+
$return .= '</div>';
407+
$return .= '</div>';
408+
return $return;
409+
}
382410
?>

history.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
$rrdfile = getRRDFileForAS($as, $peerusage);
2121

2222
$daily_graph_v4 = getHTMLImg($as, 4, $asinfo['descr'], time() - 24 * 3600, time(), $peerusage, 'daily graph', 'detailgraph', true);
23-
$weekly_graph_v4 = getHTMLImg($as, 4, $asinfo['descr'], time() - 7 * 86400, time(), $peerusage, 'weekly graph', 'detailgraph', true);
23+
$weekly_graph_v4 = getHTMLImg($as, 4, $asinfo['descr'], time() - 6.9 * 86400, time(), $peerusage, 'weekly graph', 'detailgraph', true);
2424
$monthly_graph_v4 = getHTMLImg($as, 4, $asinfo['descr'], time() - 30 * 86400, time(), $peerusage, 'monthly graph', 'detailgraph', true);
2525
$yearly_graph_v4 = getHTMLImg($as, 4, $asinfo['descr'], time() - 365 * 86400, time(), $peerusage, 'yearly graph', 'detailgraph', true);
2626

2727
if ($showv6) {
2828
$daily_graph_v6 = getHTMLImg($as, 6, $asinfo['descr'], time() - 24 * 3600, time(), $peerusage, 'daily graph', 'detailgraph', true);
29-
$weekly_graph_v6 = getHTMLImg($as, 6, $asinfo['descr'], time() - 7 * 86400, time(), $peerusage, 'weekly graph', 'detailgraph', true);
29+
$weekly_graph_v6 = getHTMLImg($as, 6, $asinfo['descr'], time() - 6.9 * 86400, time(), $peerusage, 'weekly graph', 'detailgraph', true);
3030
$monthly_graph_v6 = getHTMLImg($as, 6, $asinfo['descr'], time() - 30 * 86400, time(), $peerusage, 'monthly graph', 'detailgraph', true);
3131
$yearly_graph_v6 = getHTMLImg($as, 6, $asinfo['descr'], time() - 365 * 86400, time(), $peerusage, 'yearly graph', 'detailgraph', true);
3232
}

index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
$label = statsLabelForHours($hours);
1717
$knownlinks = getknownlinks();
18+
1819
$selected_links = array();
1920

2021
foreach($knownlinks as $link){
@@ -185,9 +186,7 @@
185186
<?php echo content_header('Top ' . $ntop . ' AS', '('.$label.')'); ?>
186187

187188
<section class="content">
188-
189189
<div class="row">
190-
191190
<div class="col-md-12 col-lg-<?php echo $first_col; ?>">
192191
<div class="row">
193192

@@ -270,6 +269,7 @@
270269
<script src="bootstrap/js/bootstrap.min.js"></script>
271270
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
272271
<script src="plugins/fastclick/fastclick.min.js"></script>
272+
<script src="plugins/jQueryUI/jquery-ui.min.js"></script>
273273
<script src="dist/js/app.min.js"></script>
274274

275275
</body>

linkgraph.php

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
/*
3+
* $Id$
4+
*
5+
* written by Manuel Kasper <[email protected]> for Monzoon Networks AG
6+
*/
7+
8+
require_once('func.inc');
9+
10+
$numtop = 10;
11+
$ascolors = array("A6CEE3", "1F78B4", "B2DF8A", "33A02C", "FB9A99", "E31A1C", "FDBF6F", "FF7F00", "CAB2D6", "6A3D9A");
12+
13+
$link = $_GET['link'];
14+
if (!preg_match("/^[0-9a-zA-Z][0-9a-zA-Z\-_]+$/", $link))
15+
die("Invalid link");
16+
17+
$v6_el = "";
18+
if (@$_GET['v'] == 6)
19+
$v6_el = "v6_";
20+
21+
$hours = 24;
22+
if (@$_GET['numhours'])
23+
$hours = (int)$_GET['numhours'];
24+
25+
$statsfile = statsFileForHours($hours);
26+
$topas = getasstats_top($numtop, $statsfile, array($_GET['link']));
27+
28+
/* now make a beautiful graph :) */
29+
header("Content-Type: image/png");
30+
31+
$width = $default_graph_width;
32+
$height = $default_graph_height;
33+
if (@$_GET['width'])
34+
$width = (int)$_GET['width'];
35+
if (@$_GET['height'])
36+
$height = (int)$_GET['height'];
37+
38+
$knownlinks = getknownlinks();
39+
40+
if ($compat_rrdtool12) {
41+
/* cannot use full-size-mode - must estimate height/width */
42+
$height -= 205;
43+
$width -= 81;
44+
}
45+
46+
$start = time() - $hours*3600;
47+
$end = time();
48+
49+
$cmd = "$rrdtool graph - " .
50+
"--slope-mode --alt-autoscale -u 0 -l 0 --imgformat=PNG --base=1000 --height=$height --width=$width " .
51+
"--color BACK#ffffff00 --color SHADEA#ffffff00 --color SHADEB#ffffff00 " .
52+
"--start " . $start . " --end " . $end . " ";
53+
54+
if (!$compat_rrdtool12)
55+
$cmd .= "--full-size-mode ";
56+
57+
if($showtitledetail && @$_GET['dname'] != "")
58+
$cmd .= "--title " . escapeshellarg($_GET['dname']) . " ";
59+
else
60+
if (isset($_GET['v']) && is_numeric($_GET['v']))
61+
$cmd .= "--title IPv" . $_GET['v'] . " ";
62+
63+
/* geneate RRD DEFs */
64+
foreach ($topas as $as => $traffic) {
65+
$rrdfile = getRRDFileForAS($as);
66+
$cmd .= "DEF:as{$as}_{$v6_el}in=\"$rrdfile\":{$link}_{$v6_el}in:AVERAGE ";
67+
$cmd .= "DEF:as{$as}_{$v6_el}out=\"$rrdfile\":{$link}_{$v6_el}out:AVERAGE ";
68+
}
69+
70+
/* generate a CDEF for each DEF to multiply by 8 (bytes to bits), and reverse for outbound */
71+
foreach ($topas as $as => $traffic) {
72+
if ($outispositive) {
73+
$cmd .= "CDEF:as{$as}_{$v6_el}in_bits=as{$as}_{$v6_el}in,-8,* ";
74+
$cmd .= "CDEF:as{$as}_{$v6_el}out_bits=as{$as}_{$v6_el}out,8,* ";
75+
} else {
76+
$cmd .= "CDEF:as{$as}_{$v6_el}in_bits=as{$as}_{$v6_el}in,8,* ";
77+
$cmd .= "CDEF:as{$as}_{$v6_el}out_bits=as{$as}_{$v6_el}out,-8,* ";
78+
}
79+
}
80+
81+
/* generate graph area/stack for inbound */
82+
$i = 0;
83+
foreach ($topas as $as => $traffic) {
84+
$asinfo = getASInfo($as);
85+
$descr = str_replace(":", "\\:", utf8_decode($asinfo['descr']));
86+
87+
$cmd .= "AREA:as{$as}_{$v6_el}in_bits#{$ascolors[$i]}:\"AS{$as} ({$descr})\\n\"";
88+
if ($i > 0)
89+
$cmd .= ":STACK";
90+
$cmd .= " ";
91+
$i++;
92+
}
93+
94+
/* generate graph area/stack for outbound */
95+
$i = 0;
96+
foreach ($topas as $as => $traffic) {
97+
$cmd .= "AREA:as{$as}_{$v6_el}out_bits#{$ascolors[$i]}:";
98+
if ($i > 0)
99+
$cmd .= ":STACK";
100+
$cmd .= " ";
101+
$i++;
102+
}
103+
104+
# zero line
105+
$cmd .= "HRULE:0#00000080";
106+
107+
passthru($cmd);
108+
109+
exit;
110+
111+
?>

linkusage.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php include("func.inc"); ?>
2+
3+
<?php
4+
$knownlinks = getknownlinks();
5+
$hours = 24;
6+
if (@$_GET['numhours'])
7+
$hours = (int)$_GET['numhours'];
8+
$label = statsLabelForHours($hours);
9+
$i = 0;
10+
foreach ($knownlinks as $link) {
11+
$class = (($i % 2) == 0) ? "" : "even";
12+
if ($showv6) {
13+
$list_img[$link['tag']] = '<img alt="link graph" src="linkgraph.php?link='.$link['tag'].'&numhours='.$hours.'&width='.$linkusage_graph_width.'&height='.$linkusage_graph_height.'&dname='.rawurlencode($link['descr'] . " - IPv4").'" width="'.$linkusage_graph_width.'" height="'.$linkusage_graph_height.'" border="0" />';
14+
$list_img_v6[$link['tag']] = '<img alt="link graph" src="linkgraph.php?link='.$link['tag'].'&numhours='.$hours.'&width='.$linkusage_graph_width.'&height='.$linkusage_graph_height.'&dname='.rawurlencode($link['descr'] . " - IPv6").'&v=6" width="'.$linkusage_graph_width.'" height="'.$linkusage_graph_height.'" border="0" />';
15+
} else {
16+
$list_img[$link['tag']] = '<img alt="link graph" src="linkgraph.php?link='.$link['tag'].'&numhours='.$hours.'&width='.$linkusage_graph_width.'&height='.$linkusage_graph_height.'&dname='.rawurlencode($link['descr']).'" width="'.$linkusage_graph_width.'" height="'.$linkusage_graph_height.'" border="0" />';
17+
}
18+
if ( ($showtitledetail && !$hidelinkusagename) || (!$showtitledetail) ) {
19+
$txt_title[$link['tag']] = $link['descr'];
20+
} else { $txt_title = ""; }
21+
}
22+
?>
23+
24+
<html>
25+
<head>
26+
<meta charset="UTF-8">
27+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
28+
<meta http-equiv="Refresh" content="300">
29+
<title>AS-Stats | Link Usage - Top 10 AS per link</title>
30+
<link rel="icon" href="favicon.ico" />
31+
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
32+
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
33+
<link rel="stylesheet" href="plugins/font-awesome/font-awesome.min.css">
34+
<link rel="stylesheet" href="plugins/ionicons/ionicons.min.css">
35+
<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
36+
<link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
37+
<link rel="stylesheet" href="css/custom.css">
38+
</head>
39+
<body class="hold-transition skin-black-light sidebar-collapse layout-top-nav fixed">
40+
41+
<div class="wrapper">
42+
43+
<!-- =============================================== -->
44+
<?php echo menu($selected_links); ?>
45+
<!-- =============================================== -->
46+
47+
<div class="content-wrapper">
48+
<?php echo content_header('Top 10 AS - per link usage', '(' . $label . ')'); ?>
49+
50+
<section class="content">
51+
<div class="row">
52+
<?php
53+
if ( !$txt_title ) {
54+
if (!$showv6) {
55+
foreach ($list_img as $key => $img) {
56+
echo '<div class="col-lg-6">';
57+
echo box_linkusage('Link Usage', $img);
58+
echo '</div>';
59+
}
60+
} else {
61+
foreach ($list_img as $key => $img) {
62+
echo '<div class="col-lg-12">';
63+
echo box_linkusage('Link Usage', $img . ' ' . $list_img_v6[$key]);
64+
echo '</div>';
65+
}
66+
}
67+
} else {
68+
if (!$showv6) {
69+
foreach ($list_img as $key => $img) {
70+
echo '<div class="col-lg-6">';
71+
echo box_linkusage('Link Usage for ' . $txt_title[$key], $img);
72+
echo '</div>';
73+
}
74+
} else {
75+
foreach ($list_img as $key => $img) {
76+
echo '<div class="col-lg-12">';
77+
echo box_linkusage('Link Usage for ' . $txt_title[$key], $img . ' ' . $list_img_v6[$key]);
78+
echo '</div>';
79+
}
80+
}
81+
}
82+
?>
83+
</div>
84+
</section>
85+
</div>
86+
87+
<!-- =============================================== -->
88+
<?php echo footer(); ?>
89+
<!-- =============================================== -->
90+
91+
</div>
92+
93+
<script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
94+
<script src="bootstrap/js/bootstrap.min.js"></script>
95+
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
96+
<script src="plugins/fastclick/fastclick.min.js"></script>
97+
<script src="plugins/jQueryUI/jquery-ui.min.js"></script>
98+
<script src="dist/js/app.min.js"></script>
99+
100+
</body>
101+
</html>

0 commit comments

Comments
 (0)