[Rspamd] Pushover, check sender by regex

master
andryyy 2020-04-16 21:58:30 +02:00
parent 7fa10cc3b4
commit 47a15c21aa
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
9 changed files with 82 additions and 21 deletions

View File

@ -201,7 +201,15 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) {
$attributes = json_decode($api_data['attributes'], true);
$senders = explode(',', $api_data['senders']);
$senders = array_filter($senders);
$senders_regex = $api_data['senders_regex'];
$sender_validated = true;
if (!empty($senders_regex) && !preg_match($senders_regex, $sender)) {
$sender_validated = false;
}
if (!empty($senders) && !in_array($sender, $senders)) {
$sender_validated = false;
}
if ($sender_validated === false) {
error_log("NOTIFY: pushover pipe: skipping unwanted sender " . $sender);
continue;
}

View File

@ -738,7 +738,6 @@ if (isset($_SESSION['mailcow_cc_role'])) {
<input type="hidden" value="0" name="evaluate_x_prio">
<input type="hidden" value="0" name="only_x_prio">
<input type="hidden" value="0" name="active">
<input type="hidden" value="" name="senders">
<div class="row">
<div class="col-sm-1">
<p class="help-block"><a href="https://pushover.net" target="_blank"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAACglBMVEUAAAAAAAEAAAAilecFGigAAAAAAAAAAAAAAAANj+c3n+Ypm+oeYI4KWI4MieAtkdQbleoJcLcjmeswmN4Rit4KgdMKUYQJKUAQSnILL0kMNlMSTngimOoNPF0hlOQBBgkNOlkRS3MHIjUhk+IPf8wKLUYsjM0AAAASTngAAAAAAAAPfckbdLIbdrYUWIgegsgce70knfEAAAAknfENOVkGHi8YaaIjnvEdgMUhkuAQSG8aca0hleQUh9YLjOM4nOEMgtMcbaYWa6YemO02ltkKhNktgLodYZEPXJEyi8kKesktfLUzj84cWYMiluckZ5YJXJYeW4Y0k9YKfs4yjs0pc6YHZaUviskLfMkqmugak+cqkNcViNcqeK4Iaq4XRmYGPmYMKDsFJTstgr0LdL0ti84CCQ4BCQ4Qgc8rlt8XjN8shcQsi8wZSGg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 @@ if (isset($_SESSION['mailcow_cc_role'])) {
<input type="text" class="form-control" name="senders" value="<?=$pushover_data['senders'];?>" placeholder="sender1@example.com, sender2@example.com">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="text"><?=$lang['admin']['pushover_sender_regex'];?></label>
<input type="text" class="form-control" name="senders_regex" value="<?=$pushover_data['senders_regex'];?>" placeholder="(.*@example\.org|foo@example\.com)" regex="true">
</div>
</div>
<div class="col-sm-12">
<div class="checkbox">
<label><input type="checkbox" value="1" name="evaluate_x_prio" <?=($pushover_data['attributes']['evaluate_x_prio']=="1") ? "checked" : null;?>> <?=$lang['edit']['evaluate_x_prio'];?></label>

View File

@ -1,4 +1,7 @@
<?php
function is_valid_regex($exp) {
return @preg_match($exp, '') !== false;
}
function isset_has_content($var) {
if (isset($var) && $var != "") {
return true;

View File

@ -41,11 +41,35 @@ function pushover($_action, $_data = null) {
);
continue;
}
$key = $_data['key'];
$token = $_data['token'];
$evaluate_x_prio = $_data['evaluate_x_prio'];
$only_x_prio = $_data['only_x_prio'];
$senders = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['senders']));
$is_now = pushover('get', $username);
if (!empty($is_now)) {
$key = (!empty($_data['key'])) ? $_data['key'] : $is_now['key'];
$token = (!empty($_data['token'])) ? $_data['token'] : $is_now['token'];
$senders = (isset($_data['senders'])) ? $_data['senders'] : $is_now['senders'];
$senders_regex = (isset($_data['senders_regex'])) ? $_data['senders_regex'] : $is_now['senders_regex'];
$title = (!empty($_data['title'])) ? $_data['title'] : $is_now['title'];
$text = (!empty($_data['text'])) ? $_data['text'] : $is_now['text'];
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active'];
$evaluate_x_prio = (isset($_data['evaluate_x_prio'])) ? intval($_data['evaluate_x_prio']) : $is_now['evaluate_x_prio'];
$only_x_prio = (isset($_data['only_x_prio'])) ? intval($_data['only_x_prio']) : $is_now['only_x_prio'];
}
else {
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
'msg' => 'access_denied'
);
continue;
}
if (!empty($senders_regex) && !is_valid_regex($senders_regex)) {
$_SESSION['return'][] = array(
'type' => 'danger',
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
'msg' => 'Invalid regex'
);
continue;
}
$senders = array_map('trim', preg_split( "/( |,|;|\n)/", $senders));
foreach ($senders as $i => &$sender) {
if (empty($sender)) {
continue;
@ -75,21 +99,19 @@ function pushover($_action, $_data = null) {
);
continue;
}
$title = $_data['title'];
$text = $_data['text'];
$active = intval($_data['active']);
$po_attributes = json_encode(
array(
'evaluate_x_prio' => strval(intval($evaluate_x_prio)),
'only_x_prio' => strval(intval($only_x_prio))
)
);
$stmt = $pdo->prepare("REPLACE INTO `pushover` (`username`, `key`, `attributes`, `senders`, `token`, `title`, `text`, `active`)
VALUES (:username, :key, :po_attributes, :senders, :token, :title, :text, :active)");
$stmt = $pdo->prepare("REPLACE INTO `pushover` (`username`, `key`, `attributes`, `senders_regex`, `senders`, `token`, `title`, `text`, `active`)
VALUES (:username, :key, :po_attributes, :senders_regex, :senders, :token, :title, :text, :active)");
$stmt->execute(array(
':username' => $username,
':key' => $key,
':po_attributes' => $po_attributes,
':senders_regex' => $senders_regex,
':senders' => $senders,
':token' => $token,
':title' => $title,

View File

@ -3,7 +3,7 @@ function init_db_schema() {
try {
global $pdo;
$db_version = "16042020_1004";
$db_version = "16042020_2104";
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
@ -841,6 +841,7 @@ function init_db_schema() {
"title" => "TEXT",
"text" => "TEXT",
"senders" => "TEXT",
"senders_regex" => "TEXT",
"active" => "TINYINT(1) NOT NULL DEFAULT '1'"
),
"keys" => array(

View File

@ -4,6 +4,7 @@ $(document).ready(function() {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function validateRegex(e){var t=e.split("/"),n=e,r="";t.length>1&&(n=t[1],r=t[2]);try{return new RegExp(n,r),!0}catch(e){return!1}}
function is_active(elem) {
if ($(elem).data('submitted') == '1') {
return true;
@ -134,6 +135,18 @@ $(document).ready(function() {
}
}
}
if ($(this).val() && $(this).attr("regex")) {
var regex_content = $(this).val();
$(this).removeClass('inputMissingAttr');
if(!validateRegex(regex_content)) {
invalid = true;
$(this).addClass('inputMissingAttr');
}
if(!regex_content.startsWith('/') || !/\/[ims]?$/.test(regex_content)){
invalid = true;
$(this).addClass('inputMissingAttr');
}
}
});
if (!invalid) {
var attr_to_merge = $(this).closest("form").serializeObject();

View File

@ -237,8 +237,9 @@
"pushover_title": "Notification Titel",
"text": "Text",
"pushover_text": "Notification Text",
"pushover_vars": "Verwendbare Variablen für Titel und Text (Datenschutzrichtlinien beachten)",
"pushover_sender_array": "Nur folgende Sender E-Mail-Adressen berücksichtigen <small>(getrennt durch Komma)</small>",
"pushover_vars": "Wenn kein Sender-Filter definiert ist, werden alle E-Mails berücksichtigt.<br>Die direkte Absenderprüfung und reguläre Ausdrücke werden unabhängig voneinander geprüft, sie <b>hängen nicht voneinander ab</b> und werden der Reihe nach ausgeführt. <br>Verwendbare Variablen für Titel und Text (Datenschutzrichtlinien beachten)",
"pushover_sender_array": "Folgende Sender E-Mail-Adressen berücksichtigen <small>(getrennt durch Komma)</small>",
"pushover_sender_regex": "Sender mit folgendem regulären Ausdruck auswählen",
"last_mail_login": "Letzter Mail-Login",
"no_last_login": "Keine letzte UI Anmeldung gespeichert",
"save": "Änderungen speichern",
@ -357,8 +358,9 @@
"pushover_title": "Notification Titel",
"text": "Text",
"pushover_text": "Notification Text",
"pushover_vars": "Verwendbare Variablen für Titel und Text (Datenschutzrichtlinien beachten)",
"pushover_sender_array": "Nur folgende Sender E-Mail-Adressen berücksichtigen <small>(getrennt durch Komma)</small>",
"pushover_vars": "Wenn kein Sender-Filter definiert ist, werden alle E-Mails berücksichtigt.<br>Die direkte Absenderprüfung und reguläre Ausdrücke werden unabhängig voneinander geprüft, sie <b>hängen nicht voneinander ab</b> und werden der Reihe nach ausgeführt. <br>Verwendbare Variablen für Titel und Text (Datenschutzrichtlinien beachten)",
"pushover_sender_array": "Folgende Sender E-Mail-Adressen berücksichtigen <small>(getrennt durch Komma)</small>",
"pushover_sender_regex": "Sender mit folgendem regulären Ausdruck auswählen",
"spamfilter": "Spamfilter",
"domain_s": "Domain(s)",
"rspamd-com_settings": "Ein Name wird automatisch generiert. Beispielinhalte zur Einsicht stehen nachstehend bereit. Siehe auch <a href=\"https://rspamd.com/doc/configuration/settings.html#settings-structure\" target=\"_blank\">Rspamd docs</a>",

View File

@ -237,8 +237,9 @@
"pushover_title": "Notification title",
"text": "Text",
"pushover_text": "Notification text",
"pushover_vars": "Useable variables for text and title (please take note of data protection)",
"pushover_sender_array": "Only consider the following sender email addresses <small>(comma-separated)</small>",
"pushover_vars": "When no sender filter is defined, all mails will be considered.<br>Regex filters as well as exact sender checks can be defined individually and will be considered sequentially. They do not depend on each other.<br>Useable variables for text and title (please take note of data protection policies)",
"pushover_sender_array": "Consider the following sender email addresses <small>(comma-separated)</small>",
"pushover_sender_regex": "Match senders by the following regex",
"no_last_login": "No last UI login information",
"last_mail_login": "Last mail login",
"save": "Save changes",
@ -357,8 +358,9 @@
"pushover_title": "Notification title",
"text": "Text",
"pushover_text": "Notification text",
"pushover_vars": "Useable variables for text and title (please take note of data protection)",
"pushover_vars": "When no sender filter is defined, all mails will be considered.<br>Regex filters as well as exact sender checks can be defined individually and will be considered sequentially. They do not depend on each other.<br>Useable variables for text and title (please take note of data protection policies)",
"pushover_sender_array": "Only consider the following sender email addresses <small>(comma-separated)</small>",
"pushover_sender_regex": "Consider the following sender regex",
"spamfilter": "Spam filter",
"domain": "Domain",
"domain_s": "Domain/s",

View File

@ -479,7 +479,6 @@ elseif (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == '
<input type="hidden" value="0" name="evaluate_x_prio">
<input type="hidden" value="0" name="only_x_prio">
<input type="hidden" value="0" name="active">
<input type="hidden" value="" name="senders">
<div class="row">
<div class="col-sm-1">
<p class="help-block"><a href="https://pushover.net" target="_blank"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAACglBMVEUAAAAAAAEAAAAilecFGigAAAAAAAAAAAAAAAANj+c3n+Ypm+oeYI4KWI4MieAtkdQbleoJcLcjmeswmN4Rit4KgdMKUYQJKUAQSnILL0kMNlMSTngimOoNPF0hlOQBBgkNOlkRS3MHIjUhk+IPf8wKLUYsjM0AAAASTngAAAAAAAAPfckbdLIbdrYUWIgegsgce70knfEAAAAknfENOVkGHi8YaaIjnvEdgMUhkuAQSG8aca0hleQUh9YLjOM4nOEMgtMcbaYWa6YemO02ltkKhNktgLodYZEPXJEyi8kKesktfLUzj84cWYMiluckZ5YJXJYeW4Y0k9YKfs4yjs0pc6YHZaUviskLfMkqmugak+cqkNcViNcqeK4Iaq4XRmYGPmYMKDsFJTstgr0LdL0ti84CCQ4BCQ4Qgc8rlt8XjN8shcQsi8wZSGgEP2cRMEUDKkUAAAD///8dmvEamfExo/EXmPEWl/ERlvElnvEsofEjnfETl/Enn/Ezo/E4pvEvovEfm/E1pPEzpPEvofEOlfEpoPEamPEQlfEYmfE6p/EgnPEVlvEroPE3pfE2pfENk/Ern/E3pPEcmfEfmvEnnvBlufT6/P0soPAknPDd7/zs9vzo9PxBqfItofAqoPD9/f3B4/q43/mx2/l/xfZ6w/Vxv/VtvfVgt/RXtPNTsfNEq/L3+/31+v3a7fvR6vvH5fqs2vmc0/jx+P3v9/3h8fzW7PvV7PvL5/q13fmo1/mh1PiY0fiNy/aHyfZ2wfVou/Vdt/RPsPM3oeoQkuowmeAgjdgcgMQbeLrw9/3k8vy74P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jUam0LBdp9ARwupFemTYudvgN/L1+A/Ko/LGBuS8pPy+YR1fuCTWNKnUyoeUyYx2o2dyEVGmr5xTD42xzvkD16+Pb9WIIH6fmt1r3mbsTY7Bvw+n23naT8BUWh86bz6G/e259UXPUK3gfAxQDlo7Rpx3Geqb2e3wp83SGEdKpB7zvwYbzvT2n65xLwbH6YP+M9C8vA8E1wxLU8gkCbdhXGUyrMgwVrcbzLHonr78lzDvWM3q/C/HtDlXoSUIe3YkblhRPIX4E8Oo/9siLv8dRjV7SBlkdgTXvKS7nzsA/9AfeEuhKq9T8zWIDv1Sd6ETAP4D6/H/1V+1BojvruNa4SZXz4JhY84dV5MOF5agUvu5OsOo+KRpG30KalEnoeDccFlutPZYs38D5n3zcpr1/0fBhfb3DOY1z2tSAgLxWezz6zuoHhfUmOejf6blHQH/sFuJYfcMZX307ytKvRa3ifoV/586P5j+tICtS77BuJxzxYAPZsntX8k3eSIhlajK4p8b7iefCEKs03kD/I2LnxL9ovH+43y4fAv1YrI/mzDBsavAX/UppfzVOrZT/ydxk6lJ047MfLfVbcb6hS9ZEzWxekKQ5WrtPqZg3rV6tWrX6Tle3KQZj/q6KxQnmDoXwFY0VSrN9e8FRXBCTAvwAAAABJRU5ErkJggg==" class="img img-fluid"></a></p>
@ -515,7 +514,13 @@ elseif (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == '
<div class="col-sm-6">
<div class="form-group">
<label for="text"><?=$lang['user']['pushover_sender_array'];?></label>
<input type="text" class="form-control" name="senders" value="<?=$pushover_data['senders'];?>">
<input type="text" class="form-control" name="senders" value="<?=$pushover_data['senders'];?>" placeholder="foo@example.com, bar@example.org">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="text"><?=$lang['user']['pushover_sender_regex'];?></label>
<input type="text" class="form-control" name="senders_regex" value="<?=$pushover_data['senders_regex'];?>" placeholder="/(.*@example\.org|foo@example\.com)/i" regex="true">
</div>
</div>
<div class="col-sm-12">