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.

379 lines
10 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 :
  10. * http://www.postfixadmin.com or http://postfixadmin.sf.net
  11. *
  12. * @version $Id$
  13. * @license GNU GPL v2 or later.
  14. *
  15. * File: setup.php
  16. * Used to help ensure a server is setup appropriately during installation/setup.
  17. * After setup, it should be renamed or removed.
  18. *
  19. * Template File: -none-
  20. *
  21. * Template Variables: -none-
  22. *
  23. * Form POST \ GET Variables: -none-
  24. */
  25. define('POSTFIXADMIN', 1); # checked in included files
  26. require_once("languages/en.lang");
  27. require_once("functions.inc.php");
  28. $CONF['show_header_text'] = 'NO';
  29. $CONF['theme_logo'] = 'images/logo-default.png';
  30. $CONF['theme_css'] = 'css/default.css';
  31. require('templates/header.php');
  32. ?>
  33. <div class='setup'>
  34. <h2>Postfix Admin Setup Checker</h2>
  35. <p>Running software:
  36. <ul>
  37. <?php
  38. //
  39. // Check for availablilty functions
  40. //
  41. $f_phpversion = function_exists ("phpversion");
  42. $f_apache_get_version = function_exists ("apache_get_version");
  43. $f_get_magic_quotes_gpc = function_exists ("get_magic_quotes_gpc");
  44. $f_mysql_connect = function_exists ("mysql_connect");
  45. $f_mysqli_connect = function_exists ("mysqli_connect");
  46. $f_pg_connect = function_exists ("pg_connect");
  47. $f_session_start = function_exists ("session_start");
  48. $f_preg_match = function_exists ("preg_match");
  49. $f_mb_encode_mimeheader = function_exists ("mb_encode_mimeheader");
  50. $f_imap_open = function_exists ("imap_open");
  51. $file_config = file_exists (realpath ("./config.inc.php"));
  52. $error = 0;
  53. //
  54. // Check for PHP version
  55. //
  56. if ($f_phpversion == 1)
  57. {
  58. if (phpversion() < 5) {
  59. print "<li><b>Error: Depends on: PHP v5</b><br /></li>\n";
  60. $error += 1;
  61. }
  62. if (phpversion() >= 5) {
  63. $phpversion = 5;
  64. print "<li>PHP version " . phpversion () . "</li>\n";
  65. }
  66. }
  67. else
  68. {
  69. print "<li><b>Unable to check for PHP version. (missing function: phpversion())</b></li>\n";
  70. }
  71. //
  72. // Check for Apache version
  73. //
  74. if ($f_apache_get_version == 1)
  75. {
  76. print "<li>" . apache_get_version() . "</li>\n";
  77. }
  78. else
  79. {
  80. # not running on Apache.
  81. # However postfixadmin _is_ running, so obviously we are on a supported webserver ;-))
  82. # No need to confuse the user with a warning.
  83. }
  84. print "</ul>";
  85. print "<p>Checking for dependencies:\n";
  86. print "<ul>\n";
  87. //
  88. // Check for Magic Quotes
  89. //
  90. if ($f_get_magic_quotes_gpc == 1)
  91. {
  92. if (get_magic_quotes_gpc () == 0)
  93. {
  94. print "<li>Magic Quotes: Disabled - OK</li>\n";
  95. }
  96. else
  97. {
  98. print "<li><b>Warning: Magic Quotes: ON (internal workaround used)</b></li>\n";
  99. }
  100. }
  101. else
  102. {
  103. print "<li><b>Unable to check for Magic Quotes. (missing function: get_magic_quotes_gpc())</b></li>\n";
  104. }
  105. //
  106. // Check for config.inc.php
  107. //
  108. $config_loaded = 0;
  109. if ($file_config == 1)
  110. {
  111. print "<li>Depends on: presence config.inc.php - OK</li>\n";
  112. require_once('config.inc.php');
  113. $config_loaded = 1;
  114. require('config.inc.php');
  115. if(isset($CONF['configured'])) {
  116. if($CONF['configured'] == TRUE) {
  117. print "<li>Checking \$CONF['configured'] - OK\n";
  118. } else {
  119. print "<li><b>Warning: \$CONF['configured'] is 'false'.<br>\n";
  120. print "You must edit your config.inc.php and change this to true (this indicates you've created the database and user)</b>\n";
  121. }
  122. }
  123. }
  124. else
  125. {
  126. print "<li><b>Error: Depends on: presence config.inc.php - NOT FOUND</b><br /></li>\n";
  127. print "Create the file, and edit as appropriate (e.g. select database type etc)<br />";
  128. print "For example:<br />\n";
  129. print "<code><pre>cp config.inc.php.sample config.inc.php</pre></code>\n";
  130. $error =+ 1;
  131. }
  132. //
  133. // Check if there is support for at least 1 database
  134. //
  135. if (($f_mysql_connect == 0) and ($f_mysqli_connect == 0) and ($f_pg_connect == 0))
  136. {
  137. print "<li><b>Error: There is no database support in your PHP setup</b><br />\n";
  138. print "To install MySQL 3.23 or 4.0 support on FreeBSD:<br />\n";
  139. print "<pre>% cd /usr/ports/databases/php$phpversion-mysql/\n";
  140. print "% make clean install\n";
  141. print " - or with portupgrade -\n";
  142. print "% portinstall php$phpversion-mysql</pre>\n";
  143. if ($phpversion >= 5)
  144. {
  145. print "To install MySQL 4.1 support on FreeBSD:<br />\n";
  146. print "<pre>% cd /usr/ports/databases/php5-mysqli/\n";
  147. print "% make clean install\n";
  148. print " - or with portupgrade -\n";
  149. print "% portinstall php5-mysqli</pre>\n";
  150. }
  151. print "To install PostgreSQL support on FreeBSD:<br />\n";
  152. print "<pre>% cd /usr/ports/databases/php$phpversion-pgsql/\n";
  153. print "% make clean install\n";
  154. print " - or with portupgrade -\n";
  155. print "% portinstall php$phpversion-pgsql</pre></li>\n";
  156. $error =+ 1;
  157. }
  158. //
  159. // MySQL 3.23, 4.0 functions
  160. //
  161. if ($f_mysql_connect == 1)
  162. {
  163. print "<li>Depends on: MySQL 3.23, 4.0 - OK</li>\n";
  164. }
  165. //
  166. // MySQL 4.1 functions
  167. //
  168. if ($phpversion >= 5)
  169. {
  170. if ($f_mysqli_connect == 1)
  171. {
  172. print "<li>Depends on: MySQL 4.1 - OK\n";
  173. if ( !($config_loaded && $CONF['database_type'] == 'mysqli') ) {
  174. print "(change the database_type to 'mysqli' in config.inc.php!!)\n";
  175. }
  176. print "</li>";
  177. }
  178. }
  179. //
  180. // PostgreSQL functions
  181. //
  182. if ($f_pg_connect == 1)
  183. {
  184. print "<li>Depends on: PostgreSQL - OK \n";
  185. if ( !($config_loaded && $CONF['database_type'] == 'pgsql') ) {
  186. print "(change the database_type to 'pgsql' in config.inc.php!!)\n";
  187. }
  188. print "</li>";
  189. }
  190. //
  191. // Database connection
  192. //
  193. if ($config_loaded) {
  194. list ($link, $error_text) = db_connect(TRUE);
  195. if ($error_text == "") {
  196. print "<li>Testing database connection - OK - {$CONF['database_type']}://{$CONF['database_user']}:xxxxx@{$CONF['database_host']}/{$CONF['database_name']}</li>";
  197. } else {
  198. print "<li><b>Error: Can't connect to database</b><br />\n";
  199. print "Please edit the \$CONF['database_*'] parameters in config.inc.php.\n";
  200. print "$error_text</li>\n";
  201. $error ++;
  202. }
  203. }
  204. //
  205. // Session functions
  206. //
  207. if ($f_session_start == 1)
  208. {
  209. print "<li>Depends on: session - OK</li>\n";
  210. }
  211. else
  212. {
  213. print "<li><b>Error: Depends on: session - NOT FOUND</b><br />\n";
  214. print "To install session support on FreeBSD:<br />\n";
  215. print "<pre>% cd /usr/ports/www/php$phpversion-session/\n";
  216. print "% make clean install\n";
  217. print " - or with portupgrade -\n";
  218. print "% portinstall php$phpversion-session</pre></li>\n";
  219. $error =+ 1;
  220. }
  221. //
  222. // PCRE functions
  223. //
  224. if ($f_preg_match == 1)
  225. {
  226. print "<li>Depends on: pcre - OK</li>\n";
  227. }
  228. else
  229. {
  230. print "<li><b>Error: Depends on: pcre - NOT FOUND</b><br />\n";
  231. print "To install pcre support on FreeBSD:<br />\n";
  232. print "<pre>% cd /usr/ports/devel/php$phpversion-pcre/\n";
  233. print "% make clean install\n";
  234. print " - or with portupgrade -\n";
  235. print "% portinstall php$phpversion-pcre</pre></li>\n";
  236. $error =+ 1;
  237. }
  238. //
  239. // Multibyte functions
  240. //
  241. if ( $f_mb_encode_mimeheader == 1 )
  242. {
  243. print "<li>Depends on: multibyte string - OK</li>\n";
  244. }
  245. else
  246. {
  247. print "<li><b>Error: Depends on: multibyte string - NOT FOUND</b><br />\n";
  248. print "To install multibyte string support, install php$phpversion-mbstring</li>\n";
  249. $error =+ 1;
  250. }
  251. //
  252. // Imap functions
  253. //
  254. if ( $f_imap_open == 1)
  255. {
  256. print "<li>Depends on: IMAP functions - OK</li>\n";
  257. }
  258. else
  259. {
  260. print "<li><b>Warning: Depends on: IMAP functions - NOT FOUND</b><br />\n";
  261. print "To install IMAP support, install php$phpversion-imap<br />\n";
  262. print "Without IMAP support, you won't be able to create subfolders when creating mailboxes.</li>\n";
  263. # $error =+ 1;
  264. }
  265. print "</ul>";
  266. if ($error != 0)
  267. {
  268. print "<p><b>Please fix the errors listed above.</b></p>";
  269. }
  270. else
  271. {
  272. print "<p>Everything seems fine... attempting to create/update database structure</p>\n";
  273. require_once('upgrade.php');
  274. $pAdminCreate_admin_username_text = $PALANG['pAdminCreate_admin_username_text'];
  275. $pAdminCreate_admin_password_text = "";
  276. $tUsername = '';
  277. $tMessage = '';
  278. if ($_SERVER['REQUEST_METHOD'] == "POST")
  279. {
  280. if (isset ($_POST['fUsername'])) $fUsername = escape_string ($_POST['fUsername']);
  281. if (isset ($_POST['fPassword'])) $fPassword = escape_string ($_POST['fPassword']);
  282. if (isset ($_POST['fPassword2'])) $fPassword2 = escape_string ($_POST['fPassword2']);
  283. // XXX need to ensure domains table includes an 'ALL' entry.
  284. $table_domain = table_by_key('domain');
  285. $r = db_query("SELECT * FROM $table_domain WHERE domain = 'ALL'");
  286. if($r['rows'] == 0) {
  287. db_insert($table_domain, array('domain' => 'ALL')); // all other fields should default through the schema.
  288. }
  289. list ($error, $tMessage, $pAdminCreate_admin_username_text, $pAdminCreate_admin_password_text) = create_admin($fUsername, $fPassword, $fPassword2, array('ALL'), TRUE);
  290. if ($error != 0) {
  291. if (isset ($_POST['fUsername'])) $tUsername = escape_string ($_POST['fUsername']);
  292. } else {
  293. print "<p><b>$tMessage</b></p>";
  294. echo "<p><b>Delete (or rename) setup.php, and then click <a href='login.php'>here to login</a>.</b></p>";
  295. }
  296. }
  297. if ($_SERVER['REQUEST_METHOD'] == "GET" || $error != 0)
  298. {
  299. ?>
  300. <div id="edit_form">
  301. <form name="create_admin" method="post">
  302. <table>
  303. <tr>
  304. <td colspan="3"><h3>Create superadmin account</h3></td>
  305. </tr>
  306. <tr>
  307. <td><?php print $PALANG['pAdminCreate_admin_username'] . ":"; ?></td>
  308. <td><input class="flat" type="text" name="fUsername" value="<?php print $tUsername; ?>" /></td>
  309. <td><?php print $pAdminCreate_admin_username_text; ?></td>
  310. </tr>
  311. <tr>
  312. <td><?php print $PALANG['pAdminCreate_admin_password'] . ":"; ?></td>
  313. <td><input class="flat" type="password" name="fPassword" /></td>
  314. <td><?php print $pAdminCreate_admin_password_text; ?></td>
  315. </tr>
  316. <tr>
  317. <td><?php print $PALANG['pAdminCreate_admin_password2'] . ":"; ?></td>
  318. <td><input class="flat" type="password" name="fPassword2" /></td>
  319. <td>&nbsp;</td>
  320. </tr>
  321. <tr>
  322. <td colspan="3" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php print $PALANG['pAdminCreate_admin_button']; ?>" /></td>
  323. </tr>
  324. <tr>
  325. <td colspan="3" class="standout"><?php print $tMessage; ?></td>
  326. </tr>
  327. </table>
  328. </form>
  329. </div>
  330. <?php
  331. }
  332. print "<b>Make sure you delete this setup.php file!</b><br />\n";
  333. print "Also check the config.inc.php file for any settings that you might need to change!<br />\n";
  334. }
  335. ?>
  336. </div>
  337. </body>
  338. </html>
  339. <?php
  340. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  341. ?>