2008-11-04 12:34:30 +00:00
<? php
2014-01-13 10:05:19 +00:00
include ( "includes/topnav.inc.php" );
2013-11-19 08:57:43 +10:00
2013-11-10 05:45:27 +10:00
function generate_front_box ( $frontbox_class , $content )
2011-03-17 00:09:20 +00:00
{
2013-11-10 05:45:27 +10:00
echo ( "<div class= \" front-box $frontbox_class \" >
2010-08-13 12:50:01 +00:00
$content
</div>" );
2008-11-04 12:34:30 +00:00
}
2014-01-13 10:05:19 +00:00
echo ( '
<div class="row">
<div class="col-md-8">
' );
2013-11-19 08:57:43 +10:00
echo ( '<div class=front-page>' );
2014-01-13 10:05:19 +00: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
2011-03-17 00:09:20 +00:00
if ( $_SESSION [ 'userlevel' ] == '10' )
{
2008-11-04 12:34:30 +00:00
$sql = mysql_query ( "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'" );
2009-12-31 19:06:05 +00:00
} else {
$sql = mysql_query ( "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION [ 'user_id' ] . "' AND D.status = '0' AND D.ignore = '0'" );
}
2011-09-20 14:37:54 +00:00
while ( $device = mysql_fetch_assoc ( $sql )) {
2008-11-04 12:34:30 +00:00
2013-11-19 08:57:43 +10:00
generate_front_box ( "device-down" , generate_device_link ( $device , shorthost ( $device [ 'hostname' ])) . "<br />
<span class=list-device-down>Device Down</span> <br />
<span class=body-date-1>" . truncate ( $device [ 'location' ], 20 ) . "</span>" );
++ $count_boxes ;
2008-11-04 12:34:30 +00:00
}
2011-03-17 00:09:20 +00:00
if ( $_SESSION [ 'userlevel' ] == '10' )
{
2010-02-20 17:22:22 +00:00
$sql = mysql_query ( "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'" );
2009-12-31 19:06:05 +00:00
} else {
2010-02-20 17:22:22 +00:00
$sql = mysql_query ( "SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION [ 'user_id' ] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'" );
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 :>
2010-07-01 12:34:01 +00:00
2013-11-19 08:57:43 +10:00
// Port down boxes
2012-03-20 11:52:01 +00:00
if ( $config [ 'warn' ][ 'ifdown' ])
2011-03-17 00:09:20 +00:00
{
2012-04-06 13:56:23 +00:00
while ( $interface = mysql_fetch_assoc ( $sql ))
2011-03-17 00:09:20 +00:00
{
2012-03-20 11:52:01 +00:00
if ( ! $interface [ 'deleted' ])
{
2013-11-19 08:57:43 +10:00
$interface = ifNameDescr ( $interface );
generate_front_box ( "port-down" , generate_device_link ( $interface , shorthost ( $interface [ 'hostname' ])) . "<br />
<span class= \" interface-updown \" >Port Down</span><br />
2012-05-16 13:25:50 +00:00
<!-- <img src='graph.php?type=bits&if=" . $interface [ 'port_id' ] . "&from=" . $config [ 'time' ][ 'day' ] . "&to=" . $config [ 'time' ][ 'now' ] . "&width=100&height=32' /> -->
2013-11-10 04:46:10 +10:00
" . generate_port_link ( $interface , truncate ( makeshortif ( $interface [ 'label' ]), 13 , '' )) . " <br />
2013-11-19 08:57:43 +10:00
" . ( $interface [ 'ifAlias' ] ? '<span class="body-date-1">' . truncate ( $interface [ 'ifAlias' ], 20 , '' ) . '</span>' : '' ));
++ $count_boxes ;
2012-03-20 11:52:01 +00:00
}
2010-07-01 12:34:01 +00:00
}
2008-11-04 12:34:30 +00:00
}
2009-12-31 19:06:05 +00:00
/* FIXME service permissions? seem nonexisting now.. */
2013-11-19 08:57:43 +10:00
// Service down boxes
2010-02-21 19:32:08 +00:00
$sql = mysql_query ( "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'" );
2011-04-06 13:54:50 +00:00
while ( $service = mysql_fetch_assoc ( $sql ))
2011-03-17 00:09:20 +00:00
{
2013-11-19 08:57:43 +10:00
generate_front_box ( "service-down" , generate_device_link ( $service , shorthost ( $service [ 'hostname' ])) . "<br />
2013-11-10 04:46:10 +10:00
<span class=service-down>Service Down</span>
" . $service [ 'service_type' ] . "<br />
2013-11-19 08:57:43 +10:00
<span class=body-date-1>" . truncate ( $interface [ 'ifAlias' ], 20 ) . "</span>" );
++ $count_boxes ;
2008-11-04 12:34:30 +00:00
}
2013-11-19 08:57:43 +10:00
// BGP neighbour down boxes
2010-07-27 20:49:31 +00:00
if ( isset ( $config [ 'enable_bgp' ]) && $config [ 'enable_bgp' ])
{
2011-03-17 00:09:20 +00:00
if ( $_SESSION [ 'userlevel' ] == '10' )
{
2011-05-11 10:01:28 +00:00
$sql = mysql_query ( "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" );
2010-07-27 20:49:31 +00:00
} else {
2011-05-11 10:01:28 +00:00
$sql = mysql_query ( "SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION [ 'user_id' ] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0" );
2010-07-27 20:49:31 +00:00
}
2011-04-06 13:54:50 +00:00
while ( $peer = mysql_fetch_assoc ( $sql ))
2010-07-27 20:49:31 +00:00
{
2013-11-19 08:57:43 +10:00
generate_front_box ( "bgp-down" , generate_device_link ( $peer , shorthost ( $peer [ 'hostname' ])) . "<br />
<span class=bgp-down>BGP Down</span>
<span class='" . ( strstr ( $peer [ 'bgpPeerIdentifier' ], ':' ) ? 'front-page-bgp-small' : 'front-page-bgp-normal' ) . "'>" . $peer [ 'bgpPeerIdentifier' ] . "</span><br />
<span class=body-date-1>AS" . truncate ( $peer [ 'bgpPeerRemoteAs' ] . " " . $peer [ 'astext' ], 14 , "" ) . "</span>" );
++ $count_boxes ;
2010-07-27 20:49:31 +00:00
}
2008-11-04 12:34:30 +00:00
}
2013-11-19 08:57:43 +10:00
// Device rebooted boxes
2011-04-13 16:37:29 +00:00
if ( filter_var ( $config [ 'uptime_warning' ], FILTER_VALIDATE_FLOAT ) !== FALSE && $config [ 'uptime_warning' ] > 0 )
2011-04-06 13:54:50 +00:00
{
2011-04-13 16:37:29 +00:00
if ( $_SESSION [ 'userlevel' ] == '10' )
{
2012-04-07 18:21:39 +00:00
$sql = mysql_query ( "SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config [ 'uptime_warning' ] . "' AND D.ignore = 0" );
2011-04-13 16:37:29 +00:00
} else {
2012-04-07 18:21:39 +00:00
$sql = mysql_query ( "SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION [ 'user_id' ] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" .
2011-04-13 16:37:29 +00:00
$config [ 'uptime_warning' ] . "' AND D.ignore = 0" );
}
2008-11-04 12:34:30 +00:00
2011-04-13 16:37:29 +00:00
while ( $device = mysql_fetch_assoc ( $sql ))
{
2013-11-19 08:57:43 +10:00
generate_front_box ( "device-rebooted" , 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>" );
++ $count_boxes ;
2011-04-13 16:37:29 +00:00
}
2008-11-04 12:34:30 +00:00
}
2013-11-19 08:57:43 +10:00
if ( $count_boxes == 0 ) {
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
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
want to start by adding one or more devices in the Devices menu.</p>" );
}
echo ( '</div>' );
2014-01-13 10:05:19 +00:00
echo ( '</div>' );
echo ( '</div>' );
echo ( '
<div class="col-md-4">
' );
include_once ( "includes/front/boxes.inc.php" );
echo ( '
</div>
</div>
<div class="row">
<div class="col-md-12">
' );
2008-11-04 12:34:30 +00:00
2011-03-17 00:09:20 +00:00
if ( $config [ 'enable_syslog' ])
{
2013-11-10 15:19:10 +10:00
echo ( "<div class=front-syslog>
2008-11-04 12:34:30 +00:00
<h3>Recent Syslog Messages</h3>
" );
2010-02-19 01:40:38 +00:00
$sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog ORDER BY timestamp DESC LIMIT 20" ;
2008-11-04 12:34:30 +00:00
$query = mysql_query ( $sql );
2014-01-13 10:05:19 +00:00
echo ( '<table class="table table-bordered">' );
2011-04-06 13:54:50 +00:00
while ( $entry = mysql_fetch_assoc ( $query ))
{
2010-01-29 21:10:05 +00:00
$entry = array_merge ( $entry , device_by_id_cache ( $entry [ 'device_id' ]));
2012-04-06 13:56:23 +00:00
2011-03-17 16:35:18 +00:00
include ( "includes/print-syslog.inc.php" );
2010-01-29 21:10:05 +00:00
}
2008-11-04 12:34:30 +00:00
echo ( "</table>" );
2013-11-19 08:57:43 +10:00
echo ( "</div>" );
2008-11-04 12:34:30 +00:00
} else {
2013-11-10 15:19:10 +10:00
echo ( "<div class=front-eventlog>
2008-11-04 12:34:30 +00:00
<h3>Recent Eventlog Entries</h3>
" );
2011-04-06 13:54:50 +00:00
if ( $_SESSION [ 'userlevel' ] == '10' )
{
$query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15" ;
} else {
$query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host =
P.device_id AND P.user_id = " . $_SESSION [ 'user_id' ] . " ORDER BY `datetime` DESC LIMIT 0,15" ;
}
2008-11-04 12:34:30 +00:00
2011-04-06 13:54:50 +00:00
$data = mysql_query ( $query );
2008-11-04 12:34:30 +00:00
2014-01-13 10:05:19 +00:00
echo ( '<table class="table table-bordered">' );
2008-11-04 12:34:30 +00:00
2011-04-06 13:54:50 +00:00
while ( $entry = mysql_fetch_assoc ( $data )) {
include ( "includes/print-event.inc.php" );
}
2008-11-04 12:34:30 +00:00
2011-04-06 13:54:50 +00:00
echo ( "</table>" );
2013-11-19 08:57:43 +10:00
echo ( "</div>" );
2008-11-04 12:34:30 +00:00
}
echo ( "</div>" );
2014-01-13 10:05:19 +00:00
echo ( '
</div>
</div>
' );
2011-04-13 16:37:29 +00:00
?>