[0] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @package Dotclear |
---|
| 4 | * @subpackage Install |
---|
| 5 | * |
---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 7 | * @copyright GPL-2.0-only |
---|
| 8 | */ |
---|
[0] | 9 | |
---|
| 10 | if (isset($_SERVER['DC_RC_PATH'])) { |
---|
[3703] | 11 | define('DC_RC_PATH', $_SERVER['DC_RC_PATH']); |
---|
[0] | 12 | } elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) { |
---|
[3703] | 13 | define('DC_RC_PATH', $_SERVER['REDIRECT_DC_RC_PATH']); |
---|
[0] | 14 | } else { |
---|
[3703] | 15 | define('DC_RC_PATH', dirname(__FILE__) . '/../../inc/config.php'); |
---|
[0] | 16 | } |
---|
| 17 | |
---|
| 18 | # ClearBricks and DotClear classes auto-loader |
---|
| 19 | if (@is_dir('/usr/lib/clearbricks')) { |
---|
[3703] | 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'); |
---|
[0] | 23 | } elseif (isset($_SERVER['CLEARBRICKS_PATH']) && is_dir($_SERVER['CLEARBRICKS_PATH'])) { |
---|
[3703] | 24 | define('CLEARBRICKS_PATH', $_SERVER['CLEARBRICKS_PATH']); |
---|
[0] | 25 | } |
---|
| 26 | |
---|
| 27 | if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) { |
---|
[3703] | 28 | exit('No clearbricks path defined'); |
---|
[0] | 29 | } |
---|
| 30 | |
---|
[3703] | 31 | require CLEARBRICKS_PATH . '/_common.php'; |
---|
[0] | 32 | |
---|
| 33 | # Loading locales for detected language |
---|
| 34 | $dlang = http::getAcceptLanguage(); |
---|
[3703] | 35 | if ($dlang != 'en') { |
---|
| 36 | l10n::init($dlang); |
---|
| 37 | l10n::set(dirname(__FILE__) . '/../../locales/' . $dlang . '/main'); |
---|
[0] | 38 | } |
---|
| 39 | |
---|
| 40 | if (is_file(DC_RC_PATH)) { |
---|
[3703] | 41 | http::redirect('index.php'); |
---|
[0] | 42 | } |
---|
| 43 | |
---|
[858] | 44 | if (!is_writable(dirname(DC_RC_PATH))) { |
---|
[3703] | 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>'; |
---|
[858] | 51 | } |
---|
| 52 | |
---|
[3703] | 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_'; |
---|
[3404] | 59 | $ADMINMAILFROM = !empty($_POST['ADMINMAILFROM']) ? $_POST['ADMINMAILFROM'] : ''; |
---|
[0] | 60 | |
---|
[3703] | 61 | if (!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); |
---|
[2994] | 68 | |
---|
[3703] | 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 | } |
---|
[2994] | 76 | |
---|
[3703] | 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 | } |
---|
[2566] | 83 | |
---|
[3703] | 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 | } |
---|
[2566] | 90 | |
---|
[3703] | 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 | } |
---|
[2566] | 100 | |
---|
[3703] | 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 | } |
---|
[2566] | 106 | |
---|
[3703] | 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 | } |
---|
[2566] | 111 | |
---|
[3703] | 112 | # Creates config.php file |
---|
| 113 | $full_conf = file_get_contents($config_in); |
---|
[2566] | 114 | |
---|
[3703] | 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); |
---|
[2566] | 121 | |
---|
[3703] | 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); |
---|
[2566] | 127 | |
---|
[3703] | 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); |
---|
[2566] | 135 | |
---|
[3703] | 136 | $con->close(); |
---|
| 137 | http::redirect('index.php?wiz=1'); |
---|
| 138 | } catch (Exception $e) { |
---|
| 139 | $err = $e->getMessage(); |
---|
| 140 | } |
---|
[0] | 141 | } |
---|
| 142 | |
---|
[3703] | 143 | function writeConfigValue($name, $val, &$str) |
---|
[0] | 144 | { |
---|
[3703] | 145 | $val = str_replace("'", "\'", $val); |
---|
| 146 | $str = preg_replace('/(\'' . $name . '\')(.*?)$/ms', '$1,\'' . $val . '\');', $str); |
---|
[0] | 147 | } |
---|
| 148 | |
---|
| 149 | header('Content-Type: text/html; charset=UTF-8'); |
---|
[2792] | 150 | |
---|
| 151 | // Prevents Clickjacking as far as possible |
---|
| 152 | header('X-Frame-Options: SAMEORIGIN'); // FF 3.6.9+ Chrome 4.1+ IE 8+ Safari 4+ Opera 10.5+ |
---|
| 153 | |
---|
[0] | 154 | ?> |
---|
[2760] | 155 | <!DOCTYPE html> |
---|
| 156 | <html lang="en"> |
---|
[0] | 157 | <head> |
---|
[2760] | 158 | <meta charset="UTF-8" /> |
---|
[0] | 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> |
---|
[3703] | 165 | <link rel="stylesheet" href="../style/install.css" type="text/css" media="screen" /> |
---|
[0] | 166 | </head> |
---|
| 167 | |
---|
| 168 | <body id="dotclear-admin" class="install"> |
---|
| 169 | <div id="content"> |
---|
| 170 | <?php |
---|
| 171 | echo |
---|
[3703] | 172 | '<h1>' . __('Dotclear installation wizard') . '</h1>' . |
---|
| 173 | '<div id="main">'; |
---|
[0] | 174 | |
---|
| 175 | if (!empty($err)) { |
---|
[3703] | 176 | echo '<div class="error" role="alert"><p><strong>' . __('Errors:') . '</strong></p>' . $err . '</div>'; |
---|
[0] | 177 | } else { |
---|
[3703] | 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>'; |
---|
[0] | 187 | } |
---|
| 188 | |
---|
| 189 | echo |
---|
[3703] | 190 | '<h2>' . __('System information') . '</h2>' . |
---|
[0] | 191 | |
---|
[3703] | 192 | '<p>' . __('Please provide the following information needed to create your configuration file.') . '</p>' . |
---|
[0] | 193 | |
---|
[3703] | 194 | '<form action="wizard.php" method="post">' . |
---|
| 195 | '<p><label class="required" for="DBDRIVER"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Database type:') . '</label> ' . |
---|
| 196 | form::combo('DBDRIVER', array( |
---|
| 197 | __('MySQL (deprecated)') => 'mysql', |
---|
| 198 | __('MySQLi') => 'mysqli', |
---|
| 199 | __('MySQLi (full UTF-8)') => 'mysqlimb4', |
---|
| 200 | __('PostgreSQL') => 'pgsql', |
---|
| 201 | __('SQLite') => 'sqlite'), |
---|
| 202 | array('default' => $DBDRIVER, 'extra_html' => 'required placeholder="' . __('Driver') . '"')) . '</p>' . |
---|
| 203 | '<p><label for="DBHOST">' . __('Database Host Name:') . '</label> ' . |
---|
| 204 | form::field('DBHOST', 30, 255, html::escapeHTML($DBHOST)) . '</p>' . |
---|
| 205 | '<p><label for="DBNAME">' . __('Database Name:') . '</label> ' . |
---|
| 206 | form::field('DBNAME', 30, 255, html::escapeHTML($DBNAME)) . '</p>' . |
---|
| 207 | '<p><label for="DBUSER">' . __('Database User Name:') . '</label> ' . |
---|
| 208 | form::field('DBUSER', 30, 255, html::escapeHTML($DBUSER)) . '</p>' . |
---|
| 209 | '<p><label for="DBPASSWORD">' . __('Database Password:') . '</label> ' . |
---|
| 210 | form::password('DBPASSWORD', 30, 255) . '</p>' . |
---|
| 211 | '<p><label for="DBPREFIX" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Database Tables Prefix:') . '</label> ' . |
---|
[3725] | 212 | form::field('DBPREFIX', 30, 255, array( |
---|
| 213 | 'default' => html::escapeHTML($DBPREFIX), |
---|
| 214 | 'extra_html' => 'required placeholder="' . __('Prefix') . '"' |
---|
| 215 | )) . |
---|
| 216 | '</p>' . |
---|
[3703] | 217 | '<p><label for="ADMINMAILFROM">' . __('Master Email: (used as sender for password recovery)') . '</label> ' . |
---|
[3806] | 218 | form::email('ADMINMAILFROM', array( |
---|
[3725] | 219 | 'size' => 30, |
---|
| 220 | 'default' => html::escapeHTML($ADMINMAILFROM), |
---|
| 221 | 'autocomplete' => 'email' |
---|
| 222 | )) . |
---|
| 223 | '</p>' . |
---|
[0] | 224 | |
---|
[3703] | 225 | '<p><input type="submit" value="' . __('Continue') . '" /></p>' . |
---|
| 226 | '</form>'; |
---|
[0] | 227 | ?> |
---|
| 228 | </div> |
---|
| 229 | </div> |
---|
| 230 | </body> |
---|
[2566] | 231 | </html> |
---|