Merge pull request #2434 from vizay/adauth_adduser_to_db

Ad-auth need to add user to db for dashboards to work properly
This commit is contained in:
Neil Lathwood
2015-11-17 12:24:22 +00:00
2 changed files with 15 additions and 3 deletions

View File

@@ -69,4 +69,5 @@ Contributors to LibreNMS:
- Rob Gormley <robert@gormley.me> (rgormley)
- Richard Kojedzinszky <krichy@nmdps.net> (rkojedzinszky)
- Tony Murray <murraytony@gmail.com> (murrant)
- Peter Lamperud <peter.lamperud@gmail.com> (vizay)
[1]: http://observium.org/ "Observium web site"

View File

@@ -35,6 +35,7 @@ function authenticate($username, $password) {
if (isset($config['auth_ad_groups'][$group_cn]['level'])) {
// user is in one of the defined groups
$user_authenticated = 1;
adduser($username);
}
}
@@ -43,6 +44,7 @@ function authenticate($username, $password) {
}
else {
// group membership is not required and user is valid
adduser($username);
return 1;
}
}
@@ -81,11 +83,20 @@ function auth_usermanagement() {
}
function adduser() {
// not supported so return 0
return 0;
function adduser($username) {
// Check to see if user is already added in the database
if (!user_exists_in_db($username)) {
return dbInsert(array('username' => $username, 'user_id' => get_userid($username), 'level' => "0", 'can_modify_passwd' => 0, 'twofactor' => 0), 'users');
}
else {
return false;
}
}
function user_exists_in_db($username) {
$return = dbFetchCell('SELECT COUNT(*) FROM users WHERE username = ?', array($username), true);
return $return;
}
function user_exists($username) {
global $config, $ds;