extended the user table to store util/db-mysql.sql

This commit is contained in:
SJ 2012-10-16 23:45:54 +02:00
parent ac61b8cf0f
commit 02f1dac543
4 changed files with 22 additions and 10 deletions

View File

@ -195,13 +195,14 @@ create table if not exists `user` (
`uid` int unsigned not null primary key,
`username` char(64) not null unique,
`realname` char(64) default null,
`samaccountname` char(64) default null,
`password` char(128) default null,
`domain` char(64) default null,
`dn` char(255) default '*',
`isadmin` tinyint default 0
) Engine=InnoDB;
insert into `user` (`uid`, `username`, `realname`, `password`, `isadmin`, `domain`) values (0, 'admin', 'built-in piler admin', '$1$PItc7d$zsUgON3JRrbdGS11t9JQW1', 1, 'local');
insert into `user` (`uid`, `username`, `realname`, `samaccountname`, `password`, `isadmin`, `domain`) values (0, 'admin', 'built-in piler admin', '', '$1$PItc7d$zsUgON3JRrbdGS11t9JQW1', 1, 'local');
drop table if exists `email`;
create table if not exists `email` (

View File

@ -0,0 +1,2 @@
alter table `user` add column `samaccountname` char(64) default null;

View File

@ -25,7 +25,7 @@ class ModelUserImport extends Model {
LOGGER("LDAP type: " . $host['type']);
if($host['type'] == "AD") {
$attrs = array("cn", "proxyaddresses", "member", "mail");
$attrs = array("cn", "samaccountname", "proxyaddresses", "member", "mail");
$mailAttr = "proxyaddresses";
$mailAttrs = array("mail", "proxyaddresses");
@ -86,10 +86,12 @@ class ModelUserImport extends Model {
}
$data[] = array(
'username' => preg_replace("/\n{1,}$/", "", $__emails[0]),
'realname' => $result['cn'],
'dn' => $result['dn'],
'samaccountname' => isset($result['samaccountname']) ? $result['samaccountname'] : '',
'emails' => preg_replace("/\n{1,}$/", "", $emails),
'members' => preg_replace("/\n{1,}$/", "", $members)
);
@ -220,7 +222,9 @@ class ModelUserImport extends Model {
/* or add the new user */
$user = $this->createNewUserArray($_user['dn'], $_user['username'], $_user['realname'], $_user['emails'], $globals);
$user = $this->createNewUserArray($_user['dn'], $_user['username'], $_user['realname'], $_user['emails'], $_user['samaccountname'], $globals);
$user['folder'] = '';
array_push($uids, $user['uid']);
$rc = $this->model_user_user->add_user($user);
@ -287,7 +291,7 @@ class ModelUserImport extends Model {
}
private function createNewUserArray($dn = '', $username = '', $realname = '', $emails = '', $globals = array()) {
private function createNewUserArray($dn = '', $username = '', $realname = '', $emails = '', $samaccountname = '', $globals = array()) {
$user = array();
$user['uid'] = $this->model_user_user->get_next_uid();
@ -317,6 +321,7 @@ class ModelUserImport extends Model {
$user['whitelist'] = '';
$user['blacklist'] = '';
$user['group'] = 0;
$user['samaccountname'] = $samaccountname;
return $user;
}

View File

@ -61,6 +61,7 @@ class ModelUserUser extends Model {
}
$query = $this->db->query("SELECT email FROM " . TABLE_EMAIL . " WHERE uid IN ($uids)");
foreach ($query->rows as $q) {
array_push($data, $q['email']);
}
@ -290,7 +291,10 @@ class ModelUserUser extends Model {
$encrypted_password = crypt($user['password']);
$query = $this->db->query("INSERT INTO " . TABLE_USER . " (uid, username, realname, password, domain, dn, isadmin) VALUES(?,?,?,?,?,?,?)", array((int)$user['uid'], $user['username'], $user['realname'], $encrypted_password, $user['domain'], @$user['dn'], (int)$user['isadmin']));
$samaccountname = '';
if(isset($user['samaccountname'])) { $samaccountname = $user['samaccountname']; }
$query = $this->db->query("INSERT INTO " . TABLE_USER . " (uid, username, realname, password, domain, dn, isadmin, samaccountname) VALUES(?,?,?,?,?,?,?,?)", array((int)$user['uid'], $user['username'], $user['realname'], $encrypted_password, $user['domain'], @$user['dn'], (int)$user['isadmin'], $samaccountname));
if($query->error == 1 || $this->db->countAffected() == 0){ return $user['username']; }