add page to remove deleted ports (pour mon petit grenouille!)

nn
  _.__-'@_ \/  _@'-__._
 /     '--)   (--`     \
/  >__<<_/  o  \_>>__<  \
 \\=x  \=x \|/ x=/  x=//



git-svn-id: http://www.observium.org/svn/observer/trunk@1074 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-04-24 22:43:25 +00:00
parent 464f495e29
commit fc0050d83c
8 changed files with 253 additions and 185 deletions

View File

@ -43,5 +43,7 @@ RewriteRule ^device/([0-9]+) ?page=device&id=$1
RewriteRule ^([a-z|0-9\-]+)/$ ?page=$1 RewriteRule ^([a-z|0-9\-]+)/$ ?page=$1
RewriteRule ^([a-z|0-9]+)/(.+)/(.+)/(.+)/$ ?page=$1&opta=$2&optb=$3&optc=$4
RewriteRule ^([a-z|0-9]+)/(.+)/(.+)/$ ?page=$1&opta=$2&optb=$3
RewriteRule ^([a-z|0-9]+)/(.+)/$ ?page=$1&opta=$2 RewriteRule ^([a-z|0-9]+)/(.+)/$ ?page=$1&opta=$2

View File

@ -13,6 +13,37 @@ function permissions_cache($user_id) {
return $permissions; return $permissions;
} }
function interfacepermitted($interface_id, $device_id = NULL)
{
global $_SESSION; global $permissions;
if(!$device_id) { $device_id = mysql_result(mysql_query("SELECT `device_id` from ports WHERE interface_id = '".$interface_id."'"),0); }
if ($_SESSION['userlevel'] >= "5") {
$allowed = TRUE;
} elseif ( devicepermitted($device_id)) {
$allowed = TRUE;
} elseif ( $permissions['port'][$interface_id]) {
$allowed = TRUE;
} else {
$allowed = FALSE;
}
return $allowed;
}
function devicepermitted($device_id)
{
global $_SESSION; global $permissions;
if ($_SESSION['userlevel'] >= "5") {
$allowed = true;
} elseif ( $permissions['device'][$device_id] ) {
$allowed = true;
} else {
$allowed = false;
}
return $allowed;
}
function print_graph_tag ($args) function print_graph_tag ($args)
{ {
echo generate_graph_tag ($args); echo generate_graph_tag ($args);

View File

@ -18,6 +18,7 @@ if($debug) {
include("includes/functions.inc.php"); include("includes/functions.inc.php");
include("includes/authenticate.inc.php"); include("includes/authenticate.inc.php");
if($_SESSION['authenticated']) { if($_SESSION['authenticated']) {
# Load permissions used my devicepermitted() and interfacepermitted()
$permissions = permissions_cache($_SESSION['user_id']); $permissions = permissions_cache($_SESSION['user_id']);
} }

View File

@ -1,162 +1,10 @@
<?php print_optionbar_start(50); ?>
<table style="text-align: left;" cellpadding=0 cellspacing=5 class=devicetable width=100%>
<tr style='padding: 0px;'>
<form method='post' action=''>
<td width='200'>
<select name='device_id' id='device_id'>
<option value=''>All Devices</option>
<?php
$query = mysql_query("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`");
while($data = mysql_fetch_array($query)) {
echo("<option value='".$data['device_id']."'");
if($data['device_id'] == $_POST['device_id']) { echo("selected"); }
echo(">".$data['hostname']."</option>");
}
?>
</select>
</td>
<td width='150'>
<select name='state' id='state'>
<option value=''>All States</option>
<option value='up' <?php if($_POST['state'] == "up") { echo("selected"); } ?>>Up</option>
<option value='down'<?php if($_POST['state'] == "down") { echo("selected"); } ?>>Down</option>
<option value='admindown' <?php if($_POST['state'] == "admindown") { echo("selected"); } ?>>Shutdown</option>
<option value='errors' <?php if($_POST['state'] == "errors") { echo("selected"); } ?>>Errors</option>
<option value='ignored' <?php if($_POST['state'] == "ignored") { echo("selected"); } ?>>Ignored</option>
<option value='ethernet' <?php if($_POST['state'] == "ethernet") { echo("selected"); } ?>>Ethernet</option>
<option value='l2vlan' <?php if($_POST['state'] == "l2vlan") { echo("selected"); } ?>>L2 VLAN</option>
<option value='sonet' <?php if($_POST['state'] == "sonet") { echo("selected"); } ?>>SONET</option>
<option value='propvirtual' <?php if($_POST['state'] == "propvirtual") { echo("selected"); } ?>>Virtual</option>
<option value='ppp' <?php if($_POST['state'] == "ppp") { echo("selected"); } ?>>PPP</option>
<option value='loopback' <?php if($_POST['state'] == "loopback") { echo("selected"); } ?>>Loopback</option>
</select>
</td>
<td width=110>
<select name='ifSpeed' id='ifSpeed'>
<option value=''>All Speeds</option>
<?php
$query = mysql_query("SELECT `ifSpeed` FROM `ports` GROUP BY `ifSpeed` ORDER BY `ifSpeed`");
while($data = mysql_fetch_array($query)) {
if ($data['ifSpeed'])
{
echo("<option value='".$data['ifSpeed']."'");
if($data['ifSpeed'] == $_POST['ifSpeed']) { echo("selected"); }
echo(">".humanspeed($data['ifSpeed'])."</option>");
}
}
?>
</select>
</td>
<td width=200>
<select name='ifType' id='ifType'>
<option value=''>All Media</option>
<?php
$query = mysql_query("SELECT `ifType` FROM `ports` GROUP BY `ifType` ORDER BY `ifType`");
while($data = mysql_fetch_array($query)) {
if ($data['ifType'])
{
echo("<option value='".$data['ifType']."'");
if($data['ifType'] == $_POST['ifType']) { echo("selected"); }
echo(">".$data['ifType']."</option>");
}
}
?>
</select>
</td>
<td>
<input type="text" name="ifAlias" id="ifAlias" size=40 value="<?php echo($_POST['ifAlias']); ?>" />
Deleted <input type=checkbox id="deleted" name="deleted" value=1 <?php if($_POST['deleted']) { echo("checked"); } ?> ></input>
</td>
<td style="text-align: right;">
<input style="align:right;" type=submit class=submit value=Search></div>
</td>
</form>
</tr>
</table>
<?php print_optionbar_end(); ?>
<table cellpadding=3 cellspacing=0 class=devicetable width=100%>
<?php <?php
#if ($_SESSION['userlevel'] >= '5') { #print_r($_GET);
# $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ORDER BY D.hostname, I.ifDescr";
#} else {
# $sql = "SELECT * FROM `ports` AS I, `devices` AS D, `devices_perms` AS P WHERE I.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, I.ifDescr";
#}
$file = $config['install_dir'] . "/html/pages/ports/" . safename($_GET['opta']) . ".inc.php";
if($_GET['opta'] == "down" || $_GET['type'] == "down" || $_POST['state'] == "down") { if(is_file($file)) { include($file); } else { include("ports/default.inc.php"); }
$where .= "AND I.ifAdminStatus = 'up' AND I.ifOperStatus = 'down' AND I.ignore = '0'";
} elseif ($_GET['opta'] == "admindown" || $_GET['type'] == "admindown" || $_POST['state'] == "admindown") {
$where .= "AND I.ifAdminStatus = 'down'";
} elseif ($_GET['opta'] == "errors" || $_GET['type'] == "errors" || $_POST['state'] == "errors") {
$where .= "AND ( I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0' )";
} elseif ($_GET['type'] == "up" || $_POST['state'] == "up") {
$where .= "AND I.ifOperStatus = 'up'";
} elseif ($_GET['opta'] == "ignored" || $_GET['type'] == "ignored" || $_POST['state'] == "ignored") {
$where .= "AND I.ignore = '1'";
} elseif ($_GET['type'] == "l2vlan" || $_POST['state'] == "l2vlan") {
$where .= " AND I.ifType = 'l2vlan'";
} elseif ($_GET['type'] == "ethernet" || $_POST['state'] == "ethernet") {
$where .= " AND I.ifType = 'ethernetCsmacd'";
} elseif ($_GET['type'] == "loopback" || $_POST['state'] == "loopback") {
$where .= " AND I.ifType = 'softwareLoopback'";
} elseif ($_GET['typee'] == "sonet" || $_POST['state'] == "sonet") {
$where .= " AND I.ifType = 'sonet'";
} elseif ($_POST['state'] == "propvirtual") {
$where .= " AND I.ifType = 'propVirtual'";
} elseif ($_POST['state'] == "ppp") {
$where .= " AND I.ifType = 'ppp'";
}
if($_POST['device_id']) { $where .= " AND I.device_id = '".$_POST['device_id']."'"; }
if($_POST['ifType']) { $where .= " AND I.ifType = '".$_POST['ifType']."'"; }
if($_POST['ifSpeed']) { $where .= " AND I.ifSpeed = '".$_POST['ifSpeed']."'"; }
if($_POST['ifAlias']) { $where .= " AND I.ifAlias LIKE '%".$_POST['ifAlias']."%'"; }
if($_POST['deleted'] || $_GET['type'] == "deleted") { $where .= " AND I.deleted = '1'"; }
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where ORDER BY D.hostname, I.ifIndex";
$query = mysql_query($sql);
echo("<tr class=tablehead><td></td><th>Device</a></th><th>Interface</th><th>Speed</th><th>Media</th><th>Description</th></tr>");
$row = 1;
while($interface = mysql_fetch_array($query)) {
if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
$speed = humanspeed($interface['ifSpeed']);
$type = humanmedia($interface['ifType']);
if($interface['in_errors'] > 0 || $interface['out_errors'] > 0) {
$error_img = generateiflink($interface,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
} else { $error_img = ""; }
if( interfacepermitted($interface['interface_id']) )
{
echo("<tr bgcolor=$row_colour>
<td width=5></td>
<td width=200 class=list-bold>" . generatedevicelink($interface) . "</td>
<td width=150 class=list-bold>" . generateiflink($interface, makeshortif(fixifname($interface['ifDescr']))) . " $error_img</td>
<td width=110 >$speed</td>
<td width=200>$type</td>
<td>" . $interface['ifAlias'] . "</td>
</tr>\n");
$row++;
}
}
echo("</table>");
?> ?>

View File

@ -0,0 +1,163 @@
<?php print_optionbar_start(50); ?>
<table style="text-align: left;" cellpadding=0 cellspacing=5 class=devicetable width=100%>
<tr style='padding: 0px;'>
<form method='post' action=''>
<td width='200'>
<select name='device_id' id='device_id'>
<option value=''>All Devices</option>
<?php
$query = mysql_query("SELECT `device_id`,`hostname` FROM `devices` GROUP BY `hostname` ORDER BY `hostname`");
while($data = mysql_fetch_array($query)) {
echo("<option value='".$data['device_id']."'");
if($data['device_id'] == $_POST['device_id']) { echo("selected"); }
echo(">".$data['hostname']."</option>");
}
?>
</select>
</td>
<td width='150'>
<select name='state' id='state'>
<option value=''>All States</option>
<option value='up' <?php if($_POST['state'] == "up") { echo("selected"); } ?>>Up</option>
<option value='down'<?php if($_POST['state'] == "down") { echo("selected"); } ?>>Down</option>
<option value='admindown' <?php if($_POST['state'] == "admindown") { echo("selected"); } ?>>Shutdown</option>
<option value='errors' <?php if($_POST['state'] == "errors") { echo("selected"); } ?>>Errors</option>
<option value='ignored' <?php if($_POST['state'] == "ignored") { echo("selected"); } ?>>Ignored</option>
<option value='ethernet' <?php if($_POST['state'] == "ethernet") { echo("selected"); } ?>>Ethernet</option>
<option value='l2vlan' <?php if($_POST['state'] == "l2vlan") { echo("selected"); } ?>>L2 VLAN</option>
<option value='sonet' <?php if($_POST['state'] == "sonet") { echo("selected"); } ?>>SONET</option>
<option value='propvirtual' <?php if($_POST['state'] == "propvirtual") { echo("selected"); } ?>>Virtual</option>
<option value='ppp' <?php if($_POST['state'] == "ppp") { echo("selected"); } ?>>PPP</option>
<option value='loopback' <?php if($_POST['state'] == "loopback") { echo("selected"); } ?>>Loopback</option>
</select>
</td>
<td width=110>
<select name='ifSpeed' id='ifSpeed'>
<option value=''>All Speeds</option>
<?php
$query = mysql_query("SELECT `ifSpeed` FROM `ports` GROUP BY `ifSpeed` ORDER BY `ifSpeed`");
while($data = mysql_fetch_array($query)) {
if ($data['ifSpeed'])
{
echo("<option value='".$data['ifSpeed']."'");
if($data['ifSpeed'] == $_POST['ifSpeed']) { echo("selected"); }
echo(">".humanspeed($data['ifSpeed'])."</option>");
}
}
?>
</select>
</td>
<td width=200>
<select name='ifType' id='ifType'>
<option value=''>All Media</option>
<?php
$query = mysql_query("SELECT `ifType` FROM `ports` GROUP BY `ifType` ORDER BY `ifType`");
while($data = mysql_fetch_array($query)) {
if ($data['ifType'])
{
echo("<option value='".$data['ifType']."'");
if($data['ifType'] == $_POST['ifType']) { echo("selected"); }
echo(">".$data['ifType']."</option>");
}
}
?>
</select>
</td>
<td>
<input type="text" name="ifAlias" id="ifAlias" size=40 value="<?php echo($_POST['ifAlias']); ?>" />
Deleted <input type=checkbox id="deleted" name="deleted" value=1 <?php if($_POST['deleted']) { echo("checked"); } ?> ></input>
</td>
<td style="text-align: right;">
<input style="align:right;" type=submit class=submit value=Search></div>
</td>
</form>
</tr>
</table>
<?php print_optionbar_end(); ?>
<table cellpadding=3 cellspacing=0 class=devicetable width=100%>
<?php
#if ($_SESSION['userlevel'] >= '5') {
# $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id ORDER BY D.hostname, I.ifDescr";
#} else {
# $sql = "SELECT * FROM `ports` AS I, `devices` AS D, `devices_perms` AS P WHERE I.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, I.ifDescr";
#}
if($_GET['opta'] == "down" || $_GET['type'] == "down" || $_POST['state'] == "down") {
$where .= "AND I.ifAdminStatus = 'up' AND I.ifOperStatus = 'down' AND I.ignore = '0'";
} elseif ($_GET['opta'] == "admindown" || $_GET['type'] == "admindown" || $_POST['state'] == "admindown") {
$where .= "AND I.ifAdminStatus = 'down'";
} elseif ($_GET['opta'] == "errors" || $_GET['type'] == "errors" || $_POST['state'] == "errors") {
$where .= "AND ( I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0' )";
} elseif ($_GET['type'] == "up" || $_POST['state'] == "up") {
$where .= "AND I.ifOperStatus = 'up'";
} elseif ($_GET['opta'] == "ignored" || $_GET['type'] == "ignored" || $_POST['state'] == "ignored") {
$where .= "AND I.ignore = '1'";
} elseif ($_GET['type'] == "l2vlan" || $_POST['state'] == "l2vlan") {
$where .= " AND I.ifType = 'l2vlan'";
} elseif ($_GET['type'] == "ethernet" || $_POST['state'] == "ethernet") {
$where .= " AND I.ifType = 'ethernetCsmacd'";
} elseif ($_GET['type'] == "loopback" || $_POST['state'] == "loopback") {
$where .= " AND I.ifType = 'softwareLoopback'";
} elseif ($_GET['typee'] == "sonet" || $_POST['state'] == "sonet") {
$where .= " AND I.ifType = 'sonet'";
} elseif ($_POST['state'] == "propvirtual") {
$where .= " AND I.ifType = 'propVirtual'";
} elseif ($_POST['state'] == "ppp") {
$where .= " AND I.ifType = 'ppp'";
}
if($_POST['device_id']) { $where .= " AND I.device_id = '".$_POST['device_id']."'"; }
if($_POST['ifType']) { $where .= " AND I.ifType = '".$_POST['ifType']."'"; }
if($_POST['ifSpeed']) { $where .= " AND I.ifSpeed = '".$_POST['ifSpeed']."'"; }
if($_POST['ifAlias']) { $where .= " AND I.ifAlias LIKE '%".$_POST['ifAlias']."%'"; }
if($_POST['deleted'] || $_GET['type'] == "deleted") { $where .= " AND I.deleted = '1'"; }
$sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id $where ORDER BY D.hostname, I.ifIndex";
$query = mysql_query($sql);
echo("<tr class=tablehead><td></td><th>Device</a></th><th>Interface</th><th>Speed</th><th>Media</th><th>Description</th></tr>");
$row = 1;
while($interface = mysql_fetch_array($query)) {
if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
$speed = humanspeed($interface['ifSpeed']);
$type = humanmedia($interface['ifType']);
if($interface['in_errors'] > 0 || $interface['out_errors'] > 0) {
$error_img = generateiflink($interface,"<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>",errors);
} else { $error_img = ""; }
if( interfacepermitted($interface['interface_id'], $interface['device_id']) )
{
$interface = ifLabel($interface, $device);
echo("<tr bgcolor=$row_colour>
<td width=5></td>
<td width=200 class=list-bold>" . generatedevicelink($interface) . "</td>
<td width=150 class=list-bold>" . generateiflink($interface) . " $error_img</td>
<td width=110 >$speed</td>
<td width=200>$type</td>
<td>" . $interface['ifAlias'] . "</td>
</tr>\n");
$row++;
}
}
echo("</table>");
?>

View File

@ -0,0 +1,48 @@
<?php
if($_GET['optb'] == "purge" && $_GET['optc'] == "all") {
$sql = "SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id";
$query = mysql_query($sql);
while($interface = mysql_fetch_assoc($query)) {
if(interfacepermitted($interface['interface_id'], $interface['device_id'])){
mysql_query("DELETE FROM `ports` WHERE `interface_id` = '".$interface['interface_id']."'");
if(mysql_affected_rows()) { echo("<div class=infobox>Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."</div>"); }
}
}
} elseif($_GET['optb'] == "purge" && $_GET['optc']) {
$interface = mysql_fetch_assoc(mysql_query("SELECT * from `ports` AS P, `devices` AS D WHERE `interface_id` = '".mres($_GET['optc'])."' AND D.device_id = P.device_id"));
if(interfacepermitted($interface['interface_id'], $interface['device_id']))
mysql_query("DELETE FROM `ports` WHERE `interface_id` = '".mres($_GET['optc'])."' AND `deleted` = '1'");
if(mysql_affected_rows()) { echo("<div class=infobox>Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."</div>"); }
}
$i_deleted = 1;
echo("<table cellpadding=5 cellspacing=0 border=0 width=100%>");
echo("<tr><td></td><td></td><td></td><td><a href='".$config['base_url'] . "/ports/deleted/purge/all/'><img src='images/16/cross.png' align=absmiddle></img> Purge All</a></td></tr>");
$sql = "SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id";
$query = mysql_query($sql);
while($interface = mysql_fetch_assoc($query)) {
$interface = ifLabel($interface, $interface);
if(interfacepermitted($interface['interface_id'], $interface['device_id'])){
if(is_integer($i_deleted/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
echo("<tr bgcolor=$row_colour>");
echo("<td width=250>".generatedevicelink($interface)."</td>");
echo("<td width=250>".generateiflink($interface)."</td>");
echo("<td></td>");
echo("<td width=100><a href='".$config['base_url'] . "/ports/deleted/purge/".$interface['interface_id']."/'><img src='images/16/cross.png' align=absmiddle></img> Purge</a></td>");
$i_deleted++;
}
}
echo("</table>");
?>

View File

@ -139,36 +139,6 @@ function billpermitted($bill_id)
return $allowed; return $allowed;
} }
function interfacepermitted($interface_id)
{
global $_SESSION;
if ($_SESSION['userlevel'] >= "5") {
$allowed = TRUE;
} elseif ( devicepermitted(mysql_result(mysql_query("SELECT `device_id` FROM `ports` WHERE `interface_id` = '$interface_id'"),0))) {
$allowed = TRUE;
} elseif ( @mysql_result(mysql_query("SELECT `interface_id` FROM `ports_perms` WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `interface_id` = $interface_id"), 0)) {
$allowed = TRUE;
} else {
$allowed = FALSE;
}
return $allowed;
}
function devicepermitted($device_id)
{
global $_SESSION;
if ($_SESSION['userlevel'] >= "5") {
$allowed = true;
} elseif ( @mysql_result(mysql_query("SELECT * FROM devices_perms WHERE `user_id` = '" . $_SESSION['user_id'] . "' AND `device_id` = $device_id"), 0) > '0' ) {
$allowed = true;
} else {
$allowed = false;
}
return $allowed;
}
function formatRates($rate) { function formatRates($rate) {
$rate = format_si($rate) . "bps"; $rate = format_si($rate) . "bps";
return $rate; return $rate;

View File

@ -23,6 +23,11 @@ function ifLabel ($interface, $device = NULL) {
$interface['label'] = $interface['ifDescr']; $interface['label'] = $interface['ifDescr'];
if(isset($config['appendifindex'][$os])) { $interface['label'] = $interface['label'] . " " . $interface['ifIndex']; } if(isset($config['appendifindex'][$os])) { $interface['label'] = $interface['label'] . " " . $interface['ifIndex']; }
} }
if($device['os'] == "speedtouch") {
list($interface['label']) = explode("thomson", $interface['label']);
}
return $interface; return $interface;
} }