improved multitenancy support

This commit is contained in:
SJ
2013-01-05 16:42:36 +01:00
parent 7085f3c225
commit cafd477392
26 changed files with 417 additions and 39 deletions

View File

@ -9,6 +9,19 @@ class ModelDomainDomain extends Model {
}
public function get_domains_by_string($s = '', $page = 0, $page_len = PAGE_LEN) {
$from = (int)$page * (int)$page_len;
if(strlen($s) < 1) { return array(); }
$query = $this->db->query("SELECT domain FROM `" . TABLE_DOMAIN . "` WHERE domain LIKE ? ORDER BY domain ASC LIMIT " . (int)$from . ", " . (int)$page_len, array($s . "%") );
if(isset($query->rows)) { return $query->rows; }
return array();
}
public function deleteDomain($domain = '') {
if($domain == "") { return 0; }

View File

@ -90,6 +90,7 @@ class ModelSearchSearch extends Model {
$f = $t = $fdomain = $tdomain = '';
$session_emails = $this->fix_email_address_for_sphinx($_SESSION['emails']);
$session_domains = $this->fix_email_address_for_sphinx($_SESSION['auditdomains']);
$all_your_addresses = $this->get_all_your_address();
@ -176,9 +177,17 @@ class ModelSearchSearch extends Model {
if(Registry::get('auditor_user') == 1 || ENABLE_FOLDER_RESTRICTIONS == 1) {
$domain_restrictions = '';
$sd = '';
foreach ($session_domains as $d) {
$sd .= '|'.$d;
}
$sd = preg_replace("/^\|/", "", $sd);
if(RESTRICTED_AUDITOR == 1) {
$domain_restrictions = ' (@todomain ' . $this->fix_email_address_for_sphinx($_SESSION['domain']) . ' | @fromdomain ' . $this->fix_email_address_for_sphinx($_SESSION['domain']) . ')';
/* !!!FIXME!!! test this evaluation */
$domain_restrictions = ' (@todomain ' . $sd . ' | @fromdomain ' . $sd . ')';
}
if($from == '' && $to == '') { return $domain_restrictions; }
@ -588,8 +597,12 @@ class ModelSearchSearch extends Model {
array_push($arr, $id);
if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 1) {
$q = "?";
array_push($a, $_SESSION['domain']);
while(list($k, $v) = each($_SESSION['auditdomains'])) {
if(validdomain($v) == 1) {
$q .= ",?";
array_push($a, $v);
}
}
}
else {
while(list($k, $v) = each($_SESSION['emails'])) {
@ -598,10 +611,9 @@ class ModelSearchSearch extends Model {
array_push($a, $v);
}
}
$q = preg_replace("/^\,/", "", $q);
}
$q = preg_replace("/^\,/", "", $q);
$arr = array_merge($arr, $a, $a);
@ -639,8 +651,12 @@ class ModelSearchSearch extends Model {
$q2 = preg_replace("/^\,/", "", $q2);
if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 1) {
$q = "?";
array_push($a, $_SESSION['domain']);
while(list($k, $v) = each($_SESSION['auditdomains'])) {
if(validdomain($v) == 1) {
$q .= ",?";
array_push($a, $v);
}
}
}
else {
if(Registry::get('auditor_user') == 0) {
@ -651,10 +667,10 @@ class ModelSearchSearch extends Model {
}
}
}
$q = preg_replace("/^\,/", "", $q);
}
$q = preg_replace("/^\,/", "", $q);
if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 0) {
$query = $this->db->query("SELECT id FROM `" . TABLE_META . "` WHERE `id` IN ($q2)", $arr);

View File

@ -45,7 +45,7 @@ class ModelStatCounter extends Model {
}
}
$query = $this->db->query("UPDATE " . TABLE_COUNTER . " set `rcvd`=0, `virus`=0, `duplicate`=0, `ignore`=0");
$query = $this->db->query("UPDATE " . TABLE_COUNTER . " SET `rcvd`=0, `virus`=0, `duplicate`=0, `ignore`=0");
return 0;
}

View File

@ -38,6 +38,7 @@ class ModelUserAuth extends Model {
$_SESSION['domain'] = $query->row['domain'];
$_SESSION['realname'] = $query->row['realname'];
$_SESSION['auditdomains'] = $this->model_user_user->get_users_all_domains($query->row['uid']);
$_SESSION['emails'] = $this->model_user_user->get_users_all_email_addresses($query->row['uid']);
$_SESSION['folders'] = $this->model_folder_folder->get_all_folder_ids($query->row['uid']);
$_SESSION['extra_folders'] = $this->model_folder_folder->get_all_extra_folder_ids($query->row['uid']);

View File

@ -14,6 +14,7 @@ class ModelUserImport extends Model {
$mailAttrs = array("mail", "mailalternateaddress");
$memberAttrs = array("memberdn");
$filter="$mailAttr=*";
$ldap = new LDAP($host['ldap_host'], $host['ldap_binddn'], $host['ldap_bindpw']);
if($ldap->is_bind_ok() == 0) {
@ -25,16 +26,17 @@ class ModelUserImport extends Model {
LOGGER("LDAP type: " . $host['type']);
if($host['type'] == "AD") {
$attrs = array("cn", "samaccountname", "proxyaddresses", "member", "mail");
$attrs = array("cn", "samaccountname", "proxyaddresses", "member", "mail", "displayname");
$mailAttr = "proxyaddresses";
$mailAttrs = array("mail", "proxyaddresses");
$memberAttrs = array("member");
$filter="(&(objectClass=user)($mailAttr=*))";
}
$query = $ldap->query($host['ldap_basedn'], "$mailAttr=*", $attrs );
$query = $ldap->query($host['ldap_basedn'], $filter, $attrs );
LOGGER("LDAP query: $mailAttr=* for basedn:" . $host['ldap_basedn']);
foreach ($query->rows as $result) {
@ -87,9 +89,17 @@ class ModelUserImport extends Model {
}
$realname = '';
if($host['type'] == "AD") {
$realname = $result['displayname'];
} else {
$realname = $result['cn'];
}
$data[] = array(
'username' => preg_replace("/\n{1,}$/", "", $__emails[0]),
'realname' => $result['cn'],
'realname' => $realname,
'dn' => $result['dn'],
'samaccountname' => isset($result['samaccountname']) ? $result['samaccountname'] : '',
'emails' => preg_replace("/\n{1,}$/", "", $emails),

View File

@ -82,6 +82,23 @@ class ModelUserUser extends Model {
}
public function get_users_all_domains($uid = 0) {
$data = array();
if($uid > 0) {
$query = $this->db->query("SELECT domain FROM " . TABLE_DOMAIN_USER . " WHERE uid=?", array((int)$uid));
if(isset($query->rows)) {
foreach ($query->rows as $q) {
array_push($data, $q['domain']);
}
}
}
return $data;
}
public function get_additional_uids($uid = 0) {
$data = array();
@ -124,6 +141,19 @@ class ModelUserUser extends Model {
}
public function get_domains_by_uid($uid = 0) {
$domains = "";
$query = $this->db->query("SELECT domain FROM " . TABLE_DOMAIN_USER . " WHERE uid=?", array((int)$uid));
foreach ($query->rows as $q) {
$domains .= $q['domain'] . "\n";
}
return preg_replace("/\n$/", "", $domains);
}
public function get_primary_email_by_domain($uid = 0, $domain = '') {
$email = "";
@ -320,6 +350,7 @@ class ModelUserUser extends Model {
if($ret == 0) { return -2; }
}
$this->update_domains_settings((int)$user['uid'], $user['domains']);
$this->update_group_settings((int)$user['uid'], $user['group']);
$this->update_folder_settings((int)$user['uid'], $user['folder']);
@ -397,6 +428,7 @@ class ModelUserUser extends Model {
}
$this->update_domains_settings((int)$user['uid'], $user['domains']);
$this->update_group_settings((int)$user['uid'], $user['group']);
$this->update_folder_settings((int)$user['uid'], $user['folder']);
@ -404,6 +436,28 @@ class ModelUserUser extends Model {
}
private function update_domains_settings($uid = -1, $domains = '') {
$__d = array();
if($uid <= 0) { return 0; }
$query = $this->db->query("DELETE FROM `" . TABLE_DOMAIN_USER . "` WHERE uid=?", array($uid));
$all_domains = $this->get_email_domains();
$submitted_domains = explode("\n", $domains);
foreach($submitted_domains as $d) {
$d = trim($d);
if($d && checkdomain($d, $all_domains) > 0) {
$query = $this->db->query("INSERT INTO `" . TABLE_DOMAIN_USER . "` (domain, uid) VALUES(?,?)", array($d, (int)$uid));
}
}
return 1;
}
private function update_group_settings($uid = -1, $group = '') {
$__g = array();