Esempio n. 1
0
function delete_service($service = null)
{
    if (!is_numeric($service)) {
        return false;
    }
    return dbDelete('services', '`service_id` =  ?', array($service));
}
Esempio n. 2
0
function deluser($username)
{
    dbDelete('bill_perms', '`user_name` =  ?', array($username));
    dbDelete('devices_perms', '`user_name` =  ?', array($username));
    dbDelete('ports_perms', '`user_name` =  ?', array($username));
    dbDelete('users_prefs', '`user_name` =  ?', array($username));
    dbDelete('users', '`user_name` =  ?', array($username));
    return dbDelete('users', '`username` =  ?', array($username));
}
Esempio n. 3
0
function delete_rule()
{
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $rule_id = mres($router['id']);
    $status = 'error';
    $err_msg = '';
    $message = '';
    $code = 500;
    if (is_numeric($rule_id)) {
        $status = 'ok';
        $code = 200;
        if (dbDelete('alert_rules', '`id` =  ? LIMIT 1', array($rule_id))) {
            $message = 'Alert rule has been removed';
        } else {
            $message = 'No alert rule by that ID';
        }
    } else {
        $err_msg = 'Invalid rule id has been provided';
    }
    $output = array('status' => $status, 'err-msg' => $err_msg, 'message' => $message);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Esempio n. 4
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;
}
Esempio n. 5
0
<?php

