mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
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:
+1
-1
@@ -11,7 +11,7 @@ if($argv[1]) {
|
|||||||
$host = strtolower($argv[1]);
|
$host = strtolower($argv[1]);
|
||||||
$id = getidbyname($host);
|
$id = getidbyname($host);
|
||||||
if($id) {
|
if($id) {
|
||||||
delHost($id);
|
delete_device($id);
|
||||||
echo("Removed $host\n");
|
echo("Removed $host\n");
|
||||||
} else {
|
} else {
|
||||||
echo("Host doesn't exist!\n");
|
echo("Host doesn't exist!\n");
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ if($_SESSION['userlevel'] < 10) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($_POST['id']) {
|
if($_POST['id']) {
|
||||||
delHost(mres($_POST['id']));
|
delete_device(mres($_POST['id']));
|
||||||
} elseif (mres($_GET['id'])) {
|
} elseif (mres($_GET['id'])) {
|
||||||
delHost(mres($_GET['id']));
|
delete_device(mres($_GET['id']));
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ if($_GET['optb'] == "purge" && $_GET['optc'] == "all") {
|
|||||||
$query = mysql_query($sql);
|
$query = mysql_query($sql);
|
||||||
while($interface = mysql_fetch_assoc($query)) {
|
while($interface = mysql_fetch_assoc($query)) {
|
||||||
if(interfacepermitted($interface['interface_id'], $interface['device_id'])){
|
if(interfacepermitted($interface['interface_id'], $interface['device_id'])){
|
||||||
mysql_query("DELETE FROM `ports` WHERE `interface_id` = '".$interface['interface_id']."'");
|
delete_port($interface['interface_id']);
|
||||||
if(mysql_affected_rows()) { echo("<div class=infobox>Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."</div>"); }
|
echo("<div class=infobox>Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."</div>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif($_GET['optb'] == "purge" && $_GET['optc']) {
|
} 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"));
|
$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']))
|
if(interfacepermitted($interface['interface_id'], $interface['device_id']))
|
||||||
mysql_query("DELETE FROM `ports` WHERE `interface_id` = '".mres($_GET['optc'])."' AND `deleted` = '1'");
|
delete_port($interface['interface_id']);
|
||||||
if(mysql_affected_rows()) { echo("<div class=infobox>Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."</div>"); }
|
echo("<div class=infobox>Deleted ".generatedevicelink($interface)." - ".generateiflink($interface)."</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+16
-8
@@ -325,15 +325,9 @@ function renamehost($id, $new) {
|
|||||||
eventlog("Hostname changed -> $new (console)", $id);
|
eventlog("Hostname changed -> $new (console)", $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delHost($id)
|
function delete_port($int_id)
|
||||||
{
|
{
|
||||||
global $config;
|
$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"));
|
||||||
$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'];
|
|
||||||
mysql_query("DELETE from `adjacencies` WHERE `interface_id` = '$int_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 `local_interface_id` = '$int_id'");
|
||||||
mysql_query("DELETE from `links` WHERE `remote_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 `mac_accounting` WHERE `interface_id` = '$int_id'");
|
||||||
mysql_query("DELETE FROM `bill_ports` WHERE `port_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 `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 />");
|
echo("Removed interface $int_id ($int_if)<br />");
|
||||||
}
|
}
|
||||||
mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'");
|
mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'");
|
||||||
|
|||||||
Reference in New Issue
Block a user