function get_authlog_array($vars) { $array = array(); // Short authlog? (no pagination, small out) $array['short'] = isset($vars['short']) && $vars['short']; // With pagination? (display page numbers in header) $array['pagination'] = isset($vars['pagination']) && $vars['pagination']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $array['pageno'] = $vars['pageno']; $array['pagesize'] = $vars['pagesize']; $start = $array['pagesize'] * $array['pageno'] - $array['pagesize']; $pagesize = $array['pagesize']; $query = " FROM `authlog`"; $query_count = 'SELECT COUNT(`id`) ' . $query; $query_updated = 'SELECT MAX(`datetime`) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY `datetime` DESC '; $query .= "LIMIT {$start},{$pagesize}"; // Query authlog $array['entries'] = dbFetchRows($query, $param); // Query authlog count if ($array['pagination'] && !$array['short']) { $array['count'] = dbFetchCell($query_count, $param); $array['pagination_html'] = pagination($vars, $array['count']); } else { $array['count'] = count($array['entries']); } // Query for last timestamp $array['updated'] = dbFetchCell($query_updated, $param); return $array; }
function get_cache($host, $value) { global $dev_cache; if (!isset($dev_cache[$host][$value])) { switch ($value) { case 'device_id': // Try by hostname $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ?', array($host, $host)); // If failed, try by IP if (!is_numeric($dev_cache[$host]['device_id'])) { $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id', array($host)); } break; case 'os': $dev_cache[$host]['os'] = dbFetchCell('SELECT `os` FROM devices WHERE `device_id` = ?', array(get_cache($host, 'device_id'))); break; case 'version': $dev_cache[$host]['version'] = dbFetchCell('SELECT `version` FROM devices WHERE `device_id`= ?', array(get_cache($host, 'device_id'))); break; default: return null; } //end switch } //end if return $dev_cache[$host][$value]; }
/** * Issue Alert-Object * @param array $alert * @return boolean */ function IssueAlert($alert) { global $config; if (dbFetchCell('SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = ?', array($alert['device_id'])) == '1') { return true; } $default_tpl = "%title\r\nSeverity: %severity\r\n{if %state == 0}Time elapsed: %elapsed\r\n{/if}Timestamp: %timestamp\r\nUnique-ID: %uid\r\nRule: {if %name}%name{else}%rule{/if}\r\n{if %faults}Faults:\r\n{foreach %faults} #%key: %value.string\r\n{/foreach}{/if}Alert sent to: {foreach %contacts}%value <%key> {/foreach}"; // FIXME: Put somewhere else? if ($config['alert']['fixed-contacts'] == false) { $alert['details']['contacts'] = GetContacts($alert['details']['rule']); } $obj = DescribeAlert($alert); if (is_array($obj)) { $tpl = dbFetchRow('SELECT `template` FROM `alert_templates` JOIN `alert_template_map` ON `alert_template_map`.`alert_templates_id`=`alert_templates`.`id` WHERE `alert_template_map`.`alert_rule_id`=?', array($alert['rule_id'])); if (isset($tpl['template'])) { $tpl = $tpl['template']; } else { $tpl = $default_tpl; } echo 'Issuing Alert-UID #' . $alert['id'] . '/' . $alert['state'] . ': '; $msg = FormatAlertTpl($tpl, $obj); $obj['msg'] = $msg; if (!empty($config['alert']['transports'])) { ExtTransports($obj); } echo "\r\n"; } return true; }
function get_instance_stats() { // Overall Ports/Devices statistics $stats['ports'] = dbFetchCell("SELECT COUNT(*) FROM ports"); $stats['devices'] = dbFetchCell("SELECT COUNT(*) FROM devices"); $stats['edition'] = OBSERVIUM_EDITION; // Per-feature statistics $stats['sensors'] = dbFetchCell("SELECT COUNT(*) FROM `sensors`"); $stats['services'] = dbFetchCell("SELECT COUNT(*) FROM `services`"); $stats['applications'] = dbFetchCell("SELECT COUNT(*) FROM `applications`"); $stats['bgp'] = dbFetchCell("SELECT COUNT(*) FROM `bgpPeers`"); $stats['ospf'] = dbFetchCell("SELECT COUNT(*) FROM `ospf_ports`"); $stats['eigrp'] = dbFetchCell("SELECT COUNT(*) FROM `eigrp_ports`"); $stats['ipsec_tunnels'] = dbFetchCell("SELECT COUNT(*) FROM `ipsec_tunnels`"); $stats['munin_plugins'] = dbFetchCell("SELECT COUNT(*) FROM `munin_plugins`"); $stats['pseudowires'] = dbFetchCell("SELECT COUNT(*) FROM `pseudowires`"); $stats['vrfs'] = dbFetchCell("SELECT COUNT(*) FROM `vrfs`"); $stats['vminfo'] = dbFetchCell("SELECT COUNT(*) FROM `vminfo`"); $stats['users'] = dbFetchCell("SELECT COUNT(*) FROM `users`"); $stats['bills'] = dbFetchCell("SELECT COUNT(*) FROM `bills`"); $stats['alerts'] = dbFetchCell("SELECT COUNT(*) FROM `alert_table`"); $stats['alert_tests'] = dbFetchCell("SELECT COUNT(*) FROM `alert_tests`"); $stats['slas'] = dbFetchCell("SELECT COUNT(*) FROM `slas`"); $stats['statuses'] = dbFetchCell("SELECT COUNT(*) FROM `status`"); $stats['groups'] = dbFetchCell("SELECT COUNT(*) FROM `groups`"); $stats['group_members'] = dbFetchCell("SELECT COUNT(*) FROM `group_table`"); $stats['poller_time'] = dbFetchCell("SELECT SUM(`last_polled_timetaken`) FROM devices"); $stats['discovery_time'] = dbFetchCell("SELECT SUM(`last_discovered_timetaken`) FROM devices"); $stats['php_version'] = phpversion(); $os_text = external_exec("DISTROFORMAT=export " . $GLOBALS['config']['install_dir'] . "/scripts/distro"); foreach (explode("\n", $os_text) as $part) { list($a, $b) = explode("=", $part); $stats['os'][$a] = $b; } // sysObjectID for Generic devices foreach (dbFetchRows("SELECT `sysObjectID`, COUNT(*) AS `count` FROM `devices` WHERE `os` = 'generic' GROUP BY `sysObjectID`") as $data) { $stats['generics'][$data['sysObjectID']] = $data['count']; } // Per-OS counts foreach (dbFetchRows("SELECT COUNT(*) AS `count`, `os` FROM `devices` GROUP BY `os`") as $data) { $stats['devicetypes'][$data['os']] = $data['count']; } // Per-type counts foreach (dbFetchRows("SELECT COUNT(*) AS `count`, `type` FROM `devices` GROUP BY `type`") as $data) { $stats['types'][$data['type']] = $data['count']; } // Per-apptype counts foreach (dbFetchRows("SELECT COUNT(*) AS `count`, `app_type` FROM `applications` GROUP BY `app_type`") as $data) { $stats['app_types'][$data['app_type']] = $data['count']; } $stats['misc']['max_len']['port_label'] = dbFetchCell("SELECT MAX(LENGTH(`port_label`)) FROM `ports`"); $stats['misc']['max_len']['port_label_short'] = dbFetchCell("SELECT MAX(LENGTH(`port_label_short`)) FROM `ports`"); $stats['misc']['max_len']['port_label_base'] = dbFetchCell("SELECT MAX(LENGTH(`port_label_base`)) FROM `ports`"); $stats['misc']['max_len']['port_label_num'] = dbFetchCell("SELECT MAX(LENGTH(`port_label_num`)) FROM `ports`"); $stats['version'] = OBSERVIUM_VERSION; $stats['uuid'] = get_unique_id(); return $stats; }
/** * Observium * * This file is part of Observium. * * @package observium * @subpackage poller * @copyright (C) 2006-2014 Adam Armstrong * */ function discover_service($device, $service) { if (!dbFetchCell("SELECT COUNT(service_id) FROM `services` WHERE `service_type`= ? AND `device_id` = ?", array($service, $device['device_id']))) { add_service($device, $service, "(自动发现) {$service}"); log_event("自动发现服务: 类型 {$service}", $device, 'service'); echo "+"; } echo "{$service} "; }
function discover_service($device, $service) { if (!dbFetchCell('SELECT COUNT(service_id) FROM `services` WHERE `service_type`= ? AND `device_id` = ?', array($service, $device['device_id']))) { add_service($device, $service, "(Auto discovered) {$service}"); log_event('Autodiscovered service: type ' . mres($service), $device, 'service'); echo '+'; } echo "{$service} "; }
function get_cache($host, $value) { global $dev_cache; $host = strtolower(trim($host)); // Check cache expiration $now = time(); $expired = TRUE; if (isset($dev_cache[$host]['lastchecked'])) { if ($now - $dev_cache[$host]['lastchecked'] < 3600) { $expired = FALSE; } // will expire after 1 hour } if ($expired) { $dev_cache[$host]['lastchecked'] = $now; } if (!isset($dev_cache[$host][$value]) || $expired) { switch ($value) { case 'device_id': // Try by hostname $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `hostname` = ? OR `sysName` = ?', array($host, $host)); // If failed, try by IP if (!is_numeric($dev_cache[$host]['device_id'])) { $ip = $host; $ip_version = get_ip_version($ip); if ($ip_version !== FALSE) { if ($ip_version == 6) { $ip = Net_IPv6::uncompress($ip, TRUE); } $address_count = dbFetchCell('SELECT COUNT(*) FROM `ipv' . $ip_version . '_addresses` WHERE `ipv' . $ip_version . '_address` = ?;', array($ip)); if ($address_count) { $query = 'SELECT `device_id` FROM `ipv' . $ip_version . '_addresses` AS A, `ports` AS I WHERE A.`ipv' . $ip_version . '_address` = ? AND I.`port_id` = A.`port_id`'; // If more than one IP address, also check the status of the port. if ($address_count > 1) { $query .= " AND I.`ifOperStatus` = 'up'"; } $dev_cache[$host]['device_id'] = dbFetchCell($query, array($ip)); } } } break; case 'os': case 'version': $dev_cache[$host][$value] = dbFetchCell('SELECT `' . $value . '` FROM `devices` WHERE `device_id` = ?', array(get_cache($host, 'device_id'))); break; case 'os_group': $os = get_cache($host, 'os'); $dev_cache[$host]['os_group'] = isset($GLOBALS['config']['os'][$os]['group']) ? $GLOBALS['config']['os'][$os]['group'] : ''; break; default: return NULL; } } return $dev_cache[$host][$value]; }
/** * Post notifications to users * @return null */ function post_notifications() { $notifs = get_notifications(); echo '[ ' . date('r') . ' ] Updating DB '; foreach ($notifs as $notif) { if (dbFetchCell('select 1 from notifications where checksum = ?', array($notif['checksum'])) != 1 && dbInsert('notifications', $notif) > 0) { echo '.'; } } echo ' Done'; echo PHP_EOL; }
/** * Get Data-Object * @param string $obj Name of Data-Object * @return mixed */ public function offsetGet($obj) { if (isset($this->data[$obj])) { if (isset($this->data[$obj]['value'])) { return $this->data[$obj]['value']; } elseif (isset($GLOBALS['_ObjCache'][$this->obj][$obj]['value'])) { return $GLOBALS['_ObjCache'][$this->obj][$obj]['value']; } else { $GLOBALS['_ObjCache'][$this->obj][$obj]['value'] = dbFetchCell($this->data[$obj]['query'], $this->data[$obj]['params']); return $GLOBALS['_ObjCache'][$this->obj][$obj]['value']; } } }
/** * Issue Alert-Object * @param array $alert * @return boolean */ function IssueAlert($alert) { global $config; if (dbFetchCell('SELECT attrib_value FROM devices_attribs WHERE attrib_type = "disable_notify" && device_id = ?', array($alert['device_id'])) == '1') { return true; } if ($config['alert']['fixed-contacts'] == false) { $alert['details']['contacts'] = GetContacts($alert['details']['rule']); } $obj = DescribeAlert($alert); if (is_array($obj)) { echo 'Issuing Alert-UID #' . $alert['id'] . '/' . $alert['state'] . ': '; $msg = FormatAlertTpl($obj); $obj['msg'] = $msg; if (!empty($config['alert']['transports'])) { ExtTransports($obj); } echo "\r\n"; } return true; }
function process_port_adsl(&$this_port, $device, $port) { // Check to make sure Port data is cached. if (!isset($this_port['adslLineCoding'])) { return; } // Used below for StatsD only $adsl_oids = array('adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAtucCurrAttainableRate', 'adslAtucChanCurrTxRate', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr', 'adslAturCurrAttainableRate', 'adslAturChanCurrTxRate', 'adslAtucPerfLofs', 'adslAtucPerfLoss', 'adslAtucPerfLprs', 'adslAtucPerfESs', 'adslAtucPerfInits', 'adslAturPerfLofs', 'adslAturPerfLoss', 'adslAturPerfLprs', 'adslAturPerfESs', 'adslAtucChanCorrectedBlks', 'adslAtucChanUncorrectBlks', 'adslAturChanCorrectedBlks', 'adslAturChanUncorrectBlks'); $adsl_db_oids = array('adslLineCoding', 'adslLineType', 'adslAtucInvVendorID', 'adslAtucInvVersionNumber', 'adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAtucCurrAttainableRate', 'adslAturInvSerialNumber', 'adslAturInvVendorID', 'adslAturInvVersionNumber', 'adslAtucChanCurrTxRate', 'adslAturChanCurrTxRate', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr', 'adslAturCurrAttainableRate'); $adsl_tenth_oids = array('adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr'); foreach ($adsl_tenth_oids as $oid) { if (isset($this_port[$oid])) { $this_port[$oid] = $this_port[$oid] / 10; } } if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = ?", array($port['port_id'])) == "0") { dbInsert(array('port_id' => $port['port_id']), 'ports_adsl'); } $adsl_update = array('port_adsl_updated' => array('NOW()')); foreach ($adsl_db_oids as $oid) { $adsl_update[$oid] = $this_port[$oid]; } dbUpdate($adsl_update, 'ports_adsl', '`port_id` = ?', array($port['port_id'])); if ($this_port['adslAtucCurrSnrMgn'] > "1280") { $this_port['adslAtucCurrSnrMgn'] = "U"; } if ($this_port['adslAturCurrSnrMgn'] > "1280") { $this_port['adslAturCurrSnrMgn'] = "U"; } rrdtool_update_ng($device, 'port-adsl', array('AtucCurrSnrMgn' => $this_port['adslAtucCurrSnrMgn'], 'AtucCurrAtn' => $this_port['adslAtucCurrAtn'], 'AtucCurrOutputPwr' => $this_port['adslAtucCurrOutputPwr'], 'AtucCurrAttainableR' => $this_port['adslAtucCurrAttainableR'], 'AtucChanCurrTxRate' => $this_port['adslAtucChanCurrTxRate'], 'AturCurrSnrMgn' => $this_port['adslAturCurrSnrMgn'], 'AturCurrAtn' => $this_port['adslAturCurrAtn'], 'AturCurrOutputPwr' => $this_port['adslAturCurrOutputPwr'], 'AturCurrAttainableR' => $this_port['adslAturCurrAttainableR'], 'AturChanCurrTxRate' => $this_port['adslAturChanCurrTxRate'], 'AtucPerfLofs' => $this_port['adslAtucPerfLofs'], 'AtucPerfLoss' => $this_port['adslAtucPerfLoss'], 'AtucPerfLprs' => $this_port['adslAtucPerfLprs'], 'AtucPerfESs' => $this_port['adslAtucPerfESs'], 'AtucPerfInits' => $this_port['adslAtucPerfInits'], 'AturPerfLofs' => $this_port['adslAturPerfLofs'], 'AturPerfLoss' => $this_port['adslAturPerfLoss'], 'AturPerfLprs' => $this_port['adslAturPerfLprs'], 'AturPerfESs' => $this_port['adslAturPerfESs'], 'AtucChanCorrectedBl' => $this_port['adslAtucChanCorrectedBl'], 'AtucChanUncorrectBl' => $this_port['adslAtucChanUncorrectBl'], 'AturChanCorrectedBl' => $this_port['adslAturChanCorrectedBl'], 'AturChanUncorrectBl' => $this_port['adslAturChanUncorrectBl']), get_port_rrdindex($port)); if ($GLOBALS['config']['statsd']['enable']) { foreach ($adsl_oids as $oid) { // Update StatsD/Carbon StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'port' . '.' . $port['ifIndex'] . '.' . $oid, $this_port[$oid]); } } //echo("ADSL (".$this_port['adslLineCoding']."/".formatRates($this_port['adslAtucChanCurrTxRate'])."/".formatRates($this_port['adslAturChanCurrTxRate']).")"); }
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);
} // Do Alerts at the bottom if ($bgp_alerts) { echo ' <li role="presentation" class="divider"></li> <li><a href="routing/protocol=bgp/adminstatus=start/state=down/"><img src="images/16/link_error.png" border="0" align="absmiddle" /> Alerted BGP (' . $bgp_alerts . ')</a></li> '; } echo ' </ul>'; ?> </li><!-- End 4 columns container --> <?php } $packages = dbFetchCell("SELECT COUNT(pkg_id) from `packages`"); if ($packages) { ?> <li class="dropdown"> <a href="<?php echo generate_url(array('page' => 'packages')); ?> " class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown"><img src="images/16/box.png" border="0" align="absmiddle" /> Packages<b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="<?php echo generate_url(array('page' => 'packages')); ?> "><img src="images/16/box.png" border="0" align="absmiddle" /> All Packages</a></li> </ul> </li>
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";
<?php if ($device['os'] == 'screenos' && dbFetchCell("SELECT COUNT(*) FROM `processors` WHERE `device_id` = ? AND `processor_type` != 'screenos'", array($device['device_id'])) == '0') { // .1.3.6.1.4.1.3224.16.1.3.0 Cpu Last 5 Minutes // discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision = "1", $current = NULL, $entPhysicalIndex = NULL, $hrDeviceIndex = NULL) echo 'ScreenOS '; $percent = snmp_get($device, '.1.3.6.1.4.1.3224.16.1.3.0', '-OvQ'); if (is_numeric($percent)) { discover_processor($valid['processor'], $device, '.1.3.6.1.4.1.3224.16.1.3.0', '1', 'screenos', 'Processor', '1', $percent, null, null); } }
// Print common global groups navbar include $config['html_dir'] . "/includes/group-navbar.inc.php"; echo '<table class="table table-condensed table-bordered table-striped table-rounded table-hover"> <thead> <tr> <th style="width: 0px"></th> <th style="width: 0px"></th> <th style="width: 25px">Id</th> <th style="">分组</th> <th style="width: 125px">成员 / 类型</th> <th style="width: 560px">成员规则</th> </tr> </thead> <tbody>', PHP_EOL; foreach (get_type_groups($vars['entity_type']) as $group) { $group['member_count'] = dbFetchCell("SELECT COUNT(*) FROM `group_table` WHERE `group_id` = ?", array($group['group_id'])); $entity_type = $config['entities'][$group['entity_type']]; echo '<tr class="' . $group['html_row_class'] . '">'; echo ' <td style="width: 1px; background-color: #194b7f; margin: 0px; padding: 0px"></td> <td style="width: 1px;"></td>'; // Print the conditions applied by this alert echo '<td><strong>'; echo $group['group_id']; echo '</strong></td>'; echo '<td><strong>'; echo '<a href="', generate_url(array('page' => 'group', 'group_id' => $group['group_id'])), '">' . $group['group_name'] . '</a></strong><br />'; echo '<i>', $group['group_descr'], '</i>'; echo '</td>'; // Print the count of entities this alert applies to and a popup containing a list and Print breakdown of entities by status. // We assume each row here is going to be two lines, so we just <br /> them.
require_once 'includes/functions.inc.php'; require_once '../includes/functions.php'; require_once 'includes/authenticate.inc.php'; if (!$_SESSION['authenticated']) { echo 'unauthenticated'; exit; } $type = mres($_POST['type']); if ($type == 'placeholder') { $output = "<span style='text-align:left;'><br><h3>Click on the Edit Dashboard button (next to the list of dashboards) to add widgets</h3><br><h4><strong>Remember:</strong> You can only move & resize widgets when you're in <strong>Edit Mode</strong>.</h4><span>"; $status = 'ok'; $title = 'Placeholder'; } elseif (is_file('includes/common/' . $type . '.inc.php')) { $results_limit = 10; $no_form = true; $title = ucfirst($type); $unique_id = str_replace(array("-", "."), "_", uniqid($type, true)); $widget_id = mres($_POST['id']); $widget_settings = json_decode(dbFetchCell('select settings from users_widgets where user_widget_id = ?', array($widget_id)), true); $widget_dimensions = $_POST['dimensions']; if (!empty($_POST['settings'])) { define('show_settings', true); } include 'includes/common/' . $type . '.inc.php'; $output = implode('', $common_output); $status = 'ok'; $title = $widget_settings['title'] ?: $title; } $response = array('status' => $status, 'html' => $output, 'title' => $title); header('Content-type: application/json'); echo _json_encode($response);
function id_to_target($id) { if ($id[0] == "g") { $id = 'g:' . dbFetchCell("SELECT name FROM device_groups WHERE id = ?", array(substr($id, 1))); } else { $id = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id)); } return $id; }
switch ($vlan_state) { case 'blocking': $class = 'text-error'; break; case 'forwarding': $class = 'text-success'; break; default: $class = 'muted'; } $rel = $vlan_name ? 'tooltip' : ''; // Hide tooltip for empty echo '<br /><span data-rel="' . $rel . '" class="small ' . $class . '" data-tooltip="<strong class=\'small ' . $class . '\'>' . $port['ifVlan'] . ' [' . $vlan_name . ']</strong>">VLAN ' . $port['ifVlan'] . '</span>'; } else { if ($port['ifVrf']) { $vrf_name = dbFetchCell("SELECT `vrf_name` FROM `vrfs` WHERE `vrf_id` = ?", array($port['ifVrf'])); echo '<span class="small text-warning" data-rel="tooltip" data-tooltip="VRF">' . $vrf_name . '</span>'; } } } if ($port_adsl['adslLineCoding']) { echo "</td><td style='width: 150px;'>"; echo $port_adsl['adslLineCoding'] . "/" . rewrite_adslLineType($port_adsl['adslLineType']); echo "<br />"; echo "Sync:" . formatRates($port_adsl['adslAtucChanCurrTxRate']) . "/" . formatRates($port_adsl['adslAturChanCurrTxRate']); echo "<br />"; echo "Max:" . formatRates($port_adsl['adslAtucCurrAttainableRate']) . "/" . formatRates($port_adsl['adslAturCurrAttainableRate']); echo "</td><td style='width: 150px;'>"; echo "Atten:" . $port_adsl['adslAtucCurrAtn'] . "dB/" . $port_adsl['adslAturCurrAtn'] . "dB"; echo "<br />"; echo "SNR:" . $port_adsl['adslAtucCurrSnrMgn'] . "dB/" . $port_adsl['adslAturCurrSnrMgn'] . "dB";
*/ /* * Code for Gridster.sort_by_row_and_col_asc(serialization) call is from http://gridster.net/demos/grid-from-serialize.html */ $no_refresh = true; $default_dash = 0; $tmp = dbFetchCell('SELECT dashboard FROM users WHERE user_id=?', array($_SESSION['user_id'])); if ($tmp != 0) { $default_dash = $tmp; } elseif ((int) $config['webui']['default_dashboard_id']) { // if the user hasn't set their default page, and there is a global default set $default_dash = dbFetchCell('SELECT `dashboard_id` FROM `dashboards` WHERE `dashboard_id` = ?', array((int) $config['webui']['default_dashboard_id'])); } if ($default_dash == 0 && dbFetchCell('SELECT dashboard_id FROM dashboards WHERE user_id=?', array($_SESSION['user_id'])) == 0) { $vars['dashboard'] = dbInsert(array('dashboard_name' => 'Default', 'user_id' => $_SESSION['user_id']), 'dashboards'); if (dbFetchCell('select 1 from users_widgets where user_id = ? && dashboard_id = ?', array($_SESSION['user_id'], 0)) == 1) { dbUpdate(array('dashboard_id' => $vars['dashboard']), 'users_widgets', 'user_id = ? && dashboard_id = ?', array($_SESSION['user_id'], 0)); } } if (!empty($vars['dashboard'])) { $orig = $vars['dashboard']; $vars['dashboard'] = dbFetchRow('select * from dashboards where user_id = ? && dashboard_id = ? order by dashboard_id limit 1', array($_SESSION['user_id'], $vars['dashboard'])); if (empty($vars['dashboard'])) { $vars['dashboard'] = dbFetchRow('select dashboards.*,users.username from dashboards inner join users on dashboards.user_id = users.user_id where dashboards.dashboard_id = ? && dashboards.access > 0', array($orig)); } } if (empty($vars['dashboard'])) { if ($default_dash != 0) { $vars['dashboard'] = dbFetchRow('select dashboards.*,users.username from dashboards inner join users on dashboards.user_id = users.user_id where dashboards.dashboard_id = ?', array($default_dash)); } else { $vars['dashboard'] = dbFetchRow('select * from dashboards where user_id = ? order by dashboard_id limit 1', array($_SESSION['user_id']));
$oid_values = explode(".", $vrf_oid); $vrf_name = ""; for ($i = 1; $i <= $oid_values[0]; $i++) { $vrf_name .= chr($oid_values[$i]); } echo "\n [VRF {$vrf_name}] OID - " . $vrf_oid; echo "\n [VRF {$vrf_name}] RD - " . $vrf_rd; echo "\n [VRF {$vrf_name}] DESC - " . $descr_table[$vrf_oid]; if (dbFetchCell('SELECT COUNT(*) FROM `vrfs` WHERE `device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid))) { $update_array = array('mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd); dbUpdate($update_array, 'vrfs', '`device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid)); } else { $insert_array = array('device_id' => $device['device_id'], 'vrf_oid' => $vrf_oid, 'vrf_name' => $vrf_name, 'mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd); dbInsert($insert_array, 'vrfs'); } $vrf_id = dbFetchCell('SELECT vrf_id FROM `vrfs` WHERE `device_id` = ? AND `vrf_oid` = ?', array($device['device_id'], $vrf_oid)); $valid_vrf[$vrf_id] = 1; echo "\n [VRF {$vrf_name}] PORTS - "; foreach ($port_table[$vrf_oid] as $if_id) { $interface = dbFetchRow('SELECT ifDescr, port_id FROM ports WHERE ifIndex = ? AND device_id = ?', array($if_id, $device['device_id'])); echo short_ifname($interface['ifDescr']) . " "; dbUpdate(array('ifVrf' => $vrf_id), 'ports', '`port_id` = ?', array($interface['port_id'])); $if = $interface['port_id']; $valid_vrf_if[$vrf_id][$if] = 1; } } } echo "\n"; foreach (dbFetchRows('SELECT * FROM ports WHERE device_id = ?', array($device['device_id'])) as $row) { $if = $row['port_id']; $vrf_id = $row['ifVrf'];
echo $navbar; ?> navbar-fixed-bottom"> <div class="container"> <div class="row"> <div class="col-md-12 text-center"> <?php echo '<h5>Powered by <a href="' . $config['project_home'] . '" target="_blank" class="red">' . $config['project_name'] . '</a>.</h5>'; ?> </div> </div> </div> </nav> <?php } if (dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` <= DATE_ADD(NOW(), INTERVAL - 15 minute) AND `ignore` = 0 AND `disabled` = 0 AND status = 1", array()) > 0) { $msg_box[] = array('type' => 'warning', 'message' => "<a href=\"poll-log/filter=unpolled/\">It appears as though you have some devices that haven't completed polling within the last 15 minutes, you may want to check that out :)</a>", 'title' => 'Devices unpolled'); } if (is_array($msg_box)) { echo "<script>\n toastr.options.timeout = 10;\n toastr.options.extendedTimeOut = 20;\n "; foreach ($msg_box as $message) { $message['type'] = mres($message['type']); $message['message'] = mres($message['message']); $message['title'] = mres($message['title']); echo "toastr." . $message['type'] . "('" . $message['message'] . "','" . $message['title'] . "');\n"; } echo "</script>"; } if (is_array($sql_debug) && is_array($php_debug) && $_SESSION['authenticated'] === true) { require_once "includes/print-debug.php"; }
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>"; $access_list[] = $device_perm['device_id']; $permdone = "yes"; } echo "</table>\n </div>";
function get_userid($username) { return dbFetchCell("SELECT `user_id` FROM `users` WHERE `username` = ?", array($username)); }
?> </code></footer> </blockquote> </div> </div> </div> <?php } if ($notifications['sticky_count'] != 0) { ?> <hr/> <?php } foreach ($notifications['unread'] as $notif) { if (is_numeric($notif['source'])) { $notif['source'] = dbFetchCell('select username from users where user_id =?', array($notif['source'])); } ?> <div class="well"> <div class="row"> <div class="col-md-12"> <h4 class="text-success" id="<?php echo $notif['notifications_id']; ?> "><strong><?php echo $notif['title']; ?> </strong><span class="pull-right"> <?php echo $_SESSION['userlevel'] == 10 ? '<button class="btn btn-primary fa fa-bell-o stick-notif" data-toggle="tooltip" data-placement="bottom" title="Mark as Sticky" style="margin-top:-10px;"></button>' : ''; ?>
} echo "\n"; } } } else { print_warn('You don\'t have $config["user"] set, this most likely needs to be set to librenms'); } // Run test on MySQL $test_db = @mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); if (mysqli_connect_error()) { print_fail('Error connecting to your database ' . mysqli_connect_error()); } else { print_ok('Database connection successful'); } // Test for MySQL Strict mode $strict_mode = dbFetchCell("SELECT @@global.sql_mode"); if (strstr($strict_mode, 'STRICT_TRANS_TABLES')) { print_fail('You have MySQL STRICT_TRANS_TABLES enabled, please disable this until full support has been added: https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html'); } $tz = ini_get('date.timezone'); if (empty($tz)) { print_fail('You have no timezone set for php: http://php.net/manual/en/datetime.configuration.php#ini.date.timezone'); } // Test transports if ($config['alerts']['email']['enable'] === true) { print_warn('You have the old alerting system enabled - this is to be deprecated on the 1st of June 2015: https://groups.google.com/forum/#!topic/librenms-project/1llxos4m0p4'); } // Test rrdcached if (!$config['rrdcached']) { $rrd_dir = stat($config['rrd_dir']); if ($rrd_dir[4] == 0 || $rrd_dir[5] == 0) {
function add_edit_rule() { global $config; $app = \Slim\Slim::getInstance(); $data = json_decode(file_get_contents('php://input'), true); $status = 'error'; $message = ''; $code = 500; $rule_id = mres($data['rule_id']); $device_id = mres($data['device_id']); if (empty($device_id) && !isset($rule_id)) { $message = 'Missing the device id or global device id (-1)'; } elseif ($device_id == 0) { $device_id = '-1'; } $rule = $data['rule']; if (empty($rule)) { $message = 'Missing the alert rule'; } $name = mres($data['name']); if (empty($name)) { $message = 'Missing the alert rule name'; } $severity = mres($data['severity']); $sevs = array('ok', 'warning', 'critical'); if (!in_array($severity, $sevs)) { $message = 'Missing the severity'; } $disabled = mres($data['disabled']); if ($disabled != '0' && $disabled != '1') { $disabled = 0; } $count = mres($data['count']); $mute = mres($data['mute']); $delay = mres($data['delay']); $delay_sec = convert_delay($delay); if ($mute == 1) { $mute = true; } else { $mute = false; } $extra = array('mute' => $mute, 'count' => $count, 'delay' => $delay_sec); $extra_json = json_encode($extra); if (dbFetchCell('SELECT `name` FROM `alert_rules` WHERE `name`=?', array($name)) == $name) { $message = 'Name has already been used'; } if (empty($message)) { if (is_numeric($rule_id)) { if (dbUpdate(array('name' => $name, 'rule' => $rule, 'severity' => $severity, 'disabled' => $disabled, 'extra' => $extra_json), 'alert_rules', 'id=?', array($rule_id)) >= 0) { $status = 'ok'; $code = 200; } else { $message = 'Failed to update existing alert rule'; } } elseif (dbInsert(array('name' => $name, 'device_id' => $device_id, 'rule' => $rule, 'severity' => $severity, 'disabled' => $disabled, 'extra' => $extra_json), 'alert_rules')) { $status = 'ok'; $code = 200; } else { $message = 'Failed to create new alert rule'; } } $output = array('status' => $status, 'err-msg' => $message); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
function set_dev_attrib($device, $attrib_type, $attrib_value) { if (dbFetchCell("SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type))) { $return = dbUpdate(array('attrib_value' => $attrib_value), 'devices_attribs', 'device_id=? and attrib_type=?', array($device['device_id'], $attrib_type)); } else { $return = dbInsert(array('device_id' => $device['device_id'], 'attrib_type' => $attrib_type, 'attrib_value' => $attrib_value), 'devices_attribs'); } return $return; }
/** * 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>"; } }
/** * Returns version info * @return array **/ function version_info($remote = true) { global $config; $output = array(); if ($remote === true && $config['update_channel'] == 'master') { $api = curl_init(); set_curl_proxy($api); curl_setopt($api, CURLOPT_USERAGENT, 'LibreNMS'); curl_setopt($api, CURLOPT_URL, $config['github_api'] . 'commits/master'); curl_setopt($api, CURLOPT_RETURNTRANSFER, 1); $output['github'] = json_decode(curl_exec($api), true); } $output['local_sha'] = chop(`git rev-parse HEAD`); $output['db_schema'] = dbFetchCell('SELECT version FROM dbSchema'); $output['php_ver'] = phpversion(); $output['mysql_ver'] = dbFetchCell('SELECT version()'); $output['rrdtool_ver'] = implode(' ', array_slice(explode(' ', shell_exec($config['rrdtool'] . ' --version |head -n1')), 1, 1)); $output['netsnmp_ver'] = shell_exec($config['snmpget'] . ' --version 2>&1'); return $output; }