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