2008-11-04 12:34:30 +00:00
< ? php
2018-09-11 07:51:35 -05:00
use LibreNMS\Authentication\LegacyAuth ;
2018-04-07 15:55:28 -05:00
2015-07-13 20:10:26 +02:00
require_once 'includes/object-cache.inc.php' ;
2013-11-19 08:57:43 +10:00
2015-07-13 20:10:26 +02:00
2016-08-18 20:28:22 -05:00
function generate_front_box ( $frontbox_class , $content )
{
2015-07-13 20:10:26 +02:00
echo " <div class= \" front-box $frontbox_class\ " >
2010-08-13 12:50:01 +00:00
$content
2015-07-13 20:10:26 +02:00
</ div > " ;
}//end generate_front_box()
2008-11-04 12:34:30 +00:00
2015-07-13 20:10:26 +02:00
echo '
2014-01-13 10:05:19 +00:00
<div class= " row " >
2015-07-13 20:10:26 +02:00
';
2014-06-17 07:07:55 +10:00
if ( $config['vertical_summary'] ) {
2015-07-13 20:10:26 +02:00
echo ' <div class= " col - md - 9 " >';
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
echo ' <div class= " col - md - 8 " >';
2014-06-17 07:07:55 +10:00
}
2015-07-13 20:10:26 +02:00
echo '
2014-06-15 01:36:49 +01:00
<div class= " row " >
<div class= " col - md - 12 " >
2015-07-13 20:10:26 +02:00
';
2014-01-13 10:05:19 +00:00
2015-07-13 20:10:26 +02:00
echo '<div class=front-page>';
2013-11-19 08:57:43 +10:00
2015-07-13 20:10:26 +02:00
echo '<div class= " status - boxes " >';
2008-11-04 12:34:30 +00:00
2013-11-19 08:57:43 +10:00
$count_boxes = 0;
// Device down boxes
2018-09-11 07:51:35 -05:00
if (LegacyAuth::user()->hasGlobalRead()) {
2016-10-08 20:48:11 +03:00
$sql = " SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0' LIMIT " . $config['front_page_down_box_limit'] ;
2016-08-18 20:28:22 -05:00
} else {
2018-09-11 07:51:35 -05:00
$sql = " SELECT * FROM `devices` AS D , devices_perms AS P WHERE D . device_id = P . device_id AND P . user_id = '" . LegacyAuth::id() . "' AND D . status = '0' AND D . ignore = '0' LIMIT " . $config['front_page_down_box_limit'] ;
2009-12-31 19:06:05 +00:00
}
2015-07-13 20:10:26 +02:00
foreach (dbFetchRows( $sql ) as $device ) {
generate_front_box(
'device-down',
2016-10-08 20:48:11 +03:00
generate_device_link( $device , shorthost( $device['hostname'] )) . '<br />
2013-11-19 08:57:43 +10:00
<span class=list-device-down>Device Down</span> <br />
2016-10-08 20:48:11 +03:00
<span class=body-date-1>' . truncate( $device['location'] , 20) . '</span>'
2015-07-13 20:10:26 +02:00
);
++ $count_boxes ;
2008-11-04 12:34:30 +00:00
}
2018-09-11 07:51:35 -05:00
if (LegacyAuth::user()->hasGlobalRead()) {
2016-10-08 20:48:11 +03:00
$sql = " SELECT * FROM `ports` AS I , `devices` AS D WHERE I . device_id = D . device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D . ignore = '0' AND I . ignore = '0' AND `D` . `status` = '1' LIMIT " . $config['front_page_down_box_limit'] ;
2016-08-18 20:28:22 -05:00
} else {
2018-09-11 07:51:35 -05:00
$sql = " SELECT * FROM `ports` AS I , `devices` AS D , devices_perms AS P WHERE D . device_id = P . device_id AND P . user_id = '" . LegacyAuth::id() . "' AND I . device_id = D . device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D . ignore = '0' AND I . ignore = '0' AND `D` . `status` = '1' LIMIT " . $config['front_page_down_box_limit'] ;
2009-12-31 19:06:05 +00:00
}
2010-07-01 12:34:01 +00:00
2012-05-25 12:24:34 +00:00
// These things need to become more generic, and more manageable across different frontpages... rewrite inc :>
2013-11-19 08:57:43 +10:00
// Port down boxes
2015-07-13 20:10:26 +02:00
if ( $config['warn'] ['ifdown']) {
foreach (dbFetchRows( $sql ) as $interface ) {
if (! $interface['deleted'] ) {
2017-04-04 08:08:23 +01:00
$interface = cleanPort( $interface );
2015-07-13 20:10:26 +02:00
generate_front_box(
2015-09-28 00:33:50 +05:30
'alert alert-danger',
2016-10-08 20:48:11 +03:00
generate_device_link( $interface , shorthost( $interface['hostname'] )) . " < br />
2013-11-19 08:57:43 +10:00
< span class = \ " interface-updown \" >Port Down</span><br />
2016-10-08 20:48:11 +03:00
<!-- <img src='graph.php?type=bits&if= " . $interface [ 'port_id' ] . '&from=' . $config [ 'time' ][ 'day' ] . '&to=' . $config [ 'time' ][ 'now' ] . " &width=100&height=32' /> -->
2016-11-20 05:12:25 -06:00
" . generate_port_link ( $interface , substr ( makeshortif ( $interface [ 'label' ]), 0 , 13 )) . ' <br />
' . ( $interface [ 'ifAlias' ] ? '<span class="body-date-1">' . substr ( $interface [ 'ifAlias' ], 0 , 20 ) . '</span>' : '' )
2015-07-13 20:10:26 +02:00
);
++ $count_boxes ;
2016-08-18 20:28:22 -05:00
}
2012-03-20 11:52:01 +00:00
}
2008-11-04 12:34:30 +00:00
}
2015-07-13 20:10:26 +02:00
/*
FIXME service permissions? seem nonexisting now.. */
2013-11-19 08:57:43 +10:00
// Service down boxes
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: user () -> hasGlobalRead ()) {
2016-10-08 20:48:11 +03:00
$sql = " SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = '2' AND D.ignore = '0' AND S.service_ignore = '0' LIMIT " . $config [ 'front_page_down_box_limit' ];
2015-07-13 20:10:26 +02:00
$param [] = '' ;
2016-08-18 20:28:22 -05:00
} else {
2016-10-08 20:48:11 +03:00
$sql = " SELECT * FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '2' LIMIT " . $config [ 'front_page_down_box_limit' ];
2018-09-11 07:51:35 -05:00
$param [] = LegacyAuth :: id ();
2014-06-25 14:51:50 +01:00
}
2015-07-13 20:10:26 +02:00
foreach ( dbFetchRows ( $sql , $param ) as $service ) {
generate_front_box (
'service-down' ,
2016-10-08 20:48:11 +03:00
generate_device_link ( $service , shorthost ( $service [ 'hostname' ])) . '<br />
2013-11-10 04:46:10 +10:00
<span class=service-down>Service Down</span>
2016-10-08 20:48:11 +03:00
' . $service [ 'service_type' ] . '<br />
<span class=body-date-1>' . truncate ( $interface [ 'ifAlias' ], 20 ) . '</span>'
2015-07-13 20:10:26 +02:00
);
++ $count_boxes ;
2008-11-04 12:34:30 +00:00
}
2013-11-19 08:57:43 +10:00
// BGP neighbour down boxes
2015-07-13 20:10:26 +02:00
if ( isset ( $config [ 'enable_bgp' ]) && $config [ 'enable_bgp' ]) {
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: user () -> hasGlobalRead ()) {
2016-10-08 20:48:11 +03:00
$sql = " SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT " . $config [ 'front_page_down_box_limit' ];
2016-08-18 20:28:22 -05:00
} else {
2018-09-11 07:51:35 -05:00
$sql = " SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ' " . LegacyAuth :: id () . " ' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0 AND `D`.`status` = '1' LIMIT " . $config [ 'front_page_down_box_limit' ];
2015-07-13 20:10:26 +02:00
}
foreach ( dbFetchRows ( $sql ) as $peer ) {
generate_front_box (
'bgp-down' ,
2016-10-08 20:48:11 +03:00
generate_device_link ( $peer , shorthost ( $peer [ 'hostname' ])) . " <br />
2013-11-19 08:57:43 +10:00
<span class=bgp-down>BGP Down</span>
2016-10-08 20:48:11 +03:00
<span class=' " . ( strstr ( $peer [ 'bgpPeerIdentifier' ], ':' ) ? 'front-page-bgp-small' : 'front-page-bgp-normal' ) . " '> " . $peer [ 'bgpPeerIdentifier' ] . '</span><br />
2016-11-20 05:12:25 -06:00
<span class=body-date-1>AS' . substr ( $peer [ 'bgpPeerRemoteAs' ] . ' ' . $peer [ 'astext' ], 0 , 14 ) . '</span>'
2015-07-13 20:10:26 +02:00
);
++ $count_boxes ;
}
2008-11-04 12:34:30 +00:00
}
2013-11-19 08:57:43 +10:00
// Device rebooted boxes
2016-10-08 20:48:11 +03:00
if ( filter_var ( $config [ 'uptime_warning' ], FILTER_VALIDATE_FLOAT ) !== false && $config [ 'uptime_warning' ] > 0 && $config [ 'os' ][ $device [ 'os' ]][ 'bad_uptime' ] !== true ) {
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: user () -> hasGlobalRead ()) {
2016-10-08 20:48:11 +03:00
$sql = " SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < ' " . $config [ 'uptime_warning' ] . " ' AND D.ignore = 0 LIMIT " . $config [ 'front_page_down_box_limit' ];
2016-08-18 20:28:22 -05:00
} else {
2018-09-11 07:51:35 -05:00
$sql = " SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = ' " . LegacyAuth :: id () . " ' AND D.status = '1' AND D.uptime > 0 AND D.uptime < ' " . $config [ 'uptime_warning' ] . " ' AND D.ignore = 0 LIMIT " . $config [ 'front_page_down_box_limit' ];
2015-07-13 20:10:26 +02:00
}
foreach ( dbFetchRows ( $sql ) as $device ) {
generate_front_box (
2016-08-18 20:28:22 -05:00
'device-rebooted' ,
2016-10-08 20:48:11 +03:00
generate_device_link ( $device , shorthost ( $device [ 'hostname' ])) . '<br />
<span class=device-rebooted>Device Rebooted</span><br />
<span class=body-date-1>' . formatUptime ( $device [ 'uptime' ], 'short' ) . '</span>'
2016-08-18 20:28:22 -05:00
);
2015-07-13 20:10:26 +02:00
++ $count_boxes ;
}
2008-11-04 12:34:30 +00:00
}
2015-07-13 20:10:26 +02:00
2013-11-19 08:57:43 +10:00
if ( $count_boxes == 0 ) {
2015-07-13 20:10:26 +02:00
echo " <h5>Nothing here yet</h5><p class=welcome>This is where status notifications about devices and services would normally go. You might have none
2016-10-08 20:48:11 +03:00
because you run such a great network, or perhaps you've just started using " . $config [ 'project_name' ] . " . If you're new to " . $config [ 'project_name' ] . ', you might
2015-07-13 20:10:26 +02:00
want to start by adding one or more devices in the Devices menu.</p>' ;
2013-11-19 08:57:43 +10:00
}
2015-07-13 20:10:26 +02:00
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
echo '
2014-06-15 01:36:49 +01:00
</div>
</div>
2015-07-13 20:10:26 +02:00
' ;
2014-01-13 10:05:19 +00:00
2015-07-13 20:10:26 +02:00
if ( $config [ 'vertical_summary' ]) {
echo ' <div class="col-md-3">' ;
include_once 'includes/device-summary-vert.inc.php' ;
2016-08-18 20:28:22 -05:00
echo implode ( '' , $common_output );
} else {
2015-07-13 20:10:26 +02:00
echo ' <div class="col-md-4">' ;
2015-07-22 22:04:33 +01:00
include_once 'includes/common/device-summary-horiz.inc.php' ;
2016-08-18 20:28:22 -05:00
echo implode ( '' , $common_output );
2014-06-14 09:31:22 +10:00
}
2014-01-13 10:05:19 +00:00
2015-07-13 20:10:26 +02:00
echo '
2014-01-13 10:05:19 +00:00
</div>
</div>
<div class="row">
<div class="col-md-12">
2015-07-13 20:10:26 +02:00
' ;
2008-11-04 12:34:30 +00:00
2015-07-13 20:10:26 +02:00
if ( $config [ 'enable_syslog' ]) {
2016-10-08 20:48:11 +03:00
$sql = " SELECT *, DATE_FORMAT(timestamp, ' " . $config [ 'dateformat' ][ 'mysql' ][ 'compact' ] . " ') AS date from syslog ORDER BY timestamp DESC LIMIT 20 " ;
2014-02-28 22:19:39 +00:00
2015-07-13 20:10:26 +02:00
echo '<div class="container-fluid">
2014-02-28 22:19:39 +00:00
<div class="row">
<div class="col-md-12">
</div>
2014-06-15 01:36:49 +01:00
</div>
<div class="row">
2014-02-28 22:19:39 +00:00
<div class="col-md-12">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">
<strong>Syslog entries</strong>
</div>
2015-07-13 20:10:26 +02:00
<table class="table table-hover table-condensed table-striped">' ;
foreach ( dbFetchRows ( $sql ) as $entry ) {
$entry = array_merge ( $entry , device_by_id_cache ( $entry [ 'device_id' ]));
2015-08-01 15:36:15 +00:00
unset ( $syslog_output );
2015-07-13 20:10:26 +02:00
include 'includes/print-syslog.inc.php' ;
2015-08-01 15:36:15 +00:00
echo $syslog_output ;
2015-07-13 20:10:26 +02:00
}
echo '</table>' ;
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
2016-08-18 20:28:22 -05:00
} else {
2018-09-11 07:51:35 -05:00
if ( LegacyAuth :: user () -> hasGlobalRead ()) {
2016-10-08 20:48:11 +03:00
$query = " SELECT *,DATE_FORMAT(datetime, ' " . $config [ 'dateformat' ][ 'mysql' ][ 'compact' ] . " ') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15 " ;
2015-07-13 20:10:26 +02:00
$alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15' ;
2016-08-18 20:28:22 -05:00
} else {
2018-09-11 07:51:35 -05:00
$query = " SELECT *,DATE_FORMAT(datetime, ' " . $config [ 'dateformat' ][ 'mysql' ][ 'compact' ] . " ') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . LegacyAuth :: id () . ' ORDER BY `datetime` DESC LIMIT 0,15' ;
$alertquery = 'SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = ' . LegacyAuth :: id () . ' ORDER BY `time_logged` DESC LIMIT 0,15' ;
2015-07-13 20:10:26 +02:00
}
echo '<div class="container-fluid">
2014-02-28 22:02:39 +00:00
<div class="row">
2015-02-20 00:33:49 +01:00
<div class="col-md-6">
2014-02-28 22:02:39 +00:00
</div>
2014-06-15 01:36:49 +01:00
</div>
<div class="row">
2015-02-20 00:33:49 +01:00
<div class="col-md-6 column">
<div class="panel panel-default panel-condensed">
<div class="panel-heading">
<strong>Alertlog entries</strong>
</div>
2015-07-13 20:10:26 +02:00
<table class="table table-hover table-condensed table-striped">' ;
foreach ( dbFetchRows ( $alertquery ) as $alert_entry ) {
include 'includes/print-alerts.inc.php' ;
}
2015-02-20 00:33:49 +01:00
2016-10-08 20:48:11 +03:00
echo '</table>
2015-02-20 00:33:49 +01:00
</div>
</div>
<div class="col-md-6 column">
2014-02-28 22:02:39 +00:00
<div class="panel panel-default panel-condensed">
<div class="panel-heading">
<strong>Eventlog entries</strong>
</div>
2015-07-13 20:10:26 +02:00
<table class="table table-hover table-condensed table-striped">' ;
2008-11-04 12:34:30 +00:00
2015-07-13 20:10:26 +02:00
foreach ( dbFetchRows ( $query ) as $entry ) {
include 'includes/print-event.inc.php' ;
}
2008-11-04 12:34:30 +00:00
2015-07-13 20:10:26 +02:00
echo '</table>' ;
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
echo '</div>' ;
} //end if
2014-01-13 10:05:19 +00:00
2016-06-20 23:00:40 +01:00
?>
</div>
2015-07-13 20:10:26 +02:00
</div>