| [0] | 1 | <?php | 
|---|
|  | 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
|  | 3 | # | 
|---|
|  | 4 | # This file is part of Dotclear 2. | 
|---|
|  | 5 | # | 
|---|
| [270] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear | 
|---|
| [0] | 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 |  | 
|---|
|  | 13 | if (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 | 
|---|
|  | 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'); | 
|---|
|  | 26 | } elseif (isset($_SERVER['CLEARBRICKS_PATH']) && is_dir($_SERVER['CLEARBRICKS_PATH'])) { | 
|---|
|  | 27 | define('CLEARBRICKS_PATH',$_SERVER['CLEARBRICKS_PATH']); | 
|---|
|  | 28 | } | 
|---|
|  | 29 |  | 
|---|
|  | 30 | if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) { | 
|---|
|  | 31 | exit('No clearbricks path defined'); | 
|---|
|  | 32 | } | 
|---|
|  | 33 |  | 
|---|
|  | 34 | require CLEARBRICKS_PATH.'/_common.php'; | 
|---|
|  | 35 |  | 
|---|
|  | 36 | # Loading locales for detected language | 
|---|
|  | 37 | $dlang = http::getAcceptLanguage(); | 
|---|
|  | 38 | if ($dlang != 'en') | 
|---|
|  | 39 | { | 
|---|
|  | 40 | l10n::init(); | 
|---|
|  | 41 | l10n::set(dirname(__FILE__).'/../../locales/'.$dlang.'/main'); | 
|---|
|  | 42 | } | 
|---|
|  | 43 |  | 
|---|
|  | 44 | if (is_file(DC_RC_PATH)) { | 
|---|
|  | 45 | http::redirect('index.php'); | 
|---|
|  | 46 | } | 
|---|
|  | 47 |  | 
|---|
| [858] | 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 |  | 
|---|
| [0] | 57 | $DBDRIVER = !empty($_POST['DBDRIVER']) ? $_POST['DBDRIVER'] : '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 |  | 
|---|
|  | 64 | if (!empty($_POST)) | 
|---|
|  | 65 | { | 
|---|
|  | 66 | try | 
|---|
|  | 67 | { | 
|---|
|  | 68 | # Tries to connect to database | 
|---|
|  | 69 | try { | 
|---|
|  | 70 | $con = dbLayer::init($DBDRIVER,$DBHOST,$DBNAME,$DBUSER,$DBPASSWORD); | 
|---|
|  | 71 | } catch (Exception $e) { | 
|---|
|  | 72 | throw new Exception('<p>' . __($e->getMessage()) . '</p>'); | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | # Checks system capabilites | 
|---|
|  | 76 | require dirname(__FILE__).'/check.php'; | 
|---|
|  | 77 | if (!dcSystemCheck($con,$_e)) { | 
|---|
|  | 78 | $can_install = false; | 
|---|
|  | 79 | throw new Exception('<p>'.__('Dotclear cannot be installed.').'</p><ul><li>'.implode('</li><li>',$_e).'</li></ul>'); | 
|---|
|  | 80 | } | 
|---|
|  | 81 |  | 
|---|
|  | 82 | # Check if dotclear is already installed | 
|---|
|  | 83 | $schema = dbSchema::init($con); | 
|---|
|  | 84 | if (in_array($DBPREFIX.'version',$schema->getTables())) { | 
|---|
|  | 85 | throw new Exception(__('Dotclear is already installed.')); | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | # Does config.php.in exist? | 
|---|
|  | 89 | $config_in = dirname(__FILE__).'/../../inc/config.php.in'; | 
|---|
|  | 90 | if (!is_file($config_in)) { | 
|---|
|  | 91 | throw new Exception(sprintf(__('File %s does not exist.'),$config_in)); | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | # Can we write config.php | 
|---|
|  | 95 | if (!is_writable(dirname(DC_RC_PATH))) { | 
|---|
|  | 96 | throw new Exception(sprintf(__('Cannot write %s file.'),DC_RC_PATH)); | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | # Creates config.php file | 
|---|
|  | 100 | $full_conf = file_get_contents($config_in); | 
|---|
|  | 101 |  | 
|---|
|  | 102 | writeConfigValue('DC_DBDRIVER',$DBDRIVER,$full_conf); | 
|---|
|  | 103 | writeConfigValue('DC_DBHOST',$DBHOST,$full_conf); | 
|---|
|  | 104 | writeConfigValue('DC_DBUSER',$DBUSER,$full_conf); | 
|---|
|  | 105 | writeConfigValue('DC_DBPASSWORD',$DBPASSWORD,$full_conf); | 
|---|
|  | 106 | writeConfigValue('DC_DBNAME',$DBNAME,$full_conf); | 
|---|
|  | 107 | writeConfigValue('DC_DBPREFIX',$DBPREFIX,$full_conf); | 
|---|
|  | 108 |  | 
|---|
|  | 109 | $admin_url = preg_replace('%install/wizard.php$%','',$_SERVER['REQUEST_URI']); | 
|---|
|  | 110 | writeConfigValue('DC_ADMIN_URL',http::getHost().$admin_url,$full_conf); | 
|---|
| [363] | 111 | writeConfigValue('DC_ADMIN_MAILFROM','dotclear@'.$_SERVER['HTTP_HOST'],$full_conf); | 
|---|
| [0] | 112 | writeConfigValue('DC_MASTER_KEY',md5(uniqid()),$full_conf); | 
|---|
|  | 113 |  | 
|---|
|  | 114 | $fp = @fopen(DC_RC_PATH,'wb'); | 
|---|
|  | 115 | if ($fp === false) { | 
|---|
|  | 116 | throw new Exception(sprintf(__('Cannot write %s file.'),DC_RC_PATH)); | 
|---|
|  | 117 | } | 
|---|
|  | 118 | fwrite($fp,$full_conf); | 
|---|
|  | 119 | fclose($fp); | 
|---|
|  | 120 | chmod(DC_RC_PATH, 0666); | 
|---|
|  | 121 |  | 
|---|
|  | 122 | $con->close(); | 
|---|
|  | 123 | http::redirect('index.php?wiz=1'); | 
|---|
|  | 124 | } | 
|---|
|  | 125 | catch (Exception $e) | 
|---|
|  | 126 | { | 
|---|
|  | 127 | $err = $e->getMessage(); | 
|---|
|  | 128 | } | 
|---|
|  | 129 | } | 
|---|
|  | 130 |  | 
|---|
|  | 131 | function writeConfigValue($name,$val,&$str) | 
|---|
|  | 132 | { | 
|---|
|  | 133 | $val = str_replace("'","\'",$val); | 
|---|
|  | 134 | $str = preg_replace('/(\''.$name.'\')(.*?)$/ms','$1,\''.$val.'\');',$str); | 
|---|
|  | 135 | } | 
|---|
|  | 136 |  | 
|---|
|  | 137 | header('Content-Type: text/html; charset=UTF-8'); | 
|---|
|  | 138 | ?> | 
|---|
|  | 139 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | 
|---|
|  | 140 | <html xmlns="http://www.w3.org/1999/xhtml" | 
|---|
|  | 141 | xml:lang="en" lang="en"> | 
|---|
|  | 142 | <head> | 
|---|
|  | 143 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | 
|---|
|  | 144 | <meta http-equiv="Content-Script-Type" content="text/javascript" /> | 
|---|
|  | 145 | <meta http-equiv="Content-Style-Type" content="text/css" /> | 
|---|
|  | 146 | <meta http-equiv="Content-Language" content="en" /> | 
|---|
|  | 147 | <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" /> | 
|---|
|  | 148 | <meta name="GOOGLEBOT" content="NOSNIPPET" /> | 
|---|
|  | 149 | <title><?php echo __('Dotclear installation wizard'); ?></title> | 
|---|
| [473] | 150 | <link rel="stylesheet" href="../style/install.css" type="text/css" media="screen" /> | 
|---|
| [0] | 151 | </head> | 
|---|
|  | 152 |  | 
|---|
|  | 153 | <body id="dotclear-admin" class="install"> | 
|---|
|  | 154 | <div id="content"> | 
|---|
|  | 155 | <?php | 
|---|
|  | 156 | echo | 
|---|
|  | 157 | '<h1>'.__('Dotclear installation wizard').'</h1>'. | 
|---|
|  | 158 | '<div id="main">'; | 
|---|
|  | 159 |  | 
|---|
|  | 160 | if (!empty($err)) { | 
|---|
|  | 161 | echo '<div class="error"><p><strong>'.__('Errors:').'</strong></p>'.$err.'</div>'; | 
|---|
|  | 162 | } else { | 
|---|
|  | 163 | echo '<h2>'.__('Welcome').'</h2>'. | 
|---|
|  | 164 | '<p>'.__('To complete your Dotclear installation and start writing on your blog, '. | 
|---|
|  | 165 | 'we just need to know how to access your database and who you are. '. | 
|---|
|  | 166 | 'Just fill this two steps wizard with this information and we will be done.').'</p>'. | 
|---|
|  | 167 | '<p class="message"><strong>'.__('Attention:').'</strong> '. | 
|---|
|  | 168 | __('this wizard may not function on every host. If it does not work for you, '. | 
|---|
|  | 169 | 'please refer to <a href="http://dotclear.org/documentation/2.0/admin/install">'. | 
|---|
|  | 170 | 'the documentation</a> to learn how to create the <strong>config.php</strong> '. | 
|---|
|  | 171 | 'file manually.').'</p>'; | 
|---|
|  | 172 | } | 
|---|
|  | 173 |  | 
|---|
|  | 174 | echo | 
|---|
|  | 175 | '<h2>'.__('System information').'</h2>'. | 
|---|
|  | 176 |  | 
|---|
|  | 177 | '<p>'.__('Please provide the following information needed to create your configuration file.').'</p>'. | 
|---|
|  | 178 |  | 
|---|
|  | 179 | '<form action="wizard.php" method="post">'. | 
|---|
| [263] | 180 | '<p><label class="required" for="DBDRIVER"><abbr title="'.__('Required field').'">*</abbr> '.__('Database type:').' '. | 
|---|
| [0] | 181 | form::combo('DBDRIVER',array('MySQL'=>'mysql','PostgreSQL'=>'pgsql'),$DBDRIVER).'</label></p>'. | 
|---|
| [263] | 182 | '<p><label for="DBHOST">'.__('Database Host Name:').' '. | 
|---|
| [0] | 183 | form::field('DBHOST',30,255,html::escapeHTML($DBHOST)).'</label></p>'. | 
|---|
| [263] | 184 | '<p><label for="DBNAME">'.__('Database Name:').' '. | 
|---|
| [0] | 185 | form::field('DBNAME',30,255,html::escapeHTML($DBNAME)).'</label></p>'. | 
|---|
| [263] | 186 | '<p><label for="DBUSER">'.__('Database User Name:').' '. | 
|---|
| [0] | 187 | form::field('DBUSER',30,255,html::escapeHTML($DBUSER)).'</label></p>'. | 
|---|
| [263] | 188 | '<p><label for="DBPASSWORD">'.__('Database Password:').' '. | 
|---|
| [0] | 189 | form::password('DBPASSWORD',30,255).'</label></p>'. | 
|---|
| [263] | 190 | '<p><label for="DBPREFIX" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Database Tables Prefix:').' '. | 
|---|
| [0] | 191 | form::field('DBPREFIX',30,255,html::escapeHTML($DBPREFIX)).'</label></p>'. | 
|---|
|  | 192 |  | 
|---|
| [557] | 193 | '<p><input type="submit" value="'.__('Continue').'" /></p>'. | 
|---|
| [0] | 194 | '</form>'; | 
|---|
|  | 195 | ?> | 
|---|
|  | 196 | </div> | 
|---|
|  | 197 | </div> | 
|---|
|  | 198 | </body> | 
|---|
|  | 199 | </html> | 
|---|