PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/install/index.php

https://bitbucket.org/tduarte/atmailopen
PHP | 181 lines | 97 code | 37 blank | 47 comment | 16 complexity | 1167f58cce4ec576287b410e0e5f488d MD5 | raw file
  1. <?php
  2. session_start();
  3. // +----------------------------------------------------------------+
  4. // | install/index.php |
  5. // | |
  6. // | Function: Install script for @Mail webmail client |
  7. // +----------------------------------------------------------------+
  8. // | AtMail Open - Licensed under the Apache 2.0 Open-source License|
  9. // | http://opensource.org/licenses/apache2.0.php |
  10. // +----------------------------------------------------------------+
  11. // | Date: May 2006 |
  12. // +----------------------------------------------------------------+
  13. // Setup lib paths
  14. $path = dirname(dirname(__FILE__));
  15. set_include_path('.' . PATH_SEPARATOR . "$path/libs" . PATH_SEPARATOR . "$path/libs/Atmail" . PATH_SEPARATOR . "$path/libs/PEAR");
  16. // Report all errors except E_NOTICE
  17. error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
  18. if (file_exists('../libs/Atmail/Config.php'))
  19. include_once('../libs/Atmail/Config.php');
  20. $pref['installed'] = 0;
  21. // Security Check! Double check that the .htaccess file does not exist!!
  22. // If the directory under which we are installed has "AllowOverride none"
  23. // or "AccessFile" is not == ".htaccess" in httpd.conf then our .htaccess
  24. // will not have stopped access
  25. // Do before copying Config.php.default, otherwise will overwrite it!
  26. if (file_exists('.htaccess') || (isset($pref) && $pref['installed']))
  27. {
  28. echo <<<EOF
  29. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  30. <html><head>
  31. <title>@Mail already installed</title>
  32. </head><body>
  33. <h1>Install Error</h1>
  34. <p>The installer can not go any further as it seems you have already installed @Mail
  35. on your system.</p>
  36. <p>For added security the installer cannot proceed until you remove the
  37. webmail/install/.htaccess file. Once removed reload the browser to continue the installation.</p>
  38. </body></html>
  39. EOF;
  40. exit;
  41. }
  42. /*
  43. if (!file_exists('../../server-install.php'));
  44. {
  45. $vars['install_error'] = "Server mode package of @Mail detected. The Web-based installer cannot be run for this mode, please run via the command line as root: cd /usr/local/atmail/ ; php server-install.php ";
  46. $vars['install_error2'] = "If you only require to install the Webmail version of @Mail, delete the /usr/local/atmail/server-install.php script and reload the browser to continue";
  47. $vars['output'] = parse("html/english/install_error.html", $vars);
  48. echo parse("html/english/template.html", $vars);
  49. exit;
  50. }
  51. */
  52. if (!file_exists('../libs/Atmail/Config.php'))
  53. {
  54. if (!copy('../libs/Atmail/Config.php.default', '../libs/Atmail/Config.php'))
  55. {
  56. $libDir = dirname(dirname(__FILE__)) . '';
  57. $vars['php_version'] = PHP_VERSION;
  58. $vars['install_error'] = "Please ensure that $libDir is writable by webserver user. See the <a href='http://support.atmail.com/php/webmail-install.html'>installation documentation</a> for the complete tutorial on installing @Mail";
  59. $vars['install_error2'] = "To change the permissions run on the command-line: <p><em>chown -R [webserveruser] $libDir</em><p>Where [webserveruser] is the user which runs Apache ( Generally user apache, nobody or www )";
  60. $vars['output'] = parse("html/english/install_error.html", $vars);
  61. echo parse("html/english/template.html", $vars);
  62. exit;
  63. //die("Please ensure that $libDir is writable by webserver user. See the installation documentation for the complete tutorial on installing @Mail");
  64. }
  65. include_once('../libs/Atmail/Config.php');
  66. }
  67. // Initial check for PHP version >= 4.3.0
  68. if (version_compare(PHP_VERSION, '4.3.0', '<'))
  69. {
  70. $vars['php_version'] = PHP_VERSION;
  71. $vars['install_error'] = 'PHP Version not Supported';
  72. $vars['install_error2'] = "@Mail requires PHP version >= 4.3.0. Your version is {$vars['php_version']}, the installation cannot proceed until you install a more recent version of PHP";
  73. $vars['output'] = parse("html/english/install_error.html", $vars);
  74. echo parse("html/english/template.html", $vars);
  75. exit;
  76. }
  77. //$pref['opensource'] = 1;
  78. // Detect open-source version
  79. if (isset($pref['opensource']))
  80. define('ATMAIL_OPEN_SOURCE', 1);
  81. // Set session vars for extension checks
  82. $_SESSION['checked_extensions'] = 1;
  83. if (count($ext['opt']))
  84. {
  85. $_SESSION['missing_ext'] = $ext['opt'];
  86. }
  87. $_SESSION['pref']['version'] = $pref['version'];
  88. // Set our lang var if known
  89. $lang = isset($_SESSION['step1']['lang']) ? $_SESSION['step1']['lang'] : 'english';
  90. // If language $lang is not supported for installation script
  91. // default to english
  92. if (@is_dir("html/$lang") && $lang)
  93. $htmlPath = "html/$lang";
  94. else
  95. $htmlPath = 'html/english';
  96. // Set up a constant to prove to the install step scripts
  97. // that they have been included by this script
  98. define('ATMAIL_INSTALL_SCRIPT', 1);
  99. // Find out which step of the install is required
  100. $vars['step'] = $step = (!empty($_REQUEST['step'])) ? $_REQUEST['step'] : 0;
  101. if (file_exists("step$step.php"))
  102. {
  103. require_once("step$step.php");
  104. }
  105. else
  106. $vars['output'] = parse("$htmlPath/file_missing_error.html");
  107. // Output the page
  108. echo parse("$htmlPath/template.phtml", $vars);
  109. //
  110. // Functions
  111. //
  112. // Send user to a install step
  113. function gotoStep($step, $args=null)
  114. {
  115. if (is_array($args))
  116. {
  117. foreach ($args as $k => $v)
  118. $extra .= "&$k=$v";
  119. }
  120. $s = empty($_SERVER["HTTPS"]) ? "" : ($_SERVER["HTTPS"] == "on") ? "s" : "";
  121. $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
  122. $port = ($_SERVER['SERVER_PORT'] != '80') ? ':'.$_SERVER['SERVER_PORT'] : '';
  123. $location = $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['SCRIPT_NAME']."?step=$step$extra";
  124. header("Location: $location");
  125. exit;
  126. }
  127. // Parse a HTML/Template file, and expand all vars into a value
  128. function parse($file, $var=null)
  129. {
  130. // Make Config vars available
  131. global $pref, $reg, $domains, $settings;
  132. ob_start();
  133. include($file);
  134. $output = ob_get_contents();
  135. ob_end_clean();
  136. return $output;
  137. }
  138. function strleft($s1, $s2)
  139. {
  140. return substr($s1, 0, strpos($s1, $s2));
  141. }
  142. ?>