function delete_device($id, $delete_rrd = FALSE)
{
    global $config;
    $ret = PHP_EOL;
    $device = device_by_id_cache($id);
    $host = $device['hostname'];
    if ($host == '') {
        $ret .= "发现错误的主机数据库中.";
    } else {
        $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($id));
        if (!empty($ports)) {
            $ret .= ' * Deleted interfaces: ';
            foreach ($ports as $int_data) {
                $int_if = $int_data['ifDescr'];
                $int_id = $int_data['port_id'];
                delete_port($int_id, $delete_rrd);
                $deleted_ports[] = "id={$int_id} ({$int_if})";
            }
            $ret .= implode(', ', $deleted_ports) . PHP_EOL;
        }
        $ret .= ' * Deleted device entries from tables: ';
        foreach ($config['device_tables'] as $table) {
            $where = '`device_id` = ?';
            if ($table == 'entity_permissions') {
                $where = "`entity_type` = 'device' AND `entity_id` = ?";
            }
            $table_status = dbDelete($table, $where, array($id));
            if ($table_status) {
                $deleted_tables[] = $table;
            }
        }
        $ret .= implode(', ', $deleted_tables) . PHP_EOL;
        if ($delete_rrd) {
            $device_rrd = rtrim(get_rrd_path($device, ''), '/');
            if (is_file($device_rrd . '/status.rrd')) {
                external_exec("rm -rf " . escapeshellarg($device_rrd));
                $ret .= ' * 删除设备 RRDs 目录: ' . $device_rrd . PHP_EOL;
            }
        }
        $ret .= " * Deleted device: {$host}";
    }
    return $ret;
}
Esempio n. 2
0
function delete_device($id)
{
    global $config, $debug;
    $ret = '';
    $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id));
    if (empty($host)) {
        return "No such host.";
    }
    // Remove IPv4/IPv6 addresses before removing ports as they depend on port_id
    dbQuery("DELETE `ipv4_addresses` FROM `ipv4_addresses` INNER JOIN `ports` ON `ports`.`port_id`=`ipv4_addresses`.`port_id` WHERE `device_id`=?", array($id));
    dbQuery("DELETE `ipv6_addresses` FROM `ipv6_addresses` INNER JOIN `ports` ON `ports`.`port_id`=`ipv6_addresses`.`port_id` WHERE `device_id`=?", array($id));
    foreach (dbFetch("SELECT * FROM `ports` WHERE `device_id` = ?", array($id)) as $int_data) {
        $int_if = $int_data['ifDescr'];
        $int_id = $int_data['port_id'];
        delete_port($int_id);
        $ret .= "Removed interface {$int_id} ({$int_if})\n";
    }
    $fields = array('device_id', 'host');
    foreach ($fields as $field) {
        foreach (dbFetch("SELECT table_name FROM information_schema.columns WHERE table_schema = ? AND column_name = ?", array($config['db_name'], $field)) as $table) {
            $table = $table['table_name'];
            $entries = (int) dbDelete($table, "`{$field}` =  ?", array($id));
            if ($entries > 0 && $debug === true) {
                $ret .= "{$field}@{$table} = #{$entries}\n";
            }
        }
    }
    $ex = shell_exec("bash -c '( [ ! -d " . trim($config['rrd_dir']) . "/" . $host . " ] || rm -vrf " . trim($config['rrd_dir']) . "/" . $host . " 2>&1 ) && echo -n OK'");
    $tmp = explode("\n", $ex);
    if ($tmp[sizeof($tmp) - 1] != "OK") {
        $ret .= "Could not remove files:\n{$ex}\n";
    }
    $ret .= "Removed device {$host}\n";
    return $ret;
}
function delete_device($id)
{
    global $config;
    $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id));
    foreach (dbFetch("SELECT * FROM `ports` WHERE `device_id` = ?", array($id)) as $int_data) {
        $int_if = $int_data['ifDescr'];
        $int_id = $int_data['port_id'];
        delete_port($int_id);
        $ret .= "Removed interface {$int_id} ({$int_if})\n";
    }
    dbDelete('devices', "`device_id` =  ?", array($id));
    $device_tables = array('entPhysical', 'devices_attribs', 'devices_perms', 'bgpPeers', 'vlans', 'vrfs', 'storage', 'alerts', 'eventlog', 'syslog', 'ports', 'services', 'toner', 'frequency', 'current', 'sensors', 'ciscoASA');
    foreach ($device_tables as $table) {
        dbDelete($table, "`device_id` =  ?", array($id));
    }
    shell_exec("rm -rf " . trim($config['rrd_dir']) . "/{$host}");
    $ret = "Removed device {$host}";
    return $ret;
}
    $ipaddrs = mysql_query("SELECT * FROM `ipaddr` WHERE `port_id` = '{$port_id}'");
    while ($ipaddr = mysql_fetch_assoc($ipaddrs)) {
        echo "<div style='padding-left:8px; font-weight: normal;'>删除 IPv4 地址 " . $ipaddr['addr'] . "/" . $ipaddr['cidr'];
        mysql_query("DELETE FROM addr WHERE id = '" . $addr['id'] . "'");
        echo "</div>";
    }
    $ip6addr = mysql_query("SELECT * FROM `ip6addr` WHERE `port_id` = '{$port_id}'");
    while ($ip6addr = mysql_fetch_assoc($ip6addrs)) {
        echo "<div style='padding-left:8px; font-weight: normal;'>删除 IPv6 地址 " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen'];
        mysql_query("DELETE FROM ip6addr WHERE ip6_addr_id = '" . $ip6addr['ip6_addr_id'] . "'");
        echo "</div>";
    }
    $ip6addr = mysql_query("SELECT * FROM `ip6addr` WHERE `port_id` = '{$port_id}'");
    while ($ip6addr = mysql_fetch_assoc($ip6addrs)) {
        echo "<div style='padding-left:8px; font-weight: normal;'>删除 IPv6 地址 " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen'];
        mysql_query("DELETE FROM ip6addr WHERE ip6_addr_id = '" . $ip6addr['ip6_addr_id'] . "'");
        echo "</div>";
    }
    mysql_query("DELETE FROM `pseudowires` WHERE `port_id` = '{$port_id}'");
    mysql_query("DELETE FROM `mac_accounting` WHERE `port_id` = '{$port_id}'");
    mysql_query("DELETE FROM `links` WHERE `local_port_id` = '{$port_id}'");
    mysql_query("DELETE FROM `links` WHERE `remote_port_id` = '{$port_id}'");
    mysql_query("DELETE FROM `ports_perms` WHERE `port_id` = '{$port_id}'");
    mysql_query("DELETE FROM `ports` WHERE `port_id` = '{$port_id}'");
}
$ports = mysql_query("SELECT * FROM `ports` WHERE `deleted` = '1'");
while ($port = mysql_fetch_assoc($ports)) {
    echo "<div style='font-weight: bold;'>删除端口 " . $port['port_id'] . " - " . $port['ifDescr'];
    delete_port($port['port_id']);
    echo "</div>";
}
Esempio n. 5
0
 * @package    observium
 * @subpackage housekeeping
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
$cutoff = age_to_unixtime($config['housekeeping']['deleted_ports']['age']);
if ($cutoff) {
    $where = "`deleted` = 1 AND UNIX_TIMESTAMP(`ifLastChange`) < {$cutoff}";
    $ports = dbFetchRows("SELECT `port_id` FROM `ports` WHERE {$where}");
    $count = count($ports);
    if ($count) {
        if ($prompt) {
            $answer = print_prompt("{$count} ports marked as deleted before " . format_unixtime($cutoff) . " will be deleted");
        }
        if ($answer) {
            foreach ($ports as $entry) {
                delete_port($entry['port_id']);
            }
            print_debug("Deleted ports housekeeping: deleted {$count} entries");
            logfile("housekeeping.log", "Deleted ports: deleted {$count} entries older than " . format_unixtime($cutoff));
        }
    } else {
        if ($prompt) {
            print_message("No ports found marked as deleted before " . format_unixtime($cutoff));
        }
    }
} else {
    print_message("Deleted ports housekeeping disabled in configuration.");
}
// EOF
Esempio n. 6
0
<?php

