Dotclear

source: admin/install/wizard.php @ 2994:c8206c9d865d

Revision 2994:c8206c9d865d, 7.8 KB checked in by Nicolas <nikrou77@…>, 10 years ago (diff)

Fix #1913 : allow SQLite in installation wizard.
No simple way to upgrade SQLite database, so bypass upgrade during connection.

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

Sites map