This is a hack/work around to automatically create a Zabbix user when a user authenticates in LDAP, but does not exist in Zabbix.
Fields for the user account are filled out with default data for my install, you will want to put in your own. I'm just creating read-only users.
File:
zabbix/api/classes/CUser.php
Insert the following code ABOVE this line:
if (!$userInfo) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Login name or password is incorrect.'));
}
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
if (!$userInfo) {
if ($this->ldapLogin($user)) {
$user2 = array();
$user2['alias'] = $name;
$user2['name'] = $name;
$user2['surname'] = '';
$user2['passwd'] = '';
$user2['url'] = '';
$user2['autologin'] = 1;
$user2['autologout'] = 0;
$user2['lang'] = 'en_GB';
$user2['theme'] = 'default';
$user2['refresh'] = 300;
$user2['rows_per_page'] = 250;
$user2['type'] = 1;
$user2['user_medias'] = '';
$user2['usrgrps'] = 11;
self::$userData['type'] = 3;
DBstart();
DBend($this->create($user2));
$userInfo = DBfetch(DBselect(
'SELECT u.userid,u.attempt_failed,u.attempt_clock,u.attemp t_ip'.
' FROM users u'.
' WHERE u.alias='.zbx_dbstr($name).
andDbNode('u.userid', $ZBX_LOCALNODEID)
));
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
Fields for the user account are filled out with default data for my install, you will want to put in your own. I'm just creating read-only users.
File:
zabbix/api/classes/CUser.php
Insert the following code ABOVE this line:
if (!$userInfo) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Login name or password is incorrect.'));
}
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
if (!$userInfo) {
if ($this->ldapLogin($user)) {
$user2 = array();
$user2['alias'] = $name;
$user2['name'] = $name;
$user2['surname'] = '';
$user2['passwd'] = '';
$user2['url'] = '';
$user2['autologin'] = 1;
$user2['autologout'] = 0;
$user2['lang'] = 'en_GB';
$user2['theme'] = 'default';
$user2['refresh'] = 300;
$user2['rows_per_page'] = 250;
$user2['type'] = 1;
$user2['user_medias'] = '';
$user2['usrgrps'] = 11;
self::$userData['type'] = 3;
DBstart();
DBend($this->create($user2));
$userInfo = DBfetch(DBselect(
'SELECT u.userid,u.attempt_failed,u.attempt_clock,u.attemp t_ip'.
' FROM users u'.
' WHERE u.alias='.zbx_dbstr($name).
andDbNode('u.userid', $ZBX_LOCALNODEID)
));
}
}
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
And sorry for the bad english. Still learning.
Comment