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.

90 lines
2.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. define('POSTFIXADMIN', 1);
  3. define('POSTFIXADMIN_CLI', 1);
  4. require_once(dirname(__FILE__) . '/../vendor/autoload.php');
  5. require_once(dirname(__FILE__) . '/../common.php');
  6. $CONF['default_language'] = 'en';
  7. $CONF['language_hook'] = '';
  8. if (getenv('DATABASE') == 'sqlite' || getenv('DATABASE') == false) {
  9. $db_file = dirname(__FILE__) . '/postfixadmin.sqlite.test';
  10. $CONF['database_type'] = 'sqlite';
  11. $CONF['database_name'] = $db_file;
  12. Config::write('database_type', 'sqlite');
  13. Config::write('database_name', $db_file);
  14. clearstatcache();
  15. if (file_exists($db_file)) {
  16. unlink($db_file);
  17. }
  18. touch($db_file);
  19. error_log("Using: SQLite database for tests - $db_file");
  20. }
  21. if (getenv('DATABASE') == 'postgresql') {
  22. $user = getenv('PGUSER') ?: 'postgres';
  23. $pass = getenv('PGPASSWORD') ?: '';
  24. $host = getenv('PGHOST') ?: 'localhost';
  25. $CONF['database_type'] = 'pgsql';
  26. $CONF['database_user'] = $user;
  27. $CONF['database_password'] = $pass;
  28. $CONF['database_host'] = $host;
  29. $CONF['database_name'] = 'postfixadmin';
  30. Config::write('database_type', 'pgsql');
  31. Config::write('database_user', $user);
  32. Config::write('database_password', $pass);
  33. Config::write('database_name', 'postfixadmin');
  34. Config::write('database_host', $host);
  35. error_log("Using: PostgreSQL database for tests\n");
  36. }
  37. if (getenv('DATABASE') == 'mysql') {
  38. $expand_tilde = function ($path) {
  39. if (function_exists('posix_getuid') && strpos($path, '~') !== false) {
  40. $info = posix_getpwuid(posix_getuid());
  41. $path = str_replace('~', $info['dir'], $path);
  42. }
  43. return $path;
  44. };
  45. $config = parse_ini_file($expand_tilde('~/.my.cnf'));
  46. if (empty($config)) {
  47. $config = ['user' => 'root', 'host' => '127.0.0.1', 'password' => ''];
  48. }
  49. if (isset($config['socket'])) {
  50. $CONF['database_socket'] = $config['socket'];
  51. Config::write('database_socket', $config['socket']);
  52. } else {
  53. $CONF['database_host'] = $config['host'];
  54. Config::write('database_host', $config['host']);
  55. }
  56. $CONF['database_type'] = 'mysql';
  57. $CONF['database_user'] = $config['user'];
  58. $CONF['database_password'] = $config['password'];
  59. $CONF['database_name'] = 'postfixadmin';
  60. Config::write('database_type', 'mysql');
  61. Config::write('database_user', $config['user']);
  62. Config::write('database_password', $config['password']);
  63. Config::write('database_name', 'postfixadmin');
  64. error_log("Using: MySQL database for tests");
  65. }
  66. try {
  67. $db = db_connect();
  68. } catch (Exception $e) {
  69. echo "failed to connect to database\n";
  70. echo $e->getMessage();
  71. exit(1);
  72. }
  73. require_once(dirname(__FILE__) . '/../public/upgrade.php');