Postfix Admin Setup Checker Running software: Error: Depends on: PHP v5 \n"; $error += 1; } elseif (version_compare(phpversion(), '5.2.3') < 0) { # smarty uses htmlentities() with 4 parameters, the 4th parameter was introduced in PHP 5.2.3 # older PHP versions will cause warnings $phpversion = 5; print " Recommended PHP version: >= 5.2.3, you have " . phpversion () . " \n"; } else { $phpversion = 5; print " PHP version " . phpversion () . " \n"; } # TODO: check for PHP >= 5.2.3 - smarty uses htmlentities with 4 parameters. The forth parameter was added in PHP 5.2.3, older versions will give a warning } else { print " Unable to check for PHP version. (missing function: phpversion()) \n"; } // // Check for Apache version // if ($f_apache_get_version == 1) { print " " . apache_get_version() . " \n"; } else { # not running on Apache. # However postfixadmin _is_ running, so obviously we are on a supported webserver ;-)) # No need to confuse the user with a warning. } print " "; print " Checking for dependencies:\n"; print " \n"; // // Check for Magic Quotes // if ($f_get_magic_quotes_gpc == 1) { if (get_magic_quotes_gpc () == 0) { print " Magic Quotes: Disabled - OK \n"; } else { print " Warning: Magic Quotes: ON (internal workaround used) \n"; } } else { print " Unable to check for Magic Quotes. (missing function: get_magic_quotes_gpc()) \n"; } // // Check for config.inc.php // $config_loaded = 0; if ($file_config == 1) { print " Depends on: presence config.inc.php - OK \n"; require_once($incpath.'/config.inc.php'); $config_loaded = 1; if(isset($CONF['configured'])) { if($CONF['configured'] === TRUE) { print " Checking \$CONF['configured'] - OK\n"; } else { print " Warning: \$CONF['configured'] is 'false'. \n"; print "You must edit your config.inc.php and change this to true (this indicates you've created the database and user)\n"; } } } else { print " Error: Depends on: presence config.inc.php - NOT FOUND \n"; print "Create the file, and edit as appropriate (e.g. select database type etc) "; print "For example: \n"; print " cp config.inc.php.sample config.inc.php \n"; $error =+ 1; } // // Check if templates directory is writable // if (!is_writeable($incpath.'/templates_c')) { print " Error: Smarty template compile directory templates_c is not writable. \n"; print "Please make it writable. \n"; print "If you are using SELinux or AppArmor, you might need to adjust their setup to allow write access. \n"; $error =+ 1; } else { print " Smarty template compile directory is writable - OK \n"; } // // 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 " Error: There is no database support in your PHP setup \n"; print "To install MySQL 3.23 or 4.0 support on FreeBSD: \n"; print " % cd /usr/ports/databases/php$phpversion-mysql/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-mysql \n"; if ($phpversion >= 5) { print "To install MySQL 4.1 support on FreeBSD: \n"; print " % cd /usr/ports/databases/php5-mysqli/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php5-mysqli \n"; } print "To install PostgreSQL support on FreeBSD: \n"; print " % cd /usr/ports/databases/php$phpversion-pgsql/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-pgsql \n"; $error =+ 1; } // // MySQL 3.23, 4.0 functions // if ($f_mysql_connect == 1) { print " Depends on: MySQL 3.23, 4.0 - OK \n"; } // // MySQL 4.1 functions // if ($phpversion >= 5) { if ($f_mysqli_connect == 1) { print " 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 if you want to use MySQL)\n"; } print " "; } } // // PostgreSQL functions // if ($f_pg_connect == 1) { print " Depends on: PostgreSQL - OK \n"; if ( !($config_loaded && $CONF['database_type'] == 'pgsql') ) { print " (change the database_type to 'pgsql' in config.inc.php if you want to use PostgreSQL)\n"; } print " "; } // // Database connection // if ($config_loaded) { list ($link, $error_text) = db_connect(TRUE); if ($error_text == "") { print " Testing database connection - OK - {$CONF['database_type']}://{$CONF['database_user']}:xxxxx@{$CONF['database_host']}/{$CONF['database_name']} "; } else { print " Error: Can't connect to database \n"; print "Please edit the \$CONF['database_*'] parameters in config.inc.php.\n"; print "$error_text \n"; $error ++; } } // // Session functions // if ($f_session_start == 1) { print " Depends on: session - OK \n"; } else { print " Error: Depends on: session - NOT FOUND \n"; print "To install session support on FreeBSD: \n"; print " % cd /usr/ports/www/php$phpversion-session/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-session \n"; $error =+ 1; } // // PCRE functions // if ($f_preg_match == 1) { print " Depends on: pcre - OK \n"; } else { print " Error: Depends on: pcre - NOT FOUND \n"; print "To install pcre support on FreeBSD: \n"; print " % cd /usr/ports/devel/php$phpversion-pcre/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-pcre \n"; $error =+ 1; } // // Multibyte functions // if ( $f_mb_encode_mimeheader == 1 ) { print " Depends on: multibyte string - OK \n"; } else { print " Error: Depends on: multibyte string - NOT FOUND \n"; print "To install multibyte string support, install php$phpversion-mbstring \n"; $error =+ 1; } // // Imap functions // if ( $f_imap_open == 1) { print " Depends on: IMAP functions - OK \n"; } else { print " Warning: Depends on: IMAP functions - NOT FOUND \n"; print "To install IMAP support, install php$phpversion-imap \n"; print "Without IMAP support, you won't be able to create subfolders when creating mailboxes. \n"; # $error =+ 1; } print " "; if ($error != 0) { print " Please fix the errors listed above. "; } else { print " Everything seems fine... attempting to create/update database structure \n"; require_once($incpath.'/upgrade.php'); $tUsername = ''; $setupMessage = ''; $lostpw_error = 0; $setuppw = ""; if (isset($CONF['setup_password'])) $setuppw = $CONF['setup_password']; if (safepost("form") == "setuppw") { # "setup password" form submitted if (safepost('setup_password') != safepost('setup_password2')) { $setupMessage = "The two passwords differ!"; $lostpw_error = 1; } else { list ($lostpw_error, $lostpw_result) = check_setup_password(safepost('setup_password'), 1); $setupMessage = $lostpw_result; $setuppw = "changed"; } } elseif (safepost("form") == "createadmin") { # "create admin" form submitted list ($pw_check_error, $pw_check_result) = check_setup_password(safepost('setup_password')); if ($pw_check_result != 'pass_OK') { $error += 1; $setupMessage = $pw_check_result; } if($error == 0 && $pw_check_result == 'pass_OK') { // XXX need to ensure domains table includes an 'ALL' entry. $table_domain = table_by_key('domain'); $r = db_query("SELECT * FROM $table_domain WHERE domain = 'ALL'"); if($r['rows'] == 0) { db_insert('domain', array('domain' => 'ALL', 'description' => '', 'transport' => '') ); // all other fields should default through the schema. } $values = array( 'username' => safepost('username'), 'password' => safepost('password'), 'password2' => safepost('password2'), 'superadmin' => 1, 'domains' => array(), 'active' => 1, ); list ($error, $setupMessage, $errormsg) = create_admin($values); if ($error != 0) { $tUsername = htmlentities($values['username']); } } } if ( ($setuppw == "" || $setuppw == "changeme" || safeget("lostpw") == 1 || $lostpw_error != 0) /* && $_SERVER['REQUEST_METHOD'] != "POST" */ ) { # show "create setup password" form ?> Change setup password Setup password Setup password (again) Create superadmin account Setup password Lost password? Since version 2.3 there is no requirement to delete setup.php! \n"; print "Check the config.inc.php file for any other settings that you might need to change! \n"; } ?> 0 (or 1), 'message => text ) */ function check_setup_password($password, $lostpw_mode = 0) { global $CONF; $error = 1; # be pessimistic $setuppw = ""; if (isset($CONF['setup_password'])) $setuppw = $CONF['setup_password']; list($confsalt, $confpass, $trash) = explode(':', $setuppw . '::'); $pass = encrypt_setup_password($password, $confsalt); $validpass = validate_password($password); if ($password == "" ) { # no password specified? $result = "Setup password must be specified If you didn't set up a setup password yet, enter the password you want to use."; } elseif (count($validpass) > 0) { $result = $validpass[0]; # TODO: honor all error messages, not only the first one } elseif ($pass == $setuppw && $lostpw_mode == 0) { # correct passsword (and not asking for a new password) $result = "pass_OK"; $error = 0; } else { $pass = encrypt_setup_password($password, generate_setup_password_salt()); $result = ""; if ($lostpw_mode == 1) { $error = 0; # non-matching password is expected when the user asks for a new password } else { $result = ' Setup password not specified correctly '; } $result .= ' If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set '; $result .= " \$CONF['setup_password'] = '$pass'; "; } return array ($error, $result); } function create_admin($values) { DEFINE('POSTFIXADMIN_SETUP', 1); # avoids instant redirect to login.php after creating the admin $handler = new AdminHandler(1, 'setup.php'); $formconf = $handler->webformConfig(); if (!$handler->init($values['username'])) { return array(1, "", $handler->errormsg); } if (!$handler->set($values)) { return array(1, "", $handler->errormsg); } if (!$handler->store()) { return array(1, "", $handler->errormsg); } return array( 0, $handler->infomsg['success'], array(), ); } /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ ?> Postfix Admin Setup Checker Running software: Error: Depends on: PHP v5 \n"; $error += 1; } elseif (version_compare(phpversion(), '5.2.3') < 0) { # smarty uses htmlentities() with 4 parameters, the 4th parameter was introduced in PHP 5.2.3 # older PHP versions will cause warnings $phpversion = 5; print " Recommended PHP version: >= 5.2.3, you have " . phpversion () . " \n"; } else { $phpversion = 5; print " PHP version " . phpversion () . " \n"; } # TODO: check for PHP >= 5.2.3 - smarty uses htmlentities with 4 parameters. The forth parameter was added in PHP 5.2.3, older versions will give a warning } else { print " Unable to check for PHP version. (missing function: phpversion()) \n"; } // // Check for Apache version // if ($f_apache_get_version == 1) { print " " . apache_get_version() . " \n"; } else { # not running on Apache. # However postfixadmin _is_ running, so obviously we are on a supported webserver ;-)) # No need to confuse the user with a warning. } print " "; print " Checking for dependencies:\n"; print " \n"; // // Check for Magic Quotes // if ($f_get_magic_quotes_gpc == 1) { if (get_magic_quotes_gpc () == 0) { print " Magic Quotes: Disabled - OK \n"; } else { print " Warning: Magic Quotes: ON (internal workaround used) \n"; } } else { print " Unable to check for Magic Quotes. (missing function: get_magic_quotes_gpc()) \n"; } // // Check for config.inc.php // $config_loaded = 0; if ($file_config == 1) { print " Depends on: presence config.inc.php - OK \n"; require_once($incpath.'/config.inc.php'); $config_loaded = 1; if(isset($CONF['configured'])) { if($CONF['configured'] === TRUE) { print " Checking \$CONF['configured'] - OK\n"; } else { print " Warning: \$CONF['configured'] is 'false'. \n"; print "You must edit your config.inc.php and change this to true (this indicates you've created the database and user)\n"; } } } else { print " Error: Depends on: presence config.inc.php - NOT FOUND \n"; print "Create the file, and edit as appropriate (e.g. select database type etc) "; print "For example: \n"; print " cp config.inc.php.sample config.inc.php \n"; $error =+ 1; } // // Check if templates directory is writable // if (!is_writeable($incpath.'/templates_c')) { print " Error: Smarty template compile directory templates_c is not writable. \n"; print "Please make it writable. \n"; print "If you are using SELinux or AppArmor, you might need to adjust their setup to allow write access. \n"; $error =+ 1; } else { print " Smarty template compile directory is writable - OK \n"; } // // 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 " Error: There is no database support in your PHP setup \n"; print "To install MySQL 3.23 or 4.0 support on FreeBSD: \n"; print " % cd /usr/ports/databases/php$phpversion-mysql/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-mysql \n"; if ($phpversion >= 5) { print "To install MySQL 4.1 support on FreeBSD: \n"; print " % cd /usr/ports/databases/php5-mysqli/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php5-mysqli \n"; } print "To install PostgreSQL support on FreeBSD: \n"; print " % cd /usr/ports/databases/php$phpversion-pgsql/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-pgsql \n"; $error =+ 1; } // // MySQL 3.23, 4.0 functions // if ($f_mysql_connect == 1) { print " Depends on: MySQL 3.23, 4.0 - OK \n"; } // // MySQL 4.1 functions // if ($phpversion >= 5) { if ($f_mysqli_connect == 1) { print " 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 if you want to use MySQL)\n"; } print " "; } } // // PostgreSQL functions // if ($f_pg_connect == 1) { print " Depends on: PostgreSQL - OK \n"; if ( !($config_loaded && $CONF['database_type'] == 'pgsql') ) { print " (change the database_type to 'pgsql' in config.inc.php if you want to use PostgreSQL)\n"; } print " "; } // // Database connection // if ($config_loaded) { list ($link, $error_text) = db_connect(TRUE); if ($error_text == "") { print " Testing database connection - OK - {$CONF['database_type']}://{$CONF['database_user']}:xxxxx@{$CONF['database_host']}/{$CONF['database_name']} "; } else { print " Error: Can't connect to database \n"; print "Please edit the \$CONF['database_*'] parameters in config.inc.php.\n"; print "$error_text \n"; $error ++; } } // // Session functions // if ($f_session_start == 1) { print " Depends on: session - OK \n"; } else { print " Error: Depends on: session - NOT FOUND \n"; print "To install session support on FreeBSD: \n"; print " % cd /usr/ports/www/php$phpversion-session/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-session \n"; $error =+ 1; } // // PCRE functions // if ($f_preg_match == 1) { print " Depends on: pcre - OK \n"; } else { print " Error: Depends on: pcre - NOT FOUND \n"; print "To install pcre support on FreeBSD: \n"; print " % cd /usr/ports/devel/php$phpversion-pcre/\n"; print "% make clean install\n"; print " - or with portupgrade -\n"; print "% portinstall php$phpversion-pcre \n"; $error =+ 1; } // // Multibyte functions // if ( $f_mb_encode_mimeheader == 1 ) { print " Depends on: multibyte string - OK \n"; } else { print " Error: Depends on: multibyte string - NOT FOUND \n"; print "To install multibyte string support, install php$phpversion-mbstring \n"; $error =+ 1; } // // Imap functions // if ( $f_imap_open == 1) { print " Depends on: IMAP functions - OK \n"; } else { print " Warning: Depends on: IMAP functions - NOT FOUND \n"; print "To install IMAP support, install php$phpversion-imap \n"; print "Without IMAP support, you won't be able to create subfolders when creating mailboxes. \n"; # $error =+ 1; } print " "; if ($error != 0) { print " Please fix the errors listed above. "; } else { print " Everything seems fine... attempting to create/update database structure \n"; require_once($incpath.'/upgrade.php'); $tUsername = ''; $setupMessage = ''; $lostpw_error = 0; $setuppw = ""; if (isset($CONF['setup_password'])) $setuppw = $CONF['setup_password']; if (safepost("form") == "setuppw") { # "setup password" form submitted if (safepost('setup_password') != safepost('setup_password2')) { $setupMessage = "The two passwords differ!"; $lostpw_error = 1; } else { list ($lostpw_error, $lostpw_result) = check_setup_password(safepost('setup_password'), 1); $setupMessage = $lostpw_result; $setuppw = "changed"; } } elseif (safepost("form") == "createadmin") { # "create admin" form submitted list ($pw_check_error, $pw_check_result) = check_setup_password(safepost('setup_password')); if ($pw_check_result != 'pass_OK') { $error += 1; $setupMessage = $pw_check_result; } if($error == 0 && $pw_check_result == 'pass_OK') { // XXX need to ensure domains table includes an 'ALL' entry. $table_domain = table_by_key('domain'); $r = db_query("SELECT * FROM $table_domain WHERE domain = 'ALL'"); if($r['rows'] == 0) { db_insert('domain', array('domain' => 'ALL', 'description' => '', 'transport' => '') ); // all other fields should default through the schema. } $values = array( 'username' => safepost('username'), 'password' => safepost('password'), 'password2' => safepost('password2'), 'superadmin' => 1, 'domains' => array(), 'active' => 1, ); list ($error, $setupMessage, $errormsg) = create_admin($values); if ($error != 0) { $tUsername = htmlentities($values['username']); } } } if ( ($setuppw == "" || $setuppw == "changeme" || safeget("lostpw") == 1 || $lostpw_error != 0) /* && $_SERVER['REQUEST_METHOD'] != "POST" */ ) { # show "create setup password" form ?> Change setup password Setup password Setup password (again) Create superadmin account Setup password Lost password? Since version 2.3 there is no requirement to delete setup.php! \n"; print "Check the config.inc.php file for any other settings that you might need to change! \n"; } ?> 0 (or 1), 'message => text ) */ function check_setup_password($password, $lostpw_mode = 0) { global $CONF; $error = 1; # be pessimistic $setuppw = ""; if (isset($CONF['setup_password'])) $setuppw = $CONF['setup_password']; list($confsalt, $confpass, $trash) = explode(':', $setuppw . '::'); $pass = encrypt_setup_password($password, $confsalt); $validpass = validate_password($password); if ($password == "" ) { # no password specified? $result = "Setup password must be specified If you didn't set up a setup password yet, enter the password you want to use."; } elseif (count($validpass) > 0) { $result = $validpass[0]; # TODO: honor all error messages, not only the first one } elseif ($pass == $setuppw && $lostpw_mode == 0) { # correct passsword (and not asking for a new password) $result = "pass_OK"; $error = 0; } else { $pass = encrypt_setup_password($password, generate_setup_password_salt()); $result = ""; if ($lostpw_mode == 1) { $error = 0; # non-matching password is expected when the user asks for a new password } else { $result = ' Setup password not specified correctly '; } $result .= ' If you want to use the password you entered as setup password, edit config.inc.php or config.local.php and set '; $result .= " \$CONF['setup_password'] = '$pass'; "; } return array ($error, $result); } function create_admin($values) { DEFINE('POSTFIXADMIN_SETUP', 1); # avoids instant redirect to login.php after creating the admin $handler = new AdminHandler(1, 'setup.php'); $formconf = $handler->webformConfig(); if (!$handler->init($values['username'])) { return array(1, "", $handler->errormsg); } if (!$handler->set($values)) { return array(1, "", $handler->errormsg); } if (!$handler->store()) { return array(1, "", $handler->errormsg); } return array( 0, $handler->infomsg['success'], array(), ); } /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ ?>