clean up device/interface removal code (it's still fucking foul, but meh)

git-svn-id: http://www.observium.org/svn/observer/trunk@1076 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-04-24 23:16:12 +00:00
parent 2e001124ba
commit 2b5fbd67f2
4 changed files with 23 additions and 15 deletions

View File

@ -11,7 +11,7 @@ if($argv[1]) {
$host = strtolower($argv[1]);
$id = getidbyname($host);
if($id) {
delHost($id);
delete_device($id);
echo("Removed $host\n");
} else {
echo("Host doesn't exist!\n");

View File

@ -6,9 +6,9 @@ if($_SESSION['userlevel'] < 10) {
}
if($_POST['id']) {
delHost(mres($_POST['id']));
delete_device(mres($_POST['id']));
} elseif (mres($_GET['id'])) {
delHost(mres($_GET['id']));
delete_device(mres($_GET['id']));
}
?>

View File

@ -6,15 +6,15 @@ if($_GET['optb'] == "purge" && $_GET['optc'] == "all") {
$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>"); }
delete_port($interface['interface_id']);
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>"); }
delete_port($interface['interface_id']);
echo("<div class=infobox>Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."</div>");
}

View File

@ -325,15 +325,9 @@ function renamehost($id, $new) {
eventlog("Hostname changed -> $new (console)", $id);
}
function delHost($id)
function delete_port($int_id)
{
global $config;
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'");
$int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'");
while($int_data = mysql_fetch_array($int_query)) {
$int_if = $int_data['ifDescr'];
$int_id = $int_data['interface_id'];
$interface = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.interface_id = '".$int_id."' AND D.device_id = P.device_id"));
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE from `links` WHERE `local_interface_id` = '$int_id'");
mysql_query("DELETE from `links` WHERE `remote_interface_id` = '$int_id'");
@ -343,6 +337,20 @@ function delHost($id)
mysql_query("DELETE from `mac_accounting` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE FROM `bill_ports` WHERE `port_id` = '$int_id'");
mysql_query("DELETE from `pseudowires` WHERE `interface_id` = '$int_id'");
mysql_query("DELETE FROM `ports` WHERE `interface_id` = '$int_id'");
shell_exec("rm -rf ".$config['rrd_dir']."/".$interface['hostname']."/".$interface['ifIndex'].".rrd");
}
function delete_device($id)
{
global $config;
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
mysql_query("DELETE FROM `devices` WHERE `device_id` = '$id'");
$int_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '$id'");
while($int_data = mysql_fetch_array($int_query)) {
$int_if = $int_data['ifDescr'];
$int_id = $int_data['interface_id'];
delete_port($int_id);
echo("Removed interface $int_id ($int_if)<br />");
}
mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'");