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.

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