/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage functions
 * @author     Adam Armstrong <*****@*****.**>
 * @copyright  (C) 2006-2014 Adam Armstrong
 *
 */
function get_entity_by_id_cache($type, $id)
{
    global $cache;
    if ($type !== 'port') {
        list($entity_table, $entity_id_field, $entity_name_field) = entity_type_translate($type);
    }
    if (is_array($cache[$type][$id])) {
        return $cache[$type][$id];
    } else {
        switch ($type) {
            case "port":
                $entity = get_port_by_id($id);
                break;
            default:
                $entity = dbFetchRow("SELECT * FROM `" . $entity_table . "` WHERE `" . $entity_id_field . "` = ?", array($id));
                if (function_exists('humanize_' . $type)) {
                    $do = 'humanize_' . $type;
                    $do($entity);
                }
                break;
        }
        if (is_array($entity)) {
            entity_rewrite($type, $entity);
            $cache[$type][$id] = $entity;
            return $entity;
        }
    }
    return FALSE;
}
function get_entity_by_id_cache($entity_type, $entity_id)
{
    global $cache;
    $translate = entity_type_translate_array($entity_type);
    if (is_array($cache[$entity_type][$entity_id])) {
        return $cache[$entity_type][$entity_id];
    } else {
        switch ($entity_type) {
            case "port":
                $entity = get_port_by_id($entity_id);
                break;
            default:
                $entity = dbFetchRow("SELECT * FROM `" . $translate['table'] . "` WHERE `" . $translate['id_field'] . "` = ?", array($entity_id));
                if (function_exists('humanize_' . $entity_type)) {
                    $do = 'humanize_' . $entity_type;
                    $do($entity);
                } elseif (isset($translate['humanize_function']) && function_exists('humanize_' . $translate['humanize_function'])) {
                    $do = 'humanize_' . $translate['humanize_function'];
                    $do($entity);
                }
                break;
        }
        if (is_array($entity)) {
            entity_rewrite($entity_type, $entity);
            $cache[$entity_type][$entity_id] = $entity;
            return $entity;
        }
    }
    return FALSE;
}
Example #3
0
/**
 * Fetch all info about a Proxmox VM
 * @param integer $vmid Proxmox VM ID
 * @param string $c Clustername
 * @return array An array with all info of this VM on this cluster, including ports
 */
function proxmox_vm_info($vmid, $c)
{
    $vm = dbFetchRow("SELECT pm.*, d.hostname AS host, d.device_id FROM proxmox pm, devices d WHERE pm.device_id = d.device_id AND pm.vmid = ? AND pm.cluster = ?", array($vmid, $c));
    $appid = dbFetchRow("SELECT app_id FROM applications WHERE device_id = ? AND app_type = ?", array($vm['device_id'], 'proxmox'));
    $vm['ports'] = dbFetchRows("SELECT * FROM proxmox_ports WHERE vm_id = ?", array($vm['id']));
    $vm['app_id'] = $appid['app_id'];
    return $vm;
}
Example #4
0
/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package        observium
 * @subpackage     functions
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
function get_customoid_by_id($oid_id)
{
    if (is_numeric($oid_id)) {
        $oid = dbFetchRow('SELECT * FROM `oids` WHERE `oid_id` = ?', array($oid_id));
    }
    if (count($oid)) {
        return $oid;
    } else {
        return FALSE;
    }
}
Example #5
0
/**
 * Check if a Proxmox VM exists
 * @param integer $i VM ID
 * @param string  $c Clustername
 * @param array   $pmxcache Reference to the Proxmox VM Cache
 * @return boolean true if the VM exists, false if it doesn't
 */
