forked from sseshachala/observium
/
ports.inc.php
173 lines (140 loc) · 6.32 KB
/
ports.inc.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
<?php
if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs')
{
if (isset($vars['graph'])) { $graph_type = "port_" . $vars['graph']; } else { $graph_type = "port_bits"; }
}
if (!$vars['view']) { $vars['view'] = trim($config['ports_page_default'],'/'); }
$link_array = array('page' => 'device',
'device' => $device['device_id'],
'tab' => 'ports');
$navbar['options']['basic']['text'] = 'Basic';
$navbar['options']['details']['text'] = 'Details';
$navbar['options']['arp']['text'] = 'ARP/NDP Table';
if(dbFetchCell("SELECT COUNT(*) FROM `vlans_fdb` WHERE `device_id` = ?", array($device['device_id'])))
{
$navbar['options']['fdb']['text'] = 'FDB Table';
}
if(dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = ? AND I.port_id = L.local_port_id", array($device['device_id'])))
{
$navbar['options']['neighbours']['text'] = 'Neighbours';
$navbar['options']['map']['text'] = 'Map';
}
if(dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl' AND `device_id` = ?", array($device['device_id'])))
{
$navbar['options']['adsl']['text'] = 'ADSL';
}
$navbar['options']['graphs'] = array('text' => 'Graphs', 'class' => 'pull-right');
$navbar['options']['minigraphs'] = array('text' => 'Minigraphs', 'class' => 'pull-right');
foreach ($navbar['options'] as $option => $array)
{
if ($vars['view'] == $option) { $navbar['options'][$option]['class'] .= " active"; }
$navbar['options'][$option]['url'] = generate_url($link_array,array('view'=>$option));
}
$graph_types = array("bits" => "Bits",
"upkts" => "Ucast Packets",
"nupkts" => "NUcast Packets",
"errors" => "Errors",
"etherlike" => "Etherlike");
foreach (array('graphs', 'minigraphs') as $option)
{
foreach ($graph_types as $type => $descr)
{
if ($vars['view'] == $option)
{
$navbar_b['class'] = "navbar-narrow";
$navbar_b['brand'] = $navbar['options'][$option]['text'];
$navbar_b['options'][$type]['text'] = $descr;
$navbar_b['options'][$type]['url'] = generate_url($link_array,array('view'=>'graphs','graph'=>$type));
if ($vars['graph'] == $type) { $navbar_b['options'][$type]['class'] = "active"; }
}
if ($vars['view'] == $option && $vars['graph'] == $type) { $navbar['options'][$option]['suboptions'][$type]['class'] = "active"; }
$navbar['options'][$option]['suboptions'][$type]['text'] = $descr;
$navbar['options'][$option]['suboptions'][$type]['url'] = generate_url($link_array,array('view'=>$option,'graph'=>$type));
}
}
$navbar['class'] = "navbar-narrow";
$navbar['brand'] = "Ports";
print_navbar($navbar);
unset($navbar);
if(is_array($navbar_b)) { print_navbar($navbar_b); }
if ($vars['view'] == 'minigraphs')
{
$timeperiods = array('-1day','-1week','-1month','-1year');
$from = '-1day';
echo("<div style='display: block; clear: both; margin: auto; min-height: 500px;'>");
unset ($seperator);
// FIXME - FIX THIS. UGLY.
foreach (dbFetchRows("select * from ports WHERE device_id = ? ORDER BY ifIndex", array($device['device_id'])) as $port)
{
echo("<div style='display: block; padding: 3px; margin: 3px; min-width: 183px; max-width:183px; min-height:90px; max-height:90px; text-align: center; float: left; background-color: #e9e9e9;'>
<div style='font-weight: bold;'>".makeshortif($port['ifDescr'])."</div>
<a href=\"" . generate_port_url($port) . "\" onmouseover=\"return overlib('\
<div style=\'font-size: 16px; padding:5px; font-weight: bold; color: #e5e5e5;\'>".$device['hostname']." - ".$port['ifDescr']."</div>\
".$port['ifAlias']." \
<img src=\'graph.php?type=".$graph_type."&id=".$port['port_id']."&from=".$from."&to=".$config['time']['now']."&width=450&height=150\'>\
', CENTER, LEFT, FGCOLOR, '#e5e5e5', BGCOLOR, '#e5e5e5', WIDTH, 400, HEIGHT, 150);\" onmouseout=\"return nd();\" >".
"<img src='graph.php?type=".$graph_type."&id=".$port['port_id']."&from=".$from."&to=".$config['time']['now']."&width=180&height=45&legend=no'>
</a>
<div style='font-size: 9px;'>".truncate(short_port_descr($port['ifAlias']), 32, '')."</div>
</div>");
}
echo("</div>");
} elseif ($vars['view'] == "arp" || $vars['view'] == "adsl" || $vars['view'] == "neighbours" || $vars['view'] == "fdb" || $vars['view'] == "map") {
include("ports/".$vars['view'].".inc.php");
} else {
if ($vars['view'] == "details") { $port_details = 1; }
if($vars['view'] == "graphs") { $table_class = "table-striped-two"; } else { $table_class = "table-striped"; }
echo('<table class="table table-hover table-bordered table-condensed table-rounded '.$table_class.'"
style="vertical-align: middle; margin-top: 5px; margin-bottom: 10px;">');
echo(' <thead>');
echo('<tr>');
$cols = array(
'state' => NULL,
'BLANK' => NULL,
'port' => 'Port',
'graphs' => NULL,
'traffic' => 'Traffic',
'speed' => 'Speed',
'media' => 'Media',
'mac' => 'MAC Address',
'details' => NULL);
foreach ($cols as $sort => $col)
{
if ($col == NULL)
{
echo('<th></th>');
}
elseif ($vars['sort'] == $sort)
{
echo('<th>'.$col.' *</th>');
} else {
echo('<th><a href="'. generate_url($vars, array('sort' => $sort)).'">'.$col.'</a></th>');
}
}
echo(" </tr>");
echo(' </thead>');
$i = "1";
global $port_cache, $port_index_cache;
$sql = "SELECT *, `ports`.`port_id` as `port_id`";
$sql .= " FROM `ports`";
$sql .= " LEFT JOIN `ports-state` ON `ports`.`port_id` = `ports-state`.`port_id`";
$sql .= " WHERE `device_id` = ? ORDER BY `ifIndex` ASC";
$ports = dbFetchRows($sql, array($device['device_id']));
// Sort ports, sharing code with global ports page.
include("includes/port-sort.inc.php");
// As we've dragged the whole database, lets pre-populate our caches :)
// FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries.
foreach ($ports as $port)
{
$port_cache[$port['port_id']] = $port;
$port_index_cache[$port['device_id']][$port['ifIndex']] = $port;
}
foreach ($ports as $port)
{
include("includes/print-interface.inc.php");
$i++;
}
echo("</table></div>");
}
$pagetitle[] = "Ports";
?>