$pagetitle[] = 'Deleted ports';
if ($vars['purge'] == 'all') {
    foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) {
        if (port_permitted($interface['port_id'], $interface['device_id'])) {
            delete_port($interface['port_id']);
            echo '<div class=infobox>Deleted ' . generate_device_link($interface) . ' - ' . generate_port_link($interface) . '</div>';
        }
    }
} elseif ($vars['purge']) {
    $interface = dbFetchRow('SELECT * from `ports` AS P, `devices` AS D WHERE `port_id` = ? AND D.device_id = P.device_id', array($vars['purge']));
    if (port_permitted($interface['port_id'], $interface['device_id'])) {
        delete_port($interface['port_id']);
    }
    echo '<div class=infobox>Deleted ' . generate_device_link($interface) . ' - ' . generate_port_link($interface) . '</div>';
}
echo '<table class="table table-hover table-condensed">';
echo "<tr><td>Device</td><td>Port</td><td></td><td><a href='deleted-ports/purge=all/'><i class='fa fa-times'></i> Purge All</a></td></tr>";
foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id", array(), true) as $interface) {
    $interface = ifLabel($interface, $interface);
    if (port_permitted($interface['port_id'], $interface['device_id'])) {
        echo '<tr class=list>';
        echo '<td width=250>' . generate_device_link($interface) . '</td>';
        echo '<td width=250>' . generate_port_link($interface) . '</td>';
        echo '<td></td>';
        echo "<td width=100><a href='deleted-ports/purge=" . $interface['port_id'] . "/'><i class='fa fa-times'></i> Purge</a></td>";
    }
}
echo '</table>';
function delete_device($id, $delete_rrd = FALSE)
{
    global $config;
    $ret = PHP_EOL;
    $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id));
    $ports = dbFetch("SELECT * FROM `ports` WHERE `device_id` = ?", array($id));
    if (!empty($ports)) {
        $ret .= '> Deleted interfaces: ';
        foreach ($ports as $int_data) {
            $int_if = $int_data['ifDescr'];
            $int_id = $int_data['port_id'];
            delete_port($int_id);
            $ret .= "id={$int_id} ({$int_if}), ";
        }
        $ret .= PHP_EOL;
    }
    dbDelete('devices', "`device_id` =  ?", array($id));
    $device_tables = array('entPhysical', 'devices_attribs', 'devices_perms', 'bgpPeers', 'vlans', 'vrfs', 'storage', 'alerts', 'eventlog', 'syslog', 'ports', 'services', 'toner', 'frequency', 'current', 'sensors', 'ospf_areas', 'ospf_ports', 'ospf_nbrs', 'ospf_instances', 'alert_table');
    $ret .= '> Deleted table entries: ';
    foreach ($device_tables as $table) {
        $table_status = dbDelete($table, "`device_id` = ?", array($id));
        if ($table_status) {
            $ret .= $table . ', ';
        }
    }
    $ret .= PHP_EOL;
    if ($delete_rrd) {
        shell_exec("rm -rf " . trim($config['rrd_dir']) . '/' . $host);
        $ret .= '> Deleted device RRDs dir: ' . $config['rrd_dir'] . '/' . $host . PHP_EOL;
    }
    $ret .= "> Deleted device: {$host}\n";
    return $ret;
}
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2015 Adam Armstrong
 *
 */
