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` = ?' ;
$param = array ( $device_id );
2015-07-20 14:03:09 +01:00
if ( isset ( $searchPhrase ) && ! empty ( $searchPhrase )) {
$sql .= " AND (`ifName` LIKE '% $searchPhrase %' OR `ifAlias` LIKE '% $searchPhrase %' OR `ifDescr` LIKE '% $searchPhrase %')" ;
}
2015-07-20 13:55:35 +01:00
$count_sql = "SELECT COUNT(`port_id`) $sql " ;
$total = dbFetchCell ( $count_sql , $param );
if ( empty ( $total )) {
$total = 0 ;
}
if ( ! isset ( $sort ) || empty ( $sort )) {
$sort = '`ifIndex` ASC' ;
}
$sql .= " ORDER BY $sort " ;
if ( isset ( $current )) {
$limit_low = (( $current * $rowCount ) - ( $rowCount ));
$limit_high = $rowCount ;
}
if ( $rowCount != - 1 ) {
$sql .= " LIMIT $limit_low , $limit_high " ;
}
$sql = "SELECT * $sql " ;
$response [] = array (
'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>" ,
2015-07-20 13:55:35 +01:00
'ifAlias' => ''
);
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 ;
2015-07-20 13:55:35 +01:00
$dowecare = ( $port [ 'ignore' ] == 0 && $port [ 'disabled' ] == 0 ) ? $isportbad : ! $isportbad ;
$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 ;
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
$response [] = array (
2015-11-17 02:20:23 -08:00
'ifIndex' => $port [ 'ifIndex' ],
'ifName' => $port [ 'label' ],
'ifAdminStatus' => $port [ 'ifAdminStatus' ],
'ifOperStatus' => '<span name="operstatus_' . $port [ 'port_id' ] . '"' . $outofsync . '>' . $port [ 'ifOperStatus' ] . '</span>' ,
2019-11-05 00:02:49 +01:00
'disabled' => '<input type="checkbox" class="disable-check" data-size="small" name="disabled_' . $port [ 'port_id' ] . '"' . ( $port [ 'disabled' ] ? 'checked' : '' ) . '>
2015-11-17 02:20:23 -08:00
<input type="hidden" name="olddis_' . $port [ 'port_id' ] . '" value="' . ( $port [ 'disabled' ] ? 1 : 0 ) . '"">' ,
2019-11-05 00:02:49 +01:00
'ignore' => '<input type="checkbox" class="ignore-check" data-size="small" name="ignore_' . $port [ 'port_id' ] . '"' . ( $port [ 'ignore' ] ? 'checked' : '' ) . '>
2015-11-17 02:20:23 -08:00
<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 . '>' ,
2017-04-04 08:08:23 +01:00
'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>' ,
2016-09-22 10:44:17 -04:00
'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
$output = array (
'current' => $current ,
'rowCount' => $rowCount ,
'rows' => $response ,
'total' => $total ,
);
2015-08-30 17:33:54 +00:00
echo _json_encode ( $output );