$updated = '1';
$affected = dbDelete('services', '`service_id` = ?', array($_POST['service']));
if ($affected) {
    $message .= $message_break . $rows . " service deleted!";
    $message_break .= "<br />";
}
Esempio n. 6
0
                echo str_pad("dot1d id", 10) . str_pad("ifIndex", 10) . str_pad("Port Name", 25) . str_pad("Priority", 10) . str_pad("State", 15) . str_pad("Cost", 10) . "\n";
            }
            foreach ($vlan_data as $vlan_port_id => $vlan_port) {
                $port = get_port_by_index_cache($device, $vlan_port['dot1dBasePortIfIndex']);
                echo str_pad($vlan_port_id, 10) . str_pad($vlan_port['dot1dBasePortIfIndex'], 10) . str_pad($port['ifDescr'], 25) . str_pad($vlan_port['dot1dStpPortPriority'], 10) . str_pad($vlan_port['dot1dStpPortState'], 15) . str_pad($vlan_port['dot1dStpPortPathCost'], 10);
                $db_w = array('device_id' => $device['device_id'], 'port_id' => $port['port_id'], 'vlan' => $vlan_id);
                $db_a['baseport'] = $vlan_port_id;
                $db_a['priority'] = isset($vlan_port['dot1dStpPortPriority']) ? $vlan_port['dot1dStpPortPriority'] : 0;
                $db_a['state'] = isset($vlan_port['dot1dStpPortState']) ? $vlan_port['dot1dStpPortState'] : "unknown";
                $db_a['cost'] = isset($vlan_port['dot1dStpPortPathCost']) ? $vlan_port['dot1dStpPortPathCost'] : 0;
                $from_db = dbFetchRow("SELECT * FROM `ports_vlans` WHERE device_id = ? AND port_id = ? AND `vlan` = ?", array($device['device_id'], $port['port_id'], $vlan_id));
                if ($from_db['port_vlan_id']) {
                    dbUpdate($db_a, 'ports_vlans', "`port_vlan_id` = ?", array($from_db['port_vlan_id']));
                    echo "Updated";
                } else {
                    dbInsert(array_merge($db_w, $db_a), 'ports_vlans');
                    echo "Inserted";
                }
                echo "\n";
            }
        }
    }
}
foreach ($vlans_db as $domain_id => $vlans) {
    foreach ($vlans as $vlan_id => $vlan) {
        if (empty($device['vlans'][$domain_id][$vlan_id])) {
            dbDelete('vlans', "`device_id` = ? AND vlan_domain = ? AND vlan_vlan = ?", array($device['device_id'], $domain_id, $vlan_id));
        }
    }
}
unset($device['vlans']);
        if ($port_low['ifType'] == 'propVirtual') {
            continue;
        }
        //Skip stacking on Vlan ports (F.u. Cisco SB)
        $ifStackStatus = $entry_low['ifStackStatus'];
        if (isset($stack_db_array[$port_id_high][$port_id_low])) {
            if ($stack_db_array[$port_id_high][$port_id_low]['ifStackStatus'] == $ifStackStatus) {
                echo ".";
            } else {
                $update_array = array('ifStackStatus' => $ifStackStatus);
                dbUpdate($update_array, 'ports_stack', "`device_id` = ? AND `port_id_high` = ? AND `port_id_low` = ?", array($device['device_id'], $port_id_high, $port_id_low));
                echo "U";
            }
            unset($stack_db_array[$port_id_high][$port_id_low]);
        } else {
            $update_array = array('device_id' => $device['device_id'], 'port_id_high' => $port_id_high, 'port_id_low' => $port_id_low, 'ifStackStatus' => $ifStackStatus);
            dbInsert($update_array, 'ports_stack');
            echo "+";
        }
    }
}
foreach ($stack_db_array as $port_id_high => $array) {
    foreach ($array as $port_id_low => $blah) {
        print_debug("DELETE STACK: " . $device['device_id'] . " " . $port_id_low . " " . $port_id_high);
        dbDelete('ports_stack', "`device_id` =  ? AND port_id_high = ? AND port_id_low = ?", array($device['device_id'], $port_id_high, $port_id_low));
        echo "-";
    }
}
unset($update_array);
echo "\n";
// EOF
Esempio n. 8
0
                if ($stp_raw[$port]['dot1dStpPortDesignatedPort']) {
                    $dp = $stp_raw[$port]['dot1dStpPortDesignatedPort'] - $dp_value;
                    $stp_port['designatedPort'] = $dp;
                }
            } else {
                // Port saved in format priority+port (ieee 802.1d-1998: clause 8.5.5.1)
                $dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2);
                //discard the first octet (priority part)
                $stp_port['designatedPort'] = hexdec($dp);
            }
            d_echo($stp_port);
            // Write to db
            if (!dbFetchCell('SELECT 1 FROM `ports_stp` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $stp_port['port_id']))) {
                dbInsert($stp_port, 'ports_stp');
                echo '+';
            }
        }
    }
    // Delete STP ports from db if absent in SNMP query
    $stp_port_db = dbFetchRows('SELECT * FROM `ports_stp` WHERE `device_id` = ?', array($device['device_id']));
    //d_echo($stp_port_db);
    foreach ($stp_port_db as $port => $value) {
        $if_index = dbFetchCell('SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id']));
        if ($if_index != $stp_raw[$if_index]['dot1dStpPort']) {
            dbDelete('ports_stp', '`device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id']));
            echo '-';
        }
    }
}
unset($stp_raw, $stp, $stp_db, $stp_port, $stp_port_db);
echo "\n";
Esempio n. 9
0
                    $cef_stat['update']['drop'] = $cef_stat['cefSwitchingDrop'];
                    $cef_stat['update']['punt'] = $cef_stat['cefSwitchingPunt'];
                    $cef_stat['update']['punt2host'] = $cef_stat['cefSwitchingPunt2Host'];
                    $cef_stat['update']['drop_prev'] = $cef_entry['drop'];
                    $cef_stat['update']['punt_prev'] = $cef_entry['punt'];
                    $cef_stat['update']['punt2host_prev'] = $cef_entry['punt2host'];
                    $cef_stat['update']['updated'] = $polled;
                    $cef_stat['update']['updated_prev'] = $cef_entry['updated'];
                    dbUpdate($cef_stat['update'], 'cef_switching', '`device_id` = ? AND `entPhysicalIndex` = ? AND `afi` = ? AND `cef_index` = ?', array($device['device_id'], $entity, $afi, $path));
                    $fields = array('drop' => $cef_stat['cefSwitchingDrop'], 'punt' => $cef_stat['cefSwitchingPunt'], 'hostpunt' => $cef_stat['cefSwitchingPunt2Host']);
                    $ret = rrdtool_update("{$filename}", $fields);
                    $tags = array('entity' => $entity, 'afi' => $afi, 'index' => $path);
                    influx_update($device, 'cefswitching', $tags, $fields);
                    echo "\n";
                }
                //end foreach
            }
            //end foreach
        }
        //end foreach
    }
    //end if
    // FIXME - need to delete old ones. FIXME REALLY.
    print_r($cefs_db);
    foreach ($cefs_db as $cef_switching_id) {
        dbDelete('cef_switching', '`cef_switching_id` =  ?', array($cef_switching_id));
        echo '-';
    }
    echo "\n";
}
//end if
Esempio n. 10
0
                // Already present in DB, update row
                if (serialize($value) != $in_db[$key]) {
                    // Submitted value is different from current value
                    dbUpdate(array('config_value' => serialize($value)), 'config', '`config_key` = ?', array($key));
                    $updates++;
                }
            } else {
                // Not set in DB yet, insert row
                dbInsert(array('config_key' => $key, 'config_value' => serialize($value)), 'config');
                $updates++;
            }
        }
    }
    // Delete fields that were reset to default
    if (count($deletes)) {
        dbDelete('config', '`config_key` IN (' . implode(',', $deletes) . ')');
        $updates++;
    }
    // Print errors from validation above, if any
    foreach ($errors as $error) {
        print_error($error);
    }
    if ($updates) {
        print_success("Settings updated.<br />Please note Web UI setting takes effect only when refreshing the page <i>after</i> saving the configuration. Please click <a href=\"" . $_SERVER['REQUEST_URI'] . "\">here</a> to reload the page.");
        // Reload $config now, or form below will show old settings still
        include $config['install_dir'] . '/includes/sql-config.inc.php';
    } else {
        print_error('No changes made.');
    }
}
$link_array = array('page' => 'settings');
Esempio n. 11
0
        $months = $config['billing_data_purge'];
        echo "Deleting billing data more than {$months} month before the last completed billing cycle\n";
        $sql = "DELETE bill_data\n                FROM bill_data\n                    INNER JOIN (SELECT bill_id, \n                        SUBDATE(\n                            SUBDATE(\n                                ADDDATE(\n                                    subdate(curdate(), (day(curdate())-1)),             # Start of this month\n                                    bill_day - 1),                                      # Billing anniversary\n                                INTERVAL IF(bill_day > DAY(curdate()), 1, 0) MONTH),    # Deal with anniversary not yet happened this month\n                            INTERVAL ? MONTH) AS threshold                              # Adjust based on config threshold\n                FROM bills) q\n                ON bill_data.bill_id = q.bill_id AND bill_data.timestamp < q.threshold;";
        dbQuery($sql, array($months));
    }
}
if ($options['f'] === 'alert_log') {
    if (is_numeric($config['alert_log_purge']) && $config['alert_log_purge'] > 0) {
        if (dbDelete('alert_log', 'time_logged < DATE_SUB(NOW(),INTERVAL ? DAY)', array($config['alert_log_purge']))) {
            echo 'Alert log data cleared for entries over ' . $config['alert_log_purge'] . " days\n";
        }
    }
}
if ($options['f'] === 'purgeusers') {
    $purge = 0;
    if (is_numeric($config['radius']['users_purge']) && $config['auth_mechanism'] === 'radius') {
        $purge = $config['radius']['users_purge'];
    }
    if (is_numeric($config['active_directory']['users_purge']) && $config['auth_mechanism'] === 'active_directory') {
        $purge = $config['active_directory']['users_purge'];
    }
    if ($purge > 0) {
        foreach (dbFetchRows("SELECT DISTINCT(`user`) FROM `authlog` WHERE `datetime` >= DATE_SUB(NOW(), INTERVAL ? DAY)", array($purge)) as $user) {
            $users[] = $user['user'];
        }
        $del_users = '"' . implode('","', $users) . '"';
        if (dbDelete('users', "username NOT IN ({$del_users})", array($del_users))) {
            echo "Removed users that haven't logged in for {$purge} days";
        }
    }
}
Esempio n. 12
0
            echo '+';
            // FIXME eventlog
        } else {
            echo '.';
        }
        /*
         * Save the discovered Virtual Machine.
         */
        $vmw_vmlist[] = $index;
    }
    /*
     * Get a list of all the known Virtual Machines for this host.
     */
    $sql = "SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '" . $device['device_id'] . "' AND vm_type='vmware'";
    foreach (dbFetchRows($sql) as $db_vm) {
        /*
         * Delete the Virtual Machines that are removed from the host.
         */
        if (!in_array($db_vm['vmwVmVMID'], $vmw_vmlist)) {
            dbDelete('vminfo', '`id` = ?', array($db_vm['id']));
            log_event(mres($db_vm['vmwVmDisplayName']) . ' Removed', $device, 'system', $db_vm['vmwVmVMID']);
            echo '-';
            // FIXME eventlog
        }
    }
    /*
     * Finished discovering VMware information.
     */
    echo "\n";
}
//end if
Esempio n. 13
0
                    if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) {
                        dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi));
                    }
                }
            }
        }
        unset($j_afisafi);
        unset($j_prefixes);
        unset($j_bgp);
        unset($j_peerIndexes);
    }
    // Delete removed peers
    $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '" . $device['device_id'] . "'";
    foreach (dbFetchRows($sql) as $entry) {
        unset($exists);
        $i = 0;
        while ($i < count($peerlist) && !isset($exists)) {
            if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) {
                $exists = 1;
            }
            $i++;
        }
        if (!isset($exists)) {
            dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
            dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id']));
            echo '-';
        }
    }
    unset($peerlist);
    echo "\n";
}
Esempio n. 14
0
                    } else {
                        //normal devices returning toner values
                        $current = $current / $capacity * 100;
                    }
                    $type = 'jetdirect';
                    if (isHexString($descr)) {
                        $descr = snmp_hexstring($descr);
                    }
                    discover_toner($valid_toner, $device, $toner_oid, $index, $type, $descr, $capacity_oid, $capacity, $current);
                }
            }
        }
        //end if
    }
    //end foreach
}
//end if
// Delete removed toners
d_echo("\n Checking ... \n");
d_echo($valid_toner);
$sql = "SELECT * FROM toner WHERE device_id = '" . $device['device_id'] . "'";
foreach (dbFetchRows($sql) as $test_toner) {
    $toner_index = $test_toner['toner_index'];
    $toner_type = $test_toner['toner_type'];
    if (!$valid_toner[$toner_type][$toner_index]) {
        echo '-';
        dbDelete('toner', '`toner_id` = ?', array($test_toner['toner_id']));
    }
}
unset($valid_toner);
echo "\n";
                    print_message("密码已更改.");
                } else {
                    print_error("密码不匹配!");
                }
            }
            // FIXME broken PoS code.
            if ($vars['action'] == "becomeuser") {
                $_SESSION['origusername'] = $_SESSION['username'];
                $_SESSION['username'] = $user_data['username'];
                header('位置: ' . $config['base_url']);
                dbInsert(array('user' => $_SESSION['origusername'], 'address' => $_SERVER["REMOTE_ADDR"], 'result' => '成为 ' . $_SESSION['username']), 'authlog');
                include "includes/authenticate.inc.php";
            }
            if ($vars['action'] == "perm_del") {
                if (dbFetchCell("SELECT COUNT(*) FROM `entity_permissions` WHERE `entity_type` = ? AND `entity_id` = ? AND `user_id` = ?", array($vars['entity_type'], $vars['entity_id'], $vars['user_id']))) {
                    dbDelete('entity_permissions', "`entity_type` = ? AND `entity_id` =  ? AND `user_id` = ?", array($vars['entity_type'], $vars['entity_id'], $vars['user_id']));
                }
            }
            if ($vars['action'] == "perm_add") {
                if (!is_array($vars['entity_id'])) {
                    $vars['entity_id'] = array($vars['entity_id']);
                }
                foreach ($vars['entity_id'] as $entry) {
                    if (!dbFetchCell("SELECT COUNT(*) FROM `entity_permissions` WHERE `entity_type` = ? AND `entity_id` = ? AND `user_id` = ?", array($vars['entity_type'], $entry, $vars['user_id']))) {
                        dbInsert(array('entity_id' => $entry, 'entity_type' => $vars['entity_type'], 'user_id' => $vars['user_id']), 'entity_permissions');
                    }
                }
            }
            ?>
  <div class="row">
