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.

101 lines
2.8 KiB

  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at http://postfixadmin.sf.net
  10. *
  11. * @license GNU GPL v2 or later.
  12. *
  13. * File: common.php
  14. * All pages should include this file - which itself sets up the necessary
  15. * environment and ensures other functions are loaded.
  16. */
  17. if (!defined('POSTFIXADMIN')) { # already defined if called from setup.php
  18. define('POSTFIXADMIN', 1); # checked in included files
  19. if (!defined('POSTFIXADMIN_CLI')) {
  20. // this is the default; see also https://sourceforge.net/p/postfixadmin/bugs/347/
  21. session_cache_limiter('nocache');
  22. session_name('postfixadmin_session');
  23. session_start();
  24. if (empty($_SESSION['flash'])) {
  25. $_SESSION['flash'] = array();
  26. }
  27. // avoid clickjacking attacks?
  28. header('X-Frame-Options: DENY');
  29. }
  30. }
  31. $incpath = dirname(__FILE__);
  32. /**
  33. * @param string $class
  34. * __autoload implementation, for use with spl_autoload_register().
  35. */
  36. function postfixadmin_autoload($class) {
  37. $PATH = dirname(__FILE__) . '/model/' . $class . '.php';
  38. if (is_file($PATH)) {
  39. require_once($PATH);
  40. return true;
  41. }
  42. return false;
  43. }
  44. spl_autoload_register('postfixadmin_autoload');
  45. if (!is_file("$incpath/config.inc.php")) {
  46. die("config.inc.php is missing!");
  47. }
  48. global $CONF;
  49. require_once("$incpath/config.inc.php");
  50. if (isset($CONF['configured']) && !defined('PHPUNIT_TEST')) {
  51. if ($CONF['configured'] == false) {
  52. die("Please edit config.local.php - change \$CONF['configured'] to true after specifying appropriate local settings (database_type etc)");
  53. }
  54. }
  55. Config::getInstance()->setAll($CONF);
  56. $PALANG = [];
  57. require_once("$incpath/languages/language.php");
  58. require_once("$incpath/functions.inc.php");
  59. if (defined('POSTFIXADMIN_CLI')) {
  60. $language = 'en'; # TODO: make configurable or autodetect from locale settings
  61. } else {
  62. $language = check_language(); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-)
  63. $_SESSION['lang'] = $language;
  64. }
  65. if (!empty($language)) {
  66. require_once("$incpath/languages/" . $language . ".lang");
  67. }
  68. if (!empty($CONF['language_hook']) && function_exists($CONF['language_hook'])) {
  69. $hook_func = $CONF['language_hook'];
  70. $PALANG = $hook_func($PALANG, $language);
  71. }
  72. Config::write('__LANG', $PALANG);
  73. if (!defined('POSTFIXADMIN_CLI')) {
  74. if (!isset($PALANG)) {
  75. die("environment not setup correctly");
  76. }
  77. require_once(__DIR__ . '/lib/smarty/libs/Autoloader.php');
  78. Smarty_Autoloader::register();
  79. }
  80. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */