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.

common.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * @version $Id$
  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. if (!defined('POSTFIXADMIN')) { # already defined if called from setup.php
  19. define('POSTFIXADMIN', 1); # checked in included files
  20. if (!defined('POSTFIXADMIN_CLI')) {
  21. // this is the default; see also https://sourceforge.net/p/postfixadmin/bugs/347/
  22. session_cache_limiter('nocache');
  23. session_name('postfixadmin_session');
  24. session_start();
  25. if (empty($_SESSION['flash'])) {
  26. $_SESSION['flash'] = array();
  27. }
  28. }
  29. }
  30. $incpath = dirname(__FILE__);
  31. (ini_get('magic_quotes_gpc') ? ini_set('magic_quotes_runtime', '0') : '1');
  32. (ini_get('magic_quotes_gpc') ? ini_set('magic_quotes_sybase', '0') : '1');
  33. if (ini_get('register_globals') == 'on') {
  34. die("Please turn off register_globals; edit your php.ini");
  35. }
  36. /**
  37. * @param string $class
  38. * __autoload implementation, for use with spl_autoload_register().
  39. */
  40. function postfixadmin_autoload($class) {
  41. $PATH = dirname(__FILE__) . '/model/' . $class . '.php';
  42. if (is_file($PATH)) {
  43. require_once($PATH);
  44. return true;
  45. }
  46. return false;
  47. }
  48. spl_autoload_register('postfixadmin_autoload');
  49. if (!is_file("$incpath/config.inc.php")) {
  50. die("config.inc.php is missing!");
  51. }
  52. require_once("$incpath/config.inc.php");
  53. if (isset($CONF['configured'])) {
  54. if ($CONF['configured'] == false) {
  55. die("Please edit config.local.php - change \$CONF['configured'] to true after setting your database settings");
  56. }
  57. }
  58. Config::write($CONF);
  59. require_once("$incpath/languages/language.php");
  60. require_once("$incpath/functions.inc.php");
  61. if(extension_loaded('Phar')) {
  62. require_once("$incpath/lib/random_compat.phar");
  63. }
  64. if (defined('POSTFIXADMIN_CLI')) {
  65. $language = 'en'; # TODO: make configurable or autodetect from locale settings
  66. } else {
  67. $language = check_language(); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-)
  68. $_SESSION['lang'] = $language;
  69. }
  70. require_once("$incpath/languages/" . $language . ".lang");
  71. if (!empty($CONF['language_hook']) && function_exists($CONF['language_hook'])) {
  72. $hook_func = $CONF['language_hook'];
  73. $PALANG = $hook_func($PALANG, $language);
  74. }
  75. Config::write('__LANG', $PALANG);
  76. unset($incpath);
  77. if (!defined('POSTFIXADMIN_CLI')) {
  78. if (!is_file(dirname(__FILE__) . "/lib/smarty.inc.php")) {
  79. die("smarty.inc.php is missing! Something is wrong...");
  80. }
  81. require_once(dirname(__FILE__) . "/lib/smarty.inc.php");
  82. }
  83. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */