PageRenderTime 73ms CodeModel.GetById 43ms RepoModel.GetById 2ms app.codeStats 0ms

/branches/GSoC-config/squirrelmail/config/configure.php

#
PHP | 179 lines | 147 code | 15 blank | 17 comment | 6 complexity | 4449727a57bb98ab8884d98482df0d58 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * configure.php
  5. *
  6. * Command-line tool to configure SquirrelMail using the
  7. * new configuration engine.
  8. *
  9. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  10. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11. * @version $Id: configure.php 12592 2007-08-20 15:16:24Z bouchon $
  12. * @package squirrelmail
  13. */
  14. define('SM_PATH', realpath(dirname(__FILE__).'/..').'/');
  15. // Must be run from the command line
  16. // Should be compatible with PHP 4.2
  17. if(getenv('SERVER_NAME') || php_sapi_name() != 'cli')
  18. {
  19. die('This script must be run from the command line !');
  20. }
  21. // PHP 4.2 compatible, no effect on PHP 4.3+
  22. if(!defined('STDIN'))
  23. {
  24. define('STDIN',fopen("php://stdin","r"));
  25. define('STDOUT',fopen("php://stdout","r"));
  26. define('STDERR',fopen("php://stderr","r"));
  27. }
  28. function read_locale()
  29. {
  30. do
  31. {
  32. fwrite(STDOUT, "Local name [en_US] : ");
  33. fscanf(STDIN, "%s\n", $locale);
  34. if(empty($locale))
  35. return "en_US";
  36. if(!is_dir('../locale/'.$locale))
  37. {
  38. fwrite(STDOUT, "Can't find $locale in the locale/ folder !\n\n");
  39. $locale = "";
  40. }
  41. }
  42. while(!$locale);
  43. return $locale;
  44. }
  45. function read_string($prompt, $def='')
  46. {
  47. fwrite(STDOUT, "$prompt [$def] : ");
  48. fscanf(STDIN, "%s\n", $in);
  49. return (empty($in) ? $def : $in);
  50. }
  51. function read_password()
  52. {
  53. fwrite(STDOUT, "Administrator password [] : ");
  54. fscanf(STDIN, "%s\n", $pass);
  55. return (empty($pass) ? '' : md5($pass.'squirrelmail'));
  56. }
  57. function read_backend($sel = 'file')
  58. {
  59. $backends = array();
  60. $dir = opendir('../class/config');
  61. while($f = readdir($dir))
  62. {
  63. if(ereg('^([a-z]*)\.class\.php$', $f, $regs))
  64. {
  65. if($regs[1] != 'skeleton' && $regs[1] != 'configurator')
  66. $backends[] = $regs[1];
  67. }
  68. }
  69. foreach($backends as $i => $b)
  70. {
  71. fwrite(STDOUT, "$i. $b\n");
  72. }
  73. do
  74. {
  75. fwrite(STDOUT, "\nSelect a backend [$sel] : ");
  76. fscanf(STDIN, "%s\n", $in);
  77. if(empty($in)) $in=$sel;
  78. }
  79. while(!in_array($in, $backends));
  80. return $in;
  81. }
  82. if(!file_exists('toplevel_config.php'))
  83. {
  84. if(!($fp = fopen('toplevel_config.php','w')))
  85. {
  86. fwrite(STDERR, "\nThis script needs write access to the config directory.");
  87. fwrite(STDERR, "\nRun it again using the account used to unpack SquirrelMail's package.\n\n");
  88. die(1);
  89. }
  90. fwrite(STDOUT, "\nWelcome to SquirrelMail !\n\n");
  91. fwrite(STDOUT, "If you have installed a translation package, please enter\n");
  92. fwrite(STDOUT, "the name of your locale : <language_COUNTRY>. Leave blank to\n");
  93. fwrite(STDOUT, "default to english.\n\n");
  94. $locale = read_locale();
  95. // TODO :
  96. // Load locales at this point !
  97. fwrite(STDOUT, "\nSquirrelMail can be configured either from the command line,\n");
  98. fwrite(STDOUT, "or using the web-based configuration page.\n");
  99. fwrite(STDOUT, "If you want to use the web interface, you need to provide an\n");
  100. fwrite(STDOUT, "administrator password. This password only prevents outsiders to\n");
  101. fwrite(STDOUT, "access your settings. If you don't provide a password, the web\n");
  102. fwrite(STDOUT, "interface will be disabled. \n\n");
  103. $pass = read_password();
  104. if($pass)
  105. {
  106. fwrite(STDOUT, "\nYou may set the charset to use in the web interface.\n\n");
  107. $charset = read_string('Default charset', 'iso-8859-1');
  108. }
  109. else
  110. {
  111. $charset = 'iso-8859-1';
  112. }
  113. fwrite(STDOUT, "\nBy default, SquirrelMail uses a configuration file to store its settings.\n");
  114. fwrite(STDOUT, "If you want to select another backend to store configuration variables, please\n");
  115. fwrite(STDOUT, "Select it in the list below :\n\n");
  116. $backend = read_backend();
  117. require_once "../class/config/$backend.class.php";
  118. fwrite($fp, '; This is the top-level configuration file of SquirrelMail. <?php die(); ?>'."\n\n");
  119. fwrite($fp, "admin_password = \"$pass\"\n");
  120. fwrite($fp, "squirrelmail_default_language = \"$locale\"\n");
  121. fwrite($fp, "default_charset = \"$charset\"\n");
  122. fwrite($fp, "config_backend = \"$backend\"\n");
  123. fwrite($fp, call_user_func("configure_backend_$backend"));
  124. fclose($fp);
  125. fwrite(STDOUT, "\nCongratulation, SquirrelMail is now ready to be configured.\n");
  126. if($pass)
  127. {
  128. fwrite(STDOUT, "You can now browse to the admin/ folder of your SquirrelMail installation.\n");
  129. }
  130. else
  131. {
  132. fwrite(STDOUT, "Run this tool again to start command line configuration.\n");
  133. }
  134. die(0);
  135. }
  136. // ADD COMMAND LINE CONFIGURATION TOOL HERE
  137. if(!is_writable('toplevel_config.php'))
  138. {
  139. fwrite(STDERR, "\nThis script needs write access to the config directory.");
  140. fwrite(STDERR, "\nRun it again using the account used to unpack SquirrelMail's package.\n\n");
  141. die(1);
  142. }
  143. fwrite(STDERR, "Command line configuration not implemented.\n");
  144. ?>