diff --git a/util/db-mysql.sql b/util/db-mysql.sql index c5185fe6..651a0354 100644 --- a/util/db-mysql.sql +++ b/util/db-mysql.sql @@ -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` ( diff --git a/util/db-upgrade-0.1.21-vs-0.1.22.sql b/util/db-upgrade-0.1.21-vs-0.1.22.sql new file mode 100644 index 00000000..05432ab8 --- /dev/null +++ b/util/db-upgrade-0.1.21-vs-0.1.22.sql @@ -0,0 +1,2 @@ +alter table `user` add column `samaccountname` char(64) default null; + diff --git a/webui/model/user/import.php b/webui/model/user/import.php index 0ac52d8a..eb01917b 100644 --- a/webui/model/user/import.php +++ b/webui/model/user/import.php @@ -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,12 +86,14 @@ class ModelUserImport extends Model { } + $data[] = array( - 'username' => preg_replace("/\n{1,}$/", "", $__emails[0]), - 'realname' => $result['cn'], - 'dn' => $result['dn'], - 'emails' => preg_replace("/\n{1,}$/", "", $emails), - 'members' => preg_replace("/\n{1,}$/", "", $members) + '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; } diff --git a/webui/model/user/user.php b/webui/model/user/user.php index 68aaba07..7c727f94 100644 --- a/webui/model/user/user.php +++ b/webui/model/user/user.php @@ -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']; }