function proxmox_vm_exists($i, $c, &$pmxcache)
{
    if (isset($pmxcache[$c][$i]) && $pmxcache[$c][$i] > 0) {
        return true;
    }
    if ($row = dbFetchRow("SELECT id FROM proxmox WHERE vmid = ? AND cluster = ?", array($i, $c))) {
        $pmxcache[$c][$i] = (int) $row['id'];
        return true;
    }
    return false;
}
Example #6
0
function get_alert_test_by_id($alert_test_id)
{
    if (is_numeric($alert_test_id)) {
        $alert_test = dbFetchRow('SELECT * FROM `alert_tests` WHERE `alert_test_id` = ?', array($alert_test_id));
    }
    if (is_array($alert_test) && count($alert_test)) {
        return $alert_test;
    } else {
        return FALSE;
    }
}
function get_port_stats_by_port_hostname()
{
    // This will return port stats based on a devices hostname and ifName
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $ifName = urldecode($router['ifname']);
    $stats = dbFetchRow("SELECT * FROM `ports` WHERE `ifName`=?", array($ifName));
    $output = array("status" => "ok", "port" => $stats);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Example #8
0
File: db.php Project: OTTO11/db
function super_query($q, $m = false)
{
    $q = query($q);
    global $qNum;
    $qNum++;
    if (!$m) {
        return dbFetchRow($q);
    }
    $r = array();
    while ($e = dbFetchRow($q)) {
        $r[] = $e;
    }
    return $r;
}
function getOrderAmount($orderId)
{
    $orderAmount = 0;
    $sql = "SELECT SUM(pd_price * od_qty)\r\n\t        FROM tbl_order_item oi, tbl_product p \r\n\t\t    WHERE oi.pd_id = p.pd_id and oi.od_id = {$orderId}\r\n\t\t\t\r\n\t\t\tUNION\r\n\t\t\t\r\n\t\t\tSELECT od_shipping_cost \r\n\t\t\tFROM tbl_order\r\n\t\t\tWHERE od_id = {$orderId}";
    $result = dbQuery($sql);
    if (dbNumRows($result) == 2) {
        $row = dbFetchRow($result);
        $totalPurchase = $row[0];
        $row = dbFetchRow($result);
        $shippingCost = $row[0];
        $orderAmount = $totalPurchase + $shippingCost;
    }
    return $orderAmount;
}
Example #10
0
/**
 * Check username against CAS authentication backend. User needs to exist in MySQL to be able to log in.
 *
 * @param string $username User name to check
 * @param string $password User password to check
 * @return int Authentication success (0 = fail, 1 = success) FIXME bool
 */
function cas_authenticate($username, $password)
{
    $row = dbFetchRow("SELECT `username`, `password` FROM `users` WHERE `username`= ?", array($username));
    if ($row['username'] && $row['username'] == $username) {
        if ($username == phpCAS::getUser()) {
            return 1;
        }
        dbInsert(array('user' => $_SESSION['username'], 'address' => $_SERVER["REMOTE_ADDR"], 'result' => 'CAS: username does not match CAS user'), 'authlog');
    } else {
        dbInsert(array('user' => $_SESSION['username'], 'address' => $_SERVER["REMOTE_ADDR"], 'result' => 'CAS: NOT found in DB'), 'authlog');
    }
    //session_logout();
    return 0;
}
Example #11
0
function get_port_stats_by_port_hostname()
{
    // This will return port stats based on a devices hostname and ifName
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $hostname = $router['hostname'];
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    $ifName = urldecode($router['ifname']);
    $stats = dbFetchRow('SELECT * FROM `ports` WHERE `device_id`=? AND `ifName`=?', array($device_id, $ifName));
    $output = array('status' => 'ok', 'port' => $stats);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Example #12
0
function authenticate($username, $password)
{
    global $config;
    if (isset($_SERVER['REMOTE_USER'])) {
        $_SESSION['username'] = mres($_SERVER['REMOTE_USER']);
        $row = @dbFetchRow("SELECT username FROM `users` WHERE `username`=?", array($_SESSION['username']));
        if (isset($row['username']) && $row['username'] == $_SESSION['username']) {
            return 1;
        } else {
            $_SESSION['username'] = $config['http_auth_guest'];
            return 1;
        }
    }
    return 0;
}
Example #13
0
/**
 * Check user permission to access the bill
 *
 * @return boolean
 * @param  bill_id
 *
*/
function api_bill_permitted($bill_id)
{
    global $vars;
    $res = false;
    if ($vars['user']['level'] >= 10) {
        $res = true;
    } else {
        api_show_debug("Checking permission for bill", $bill_id);
        $row = dbFetchRow("SELECT * FROM `entity_permissions` WHERE `entity_type` = 'bill' AND `user_id` = ? AND `entity_id`= ? LIMIT 1", array($vars['user']['id'], $bill_id));
        if (is_array($row)) {
            $res = true;
        }
    }
    api_show_debug("Returned bill permitted", $res);
    return $res;
}
Example #14
0
 public function getComponentType($TYPE = null)
 {
     if (is_null($TYPE)) {
         $SQL = "SELECT DISTINCT `type` as `name` FROM `component` ORDER BY `name`";
         $row = dbFetchRow($SQL, array());
     } else {
         $SQL = "SELECT DISTINCT `type` as `name` FROM `component` WHERE `type` = ? ORDER BY `name`";
         $row = dbFetchRow($SQL, array($TYPE));
     }
     if (!isset($row)) {
         // We didn't find any component types
         return false;
     } else {
         // We found some..
         return $row;
     }
 }
Example #15
0
function mysql_query($query, $multi = false){
	global $inited_mysql, $mysql_iid;

	if(!$inited_mysql){
		new_db_decl();
		dbQuery("SET NAMES 'utf8'");
		$inited_mysql = true;
	}

	$db = dbQuery($query);

	$mysql_iid = dbInsertedId();

	if($multi){
		$data = array();
		while ($row = dbFetchRow($db)) $data[] = $row;
		return $data;
	}else return dbFetchRow($db);
}
Example #16
0
function authenticate($username, $password)
{
    $encrypted_old = md5($password);
    $row = dbFetchRow("SELECT username,password FROM `users` WHERE `username`= ?", array($username));
    if ($row['username'] && $row['username'] == $username) {
        // Migrate from old, unhashed password
        if ($row['password'] == $encrypted_old) {
            $row = dbFetchRow("DESCRIBE users password");
            if ($row['Type'] == 'varchar(34)') {
                changepassword($username, $password);
            }
            return 1;
        }
        if ($row['password'] == crypt($password, $row['password'])) {
            return 1;
        }
    }
    return 0;
}
Example #17
0
function mysql_authenticate($username, $password)
{
    $encrypted_old = md5($password);
    $row = dbFetchRow("SELECT `username`, `password` FROM `users` WHERE `username`= ?", array($username));
    if ($row['username'] && $row['username'] == $username) {
        // Migrate from old, unhashed password
        if ($row['password'] == $encrypted_old) {
            $row = dbFetchRow("DESCRIBE `users` `password`");
            if ($row['Type'] == 'varchar(34)') {
                mysql_auth_change_password($username, $password);
            }
            return 1;
        }
        if ($row['password'] == crypt($password, $row['password'])) {
            return 1;
        }
    }
    session_logout();
    return 0;
}
Example #18
0
function get_port_stats_by_port_hostname()
{
    // This will return port stats based on a devices hostname and ifName
    global $config;
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $hostname = $router['hostname'];
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    $ifName = urldecode($router['ifname']);
    $port = dbFetchRow('SELECT * FROM `ports` WHERE `device_id`=? AND `ifName`=?', array($device_id, $ifName));
    $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8);
    $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8);
    $port['in_perc'] = @round($port['in_rate'] / $port['ifSpeed'] * 100);
    $port['out_perc'] = @round($port['in_rate'] / $port['ifSpeed'] * 100);
    $port['in_pps'] = format_bi($port['ifInUcastPkts_rate']);
    $port['out_pps'] = format_bi($port['ifOutUcastPkts_rate']);
    $output = array('status' => 'ok', 'port' => $port);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Example #19
0
/**
 * Display device inventory hierarchy.
 *
 * @param string $ent, $level, $class
 * @return none
 *
 */
function print_ent_physical($ent, $level, $class)
{
    global $device;
    $ents = dbFetchRows("SELECT * FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalContainedIn` = ? ORDER BY `entPhysicalContainedIn`, `entPhysicalIndex`", array($device['device_id'], $ent));
    foreach ($ents as $ent) {
        $link = '';
        $text = " <li class='{$class}'>";
        /*
        Currently no icons for:
        
        JUNIPER-MIB::jnxFruType.10.1.1.0 = INTEGER: frontPanelModule(8)
        JUNIPER-MIB::jnxFruType.12.1.0.0 = INTEGER: controlBoard(5)
        
        For Geist RCX, IPOMan:
        outlet
        relay
        */
        switch ($ent['entPhysicalClass']) {
            case 'chassis':
                $text .= '<i class="oicon-database"></i> ';
                break;
            case 'module':
            case 'portInterfaceCard':
                $text .= '<i class="oicon-drive"></i> ';
                break;
            case 'port':
                $text .= '<i class="oicon-network-ethernet"></i> ';
                break;
            case 'container':
            case 'flexiblePicConcentrator':
                $text .= '<i class="oicon-box-zipper"></i> ';
                break;
            case 'stack':
                $text .= '<i class="oicon-databases"></i> ';
                break;
            case 'fan':
            case 'airflowSensor':
                $text .= '<i class="oicon-weather-wind"></i> ';
                break;
            case 'powerSupply':
            case 'powerEntryModule':
                $text .= '<i class="oicon-plug"></i> ';
                break;
            case 'backplane':
                $text .= '<i class="oicon-zones"></i> ';
                break;
            case 'sensor':
                $text .= '<i class="oicon-asterisk"></i> ';
                $sensor = dbFetchRow("SELECT * FROM `sensors` AS S\n                             LEFT JOIN `sensors-state` AS ST ON S.`sensor_id` = ST.`sensor_id`\n                             WHERE `device_id` = ? AND (`entPhysicalIndex` = ? OR `sensor_index` = ?)", array($device['device_id'], $ent['entPhysicalIndex'], $ent['entPhysicalIndex']));
                break;
            default:
                $text .= '<i class="oicon-chain"></i> ';
        }
        if ($ent['entPhysicalParentRelPos'] > '-1') {
            $text .= '<strong>' . $ent['entPhysicalParentRelPos'] . '.</strong> ';
        }
        $ent_text = '';
        if ($ent['ifIndex']) {
            $interface = get_port_by_ifIndex($device['device_id'], $ent['ifIndex']);
            $ent['entPhysicalName'] = generate_port_link($interface);
        }
        if ($ent['entPhysicalModelName'] && $ent['entPhysicalName']) {
            $ent_text .= "<strong>" . $ent['entPhysicalModelName'] . "</strong> (" . $ent['entPhysicalName'] . ")";
        } elseif ($ent['entPhysicalModelName']) {
            $ent_text .= "<strong>" . $ent['entPhysicalModelName'] . "</strong>";
        } elseif (is_numeric($ent['entPhysicalName']) && $ent['entPhysicalVendorType']) {
            $ent_text .= "<strong>" . $ent['entPhysicalName'] . " " . $ent['entPhysicalVendorType'] . "</strong>";
        } elseif ($ent['entPhysicalName']) {
            $ent_text .= "<strong>" . $ent['entPhysicalName'] . "</strong>";
        } elseif ($ent['entPhysicalDescr']) {
            $ent_text .= "<strong>" . $ent['entPhysicalDescr'] . "</strong>";
        }
        $ent_text .= "<br /><div class='small' style='margin-left: 20px;'>" . $ent['entPhysicalDescr'];
        if ($ent['entPhysicalClass'] == "sensor" && $sensor['sensor_value']) {
            $ent_text .= ' (' . $sensor['sensor_value'] . ' ' . $sensor['sensor_class'] . ')';
            $link = generate_entity_link('sensor', $sensor, $ent_text, NULL, FALSE);
        }
        $text .= $link ? $link : $ent_text;
        if ($ent['entPhysicalSerialNum']) {
            $text .= ' <span class="text-info">[Serial: ' . $ent['entPhysicalSerialNum'] . ']</span> ';
        }
        $text .= "</div>";
        echo $text;
        $count = dbFetchCell("SELECT COUNT(*) FROM `entPhysical` WHERE `device_id` = ? AND `entPhysicalContainedIn` = ?", array($device['device_id'], $ent['entPhysicalIndex']));
        if ($count) {
            echo "<ul>";
            print_ent_physical($ent['entPhysicalIndex'], $level + 1, '');
            echo "</ul>";
        }
        echo "</li>";
    }
}
Example #20
0
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage graphs
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
 *
 */
if (is_numeric($vars['id'])) {
    $sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($vars['id']));
    if (is_numeric($sensor['device_id']) && ($auth || is_entity_permitted($sensor['sensor_id'], 'sensor') || device_permitted($sensor['device_id']))) {
        $device = device_by_id_cache($sensor['device_id']);
        $rrd_filename = get_rrd_path($device, get_sensor_rrd($device, $sensor));
        $title = generate_device_link($device);
        $title .= " :: Sensors :: ";
        $auth = TRUE;
    }
}
// EOF
Example #21
0
        if ($override_sysLocation_bool) {
            $override_sysLocation = 1;
        } else {
            $override_sysLocation = 0;
        }
        dbUpdate(array('override_sysLocation' => $override_sysLocation), 'devices', '`device_id`=?', array($device['device_id']));
        if (isset($override_sysLocation_string)) {
            dbUpdate(array('location' => $override_sysLocation_string), 'devices', '`device_id`=?', array($device['device_id']));
        }
        #FIXME needs more sanity checking! and better feedback
        $param = array('purpose' => $_POST['descr'], 'type' => $_POST['type'], 'ignore' => $_POST['ignore'], 'disabled' => $_POST['disabled']);
        $rows_updated = dbUpdate($param, 'devices', '`device_id` = ?', array($device['device_id']));
        if ($rows_updated > 0 || $updated) {
            $update_message = "Device record updated.";
            $updated = 1;
            $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device['device_id']));
        } elseif ($rows_updated = '-1') {
            $update_message = "Device record unchanged. No update necessary.";
            $updated = -1;
        } else {
            $update_message = "Device record update error.";
        }
    } else {
        include 'includes/error-no-perm.inc.php';
    }
}
$descr = $device['purpose'];
$override_sysLocation = $device['override_sysLocation'];
$override_sysLocation_string = $device['location'];
if ($updated && $update_message) {
    print_message($update_message);
/**
 * Find contacts for alert
 * @param array $results Rule-Result
 * @return array
 */
function GetContacts($results)
{
    global $config;
    if (sizeof($results) == 0) {
        return array();
    }
    if ($config['alerts']['email']['default_only']) {
        return array($config['alerts']['email']['default'] => 'NOC');
    }
    $contacts = array();
    $uids = array();
    foreach ($results as $result) {
        $tmp = NULL;
        if (is_numeric($result["port_id"])) {
            $tmpa = dbFetchRows("SELECT user_id FROM ports_perms WHERE access_level >= 0 AND port_id = ?", array($result["port_id"]));
            foreach ($tmpa as $tmp) {
                $uids[$tmp['user_id']] = $tmp['user_id'];
            }
        }
        if (is_numeric($result["device_id"])) {
            $tmpa = dbFetchRow("SELECT sysContact FROM devices WHERE device_id = ?", array($result["device_id"]));
            $contacts[$tmpa["sysContact"]] = "NOC";
            $tmpa = dbFetchRows("SELECT user_id FROM devices_perms WHERE access_level >= 0 AND device_id = ?", array($result["device_id"]));
            foreach ($tmpa as $tmp) {
                $uids[$tmp['user_id']] = $tmp['user_id'];
            }
        }
    }
    if ($config["alert"]["globals"]) {
        $tmpa = dbFetchRows("SELECT realname,email FROM users WHERE level >= 5 AND level < 10");
        foreach ($tmpa as $tmp) {
            $contacts[$tmp['email']] = $tmp['realname'];
        }
    }
    if ($config["alert"]["admins"]) {
        $tmpa = dbFetchRows("SELECT realname,email FROM users WHERE level = 10");
        foreach ($tmpa as $tmp) {
            $contacts[$tmp['email']] = $tmp['realname'];
        }
    }
    if (is_array($uids)) {
        foreach ($uids as $uid) {
            $tmp = dbFetchRow("SELECT realname,email FROM users WHERE user_id = ?", array($uid));
            $contacts[$tmp['email']] = $tmp['realname'];
        }
    }
    return $contacts;
}
Example #23
0
function ip_exists($ip)
{
    // Function to check if an IP exists in the DB already
    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== FALSE) {
        if (!dbFetchRow("SELECT `ipv6_address_id` FROM `ipv6_addresses` WHERE `ipv6_address` = ? OR `ipv6_compressed` = ?", array($ip, $ip))) {
            return false;
        }
    } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== FALSE) {
        if (!dbFetchRow("SELECT `ipv4_address_id` FROM `ipv4_addresses` WHERE `ipv4_address` = ?", array($ip))) {
            return false;
        }
    } else {
        return false;
    }
    return true;
}
         echo ">Normal User</option>\n        <option value='5'";
         if ($vars['new_level'] == '5') {
             echo "selected";
         }
         echo ">Global Read</option>\n        <option value='10'";
         if ($vars['new_level'] == '10') {
             echo "selected";
         }
         echo ">Administrator</option>\n      </select>\n    </div>\n    <div class='col-sm-6'>\n    </div>\n  </div>\n  <div class='form-group'>\n    <div class='col-sm-6'>\n      <div class='checkbox'>\n        <label>\n          <input type='checkbox' ";
         if ($vars['can_modify_passwd'] == '1') {
             echo "checked='checked'";
         }
         echo " name='can_modify_passwd'> Allow the user to change his password.\n        </label>\n      </div>\n    </div>\n    <div class='col-sm-6'>\n    </div>\n  </div>\n  <button type='submit' class='btn btn-default'>Update User</button>\n  </form>";
         if ($config['twofactor']) {
             echo "<br/><div class='well'><h3>Two-Factor Authentication</h3>";
             $twofactor = dbFetchRow("SELECT twofactor FROM users WHERE user_id = ?", array($vars['user_id']));
             $twofactor = json_decode($twofactor['twofactor'], true);
             if ($twofactor['fails'] >= 3 && (!$config['twofactor_lock'] || time() - $twofactor['last'] < $config['twofactor_lock'])) {
                 echo "<form class='form-horizontal' role='form' method='post' action=''>\n  <input type='hidden' name='user_id' value='" . $vars['user_id'] . "'>\n  <input type='hidden' name='edit' value='yes'>\n  <div class='form-group'>\n    <label for='twofactorunlock' class='col-sm-2 control-label'>User exceeded failures</label>\n    <input type='hidden' name='twofactorunlock' value='1'>\n    <button type='submit' class='btn btn-default'>Unlock</button>\n  </div>\n</form>";
             }
             if ($twofactor['key']) {
                 echo "<form class='form-horizontal' role='form' method='post' action=''>\n  <input type='hidden' name='user_id' value='" . $vars['user_id'] . "'>\n  <input type='hidden' name='edit' value='yes'>\n  <input type='hidden' name='twofactorremove' value='1'>\n  <button type='submit' class='btn btn-danger'>Disable TwoFactor</button>\n</form>\n</div>";
             } else {
                 echo "<p>No TwoFactor key generated for this user, Nothing to do.</p>";
             }
         }
     } else {
         echo print_error("Error getting user details");
     }
 } else {
     echo print_error("Authentication method doesn't support updating users");
<?php

/*
 * LibreNMS
 *
 * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.  Please see LICENSE.txt at the top level of
 * the source code distribution for details.
 */
if (is_admin() === false) {
    header('Content-type: text/plain');
    die('ERROR: You need to be admin');
}
$alert_id = $_POST['alert_id'];
if (is_numeric($alert_id) && $alert_id > 0) {
    $rule = dbFetchRow('SELECT * FROM `alert_rules` WHERE `id` = ? LIMIT 1', array($alert_id));
    $rule_split = preg_split('/([a-zA-Z0-9_\\-\\.\\=\\%\\<\\>\\ \\"\'\\!\\~\\(\\)\\*\\/\\@\\|]+[&&|\\|\\|]{2})/', $rule['rule'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    $count = count($rule_split) - 1;
    $rule_split[$count] = $rule_split[$count] . '  &&';
    $output = array('severity' => $rule['severity'], 'extra' => $rule['extra'], 'name' => $rule['name'], 'proc' => $rule['proc'], 'rules' => $rule_split);
    header('Content-type: application/json');
    echo _json_encode($output);
}
Example #26
0
     case 'prefixes_ipv4multicast':
     case 'prefixes_ipv4vpn':
     case 'prefixes_ipv6unicast':
     case 'prefixes_ipv6multicast':
         list(, $afisafi) = explode('_', $vars['graph']);
         if (isset($peer['afisafi'][$afisafi])) {
             $peer['graph'] = 1;
         }
     case 'updates':
         $graph_array['type'] = 'bgp_' . $vars['graph'];
         $graph_array['id'] = $peer['bgpPeer_id'];
 }
 switch ($vars['graph']) {
     case 'macaccounting_bits':
     case 'macaccounting_pkts':
         $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', array($peer['bgpPeerIdentifier']));
         $database = $config['rrd_dir'] . '/' . $device['hostname'] . '/cip-' . $acc['ifIndex'] . '-' . $acc['mac'] . '.rrd';
         if (is_array($acc) && is_file($database)) {
             $peer['graph'] = 1;
             $graph_array['id'] = $acc['ma_id'];
             $graph_array['type'] = $vars['graph'];
         }
 }
 if ($vars['graph'] == 'updates') {
     $peer['graph'] = 1;
 }
 if ($peer['graph']) {
     $graph_array['height'] = '100';
     $graph_array['width'] = '218';
     $graph_array['to'] = $config['time']['now'];
     echo '<tr></tr><tr class="bgp"' . ($bg_image ? ' background="' . $bg_image . '"' : '') . '"><td colspan="9">';
Example #27
0
                $vlan_data = snmpwalk_cache_oid($vlan_device, "dot1dStpPortEntry", array(), "BRIDGE-MIB:Q-BRIDGE-MIB");
                $vlan_data = snmpwalk_cache_oid($vlan_device, "dot1dBasePortEntry", $vlan_data, "BRIDGE-MIB:Q-BRIDGE-MIB");
            }
            echo "VLAN {$vlan_id} \n";
            if ($vlan_data) {
                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])) {
Example #28
0
function dbFetchCell($sql, $parameters = array(), $nocache = false)
{
    global $db_stats, $config;
    $time_start = microtime(true);
    $row = dbFetchRow($sql, $parameters, $nocache);
    if ($row) {
        return array_shift($row);
        // shift first field off first row
    }
    $time_end = microtime(true);
    $db_stats['fetchcell_sec'] += number_format($time_end - $time_start, 8);
    $db_stats['fetchcell']++;
    return null;
}
Example #29
0
function get_config_by_name($name)
{
    $config_item = dbFetchRow('SELECT * FROM `config` WHERE `config_name` = ?', array($name));
    return $config_item;
}
Example #30
0
         echo ' <span class="label">' . $pseudowire['pw_psntype'] . '</span>';
         echo ' <span class="label">' . $pseudowire['pw_type'] . '</span>';
         $br = "<br />";
     }
 }
 if (!isset($ports_has_ext['ports_pagp']) || in_array($port['ifIndex'], $ports_has_ext['ports_pagp'])) {
     foreach (dbFetchRows("SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? AND `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $member) {
         humanize_port($member);
         $pagp[$device['device_id']][$port['ifIndex']][$member['ifIndex']] = TRUE;
         echo $br . '<i class="oicon-arrow-join"></i> <strong>' . generate_port_link($member) . ' [PAgP]</strong>';
         $br = "<br />";
     }
 }
 if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) {
     $pagp[$device['device_id']][$port['pagpGroupIfIndex']][$port['ifIndex']] = TRUE;
     $parent = dbFetchRow("SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?", array($port['pagpGroupIfIndex'], $device['device_id']));
     humanize_port($parent);
     echo $br . '<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($parent) . ' [PAgP]</strong>';
     $br = "<br />";
 }
 if (!isset($ports_has_ext['ports_stack_low']) || in_array($port['ifIndex'], $ports_has_ext['ports_stack_low'])) {
     foreach (dbFetchRows("SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?", array($port['ifIndex'], $device['device_id'])) as $higher_if) {
         if ($higher_if['port_id_high']) {
             if ($pagp[$device['device_id']][$higher_if['port_id_high']][$port['ifIndex']]) {
                 continue;
             }
             // Skip if same PAgP port
             $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']);
             if (is_array($this_port)) {
                 echo $br . '<i class="oicon-arrow-split"></i> <strong>' . generate_port_link($this_port) . '</strong>';
                 $br = "<br />";