Dotclear

source: admin/install/wizard.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 9.2 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

Line 
1<?php
2/**
3 * @package Dotclear
4 * @subpackage Install
5 *
6 * @copyright Olivier Meunier & Association Dotclear
7 * @copyright GPL-2.0-only
8 */
9
10if (isset($_SERVER['DC_RC_PATH'])) {
11    define('DC_RC_PATH', $_SERVER['DC_RC_PATH']);
12} elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) {
13    define('DC_RC_PATH', $_SERVER['REDIRECT_DC_RC_PATH']);
14} else {
15    define('DC_RC_PATH', dirname(__FILE__) . '/../../inc/config.php');
16}
17
18#  ClearBricks and DotClear classes auto-loader
19if (@is_dir('/usr/lib/clearbricks')) {
20    define('CLEARBRICKS_PATH', '/usr/lib/clearbricks');
21} elseif (is_dir(dirname(__FILE__) . '/../../inc/libs/clearbricks')) {
22    define('CLEARBRICKS_PATH', dirname(__FILE__) . '/../../inc/libs/clearbricks');
23} elseif (isset($_SERVER['CLEARBRICKS_PATH']) && is_dir($_SERVER['CLEARBRICKS_PATH'])) {
24    define('CLEARBRICKS_PATH', $_SERVER['CLEARBRICKS_PATH']);
25}
26
27if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) {
28    exit('No clearbricks path defined');
29}
30
31require CLEARBRICKS_PATH . '/_common.php';
32
33# Loading locales for detected language
34$dlang = http::getAcceptLanguage();
35if ($dlang != 'en') {
36    l10n::init($dlang);
37    l10n::set(dirname(__FILE__) . '/../../locales/' . $dlang . '/main');
38}
39
40if (is_file(DC_RC_PATH)) {
41    http::redirect('index.php');
42}
43
44if (!is_writable(dirname(DC_RC_PATH))) {
45    $err = '<p>' . sprintf(__('Path <strong>%s</strong> is not writable.'), path::real(dirname(DC_RC_PATH))) . '</p>' .
46    '<p>' . __('Dotclear installation wizard could not create configuration file for you. ' .
47        'You must change folder right or create the <strong>config.php</strong> ' .
48        'file manually, please refer to ' .
49        '<a href="http://dotclear.org/documentation/2.0/admin/install">' .
50        'the documentation</a> to learn how to do this.') . '</p>';
51}
52
53$DBDRIVER      = !empty($_POST['DBDRIVER']) ? $_POST['DBDRIVER'] : (function_exists('mysqli_connect') ? 'mysqli' : 'mysql');
54$DBHOST        = !empty($_POST['DBHOST']) ? $_POST['DBHOST'] : '';
55$DBNAME        = !empty($_POST['DBNAME']) ? $_POST['DBNAME'] : '';
56$DBUSER        = !empty($_POST['DBUSER']) ? $_POST['DBUSER'] : '';
57$DBPASSWORD    = !empty($_POST['DBPASSWORD']) ? $_POST['DBPASSWORD'] : '';
58$DBPREFIX      = !empty($_POST['DBPREFIX']) ? $_POST['DBPREFIX'] : 'dc_';
59$ADMINMAILFROM = !empty($_POST['ADMINMAILFROM']) ? $_POST['ADMINMAILFROM'] : '';
60
61if (!empty($_POST)) {
62    try
63    {
64        if ($DBDRIVER == 'sqlite') {
65            if (strpos($DBNAME, '/') === false) {
66                $sqlite_db_directory = dirname(DC_RC_PATH) . '/../db/';
67                files::makeDir($sqlite_db_directory, true);
68
69                # Can we write sqlite_db_directory ?
70                if (!is_writable($sqlite_db_directory)) {
71                    throw new Exception(sprintf(__('Cannot write "%s" directory.'), path::real($sqlite_db_directory, false)));
72                }
73                $DBNAME = $sqlite_db_directory . $DBNAME;
74            }
75        }
76
77        # Tries to connect to database
78        try {
79            $con = dbLayer::init($DBDRIVER, $DBHOST, $DBNAME, $DBUSER, $DBPASSWORD);
80        } catch (Exception $e) {
81            throw new Exception('<p>' . __($e->getMessage()) . '</p>');
82        }
83
84        # Checks system capabilites
85        require dirname(__FILE__) . '/check.php';
86        if (!dcSystemCheck($con, $_e)) {
87            $can_install = false;
88            throw new Exception('<p>' . __('Dotclear cannot be installed.') . '</p><ul><li>' . implode('</li><li>', $_e) . '</li></ul>');
89        }
90
91        # Check if dotclear is already installed
92        $schema = dbSchema::init($con);
93        if (in_array($DBPREFIX . 'version', $schema->getTables())) {
94            throw new Exception(__('Dotclear is already installed.'));
95        }
96        # Check master email
97        if (!text::isEmail($ADMINMAILFROM)) {
98            throw new Exception(__('Master email is not valid.'));
99        }
100
101        # Does config.php.in exist?
102        $config_in = dirname(__FILE__) . '/../../inc/config.php.in';
103        if (!is_file($config_in)) {
104            throw new Exception(sprintf(__('File %s does not exist.'), $config_in));
105        }
106
107        # Can we write config.php
108        if (!is_writable(dirname(DC_RC_PATH))) {
109            throw new Exception(sprintf(__('Cannot write %s file.'), DC_RC_PATH));
110        }
111
112        # Creates config.php file
113        $full_conf = file_get_contents($config_in);
114
115        writeConfigValue('DC_DBDRIVER', $DBDRIVER, $full_conf);
116        writeConfigValue('DC_DBHOST', $DBHOST, $full_conf);
117        writeConfigValue('DC_DBUSER', $DBUSER, $full_conf);
118        writeConfigValue('DC_DBPASSWORD', $DBPASSWORD, $full_conf);
119        writeConfigValue('DC_DBNAME', $DBNAME, $full_conf);
120        writeConfigValue('DC_DBPREFIX', $DBPREFIX, $full_conf);
121
122        $admin_url = preg_replace('%install/wizard.php$%', '', $_SERVER['REQUEST_URI']);
123        writeConfigValue('DC_ADMIN_URL', http::getHost() . $admin_url, $full_conf);
124        $admin_email = !empty($ADMINMAILFROM) ? $ADMINMAILFROM : 'dotclear@' . $_SERVER['HTTP_HOST'];
125        writeConfigValue('DC_ADMIN_MAILFROM', $admin_email, $full_conf);
126        writeConfigValue('DC_MASTER_KEY', md5(uniqid()), $full_conf);
127
128        $fp = @fopen(DC_RC_PATH, 'wb');
129        if ($fp === false) {
130            throw new Exception(sprintf(__('Cannot write %s file.'), DC_RC_PATH));
131        }
132        fwrite($fp, $full_conf);
133        fclose($fp);
134        chmod(DC_RC_PATH, 0666);
135
136        $con->close();
137        http::redirect('index.php?wiz=1');
138    } catch (Exception $e) {
139        $err = $e->getMessage();
140    }
141}
142
143function writeConfigValue($name, $val, &$str)
144{
145    $val = str_replace("'", "\'", $val);
146    $str = preg_replace('/(\'' . $name . '\')(.*?)$/ms', '$1,\'' . $val . '\');', $str);
147}
148
149header('Content-Type: text/html; charset=UTF-8');
150
151// Prevents Clickjacking as far as possible
152header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+
153
154?>
155<!DOCTYPE html>
156<html lang="en">
157<head>
158  <meta charset="UTF-8" />
159  <meta http-equiv="Content-Script-Type" content="text/javascript" />
160  <meta http-equiv="Content-Style-Type" content="text/css" />
161  <meta http-equiv="Content-Language" content="en" />
162  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />
163  <meta name="GOOGLEBOT" content="NOSNIPPET" />
164  <title><?php echo __('Dotclear installation wizard'); ?></title>
165    <link rel="stylesheet" href="../style/install.css" type="text/css" media="screen" />
166</head>
167
168<body id="dotclear-admin" class="install">
169<div id="content">
170<?php
171echo
172'<h1>' . __('Dotclear installation wizard') . '</h1>' .
173    '<div id="main">';
174
175if (!empty($err)) {
176    echo '<div class="error" role="alert"><p><strong>' . __('Errors:') . '</strong></p>' . $err . '</div>';
177} else {
178    echo '<h2>' . __('Welcome') . '</h2>' .
179    '<p>' . __('To complete your Dotclear installation and start writing on your blog, ' .
180        'we just need to know how to access your database and who you are. ' .
181        'Just fill this two steps wizard with this information and we will be done.') . '</p>' .
182    '<p class="message"><strong>' . __('Attention:') . '</strong> ' .
183    __('this wizard may not function on every host. If it does not work for you, ' .
184        'please refer to <a href="http://dotclear.org/documentation/2.0/admin/install">' .
185        'the documentation</a> to learn how to create the <strong>config.php</strong> ' .
186        'file manually.') . '</p>';
187}
188
189echo
190'<h2>' . __('System information') . '</h2>' .
191
192'<p>' . __('Please provide the following information needed to create your configuration file.') . '</p>' .
193
194'<form action="wizard.php" method="post">' .
195'<p><label class="required" for="DBDRIVER"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Database type:') . '</label> ' .
196form::combo('DBDRIVER', [
197    __('MySQL (deprecated)')  => 'mysql',
198    __('MySQLi')              => 'mysqli',
199    __('MySQLi (full UTF-8)') => 'mysqlimb4',
200    __('PostgreSQL')          => 'pgsql',
201    __('SQLite')              => 'sqlite'],
202    ['default' => $DBDRIVER, 'extra_html' => 'required placeholder="' . __('Driver') . '"']) . '</p>' .
203'<p><label for="DBHOST">' . __('Database Host Name:') . '</label> ' .
204form::field('DBHOST', 30, 255, html::escapeHTML($DBHOST)) . '</p>' .
205'<p><label for="DBNAME">' . __('Database Name:') . '</label> ' .
206form::field('DBNAME', 30, 255, html::escapeHTML($DBNAME)) . '</p>' .
207'<p><label for="DBUSER">' . __('Database User Name:') . '</label> ' .
208form::field('DBUSER', 30, 255, html::escapeHTML($DBUSER)) . '</p>' .
209'<p><label for="DBPASSWORD">' . __('Database Password:') . '</label> ' .
210form::password('DBPASSWORD', 30, 255) . '</p>' .
211'<p><label for="DBPREFIX" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Database Tables Prefix:') . '</label> ' .
212form::field('DBPREFIX', 30, 255, [
213    'default'    => html::escapeHTML($DBPREFIX),
214    'extra_html' => 'required placeholder="' . __('Prefix') . '"'
215]) .
216'</p>' .
217'<p><label for="ADMINMAILFROM">' . __('Master Email: (used as sender for password recovery)') . '</label> ' .
218form::email('ADMINMAILFROM', [
219    'size'         => 30,
220    'default'      => html::escapeHTML($ADMINMAILFROM),
221    'autocomplete' => 'email'
222]) .
223'</p>' .
224
225'<p><input type="submit" value="' . __('Continue') . '" /></p>' .
226    '</form>';
227?>
228</div>
229</div>
230</body>
231</html>
Note: See TracBrowser for help on using the repository browser.

Sites map