Esempio n. 16
0
function applet_userbanlist()
{
    $inCore = cmsCore::getInstance();
    $inDB = cmsDatabase::getInstance();
    $inUser = cmsUser::getInstance();
    global $_LANG;
    global $adminAccess;
    if (!cmsUser::isAdminCan('admin/users', $adminAccess)) {
        cpAccessDenied();
    }
    $GLOBALS['cp_page_title'] = $_LANG['AD_BANLIST'];
    cpAddPathway($_LANG['AD_USERS'], 'index.php?view=users');
    cpAddPathway($_LANG['AD_BANLIST'], 'index.php?view=userbanlist');
    $do = cmsCore::request('do', 'str', 'list');
    $id = cmsCore::request('id', 'int', -1);
    $to = cmsCore::request('to', 'int', 0);
    // для редиректа обратно в профиль на сайт
    if ($to) {
        cmsUser::sessionPut('back_url', cmsCore::getBackURL());
    }
    if ($do == 'list') {
        $toolmenu[] = array('icon' => 'useradd.gif', 'title' => $_LANG['AD_TO_BANLIST_ADD'], 'link' => '?view=userbanlist&do=add');
        $toolmenu[] = array('icon' => 'edit.gif', 'title' => $_LANG['AD_EDIT_SELECTED'], 'link' => "javascript:checkSel('?view=userbanlist&do=edit&multiple=1');");
        $toolmenu[] = array('icon' => 'delete.gif', 'title' => $_LANG['AD_DELETE_SELECTED'], 'link' => "javascript:checkSel('?view=userbanlist&do=delete&multiple=1');");
        cpToolMenu($toolmenu);
        $fields[] = array('title' => 'id', 'field' => 'id', 'width' => '30');
        $fields[] = array('title' => $_LANG['AD_IS_ACTIVE'], 'field' => 'status', 'width' => '55', 'prc' => 'cpYesNo');
        $fields[] = array('title' => $_LANG['AD_BANLIST_USER'], 'field' => 'user_id', 'width' => '120', 'filter' => '12', 'prc' => 'cpUserNick');
        $fields[] = array('title' => $_LANG['AD_BANLIST_IP'], 'field' => 'ip', 'width' => '100', 'link' => '?view=userbanlist&do=edit&id=%id%', 'filter' => '12');
        $fields[] = array('title' => $_LANG['DATE'], 'field' => 'bandate', 'width' => '', 'fdate' => '%d/%m/%Y %H:%i:%s', 'filter' => '12');
        $fields[] = array('title' => $_LANG['AD_BANLIST_TIME'], 'field' => 'int_num', 'width' => '55');
        $fields[] = array('title' => '', 'field' => 'int_period', 'width' => '70');
        $fields[] = array('title' => $_LANG['AD_AUTOREMOVE'], 'field' => 'autodelete', 'width' => '90', 'prc' => 'cpYesNo');
        $actions[] = array('title' => $_LANG['EDIT'], 'icon' => 'edit.gif', 'link' => '?view=userbanlist&do=edit&id=%id%');
        $actions[] = array('title' => $_LANG['DELETE'], 'icon' => 'delete.gif', 'confirm' => $_LANG['AD_REMOVE_RULE'], 'link' => '?view=userbanlist&do=delete&id=%id%');
        cpListTable('cms_banlist', $fields, $actions, '1=1', 'ip DESC');
    }
    if ($do == 'delete') {
        if (!isset($_REQUEST['item'])) {
            if ($id >= 0) {
                dbDelete('cms_banlist', $id);
            }
        } else {
            dbDeleteList('cms_banlist', cmsCore::request('item', 'array_int', array()));
        }
        cmsCore::redirect('?view=userbanlist');
    }
    if ($do == 'submit' || $do == 'update') {
        if (!cmsUser::checkCsrfToken()) {
            cmsCore::error404();
        }
        $types = array('user_id' => array('user_id', 'int', 0), 'ip' => array('ip', 'str', ''), 'cause' => array('cause', 'str', ''), 'autodelete' => array('autodelete', 'int', 0), 'int_num' => array('int_num', 'int', 0), 'int_period' => array('int_period', 'str', '', create_function('$p', 'if(!in_array($p, array("MONTH","DAY","HOUR","MINUTE"))){ $p = "MINUTE"; } return $p;')));
        $items = cmsCore::getArrayFromRequest($types);
        $error = false;
        if (!$items['ip']) {
            $error = true;
            cmsCore::addSessionMessage($_LANG['AD_NEED_IP'], 'error');
        }
        if ($items['ip'] == $_SERVER['REMOTE_ADDR'] || $items['user_id'] == $inUser->id) {
            $error = true;
            cmsCore::addSessionMessage($_LANG['AD_ITS_YOUR_IP'], 'error');
        }
        if (cmsUser::userIsAdmin($items['user_id'])) {
            $error = true;
            cmsCore::addSessionMessage($_LANG['AD_ITS_ADMIN'], 'error');
        }
        if ($error) {
            cmsCore::redirectBack();
        }
        if ($do == 'update') {
            $inDB->update('cms_banlist', $items, $id);
            if (empty($_SESSION['editlist'])) {
                cmsCore::redirect('?view=userbanlist');
            } else {
                cmsCore::redirect('?view=userbanlist&do=edit');
            }
        }
        $inDB->insert('cms_banlist', $items);
        $back_url = cmsUser::sessionGet('back_url');
        cmsUser::sessionDel('back_url');
        cmsCore::redirect($back_url ? $back_url : '?view=userbanlist');
    }
    if ($do == 'add' || $do == 'edit') {
        $GLOBALS['cp_page_head'][] = '<script language="JavaScript" type="text/javascript" src="/admin/js/banlist.js"></script>';
        $toolmenu[] = array('icon' => 'save.gif', 'title' => $_LANG['SAVE'], 'link' => 'javascript:document.addform.submit();');
        $toolmenu[] = array('icon' => 'cancel.gif', 'title' => $_LANG['CANCEL'], 'link' => 'javascript:history.go(-1);');
        cpToolMenu($toolmenu);
        if ($do == 'add') {
            echo '<h3>' . $_LANG['AD_TO_BANLIST_ADD'] . '</h3>';
            cpAddPathway($_LANG['AD_TO_BANLIST_ADD']);
        } else {
            if (isset($_REQUEST['multiple'])) {
                if (isset($_REQUEST['item'])) {
                    $_SESSION['editlist'] = cmsCore::request('item', 'array_int', array());
                } else {
                    cmsCore::addSessionMessage($_LANG['AD_NO_SELECT_OBJECTS'], 'error');
                    cmsCore::redirectBack();
                }
            }
            $ostatok = '';
            if (isset($_SESSION['editlist'])) {
                $item_id = array_shift($_SESSION['editlist']);
                if (sizeof($_SESSION['editlist']) == 0) {
                    unset($_SESSION['editlist']);
                } else {
                    $ostatok = '(' . $_LANG['AD_NEXT_IN'] . sizeof($_SESSION['editlist']) . ')';
                }
            } else {
                $item_id = cmsCore::request('id', 'int', 0);
            }
            $mod = $inDB->get_fields('cms_banlist', "id = '{$item_id}'", '*');
            if (!$mod) {
                cmsCore::error404();
            }
            echo '<h3>' . $_LANG['AD_EDIT_RULE'] . ' ' . $ostatok . '</h3>';
            cpAddPathway($_LANG['AD_EDIT_RULE']);
        }
        ?>
	  <div style="margin-top:2px;padding:10px;border:dotted 1px silver; width:508px;background:#FFFFCC">
	  	<div style="font-weight:bold"><?php 
        echo $_LANG['ATTENTION'];
        ?>
!</div>
		<div><?php 
        echo $_LANG['AD_CAUTION_INFO_0'];
        ?>
</div>
		<div><?php 
        echo $_LANG['AD_CAUTION_INFO_1'];
        ?>
</div>
	  </div>
      <form id="addform" name="addform" method="post" action="index.php?view=userbanlist">
        <input type="hidden" name="csrf_token" value="<?php 
        echo cmsUser::getCsrfToken();
        ?>
" />
        <table width="530" border="0" cellspacing="5" class="proptable">
          <tr>
            <td width="150" valign="top"><div><strong><?php 
        echo $_LANG['AD_BANLIST_USER'];
        ?>
: </strong></div></td>
			<?php 
        if ($do == 'add' && $to) {
            $mod['user_id'] = $to;
            $mod['ip'] = $inDB->get_field('cms_users', 'id=' . $to, 'last_ip');
        }
        ?>
            <td valign="top">
				<select name="user_id" id="user_id" onchange="loadUserIp()" style="width: 250px;">
                    <option value="0" <?php 
        if (@(!$mod['user_id'])) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo $_LANG['AD_WHITHOUT_USER'];
        ?>
</option>
                    <?php 
        if (isset($mod['user_id'])) {
            echo $inCore->getListItems('cms_users', $mod['user_id'], 'nickname', 'ASC', 'is_deleted=0 AND is_locked=0', 'id', 'nickname');
        } else {
            echo $inCore->getListItems('cms_users', 0, 'nickname', 'ASC', 'is_deleted=0 AND is_locked=0', 'id', 'nickname');
        }
        ?>
				</select>
            </td>
          </tr>
          <tr>
            <td valign="top"><strong><?php 
        echo $_LANG['AD_BANLIST_IP'];
        ?>
:</strong></td>
            <td valign="top"><input name="ip" type="text" id="ip" style="width: 244px;" value="<?php 
        echo @$mod['ip'];
        ?>
"/></td>
          </tr>
          <tr>
            <td valign="top"><strong><?php 
        echo $_LANG['AD_BANLIST_CAUSE'];
        ?>
:</strong></td>
            <td valign="top">
                <textarea name="cause" style="width:240px" rows="5"><?php 
        echo @$mod['cause'];
        ?>
</textarea>
            </td>
          </tr>
		  <?php 
        $forever = false;
        if (!@$mod['int_num']) {
            $forever = true;
        }
        ?>
          <tr>
            <td valign="top"><strong><?php 
        echo $_LANG['AD_BAN_FOREVER'];
        ?>
</strong></td>
            <td valign="top"><input type="checkbox" name="forever" value="1" <?php 
        if ($forever) {
            echo 'checked="checked"';
        }
        ?>
 onclick="$('tr.bantime').toggle();"/></td>
          </tr>
          <tr class="bantime">
            <td valign="top"><strong><?php 
        echo $_LANG['AD_BAN_FOR_TIME'];
        ?>
</strong> </td>

            <td valign="top"><p>
            <input name="int_num" type="text" id="int_num" size="5" value="<?php 
        echo @(int) $mod['int_num'];
        ?>
"/>
              <select name="int_period" id="int_period">
                <option value="MINUTE"  <?php 
        if (@mb_strstr($mod['int_period'], 'MINUTE')) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo $_LANG['MINUTE10'];
        ?>
</option>]
                <option value="HOUR"  <?php 
        if (@mb_strstr($mod['int_period'], 'HOUR')) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo $_LANG['HOUR10'];
        ?>
</option>
                <option value="DAY" <?php 
        if (@mb_strstr($mod['int_period'], 'DAY')) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo $_LANG['DAY10'];
        ?>
</option>
                <option value="MONTH" <?php 
        if (@mb_strstr($mod['int_period'], 'MONTH')) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo $_LANG['MONTH10'];
        ?>
</option>
              </select>
            </p>
            <p><label><input name="autodelete" type="checkbox" id="autodelete" value="1" <?php 
        if ($mod['autodelete']) {
            echo 'checked="checked"';
        }
        ?>
 /> <?php 
        echo $_LANG['AD_REMOVE_BAN'];
        ?>
</label></p>
            </td>
          </tr>
		  <?php 
        if ($forever) {
            ?>
<script type="text/javascript">$('tr.bantime').hide();</script><?php 
        }
        ?>
        </table>
        <p>
          <label>
          <input name="add_mod" type="submit" id="add_mod" <?php 
        if ($do == 'add') {
            echo 'value="' . $_LANG['AD_TO_BANLIST_ADD'] . '"';
        } else {
            echo 'value="' . $_LANG['SAVE'] . '"';
        }
        ?>
 />
          </label>
          <label><span style="margin-top:15px">
          <input name="back" type="button" id="back" value="<?php 
        echo $_LANG['CANCEL'];
        ?>
" onclick="window.history.back();"/>
          </span></label>
          <input name="do" type="hidden" id="do" <?php 
        if ($do == 'add') {
            echo 'value="submit"';
        } else {
            echo 'value="update"';
        }
        ?>
 />
          <?php 
        if ($do == 'edit') {
            echo '<input name="id" type="hidden" value="' . $mod['id'] . '" />';
        }
        ?>
        </p>
      </form>
	<?php 
    }
}
Esempio n. 17
0
function del_dev_attrib($device, $attrib_type)
{
    return dbDelete('devices_attribs', "`device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type));
}
Esempio n. 18
0
            if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') {
                d_echo("Changed mac address for {$ip} from {$old_mac} to {$clean_mac}\n");
                log_event("MAC change: {$ip} : " . mac_clean_to_readable($old_mac) . ' -> ' . mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']);
            }
            dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip));
            echo '.';
        } else {
            if (isset($interface['port_id'])) {
                echo '+';
                // echo("Add MAC $mac\n");
                $insert_data = array('port_id' => $interface['port_id'], 'mac_address' => $clean_mac, 'ipv4_address' => $ip);
                dbInsert($insert_data, 'ipv4_mac');
            }
        }
        //end if
    }
    //end if
}
//end foreach
$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '" . $device['device_id'] . "'";
foreach (dbFetchRows($sql) as $entry) {
    $entry_mac = $entry['mac_address'];
    $entry_if = $entry['port_id'];
    if (!$mac_table[$entry_if][$entry_mac]) {
        dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac));
        d_echo("Removing MAC {$entry_mac} from interface " . $interface['ifName']);
        echo '-';
    }
}
echo "\n";
unset($mac);
Esempio n. 19
0
            echo 'S';
        }
        $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network));
        if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') {
            dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses');
            // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n");
            echo '+';
        } else {
            echo '.';
        }
        $full_address = "{$oid}/{$cidr}|{$ifIndex}";
        $valid_v4[$full_address] = 1;
    } else {
        echo '!';
    }
    //end if
}
//end foreach
$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '" . $device['device_id'] . "' AND  A.port_id = I.port_id";
foreach (dbFetchRows($sql) as $row) {
    $full_address = $row['ipv4_address'] . '/' . $row['ipv4_prefixlen'] . '|' . $row['ifIndex'];
    if (!$valid_v4[$full_address]) {
        echo '-';
        $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id']));
        if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) {
            $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id']));
        }
    }
}
echo "\n";
unset($valid_v4);
Esempio n. 20
0
             }
         }
     }
     $db_inserts = implode(',', $db_id);
     if (!empty($db_inserts) || empty($_POST['config_value'])) {
         if (empty($_POST['config_value'])) {
             $db_inserts = 0;
         }
         if ($config_type == 'slack') {
             dbDelete('config', "(`config_name` LIKE 'alert.transports.slack.{$config_id}.%' AND `config_name` != 'alert.transports.slack.{$config_id}.url' AND `config_id` NOT IN ({$db_inserts}))");
         } else {
             if ($config_type == 'hipchat') {
                 dbDelete('config', "(`config_name` LIKE 'alert.transports.hipchat.{$config_id}.%' AND (`config_name` != 'alert.transports.hipchat.{$config_id}.url' AND `config_name` != 'alert.transports.hipchat.{$config_id}.room_id' AND `config_name` != 'alert.transports.hipchat.{$config_id}.from') AND `config_id` NOT IN ({$db_inserts}))");
             } else {
                 if ($config_type == 'pushover') {
                     dbDelete('config', "(`config_name` LIKE 'alert.transports.pushover.{$config_id}.%' AND (`config_name` != 'alert.transports.pushover.{$config_id}.appkey' AND `config_name` != 'alert.transports.pushover.{$config_id}.userkey') AND `config_id` NOT IN ({$db_inserts}))");
                 }
             }
         }
     }
     $message = 'Config item has been updated:';
     $status = 'ok';
 } else {
     $state = mres($_POST['config_value']);
     $update = dbUpdate(array('config_value' => $state), 'config', '`config_id`=?', array($config_id));
     if (!empty($update) || $update == '0') {
         $message = 'Alert rule has been updated.';
         $status = 'ok';
     } else {
         $message = 'ERROR: Alert rule has not been updated.';
     }
Esempio n. 21
0
        }
        echo "\n";
        foreach (dbFetchRows('SELECT * FROM ports WHERE device_id = ?', array($device['device_id'])) as $row) {
            $if = $row['port_id'];
            $vrf_id = $row['ifVrf'];
            if ($row['ifVrf']) {
                if (!$valid_vrf_if[$vrf_id][$if]) {
                    echo "-";
                    dbUpdate(array('ifVrf' => NULL), 'ports', '`port_id` = ?', array($if));
                } else {
                    echo ".";
                }
            }
        }
        foreach (dbFetchRows('SELECT * FROM vrfs WHERE device_id = ?', array($device['device_id'])) as $row) {
            $vrf_id = $row['vrf_id'];
            if (!$valid_vrf[$vrf_id]) {
                echo "-";
                dbDelete('vrfs', '`vrf_id` = ?', array($vrf_id));
            } else {
                echo ".";
            }
        }
        unset($valid_vrf_if);
        unset($valid_vrf);
        echo PHP_EOL;
    }
    # cisco/junos/ironware
}
# enable_vrfs
// EOF
function delete_port($int_id, $delete_rrd = TRUE)
{
    global $config;
    $port = dbFetchRow("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.`port_id` = ? AND D.`device_id` = P.`device_id`", array($int_id));
    $ret = "> 删除接口自 " . $port['hostname'] . ": id={$int_id} (" . $port['ifDescr'] . ")\n";
    $port_tables = array('bill_ports', 'eigrp_ports', 'ipv4_addresses', 'ipv6_addresses', 'ip_mac', 'juniAtmVp', 'mac_accounting', 'ospf_nb', 'ospf_ports', 'ports_adsl', 'ports_cbqos', 'ports_vlans', 'pseudowires', 'vlans_fdb', 'ports');
    foreach ($port_tables as $table) {
        $table_status = dbDelete($table, "`port_id` = ?", array($int_id));
        if ($table_status) {
            $deleted_tables[] = $table;
        }
    }
    $table_status = dbDelete('ports_stack', "`port_id_high` = ?  OR `port_id_low` = ?", array($int_id, $int_id));
    if ($table_status) {
        $deleted_tables[] = 'ports_stack';
    }
    $table_status = dbDelete('links', "`local_port_id` = ? OR `remote_port_id` = ?", array($int_id, $int_id));
    if ($table_status) {
        $deleted_tables[] = 'links';
    }
    $table_status = dbDelete('entity_permissions', "`entity_type` = 'port' AND `entity_id` = ?", array($int_id));
    if ($table_status) {
        $deleted_tables[] = 'entity_permissions';
    }
    $table_status = dbDelete('alert_table', "`entity_type` = 'port' AND `entity_id` = ?", array($int_id));
    if ($table_status) {
        $deleted_tables[] = 'alert_table';
    }
    $table_status = dbDelete('group_table', "`entity_type` = 'port' AND `entity_id` = ?", array($int_id));
    if ($table_status) {
        $deleted_tables[] = 'group_table';
    }
    $ret .= '> 从表中删除接口内容: ' . implode(', ', $deleted_tables) . PHP_EOL;
    if ($delete_rrd) {
        $rrd_types = array('adsl', 'dot3', 'fdbcount', 'poe', NULL);
        foreach ($rrd_types as $type) {
            $rrdfile = get_port_rrdfilename($port, $type, TRUE);
            if (is_file($rrdfile)) {
                unlink($rrdfile);
                $deleted_rrds[] = $rrdfile;
            }
        }
        $ret .= '> 删除接口RDD文件: ' . implode(', ', $deleted_rrds) . PHP_EOL;
    }
    return $ret;
}
Esempio n. 23
0
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar') {
    $config_id = mres($_POST['config_id']);
    if (empty($config_id)) {
        $message = 'No config id passed';
    } else {
        if (dbDelete('config', '`config_id`=?', array($config_id))) {
            if ($action == 'remove-slack') {
                dbDelete('config', "`config_name` LIKE 'alert.transports.slack.{$config_id}.%'");
            } else {
                if ($action == 'remove-hipchat') {
                    dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.{$config_id}.%'");
                } else {
                    if ($action == 'remove-pushover') {
                        dbDelete('config', "`config_name` LIKE 'alert.transports.pushover.{$config_id}.%'");
                    } elseif ($action == 'remove-boxcar') {
                        dbDelete('config', "`config_name` LIKE 'alert.transports.boxcar.{$config_id}.%'");
                    }
                }
            }
            $status = 'ok';
            $message = 'Config item removed';
        } else {
            $message = 'General error, could not remove config';
        }
    }
} else {
    if ($action == 'add-slack') {
        if (empty($config_value)) {
            $message = 'No Slack url provided';
        } else {
            $config_id = dbInsert(array('config_name' => 'alert.transports.slack.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Slack Transport'), 'config');
Esempio n. 24
0
    foreach (dbFetchRows('SELECT DISTINCT(`ospfNbrIpAddr`),`device_id` FROM `ospf_nbrs` WHERE `device_id`=?', array($device['device_id'])) as $nbr) {
        $ip = $nbr['ospfNbrIpAddr'];
        if (match_network($config['autodiscovery']['nets-exclude'], $ip)) {
            echo 'x';
            continue;
        }
        if (!match_network($config['nets'], $ip)) {
            echo 'i';
            continue;
        }
        $name = gethostbyaddr($ip);
        $remote_device_id = discover_new_device($name, $device, 'OSPF');
    }
} else {
    echo "disabled\n";
}
d_echo($link_exists);
$sql = "SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_port_id = I.port_id AND I.device_id = '" . $device['device_id'] . "'";
foreach (dbFetchRows($sql) as $test) {
    $local_port_id = $test['local_port_id'];
    $remote_hostname = $test['remote_hostname'];
    $remote_port = $test['remote_port'];
    d_echo("{$local_port_id} -> {$remote_hostname} -> {$remote_port} \n");
    if (!$link_exists[$local_port_id][$remote_hostname][$remote_port]) {
        echo '-';
        $rows = dbDelete('links', '`id` = ?', array($test['id']));
        d_echo("{$rows} deleted ");
    }
}
unset($link_exists);
echo "\n";
         dbInsert(array('device_id' => $vars['device_id'], 'user_id' => $vars['user_id']), 'devices_perms');
     }
 }
 if ($vars['action'] == "delifperm") {
     if (dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) {
         dbDelete('ports_perms', "`port_id` =  ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']));
     }
 }
 if ($vars['action'] == "addifperm") {
     if (!dbFetchCell("SELECT COUNT(*) FROM ports_perms WHERE `port_id` = ? AND `user_id` = ?", array($vars['port_id'], $vars['user_id']))) {
         dbInsert(array('port_id' => $vars['port_id'], 'user_id' => $vars['user_id']), 'ports_perms');
     }
 }
 if ($vars['action'] == "delbillperm") {
     if (dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) {
         dbDelete('bill_perms', "`bill_id` =  ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']));
     }
 }
 if ($vars['action'] == "addbillperm") {
     if (!dbFetchCell("SELECT COUNT(*) FROM bill_perms WHERE `bill_id` = ? AND `user_id` = ?", array($vars['bill_id'], $vars['user_id']))) {
         dbInsert(array('bill_id' => $vars['bill_id'], 'user_id' => $vars['user_id']), 'bill_perms');
     }
 }
 echo '<div class="row">
    <div class="col-md-4">';
 // Display devices this users has access to
 echo "<h3>Device Access</h3>";
 echo "<div class='panel panel-default panel-condensed'>\n            <table class='table table-hover table-condensed table-striped'>\n              <tr>\n                <th>Device</th>\n                <th>Action</th>\n              </tr>";
 $device_perms = dbFetchRows("SELECT * from devices_perms as P, devices as D WHERE `user_id` = ? AND D.device_id = P.device_id", array($vars['user_id']));
 foreach ($device_perms as $device_perm) {
     echo "<tr><td><strong>" . $device_perm['hostname'] . "</td><td> <a href='edituser/action=deldevperm/user_id=" . $vars['user_id'] . "/device_id=" . $device_perm['device_id'] . "'><img src='images/16/cross.png' align=absmiddle border=0></a></strong></td></tr>";
Esempio n. 26
0
<?php

echo 'Storage : ';
// Include all discovery modules
$include_dir = 'includes/discovery/storage';
require 'includes/include-dir.inc.php';
// Remove storage which weren't redetected here
$sql = "SELECT * FROM `storage` WHERE `device_id`  = '" . $device['device_id'] . "'";
d_echo($valid_storage);
foreach (dbFetchRows($sql) as $test_storage) {
    $storage_index = $test_storage['storage_index'];
    $storage_mib = $test_storage['storage_mib'];
    d_echo($storage_index . ' -> ' . $storage_mib . "\n");
    if (!$valid_storage[$storage_mib][$storage_index]) {
        echo '-';
        dbDelete('storage', '`storage_id` = ?', array($test_storage['storage_id']));
    }
    unset($storage_index);
    unset($storage_mib);
}
unset($valid_storage);
echo "\n";
Esempio n. 27
0
}
// Check if the form was POSTed
if ($_POST['device']) {
    $updated = 0;
    $param[] = $device['device_id'];
    foreach (array_keys($_POST) as $key) {
        if (substr($key, 0, 4) == 'app_') {
            $param[] = substr($key, 4);
            $enabled[] = substr($key, 4);
            $replace[] = '?';
        }
    }
    if (count($enabled)) {
        $updated += dbDelete('applications', '`device_id` = ? AND `app_type` NOT IN (' . implode(',', $replace) . ')', $param);
    } else {
        $updated += dbDelete('applications', '`device_id` = ?', array($param));
    }
    foreach (dbFetchRows('SELECT `app_type` FROM `applications` WHERE `device_id` = ?', array($device['device_id'])) as $row) {
        $app_in_db[] = $row['app_type'];
    }
    foreach ($enabled as $app) {
        if (!in_array($app, $app_in_db)) {
            $updated += dbInsert(array('device_id' => $device['device_id'], 'app_type' => $app), 'applications');
        }
    }
    if ($updated) {
        print_message('Applications updated!');
    } else {
        print_message('No changes.');
    }
}
Esempio n. 28
0
function poll_device($device, $options)
{
    global $config, $device, $polled_devices, $db_stats, $memcache;
    $attribs = get_dev_attribs($device['device_id']);
    $status = 0;
    unset($array);
    $device_start = utime();
    // Start counting device poll time
    echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' ';
    if ($config['os'][$device['os']]['group']) {
        $device['os_group'] = $config['os'][$device['os']]['group'];
        echo '(' . $device['os_group'] . ')';
    }
    echo "\n";
    unset($poll_update);
    unset($poll_update_query);
    unset($poll_separator);
    $poll_update_array = array();
    $update_array = array();
    $host_rrd = $config['rrd_dir'] . '/' . $device['hostname'];
    if (!is_dir($host_rrd)) {
        mkdir($host_rrd);
        echo "Created directory : {$host_rrd}\n";
    }
    $address_family = snmpTransportToAddressFamily($device['transport']);
    $ping_response = isPingable($device['hostname'], $address_family, $attribs);
    $device_perf = $ping_response['db'];
    $device_perf['device_id'] = $device['device_id'];
    $device_perf['timestamp'] = array('NOW()');
    if (can_ping_device($attribs) === true && is_array($device_perf)) {
        dbInsert($device_perf, 'device_perf');
    }
    $device['pingable'] = $ping_response['result'];
    $ping_time = $ping_response['last_ping_timetaken'];
    $response = array();
    $status_reason = '';
    if ($device['pingable']) {
        $device['snmpable'] = isSNMPable($device);
        if ($device['snmpable']) {
            $status = '1';
            $response['status_reason'] = '';
        } else {
            echo 'SNMP Unreachable';
            $status = '0';
            $response['status_reason'] = 'snmp';
        }
    } else {
        echo 'Unpingable';
        $status = '0';
        $response['status_reason'] = 'icmp';
    }
    if ($device['status'] != $status) {
        $poll_update .= $poll_separator . "`status` = '{$status}'";
        $poll_separator = ', ';
        dbUpdate(array('status' => $status, 'status_reason' => $response['status_reason']), 'devices', 'device_id=?', array($device['device_id']));
        dbInsert(array('importance' => '0', 'device_id' => $device['device_id'], 'message' => 'Device is ' . ($status == '1' ? 'up' : 'down')), 'alerts');
        log_event('Device status changed to ' . ($status == '1' ? 'Up' : 'Down'), $device, $status == '1' ? 'up' : 'down');
    }
    if ($status == '1') {
        $graphs = array();
        $oldgraphs = array();
        if ($options['m']) {
            foreach (explode(',', $options['m']) as $module) {
                if (is_file('includes/polling/' . $module . '.inc.php')) {
                    include 'includes/polling/' . $module . '.inc.php';
                }
            }
        } else {
            foreach ($config['poller_modules'] as $module => $module_status) {
                if ($attribs['poll_' . $module] || $module_status && !isset($attribs['poll_' . $module])) {
                    // TODO per-module polling stats
                    include 'includes/polling/' . $module . '.inc.php';
                } else {
                    if (isset($attribs['poll_' . $module]) && $attribs['poll_' . $module] == '0') {
                        echo "Module [ {$module} ] disabled on host.\n";
                    } else {
                        echo "Module [ {$module} ] disabled globally.\n";
                    }
                }
            }
        }
        //end if
        if (!$options['m']) {
            // FIXME EVENTLOGGING -- MAKE IT SO WE DO THIS PER-MODULE?
            // This code cycles through the graphs already known in the database and the ones we've defined as being polled here
            // If there any don't match, they're added/deleted from the database.
            // Ideally we should hold graphs for xx days/weeks/polls so that we don't needlessly hide information.
            foreach (dbFetch('SELECT `graph` FROM `device_graphs` WHERE `device_id` = ?', array($device['device_id'])) as $graph) {
                if (isset($graphs[$graph['graph']])) {
                    $oldgraphs[$graph['graph']] = true;
                } else {
                    dbDelete('device_graphs', '`device_id` = ? AND `graph` = ?', array($device['device_id'], $graph['graph']));
                }
            }
            foreach ($graphs as $graph => $value) {
                if (!isset($oldgraphs[$graph])) {
                    echo '+';
                    dbInsert(array('device_id' => $device['device_id'], 'graph' => $graph), 'device_graphs');
                }
                echo $graph . ' ';
            }
        }
        //end if
        $device_end = utime();
        $device_run = $device_end - $device_start;
        $device_time = substr($device_run, 0, 5);
        // TODO: These should be easy converts to rrd_create_update()
        // Poller performance rrd
        $poller_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/poller-perf.rrd';
        if (!is_file($poller_rrd)) {
            rrdtool_create($poller_rrd, 'DS:poller:GAUGE:600:0:U ' . $config['rrd_rra']);
        }
        if (!empty($device_time)) {
            $fields = array('poller' => $device_time);
            rrdtool_update($poller_rrd, $fields);
        }
        // Ping response rrd
        if (can_ping_device($attribs) === true) {
            $ping_rrd = $config['rrd_dir'] . '/' . $device['hostname'] . '/ping-perf.rrd';
            if (!is_file($ping_rrd)) {
                rrdtool_create($ping_rrd, 'DS:ping:GAUGE:600:0:65535 ' . $config['rrd_rra']);
            }
            if (!empty($ping_time)) {
                $fields = array('ping' => $ping_time);
                rrdtool_update($ping_rrd, $fields);
            }
            $update_array['last_ping'] = array('NOW()');
            $update_array['last_ping_timetaken'] = $ping_time;
        }
        $update_array['last_polled'] = array('NOW()');
        $update_array['last_polled_timetaken'] = $device_time;
        // echo("$device_end - $device_start; $device_time $device_run");
        echo "Polled in {$device_time} seconds\n";
        d_echo('Updating ' . $device['hostname'] . "\n");
        d_echo($update_array);
        $updated = dbUpdate($update_array, 'devices', '`device_id` = ?', array($device['device_id']));
        if ($updated) {
            echo "UPDATED!\n";
        }
        unset($storage_cache);
        // Clear cache of hrStorage ** MAYBE FIXME? **
        unset($cache);
        // Clear cache (unify all things here?)
    }
    //end if
}
Esempio n. 29
0
                if ($mac != $old_mac && $mac != '') {
                    d_echo("Changed mac address for {$ip} from {$old_mac} to {$mac}\n");
                    log_event("MAC change: {$ip} : " . mac_clean_to_readable($old_mac) . ' -> ' . mac_clean_to_readable($mac), $device, 'interface', $port_id);
                    dbUpdate(array('mac_address' => $mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', array($port_id, $ip, $context));
                }
                d_echo(null, '.');
            } elseif (isset($interface['port_id'])) {
                d_echo(null, '+');
                $insert_data[] = array('port_id' => $port_id, 'mac_address' => $mac, 'ipv4_address' => $ip, 'context_name' => $context);
            }
        }
    }
    // add new entries
    if (!empty($insert_data)) {
        dbBulkInsert($insert_data, 'ipv4_mac');
    }
    // remove stale entries
    foreach ($existing_data as $entry) {
        $entry_mac = $entry['mac_address'];
        $entry_if = $entry['port_id'];
        $entry_ip = $entry['ipv4_address'];
        if ($arp_table[$entry_if][$entry_ip] != $entry_mac) {
            dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address`=? AND `ipv4_address`=? AND `context_name`=?', array($entry_if, $entry_mac, $entry_ip, $context));
            d_echo(null, '-');
        }
    }
    echo PHP_EOL;
    unset($existing_data, $arp_table, $insert_data, $sql, $params, $context);
    unset($device['context_name']);
}
unset($vrfs_lite_cisco);
Esempio n. 30
0
                     break;
                 }
                 $rows += $iter;
                 $i--;
             }
         }
         print_debug("Timing housekeeping: deleted {$rows} entries (per-device)");
         logfile("housekeeping.log", "Timing: deleted {$rows} entries older than " . format_unixtime($cutoff) . " (per-device)");
         $rows = dbDelete('perf_times', $where);
         if ($rows === FALSE) {
             // Use LIMIT with big tables
             print_debug("Performance table (per-run) is too big, using LIMIT for delete entries");
             $rows = 0;
             $i = 1000;
             while ($i && $rows < $count_run) {
                 $iter = dbDelete('perf_times', $where . ' LIMIT 1000000');
                 if ($iter === FALSE) {
                     break;
                 }
                 $rows += $iter;
                 $i--;
             }
         }
         print_debug("Timing housekeeping: deleted {$rows} entries (per-run)");
         logfile("housekeeping.log", "Timing: deleted {$rows} entries older than " . format_unixtime($cutoff) . " (per-run)");
     }
 } else {
     if ($prompt) {
         print_message("No perfomance entries found older than " . format_unixtime($cutoff));
     }
 }