1<?php
2
3/**
4 * Observium
5 *
6 *   This file is part of Observium.
7 *
8 * @package    observium
9 * @subpackage web
10 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
11 *
12 */
13
14$vars['page'] = 'overview'; // Always set variable page (need for generate_query_permitted())
15
16foreach ($config['frontpage']['order'] as $module)
17{
18  switch ($module)
19  {
20    case "status_summary":
21      $div_class = "col-md-6"; // Class for each block
22      echo('<div class="row hidden-xl">' . PHP_EOL); // Moved on XL screen to panel side
23      include($config['html_dir']."/includes/status-summary.inc.php");
24      echo('</div>' . PHP_EOL);
25      break;
26
27    case "status_donuts":
28      $div_class = "col-md-12"; // Class for each block
29      echo('<div class="row">' . PHP_EOL); // Moved on XL screen to panel side
30      include($config['html_dir']."/includes/status-donuts.inc.php");
31      echo('</div>' . PHP_EOL);
32      break;
33
34    case "cable-map":
35      include($config['html_dir']."/includes/cable-map.inc.php");
36      break;
37
38    case "map":
39      //include($config['html_dir']."/includes/map.inc.php");
40      show_map($config);
41      break;
42
43    case "device_status_boxes":
44      show_status_boxes($config);
45      break;
46    case "device_status":
47      show_status($config);
48      break;
49    case "alert_status":
50      include("includes/alert-status.inc.php");
51      break;
52    case "overall_traffic":
53      show_traffic($config);
54      break;
55    case "custom_traffic":
56      show_customtraffic($config);
57      break;
58    case "alert_table":
59
60      print_alert_table(array('status' => 'failed', 'pagination' => FALSE, 'short' => TRUE,
61                              'header' => array('title' => 'Current Alerts',
62                                                'url' => '/alerts/'
63                                                )
64                       ));
65      break;
66
67    case "splitlog":
68      show_splitlog($config);
69      break;
70    case "syslog":
71      show_syslog($config);
72      break;
73    case "eventlog":
74      show_eventlog($config);
75      break;
76    case "minigraphs":
77      show_minigraphs($config);
78      break;
79    case "micrographs":
80      show_micrographs($config);
81      break;
82    case "portpercent":
83      include($config['html_dir']."/includes/status-portpercent.inc.php");
84      break;
85  }
86}
87
88// FIXME, make this function generic for use in any place
89// MOVEME html/includes/print/maps.inc.php
90function show_map($config)
91{
92  ?>
93<div class="row">
94  <div class="col-sm-12">
95  <style type="text/css">
96    #map label { width: auto; display:inline; }
97    #map img { max-width: none; }
98    #map {
99      height: <?php echo $config['frontpage']['map']['height']; ?>px; /* Or whatever height you like */
100      width: 100%;
101    }
102  </style>
103
104  <div class="box box-solid">
105  <!-- <div id="reset" style="width: 100%; text-align: right;"><input type="button" onclick="resetMap();" value="Reset Map" /></div> -->
106    <div id="map"></div>
107
108  </div>
109
110<?php
111
112  // Map API and keys
113  $map_default = 'leaflet'; // Default
114  switch ($config['frontpage']['map']['api'])
115  {
116    case 'google-mc':
117    case 'google':
118      // Check if key exist
119      if (strlen($config['geo_api']['google']['key']))
120      {
121        $map = $config['frontpage']['map']['api'];
122      }
123      break;
124    case 'mapbox':
125      // Check if key exist
126      if (!strlen($config['geo_api']['mapbox']['key']))
127      {
128        // If api key not set, reset to default map provider
129        $config['frontpage']['map']['api'] = 'carto';
130      }
131      break;
132
133    case 'carto':
134    default:
135      //$map = 'leaflet';
136      break;
137  }
138
139  if (isset($map) && is_file($config['html_dir']."/includes/map/$map.inc.php"))
140  {
141    include($config['html_dir']."/includes/map/$map.inc.php");
142  } else {
143    include($config['html_dir']."/includes/map/$map_default.inc.php");
144    //print_error("Unknown map type: $map");
145  }
146?>
147  </div>
148</div>
149<?php
150} // End show_map
151
152function show_traffic($config)
153{
154  // Show Traffic
155  if ($_SESSION['userlevel'] >= '5')
156  {
157    $ports = array();
158    $query_permitted = generate_query_permitted(array('port'));
159    foreach (dbFetchRows("SELECT `port_descr_type`,`port_id`,`ifAlias` FROM `ports`
160                          WHERE `port_descr_type` IS NOT NULL $query_permitted
161                          ORDER BY `ifAlias`") as $port)
162    {
163      switch ($port['port_descr_type'])
164      {
165        case 'transit':
166        case 'peering':
167        case 'core':
168          $ports[$port['port_descr_type']][] = $port['port_id'];
169          break;
170      }
171    }
172
173    echo generate_box_open();
174
175     $links['transit']      = generate_url(array("page" => "iftype", "type" => "transit"));
176     $ports['transit_list'] = implode(',', $ports['transit']);
177
178    $graph_array['from']   = $config['time']['day'];
179    $graph_array['to']     = $config['time']['now'];
180    $graph_array['type']   = 'multi-port_bits_separate';
181    $graph_array['width']  = 528;
182    $graph_array['height'] = 100;
183    $graph_array['legend'] = 'no';
184    $graph_array['id']     = $ports['transit_list'];
185    $transit_graph         = generate_graph_tag($graph_array);
186    $graph_array['from']   = $config['time']['week'];
187    $transit_graph_week    = generate_graph_tag($graph_array);
188
189    $links['peering']      = generate_url(array("page" => "iftype", "type" => "peering"));
190    $ports['peering_list'] = implode(',', $ports['peering']);
191
192    $graph_array['from']   = $config['time']['day'];
193    $graph_array['id']     = $ports['peering_list'];
194    $peering_graph         = generate_graph_tag($graph_array);
195    $graph_array['from']   = $config['time']['week'];
196    $peering_graph_week    = generate_graph_tag($graph_array);
197
198    $graph_array['id']     = $ports['peering_list'];
199    $graph_array['idb']    = $ports['transit_list'];
200    $graph_array['from']   = $config['time']['month'];
201    $graph_array['type']   = 'multi-port_bits_duo_separate';
202    $graph_array['width']  = 1158;
203
204    $summary_graph         = generate_graph_tag($graph_array);
205
206    if (count($ports['transit']) && count($ports['peering']))
207    {
208      echo('<div class="row">');
209      echo('  <div class="col-sm-6">');
210      echo('    <h3><a href="/iftype/type=transit">Overall Transit Traffic Today</a></h3>');
211      echo('    <a href="'.$links['transit'].'">'.$transit_graph.'</a>');
212      echo('  </div>');
213      echo('  <div class="col-sm-6">');
214      echo('    <h3><a href="/iftype/type=peering">Overall Peering Traffic Today</a></h3>');
215      echo('    <a href="'.$links['peering'].'">'.$peering_graph.'</a>');
216      echo('  </div>');
217      echo('</div>');
218    }
219    elseif (count($ports['transit']))
220    {
221      echo('<div class="row">');
222      echo('  <div class="col-sm-6">');
223      echo('    <h3><a href="/iftype/type=transit">Overall Transit Traffic Today</a></h3>');
224      echo('    <a href="'.$links['transit'].'">'.$transit_graph.'</a>');
225      echo('  </div>');
226
227      echo('  <div class="col-sm-6 ">');
228      echo('    <h3><a href="/iftype/type=transit">Overall Transit Traffic This Week</a></h3>');
229      echo('    <a href="'.$links['transit'].'">'.$transit_graph_week.'</a>');
230      echo('  </div>');
231      echo('</div>');
232    }
233    elseif (count($ports['peering']))
234    {
235      $links['peering']      = generate_url(array("page" => "iftype", "type" => "peering"));
236      $ports['peering_list'] = implode(',', $ports['peering']);
237      echo('<div class="row">');
238      echo('  <div class="col-sm-6 ">');
239      echo('    <h3><a href="/iftype/type=peering">Overall Peering Traffic Today</a></h3>');
240      echo('    <a href="'.$links['peering'].'">'.$peering_graph.'</a>');
241      echo('  </div>');
242      echo('  <div class="col-sm-6 ">');
243      echo('    <h3><a href="/iftype/type=peering">Overall Peering Traffic This Week</a></h3>');
244      echo('    <a href="'.$links['peering'].'">'.$peering_graph_week.'</a>');
245      echo('  </div>');
246      echo('</div>');
247
248    }
249
250    if ($ports['transit_list'] && $ports['peering_list'])
251    {
252      $links['peer_trans']  = generate_url(array("page" => "iftype", "type" => "peering,transit"));
253      echo('<div class="row">');
254      echo('  <div class="col-sm-12">');
255      echo('    <h3><a href="/iftype/type=transit%2Cpeering">Overall Transit &amp; Peering Traffic This Month</a></h3>');
256      echo('    <a href="'.$links['peer_trans'].'">'.$summary_graph.'</a>');
257      echo('  </div>');
258      echo('</div>');
259    }
260
261    echo generate_box_close();
262  }
263} // End show_traffic
264
265function show_customtraffic($config)
266{
267  // Show Custom Traffic
268  if ($_SESSION['userlevel'] >= '5')
269  {
270    echo generate_box_open();
271
272    $config['frontpage']['custom_traffic']['title'] = (empty($config['frontpage']['custom_traffic']['title']) ? "Custom Traffic" : $config['frontpage']['custom_traffic']['title']);
273    echo('<div class="row">');
274    echo('  <div class="col-sm-6 ">');
275    echo('    <h3 class="bill">'.$config['frontpage']['custom_traffic']['title'].' Today</h3>');
276    echo('    <img src="graph.php?type=multi-port_bits&amp;id='.$config['frontpage']['custom_traffic']['ids'].'&amp;legend=no&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now'].'&amp;width=520&amp;height=100" alt="" />');
277    echo('  </div>');
278    echo('  <div class="col-sm-6 ">');
279    echo('    <h3 class="bill">'.$config['frontpage']['custom_traffic']['title'].' This Week</h3>');
280    echo('    <img src="graph.php?type=multi-port_bits&amp;id='.$config['frontpage']['custom_traffic']['ids'].'&amp;legend=no&amp;from='.$config['time']['week'].'&amp;to='.$config['time']['now'].'&amp;width=520&amp;height=100" alt="" />');
281    echo('  </div>');
282    echo('</div>');
283    echo('<div class="row">');
284    echo('  <div class="col-sm-12 ">');
285    echo('    <h3 class="bill">'.$config['frontpage']['custom_traffic']['title'].' This Month</h3>');
286    echo('    <img src="graph.php?type=multi-port_bits&amp;id='.$config['frontpage']['custom_traffic']['ids'].'&amp;legend=no&amp;from='.$config['time']['month'].'&amp;to='.$config['time']['now'].'&amp;width=1100&amp;height=200" alt="" />');
287    echo('  </div>');
288    echo('</div>');
289
290    echo generate_box_close();
291  }
292}  // End show_customtraffic
293
294function show_minigraphs($config)
295{
296  // Show Custom MiniGraphs
297  if ($_SESSION['userlevel'] >= '5' && $config['frontpage']['minigraphs']['ids'] != '')
298  {
299    $minigraphs = explode(';', $config['frontpage']['minigraphs']['ids']);
300    $width = $config['frontpage']['minigraphs']['width'];
301    $height = $config['frontpage']['minigraphs']['height'];
302    $legend = (($config['frontpage']['minigraphs']['legend'] == false) ? 'no' : 'yes');
303
304    echo generate_box_open();
305    echo('<div class="row">');
306    echo('  <div class="col-sm-12">');
307    if ($config['frontpage']['minigraphs']['title'])
308    {
309      echo('    <h3 class="bill">'.$config['frontpage']['minigraphs']['title'].'</h3>');
310    }
311
312    foreach ($minigraphs as $graph)
313    {
314      if (!$graph) { continue; } // Skip empty graphs from excess semicolons
315      list($device, $type, $header) = explode(',', $graph, 3);
316      if (strpos($type, 'device') === false)
317      {
318        if (strpos($type, 'multi') !== false) // Copy/pasted id= from multi graph url works, prevents broken uri
319        {
320          $links = generate_url(array('page' => 'graphs', 'type' => $type, 'id' => urldecode($device)));
321        } else {
322          $links = generate_url(array('page' => 'graphs', 'type' => $type, 'id' => $device));
323        }
324        //, 'from' => $config['time']['day'], 'to' => $config['time']['now']));
325        echo('    <div class="pull-left"><p style="text-align: center; margin-bottom: 0px;"><strong>'.$header.'</strong></p><a href="'.$links.'"><img src="graph.php?type='.$type.'&amp;id='.$device.'&amp;legend='.$legend.'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now'].'&amp;width='.$width.'&amp;height='.$height.'"/></a></div>');
326      } else {
327        $links = generate_url(array('page' => 'graphs', 'type' => $type, 'device' => $device));
328        //, 'from' => $config['time']['day'], 'to' => $config['time']['now']));
329        echo('    <div class="pull-left"><p style="text-align: center; margin-bottom: 0px;"><strong>'.$header.'</strong></p><a href="'.$links.'"><img src="graph.php?type='.$type.'&amp;device='.$device.'&amp;legend='.$legend.'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now'].'&amp;width='.$width.'&amp;height='.$height.'"/></a></div>'); // Apply custom dimensions to device graphs
330      }
331    }
332
333    unset($links);
334    echo('  </div>');
335    echo('</div>');
336    echo generate_box_close();
337  }
338} // End show_minigraphs
339
340function show_micrographs($config)
341{
342  if ($_SESSION['userlevel'] >= '5' && $config['frontpage']['micrographs'] != '')
343  {
344    $width = $config['frontpage']['micrograph_settings']['width'];
345    $height = $config['frontpage']['micrograph_settings']['height'];
346
347    echo generate_box_open();
348    echo('<div class="row">');
349    echo('  <div class="col-sm-12">');
350    echo('  <table class="box box-solid table  table-condensed-more table-rounded">');
351    echo('    <tbody>');
352
353    foreach ($config['frontpage']['micrographs'] as $row)
354    {
355      $micrographs = explode(';', $row['ids']);
356      $legend = (($row['legend'] == false) ? 'no' : 'yes');
357      echo('    <tr>');
358      if ($row['title'])
359      {
360        echo('      <th style="vertical-align: middle;">'.$row['title'].'</th>');
361      }
362
363      echo('      <td>');
364      foreach ($micrographs as $graph)
365      {
366        if (!$graph) { continue; } // Skip empty graphs from excess semicolons
367        list($device, $type, $header) = explode(',', $graph, 3);
368        if (strpos($type, 'device') === false)
369        {
370          $which = 'id';
371          if (strpos($type, 'multi') !== false) // Copy/pasted id= from multi graph url works, prevents broken uri
372          {
373            $links = generate_url(array('page' => 'graphs', 'type' => $type, 'id' => urldecode($device)));
374          } else {
375            $links = generate_url(array('page' => 'graphs', 'type' => $type, 'id' => $device));
376          }
377        } else {
378          $which = 'device';
379          $links = generate_url(array('page' => 'graphs', 'type' => $type, 'device' => $device));
380        }
381
382        echo('<div class="pull-left">');
383        if ($header)
384        {
385          echo('<p style="text-align: center; margin-bottom: 0px;">'.$header.'</p>');
386        }
387
388        echo('<a href="'.$links.'" style="margin-left: 5px"><img src="graph.php?type='.$type.'&amp;'.$which.'='.$device.'&amp;legend='.$legend.'&amp;width='.$width.'&amp;height='.$height.'"/></a>');
389        echo('</div>');
390      }
391
392      unset($links);
393      echo('      </td>');
394      echo('    </tr>');
395    }
396
397    echo('    </tbody>');
398    echo('  </table>');
399    echo('  </div>');
400    echo('</div>');
401    echo generate_box_close();
402  }
403} // End show_micrographs
404
405function show_status($config)
406{
407  echo generate_box_open(array('title' => 'Status Warnings and Notifications', 'url' => '/alerts/', 'header-border' => TRUE));
408  generate_status_table($config['frontpage']['device_status']);
409  echo generate_box_close();
410}
411
412function show_portpercent($config)
413{
414  if ($config['frontpage']['portpercent'] != '') {
415  echo generate_box_open(array('title' => 'Port Utilization by Type', 'url' => '/groups/entity_type=port/', 'header-border' => TRUE));
416	echo('<img src="portpercent-graph.php">');
417  echo generate_box_close();
418  }
419}
420
421function show_status_boxes($config)
422{
423  echo('<div class="row">' . PHP_EOL);
424  echo('  <div class="col-sm-12" style="padding-right: 0px;">' . PHP_EOL);
425  print_status_boxes($config['frontpage']['device_status']);
426  echo('  </div>' . PHP_EOL);
427  echo('</div>' . PHP_EOL);
428}
429
430function show_syslog($config)
431{
432  print_syslogs(array('short' => TRUE, 'pagesize' => $config['frontpage']['syslog']['items'], 'priority' => $config['frontpage']['syslog']['priority'],
433                      'header' => array('url' => '/syslog/', 'title' => 'Recent Syslog Messages', 'header-border' => TRUE)));
434}
435
436function show_eventlog($config)
437{
438  print_events(array('short' => TRUE, 'pagesize' => $config['frontpage']['eventlog']['items'], 'severity' => $config['frontpage']['eventlog']['severity'],
439                     'header' => array('url' => '/eventlog/', 'title' => 'Recent Events', 'header-border' => TRUE)));
440}
441
442function show_splitlog($config)
443{
444  echo '<div class="row">' . PHP_EOL;
445  echo '  <div class="col-sm-6">' . PHP_EOL;
446  print_events(array('short' => TRUE, 'pagesize' => $config['frontpage']['eventlog']['items'], 'severity' => $config['frontpage']['eventlog']['severity'],
447                     'header' => array('url' => '/eventlog/', 'title' => 'Recent Events', 'header-border' => TRUE)));
448  echo '  </div>';
449
450  echo '  <div class="col-sm-6">' . PHP_EOL;
451  print_syslogs(array('short' => TRUE, 'pagesize' => $config['frontpage']['syslog']['items'], 'priority' => $config['frontpage']['syslog']['priority'],
452                      'header' => array('url' => '/syslog/', 'title' => 'Recent Syslog Messages', 'header-border' => TRUE)));
453  echo '  </div>';
454  echo '</div>';
455}
456
457// EOF
458