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, `uid` int unsigned not null primary key,
`username` char(64) not null unique, `username` char(64) not null unique,
`realname` char(64) default null, `realname` char(64) default null,
`samaccountname` char(64) default null,
`password` char(128) default null, `password` char(128) default null,
`domain` char(64) default null, `domain` char(64) default null,
`dn` char(255) default '*', `dn` char(255) default '*',
`isadmin` tinyint default 0 `isadmin` tinyint default 0
) Engine=InnoDB; ) 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`; drop table if exists `email`;
create table if not 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']); LOGGER("LDAP type: " . $host['type']);
if($host['type'] == "AD") { if($host['type'] == "AD") {
$attrs = array("cn", "proxyaddresses", "member", "mail"); $attrs = array("cn", "samaccountname", "proxyaddresses", "member", "mail");
$mailAttr = "proxyaddresses"; $mailAttr = "proxyaddresses";
$mailAttrs = array("mail", "proxyaddresses"); $mailAttrs = array("mail", "proxyaddresses");
@ -86,10 +86,12 @@ class ModelUserImport extends Model {
} }
$data[] = array( $data[] = array(
'username' => preg_replace("/\n{1,}$/", "", $__emails[0]), 'username' => preg_replace("/\n{1,}$/", "", $__emails[0]),
'realname' => $result['cn'], 'realname' => $result['cn'],
'dn' => $result['dn'], 'dn' => $result['dn'],
'samaccountname' => isset($result['samaccountname']) ? $result['samaccountname'] : '',
'emails' => preg_replace("/\n{1,}$/", "", $emails), 'emails' => preg_replace("/\n{1,}$/", "", $emails),
'members' => preg_replace("/\n{1,}$/", "", $members) 'members' => preg_replace("/\n{1,}$/", "", $members)
); );
@ -220,7 +222,9 @@ class ModelUserImport extends Model {
/* or add the new user */ /* 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']); array_push($uids, $user['uid']);
$rc = $this->model_user_user->add_user($user); $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 = array();
$user['uid'] = $this->model_user_user->get_next_uid(); $user['uid'] = $this->model_user_user->get_next_uid();
@ -317,6 +321,7 @@ class ModelUserImport extends Model {
$user['whitelist'] = ''; $user['whitelist'] = '';
$user['blacklist'] = ''; $user['blacklist'] = '';
$user['group'] = 0; $user['group'] = 0;
$user['samaccountname'] = $samaccountname;
return $user; 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)"); $query = $this->db->query("SELECT email FROM " . TABLE_EMAIL . " WHERE uid IN ($uids)");
foreach ($query->rows as $q) { foreach ($query->rows as $q) {
array_push($data, $q['email']); array_push($data, $q['email']);
} }
@ -290,7 +291,10 @@ class ModelUserUser extends Model {
$encrypted_password = crypt($user['password']); $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']; } if($query->error == 1 || $this->db->countAffected() == 0){ return $user['username']; }