2007-03-24 08:27:00 +01:00
< ? php
2007-09-30 17:53:54 +02:00
/**
* Postfix Admin
*
* LICENSE
* This source file is subject to the GPL license that is bundled with
* this package in the file LICENSE . TXT .
*
* Further details on the project are available at :
* http :// www . postfixadmin . com or http :// postfixadmin . sf . net
*
* @ version $Id $
* @ license GNU GPL v2 or later .
*
* File : setup . php
* Used to help ensure a server is setup appropriately during installation / setup .
* After setup , it should be renamed or removed .
*
* Template File : - none -
*
* Template Variables : - none -
*
* Form POST \ GET Variables : - none -
*/
2007-10-07 19:23:29 +02:00
2007-12-06 14:03:36 +01:00
define ( 'POSTFIXADMIN' , 1 ); # checked in included files
2007-10-07 19:23:29 +02:00
require_once ( " languages/en.lang " );
require_once ( " functions.inc.php " );
$CONF [ 'show_header_text' ] = 'NO' ;
2007-12-02 14:59:33 +01:00
require ( 'templates/header.php' );
2007-03-24 08:27:00 +01:00
?>
2007-10-07 19:23:29 +02:00
< div class = 'setup' >
< h2 > Postfix Admin Setup Checker </ h2 >
< p > Running software :
< ul >
2007-03-24 08:27:00 +01:00
< ? php
//
// Check for availablilty functions
//
$f_phpversion = function_exists ( " phpversion " );
$f_apache_get_version = function_exists ( " apache_get_version " );
$f_get_magic_quotes_gpc = function_exists ( " get_magic_quotes_gpc " );
$f_mysql_connect = function_exists ( " mysql_connect " );
$f_mysqli_connect = function_exists ( " mysqli_connect " );
$f_pg_connect = function_exists ( " pg_connect " );
$f_session_start = function_exists ( " session_start " );
$f_preg_match = function_exists ( " preg_match " );
2007-12-14 01:05:54 +01:00
$f_mb_encode_mimeheader = function_exists ( " mb_encode_mimeheader " );
2007-03-24 08:27:00 +01:00
$file_config = file_exists ( realpath ( " ./config.inc.php " ));
$error = 0 ;
//
// Check for PHP version
//
if ( $f_phpversion == 1 )
{
if ( phpversion () < 5 ) $phpversion = 4 ;
if ( phpversion () >= 5 ) $phpversion = 5 ;
2007-11-03 20:21:27 +01:00
print " <li>PHP version " . phpversion () . " </li> \n " ;
2007-03-24 08:27:00 +01:00
}
else
{
2007-11-03 20:21:27 +01:00
print " <li><b>Unable to check for PHP version. (missing function: phpversion())</b></li> \n " ;
2007-03-24 08:27:00 +01:00
}
//
// Check for Apache version
//
if ( $f_apache_get_version == 1 )
{
2007-11-03 20:21:27 +01:00
print " <li> " . apache_get_version () . " </li> \n " ;
2007-03-24 08:27:00 +01:00
}
else
{
2007-12-14 01:05:54 +01:00
print " <li><b>Unable to check for Apache version. (missing function: apache_get_version())<br />(Ignore this warning if you use another webserver software.)</b></li> \n " ;
2007-03-24 08:27:00 +01:00
}
2007-10-07 19:23:29 +02:00
print " </ul> " ;
print " <p>Checking for dependencies: \n " ;
print " <ul> \n " ;
2007-03-24 08:27:00 +01:00
//
// Check for Magic Quotes
//
if ( $f_get_magic_quotes_gpc == 1 )
{
2007-09-22 10:05:27 +02:00
if ( get_magic_quotes_gpc () == 0 )
2007-03-24 08:27:00 +01:00
{
2007-11-03 20:21:27 +01:00
print " <li>Magic Quotes: Disabled - OK</li> \n " ;
2007-03-24 08:27:00 +01:00
}
else
{
2007-11-03 20:21:27 +01:00
print " <li><b>Warning: Magic Quotes: ON (internal workaround used)</b></li> \n " ;
2007-03-24 08:27:00 +01:00
}
}
else
{
2007-11-03 20:21:27 +01:00
print " <li><b>Unable to check for Magic Quotes. (missing function: get_magic_quotes_gpc())</b></li> \n " ;
2007-03-24 08:27:00 +01:00
}
//
// Check for config.inc.php
//
2007-10-07 19:23:29 +02:00
$config_loaded = 0 ;
2007-03-24 08:27:00 +01:00
if ( $file_config == 1 )
{
2007-11-03 20:21:27 +01:00
print " <li>Depends on: presence config.inc.php - OK</li> \n " ;
2007-10-07 19:23:29 +02:00
require_once ( 'config.inc.php' );
$config_loaded = 1 ;
2008-01-06 20:47:45 +01:00
require ( 'config.inc.php' );
if ( isset ( $CONF [ 'configured' ])) {
if ( $CONF [ 'configured' ] == TRUE ) {
print " <li>Checking \$ CONF['configured'] - OK \n " ;
} else {
print " <li><b>Error: \$ CONF['configured'] is 'false'.<br> \n " ;
print " Please edit your config.inc.php settings and then change it.</b> \n " ;
}
}
2007-03-24 08:27:00 +01:00
}
else
{
2007-11-03 20:21:27 +01:00
print " <li><b>Error: Depends on: presence config.inc.php - NOT FOUND</b><br /></li> \n " ;
print " Create the file, and edit as appropriate (e.g. select database type etc)<br /> " ;
2007-03-24 08:27:00 +01:00
print " For example:<br /> \n " ;
2007-11-03 20:21:27 +01:00
print " <code><pre>cp config.inc.php.sample config.inc.php</pre></code> \n " ;
2007-03-24 08:27:00 +01:00
$error =+ 1 ;
}
//
// Check if there is support for at least 1 database
//
if (( $f_mysql_connect == 0 ) and ( $f_mysqli_connect == 0 ) and ( $f_pg_connect == 0 ))
{
print " <li><b>Error: There is no database support in your PHP setup</b><br /> \n " ;
print " To install MySQL 3.23 or 4.0 support on FreeBSD:<br /> \n " ;
print " <pre>% cd /usr/ports/databases/php $phpversion -mysql/ \n " ;
print " % make clean install \n " ;
print " - or with portupgrade - \n " ;
print " % portinstall php $phpversion -mysql</pre> \n " ;
if ( $phpversion >= 5 )
{
print " To install MySQL 4.1 support on FreeBSD:<br /> \n " ;
print " <pre>% cd /usr/ports/databases/php5-mysqli/ \n " ;
print " % make clean install \n " ;
print " - or with portupgrade - \n " ;
print " % portinstall php5-mysqli</pre> \n " ;
}
print " To install PostgreSQL support on FreeBSD:<br /> \n " ;
print " <pre>% cd /usr/ports/databases/php $phpversion -pgsql/ \n " ;
print " % make clean install \n " ;
print " - or with portupgrade - \n " ;
2007-11-03 20:21:27 +01:00
print " % portinstall php $phpversion -pgsql</pre></li> \n " ;
2007-03-24 08:27:00 +01:00
$error =+ 1 ;
}
//
// MySQL 3.23, 4.0 functions
//
if ( $f_mysql_connect == 1 )
{
2007-11-03 20:21:27 +01:00
print " <li>Depends on: MySQL 3.23, 4.0 - OK</li> \n " ;
2007-03-24 08:27:00 +01:00
}
//
// MySQL 4.1 functions
//
if ( $phpversion >= 5 )
{
if ( $f_mysqli_connect == 1 )
{
2007-10-07 19:23:29 +02:00
print " <li>Depends on: MySQL 4.1 - OK \n " ;
if ( ! ( $config_loaded && $CONF [ 'database_type' ] == 'mysqli' ) ) {
print " (change the database_type to 'mysqli' in config.inc.php!!) \n " ;
}
2007-11-03 20:21:27 +01:00
print " </li> " ;
2007-03-24 08:27:00 +01:00
}
}
//
// PostgreSQL functions
//
if ( $f_pg_connect == 1 )
{
2007-10-07 19:23:29 +02:00
print " <li>Depends on: PostgreSQL - OK \n " ;
if ( ! ( $config_loaded && $CONF [ 'database_type' ] == 'pgsql' ) ) {
print " (change the database_type to 'pgsql' in config.inc.php!!) \n " ;
}
2007-11-03 20:21:27 +01:00
print " </li> " ;
2007-10-07 19:23:29 +02:00
}
//
// Database connection
//
if ( $config_loaded ) {
list ( $link , $error_text ) = db_connect ( TRUE );
if ( $error_text == " " ) {
2007-11-03 20:21:27 +01:00
print " <li>Testing database connection - OK - { $CONF [ 'database_type' ] } :// { $CONF [ 'database_user' ] } :xxxxx@ { $CONF [ 'database_host' ] } / { $CONF [ 'database_name' ] } </li> " ;
2007-10-07 19:23:29 +02:00
} else {
print " <li><b>Error: Can't connect to database</b><br /> \n " ;
print " Please edit the \$ CONF['database_*'] parameters in config.inc.php. \n " ;
2007-11-03 20:21:27 +01:00
print " $error_text </li> \n " ;
2007-10-07 19:23:29 +02:00
$error ++ ;
}
2007-03-24 08:27:00 +01:00
}
//
// Session functions
//
if ( $f_session_start == 1 )
{
2007-11-03 20:21:27 +01:00
print " <li>Depends on: session - OK</li> \n " ;
2007-03-24 08:27:00 +01:00
}
else
{
print " <li><b>Error: Depends on: session - NOT FOUND</b><br /> \n " ;
print " To install session support on FreeBSD:<br /> \n " ;
print " <pre>% cd /usr/ports/www/php $phpversion -session/ \n " ;
print " % make clean install \n " ;
print " - or with portupgrade - \n " ;
2007-11-03 20:21:27 +01:00
print " % portinstall php $phpversion -session</pre></li> \n " ;
2007-03-24 08:27:00 +01:00
$error =+ 1 ;
}
//
// PCRE functions
//
if ( $f_preg_match == 1 )
{
2007-11-03 20:21:27 +01:00
print " <li>Depends on: pcre - OK</li> \n " ;
2007-03-24 08:27:00 +01:00
}
else
{
print " <li><b>Error: Depends on: pcre - NOT FOUND</b><br /> \n " ;
print " To install pcre support on FreeBSD:<br /> \n " ;
print " <pre>% cd /usr/ports/devel/php $phpversion -pcre/ \n " ;
print " % make clean install \n " ;
print " - or with portupgrade - \n " ;
2007-11-03 20:21:27 +01:00
print " % portinstall php $phpversion -pcre</pre></li> \n " ;
2007-03-24 08:27:00 +01:00
$error =+ 1 ;
}
2007-12-14 01:05:54 +01:00
//
// Multibyte functions
//
if ( $f_mb_encode_mimeheader == 1 )
{
print " <li>Depends on: multibyte string - OK</li> \n " ;
}
else
{
print " <li><b>Error: Depends on: multibyte string - NOT FOUND</b><br /> \n " ;
print " To install multibyte string support, install php $phpversion -mbstring</li> \n " ;
$error =+ 1 ;
}
2007-10-07 19:23:29 +02:00
print " </ul> " ;
if ( $error != 0 )
{
print " <p><b>Please fix the errors listed above.</b></p> " ;
}
else
2007-03-24 08:27:00 +01:00
{
2007-10-07 19:23:29 +02:00
print " <p>Everything seems fine... you are ready to rock & roll!</p> \n " ;
$pAdminCreate_admin_username_text = $PALANG [ 'pAdminCreate_admin_username_text' ];
$pAdminCreate_admin_password_text = " " ;
$tUsername = '' ;
$tMessage = '' ;
if ( $_SERVER [ 'REQUEST_METHOD' ] == " POST " )
{
if ( isset ( $_POST [ 'fUsername' ])) $fUsername = escape_string ( $_POST [ 'fUsername' ]);
if ( isset ( $_POST [ 'fPassword' ])) $fPassword = escape_string ( $_POST [ 'fPassword' ]);
if ( isset ( $_POST [ 'fPassword2' ])) $fPassword2 = escape_string ( $_POST [ 'fPassword2' ]);
2007-11-03 20:21:27 +01:00
// XXX need to ensure domains table includes an 'ALL' entry.
$r = db_query ( " SELECT * FROM domain WHERE domain = 'ALL' " );
if ( $r [ 'rows' ] == 0 ) {
db_insert ( 'domain' , array ( 'domain' => 'ALL' )); // all other fields should default through the schema.
}
2007-10-07 19:23:29 +02:00
list ( $error , $tMessage , $pAdminCreate_admin_username_text , $pAdminCreate_admin_password_text ) = create_admin ( $fUsername , $fPassword , $fPassword2 , array ( 'ALL' ), TRUE );
if ( $error != 0 ) {
if ( isset ( $_POST [ 'fUsername' ])) $tUsername = escape_string ( $_POST [ 'fUsername' ]);
} else {
print " <p><b> $tMessage </b></p> " ;
echo " <p><b>You can now log in to Postfix Admin.</b></p> " ;
}
}
if ( $_SERVER [ 'REQUEST_METHOD' ] == " GET " || $error != 0 )
{
?>
< div id = " edit_form " >
< form name = " create_admin " method = " post " >
< table >
< tr >
< td colspan = " 3 " >< h3 > Create superadmin account </ h3 ></ td >
</ tr >
< tr >
< td >< ? php print $PALANG [ 'pAdminCreate_admin_username' ] . " : " ; ?> </td>
< td >< input class = " flat " type = " text " name = " fUsername " value = " <?php print $tUsername ; ?> " /></ td >
< td >< ? php print $pAdminCreate_admin_username_text ; ?> </td>
</ tr >
< tr >
< td >< ? php print $PALANG [ 'pAdminCreate_admin_password' ] . " : " ; ?> </td>
< td >< input class = " flat " type = " password " name = " fPassword " /></ td >
< td >< ? php print $pAdminCreate_admin_password_text ; ?> </td>
</ tr >
< tr >
< td >< ? php print $PALANG [ 'pAdminCreate_admin_password2' ] . " : " ; ?> </td>
< td >< input class = " flat " type = " password " name = " fPassword2 " /></ td >
< td >& nbsp ; </ td >
</ tr >
< tr >
< td colspan = " 3 " class = " hlp_center " >< input class = " button " type = " submit " name = " submit " value = " <?php print $PALANG['pAdminCreate_admin_button'] ; ?> " /></ td >
</ tr >
< tr >
< td colspan = " 3 " class = " standout " >< ? php print $tMessage ; ?> </td>
</ tr >
</ table >
</ form >
</ div >
< ? php
}
2007-03-24 08:27:00 +01:00
print " <b>Make sure you delete this setup.php file!</b><br /> \n " ;
print " Also check the config.inc.php file for any settings that you might need to change!<br /> \n " ;
}
?>
2007-10-07 19:23:29 +02:00
</ div >
2007-03-24 08:27:00 +01:00
</ body >
</ html >