Implementation of the WebMUM installer (#52)
* Preparation for installer and discontinue support of old config style. * Adding installer with step 0 * Fixing travis config, because example config isn't loaded anymore if normal config does not exist. * Adding installer step 1: database connection * Adding installer step 2: database schema * Adding installer step 3: Your first admin user * Minor fix on step 3 * Adding installer step 4: general settings * Adding installer step 5: optional features * Adding final installation step 7: writing config & finish * Display the current installation progress * Fixing installation finish * Disable direct access to installer * Change colors of "notifying" text * Add check and cross marks to requirements page of the installer * Change how config directory is checked, no more writable check but error if writing fails. * Execute post-receice..
This commit is contained in:
parent
dbb66ee3aa
commit
a7c3a4f271
14 changed files with 1768 additions and 90 deletions
|
@ -20,5 +20,7 @@ before_install:
|
|||
- mysql -u root -e "CREATE TABLE vmail.domains (id int(10) unsigned NOT NULL AUTO_INCREMENT, domain varchar(128) NOT NULL, PRIMARY KEY (domain), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"
|
||||
- mysql -u root -e "CREATE TABLE vmail.users (id int(10) unsigned NOT NULL AUTO_INCREMENT, username varchar(128) NOT NULL DEFAULT '', domain varchar(128) NOT NULL DEFAULT '', password varchar(128) NOT NULL DEFAULT '', mailbox_limit int(10) NOT NULL DEFAULT '128', max_user_redirects int(10) NOT NULL DEFAULT '0', PRIMARY KEY (username,domain), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"
|
||||
- mysql -u root -e "CREATE TABLE vmail.aliases (id int(10) unsigned NOT NULL AUTO_INCREMENT, source varchar(128) NOT NULL, destination text NOT NULL, multi_source varchar(32) DEFAULT NULL, is_created_by_user int(1) NOT NULL DEFAULT '0', PRIMARY KEY (source), UNIQUE KEY id (id)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"
|
||||
# Copy the example config
|
||||
- cp config/config.php.example config/config.php
|
||||
notifications:
|
||||
email: false
|
|
@ -5,6 +5,28 @@ body {
|
|||
background-color: white;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: none;
|
||||
border-bottom: 1px solid #ccc;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
hr.invisible {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.text-fail {
|
||||
color: #d90000;
|
||||
}
|
||||
|
||||
.text-warning {
|
||||
color: #ADA900;
|
||||
}
|
||||
|
||||
.text-success {
|
||||
color: #39AD00;
|
||||
}
|
||||
|
||||
|
||||
#header {
|
||||
position: relative;
|
||||
|
@ -66,6 +88,13 @@ body {
|
|||
color: rgba(62, 59, 59, 1);
|
||||
}
|
||||
|
||||
#content .sub-header {
|
||||
font-weight: normal;
|
||||
font-size: .9em;
|
||||
color: #999;
|
||||
padding: 5px 0 0 5px;
|
||||
}
|
||||
|
||||
#content a {
|
||||
color: blue;
|
||||
text-decoration: none;
|
||||
|
@ -80,6 +109,10 @@ body {
|
|||
margin: 25px 0;
|
||||
}
|
||||
|
||||
#content .form hr {
|
||||
margin: 5px 0 15px;
|
||||
}
|
||||
|
||||
#content .form .input-group, #content .form .buttons {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
@ -96,10 +129,13 @@ body {
|
|||
}
|
||||
|
||||
#content .form .input-group > .input-group {
|
||||
padding-top: 10px;
|
||||
padding-left: 25px;
|
||||
}
|
||||
|
||||
#content .form .input-group > .input-group:first-of-type {
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
#content .form .input-group > .input-group > label {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
@ -131,6 +167,27 @@ body {
|
|||
width: 70px;
|
||||
}
|
||||
|
||||
#content .form .input input[type="checkbox"],
|
||||
#content .form .input input[type="radio"] {
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
min-width: inherit;
|
||||
vertical-align: middle;
|
||||
margin: 6px 0 8px 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#content .form .input input[type="checkbox"]+label,
|
||||
#content .form .input input[type="radio"]+label {
|
||||
padding-left: 3px;
|
||||
margin-right: 15px;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#content .form .input textarea {
|
||||
min-height: 150px;
|
||||
min-width: 400px;
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Start session as the very first thing
|
||||
*/
|
||||
session_start();
|
||||
session_regenerate_id();
|
||||
|
||||
|
||||
/**
|
||||
* Register automatic loading for dependency injection
|
||||
*/
|
||||
|
@ -20,6 +13,13 @@ spl_autoload_register(function($class){
|
|||
});
|
||||
|
||||
|
||||
/**
|
||||
* Start session as the very first thing
|
||||
*/
|
||||
session_start();
|
||||
session_regenerate_id();
|
||||
|
||||
|
||||
/**
|
||||
* Load some global accessible functions
|
||||
*/
|
||||
|
@ -27,95 +27,43 @@ require_once 'include/php/global.inc.php';
|
|||
|
||||
|
||||
/**
|
||||
* Require config
|
||||
* Setting up
|
||||
*/
|
||||
if(file_exists('config/config.php')){
|
||||
$configValues = require_once 'config/config.php';
|
||||
if(!is_array($configValues)){
|
||||
die('Config must return an array of config values.');
|
||||
}
|
||||
if(file_exists('config/config.php') && !isset($_SESSION['installer'])){
|
||||
|
||||
/**
|
||||
* Loading config
|
||||
*/
|
||||
$configValues = require_once 'config/config.php';
|
||||
|
||||
Config::init($configValues);
|
||||
}
|
||||
else{
|
||||
$configValues = require_once 'config/config.php.example';
|
||||
if(!is_array($configValues)){
|
||||
die('Config must return an array of config values.');
|
||||
throw new Exception('Config must return an array of config values.');
|
||||
}
|
||||
|
||||
Config::init($configValues);
|
||||
|
||||
/**
|
||||
* Handle old config style, if it still exists.
|
||||
**/
|
||||
if(file_exists('config/config.inc.php') || file_exists('config/config.inc.php.example')){
|
||||
define('USING_OLD_CONFIG', true);
|
||||
|
||||
if(file_exists('config/config.inc.php')){
|
||||
require_once 'config/config.inc.php';
|
||||
}
|
||||
else{
|
||||
require_once 'config/config.inc.php.example';
|
||||
}
|
||||
|
||||
Config::set('base_url', FRONTEND_BASE_PATH);
|
||||
|
||||
Config::set('mysql.host', MYSQL_HOST);
|
||||
Config::set('mysql.user', MYSQL_USER);
|
||||
Config::set('mysql.password', MYSQL_PASSWORD);
|
||||
Config::set('mysql.database', MYSQL_DATABASE);
|
||||
|
||||
Config::set('schema.tables.users', DBT_USERS);
|
||||
Config::set('schema.tables.domains', DBT_DOMAINS);
|
||||
Config::set('schema.tables.aliases', DBT_ALIASES);
|
||||
|
||||
Config::set('schema.attributes.users.id', DBC_USERS_ID);
|
||||
Config::set('schema.attributes.users.username', DBC_USERS_USERNAME);
|
||||
Config::set('schema.attributes.users.domain', DBC_USERS_DOMAIN);
|
||||
Config::set('schema.attributes.users.password', DBC_USERS_PASSWORD);
|
||||
Config::set('schema.attributes.users.mailbox_limit', defined('DBC_USERS_MAILBOXLIMIT') ? DBC_USERS_MAILBOXLIMIT : 'mailbox_limit');
|
||||
|
||||
Config::set('schema.attributes.domains.id', DBC_DOMAINS_ID);
|
||||
Config::set('schema.attributes.domains.domain', DBC_DOMAINS_DOMAIN);
|
||||
|
||||
Config::set('schema.attributes.aliases.id', DBC_ALIASES_ID);
|
||||
Config::set('schema.attributes.aliases.source', DBC_ALIASES_SOURCE);
|
||||
Config::set('schema.attributes.aliases.destination', DBC_ALIASES_DESTINATION);
|
||||
Config::set('schema.attributes.aliases.multi_source', defined('DBC_ALIASES_MULTI_SOURCE') ? DBC_ALIASES_MULTI_SOURCE : 'multi_source');
|
||||
* Establish database connection
|
||||
*/
|
||||
Database::init(Config::get('mysql'));
|
||||
|
||||
|
||||
Config::set('options.enable_mailbox_limits', defined('DBC_USERS_MAILBOXLIMIT'));
|
||||
Config::set('options.enable_validate_aliases_source_domain', defined('VALIDATE_ALIASES_SOURCE_DOMAIN_ENABLED'));
|
||||
Config::set('options.enable_multi_source_redirects', defined('DBC_ALIASES_MULTI_SOURCE'));
|
||||
Config::set('options.enable_admin_domain_limits', defined('ADMIN_DOMAIN_LIMITS_ENABLED') ? ADMIN_DOMAIN_LIMITS_ENABLED : false);
|
||||
Config::set('options.enable_logging', defined('WRITE_LOG') ? WRITE_LOG : false);
|
||||
/**
|
||||
* Initialize Authentication (Login User if in session)
|
||||
*/
|
||||
Auth::init();
|
||||
|
||||
Config::set('admins', isset($admins) ? $admins : array());
|
||||
Config::set('admin_domain_limits', isset($adminDomainLimits) ? $adminDomainLimits : array());
|
||||
|
||||
Config::set('password.hash_algorithm', PASS_HASH_SCHEMA);
|
||||
Config::set('password.min_length', MIN_PASS_LENGTH);
|
||||
|
||||
Config::set('log_path', defined('WRITE_LOG_PATH') ? WRITE_LOG_PATH : '/var/www/webmum/log/');
|
||||
|
||||
Config::set('frontend_options.email_separator_text', FRONTEND_EMAIL_SEPARATOR_TEXT);
|
||||
Config::set('frontend_options.email_separator_form', FRONTEND_EMAIL_SEPARATOR_FORM);
|
||||
}
|
||||
/**
|
||||
* Setup routes
|
||||
*/
|
||||
require_once 'include/php/routes.inc.php';
|
||||
}
|
||||
else{
|
||||
|
||||
/**
|
||||
* Switching to install mode
|
||||
*/
|
||||
define('INSTALLER_ENABLED', true);
|
||||
|
||||
/**
|
||||
* Establish database connection
|
||||
*/
|
||||
Database::init(Config::get('mysql'));
|
||||
|
||||
|
||||
/**
|
||||
* Initialize Authentication (Login User if in session)
|
||||
*/
|
||||
Auth::init();
|
||||
|
||||
/**
|
||||
* Setup routes
|
||||
*/
|
||||
require_once 'include/php/routes.inc.php';
|
||||
}
|
||||
|
|
18
index.php
18
index.php
|
@ -6,11 +6,19 @@ try {
|
|||
*/
|
||||
require_once 'include/php/default.inc.php';
|
||||
|
||||
|
||||
/**
|
||||
* Handle request
|
||||
*/
|
||||
$content = Router::executeCurrentRequest();
|
||||
|
||||
if(defined('INSTALLER_ENABLED')){
|
||||
/**
|
||||
* Load installer
|
||||
*/
|
||||
$content = Router::loadAndBufferOutput('installer/index.php');
|
||||
}
|
||||
else {
|
||||
/**
|
||||
* Handle request
|
||||
*/
|
||||
$content = Router::executeCurrentRequest();
|
||||
}
|
||||
}
|
||||
catch(DatabaseException $e){
|
||||
$content = '<div class="notification notification-fail">Faulty database query: "'.$e->getQuery().'".</div>';
|
||||
|
|
1
installer/.htaccess
Normal file
1
installer/.htaccess
Normal file
|
@ -0,0 +1 @@
|
|||
Deny from all
|
125
installer/index.php
Normal file
125
installer/index.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
define('INSTALLER_MAX_STEP', 6);
|
||||
|
||||
define('INSTALLER_TYPE_CREATE', 0);
|
||||
define('INSTALLER_TYPE_MAP', 1);
|
||||
|
||||
$installerStepTitles = array(
|
||||
'Requirements',
|
||||
'Database connection',
|
||||
'Database schema',
|
||||
'Your first admin user',
|
||||
'General settings',
|
||||
'Optional features',
|
||||
'Finish installation',
|
||||
);
|
||||
|
||||
$installerStepMapping = array(
|
||||
0 => 0,
|
||||
1 => 1,
|
||||
2 => 2,
|
||||
3 => 2,
|
||||
4 => 3,
|
||||
5 => 4,
|
||||
6 => 5,
|
||||
7 => 6,
|
||||
);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
function installer_reset()
|
||||
{
|
||||
global $_SESSION;
|
||||
|
||||
$_SESSION['installer'] = array(
|
||||
'lastStep' => 0,
|
||||
'step' => 0,
|
||||
'config' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
function installer_message($setMessage = null)
|
||||
{
|
||||
global $_SESSION;
|
||||
|
||||
if(!is_null($setMessage)){
|
||||
$_SESSION['installer']['message'] = $setMessage;
|
||||
}
|
||||
elseif(isset($_SESSION['installer']['message'])){
|
||||
$m = '<div class="notification notification-success">'.$_SESSION['installer']['message'].'</div>';
|
||||
unset($_SESSION['installer']['message']);
|
||||
|
||||
return $m;
|
||||
}
|
||||
|
||||
return $setMessage;
|
||||
}
|
||||
|
||||
function installer_prev($thisStep, $stepSize = 1)
|
||||
{
|
||||
$s = ($thisStep < 0) ? 0 : ($thisStep - $stepSize);
|
||||
|
||||
$_SESSION['installer']['lastStep'] = $thisStep;
|
||||
$_SESSION['installer']['step'] = $s;
|
||||
|
||||
Router::redirect('/?step='.$s);
|
||||
}
|
||||
|
||||
function installer_next($thisStep, $stepSize = 1)
|
||||
{
|
||||
$s = ($thisStep > 8) ? 8 : ($thisStep + $stepSize);
|
||||
|
||||
$_SESSION['installer']['lastStep'] = $thisStep;
|
||||
$_SESSION['installer']['step'] = $s;
|
||||
|
||||
Router::redirect('/?step='.$s);
|
||||
}
|
||||
|
||||
if(!isset($_SESSION['installer'])){
|
||||
installer_reset();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$step = (isset($_GET['step']) && is_numeric($_GET['step'])) ? intval($_GET['step']) : 0;
|
||||
|
||||
echo '<h1>Installation of WebMUM</h1>';
|
||||
|
||||
if($step > 0){
|
||||
?>
|
||||
<ol style="font-size: 1.1em;">
|
||||
<?php for($s = 1; $s <= INSTALLER_MAX_STEP; $s++): ?>
|
||||
<li>
|
||||
<?php if(isset($installerStepMapping[$step]) && $s < $installerStepMapping[$step]): ?>
|
||||
<span style="color: #999;"><?php echo $installerStepTitles[$s]; ?></span>
|
||||
<?php elseif(isset($installerStepMapping[$step]) && $s === $installerStepMapping[$step]): ?>
|
||||
<strong><?php echo $installerStepTitles[$s]; ?></strong>
|
||||
<?php else: ?>
|
||||
<?php echo $installerStepTitles[$s]; ?>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<?php endfor; ?>
|
||||
</ol>
|
||||
<?php
|
||||
}
|
||||
|
||||
try{
|
||||
$stepFile = __DIR__.'/step'.$step.'.php';
|
||||
if(file_exists($stepFile)){
|
||||
include_once $stepFile;
|
||||
}
|
||||
else{
|
||||
installer_reset();
|
||||
echo 'Wizard step '.$step.' is missing.';
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
echo $e->getMessage();
|
||||
}
|
103
installer/step0.php
Normal file
103
installer/step0.php
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 0;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$requirements = array();
|
||||
$numberOfRequirements = 5;
|
||||
if(version_compare(phpversion(), '5.4.0', '>=')){
|
||||
$requirements[] = 'php_version';
|
||||
}
|
||||
if(function_exists('mysqli_connect')){
|
||||
$requirements[] = 'php_extension_mysqli';
|
||||
}
|
||||
if(session_status() != PHP_SESSION_DISABLED){
|
||||
$requirements[] = 'php_session_enabled';
|
||||
}
|
||||
if(file_exists('config') && is_dir('config')){
|
||||
$requirements[] = 'config_directory';
|
||||
}
|
||||
if(file_exists('config/config.php.example')){
|
||||
$requirements[] = 'config_example';
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_GET['go']) && $_GET['go'] == 'next'){
|
||||
if(count($requirements) === $numberOfRequirements){
|
||||
installer_message('All requirements fulfilled, let\'s get started with the installation!');
|
||||
|
||||
installer_next($thisStep);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>Getting started</h2>
|
||||
|
||||
<p>By following this wizard you will install and configure your new WebMUM installation.</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<strong>System Info:</strong>
|
||||
<ul>
|
||||
<li>System: <strong><?php echo php_uname(); ?></strong></li>
|
||||
<li>Hostname: <strong><?php echo $_SERVER['SERVER_NAME']; ?></strong></li>
|
||||
<li>IP: <strong><?php echo $_SERVER['SERVER_ADDR']; ?></strong></li>
|
||||
<li>PHP version: <strong><?php echo phpversion(); ?></strong></li>
|
||||
<li>Server API: <strong><?php echo php_sapi_name(); ?></strong></li>
|
||||
<li>WebMUM directory: <strong><?php echo dirname($_SERVER['SCRIPT_FILENAME']); ?></strong></li>
|
||||
</ul>
|
||||
|
||||
<strong>Server requirements</strong>
|
||||
<ul>
|
||||
<?php if(in_array('php_version', $requirements)): ?>
|
||||
<li class="text-success">PHP version (>=5.4.0 or >=7.0.0): <strong><?php echo phpversion(); ?> ✓</strong></li>
|
||||
<?php else: ?>
|
||||
<li class="text-fail">PHP version (>=5.4.0 or >=7.0.0): <strong><?php echo phpversion(); ?> ❌</strong></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
|
||||
<strong>Required PHP settings</strong>
|
||||
<ul>
|
||||
<?php if(in_array('php_extension_mysqli', $requirements)): ?>
|
||||
<li class="text-success">Database extension (mysqli): <strong>enabled ✓</strong></li>
|
||||
<?php else: ?>
|
||||
<li class="text-fail">Database extension (mysqli): <strong>disabled ❌</strong></li>
|
||||
<?php endif; ?>
|
||||
<?php if(in_array('php_session_enabled', $requirements)): ?>
|
||||
<li class="text-success">Session support: <strong>enabled ✓</strong></li>
|
||||
<?php else: ?>
|
||||
<li class="text-fail">Session support: <strong>disabled ❌</strong></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
|
||||
<strong>Directories and files</strong>
|
||||
<ul>
|
||||
<?php if(in_array('config_directory', $requirements)): ?>
|
||||
<li class="text-success">"config/": <strong>exists ✓</strong></li>
|
||||
<?php else: ?>
|
||||
<li class="text-fail">"config/": <strong>is missing ❌</strong></li>
|
||||
<?php endif; ?>
|
||||
<?php if(in_array('config_example', $requirements)): ?>
|
||||
<li class="text-success">"config/config.php.example": <strong>exists ✓</strong></li>
|
||||
<?php else: ?>
|
||||
<li class="text-fail">"config/config.php.example": <strong>is missing ❌</strong></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<?php if(count($requirements) === $numberOfRequirements):?>
|
||||
<p>Click on the Start button to continue.</p>
|
||||
<a class="button button-primary" href="/?step=<?php echo $thisStep; ?>&go=next">Start</a>
|
||||
<?php else:?>
|
||||
<p class="notification notification-fail">Some requirements aren't fulfilled.</p>
|
||||
<?php endif; ?>
|
131
installer/step1.php
Normal file
131
installer/step1.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 1;
|
||||
|
||||
$error = null;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_GET['go'])){
|
||||
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
try{
|
||||
// testing db settings
|
||||
Database::init($_POST);
|
||||
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['mysql'] = array(
|
||||
'host' => $_POST['host'],
|
||||
'user' => $_POST['user'],
|
||||
'password' => $_POST['password'],
|
||||
'database' => $_POST['database'],
|
||||
);
|
||||
$_SESSION['installer']['type'] = (isset($_POST['install_type']) && $_POST['install_type'] == INSTALLER_TYPE_MAP)
|
||||
? INSTALLER_TYPE_MAP
|
||||
: INSTALLER_TYPE_CREATE;
|
||||
|
||||
installer_message('Database connection was successfully established.');
|
||||
|
||||
installer_next($thisStep, ($_SESSION['installer']['type'] === INSTALLER_TYPE_MAP) ? 2 : 1);
|
||||
}
|
||||
catch(InvalidArgumentException $e){
|
||||
$error = 'Some fields are missing.';
|
||||
}
|
||||
catch(Exception $e){
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'prev'){
|
||||
// reset
|
||||
unset($_SESSION['installer']['config']['mysql']);
|
||||
unset($_SESSION['installer']['type']);
|
||||
|
||||
installer_prev($thisStep);
|
||||
}
|
||||
}
|
||||
|
||||
function getAttr($name, $default = null)
|
||||
{
|
||||
global $_SESSION, $_POST;
|
||||
|
||||
if(isset($_POST[$name])){
|
||||
return strip_tags($_POST[$name]);
|
||||
}
|
||||
elseif(isset($_SESSION['installer']['config']['mysql'][$name])){
|
||||
return $_SESSION['installer']['config']['mysql'][$name];
|
||||
}
|
||||
elseif($name === 'install_type' && isset($_SESSION['installer']['type'])){
|
||||
return $_SESSION['installer']['type'];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
?>
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>Step 1 of <?php echo INSTALLER_MAX_STEP; ?>: Database connection.</h2>
|
||||
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="notification notification-fail"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
|
||||
<p>Setup your MySQL database connection.</p>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="host">Database Host</label>
|
||||
<div class="input">
|
||||
<input type="text" name="host" value="<?php echo getAttr('host', 'localhost'); ?>" autofocus/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="database">Database Name</label>
|
||||
<div class="input">
|
||||
<input type="text" name="database" value="<?php echo getAttr('database'); ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="user">Database Username</label>
|
||||
<div class="input">
|
||||
<input type="text" name="user" value="<?php echo getAttr('user'); ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="password">Database Password</label>
|
||||
<div class="input">
|
||||
<input type="password" name="password" value="<?php echo getAttr('password'); ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="install_type">Installation Type</label>
|
||||
<div class="input-info">Be sure to select the correct option.</div>
|
||||
<div class="input">
|
||||
<input type="radio" name="install_type" id="install_type_0" value="0" <?php echo getAttr('install_type', 0) == 0 ? 'checked' : ''; ?>/>
|
||||
<label for="install_type_0">Create new database schema</label>
|
||||
</div>
|
||||
<div class="input">
|
||||
<input type="radio" name="install_type" id="install_type_1" value="1" <?php echo getAttr('install_type', 0) == 1 ? 'checked' : ''; ?>/>
|
||||
<label for="install_type_1">Map existing database schema</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button button-primary" type="submit">Continue</button>
|
||||
</div>
|
||||
</form>
|
209
installer/step2.php
Normal file
209
installer/step2.php
Normal file
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 2;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$exampleConfigValues = require_once 'config/config.php.example';
|
||||
|
||||
$tablesInDatabase = array();
|
||||
try{
|
||||
Database::init($_SESSION['installer']['config']['mysql']);
|
||||
|
||||
$tablesResult = Database::getInstance()->query("SELECT table_name FROM information_schema.tables WHERE table_schema='".$_SESSION['installer']['config']['mysql']['database']."';");
|
||||
foreach($tablesResult->fetch_all() as $row){
|
||||
$tablesInDatabase[] = $row[0];
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$databaseSchema = array(
|
||||
'domains' => "CREATE TABLE IF NOT EXISTS ___database___.___table___ (___id___ INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, ___domain___ VARCHAR(128) NOT NULL, PRIMARY KEY (___domain___), UNIQUE KEY ___id___ (___id___)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;",
|
||||
'users' => "CREATE TABLE IF NOT EXISTS ___database___.___table___ (___id___ INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, ___username___ VARCHAR(128) NOT NULL DEFAULT '', ___domain___ VARCHAR(128) NOT NULL DEFAULT '', ___password___ VARCHAR(128) NOT NULL DEFAULT '', ___mailbox_limit___ INT(10) NOT NULL DEFAULT '128', ___max_user_redirects___ INT(10) NOT NULL DEFAULT '0', PRIMARY KEY (___username___,___domain___), UNIQUE KEY ___id___ (___id___)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;",
|
||||
'aliases' => "CREATE TABLE IF NOT EXISTS ___database___.___table___ (___id___ INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, ___source___ VARCHAR(128) NOT NULL, ___destination___ TEXT NOT NULL, ___multi_source___ VARCHAR(32) DEFAULT NULL, ___is_created_by_user___ INT(1) NOT NULL DEFAULT '0', PRIMARY KEY (___source___), UNIQUE KEY ___id___ (___id___)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;",
|
||||
);
|
||||
|
||||
/**
|
||||
* @param string $stmt
|
||||
* @param string $database
|
||||
* @param string $table
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function prepareSchemaTableStmt($stmt, $database, $table, $attributes)
|
||||
{
|
||||
$attributes['database'] = $database;
|
||||
$attributes['table'] = $table;
|
||||
|
||||
foreach($attributes as $search => $replace){
|
||||
$stmt = str_replace('___'.$search.'___', '`'.Database::getInstance()->escape($replace).'`', $stmt);
|
||||
}
|
||||
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
$preparedSchemaStmt = '';
|
||||
$allTablesFromSchemaExist = true;
|
||||
|
||||
foreach($databaseSchema as $table => $stmt){
|
||||
$preparedSchemaStmt .= prepareSchemaTableStmt(
|
||||
$stmt,
|
||||
$_SESSION['installer']['config']['mysql']['database'],
|
||||
$exampleConfigValues['schema']['tables'][$table],
|
||||
$exampleConfigValues['schema']['attributes'][$table]
|
||||
).PHP_EOL;
|
||||
|
||||
// check if tables exist, should be enough for now
|
||||
if(!in_array($exampleConfigValues['schema']['tables'][$table], $tablesInDatabase)){
|
||||
$allTablesFromSchemaExist = false;
|
||||
}
|
||||
}
|
||||
|
||||
$commandDenied = false;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_GET['go'])){
|
||||
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
if(isset($_POST['manual'])){
|
||||
if($_POST['manual'] == 1){
|
||||
// display SQL
|
||||
}
|
||||
elseif($_POST['manual'] == 2){
|
||||
// check if schema was created
|
||||
if($allTablesFromSchemaExist){
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['schema'] = $exampleConfigValues['schema'];
|
||||
|
||||
installer_message('Database schema was manually created.');
|
||||
|
||||
installer_next($thisStep, 2);
|
||||
}
|
||||
else{
|
||||
$_POST['manual'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(!$allTablesFromSchemaExist){
|
||||
try{
|
||||
foreach(explode(PHP_EOL, $preparedSchemaStmt) as $stmt){
|
||||
Database::getInstance()->query($stmt);
|
||||
}
|
||||
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['schema'] = $exampleConfigValues['schema'];
|
||||
|
||||
installer_message('Database schema was automatically created.');
|
||||
|
||||
installer_next($thisStep, 2);
|
||||
}
|
||||
catch(Exception $e){
|
||||
if(strpos($e->getMessage(), 'command denied') !== false){
|
||||
$commandDenied = true;
|
||||
}
|
||||
else{
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'prev'){
|
||||
// reset
|
||||
unset($_SESSION['installer']['config']['schema']);
|
||||
|
||||
installer_prev($thisStep);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>Step 2 of <?php echo INSTALLER_MAX_STEP; ?>: Create database schema.</h2>
|
||||
|
||||
<?php if($allTablesFromSchemaExist): ?>
|
||||
<div class="notification notification-fail">
|
||||
The schema already exists in database "<?php echo $_SESSION['installer']['config']['mysql']['database']; ?>".
|
||||
</div>
|
||||
|
||||
<div>
|
||||
Your next possible steps:
|
||||
<ul>
|
||||
<li>Either <strong>delete</strong> the existing schema.</li>
|
||||
<li>Go Back and <strong>change</strong> the used database.</li>
|
||||
<li>Go Back and <strong>start mapping</strong> the existing database schema.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>">Retry</a>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
<?php if(isset($_POST['manual']) && $_POST['manual'] == 1): ?>
|
||||
<textarea readonly style="width: 100%; height: 170px"><?php echo $preparedSchemaStmt; ?></textarea>
|
||||
|
||||
<div class="notification notification-warning">
|
||||
Copy the SQL-Code above and import it into your database "<?php echo $_SESSION['installer']['config']['mysql']['database']; ?>".
|
||||
</div>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<p>Once you have imported the schema, you can continue by clicking on the Continue button.</p>
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>">Back</a>
|
||||
<button class="button button-primary" name="manual" value="2" type="submit">Continue</button>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="notification notification-warning">
|
||||
The following database schema will be created in
|
||||
<strong>database "<?php echo $_SESSION['installer']['config']['mysql']['database']; ?>"</strong>.
|
||||
<br><strong>Please make sure that "<?php echo $_SESSION['installer']['config']['mysql']['database']; ?>" is clean / empty database!</strong>
|
||||
</div>
|
||||
|
||||
<?php if($commandDenied): ?>
|
||||
<div class="notification notification-fail">The
|
||||
<strong>user "<?php echo $_SESSION['installer']['config']['mysql']['user']; ?>" is missing the permission</strong> to execute MySQL "CREATE" commands.
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="notification notification-warning">
|
||||
Also <strong>make sure</strong> that the database
|
||||
<strong>user "<?php echo $_SESSION['installer']['config']['mysql']['user']; ?>" has the privileges to create</strong> the schema.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach($exampleConfigValues['schema']['tables'] as $table => $mappedTable): ?>
|
||||
<div>
|
||||
<strong>Table "<?php echo $table; ?>"</strong>
|
||||
<ul>
|
||||
<?php foreach($exampleConfigValues['schema']['attributes'][$table] as $attribute => $mappedAttribute): ?>
|
||||
<li><?php echo $attribute; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<p>Click on the Continue button to try creating the schema automatically.</p>
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button" name="manual" value="1" type="submit">Import schema manually</button>
|
||||
<button class="button button-primary" type="submit">Continue</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<?php endif; ?>
|
306
installer/step3.php
Normal file
306
installer/step3.php
Normal file
|
@ -0,0 +1,306 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 3;
|
||||
|
||||
if($_SESSION['installer']['lastStep'] > $thisStep){
|
||||
$_SESSION['installer']['subStep'] = 1;
|
||||
}
|
||||
elseif($_SESSION['installer']['lastStep'] < $thisStep || !isset($_SESSION['installer']['subStep'])){
|
||||
$_SESSION['installer']['subStep'] = 0;
|
||||
}
|
||||
|
||||
$error = null;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$exampleConfigValues = require_once 'config/config.php.example';
|
||||
|
||||
$tablesInDatabase = array();
|
||||
try{
|
||||
Database::init($_SESSION['installer']['config']['mysql']);
|
||||
|
||||
$db = Database::getInstance();
|
||||
$tablesResult = $db->query(
|
||||
"SELECT TABLE_NAME FROM information_schema.tables "
|
||||
."WHERE TABLE_SCHEMA='".$db->escape($_SESSION['installer']['config']['mysql']['database'])."';"
|
||||
);
|
||||
|
||||
foreach($tablesResult->fetch_all() as $row){
|
||||
$tablesInDatabase[] = $row[0];
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
}
|
||||
|
||||
function getTableAttributes($table)
|
||||
{
|
||||
global $_SESSION;
|
||||
$attributes = array();
|
||||
|
||||
if(Database::isInitialized()){
|
||||
try{
|
||||
$db = Database::getInstance();
|
||||
$tablesResult = $db->query(
|
||||
"SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_KEY, EXTRA FROM information_schema.columns "
|
||||
."WHERE TABLE_SCHEMA = '".$db->escape($_SESSION['installer']['config']['mysql']['database'])."' "
|
||||
."AND TABLE_NAME = '".$db->escape($table)."' "
|
||||
."ORDER BY TABLE_NAME,ORDINAL_POSITION;"
|
||||
);
|
||||
|
||||
foreach($tablesResult->fetch_all() as $row){
|
||||
$s = $row[0];
|
||||
|
||||
if(!empty($row[1])){
|
||||
$s .= ' : '.$row[1];
|
||||
}
|
||||
|
||||
if($row[2] == 'NO'){
|
||||
$s .= ', NOT NULL';
|
||||
}
|
||||
|
||||
if(!is_null($row[3])){
|
||||
$s .= ', DEFAULT \''.$row[3].'\'';
|
||||
}
|
||||
|
||||
if(!empty($row[4])){
|
||||
if(strpos($row[4], 'PR') !== false){
|
||||
$s .= ', PRIMARY KEY';
|
||||
}
|
||||
if(strpos($row[4], 'UN') !== false){
|
||||
$s .= ', UNIQUE KEY';
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($row[5]) && strpos($row[5], 'auto_inc') !== false){
|
||||
$s .= ', AUTO_INCREMENT';
|
||||
}
|
||||
|
||||
$attributes[$row[0]] = $s;
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
$optionalAttributes = array(
|
||||
'users' => array('mailbox_limit', 'max_user_redirects'),
|
||||
'aliases' => array('multi_source', 'is_created_by_user'),
|
||||
);
|
||||
|
||||
define('ATTR_SEP', '---');
|
||||
|
||||
function getAttr($name, $default = null)
|
||||
{
|
||||
global $_SESSION, $_POST;
|
||||
|
||||
if(isset($_POST[$name])){
|
||||
return strip_tags($_POST[$name]);
|
||||
}
|
||||
elseif(strpos($name, ATTR_SEP) !== false){
|
||||
list($table, $attribute) = explode(ATTR_SEP, $name);
|
||||
|
||||
if(isset($_SESSION['installer']['config']['schema']['attributes'][$table][$attribute])){
|
||||
return $_SESSION['installer']['config']['schema']['attributes'][$table][$attribute];
|
||||
}
|
||||
}
|
||||
elseif(isset($_SESSION['installer']['config']['schema']['tables'][$name])){
|
||||
return $_SESSION['installer']['config']['schema']['tables'][$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_GET['go'])){
|
||||
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
try{
|
||||
if($_SESSION['installer']['subStep'] === 0){
|
||||
|
||||
$tables = array();
|
||||
foreach($exampleConfigValues['schema']['tables'] as $table => $mappedTable){
|
||||
if(!isset($_POST[$table])
|
||||
|| !in_array($_POST[$table], $tablesInDatabase)
|
||||
){
|
||||
throw new InvalidArgumentException('Missing mapping for table "'.$table.'".');
|
||||
}
|
||||
|
||||
if(in_array($_POST[$table], array_values($tables))){
|
||||
throw new Exception('You cannot map table "'.$_POST[$table].'" twice.');
|
||||
}
|
||||
|
||||
$tables[$table] = $_POST[$table];
|
||||
}
|
||||
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['schema'] = array();
|
||||
$_SESSION['installer']['config']['schema']['tables'] = $tables;
|
||||
|
||||
installer_message('Database tables were successfully mapped.');
|
||||
|
||||
$_SESSION['installer']['subStep'] = 1;
|
||||
installer_next($thisStep, 0);
|
||||
}
|
||||
elseif($_SESSION['installer']['subStep'] === 1){
|
||||
|
||||
$attributes = array();
|
||||
foreach($_SESSION['installer']['config']['schema']['tables'] as $table => $mappedTable){
|
||||
|
||||
$attributes[$table] = array();
|
||||
|
||||
$attributesInDatabase = getTableAttributes($table);
|
||||
|
||||
foreach($exampleConfigValues['schema']['attributes'][$table] as $attribute => $mappedAttribute){
|
||||
$key = $table.'---'.$attribute;
|
||||
|
||||
if(isset($optionalAttributes[$table])
|
||||
&& in_array($attribute, $optionalAttributes[$table])
|
||||
&& !isset($attributesInDatabase[$_POST[$key]])
|
||||
){
|
||||
$attributes[$table][$attribute] = '';
|
||||
}
|
||||
else{
|
||||
if(!isset($_POST[$key]) || !isset($attributesInDatabase[$_POST[$key]])){
|
||||
throw new InvalidArgumentException('Missing mapping for attribute "'.$attribute.'" on table "'.$table.'".');
|
||||
}
|
||||
|
||||
if(in_array($_POST[$key], $attributes[$table])){
|
||||
throw new Exception('You cannot map attribute "'.$_POST[$key].'" twice on table "'.$table.'".');
|
||||
}
|
||||
|
||||
$attributes[$table][$attribute] = $_POST[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['schema']['attributes'] = $attributes;
|
||||
|
||||
installer_message('Database attributes were successfully mapped.');
|
||||
|
||||
unset($_SESSION['installer']['subStep']);
|
||||
installer_next($thisStep);
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'prev'){
|
||||
|
||||
// reset
|
||||
if(isset($_SESSION['installer']['config']['schema']['tables'])){
|
||||
if($_SESSION['installer']['subStep'] === 0){
|
||||
unset($_SESSION['installer']['config']['schema']);
|
||||
}
|
||||
elseif($_SESSION['installer']['subStep'] === 1){
|
||||
unset($_SESSION['installer']['config']['schema']['attributes']);
|
||||
}
|
||||
}
|
||||
|
||||
if($_SESSION['installer']['subStep'] === 0){
|
||||
unset($_SESSION['installer']['subStep']);
|
||||
installer_prev($thisStep, ($_SESSION['installer']['type'] === INSTALLER_TYPE_MAP) ? 2 : 1);
|
||||
}
|
||||
else{
|
||||
$_SESSION['installer']['subStep'] = 0;
|
||||
installer_prev($thisStep, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>
|
||||
Step 2 of <?php echo INSTALLER_MAX_STEP; ?>:
|
||||
<?php if($_SESSION['installer']['subStep'] === 0): ?>
|
||||
Database - table mapping.
|
||||
<?php elseif($_SESSION['installer']['subStep'] === 1): ?>
|
||||
Database - attribute mapping.
|
||||
<?php else: ?>
|
||||
Wrong turn
|
||||
<?php endif; ?>
|
||||
</h2>
|
||||
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="notification notification-fail"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($_SESSION['installer']['subStep'] === 0): ?>
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
<?php foreach($exampleConfigValues['schema']['tables'] as $table => $mappedTable): ?>
|
||||
<div class="input-group">
|
||||
<label for="<?php echo $table; ?>">Table "<?php echo $table; ?>"</label>
|
||||
<div class="input">
|
||||
<select name="<?php echo $table; ?>">
|
||||
<option value="">-- Not mapped --</option>
|
||||
<?php foreach($tablesInDatabase as $t): ?>
|
||||
<option value="<?php echo $t; ?>" <?php echo getAttr($table, $mappedTable) == $t ? 'selected' : ''; ?>><?php echo $t; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button button-primary" type="submit">Continue</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php elseif($_SESSION['installer']['subStep'] === 1): ?>
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
<?php
|
||||
$lastTable = array_keys($_SESSION['installer']['config']['schema']['tables']);
|
||||
$lastTable = $lastTable[count($lastTable) - 1];
|
||||
foreach($_SESSION['installer']['config']['schema']['tables'] as $table => $mappedTable):
|
||||
$attributesInDatabase = getTableAttributes($mappedTable);
|
||||
?>
|
||||
<h3>
|
||||
Table "<?php echo $table; ?>"
|
||||
<div class="sub-header">Has been mapped to table "<?php echo $mappedTable; ?>".</div>
|
||||
</h3>
|
||||
<div style="margin-left: 25px;">
|
||||
<?php foreach($exampleConfigValues['schema']['attributes'][$table] as $attribute => $mappedAttribute): ?>
|
||||
<div class="input-group">
|
||||
<label for="<?php echo $table.ATTR_SEP.$attribute; ?>">Attribute "<?php echo $attribute; ?>"</label>
|
||||
<?php if(isset($optionalAttributes[$table]) && in_array($attribute, $optionalAttributes[$table])): ?>
|
||||
<div class="input-info">This attribute is optional (used by optional features) and doesn't need to be mapped.</div>
|
||||
<?php endif; ?>
|
||||
<div class="input">
|
||||
<select name="<?php echo $table.ATTR_SEP.$attribute; ?>">
|
||||
<option value="">-- Not mapped --</option>
|
||||
<?php foreach($attributesInDatabase as $dbAttr => $dbAttrText): ?>
|
||||
<option value="<?php echo $dbAttr; ?>" <?php echo getAttr($table.ATTR_SEP.$attribute, $mappedAttribute) == $dbAttr ? 'selected' : ''; ?>><?php echo $dbAttrText; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if($table != $lastTable): ?>
|
||||
<hr>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button button-primary" type="submit">Continue</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<div class="notification notification-fail">You took the wrong turn, <a href="/">restart installation</a>.</div>
|
||||
<?php endif; ?>
|
216
installer/step4.php
Normal file
216
installer/step4.php
Normal file
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 4;
|
||||
|
||||
$error = null;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$exampleConfigValues = require_once 'config/config.php.example';
|
||||
|
||||
$hashAlgorithms = array(
|
||||
'SHA-512',
|
||||
'SHA-256',
|
||||
'BLOWFISH',
|
||||
);
|
||||
|
||||
Database::init($_SESSION['installer']['config']['mysql']);
|
||||
|
||||
$databaseUserCount = Database::getInstance()->count(
|
||||
$_SESSION['installer']['config']['schema']['tables']['users'],
|
||||
$_SESSION['installer']['config']['schema']['attributes']['users']['id']
|
||||
);
|
||||
|
||||
function getAttr($name, $default = null)
|
||||
{
|
||||
global $_SESSION, $_POST;
|
||||
|
||||
if(isset($_POST[$name])){
|
||||
return strip_tags($_POST[$name]);
|
||||
}
|
||||
elseif(isset($_SESSION['installer']['config']['password'][$name])){
|
||||
return $_SESSION['installer']['config']['password'][$name];
|
||||
}
|
||||
elseif($name === 'admin_user' && isset($_SESSION['installer']['user']['user'])){
|
||||
return $_SESSION['installer']['user']['user'];
|
||||
}
|
||||
elseif($name === 'admin_password' && isset($_SESSION['installer']['user']['password'])){
|
||||
return $_SESSION['installer']['user']['password'];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_GET['go'])){
|
||||
|
||||
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
try{
|
||||
if(!isset($_POST['hash_algorithm']) || !isset($_POST['min_length']) || !isset($_POST['admin_user']) || !isset($_POST['admin_password'])){
|
||||
throw new InvalidArgumentException;
|
||||
}
|
||||
|
||||
$passwordConfig = array(
|
||||
'hash_algorithm' => in_array($_POST['hash_algorithm'], $hashAlgorithms) ? $_POST['hash_algorithm'] : $exampleConfigValues['password']['hash_algorithm'],
|
||||
'min_length' => intval($_POST['min_length']),
|
||||
);
|
||||
|
||||
// init system for testing
|
||||
Config::init(array('password' => $passwordConfig));
|
||||
|
||||
// handle user
|
||||
if($databaseUserCount > 0){
|
||||
// testing existing login
|
||||
|
||||
$validLogin = Auth::login($_POST['admin_user'], $_POST['admin_password']);
|
||||
unset($_SESSION[Auth::SESSION_IDENTIFIER]);
|
||||
|
||||
if(!$validLogin){
|
||||
throw new Exception('Invalid combination of user and password.');
|
||||
}
|
||||
}
|
||||
else{
|
||||
// create user in database
|
||||
|
||||
if(strpos($_POST['admin_user'], '@') === false){
|
||||
throw new Exception('The field "Your user" must be an email address.');
|
||||
}
|
||||
else{
|
||||
list($username, $domain) = explode('@', $_POST['admin_user']);
|
||||
$passwordHash = Auth::generatePasswordHash($_POST['admin_password']);
|
||||
|
||||
$hasDomain = Database::getInstance()->count(
|
||||
$_SESSION['installer']['config']['schema']['tables']['domains'],
|
||||
$_SESSION['installer']['config']['schema']['attributes']['domains']['id'],
|
||||
array($_SESSION['installer']['config']['schema']['attributes']['domains']['domain'], $domain)
|
||||
);
|
||||
if($hasDomain === 0){
|
||||
Database::getInstance()->insert(
|
||||
$_SESSION['installer']['config']['schema']['tables']['domains'],
|
||||
array(
|
||||
$_SESSION['installer']['config']['schema']['attributes']['domains']['domain'] => $domain,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Database::getInstance()->insert(
|
||||
$_SESSION['installer']['config']['schema']['tables']['users'],
|
||||
array(
|
||||
$_SESSION['installer']['config']['schema']['attributes']['users']['username'] => $username,
|
||||
$_SESSION['installer']['config']['schema']['attributes']['users']['domain'] => $domain,
|
||||
$_SESSION['installer']['config']['schema']['attributes']['users']['password'] => $passwordHash,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['password'] = $passwordConfig;
|
||||
$_SESSION['installer']['config']['admins'] = array($_POST['admin_user']);
|
||||
$_SESSION['installer']['config']['admin_domain_limits'] = array();
|
||||
$_SESSION['installer']['user'] = array(
|
||||
'user' => $_POST['admin_user'],
|
||||
'password' => $_POST['admin_password'],
|
||||
);
|
||||
|
||||
installer_message('You have successfully added your first admin user.');
|
||||
|
||||
installer_next($thisStep);
|
||||
}
|
||||
catch(InvalidArgumentException $e){
|
||||
$error = 'Some fields are missing.';
|
||||
}
|
||||
catch(Exception $e){
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'prev'){
|
||||
// reset
|
||||
unset($_SESSION['installer']['config']['password']);
|
||||
unset($_SESSION['installer']['config']['admins']);
|
||||
unset($_SESSION['installer']['config']['admin_domain_limits']);
|
||||
unset($_SESSION['installer']['user']);
|
||||
|
||||
installer_prev($thisStep, ($_SESSION['installer']['type'] === INSTALLER_TYPE_MAP) ? 1 : 2);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>Step 3 of <?php echo INSTALLER_MAX_STEP; ?>: Your first admin user.</h2>
|
||||
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="notification notification-fail"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
<div class="input-group">
|
||||
<label for="password">Password hash algorithm</label>
|
||||
<div class="input-info">Hash algorithm that you chose in your mailserver installation process.</div>
|
||||
<div class="input">
|
||||
<select name="hash_algorithm">
|
||||
<?php foreach($hashAlgorithms as $algo): ?>
|
||||
<option value="<?php echo $algo; ?>" <?php echo getAttr('hash_algorithm', $exampleConfigValues['password']['hash_algorithm']) == $algo ? 'selected' : ''; ?>>
|
||||
<?php echo $algo; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="min_length">Minimum password length</label>
|
||||
<div class="input">
|
||||
<div class="input input-labeled input-labeled-right">
|
||||
<input name="min_length" type="number" value="<?php echo getAttr('min_length', $exampleConfigValues['password']['min_length']); ?>" placeholder="Mailbox limit in MB" min="0"/>
|
||||
<span class="input-label">chars</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<?php if($databaseUserCount === 0): ?>
|
||||
<div class="notification notification-warning">
|
||||
There is no user created yet, please create one now as your admin user.
|
||||
<br>Please note that once the user is created you will have to remember the password.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<p>This user will be mark as an admin in the configuration.</p>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="admin_user">Your user</label>
|
||||
<div class="input-info">
|
||||
Must be an email address (user@domain).<br>
|
||||
<?php if($databaseUserCount > 0): ?>
|
||||
This user must have been added in mailserver installation process.<br>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="input">
|
||||
<input type="text" name="admin_user" value="<?php echo getAttr('admin_user'); ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="admin_password">Your password</label>
|
||||
<div class="input">
|
||||
<input type="password" name="admin_password" value="<?php echo getAttr('admin_password'); ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button button-primary" type="submit">Continue</button>
|
||||
</div>
|
||||
</form>
|
150
installer/step5.php
Normal file
150
installer/step5.php
Normal file
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 5;
|
||||
|
||||
$error = null;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$exampleConfigValues = require_once 'config/config.php.example';
|
||||
|
||||
$possibleEmailSeparatorsText = array(', ', '; ', "\n");
|
||||
$possibleEmailSeparatorsForm = array(',', ';', "\n");
|
||||
|
||||
function getAttr($name, $default = null)
|
||||
{
|
||||
global $_SESSION, $_POST;
|
||||
|
||||
if(isset($_POST[$name])){
|
||||
return strip_tags($_POST[$name]);
|
||||
}
|
||||
elseif($name === 'base_url' && isset($_SESSION['installer']['config']['base_url'])){
|
||||
return $_SESSION['installer']['config']['base_url'];
|
||||
}
|
||||
elseif(isset($_SESSION['installer']['config']['frontend_options'][$name])){
|
||||
return $_SESSION['installer']['config']['frontend_options'][$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_GET['go'])){
|
||||
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
try{
|
||||
if(!isset($_POST['base_url']) || empty($_POST['base_url'])){
|
||||
throw new Exception('The field URL isn\'t filled out yet.');
|
||||
}
|
||||
if(!isset($_POST['email_separator_text'])
|
||||
|| !is_numeric($_POST['email_separator_text'])
|
||||
|| !isset($possibleEmailSeparatorsText[$_POST['email_separator_text']])
|
||||
|| !isset($_POST['email_separator_form'])
|
||||
|| !is_numeric($_POST['email_separator_form'])
|
||||
|| !isset($possibleEmailSeparatorsForm[$_POST['email_separator_form']])
|
||||
){
|
||||
throw new InvalidArgumentException;
|
||||
}
|
||||
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['base_url'] = $_POST['base_url'];
|
||||
$_SESSION['installer']['config']['frontend_options'] = array(
|
||||
'email_separator_text' => $possibleEmailSeparatorsText[$_POST['email_separator_text']],
|
||||
'email_separator_form' => $possibleEmailSeparatorsForm[$_POST['email_separator_form']],
|
||||
);
|
||||
|
||||
installer_message('General settings saved.');
|
||||
|
||||
installer_next($thisStep);
|
||||
}
|
||||
catch(InvalidArgumentException $e){
|
||||
$error = 'Some field is missing.';
|
||||
}
|
||||
catch(Exception $e){
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'prev'){
|
||||
// reset
|
||||
unset($_SESSION['installer']['config']['base_url']);
|
||||
unset($_SESSION['installer']['config']['frontend_options']);
|
||||
|
||||
installer_prev($thisStep);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>Step 4 of <?php echo INSTALLER_MAX_STEP; ?>: General settings</h2>
|
||||
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="notification notification-fail"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="base_url">URL to this WebMUM installation</label>
|
||||
<div class="input-info">
|
||||
The URL your WebMUM installation is accessible from outside including subdirectories, ports and the protocol.
|
||||
<br><br>Some examples:
|
||||
<ul style="margin: 2px 0">
|
||||
<li>http://localhost/webmum</li>
|
||||
<li>http://webmum.mydomain.tld</li>
|
||||
<li>https://mydomain.tld/dir</li>
|
||||
<li>http://mydomain.tld:8080</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="input">
|
||||
<input type="text" name="base_url" value="<?php echo getAttr('base_url'); ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="input-group">
|
||||
<label>Separator for email lists</label>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="email_separator_text">… in texts.</label>
|
||||
<div class="input">
|
||||
<input type="radio" name="email_separator_text" id="email_separator_text_0" value="0" <?php echo (getAttr('email_separator_text', 0) == 0) ? 'checked' : ''; ?>>
|
||||
<label for="email_separator_text_0">comma: <code>', '</code></label>
|
||||
|
||||
<input type="radio" name="email_separator_text" id="email_separator_text_1" value="1" <?php echo (getAttr('email_separator_text', 0) == 1) ? 'checked' : ''; ?>>
|
||||
<label for="email_separator_text_1">semicolon: <code>'; '</code></label>
|
||||
|
||||
<input type="radio" name="email_separator_text" id="email_separator_text_2" value="2" <?php echo (getAttr('email_separator_text', 0) == 2) ? 'checked' : ''; ?>>
|
||||
<label for="email_separator_text_2">newline: <code>'<br>'</code></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="email_separator_form">… in forms.</label>
|
||||
<div class="input">
|
||||
<input type="radio" name="email_separator_form" id="email_separator_form_0" value="0" <?php echo (getAttr('email_separator_form', 0) == 0) ? 'checked' : ''; ?>>
|
||||
<label for="email_separator_form_0">comma: <code>','</code></label>
|
||||
|
||||
<input type="radio" name="email_separator_form" id="email_separator_form_1" value="1" <?php echo (getAttr('email_separator_form', 0) == 1) ? 'checked' : ''; ?>>
|
||||
<label for="email_separator_form_1">semicolon: <code>';'</code></label>
|
||||
|
||||
<input type="radio" name="email_separator_form" id="email_separator_form_2" value="2" <?php echo (getAttr('email_separator_form', 0) == 2) ? 'checked' : ''; ?>>
|
||||
<label for="email_separator_form_2">newline: <code>'\n'</code></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button button-primary" type="submit">Continue</button>
|
||||
</div>
|
||||
</form>
|
270
installer/step6.php
Normal file
270
installer/step6.php
Normal file
|
@ -0,0 +1,270 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 6;
|
||||
|
||||
$error = null;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$exampleConfigValues = require_once 'config/config.php.example';
|
||||
|
||||
function getAttr($name, $default = null)
|
||||
{
|
||||
global $_SESSION, $_POST;
|
||||
|
||||
if(isset($_POST[$name])){
|
||||
return strip_tags($_POST[$name]);
|
||||
}
|
||||
elseif(isset($_SESSION['installer']['config']['options'][$name])){
|
||||
return $_SESSION['installer']['config']['options'][$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_GET['go'])){
|
||||
|
||||
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
try{
|
||||
$options = array();
|
||||
|
||||
// Mailbox limits
|
||||
if(isset($_POST['enable_mailbox_limits']) && $_POST['enable_mailbox_limits'] == 1){
|
||||
if(empty($_SESSION['installer']['config']['schema']['attributes']['users']['mailbox_limit'])){
|
||||
throw new Exception('Mailbox limits couldn\'t be enabled, because the attribute "mailbox_limit" in database table "users" is missing or not mapped yet');
|
||||
}
|
||||
else{
|
||||
$options['enable_mailbox_limits'] = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$options['enable_mailbox_limits'] = false;
|
||||
}
|
||||
|
||||
// Validate source addresses in redirects
|
||||
if(isset($_POST['enable_validate_aliases_source_domain']) && $_POST['enable_validate_aliases_source_domain'] == 1){
|
||||
$options['enable_validate_aliases_source_domain'] = true;
|
||||
}
|
||||
else{
|
||||
$options['enable_validate_aliases_source_domain'] = false;
|
||||
}
|
||||
|
||||
// Multiple source redirect support
|
||||
if(isset($_POST['enable_multi_source_redirects']) && $_POST['enable_multi_source_redirects'] == 1){
|
||||
if(empty($_SESSION['installer']['config']['schema']['attributes']['aliases']['multi_source'])){
|
||||
throw new Exception('Multiple source redirect support couldn\'t be enabled, because the attribute "multi_source" in database table "aliases" is missing or not mapped yet');
|
||||
}
|
||||
else{
|
||||
$options['enable_multi_source_redirects'] = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$options['enable_multi_source_redirects'] = false;
|
||||
}
|
||||
|
||||
// Admin domain limits
|
||||
if(isset($_POST['enable_admin_domain_limits']) && $_POST['enable_admin_domain_limits'] == 1){
|
||||
$options['enable_admin_domain_limits'] = true;
|
||||
}
|
||||
else{
|
||||
$options['enable_admin_domain_limits'] = false;
|
||||
}
|
||||
|
||||
// Users redirects
|
||||
if(isset($_POST['enable_user_redirects']) && $_POST['enable_user_redirects'] == 1){
|
||||
if(empty($_SESSION['installer']['config']['schema']['attributes']['users']['max_user_redirects'])
|
||||
|| empty($_SESSION['installer']['config']['schema']['attributes']['aliases']['is_created_by_user'])
|
||||
){
|
||||
throw new Exception('Users redirects couldn\'t be enabled, because some database attributes are missing or not mapped yet');
|
||||
}
|
||||
else{
|
||||
$options['enable_user_redirects'] = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$options['enable_user_redirects'] = false;
|
||||
}
|
||||
|
||||
// Logging for failed login attempts
|
||||
$logPath = '';
|
||||
if(isset($_POST['enable_logging']) && $_POST['enable_logging'] == 1){
|
||||
$options['enable_logging'] = true;
|
||||
|
||||
if(!isset($_POST['log_path']) || empty($_POST['log_path'])){
|
||||
throw new Exception('You need to set the log path if you enabled logging.');
|
||||
}
|
||||
|
||||
$logPath = $_POST['log_path'];
|
||||
|
||||
if(!file_exists($_POST['log_path'])){
|
||||
throw new Exception('The log path you set doesn\'t exist.');
|
||||
}
|
||||
|
||||
if(!is_writable($_POST['log_path'])){
|
||||
throw new Exception('The log path you set isn\'t writable.');
|
||||
}
|
||||
}
|
||||
else{
|
||||
$options['enable_logging'] = false;
|
||||
}
|
||||
|
||||
// saving information
|
||||
$_SESSION['installer']['config']['options'] = $options;
|
||||
$_SESSION['installer']['config']['log_path'] = $logPath;
|
||||
|
||||
installer_message('Saved settings for optional features.');
|
||||
|
||||
installer_next($thisStep);
|
||||
}
|
||||
catch(Exception $e){
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'prev'){
|
||||
// reset
|
||||
unset($_SESSION['installer']['config']['options']);
|
||||
unset($_SESSION['installer']['config']['log_path']);
|
||||
|
||||
installer_prev($thisStep);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>Step 5 of <?php echo INSTALLER_MAX_STEP; ?>: Optional features</h2>
|
||||
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="notification notification-fail"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
|
||||
<div class="input-group">
|
||||
<label for="enable_mailbox_limits">Mailbox limits</label>
|
||||
<div class="input-info">Limit the maximum size of mailbox for users.</div>
|
||||
<?php if(empty($_SESSION['installer']['config']['schema']['attributes']['users']['mailbox_limit'])): ?>
|
||||
<p class="text-warning">
|
||||
<strong>This feature cannot be enabled because the attribute "mailbox_limit" in database table "users" is missing or not mapped yet.</strong>
|
||||
<br><br>You could go back and create / map the missing attribute.
|
||||
</p>
|
||||
<?php else: ?>
|
||||
<div class="input">
|
||||
<input type="checkbox" name="enable_mailbox_limits" id="enable_mailbox_limits" value="1" <?php echo getAttr('enable_mailbox_limits', false) ? 'checked' : ''; ?>>
|
||||
<label for="enable_mailbox_limits">Enable feature</label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="enable_validate_aliases_source_domain">Validate source addresses in redirects</label>
|
||||
<div class="input-info">Only email addresses ending with a domain from domains will be allowed.</div>
|
||||
<div class="input">
|
||||
<input type="checkbox" name="enable_validate_aliases_source_domain" id="enable_validate_aliases_source_domain" value="1" <?php echo getAttr('enable_validate_aliases_source_domain', true) ? 'checked' : ''; ?>>
|
||||
<label for="enable_validate_aliases_source_domain">Enable feature</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="enable_multi_source_redirects">Multiple source redirect support</label>
|
||||
<div class="input-info">Redirects can have multiple source addresses. This enables you to enter multiple redirects to a destination at once.</div>
|
||||
<?php if(empty($_SESSION['installer']['config']['schema']['attributes']['aliases']['multi_source'])): ?>
|
||||
<p class="text-warning">
|
||||
<strong>This feature cannot be enabled because the attribute "multi_source" in database table "aliases" is missing or not mapped yet.</strong>
|
||||
<br><br>You could go back and create / map the missing attribute.
|
||||
</p>
|
||||
<?php else: ?>
|
||||
<div class="input">
|
||||
<input type="checkbox" name="enable_multi_source_redirects" id="enable_multi_source_redirects" value="1" <?php echo getAttr('enable_multi_source_redirects', false) ? 'checked' : ''; ?>>
|
||||
<label for="enable_multi_source_redirects">Enable feature</label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="enable_admin_domain_limits">Admin domain limits</label>
|
||||
<div class="input-info">
|
||||
Limit certain admins to have access to certain domains only.
|
||||
<br>Note: This needs to be manually configured in the <code>'admin_domain_limits'</code> config variable.
|
||||
</div>
|
||||
<div class="input">
|
||||
<input type="checkbox" name="enable_admin_domain_limits" id="enable_admin_domain_limits" value="1" <?php echo getAttr('enable_admin_domain_limits', false) ? 'checked' : ''; ?>>
|
||||
<label for="enable_admin_domain_limits">Enable feature</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="enable_user_redirects">Users redirects</label>
|
||||
<div class="input-info">
|
||||
Enable users to create their redirects on their own.
|
||||
<br>Users can also be limited to a maximum number of redirects they can create.
|
||||
</div>
|
||||
<?php if(empty($_SESSION['installer']['config']['schema']['attributes']['users']['max_user_redirects']) || empty($_SESSION['installer']['config']['schema']['attributes']['aliases']['is_created_by_user'])): ?>
|
||||
<p class="text-warning">
|
||||
<strong>This feature cannot be enabled because,
|
||||
<?php if(empty($_SESSION['installer']['config']['schema']['attributes']['users']['max_user_redirects']) && empty($_SESSION['installer']['config']['schema']['attributes']['aliases']['is_created_by_user'])): ?>
|
||||
there are missing attributes in two database tables:</strong>
|
||||
<ul>
|
||||
<li>"max_user_redirects" in "users"</li>
|
||||
<li>"is_created_by_user" in "aliases"</li>
|
||||
</ul>
|
||||
<br>You could go back and create / map the missing attributes.
|
||||
<?php else: ?>
|
||||
the attribute <?php echo empty($_SESSION['installer']['config']['schema']['attributes']['users']['max_user_redirects']) ? '"max_user_redirects" in database table "users"' : '"is_created_by_user" in database table "aliases"'; ?> is missing or not mapped yet.
|
||||
<?php endif; ?>
|
||||
</strong>
|
||||
<br><br>You could go back and create / map the missing attributes.
|
||||
</p>
|
||||
<?php else: ?>
|
||||
<div class="input">
|
||||
<input type="checkbox" name="enable_user_redirects" id="enable_user_redirects" value="1" <?php echo getAttr('enable_user_redirects', false) ? 'checked' : ''; ?>>
|
||||
<label for="enable_user_redirects">Enable feature</label>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="enable_logging">Logging for failed login attempts</label>
|
||||
<div class="input-info">
|
||||
WebMUM will write messages into the logfile.
|
||||
<br>The logfile could be used by <strong>Fail2ban</strong> to block brute-forcing attacks.
|
||||
</div>
|
||||
<div class="input">
|
||||
<input type="checkbox" name="enable_logging" id="enable_logging" value="1" <?php echo getAttr('enable_logging', false) ? 'checked' : ''; ?>>
|
||||
<label for="enable_logging">Enable feature</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="log_path">Log path</label>
|
||||
<div class="input-info">Directory where the <code>webmum.log</code> should be written to:</div>
|
||||
<div class="input">
|
||||
<input type="text" name="log_path" value="<?php echo getAttr('log_path'); ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button button-primary" type="submit">Continue</button>
|
||||
</div>
|
||||
</form>
|
152
installer/step7.php
Normal file
152
installer/step7.php
Normal file
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
if(strpos($_SERVER['REQUEST_URI'], 'installer/') !== false){
|
||||
die('You cannot directly access the installer files.');
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$thisStep = 7;
|
||||
|
||||
$error = '';
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
$configPath = dirname(__DIR__).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php';
|
||||
|
||||
$configString = '<?php'.PHP_EOL
|
||||
.'// This config has been automatically generated by the WebMUM installer.'.PHP_EOL.PHP_EOL
|
||||
.'return '.var_export($_SESSION['installer']['config'], true).';'.PHP_EOL;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
if(isset($_SESSION['installer']['finished'])){
|
||||
if(!file_exists($configPath)){
|
||||
unset($_SESSION['installer']['finished']);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_GET['go'])){
|
||||
|
||||
if($_GET['go'] == 'next' && $_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
try{
|
||||
if(isset($_POST['automatic']) && $_POST['automatic'] == 1){
|
||||
if(file_exists($configPath)){
|
||||
throw new Exception('The file "'.$configPath.'"" already exists, if you\'ve already written the config manually then complete manually.');
|
||||
}
|
||||
|
||||
if(!file_exists(dirname($configPath)) || !is_dir(dirname($configPath))){
|
||||
throw new Exception('The directory "'.dirname($configPath).'"" is missing.');
|
||||
}
|
||||
|
||||
// Write config
|
||||
if(file_put_contents($configPath, $configString) === false){
|
||||
throw new Exception('Couldn\'t automatically write config to "'.$configPath.'", please write the config on your own.');
|
||||
}
|
||||
|
||||
$_SESSION['installer']['finished'] = true;
|
||||
}
|
||||
elseif(isset($_POST['manual']) && $_POST['manual'] == 1){
|
||||
|
||||
if(!file_exists($configPath)){
|
||||
throw new Exception('You need to write the config file first before you can manually complete the installation.');
|
||||
}
|
||||
|
||||
$configValues = require_once 'config/config.php';
|
||||
if(!is_array($configValues)){
|
||||
throw new Exception('The data in the config file is invalid, please try again and be sure to use the config provided below.');
|
||||
}
|
||||
|
||||
$_SESSION['installer']['finished'] = true;
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'finish'){
|
||||
try{
|
||||
if(isset($_SESSION['installer']['finished'])){
|
||||
// Load config
|
||||
$configValues = include_once 'config/config.php';
|
||||
if(!is_array($configValues)){
|
||||
throw new Exception('Error writing the config, please manually write the config to "'.$configPath.'".');
|
||||
}
|
||||
|
||||
// Init system
|
||||
Config::init($configValues);
|
||||
Database::init(Config::get('mysql'));
|
||||
Auth::init();
|
||||
|
||||
// Login user
|
||||
Auth::login($_SESSION['installer']['user']['user'], $_SESSION['installer']['user']['password']);
|
||||
|
||||
// Reset installer
|
||||
unset($_SESSION['installer']);
|
||||
|
||||
Router::redirect('/');
|
||||
}
|
||||
}
|
||||
catch(Exception $e){
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
elseif($_GET['go'] == 'prev'){
|
||||
installer_prev($thisStep);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if(isset($_SESSION['installer']['finished'])): ?>
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=finish" method="post">
|
||||
<div class="notification notification-success">You finished your installation!</div>
|
||||
|
||||
<h2 style="text-align: center;">Welcome to WebMUM - Web Mailserver User Manager.</h2>
|
||||
|
||||
<div>
|
||||
If you like this project, be sure to give us a Star and Follow the project on GitHub <a target="_blank" href="https://git.io/vwXhh">https://github.com/ohartl/webmum</a>
|
||||
|
||||
<ol>
|
||||
<li>To change the configuration you have to edit to config file "<?php echo $configPath; ?>" (see <a target="_blank" href="https://git.io/vwXhh#webmum-configuration">the README</a> for further instructions.</li>
|
||||
<li>If you've found a bug or got a great idea, feel free to submit an issue on GitHub <a target="_blank" href="https://git.io/vrnOM">here</a>.</li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<p>By clicking Finish you will end the installation process and get logged in automatically.</p>
|
||||
|
||||
<div class="buttons">
|
||||
<button class="button button-primary" type="submit">Finish & Start using WebMUM</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<?php echo installer_message(); ?>
|
||||
|
||||
<h2>Step 6 of <?php echo INSTALLER_MAX_STEP; ?>: Write the config & finish the installation!</h2>
|
||||
|
||||
<?php if(!empty($error)): ?>
|
||||
<div class="notification notification-fail"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
<form class="form" action="/?step=<?php echo $thisStep; ?>&go=next" method="post">
|
||||
<p>The following config needs to be written to <code><?php echo $configPath; ?></code>.</p>
|
||||
|
||||
<textarea readonly style="width: 100%; height: 500px;"><?php echo $configString; ?></textarea>
|
||||
|
||||
<hr class="invisible">
|
||||
|
||||
<div>
|
||||
This is the last step, you are almost there!<br>
|
||||
<ul>
|
||||
<li>Click "Already manually completed" if you already wrote the config to "<?php echo $configPath; ?>".</li>
|
||||
<li>Or click "Complete automatically" if you want the installer to do the work for you.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<a class="button" href="/?step=<?php echo $thisStep; ?>&go=prev">Back</a>
|
||||
<button class="button" name="manual" value="1" type="submit">Already manually completed</button>
|
||||
<button class="button button-primary" name="automatic" value="1" type="submit">Complete automatically!</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
Loading…
Add table
Reference in a new issue