2017-11-23 18:09:36 -05:00
< ? php
2018-01-12 15:35:31 -05:00
require_once ( " template.php " );
define ( " WEB_URL " , " . " ); //Website name
2017-12-30 18:41:58 -05:00
define ( " NAME " , _ ( 'Status page' )); //Website name
2018-01-18 16:57:12 -05:00
require_once ( " classes/locale-negotiator.php " );
2018-01-12 15:35:31 -05:00
$negotiator = new LocaleNegotiator ( " en_GB " );
$message = " " ;
if ( ! isset ( $_SESSION [ 'locale' ]) || isset ( $_GET [ 'lang' ]))
{
$override = (( isset ( $_GET [ 'lang' ])) ? $_GET [ 'lang' ] : null );
$best_match = $negotiator -> negotiate ( $override );
$_SESSION [ 'locale' ] = $best_match ;
setlocale ( LC_ALL , $_SESSION [ 'locale' ] . " .UTF-8 " );
bindtextdomain ( " server-status " , __DIR__ . " /locale/ " );
bind_textdomain_codeset ( $_SESSION [ 'locale' ], " utf-8 " );
textdomain ( " server-status " );
}
2017-11-29 08:40:34 -05:00
if ( isset ( $_POST [ 'server' ]))
{
$mysqli = new mysqli ( $_POST [ 'server' ], $_POST [ 'dbuser' ], $_POST [ 'dbpassword' ], $_POST [ 'database' ]);
if ( $mysqli -> connect_errno ) {
2018-03-09 18:32:06 -05:00
$message .= sprintf ( _ ( " Connection failed: %s \n " ), $mysqli -> connect_error );
2017-11-29 08:40:34 -05:00
}
2018-01-12 15:35:31 -05:00
if ( isset ( $_POST [ 'url' ]) && filter_var ( $_POST [ 'url' ], FILTER_VALIDATE_URL ) === false )
{
$message .= _ ( " Please set valid url! " );
}
2017-11-29 08:40:34 -05:00
2018-01-12 15:35:31 -05:00
//Ostatní má checky existence ve funkci pro pridani
if ( 0 == strlen ( trim ( $_POST [ 'servername' ]))){
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Server name " );
2018-01-12 15:35:31 -05:00
}
if ( 0 == strlen ( trim ( $_POST [ 'url' ]))){
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Url " );
2018-01-12 15:35:31 -05:00
}
if ( 0 == strlen ( trim ( $_POST [ 'mailer' ]))){
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Mailer name " );
2018-01-12 15:35:31 -05:00
}
2018-03-09 18:32:06 -05:00
if ( 0 == strlen ( trim ( $_POST [ 'title' ]))){
$messages [] = _ ( " Title " );
}
2018-01-12 15:35:31 -05:00
if ( 0 == strlen ( trim ( $_POST [ 'mailer_email' ]))){
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Mailer email " );
2018-01-12 15:35:31 -05:00
}
if ( 0 == strlen ( trim ( $_POST [ 'server' ]))){
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Database server " );
2018-01-12 15:35:31 -05:00
}
if ( 0 == strlen ( trim ( $_POST [ 'database' ]))){
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Database name " );
2018-01-12 15:35:31 -05:00
}
if ( 0 == strlen ( trim ( $_POST [ 'dbuser' ]))){
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Database user " );
2018-01-12 15:35:31 -05:00
}
if ( 0 == strlen ( trim ( $_POST [ 'dbpassword' ])))
{
2018-01-12 21:00:13 -05:00
$messages [] = _ ( " Database password " );
2018-01-12 15:35:31 -05:00
}
if ( isset ( $messages ))
{
2018-03-09 18:32:06 -05:00
$message .= _ ( " Please enter " );
2018-01-12 15:35:31 -05:00
$message .= implode ( " , " , $messages );
}
2017-11-29 08:40:34 -05:00
}
2018-01-12 15:35:31 -05:00
if ( isset ( $_POST [ 'server' ]) && empty ( $message ))
2017-11-23 18:09:36 -05:00
{
2018-01-12 15:35:31 -05:00
define ( " MAILER_NAME " , $_POST [ 'mailer' ]);
define ( " MAILER_ADDRESS " , $_POST [ 'mailer_email' ]);
2017-11-23 18:09:36 -05:00
define ( " INSTALL_OVERRIDE " , true );
2017-11-29 08:40:34 -05:00
//No need to include config, as we have connection from testing it... :)
//There may be better way to do this...
2017-11-23 18:09:36 -05:00
$sql = file_get_contents ( " install.sql " );
$array = explode ( " ; " , $sql );
2017-11-29 08:40:34 -05:00
2017-11-23 18:09:36 -05:00
foreach ( $array as $value ) {
2018-01-13 10:51:17 -05:00
$val = trim ( $value );
if ( empty ( $val ))
2018-01-12 15:35:31 -05:00
{
continue ;
}
2017-11-29 08:40:34 -05:00
$q_res = $mysqli -> query ( $value );
if ( $q_res === false )
{
2018-01-12 15:35:31 -05:00
$message = sprintf ( _ ( " Error while creating database. Please check permission for your account or MYSQL version.<br>Error: %s " ), $mysqli -> error );
2017-11-29 08:40:34 -05:00
break ;
}
2017-11-23 18:09:36 -05:00
}
2018-01-12 15:35:31 -05:00
if ( empty ( $message ))
2017-11-23 18:09:36 -05:00
{
2018-01-18 16:57:12 -05:00
require_once ( " classes/constellation.php " );
2017-11-29 08:40:34 -05:00
User :: add ();
2017-11-23 18:09:36 -05:00
}
2018-01-12 15:35:31 -05:00
if ( empty ( $message ))
2017-11-29 08:40:34 -05:00
{
//Create config
$config = file_get_contents ( " config.php.template " );
$config = str_replace ( " ##name## " , $_POST [ 'servername' ], $config );
2018-03-09 18:32:06 -05:00
$config = str_replace ( " ##title## " , $_POST [ 'title' ], $config );
2017-11-29 08:40:34 -05:00
$config = str_replace ( " ##url## " , $_POST [ 'url' ], $config );
$config = str_replace ( " ##mailer## " , $_POST [ 'mailer' ], $config );
$config = str_replace ( " ##mailer_email## " , $_POST [ 'mailer_email' ], $config );
$config = str_replace ( " ##server## " , $_POST [ 'server' ], $config );
$config = str_replace ( " ##database## " , $_POST [ 'database' ], $config );
$config = str_replace ( " ##user## " , $_POST [ 'dbuser' ], $config );
$config = str_replace ( " ##password## " , $_POST [ 'dbpassword' ], $config );
$config = str_replace ( " ##name## " , $_POST [ 'servername' ], $config );
2018-08-02 05:48:10 -04:00
$config = str_replace ( " ##policy_name## " , $_POST [ 'policy_name' ], $config );
$config = str_replace ( " ##address## " , $_POST [ 'address' ], $config );
$config = str_replace ( " ##policy_mail## " , $_POST [ 'policy_mail' ], $config );
$config = str_replace ( " ##policy_phone## " , $_POST [ 'policy_phone' ], $config );
$config = str_replace ( " ##who_we_are## " , $_POST [ 'who_we_are' ], $config );
2017-11-29 08:40:34 -05:00
file_put_contents ( " config.php " , $config );
2018-08-02 05:48:10 -04:00
2017-11-29 08:40:34 -05:00
2018-01-12 15:35:31 -05:00
unlink ( " config.php.template " );
2017-11-29 08:40:34 -05:00
unlink ( " install.sql " );
unlink ( __FILE__ );
2017-11-23 18:09:36 -05:00
2018-01-12 15:35:31 -05:00
header ( " Location: " . WEB_URL );
2017-11-29 08:40:34 -05:00
}
}
2018-01-12 15:35:31 -05:00
Template :: render_header ( _ ( " Install " ));
?>
< h1 class = " text-center " >< ? php echo _ ( " Installation " ); ?> </h1>
< ? php
if ( ! empty ( $message ))
2017-11-29 08:40:34 -05:00
{
2018-03-09 18:32:06 -05:00
?>
< p class = " alert alert-danger " >< ? php echo $message ; ?> </p>
< ? php
2017-11-29 08:40:34 -05:00
}
2017-11-23 18:09:36 -05:00
?>
2018-03-09 18:32:06 -05:00
< summary >< ? php echo _ ( " We will ask you some basic questions about your website. Most of the settings can be later edited in the config.php file. " ); ?> </summary>
2018-01-12 15:35:31 -05:00
< form method = " post " action = " . " class = " clearfix install " >
2017-11-23 18:09:36 -05:00
< section class = " install-section clearfix " >
2017-12-30 18:41:58 -05:00
< h2 >< ? php echo _ ( " Website details " ); ?> </h2>
2018-03-09 18:32:06 -05:00
< summary >< ? php echo _ ( " We need a name for your status page (shown behind page title after the dash) and a url of your server status installation (i.e. <a href='#'>https://example.com/status</a> - without the trailing slash), so we can mail users link for forgotten password etc... " ); ?> </summary>
2017-11-23 18:09:36 -05:00
2018-03-09 18:32:06 -05:00
< div class = " form-group clearfix " >
< div class = " col-sm-6 " >< label for = " servername " >< ? php echo _ ( " Name " ); ?> : </label><input type="text" name="servername" value="<?php echo ((isset($_POST['servername']))?htmlspecialchars($_POST['servername'], ENT_QUOTES):'');?>" id="servername" placeholder="<?php echo _("Name");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " url " >< ? php echo _ ( " Url " ); ?> : </label><input type="url" name="url" value="<?php echo ((isset($_POST['url']))?htmlspecialchars($_POST['url'], ENT_QUOTES):'');?>" id="url" placeholder="<?php echo _("Url");?>" class="form-control" required></div>
</ div >
< summary >< ? php echo _ ( " A title that you want to be shown on the top of the page. " ); ?> </summary>
< div class = " form-group clearfix " >
< div class = " col-sm-6 " >< label for = " title " >< ? php echo _ ( " Title " ); ?> : </label><input type="text" name="title" value="<?php echo ((isset($_POST['title']))?htmlspecialchars($_POST['title'], ENT_QUOTES):'Server Status');?>" id="title" placeholder="<?php echo _("Title");?>" class="form-control" required></div>
< div class = " col-sm-6 " ></ div >
</ div >
< summary >< ? php echo _ ( " Also an email address for mailer would be nice :) " ); ?> </summary>
< div class = " form-group clearfix " >
< div class = " col-sm-6 " >< label for = " mailer " >< ? php echo _ ( " Name " ); ?> : </label><input type="text" name="mailer" value="<?php echo ((isset($_POST['mailer']))?htmlspecialchars($_POST['mailer'], ENT_QUOTES):'');?>" id="mailer" placeholder="<?php echo _("Name");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " mailer_email " >< ? php echo _ ( " Email " ); ?> : </label><input type="email" name="mailer_email" value="<?php echo ((isset($_POST['mailer_email']))?htmlspecialchars($_POST['mailer_email'], ENT_QUOTES):'');?>" id="mailer_email" placeholder="<?php echo _("Email");?>" class="form-control" required></div>
</ div >
2017-11-23 18:09:36 -05:00
</ section >
< section class = " install-section clearfix " >
2017-12-30 18:41:58 -05:00
< h2 >< ? php echo _ ( " Database connection " ); ?> </h2>
< summary >< ? php echo _ ( " We need database connection to be able to create tables. Please check that your account has the permission needed to do that. " ); ?> </summary>
2017-11-23 18:09:36 -05:00
2018-03-09 18:32:06 -05:00
< div class = " form-group clearfix " >
< div class = " col-sm-6 " >< label for = " server " >< ? php echo _ ( " Server " ); ?> : </label><input type="text" name="server" value="<?php echo ((isset($_POST['server']))?htmlspecialchars($_POST['server'], ENT_QUOTES):'');?>" id="server" placeholder="<?php echo _("Server");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " database " >< ? php echo _ ( " Database " ); ?> : </label><input type="text" name="database" value="<?php echo ((isset($_POST['database']))?htmlspecialchars($_POST['database'], ENT_QUOTES):'');?>" id="database" placeholder="<?php echo _("Database");?>" class="form-control" required></div>
</ div >
< div class = " form-group clearfix " >
< div class = " col-sm-6 " >< label for = " dbuser " >< ? php echo _ ( " User " ); ?> : </label><input type="text" name="dbuser" value="<?php echo ((isset($_POST['dbuser']))?htmlspecialchars($_POST['dbuser'], ENT_QUOTES):'');?>" id="dbuser" placeholder="<?php echo _("User");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " dbpassword " >< ? php echo _ ( " Password " ); ?> : </label><input type="password" name="dbpassword" value="<?php echo ((isset($_POST['dbpassword']))?htmlspecialchars($_POST['dbpassword'], ENT_QUOTES):'');?>" id="dbpassword" placeholder="<?php echo _("Password");?>" class="form-control" required></div>
</ div >
2017-11-23 18:09:36 -05:00
</ section >
2018-08-02 05:48:10 -04:00
< section class = " install-section clearfix " >
< h2 >< ? php echo _ ( " Privacy Policy " ); ?> </h2>
2018-08-10 16:57:27 -04:00
< summary >< ? php echo _ ( " Since you are collecting personal information, the GDPR needs you to have a privacy policy. Enter the details below. " ); ?> </summary>
2018-08-02 05:48:10 -04:00
< div class = " form-group clearfix " >
< div class = " col-sm-6 " >< label for = " policy_name " >< ? php echo _ ( " Name " ); ?> : </label><input type="text" name="policy_name" value="<?php echo ((isset($_POST['policy_name']))?htmlspecialchars($_POST['policy_name'], ENT_QUOTES):'');?>" id="policy_name" placeholder="<?php echo _("Company name");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " address " >< ? php echo _ ( " Address " ); ?> : </label><input type="text" name="address" value="<?php echo ((isset($_POST['address']))?htmlspecialchars($_POST['address'], ENT_QUOTES):'');?>" id="address" placeholder="<?php echo _("Full address");?>" class="form-control" required></div>
</ div >
< div class = " form-group clearfix " >
< div class = " col-sm-6 " >< label for = " policy_mail " >< ? php echo _ ( " E-Mail " ); ?> : </label><input type="text" name="policy_mail" value="<?php echo ((isset($_POST['policy_mail']))?htmlspecialchars($_POST['policy_mail'], ENT_QUOTES):'');?>" id="policy_mail" placeholder="<?php echo _("E-Mail");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " policy_phone " >< ? php echo _ ( " Phone " ); ?> : </label><input type="text" name="policy_phone" value="<?php echo ((isset($_POST['policy_phone']))?htmlspecialchars($_POST['policy_phone'], ENT_QUOTES):'');?>" id="policy_phone" placeholder="<?php echo _("Phone number");?>" class="form-control"></div>
</ div >
< div class = " form-group clearfix " >
2018-08-10 16:57:27 -04:00
< div class = " " >< label for = " who_we_are " >< ? php echo _ ( " Who we are " ); ?> : </label><textarea class="form-control" id="who_we_are" rows="3" name="who_we_are" placeholder="<?php echo _("Some info about yourself");?>" value="<?php echo ((isset($_POST['who_we_are']))?htmlspecialchars($_POST['who_we_are'], ENT_QUOTES):'');?>"></textarea></div>
2018-08-02 05:48:10 -04:00
</ div >
</ section >
2017-11-23 18:09:36 -05:00
< section class = " install-section clearfix " >
2017-12-30 18:41:58 -05:00
< h2 >< ? php echo _ ( " User " ); ?> </h2>
< summary >< ? php echo _ ( " And finally, we need info to create a new user. You don't have to provide it, but then... No status page admin... " ); ?> </summary>
2018-03-09 18:32:06 -05:00
< div class = " form-group " >
< div class = " col-sm-6 " >< label for = " name " >< ? php echo _ ( " Name " ); ?> : </label><input type="text" maxlength="50" name="name" value="<?php echo ((isset($_POST['name']))?htmlspecialchars($_POST['name'], ENT_QUOTES):'');?>" id="name" placeholder="<?php echo _("Name");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " surname " >< ? php echo _ ( " Surname " ); ?> : </label><input type="text" maxlength="50" name="surname" value="<?php echo ((isset($_POST['surname']))?htmlspecialchars($_POST['surname'], ENT_QUOTES):'');?>" id="surname" placeholder="<?php echo _("Surname");?>" class="form-control" required></div>
</ div >
< div class = " form-group " >
< div class = " col-sm-6 " >< label for = " username " >< ? php echo _ ( " Username " ); ?> :</label><input type="text" maxlength="50" name="username" value="<?php echo ((isset($_POST['username']))?htmlspecialchars($_POST['username'], ENT_QUOTES):'');?>" id="username" placeholder="<?php echo _("Username");?>" class="form-control" required></div>
< div class = " col-sm-6 " >< label for = " email " >< ? php echo _ ( " Email " ); ?> :</label><input type="email" maxlength="60" name="email" value="<?php echo ((isset($_POST['email']))?htmlspecialchars($_POST['email'], ENT_QUOTES):'');?>" id="email" placeholder="<?php echo _("Email");?>" class="form-control" required><input type="hidden" name="permission" value="0"></div>
</ div >
< div class = " form-group " >
< div class = " col-sm-6 " >< label for = " password " >< ? php echo _ ( " Password " ); ?> :</label><input type="password" name="password" value="<?php echo ((isset($_POST['password']))?htmlspecialchars($_POST['password'], ENT_QUOTES):'');?>" id="password" placeholder="<?php echo _("Password");?>" class="form-control" required></div>
< div class = " col-sm-6 " >
< input type = " hidden " value = " 0 " name = " permission " >
< button type = " submit " class = " btn btn-success pull-right " >< ? php echo _ ( " Run install! " ); ?> </button>
</ div >
2017-11-23 18:09:36 -05:00
</ div >
</ section >
</ form >
< ? php
2018-01-12 15:35:31 -05:00
Template :: render_footer ();