2015-07-20 13:55:35 +01:00
<? php
$row = 1 ;
2018-03-25 22:50:09 +02:00
$device_id = $vars [ 'device_id' ];
2015-07-20 13:55:35 +01:00
$sql = 'FROM `ports` WHERE `device_id` = ?' ;
2020-09-21 15:40:17 +02:00
$param = [ $device_id ];
2015-07-20 13:55:35 +01:00
2020-09-21 15:40:17 +02:00
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
2020-09-21 15:59:34 +02:00
$sql .= ' AND (`ifName` LIKE ? OR `ifAlias` LIKE ? OR `ifDescr` LIKE ?)' ;
2020-07-10 16:17:09 +02:00
$param [] = "% $searchPhrase %" ;
$param [] = "% $searchPhrase %" ;
$param [] = "% $searchPhrase %" ;
2015-07-20 14:03:09 +01:00
}
2015-07-20 13:55:35 +01:00
$count_sql = "SELECT COUNT(`port_id`) $sql " ;
2020-09-21 15:40:17 +02:00
$total = dbFetchCell ( $count_sql , $param );
2015-07-20 13:55:35 +01:00
if ( empty ( $total )) {
$total = 0 ;
}
2020-09-21 15:40:17 +02:00
if ( ! isset ( $sort ) || empty ( $sort )) {
2015-07-20 13:55:35 +01:00
$sort = '`ifIndex` ASC' ;
}
$sql .= " ORDER BY $sort " ;
if ( isset ( $current )) {
2020-09-21 15:40:17 +02:00
$limit_low = (( $current * $rowCount ) - ( $rowCount ));
2015-07-20 13:55:35 +01:00
$limit_high = $rowCount ;
}
if ( $rowCount != - 1 ) {
$sql .= " LIMIT $limit_low , $limit_high " ;
}
$sql = "SELECT * $sql " ;
2020-09-21 15:40:17 +02:00
$response [] = [
2015-07-20 13:55:35 +01:00
'ifIndex' => "<button id='save-form' type='submit' value='Save' class='btn btn-success btn-sm' title='Save current port disable/ignore settings'>Save</button><button type='submit' value='Reset' class='btn btn-danger btn-sm' id='form-reset' title='Reset form to previously-saved settings'>Reset</button>" ,
'label' => '' ,
'ifAdminStatus' => '' ,
'ifOperStatus' => "<button type='submit' value='Alerted' class='btn btn-default btn-sm' id='alerted-toggle' title='Toggle alerting on all currently-alerted ports'>Alerted</button><button type='submit' value='Down' class='btn btn-default btn-sm' id='down-select' title='Disable alerting on all currently-down ports'>Down</button>" ,
'disabled' => "<button type='submit' value='Toggle' class='btn btn-default btn-sm' id='disable-toggle' title='Toggle polling for all ports'>Toggle</button><button type='submit' value='Select' class='btn btn-default btn-sm' id='disable-select' title='Disable polling on all ports'>Select All</button>" ,
2020-01-09 23:55:09 +01:00
'ignore' => "<button type='submit' value='Toggle' class='btn btn-default btn-sm' id='ignore-toggle' title='Toggle alert tag for all ports'>Toggle</button><button type='submit' value='Select' class='btn btn-default btn-sm' id='ignore-select' title='Disable alert tag on all ports'>Select All</button>" ,
2020-09-21 15:40:17 +02:00
'ifAlias' => '' ,
];
2015-07-20 13:55:35 +01:00
foreach ( dbFetchRows ( $sql , $param ) as $port ) {
2017-04-04 08:08:23 +01:00
$port = cleanPort ( $port );
2015-07-20 13:55:35 +01:00
// Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled
// - as to draw the attention to a possible problem.
2020-01-15 15:28:36 +01:00
$isportbad = ( $port [ 'ifOperStatus' ] != 'up' && $port [ 'ifAdminStatus' ] != 'down' ) ? 1 : 0 ;
2020-09-21 15:40:17 +02:00
$dowecare = ( $port [ 'ignore' ] == 0 && $port [ 'disabled' ] == 0 ) ? $isportbad : ! $isportbad ;
2015-07-20 13:55:35 +01:00
$outofsync = $dowecare ? " class='red'" : '' ;
2015-11-17 02:20:23 -08:00
$checked = '' ;
2016-01-21 12:32:20 +00:00
$device [ 'device_id' ] = $device_id ;
2020-09-21 15:59:34 +02:00
if ( get_dev_attrib ( $device , 'ifName_tune:' . $port [ 'ifName' ]) == 'true' ) {
2015-11-17 02:20:23 -08:00
$checked = 'checked' ;
}
2015-07-20 13:55:35 +01:00
2020-09-21 15:40:17 +02:00
$response [] = [
2015-11-17 02:20:23 -08:00
'ifIndex' => $port [ 'ifIndex' ],
'ifName' => $port [ 'label' ],
'ifAdminStatus' => $port [ 'ifAdminStatus' ],
2020-09-21 15:40:17 +02:00
'ifOperStatus' => '<span name="operstatus_' . $port [ 'port_id' ] . '"' . $outofsync . '>' . $port [ 'ifOperStatus' ] . '</span>' ,
'disabled' => '<input type="checkbox" class="disable-check" data-size="small" name="disabled_' . $port [ 'port_id' ] . '"' . ( $port [ 'disabled' ] ? 'checked' : '' ) . '>
<input type="hidden" name="olddis_' . $port [ 'port_id' ] . '" value="' . ( $port [ 'disabled' ] ? 1 : 0 ) . '"">' ,
'ignore' => '<input type="checkbox" class="ignore-check" data-size="small" name="ignore_' . $port [ 'port_id' ] . '"' . ( $port [ 'ignore' ] ? 'checked' : '' ) . '>
<input type="hidden" name="oldign_' . $port [ 'port_id' ] . '" value="' . ( $port [ 'ignore' ] ? 1 : 0 ) . '"">' ,
'port_tune' => '<input type="checkbox" id="override_config" name="override_config" data-attrib="ifName_tune:' . $port [ 'ifName' ] . '" data-device_id="' . $port [ 'device_id' ] . '" data-size="small" ' . $checked . '>' ,
'ifAlias' => '<div class="form-group"><input class="form-control input-sm" id="if-alias" name="if-alias" data-device_id="' . $port [ 'device_id' ] . '" data-port_id="' . $port [ 'port_id' ] . '" data-ifName="' . $port [ 'ifName' ] . '" value="' . $port [ 'ifAlias' ] . '"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>' ,
'ifSpeed' => '<div class="form-group has-feedback"><input type="text" pattern="[0-9]*" inputmode="numeric" class="form-control input-sm" id="if-speed" name="if-speed" data-device_id="' . $port [ 'device_id' ] . '" data-port_id="' . $port [ 'port_id' ] . '" data-ifName="' . $port [ 'ifName' ] . '" value="' . $port [ 'ifSpeed' ] . '"><span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span></div>' ,
];
2015-07-20 13:55:35 +01:00
} //end foreach
2020-09-21 15:40:17 +02:00
$output = [
2015-07-20 13:55:35 +01:00
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
'total' => $total ,
2020-09-21 15:40:17 +02:00
];
2015-08-30 17:33:54 +00:00
echo _json_encode ( $output );