$page_title[] = '删除端口';
if ($vars['purge'] == 'all') {
    foreach (dbFetchRows('SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = "1" AND D.device_id = P.device_id') as $port) {
        if (port_permitted($port['port_id'], $port['device_id'])) {
            print_message(delete_port($port['port_id']), 'console');
        }
    }
} else {
    if (is_numeric($vars['purge'])) {
        $port = dbFetchRow('SELECT * from `ports` AS P, `devices` AS D WHERE `port_id` = ? AND D.device_id = P.device_id', array($vars['purge']));
        if ($port && port_permitted($port['port_id'], $port['device_id'])) {
            print_message(delete_port($port['port_id']), 'console');
        }
    }
}
echo '<table class="table table-condensed table-striped table-bordered table-condensed">
  <thead><tr>
    <th>设备</th>
    <th>端口</th>
    <th>描述</th>
    <th>删除自</th>
    <th style="text-align: right;"><a href="' . generate_url(array('page' => 'deleted-ports', 'purge' => 'all')) . '"><button class="btn btn-danger btn-mini"><i class="icon-remove icon-white"></i> 清除全部</button></a></th>
  </tr></thead>';
foreach (dbFetchRows('SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = "1" AND D.device_id = P.device_id') as $port) {
    humanize_port($port);
    $since = $config['time']['now'] - strtotime($port['ifLastChange']);
    if (port_permitted($port['port_id'], $port['device_id'])) {
Esempio n. 9
0
function delete_device($id, $delete_rrd = FALSE)
{
    global $config;
    $ret = PHP_EOL;
    $device = device_by_id_cache($id);
    $host = $device['hostname'];
    if ($host == '') {
        $ret .= "Error finding host in the database.";
    } else {
        $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ?", array($id));
        if (!empty($ports)) {
            $ret .= ' * Deleted interfaces: ';
            foreach ($ports as $int_data) {
                $int_if = $int_data['ifDescr'];
                $int_id = $int_data['port_id'];
                delete_port($int_id, $delete_rrd);
                $deleted_ports[] = "id={$int_id} ({$int_if})";
            }
            $ret .= implode(', ', $deleted_ports) . PHP_EOL;
        }
        // Remove entities from common tables
        $deleted_entities = array();
        foreach (get_device_entities($id) as $entity_type => $entity_ids) {
            foreach ($config['entity_tables'] as $table) {
                $where = '`entity_type` = ?' . generate_query_values($entity_ids, 'entity_id');
                $table_status = dbDelete($table, $where, array($entity_type));
                if ($table_status) {
                    $deleted_entities[$entity_type] = 1;
                }
            }
        }
        if (count($deleted_entities)) {
            $ret .= ' * Deleted common entity entries linked to device: ';
            $ret .= implode(', ', array_keys($deleted_entities)) . PHP_EOL;
        }
        $deleted_tables = array();
        $ret .= ' * Deleted device entries from tables: ';
        foreach ($config['device_tables'] as $table) {
            $where = '`device_id` = ?';
            $table_status = dbDelete($table, $where, array($id));
            if ($table_status) {
                $deleted_tables[] = $table;
            }
        }
        $ret .= implode(', ', $deleted_tables) . PHP_EOL;
        if ($delete_rrd) {
            $device_rrd = rtrim(get_rrd_path($device, ''), '/');
            if (is_file($device_rrd . '/status.rrd')) {
                external_exec("rm -rf " . escapeshellarg($device_rrd));
                $ret .= ' * Deleted device RRDs dir: ' . $device_rrd . PHP_EOL;
            }
        }
        $ret .= " * Deleted device: {$host}";
    }
    return $ret;
}
Esempio n. 10
0
 * @subpackage webui
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
$pagetitle[] = 'Deleted ports';
if ($vars['purge'] == 'all') {
    foreach (dbFetchRows('SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = "1" AND D.device_id = P.device_id') as $port) {
        if (port_permitted($port['port_id'], $port['device_id'])) {
            print_warning(delete_port($port['port_id']));
        }
    }
} elseif (is_numeric($vars['purge'])) {
    $port = dbFetchRow('SELECT * from `ports` AS P, `devices` AS D WHERE `port_id` = ? AND D.device_id = P.device_id', array($vars['purge']));
    if ($port && port_permitted($port['port_id'], $port['device_id'])) {
        print_warning(delete_port($port['port_id']));
    }
}
echo '<table class="table table-striped table-bordered table-condensed">
  <thead><tr>
    <th>Device</th>
    <th>Port</th>
    <th>Description</th>
    <th>Deleted since</th>
    <th style="text-align: right;"><a href="' . generate_url(array('page' => 'deleted-ports', 'purge' => 'all')) . '"><button class="btn btn-danger btn-small"><i class="icon-remove icon-white"></i> Purge All</button></a></th>
  </tr></thead>';
foreach (dbFetchRows('SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = "1" AND D.device_id = P.device_id') as $port) {
    humanize_port($port);
    $since = $config['time']['now'] - strtotime($port['ifLastChange']);
    if (port_permitted($port['port_id'], $port['device_id'])) {
        echo '<tr class="list">';
Esempio n. 11
0
    $ipaddrs = mysql_query("SELECT * FROM `ipaddr` WHERE `interface_id` = '{$interface_id}'");
    while ($ipaddr = mysql_fetch_array($ipaddrs)) {
        echo "<div style='padding-left:8px; font-weight: normal;'>Deleting IPv4 address " . $ipaddr['addr'] . "/" . $ipaddr['cidr'];
        mysql_query("DELETE FROM addr WHERE id = '" . $addr['id'] . "'");
        echo "</div>";
    }
    $ip6addr = mysql_query("SELECT * FROM `ip6addr` WHERE `interface_id` = '{$interface_id}'");
    while ($ip6addr = mysql_fetch_array($ip6addrs)) {
        echo "<div style='padding-left:8px; font-weight: normal;'>Deleting IPv6 address " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen'];
        mysql_query("DELETE FROM ip6addr WHERE ip6_addr_id = '" . $ip6addr['ip6_addr_id'] . "'");
        echo "</div>";
    }
    $ip6addr = mysql_query("SELECT * FROM `ip6addr` WHERE `interface_id` = '{$interface_id}'");
    while ($ip6addr = mysql_fetch_array($ip6addrs)) {
        echo "<div style='padding-left:8px; font-weight: normal;'>Deleting IPv6 address " . $ip6addr['ip6_comp_addr'] . "/" . $ip6addr['ip6_prefixlen'];
        mysql_query("DELETE FROM ip6addr WHERE ip6_addr_id = '" . $ip6addr['ip6_addr_id'] . "'");
        echo "</div>";
    }
    mysql_query("DELETE FROM `pseudowires` WHERE `interface_id` = '{$interface_id}'");
    mysql_query("DELETE FROM `mac_accounting` WHERE `interface_id` = '{$interface_id}'");
    mysql_query("DELETE FROM `links` WHERE `local_interface_id` = '{$interface_id}'");
    mysql_query("DELETE FROM `links` WHERE `remote_interface_id` = '{$interface_id}'");
    mysql_query("DELETE FROM `ports_perms` WHERE `interface_id` = '{$interface_id}'");
    mysql_query("DELETE FROM `ports` WHERE `interface_id` = '{$interface_id}'");
}
$ports = mysql_query("SELECT * FROM `ports` WHERE `deleted` = '1'");
while ($port = mysql_fetch_array($ports)) {
    echo "<div style='font-weight: bold;'>Deleting port " . $port['interface_id'] . " - " . $port['ifDescr'];
    delete_port($port['interface_id']);
    echo "</div>";
}