mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 00:24:21 +02:00
Merge pull request #2007 from QuxLabs/qux-issue-8
Added working memcached support
This commit is contained in:
+17
-34
@@ -72,22 +72,16 @@ if (isset($_GET['term'],$_GET['device_id'])) {
|
||||
$_GET['device_id'] = mres($_GET['device_id']);
|
||||
if (strstr($_GET['term'], '.')) {
|
||||
$term = explode('.', $_GET['term']);
|
||||
if ($config['memcached']['enable']) {
|
||||
$chk = $memcache->get('rule-suggest_'.$term[0]);
|
||||
}
|
||||
|
||||
if (!(sizeof($chk) > 0) || $chk === false) {
|
||||
if ($term[0] == 'macros') {
|
||||
foreach ($config['alert']['macros']['rule'] as $macro => $v) {
|
||||
$chk[] = 'macros.'.$macro;
|
||||
}
|
||||
if ($term[0] == 'macros') {
|
||||
foreach ($config['alert']['macros']['rule'] as $macro => $v) {
|
||||
$chk[] = 'macros.'.$macro;
|
||||
}
|
||||
else {
|
||||
$tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]);
|
||||
foreach ($tmp as $tst) {
|
||||
if (isset($tst['Field'])) {
|
||||
$chk[] = $term[0].'.'.$tst['Field'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tmp = dbFetchRows('SHOW COLUMNS FROM '.$term[0]);
|
||||
foreach ($tmp as $tst) {
|
||||
if (isset($tst['Field'])) {
|
||||
$chk[] = $term[0].'.'.$tst['Field'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,29 +89,18 @@ if (isset($_GET['term'],$_GET['device_id'])) {
|
||||
$current = true;
|
||||
}
|
||||
else {
|
||||
if ($config['memcached']['enable']) {
|
||||
$chk = $memcache->get('rule-suggest-toplvl');
|
||||
$tmp = dbFetchRows("SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'device_id'");
|
||||
foreach ($tmp as $tst) {
|
||||
$chk[] = $tst['TABLE_NAME'].'.';
|
||||
}
|
||||
|
||||
if (!(sizeof($chk) > 0) || $chk === false) {
|
||||
$tmp = dbFetchRows("SELECT TABLE_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME = 'device_id'");
|
||||
foreach ($tmp as $tst) {
|
||||
$chk[] = $tst['TABLE_NAME'].'.';
|
||||
}
|
||||
|
||||
$chk[] = 'macros.';
|
||||
$chk[] = 'bills.';
|
||||
}
|
||||
$chk[] = 'macros.';
|
||||
$chk[] = 'bills.';
|
||||
}
|
||||
if (sizeof($chk) > 0) {
|
||||
if ($config['memcached']['enable']) {
|
||||
$memcache->set('rule-suggest-'.$oterm, $chk, 86400);
|
||||
// Cache for 24h
|
||||
}
|
||||
|
||||
$obj = levsort($_GET['term'], $chk);
|
||||
$obj = array_chunk($obj, 20, true);
|
||||
$obj = $obj[0];
|
||||
$obj = levsort($_GET['term'], $chk);
|
||||
$obj = array_chunk($obj, 20, true);
|
||||
$obj = $obj[0];
|
||||
$flds = array();
|
||||
if ($current === true) {
|
||||
foreach ($obj as $fld) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
function authenticate($username, $password) {
|
||||
$encrypted_old = md5($password);
|
||||
$row = dbFetchRow('SELECT username,password FROM `users` WHERE `username`= ?', array($username));
|
||||
$row = dbFetchRow('SELECT username,password FROM `users` WHERE `username`= ?', array($username), true);
|
||||
if ($row['username'] && $row['username'] == $username) {
|
||||
// Migrate from old, unhashed password
|
||||
if ($row['password'] == $encrypted_old) {
|
||||
@@ -36,7 +36,7 @@ function authenticate($username, $password) {
|
||||
|
||||
function reauthenticate($sess_id, $token) {
|
||||
list($uname,$hash) = explode('|', $token);
|
||||
$session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'");
|
||||
$session = dbFetchRow("SELECT * FROM `session` WHERE `session_username` = '$uname' AND session_value='$sess_id'", array(), true);
|
||||
$hasher = new PasswordHash(8, false);
|
||||
if ($hasher->CheckPassword($uname.$session['session_token'], $hash)) {
|
||||
$_SESSION['username'] = $uname;
|
||||
@@ -59,7 +59,7 @@ function passwordscanchange($username='') {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return dbFetchCell('SELECT can_modify_passwd FROM users WHERE username = ?', array($username));
|
||||
return dbFetchCell('SELECT can_modify_passwd FROM users WHERE username = ?', array($username), true);
|
||||
}
|
||||
|
||||
}//end passwordscanchange()
|
||||
@@ -114,20 +114,20 @@ function adduser($username, $password, $level, $email='', $realname='', $can_mod
|
||||
|
||||
|
||||
function user_exists($username) {
|
||||
$return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username));
|
||||
$return = @dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username), true);
|
||||
return $return;
|
||||
|
||||
}//end user_exists()
|
||||
|
||||
|
||||
function get_userlevel($username) {
|
||||
return dbFetchCell('SELECT `level` FROM `users` WHERE `username` = ?', array($username));
|
||||
return dbFetchCell('SELECT `level` FROM `users` WHERE `username` = ?', array($username), true);
|
||||
|
||||
}//end get_userlevel()
|
||||
|
||||
|
||||
function get_userid($username) {
|
||||
return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username` = ?', array($username));
|
||||
return dbFetchCell('SELECT `user_id` FROM `users` WHERE `username` = ?', array($username), true);
|
||||
|
||||
}//end get_userid()
|
||||
|
||||
@@ -158,7 +158,7 @@ function can_update_users() {
|
||||
|
||||
|
||||
function get_user($user_id) {
|
||||
return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id));
|
||||
return dbFetchRow('SELECT * FROM `users` WHERE `user_id` = ?', array($user_id), true);
|
||||
|
||||
}//end get_user()
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ if ($rowCount != -1) {
|
||||
|
||||
$sql = "SELECT D.device_id,D.hostname AS `hostname`, D.last_polled AS `last_polled`, `group_name`, D.last_polled_timetaken AS `last_polled_timetaken` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql) as $device) {
|
||||
foreach (dbFetchRows($sql,array(),true) as $device) {
|
||||
if (empty($device['group_name'])) {
|
||||
$device['group_name'] = 'General';
|
||||
}
|
||||
|
||||
+3
-1
@@ -32,7 +32,7 @@ function catchFatal() {
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($_SERVER['PATH_INFO'], "debug")) {
|
||||
if (strpos($_SERVER['PATH_INFO'], "debug") || true) {
|
||||
$debug = "1";
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('display_startup_errors', 1);
|
||||
@@ -66,6 +66,8 @@ require 'includes/functions.inc.php';
|
||||
require 'includes/vars.inc.php';
|
||||
require 'includes/plugins.inc.php';
|
||||
|
||||
$config['memcached']['ttl'] = $config['time']['now']+300;
|
||||
|
||||
Plugins::start();
|
||||
|
||||
$runtime_start = utime();
|
||||
|
||||
@@ -22,7 +22,7 @@ else if ($vars['purge']) {
|
||||
echo '<table cellpadding=5 cellspacing=0 border=0 width=100%>';
|
||||
echo "<tr><td></td><td></td><td></td><td><a href='deleted-ports/purge=all/'><img src='images/16/cross.png' align=absmiddle></img> Purge All</a></td></tr>";
|
||||
|
||||
foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) {
|
||||
foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id",array(),true) as $interface) {
|
||||
$interface = ifLabel($interface, $interface);
|
||||
if (port_permitted($interface['port_id'], $interface['device_id'])) {
|
||||
echo '<tr class=list>';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
$no_refresh = TRUE;
|
||||
$config['memcached']['enable'] = false;
|
||||
|
||||
$link_array = array('page' => 'device',
|
||||
'device' => $device['device_id'],
|
||||
|
||||
@@ -13,17 +13,6 @@ foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($devi
|
||||
$row_colour = $list_colour_b;
|
||||
}
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$mempool = array_merge($mempool, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
$text_descr = rewrite_entity_descr($mempool['mempool_descr']);
|
||||
|
||||
$mempool_url = 'graphs/id='.$mempool['mempool_id'].'/type=mempool_usage/';
|
||||
@@ -55,4 +44,4 @@ foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($devi
|
||||
echo "</div></div>";
|
||||
|
||||
$i++;
|
||||
}//end foreach
|
||||
}//end foreach
|
||||
|
||||
@@ -12,10 +12,6 @@ if (count($sensors)) {
|
||||
echo ' </div>
|
||||
<table class="table table-hover table-condensed table-striped">';
|
||||
foreach ($sensors as $sensor) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value');
|
||||
}
|
||||
|
||||
if (empty($sensor['sensor_current'])) {
|
||||
$sensor['sensor_current'] = 'NaN';
|
||||
}
|
||||
|
||||
@@ -19,17 +19,6 @@ if (count($mempools)) {
|
||||
';
|
||||
|
||||
foreach ($mempools as $mempool) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('mempool-'.$mempool['mempool_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$mempool = array_merge($mempool, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
$percent = round($mempool['mempool_perc'], 0);
|
||||
$text_descr = rewrite_entity_descr($mempool['mempool_descr']);
|
||||
$total = formatStorage($mempool['mempool_total']);
|
||||
|
||||
@@ -6,17 +6,6 @@ if (!isset($vars['view'])) {
|
||||
|
||||
$port = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($vars['port']));
|
||||
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('port-'.$port['port_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$port = array_merge($port, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
$port_details = 1;
|
||||
|
||||
$hostname = $device['hostname'];
|
||||
|
||||
@@ -136,19 +136,7 @@ else {
|
||||
}
|
||||
|
||||
foreach ($ports as $port) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$state = $memcache->get('port-'.$port['port_id'].'-state');
|
||||
d_echo($state);
|
||||
|
||||
if (is_array($state)) {
|
||||
$port = array_merge($port, $state);
|
||||
}
|
||||
|
||||
unset($state);
|
||||
}
|
||||
|
||||
include 'includes/print-interface.inc.php';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,6 @@ echo '<tr class="tablehead">
|
||||
</tr>';
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $sensor) {
|
||||
if ($config['memcached']['enable'] === true) {
|
||||
$sensor['sensor_current'] = $memcache->get('sensor-'.$sensor['sensor_id'].'-value');
|
||||
d_echo('Memcached['.'sensor-'.$sensor['sensor_id'].'-value'.'='.$sensor['sensor_current'].']');
|
||||
}
|
||||
|
||||
if (empty($sensor['sensor_current'])) {
|
||||
$sensor['sensor_current'] = 'NaN';
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* @subpackage Page
|
||||
*/
|
||||
$pagetitle[] = 'Global Settings';
|
||||
$config['memcached']['enable'] = false;
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
Reference in New Issue
Block a user