functions.presets.inc.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/Spyc.php';
  3. function presets($_action, $_data = null)
  4. {
  5. if ($_SESSION['mailcow_cc_role'] !== 'admin') {
  6. $_SESSION['return'][] = [
  7. 'type' => 'danger',
  8. 'log' => [__FUNCTION__, $_action, $_data_log],
  9. 'msg' => 'access_denied',
  10. ];
  11. return false;
  12. }
  13. global $lang;
  14. if ($_action === 'get') {
  15. $kind = strtolower(trim($_data));
  16. if (!in_array($kind, ['rspamd', 'sieve'], true)) {
  17. return [];
  18. }
  19. $presets = [];
  20. foreach (glob(__DIR__ . '/presets/' . $kind . '/*.yml') as $filename) {
  21. $preset = Spyc::YAMLLoad($filename);
  22. /* get translated headlines */
  23. if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) {
  24. $textName = trim(substr($preset['headline'], 5));
  25. if ($kind === 'rspamd') {
  26. $preset['headline'] = $lang['admin'][$textName];
  27. } elseif ($kind === 'sieve') {
  28. $preset['headline'] = $lang['mailbox'][$textName];
  29. }
  30. }
  31. $presets[] = $preset;
  32. }
  33. return $presets;
  34. }
  35. return [];
  36. }