functions.presets.inc.php 1.1 KB

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