mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-24 19:30:12 +01:00
introduced a new group management feature
This commit is contained in:
parent
d79b1f97c7
commit
bdae1bab9d
@ -224,9 +224,9 @@ create table if not exists `group` (
|
||||
|
||||
create table if not exists `group_user` (
|
||||
`id` bigint unsigned not null,
|
||||
`uid` int unsigned not null,
|
||||
`email` char(128) not null,
|
||||
key `group_user_idx` (`id`),
|
||||
key `group_user_idx2` (`uid`)
|
||||
key `group_user_idx2` (`email`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
|
@ -36,3 +36,13 @@ create unique index `entry` on archiving_rule (`domain`,`from`,`to`,`subject`,`_
|
||||
|
||||
create unique index `entry` on retention_rule (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`);
|
||||
|
||||
-- 2014.07.05
|
||||
drop table if exists `group_user`;
|
||||
|
||||
create table if not exists `group_user` (
|
||||
`id` bigint unsigned not null,
|
||||
`email` char(128) not null,
|
||||
key `group_user_idx` (`id`),
|
||||
key `group_user_idx2` (`email`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
@ -70,6 +70,10 @@ class ControllerGroupAdd extends Controller {
|
||||
$this->error['email'] = $this->data['text_missing_data'];
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['assigned_email']) || $this->request->post['assigned_email'] == '') {
|
||||
$this->error['assigned_email'] = $this->data['text_missing_data'];
|
||||
}
|
||||
|
||||
if (!$this->error) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -59,6 +59,7 @@ class ControllerGroupEdit extends Controller {
|
||||
else {
|
||||
$this->data['group'] = $this->model_group_group->get_domain_by_id($this->data['id']);
|
||||
$this->data['email'] = $this->model_group_group->get_emails_by_group_id($this->data['id']);
|
||||
$this->data['assigned_email'] = $this->model_group_group->get_assigned_emails_by_group_id($this->data['id']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -83,6 +84,10 @@ class ControllerGroupEdit extends Controller {
|
||||
$this->error['email'] = $this->data['text_missing_data'];
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['assigned_email']) || $this->request->post['assigned_email'] == '') {
|
||||
$this->error['assigned_email'] = $this->data['text_missing_data'];
|
||||
}
|
||||
|
||||
if(!isset($this->request->post['id']) || !is_numeric($this->request->post['id']) || (int)$this->request->post['id'] < 0) {
|
||||
$this->error['id'] = $this->data['text_invalid_data'];
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ class ControllerUserEdit extends Controller {
|
||||
|
||||
$this->data['user']['domains'] = $this->model_user_user->get_domains_by_uid($this->data['uid']);
|
||||
$this->data['user']['group_membership'] = $this->model_user_user->get_additional_uids($this->data['uid']);
|
||||
$this->data['user']['group'] = $this->model_group_group->get_groups_by_uid($this->data['uid']);
|
||||
$this->data['user']['folder'] = $this->model_folder_folder->get_folders_by_uid($this->data['uid']);
|
||||
|
||||
$this->data['emails'] = $this->model_user_user->get_emails($this->data['user']['username']);
|
||||
|
||||
$this->data['user']['group'] = $this->model_group_group->get_groups_by_email(array($this->data['emails']));
|
||||
//}
|
||||
}
|
||||
else {
|
||||
|
@ -39,7 +39,7 @@ class ControllerUserSettings extends Controller {
|
||||
}
|
||||
$auditdomains = preg_replace("/^,\s/", "", $auditdomains);
|
||||
|
||||
$auditgroups = preg_replace("/\s/", ", ", $this->model_group_group->get_groups_by_uid($session->get("uid")));
|
||||
$auditgroups = preg_replace("/\s/", ", ", $this->model_group_group->get_groups_by_email($session->get("emails")));
|
||||
|
||||
$folders = $session->get("folders");
|
||||
|
||||
|
@ -45,6 +45,19 @@ class ModelGroupGroup extends Model {
|
||||
public function get_emails_by_group_id($id = 0) {
|
||||
$emails = '';
|
||||
|
||||
$query = $this->db->query("SELECT `email` FROM `" . TABLE_GROUP_USER . "` WHERE id=?", array($id));
|
||||
|
||||
foreach ($query->rows as $q) {
|
||||
$emails .= $q['email'] . "\n";
|
||||
}
|
||||
|
||||
return preg_replace("/\n$/", "", $emails);
|
||||
}
|
||||
|
||||
|
||||
public function get_assigned_emails_by_group_id($id = 0) {
|
||||
$emails = '';
|
||||
|
||||
$query = $this->db->query("SELECT `email` FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id));
|
||||
|
||||
foreach ($query->rows as $q) {
|
||||
@ -86,11 +99,19 @@ class ModelGroupGroup extends Model {
|
||||
foreach ($emails as $email) {
|
||||
$email = rtrim($email);
|
||||
if(validemail($email)) {
|
||||
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($gid, $email));
|
||||
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, email) VALUES(?,?)", array($gid, $email));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$emails = explode("\n", $group['assigned_email']);
|
||||
foreach ($emails as $email) {
|
||||
$email = rtrim($email);
|
||||
if(validemail($email)) {
|
||||
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($gid, $email));
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER("add group: " . $group['groupname'] . ", id=" . (int)$gid);
|
||||
|
||||
return 1;
|
||||
@ -102,17 +123,30 @@ class ModelGroupGroup extends Model {
|
||||
|
||||
$query = $this->db->query("UPDATE `" . TABLE_GROUP . "` SET `groupname`=? WHERE id=?", array($group['groupname'], (int)$group['id']));
|
||||
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($group['id']));
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE id=?", array($group['id']));
|
||||
|
||||
$emails = explode("\n", $group['email']);
|
||||
foreach ($emails as $email) {
|
||||
$email = rtrim($email);
|
||||
|
||||
if(validemail($email)) {
|
||||
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, email) VALUES(?,?)", array($group['id'], $email));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($group['id']));
|
||||
|
||||
$emails = explode("\n", $group['assigned_email']);
|
||||
foreach ($emails as $email) {
|
||||
$email = rtrim($email);
|
||||
|
||||
if(validemail($email)) {
|
||||
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_EMAIL . "` (id, email) VALUES(?,?)", array($group['id'], $email));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->db->countAffected();
|
||||
}
|
||||
|
||||
@ -132,11 +166,13 @@ class ModelGroupGroup extends Model {
|
||||
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_EMAIL . "` WHERE id=?", array($id));
|
||||
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE id=?", array($id));
|
||||
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP . "` WHERE id=?", array((int)$id));
|
||||
|
||||
LOGGER("remove group: id=$id");
|
||||
|
||||
return $this->db->countAffected();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -214,10 +250,15 @@ class ModelGroupGroup extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function get_groups_by_uid($uid = 0) {
|
||||
public function get_groups_by_email($email = array()) {
|
||||
$groups = '';
|
||||
$q = '?';
|
||||
|
||||
$query = $this->db->query("SELECT `" . TABLE_GROUP_USER . "`.id, groupname FROM `" . TABLE_GROUP_USER . "`, `" . TABLE_GROUP . "` WHERE `" . TABLE_GROUP_USER . "`.id=`" . TABLE_GROUP . "`.id AND uid=?", array($uid) );
|
||||
for($i=1; $i<count($email); $i++) {
|
||||
$q .= ',?';
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT `" . TABLE_GROUP_USER . "`.id, groupname FROM `" . TABLE_GROUP_USER . "`, `" . TABLE_GROUP . "` WHERE `" . TABLE_GROUP_USER . "`.id=`" . TABLE_GROUP . "`.id AND email IN ($q)", $email);
|
||||
|
||||
if(isset($query->rows)) {
|
||||
foreach ($query->rows as $q) { $groups .= "\n" . $q['groupname']; }
|
||||
|
@ -129,6 +129,9 @@ class ModelUserAuth extends Model {
|
||||
|
||||
$emails = $this->get_email_array_from_ldap_attr($query->rows);
|
||||
|
||||
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
|
||||
$emails = array_merge($emails, $extra_emails);
|
||||
|
||||
$this->add_session_vars($a['cn'], $username, $emails, $role);
|
||||
|
||||
AUDIT(ACTION_LOGIN, $username, '', '', 'successful auth against LDAP');
|
||||
@ -270,6 +273,7 @@ class ModelUserAuth extends Model {
|
||||
|
||||
private function checkLoginAgainstIMAP($username = '', $password = '') {
|
||||
$session = Registry::get('session');
|
||||
$emails = array($username);
|
||||
|
||||
if(!strchr($username, '@')) { return 0; }
|
||||
|
||||
@ -277,7 +281,10 @@ class ModelUserAuth extends Model {
|
||||
if($imap->login($username, $password)) {
|
||||
$imap->logout();
|
||||
|
||||
$this->add_session_vars($username, $username, array($username), 0);
|
||||
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
|
||||
$emails = array_merge($emails, $extra_emails);
|
||||
|
||||
$this->add_session_vars($username, $username, $emails, 0);
|
||||
|
||||
$session->set("password", $password);
|
||||
|
||||
@ -290,6 +297,7 @@ class ModelUserAuth extends Model {
|
||||
|
||||
private function checkLoginAgainstPOP3($username = '', $password = '') {
|
||||
$rc = 0;
|
||||
$emails = array($username);
|
||||
|
||||
try {
|
||||
$conn = new Zend_Mail_Protocol_Pop3(POP3_HOST, POP3_PORT, POP3_SSL);
|
||||
@ -302,7 +310,10 @@ class ModelUserAuth extends Model {
|
||||
try {
|
||||
$conn->login($username, $password);
|
||||
|
||||
$this->add_session_vars($username, $username, array($username), 0);
|
||||
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
|
||||
$emails = array_merge($emails, $extra_emails);
|
||||
|
||||
$this->add_session_vars($username, $username, $emails, 0);
|
||||
$rc = 1;
|
||||
}
|
||||
catch (Zend_Mail_Protocol_Exception $e) {}
|
||||
@ -351,6 +362,9 @@ class ModelUserAuth extends Model {
|
||||
|
||||
$emails = $this->get_email_array_from_ldap_attr($query->rows);
|
||||
|
||||
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails));
|
||||
$emails = array_merge($emails, $extra_emails);
|
||||
|
||||
if($this->check_ldap_membership($ldap_auditor_member_dn, $query->rows) == 1) { $role = 2; }
|
||||
if($this->check_ldap_membership($ldap_admin_member_dn, $query->rows) == 1) { $role = 1; }
|
||||
|
||||
|
@ -69,8 +69,7 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
$query = $this->db->query("SELECT `" . TABLE_GROUP_EMAIL . "`.email FROM `" . TABLE_GROUP_EMAIL . "`, `" . TABLE_GROUP_USER . "` WHERE `" . TABLE_GROUP_EMAIL . "`.id=`" . TABLE_GROUP_USER . "`.id and `" . TABLE_GROUP_USER . "`.uid=?", array($uid) );
|
||||
|
||||
$query = $this->db->query("SELECT g.email FROM `" . TABLE_GROUP_EMAIL . "` g WHERE g.id IN (SELECT u.id FROM `" . TABLE_GROUP_USER . "` u WHERE u.email IN (?))", $data);
|
||||
|
||||
if(isset($query->rows)) {
|
||||
foreach ($query->rows as $q) {
|
||||
@ -359,7 +358,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_group_settings($emails[0], $user['group']);
|
||||
$this->update_folder_settings((int)$user['uid'], $user['folder']);
|
||||
|
||||
return 1;
|
||||
@ -442,7 +441,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_group_settings($emails[0], $user['group']);
|
||||
$this->update_folder_settings((int)$user['uid'], $user['folder']);
|
||||
|
||||
return 1;
|
||||
@ -471,12 +470,14 @@ class ModelUserUser extends Model {
|
||||
}
|
||||
|
||||
|
||||
private function update_group_settings($uid = -1, $group = '') {
|
||||
private function update_group_settings($email = '', $group = '') {
|
||||
$__g = array();
|
||||
|
||||
if($uid <= 0) { return 0; }
|
||||
$email = rtrim($email);
|
||||
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE uid=?", array($uid));
|
||||
if($email == '') { return 0; }
|
||||
|
||||
$query = $this->db->query("DELETE FROM `" . TABLE_GROUP_USER . "` WHERE email=?", array($email));
|
||||
|
||||
$query = $this->db->query("SELECT id, groupname FROM `" . TABLE_GROUP . "`");
|
||||
|
||||
@ -492,7 +493,7 @@ class ModelUserUser extends Model {
|
||||
$g = rtrim($g);
|
||||
|
||||
if($g && !isset($__g[$groups[$g]])) {
|
||||
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, uid) VALUES(?,?)", array($groups[$g], (int)$uid));
|
||||
$query = $this->db->query("INSERT INTO `" . TABLE_GROUP_USER . "` (id, email) VALUES(?,?)", array($groups[$g], $email));
|
||||
$__g[$groups[$g]] = 1;
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,13 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="groupname"><?php print $text_assigned_email_addresses; ?>**:</label>
|
||||
<div class="controls">
|
||||
<textarea style="height:280px;" name="assigned_email" id="assigned_email" class="domain"><?php if(isset($assigned_email)){ print $assigned_email; } ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-info">*: <?php print $text_min_2_chars; ?><br />**: <?php print $text_enter_one_email_address_per_line; ?></div>
|
||||
|
||||
<div class="form-actions">
|
||||
|
@ -50,9 +50,16 @@
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="groupname"><?php print $text_email_addresses; ?>**:</label>
|
||||
<label class="control-label" for="groupname"><?php print $text_email_addresses; ?>**:</label>
|
||||
<div class="controls">
|
||||
<textarea style="height:280px;" name="email" id="email" class="domain"><?php if(isset($email)){ print $email; } ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="groupname"><?php print $text_assigned_email_addresses; ?>**:</label>
|
||||
<div class="controls">
|
||||
<textarea style="height:280px;" name="email" id="email" class="domain"><?php if(isset($email)){ print $email; } ?></textarea>
|
||||
<textarea style="height:280px;" name="assigned_email" id="assigned_email" class="domain"><?php if(isset($assigned_email)){ print $assigned_email; } ?></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user