Added support for wildcard domains

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2020-10-31 21:10:41 +01:00
parent b5a8255be1
commit bfeef2669e
3 changed files with 83 additions and 49 deletions

View File

@ -53,6 +53,11 @@ class ControllerUserSettings extends Controller {
if($auditgroups) { $this->data['groups'] = $auditgroups; } else { $this->data['groups'] = $this->data['text_none_found']; }
if($auditfolders) { $this->data['folders'] = $auditfolders; } else { $this->data['folders'] = $this->data['text_none_found']; }
$this->data['wildcard_domains'] = $session->get("wildcard_domains");
if($this->data['wildcard_domains']) {
$this->data['wildcard_domains'] = implode(", ", $this->data['wildcard_domains']);
}
if(isset($this->request->post['pagelen']) && isset($this->request->post['theme'])) {
$this->model_user_prefs->set_user_preferences(Registry::get('username'), $this->request->post);

View File

@ -81,8 +81,14 @@ class ModelSearchSearch extends Model {
if(ENABLE_FOLDER_RESTRICTIONS == 1) { return ""; }
$all_your_addresses = $this->get_all_your_address();
return sprintf(" (%s %s | %s %s) ", FROM_TOKEN, $all_your_addresses, TO_TOKEN, $all_your_addresses);
$all_your_addresses = $this->get_all_your_address("emails");
$all_your_wildcard_domains = $this->get_all_your_address("wildcard_domains");
if($all_your_wildcard_domains) {
return sprintf(" ( (%s %s) | (%s %s) | (%s %s) | (%s %s) ) ", FROM_TOKEN, $all_your_addresses, TO_TOKEN, $all_your_addresses, FROMDOMAIN_TOKEN, $all_your_wildcard_domains, TODOMAIN_TOKEN, $all_your_wildcard_domains);
} else {
return sprintf(" ( (%s %s) | (%s %s) ) ", FROM_TOKEN, $all_your_addresses, TO_TOKEN, $all_your_addresses);
}
}
@ -645,12 +651,12 @@ class ModelSearchSearch extends Model {
}
private function get_all_your_address() {
private function get_all_your_address($session_var) {
$s = '';
$session = Registry::get('session');
$emails = $session->get("emails");
$emails = $session->get($session_var);
while(list($k, $v) = each($emails)) {
if($s) { $s .= '| ' . $this->fix_email_address_for_sphinx($v); }
@ -661,6 +667,25 @@ class ModelSearchSearch extends Model {
}
private function get_wildcard_domains($arr=[]) {
$query_suffix = '';
$results = $arr;
$session = Registry::get('session');
$wildcard_domains = $session->get('wildcard_domains');
if($wildcard_domains) {
$q = str_repeat('?,', count($wildcard_domains));
$q = trim($q, ',');
$results = array_merge($results, $wildcard_domains, $wildcard_domains);
$query_suffix = "OR fromdomain IN ($q) OR todomain IN ($q)";
}
return [$results, $query_suffix];
}
public function check_your_permission_by_id($id = '') {
$q = '';
$arr = $a = array();
@ -717,7 +742,8 @@ class ModelSearchSearch extends Model {
if(Registry::get('auditor_user') == 1 && RESTRICTED_AUDITOR == 1) {
$query = $this->db->query("SELECT id FROM " . VIEW_MESSAGES . " WHERE id=? AND ( `fromdomain` IN ($q) OR `todomain` IN ($q) )", $arr);
} else {
$query = $this->db->query("SELECT id FROM " . VIEW_MESSAGES . " WHERE id=? AND ( `from` IN ($q) OR `to` IN ($q) )", $arr);
[$arr, $query_suffix] = $this->get_wildcard_domains($arr);
$query = $this->db->query("SELECT id FROM " . VIEW_MESSAGES . " WHERE id=? AND ( `from` IN ($q) OR `to` IN ($q) $query_suffix )", $arr);
}
if(isset($query->row['id'])) { return 1; }
@ -796,7 +822,9 @@ class ModelSearchSearch extends Model {
}
}
$query = $this->db->query("SELECT id FROM `" . VIEW_MESSAGES . "` WHERE `id` IN ($q2) AND ( `from` IN ($q) OR `to` IN ($q) )", $arr);
[$arr, $query_suffix] = $this->get_wildcard_domains($arr);
$query = $this->db->query("SELECT id FROM `" . VIEW_MESSAGES . "` WHERE `id` IN ($q2) AND ( `from` IN ($q) OR `to` IN ($q) $query_suffix)", $arr);
}
}

View File

@ -7,8 +7,7 @@
<table class="table table-striped">
<tr>
<td class="span2"><?php print $text_email_addresses; ?>:</td>
<td class="span8">
<?php print $emails; ?>
<td class="span8"><?php print $emails; ?>
</td>
</tr>
@ -16,9 +15,7 @@
<tr>
<td><?php print $text_domains; ?>:</td>
<td>
<?php print $domains; ?>
</td>
<td><?php print $domains; ?></td>
</tr>
<?php } ?>
@ -27,20 +24,24 @@
<tr>
<td><?php print $text_groups; ?>:</td>
<td>
<?php print $groups; ?>
</td>
<td><?php print $groups; ?></td>
</tr>
<?php if($wildcard_domains) { ?>
<tr>
<td>Wildcard domains:</td>
<td><?php print $wildcard_domains; ?></td>
</tr>
<?php } ?>
<?php } ?>
<?php if(ENABLE_FOLDER_RESTRICTIONS == 1) { ?>
<tr>
<td><?php print $text_folders; ?>:</td>
<td>
<?php print $folders; ?>
</td>
<td><?php print $folders; ?></td>
</tr>
<?php } ?>