2015-08-11 10:38:25 +00:00
< ? php
2018-08-21 15:45:37 -05:00
use LibreNMS\Config ;
2015-08-11 10:38:25 +00:00
2018-08-21 15:45:37 -05:00
$cust_descrs = ( array ) Config :: get ( 'customers_descr' , [ 'cust' ]);
2015-08-11 10:38:25 +00:00
2018-08-21 15:45:37 -05:00
$sql = ' FROM `ports` LEFT JOIN `devices` AS `D` ON `ports`.`device_id` = `D`.`device_id` WHERE `port_descr_type` IN ' . dbGenPlaceholders ( count ( $cust_descrs ));
$param = $cust_descrs ;
2015-08-11 10:38:25 +00:00
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
2018-08-21 15:45:37 -05:00
$sql .= " AND (`port_descr_descr` LIKE ? OR `ifName` LIKE ? OR `ifDescr` LIKE ? OR `ifAlias` LIKE ? OR `D`.`hostname` LIKE ? OR `port_descr_speed` LIKE ? OR `port_descr_notes` LIKE ?) " ;
array_push ( $param , " % $searchPhrase % " , " % $searchPhrase % " , " % $searchPhrase % " , " % $searchPhrase % " , " % $searchPhrase % " , " % $searchPhrase % " , " % $searchPhrase % " );
2015-08-11 10:38:25 +00:00
}
$count_sql = " SELECT COUNT(DISTINCT(`port_descr_descr`)) $sql " ;
$sql .= ' GROUP BY `port_descr_descr`' ;
2016-08-18 20:28:22 -05:00
$total = dbFetchCell ( $count_sql , $param );
2015-08-11 10:38:25 +00:00
if ( empty ( $total )) {
$total = 0 ;
}
if ( ! isset ( $sort ) || empty ( $sort )) {
$sort = '`port_descr_descr`' ;
}
$sql .= " ORDER BY $sort " ;
if ( isset ( $current )) {
$limit_low = ( $current * $rowCount ) - ( $rowCount );
$limit_high = $rowCount ;
}
if ( $rowCount != - 1 ) {
$sql .= " LIMIT $limit_low , $limit_high " ;
}
2017-01-07 17:32:38 +00:00
$sql = " SELECT `port_descr_descr` $sql " ;
2015-08-11 10:38:25 +00:00
foreach ( dbFetchRows ( $sql , $param ) as $customer ) {
$customer_name = $customer [ 'port_descr_descr' ];
2018-08-21 15:45:37 -05:00
$port_query = 'SELECT * FROM `ports` WHERE `port_descr_type` IN ' . dbGenPlaceholders ( count ( $cust_descrs )) . ' AND `port_descr_descr` = ?' ;
$port_params = $cust_descrs ;
$port_params [] = $customer_name ;
foreach ( dbFetchRows ( $port_query , $port_params ) as $port ) {
2015-08-11 10:38:25 +00:00
$device = device_by_id_cache ( $port [ 'device_id' ]);
$ifname = fixifname ( $device [ 'ifDescr' ]);
$ifclass = ifclass ( $port [ 'ifOperStatus' ], $port [ 'ifAdminStatus' ]);
2017-04-04 08:08:23 +01:00
$port = cleanPort ( $port );
2015-08-11 10:38:25 +00:00
if ( $device [ 'os' ] == 'ios' ) {
if ( $port [ 'ifTrunk' ]) {
$vlan = '<span class=box-desc><span class=red>' . $port [ 'ifTrunk' ] . '</span></span>' ;
2016-08-18 20:28:22 -05:00
} elseif ( $port [ 'ifVlan' ]) {
2015-08-11 10:38:25 +00:00
$vlan = '<span class=box-desc><span class=blue>VLAN ' . $port [ 'ifVlan' ] . '</span></span>' ;
2016-08-18 20:28:22 -05:00
} else {
2015-08-11 10:38:25 +00:00
$vlan = '' ;
}
}
$response [] = array (
'port_descr_descr' => $customer_name ,
'device_id' => generate_device_link ( $device ),
'ifDescr' => generate_port_link ( $port , makeshortif ( $port [ 'ifDescr' ])),
'port_descr_speed' => $port [ 'port_descr_speed' ],
'port_descr_circuit' => $port [ 'port_descr_circuit' ],
'port_descr_notes' => $port [ 'port_descr_notes' ],
);
unset ( $customer_name );
}
$graph_array [ 'type' ] = 'customer_bits' ;
$graph_array [ 'height' ] = '100' ;
$graph_array [ 'width' ] = '220' ;
$graph_array [ 'to' ] = $config [ 'time' ][ 'now' ];
$graph_array [ 'id' ] = $customer [ 'port_descr_descr' ];
$return_data = true ;
include 'includes/print-graphrow.inc.php' ;
$response [] = array (
'port_descr_descr' => $graph_data [ 0 ],
'device_id' => $graph_data [ 1 ],
'ifDescr' => '' ,
'port_descr_speed' => '' ,
'port_descr_circuit' => $graph_data [ 2 ],
'port_descr_notes' => $graph_data [ 3 ],
);
}
$output = array (
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
'total' => $total ,
);
2016-08-18 20:28:22 -05:00
echo _json_encode ( $output );