2009-10-02 13:20:24 +00:00
<? php
2011-03-16 18:28:52 +00:00
function generate_device_link ( $device , $text = 0 , $linksuffix = "" , $start = 0 , $end = 0 )
2010-06-24 18:04:42 +00:00
{
2011-03-31 10:51:02 +00:00
global $twoday , $day , $now , $config ;
2011-02-02 11:59:08 +00:00
2010-06-24 18:04:42 +00:00
if ( ! $start ) { $start = $day ; }
if ( ! $end ) { $end = $now ; }
$class = devclass ( $device );
if ( ! $text ) { $text = $device [ 'hostname' ]; }
2011-02-02 11:59:08 +00:00
2010-07-23 15:05:01 +00:00
if ( isset ( $config [ 'os' ][ $device [ 'os' ]][ 'over' ]))
2010-06-24 18:04:42 +00:00
{
2010-07-23 15:05:01 +00:00
$graphs = $config [ 'os' ][ $device [ 'os' ]][ 'over' ];
2010-06-24 18:04:42 +00:00
}
2010-07-23 15:05:01 +00:00
elseif ( isset ( $config [ 'os' ][ $device [ 'os_group' ]][ 'over' ]))
2010-06-25 13:04:03 +00:00
{
2010-07-23 15:05:01 +00:00
$graphs = $config [ 'os' ][ $device [ 'os_group' ]][ 'over' ];
2011-03-16 18:28:52 +00:00
}
2010-06-24 18:04:42 +00:00
else
{
2011-03-16 18:28:52 +00:00
$graphs = $config [ 'os' ][ 'default' ][ 'over' ];
2010-06-24 18:04:42 +00:00
}
2011-04-21 13:41:24 +00:00
$url = "device/" . $device [ 'device_id' ] . "/" . $linksuffix ;
2010-07-24 19:14:41 +00:00
$contents = "<div class=list-large>" . $device [ 'hostname' ];
2011-03-16 18:28:52 +00:00
if ( $device [ 'hardware' ]) { $contents .= " - " . $device [ 'hardware' ]; }
2010-07-24 19:14:41 +00:00
$contents .= "</div>" ;
2010-07-23 13:40:31 +00:00
$contents .= "<div>" ;
2011-03-16 18:28:52 +00:00
if ( $device [ 'os' ]) { $contents .= mres ( $config [ 'os' ][ $device [ 'os' ]][ 'text' ]); }
if ( $device [ 'version' ]) { $contents .= " " . mres ( $device [ 'version' ]); }
if ( $device [ 'features' ]) { $contents .= " (" . mres ( $device [ 'features' ]) . ")" ; }
# if ($device['hardware']) { $contents .= " - ".$device['hardware']; }
2010-07-23 13:40:31 +00:00
$contents .= "</div>" ;
2010-07-24 19:14:41 +00:00
# if (isset($device['location'])) { $contents .= "" . htmlentities($device['location'])."<br />"; }
2010-07-23 15:05:01 +00:00
foreach ( $graphs as $entry )
2010-06-24 18:04:42 +00:00
{
2010-07-23 15:05:01 +00:00
$graph = $entry [ 'graph' ];
2011-03-16 18:28:52 +00:00
$graphhead = $entry [ 'text' ];
2010-07-23 15:05:01 +00:00
$contents .= '<div style="width: 708px">' ;
$contents .= '<span style="margin-left: 5px; font-size: 12px; font-weight: bold;">' . $graphhead . '</span><br />' ;
2011-04-21 13:41:24 +00:00
$contents .= "<img src= \" graph.php?id=" . $device [ 'device_id' ] . "&from= $start &to= $end &width=275&height=100&type= $graph &legend=no" . '" style="margin: 2px;">' ;
$contents .= "<img src= \" graph.php?id=" . $device [ 'device_id' ] . "&from=" . $config [ 'week' ] . "&to= $end &width=275&height=100&type= $graph &legend=no" . '" style="margin: 2px;">' ;
2010-07-23 15:05:01 +00:00
$contents .= '</div>' ;
2010-06-24 18:04:42 +00:00
}
2011-03-16 18:28:52 +00:00
2010-06-24 18:04:42 +00:00
$text = htmlentities ( $text );
$link = overlib_link ( $url , $text , $contents , $class );
2011-03-16 18:28:52 +00:00
if ( device_permitted ( $device [ 'device_id' ]))
{
2010-06-24 18:04:42 +00:00
return $link ;
} else {
return $device [ 'hostname' ];
}
return $link ;
}
2011-03-16 18:28:52 +00:00
function overlib_link ( $url , $text , $contents , $class )
{
2010-05-02 23:24:47 +00:00
global $config ;
2011-03-16 18:28:52 +00:00
2010-05-02 23:24:47 +00:00
$contents = str_replace ( " \" " , "\'" , $contents );
$output = "<a class='" . $class . "' href='" . $url . "'" ;
$output .= " onmouseover= \" return overlib('" . $contents . "'" . $config [ 'overlib_defaults' ] . "); \" onmouseout= \" return nd(); \" >" ;
$output .= $text . "</a>" ;
2011-03-16 18:28:52 +00:00
2010-05-02 23:24:47 +00:00
return $output ;
}
2011-03-16 18:28:52 +00:00
function generate_graph_popup ( $graph_array )
2010-05-02 23:24:47 +00:00
{
global $config ;
## Take $graph_array and print day,week,month,year graps in overlib, hovered over graph
$graph = generate_graph_tag ( $graph_array );
$content = "<div class=list-large>" . $graph_array [ 'popup_title' ] . "</div>" ;
$content .= "<div style=\'width: 850px\'>" ;
$graph_array [ 'legend' ] = "yes" ;
$graph_array [ 'height' ] = "100" ;
$graph_array [ 'width' ] = "340" ;
$graph_array [ 'from' ] = $config [ 'day' ];
$content .= generate_graph_tag ( $graph_array );
$graph_array [ 'from' ] = $config [ 'week' ];
$content .= generate_graph_tag ( $graph_array );
$graph_array [ 'from' ] = $config [ 'month' ];
$content .= generate_graph_tag ( $graph_array );
$graph_array [ 'from' ] = $config [ 'year' ];
$content .= generate_graph_tag ( $graph_array );
$content .= "</div>" ;
2011-03-31 10:51:02 +00:00
return overlib_link ( $graph_array [ 'link' ], $graph , $content , NULL );
2010-05-02 23:24:47 +00:00
}
function print_graph_popup ( $graph_array )
{
2010-11-20 14:04:07 +00:00
echo ( generate_graph_popup ( $graph_array ));
2010-05-02 23:24:47 +00:00
}
2011-03-16 18:28:52 +00:00
function permissions_cache ( $user_id )
2010-07-31 21:08:35 +00:00
{
2010-04-24 14:23:16 +00:00
$permissions = array ();
$query = mysql_query ( "SELECT * FROM devices_perms WHERE user_id = '" . $user_id . "'" );
2011-03-16 18:28:52 +00:00
while ( $device = mysql_fetch_assoc ( $query ))
{
$permissions [ 'device' ][ $device [ 'device_id' ]] = 1 ;
2010-04-24 14:23:16 +00:00
}
$query = mysql_query ( "SELECT * FROM ports_perms WHERE user_id = '" . $user_id . "'" );
2011-03-16 18:28:52 +00:00
while ( $port = mysql_fetch_assoc ( $query ))
{
2010-06-10 20:13:41 +00:00
$permissions [ 'port' ][ $port [ 'interface_id' ]] = 1 ;
2010-04-24 14:23:16 +00:00
}
2010-07-31 21:08:35 +00:00
$query = mysql_query ( "SELECT * FROM bill_perms WHERE user_id = '" . $user_id . "'" );
2011-03-16 18:28:52 +00:00
while ( $bill = mysql_fetch_assoc ( $query ))
{
2010-07-31 21:08:35 +00:00
$permissions [ 'bill' ][ $bill [ 'bill_id' ]] = 1 ;
}
2011-03-31 10:51:02 +00:00
2010-04-24 14:23:16 +00:00
return $permissions ;
}
2011-03-16 18:28:52 +00:00
function bill_permitted ( $bill_id )
2010-07-31 21:08:35 +00:00
{
2011-03-31 17:19:54 +00:00
global $permissions ;
2011-03-16 18:28:52 +00:00
2010-07-31 21:08:35 +00:00
if ( $_SESSION [ 'userlevel' ] >= "5" ) {
$allowed = TRUE ;
2011-03-16 18:28:52 +00:00
} elseif ( $permissions [ 'bill' ][ $bill_id ]) {
2010-07-31 21:08:35 +00:00
$allowed = TRUE ;
} else {
$allowed = FALSE ;
}
2011-03-16 18:28:52 +00:00
return $allowed ;
2010-07-31 21:08:35 +00:00
}
2011-03-16 18:28:52 +00:00
2010-08-01 14:17:06 +00:00
function port_permitted ( $interface_id , $device_id = NULL )
2010-04-24 22:43:25 +00:00
{
2011-03-31 17:19:54 +00:00
global $permissions ;
2010-08-01 14:17:06 +00:00
2011-03-16 18:28:52 +00:00
if ( ! is_numeric ( $device_id )) { $device_id = get_device_id_by_interface_id ( $interface_id ); }
if ( $_SESSION [ 'userlevel' ] >= "5" )
{
2010-04-24 22:43:25 +00:00
$allowed = TRUE ;
2011-03-16 18:28:52 +00:00
} elseif ( device_permitted ( $device_id )) {
2010-04-24 22:43:25 +00:00
$allowed = TRUE ;
2011-03-16 18:28:52 +00:00
} elseif ( $permissions [ 'port' ][ $interface_id ]) {
2010-04-24 22:43:25 +00:00
$allowed = TRUE ;
} else {
$allowed = FALSE ;
}
2011-03-16 18:28:52 +00:00
2010-04-24 22:43:25 +00:00
return $allowed ;
}
2010-08-01 14:17:06 +00:00
function application_permitted ( $app_id , $device_id = NULL )
{
2011-03-31 17:19:54 +00:00
global $permissions ;
2011-03-16 18:28:52 +00:00
if ( is_numeric ( $app_id ))
2010-08-01 14:17:06 +00:00
{
2011-03-16 18:28:52 +00:00
if ( ! $device_id ) { $device_id = device_by_id_cache ( $app_id ); }
2010-08-01 14:17:06 +00:00
if ( $_SESSION [ 'userlevel' ] >= "5" ) {
$allowed = TRUE ;
2011-03-16 18:28:52 +00:00
} elseif ( device_permitted ( $device_id )) {
2010-08-01 14:17:06 +00:00
$allowed = TRUE ;
2011-03-16 18:28:52 +00:00
} elseif ( $permissions [ 'application' ][ $app_id ]) {
2010-08-01 14:17:06 +00:00
$allowed = TRUE ;
} else {
$allowed = FALSE ;
}
} else {
$allowed = FALSE ;
}
2011-03-31 10:51:02 +00:00
2010-08-01 14:17:06 +00:00
return $allowed ;
}
function device_permitted ( $device_id )
2010-04-24 22:43:25 +00:00
{
2011-03-31 17:19:54 +00:00
global $permissions ;
2011-03-16 18:28:52 +00:00
if ( $_SESSION [ 'userlevel' ] >= "5" )
{
2010-04-24 22:43:25 +00:00
$allowed = true ;
2011-03-27 10:21:19 +00:00
} elseif ( $permissions [ 'device' ][ $device_id ]) {
2010-04-24 22:43:25 +00:00
$allowed = true ;
} else {
$allowed = false ;
}
2011-03-16 18:28:52 +00:00
return $allowed ;
2010-04-24 22:43:25 +00:00
}
2011-03-16 18:28:52 +00:00
function print_graph_tag ( $args )
2010-03-11 21:58:50 +00:00
{
2010-11-20 14:04:07 +00:00
echo ( generate_graph_tag ( $args ));
2010-03-11 21:58:50 +00:00
}
2011-03-16 18:28:52 +00:00
function generate_graph_tag ( $args )
2010-03-11 21:58:50 +00:00
{
global $config ;
2011-03-16 18:28:52 +00:00
2010-03-11 21:58:50 +00:00
$sep = "?" ;
2011-04-21 13:41:24 +00:00
$url = "graph.php" ;
2011-03-16 18:28:52 +00:00
foreach ( $args as $key => $arg )
2010-03-11 21:58:50 +00:00
{
$url .= $sep . $key . "=" . $arg ;
2011-03-28 09:11:05 +00:00
$sep = "&" ;
2010-03-11 21:58:50 +00:00
}
2011-03-31 10:51:02 +00:00
2010-03-11 21:58:50 +00:00
return "<img src= \" " . $url . " \" border=0>" ;
}
2011-03-16 18:28:52 +00:00
function print_percentage_bar ( $width , $height , $percent , $left_text , $left_colour , $left_background , $right_text , $right_colour , $right_background )
2010-02-16 00:44:10 +00:00
{
$output = '
<div style="font-size:11px;">
<div style=" width:' . $width . 'px; height:' . $height . 'px; background-color:#' . $right_background . ';">
<div style="width:' . $percent . '%; height:' . $height . 'px; background-color:#' . $left_background . '; border-right:0px white solid;"></div>
2011-03-04 16:14:21 +00:00
<div style="vertical-align: middle;height: ' . $height . 'px;margin-top:-' . ( $height ) . 'px; color:#' . $left_colour . '; padding-left :4px;"><b>' . $left_text . '</b></div>
<div style="vertical-align: middle;height: ' . $height . 'px;margin-top:-' . ( $height ) . 'px; color:#' . $right_colour . '; padding-right:4px;text-align:right;"><b>' . $right_text . '</b></div>
2010-02-16 00:44:10 +00:00
</div>
</div>' ;
2011-03-31 10:51:02 +00:00
2010-02-13 23:55:56 +00:00
return $output ;
}
2010-08-02 22:09:52 +00:00
function generate_port_link ( $args , $text = NULL , $type = NULL )
2009-10-02 13:20:24 +00:00
{
2011-03-31 10:51:02 +00:00
global $twoday , $now , $config , $day , $month ;
2009-10-02 13:20:24 +00:00
$args = ifNameDescr ( $args );
2011-03-16 18:28:52 +00:00
if ( ! $text ) { $text = fixIfName ( $args [ 'label' ]); }
if ( $type ) { $args [ 'graph_type' ] = $type ; }
if ( ! $args [ 'graph_type' ]) { $args [ 'graph_type' ] = 'port_bits' ; }
2009-10-02 13:20:24 +00:00
$class = ifclass ( $args [ 'ifOperStatus' ], $args [ 'ifAdminStatus' ]);
2011-03-16 18:28:52 +00:00
if ( ! isset ( $args [ 'hostname' ])) { $args = array_merge ( $args , device_by_id_cache ( $args [ 'device_id' ])); }
2010-05-02 23:24:47 +00:00
$content = "<div class=list-large>" . $args [ 'hostname' ] . " - " . fixifName ( $args [ 'label' ]) . "</div>" ;
2011-03-16 18:28:52 +00:00
if ( $args [ 'ifAlias' ]) { $content .= $args [ 'ifAlias' ] . "<br />" ; }
2010-05-02 23:24:47 +00:00
$content .= "<div style=\'width: 850px\'>" ;
$graph_array [ 'type' ] = $args [ 'graph_type' ];
$graph_array [ 'legend' ] = "yes" ;
$graph_array [ 'height' ] = "100" ;
$graph_array [ 'width' ] = "340" ;
2010-08-01 16:50:53 +00:00
$graph_array [ 'to' ] = $config [ 'now' ];
2010-05-02 23:24:47 +00:00
$graph_array [ 'from' ] = $config [ 'day' ];
2010-08-01 00:38:01 +00:00
$graph_array [ 'id' ] = $args [ 'interface_id' ];
2010-05-02 23:24:47 +00:00
$content .= generate_graph_tag ( $graph_array );
$graph_array [ 'from' ] = $config [ 'week' ];
$content .= generate_graph_tag ( $graph_array );
$graph_array [ 'from' ] = $config [ 'month' ];
$content .= generate_graph_tag ( $graph_array );
$graph_array [ 'from' ] = $config [ 'year' ];
$content .= generate_graph_tag ( $graph_array );
$content .= "</div>" ;
2011-03-16 18:28:52 +00:00
2011-04-21 13:41:24 +00:00
$url = "device/" . $args [ 'device_id' ] . "/port/" . $args [ 'interface_id' ] . "/" ;
2010-05-02 23:24:47 +00:00
2011-03-16 18:28:52 +00:00
if ( port_permitted ( $args [ 'interface_id' ])) {
2010-05-02 23:24:47 +00:00
return overlib_link ( $url , $text , $content , $class );
} else {
return fixifName ( $text );
}
2009-10-02 13:20:24 +00:00
}
2011-03-16 18:28:52 +00:00
function generate_port_thumbnail ( $args )
2010-03-11 21:58:50 +00:00
{
2011-03-31 10:51:02 +00:00
if ( ! $args [ 'bg' ]) { $args [ 'bg' ] = "FFFFF" ; }
$args [ 'content' ] = "<img src='graph.php?type=" . $args [ 'graph_type' ] . "&id=" . $args [ 'interface_id' ] . "&from=" . $args [ 'from' ] . "&to=" . $args [ 'to' ] . "&width=" . $args [ 'width' ] . "&height=" . $args [ 'height' ] . "&legend=no&bg=" . $args [ 'bg' ] . "'>" ;
echo ( generate_port_link ( $args , $args [ 'content' ]));
2009-10-02 13:20:24 +00:00
}
2011-03-16 18:28:52 +00:00
function print_optionbar_start ( $height = 20 , $width = 0 , $marginbottom = 5 )
2010-03-11 21:58:50 +00:00
{
2009-10-02 13:20:24 +00:00
echo ( "
2010-07-05 19:19:19 +00:00
<div style='text-align: center; margin-top: 0px; margin-bottom: " . $marginbottom . "px; " . ( $width ? 'max-width: ' . $width . ( strstr ( $width , '%' ) ? '' : 'px' ) . '; ' : '' ) . "'>
2009-10-02 13:20:24 +00:00
<b class='rounded'>
<b class='rounded1'><b></b></b>
<b class='rounded2'><b></b></b>
<b class='rounded3'></b>
<b class='rounded4'></b>
<b class='rounded5'></b></b>
<div class='roundedfg' style='padding: 0px 5px;'>
2010-06-23 16:33:23 +00:00
<div style='margin: auto; text-align: left; padding: 2px 5px; padding-left: 11px; clear: both; display:block; " . ( $height ? 'height:' . $height . 'px;' : '' ) . "'>" );
2009-10-02 13:20:24 +00:00
}
2011-03-16 18:28:52 +00:00
function print_optionbar_end ()
2010-03-11 21:58:50 +00:00
{
2011-03-16 18:28:52 +00:00
echo ( ' </div>
2009-10-02 13:20:24 +00:00
</div>
2011-03-16 18:28:52 +00:00
<b class="rounded">
<b class="rounded5"></b>
<b class="rounded4"></b>
<b class="rounded3"></b>
<b class="rounded2"><b></b></b>
<b class="rounded1"><b></b></b></b>
</div>' );
2009-10-02 13:20:24 +00:00
}
2011-03-16 18:28:52 +00:00
function geteventicon ( $message )
2010-07-07 13:58:11 +00:00
{
if ( $message == "Device status changed to Down" ) { $icon = "server_connect.png" ; }
if ( $message == "Device status changed to Up" ) { $icon = "server_go.png" ; }
2011-03-27 10:21:19 +00:00
if ( $message == "Interface went down" || $message == "Interface changed state to Down" ) { $icon = "if-disconnect.png" ; }
if ( $message == "Interface went up" || $message == "Interface changed state to Up" ) { $icon = "if-connect.png" ; }
2010-07-07 13:58:11 +00:00
if ( $message == "Interface disabled" ) { $icon = "if-disable.png" ; }
if ( $message == "Interface enabled" ) { $icon = "if-enable.png" ; }
if ( isset ( $icon )) { return $icon ; } else { return false ; }
}
2011-03-16 18:28:52 +00:00
function overlibprint ( $text )
{
return "onmouseover= \" return overlib('" . $text . "'); \" onmouseout= \" return nd(); \" " ;
2010-07-07 13:58:11 +00:00
}
2011-03-16 18:28:52 +00:00
function humanmedia ( $media )
2010-07-07 13:58:11 +00:00
{
array_preg_replace ( $rewrite_iftype , $media );
return $media ;
}
2011-03-16 18:28:52 +00:00
function humanspeed ( $speed )
2010-07-07 13:58:11 +00:00
{
$speed = formatRates ( $speed );
if ( $speed == "" ) { $speed = "-" ; }
return $speed ;
}
function print_error ( $text )
{
2011-03-26 19:28:39 +00:00
echo ( '<div class="errorbox"><img src="/images/15/exclamation.png" align="absmiddle"> ' . $text . '</div>' );
2010-07-07 13:58:11 +00:00
}
function print_message ( $text )
{
2011-03-26 19:28:39 +00:00
echo ( '<div class="messagebox"><img src="/images/16/tick.png" align="absmiddle"> ' . $text . '</div>' );
2010-07-07 13:58:11 +00:00
}
2011-03-16 18:28:52 +00:00
function devclass ( $device )
2010-07-17 22:53:53 +00:00
{
2011-03-16 18:28:52 +00:00
if ( isset ( $device [ 'status' ]) && $device [ 'status' ] == '0' ) { $class = "list-device-down" ; } else { $class = "list-device" ; }
if ( isset ( $device [ 'ignore' ]) && $device [ 'ignore' ] == '1' )
{
2010-07-17 22:53:53 +00:00
$class = "list-device-ignored" ;
if ( isset ( $device [ 'status' ]) && $device [ 'status' ] == '1' ) { $class = "list-device-ignored-up" ; }
2011-03-16 18:28:52 +00:00
}
if ( isset ( $device [ 'disabled' ]) && $device [ 'disabled' ] == '1' ) { $class = "list-device-disabled" ; }
2010-07-17 22:53:53 +00:00
return $class ;
}
2011-03-31 17:19:54 +00:00
function getlocations ()
{
# Fetch override locations, not through get_dev_attrib, this would be a huge number of queries
$result = mysql_query ( "SELECT attrib_type,attrib_value,device_id FROM devices_attribs WHERE attrib_type LIKE 'override_sysLocation%' ORDER BY attrib_type" );
while ( $row = mysql_fetch_assoc ( $result ))
{
if ( $row [ 'attrib_type' ] == 'override_sysLocation_bool' && $row [ 'attrib_value' ] == 1 )
{
$ignore_dev_location [ $row [ 'device_id' ]] = 1 ;
}
# We can do this because of the ORDER BY, "bool" will be handled before "string"
elseif ( $row [ 'attrib_type' ] == 'override_sysLocation_string' && $ignore_dev_location [ $row [ 'device_id' ]] == 1 )
{
2011-03-31 17:35:09 +00:00
if ( ! in_array ( $row [ 'attrib_value' ], $locations )) { $locations [] = $row [ 'attrib_value' ]; }
2011-03-31 17:19:54 +00:00
}
}
# Fetch regular locations
if ( $_SESSION [ 'userlevel' ] >= '5' )
{
$result = mysql_query ( "SELECT D.device_id,location FROM devices AS D GROUP BY location ORDER BY location" );
} else {
$result = mysql_query ( "SELECT D.device_id,location FROM devices AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION [ 'user_id' ] . "' GROUP BY location ORDER BY location" );
}
while ( $row = mysql_fetch_assoc ( $result ))
{
# Only add it as a location if it wasn't overridden (and not already there)
if ( $row [ 'location' ] != '' && ! $ignore_dev_location [ $row [ 'device_id' ]])
{
if ( ! in_array ( $row [ 'location' ], $locations )) { $locations [] = $row [ 'location' ]; }
}
}
sort ( $locations );
return $locations ;
}
2011-03-16 18:28:52 +00:00
?>