functions.presets.inc.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. $langSection = 'admin';
  17. if (!in_array($kind, ['admin-rspamd', 'mailbox-sieve'], true)) {
  18. return [];
  19. }
  20. if ($kind === 'mailbox-sieve') {
  21. $langSection = 'mailbox';
  22. }
  23. $presets = [];
  24. foreach (glob(__DIR__ . '/presets/' . $kind . '/*.yml') as $filename) {
  25. $preset = Spyc::YAMLLoad($filename);
  26. /* get translated headlines */
  27. if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) {
  28. $langTextName = trim(substr($preset['headline'], 5));
  29. if (isset($lang[$langSection][$langTextName])) {
  30. $preset['headline'] = $lang[$langSection][$langTextName];
  31. }
  32. }
  33. $presets[] = $preset;
  34. }
  35. return $presets;
  36. }
  37. return [];
  38. }