mailcow/data/web/inc/ajax/regex_validation.php
andryyy b52ee0a706
[Rspamd] Fix map permissions for www
[Web] Allow to manage global maps in UI (WIP)
2019-10-29 08:39:57 +01:00

26 lines
914 B
PHP

<?php
session_start();
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
header('Content-Type: application/json');
if (!isset($_SESSION['mailcow_cc_role'])) {
exit();
}
if (isset($_GET['regex'])) {
$regex_lines = preg_split("/(\r\n|\n|\r)/", $_GET['regex']);
foreach ($regex_lines as $line => $regex) {
if (empty($regex) || substr($regex, 0, 1) == "#") {
continue;
}
if (empty($regex) || substr($regex, 0, 1) != "/") {
echo json_encode(array('type' => 'danger', 'msg' => 'Line ' . ($line + 1) . ': Invalid regex'));
exit();
}
if (@preg_match($regex, 'Lorem Ipsum') === false) {
echo json_encode(array('type' => 'danger', 'msg' => 'Line ' . ($line + 1) . ': Invalid regex "' . $regex . '"'));
exit();
}
}
echo json_encode(array('type' => 'success', 'msg' => $lang['add']['validation_success']));
}
?>