Adding final installation step 7: writing config & finish
This commit is contained in:
parent
07dcccbaa4
commit
d092816cea
1 changed files with 148 additions and 0 deletions
148
installer/step7.php
Normal file
148
installer/step7.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
$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))){
|
||||
throw new Exception('The directory "'.dirname($configPath).'"" is missing.');
|
||||
}
|
||||
|
||||
if(!is_writable(dirname($configPath))){
|
||||
throw new Exception('The directory "'.dirname($configPath).'"" isn\'t writable.');
|
||||
}
|
||||
|
||||
// Write config
|
||||
file_put_contents($configPath, $configString);
|
||||
|
||||
$_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: 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