PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.4 KiB

  1. <?php
  2. require_once ("$incpath/smarty/libs/Smarty.class.php");
  3. /**
  4. * Turn on sanitisation of all data by default so it's not possible for XSS flaws to occur in PFA
  5. */
  6. class PFASmarty {
  7. protected $template = null;
  8. public function __construct() {
  9. $this->template = new Smarty();
  10. //$this->template->debugging = true;
  11. $incpath = dirname(__FILE__);
  12. $this->template->template_dir = $incpath.'/templates';
  13. $this->template->compile_dir = $incpath.'/templates_c';
  14. $this->template->config_dir = $incpath.'/'.$this->template->config_dir;
  15. $this->template->allow_php_tag = true;
  16. }
  17. public function assign($key, $value, $sanitise = true) {
  18. if($sanitise == false) {
  19. return $this->template->assign($key, $value);
  20. }
  21. $clean = $this->sanitise($value);
  22. /* we won't run the key through sanitise() here... some might argue we should */
  23. return $this->template->assign($key, $clean);
  24. }
  25. public function display($template) {
  26. $this->template->display($template);
  27. }
  28. /**
  29. * Recursive cleaning of data, using htmlentities - this assumes we only ever output to HTML and we're outputting in UTF-8 charset
  30. *
  31. * @param mixed $data - array or primitive type; objects not supported.
  32. * @return mixed $data
  33. * */
  34. public function sanitise($data) {
  35. if(!is_array($data)) {
  36. return htmlentities($data, ENT_QUOTES, 'UTF-8', false);
  37. }
  38. if(is_array($data)) {
  39. $clean = array();
  40. foreach($data as $key => $value) {
  41. /* as this is a nested data structure it's more likely we'll output the key too (at least in my opinion, so we'll sanitise it too */
  42. $clean[$this->sanitise($key)] = $this->sanitise($value);
  43. }
  44. return $clean;
  45. }
  46. }
  47. }
  48. $smarty = new PFASmarty();
  49. $CONF['theme_css'] = $CONF['postfix_admin_url'].'/'.htmlentities($CONF['theme_css']);
  50. $CONF['theme_logo'] = $CONF['postfix_admin_url'].'/'.htmlentities($CONF['theme_logo']);
  51. $smarty->assign ('CONF', $CONF);
  52. $smarty->assign ('PALANG', $PALANG);
  53. $smarty->assign('url_domain', '');
  54. //*** footer.tpl
  55. $smarty->assign ('version', $version);
  56. //*** menu.tpl
  57. $smarty->assign ('boolconf_alias_domain', boolconf('alias_domain'));
  58. $smarty->assign ('authentication_has_role', array ('global_admin' => authentication_has_role ('global-admin'), 'admin' => authentication_has_role ('admin'), 'user' => authentication_has_role ('user')));
  59. if (authentication_has_role('global-admin')) {
  60. $motd_file = "motd-admin.txt";
  61. } else {
  62. $motd_file = "motd.txt";
  63. }
  64. $smarty->assign('motd_file', '');
  65. if (file_exists ($CONF ['postfix_admin_path'].'/templates/'.$motd_file)) {
  66. $smarty->assign ('motd_file', $motd_file);
  67. }
  68. function select_options($aValues, $aSelected) {
  69. $ret_val = '';
  70. foreach ($aValues as $val) {
  71. $ret_val .= '<option value="'.$val.'"';
  72. if (in_array ($val, $aSelected))
  73. $ret_val .= ' selected="selected"';
  74. $ret_val .= '>'.$val.'</option>';
  75. }
  76. return $ret_val;
  77. }
  78. function eval_size ($aSize) {
  79. if ($aSize == 0) {$ret_val = $GLOBALS ['PALANG']['pOverview_unlimited']; }
  80. elseif ($aSize < 0) {$ret_val = $GLOBALS ['PALANG']['pOverview_disabled']; }
  81. else {$ret_val = $aSize; }
  82. return $ret_val;
  83. }
  84. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  85. ?>