fix: Make irc bot to use authentication module for user info (#4372)

This commit is contained in:
Neil Lathwood
2016-09-12 17:24:22 +01:00
committed by Tony Murray
parent b397e23763
commit 9e85f24b00
3 changed files with 8 additions and 4 deletions

View File

@@ -478,7 +478,8 @@ class IRCBot
if (strlen($params[0]) == 64) { if (strlen($params[0]) == 64) {
if ($this->tokens[$this->getUser($this->data)] == $params[0]) { if ($this->tokens[$this->getUser($this->data)] == $params[0]) {
$this->user['expire'] = (time() + ($this->config['irc_authtime'] * 3600)); $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']; $this->user['level'] = $tmp['level'];
if ($this->user['level'] < 5) { if ($this->user['level'] < 5) {
foreach (dbFetchRows('SELECT device_id FROM devices_perms WHERE user_id = ?', array($this->user['id'])) as $tmp) { 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.'); return $this->respond('Nope.');
} }
} else { } 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]) { if ($user['email'] && $user['username'] == $params[0]) {
$token = hash('gost', openssl_random_pseudo_bytes(1024)); $token = hash('gost', openssl_random_pseudo_bytes(1024));
$this->tokens[$this->getUser($this->data)] = $token; $this->tokens[$this->getUser($this->data)] = $token;

View File

@@ -108,8 +108,9 @@ function get_userlevel($username)
// Loop the list and find the highest level // Loop the list and find the highest level
foreach ($entries as $entry) { foreach ($entries as $entry) {
$groupname = $entry['cn'][0]; $groupname = $entry['cn'][0];
$userlevel = array();
if ($config['auth_ldap_groups'][$groupname]['level'] > $userlevel) { 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) { foreach (get_userlist() as $users) {
if ($users['user_id'] === $user_id) { if ($users['user_id'] === $user_id) {
return $users['username']; return $users;
} }
} }
return 0; return 0;

View File

@@ -25,6 +25,7 @@ require_once 'config.php';
require_once 'includes/definitions.inc.php'; require_once 'includes/definitions.inc.php';
require_once 'includes/functions.php'; require_once 'includes/functions.php';
require_once 'includes/discovery/functions.inc.php'; require_once 'includes/discovery/functions.inc.php';
require_once 'html/includes/authentication/'.$config['auth_mechanism'].'.inc.php';
error_reporting(E_ERROR); error_reporting(E_ERROR);
$irc = new LibreNMS\IRCBot(); $irc = new LibreNMS\IRCBot();