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.

110 lines
3.5 KiB

11 months ago
  1. <?php
  2. require_once(dirname(__FILE__) . '/vendor/autoload.php');
  3. /**
  4. * Postfix Admin
  5. *
  6. * LICENSE
  7. * This source file is subject to the GPL license that is bundled with
  8. * this package in the file LICENSE.TXT.
  9. *
  10. * Further details on the project are available at https://github.com/postfixadmin/postfixadmin
  11. *
  12. * @license GNU GPL v2 or later.
  13. *
  14. * File: common.php
  15. * All pages should include this file - which itself sets up the necessary
  16. * environment and ensures other functions are loaded.
  17. */
  18. // See: https://github.com/postfixadmin/postfixadmin/pull/541 - try and check if the user has a turkish locale and warn?
  19. $old = setlocale(LC_ALL, 'C');
  20. if (preg_match('/_TR/i', $old)) {
  21. error_log("WARNING: You may have a Turkish locale set; this breaks the loading of some libraries (Smarty) we depend upon.");
  22. // don't revert back to $old?
  23. } else {
  24. setlocale(LC_ALL, $old); // revert back.
  25. }
  26. if (!defined('POSTFIXADMIN')) {
  27. define('POSTFIXADMIN', 1);
  28. if (!defined('POSTFIXADMIN_CLI')) { // postfixadmin-cli
  29. // this is the default; see also https://sourceforge.net/p/postfixadmin/bugs/347/
  30. session_cache_limiter('nocache');
  31. /**
  32. * @see https://github.com/postfixadmin/postfixadmin/issues/903
  33. */
  34. $cookie_params = session_get_cookie_params();
  35. $cookie_params['samesite'] = 'Strict';
  36. $cookie_params['httponly'] = true;
  37. // Is this worthwhile? a non https request will get a non 'secure' cookie.
  38. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
  39. $cookie_params['secure'] = true;
  40. }
  41. session_set_cookie_params($cookie_params);
  42. session_name('postfixadmin_session');
  43. session_start();
  44. if (empty($_SESSION['flash'])) {
  45. $_SESSION['flash'] = array();
  46. }
  47. // avoid clickjacking attacks?
  48. header('X-Frame-Options: DENY');
  49. // see https://github.com/postfixadmin/postfixadmin/issues/905
  50. header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:");
  51. }
  52. }
  53. $incpath = dirname(__FILE__);
  54. if (!is_file("$incpath/config.inc.php")) {
  55. die("config.inc.php is missing!");
  56. }
  57. global $CONF;
  58. require_once("$incpath/config.inc.php");
  59. if (isset($CONF['configured']) && !defined('PHPUNIT_TEST')) {
  60. if ($CONF['configured'] == false) {
  61. die("Please edit config.local.php - change \$CONF['configured'] to true after specifying appropriate local settings (database_type etc)");
  62. }
  63. }
  64. Config::getInstance()->setAll($CONF);
  65. $PALANG = [];
  66. require_once("$incpath/languages/language.php");
  67. require_once("$incpath/functions.inc.php");
  68. if (defined('POSTFIXADMIN_CLI')) {
  69. $language = 'en'; # TODO: make configurable or autodetect from locale settings
  70. } else {
  71. $language = check_language(); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-)
  72. $_SESSION['lang'] = $language;
  73. }
  74. if (!empty($language)) {
  75. require_once("$incpath/languages/" . $language . ".lang");
  76. }
  77. if (!empty($CONF['language_hook']) && function_exists($CONF['language_hook'])) {
  78. $hook_func = $CONF['language_hook'];
  79. $PALANG = $hook_func($PALANG, $language);
  80. }
  81. Config::write('__LANG', $PALANG);
  82. if (!defined('POSTFIXADMIN_CLI')) {
  83. if (!isset($PALANG)) {
  84. die("environment not setup correctly");
  85. }
  86. Smarty_Autoloader::register();
  87. }
  88. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */