From 9e85f24b000ed158ca11fdb6890bb986c2063967 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Mon, 12 Sep 2016 17:24:22 +0100 Subject: [PATCH] fix: Make irc bot to use authentication module for user info (#4372) --- LibreNMS/IRCBot.php | 6 ++++-- html/includes/authentication/ldap.inc.php | 5 +++-- irc.php | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/LibreNMS/IRCBot.php b/LibreNMS/IRCBot.php index 237028d686..0d97518134 100644 --- a/LibreNMS/IRCBot.php +++ b/LibreNMS/IRCBot.php @@ -478,7 +478,8 @@ class IRCBot if (strlen($params[0]) == 64) { if ($this->tokens[$this->getUser($this->data)] == $params[0]) { $this->user['expire'] = (time() + ($this->config['irc_authtime'] * 3600)); - $tmp = dbFetchRow('SELECT level FROM users WHERE user_id = ?', array($this->user['id'])); + $tmp_user = get_user($this->user['id']); + $tmp = get_userlevel($tmp_user['username']); $this->user['level'] = $tmp['level']; if ($this->user['level'] < 5) { foreach (dbFetchRows('SELECT device_id FROM devices_perms WHERE user_id = ?', array($this->user['id'])) as $tmp) { @@ -495,7 +496,8 @@ class IRCBot return $this->respond('Nope.'); } } else { - $user = dbFetchRow('SELECT `user_id`,`username`,`email` FROM `users` WHERE `username` = ?', array(mres($params[0]))); + $user_id = get_userid(mres($params[0])); + $user = get_user($user_id); if ($user['email'] && $user['username'] == $params[0]) { $token = hash('gost', openssl_random_pseudo_bytes(1024)); $this->tokens[$this->getUser($this->data)] = $token; diff --git a/html/includes/authentication/ldap.inc.php b/html/includes/authentication/ldap.inc.php index 238149bcbe..a7465ce400 100644 --- a/html/includes/authentication/ldap.inc.php +++ b/html/includes/authentication/ldap.inc.php @@ -108,8 +108,9 @@ function get_userlevel($username) // Loop the list and find the highest level foreach ($entries as $entry) { $groupname = $entry['cn'][0]; + $userlevel = array(); if ($config['auth_ldap_groups'][$groupname]['level'] > $userlevel) { - $userlevel = $config['auth_ldap_groups'][$groupname]['level']; + $userlevel['level'] = $config['auth_ldap_groups'][$groupname]['level']; } } @@ -190,7 +191,7 @@ function get_user($user_id) { foreach (get_userlist() as $users) { if ($users['user_id'] === $user_id) { - return $users['username']; + return $users; } } return 0; diff --git a/irc.php b/irc.php index 0df30e49ae..5b78388df2 100755 --- a/irc.php +++ b/irc.php @@ -25,6 +25,7 @@ require_once 'config.php'; require_once 'includes/definitions.inc.php'; require_once 'includes/functions.php'; require_once 'includes/discovery/functions.inc.php'; +require_once 'html/includes/authentication/'.$config['auth_mechanism'].'.inc.php'; error_reporting(E_ERROR); $irc = new LibreNMS\IRCBot();