2
0

regex_validation.php 914 B

12345678910111213141516171819202122232425
  1. <?php
  2. session_start();
  3. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php';
  4. header('Content-Type: application/json');
  5. if (!isset($_SESSION['mailcow_cc_role'])) {
  6. exit();
  7. }
  8. if (isset($_GET['regex'])) {
  9. $regex_lines = preg_split("/(\r\n|\n|\r)/", $_GET['regex']);
  10. foreach ($regex_lines as $line => $regex) {
  11. if (empty($regex) || substr($regex, 0, 1) == "#") {
  12. continue;
  13. }
  14. if (empty($regex) || substr($regex, 0, 1) != "/") {
  15. echo json_encode(array('type' => 'danger', 'msg' => 'Line ' . ($line + 1) . ': Invalid regex'));
  16. exit();
  17. }
  18. if (@preg_match($regex, 'Lorem Ipsum') === false) {
  19. echo json_encode(array('type' => 'danger', 'msg' => 'Line ' . ($line + 1) . ': Invalid regex "' . $regex . '"'));
  20. exit();
  21. }
  22. }
  23. echo json_encode(array('type' => 'success', 'msg' => $lang['add']['validation_success']));
  24. }
  25. ?>