Dotclear

source: admin/install/index.php @ 0:54703be25dd6

Revision 0:54703be25dd6, 11.5 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

2.3 branch (trunk) first checkin

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 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     $rc_path = $_SERVER['DC_RC_PATH'];
15} elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) {
16     $rc_path = $_SERVER['REDIRECT_DC_RC_PATH'];
17} else {
18     $rc_path = dirname(__FILE__).'/../../inc/config.php';
19}
20
21require dirname(__FILE__).'/../../inc/prepend.php';
22require dirname(__FILE__).'/check.php';
23
24$can_install = true;
25$err = '';
26
27# Loading locales for detected language
28$dlang = http::getAcceptLanguage();
29if ($dlang != 'en')
30{
31     l10n::init();
32     l10n::set(dirname(__FILE__).'/../../locales/'.$dlang.'/date');
33     l10n::set(dirname(__FILE__).'/../../locales/'.$dlang.'/main');
34}
35
36if (!defined('DC_MASTER_KEY') || DC_MASTER_KEY == '') {
37     $can_install = false;
38     $err = '<p>'.__('Please set a master key (DC_MASTER_KEY) in configuration file.').'</p>';
39}
40
41# Check if dotclear is already installed
42$schema = dbSchema::init($core->con);
43if (in_array($core->prefix.'post',$schema->getTables())) {
44     $can_install = false;
45     $err = '<p>'.__('Dotclear is already installed.').'</p>';
46}
47
48# Check system capabilites
49if (!dcSystemCheck($core->con,$_e)) {
50     $can_install = false;
51     $err = '<p>'.__('Dotclear cannot be installed.').'</p><ul><li>'.implode('</li><li>',$_e).'</li></ul>';
52}
53
54# Get information and perform install
55$u_email = $u_firstname = $u_name = $u_login = $u_pwd = '';
56$mail_sent = false;
57if ($can_install && !empty($_POST))
58{
59     $u_email = !empty($_POST['u_email']) ? $_POST['u_email'] : null;
60     $u_firstname = !empty($_POST['u_firstname']) ? $_POST['u_firstname'] : null;
61     $u_name = !empty($_POST['u_name']) ? $_POST['u_name'] : null;
62     $u_login = !empty($_POST['u_login']) ? $_POST['u_login'] : null;
63     $u_pwd = !empty($_POST['u_pwd']) ? $_POST['u_pwd'] : null;
64     $u_pwd2 = !empty($_POST['u_pwd2']) ? $_POST['u_pwd2'] : null;
65     
66     try
67     {
68          # Check user information
69          if (empty($u_login)) {
70               throw new Exception(__('No user ID given'));
71          }
72          if (!preg_match('/^[A-Za-z0-9@._-]{2,}$/',$u_login)) {
73               throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.'));
74          }
75          if ($u_email && !text::isEmail($u_email)) {
76               throw new Exception(__('Invalid email address'));
77          }
78         
79          if (empty($u_pwd)) {
80               throw new Exception(__('No password given'));
81          }
82          if ($u_pwd != $u_pwd2) {
83               throw new Exception(__("Passwords don't match"));
84          }
85          if (strlen($u_pwd) < 6) {
86               throw new Exception(__('Password must contain at least 6 characters.'));
87          }
88         
89          # Try to guess timezone
90          $default_tz = 'Europe/London';
91          if (!empty($_POST['u_date']) && function_exists('timezone_open'))
92          {
93               if (preg_match('/\((.+)\)$/',$_POST['u_date'],$_tz)) {
94                    $_tz = $_tz[1];
95                    $_tz = @timezone_open($_tz);
96                    if ($_tz instanceof DateTimeZone) {
97                         $_tz = @timezone_name_get($_tz);
98                         if ($_tz) {
99                              $default_tz = $_tz;
100                         }
101                    }
102                    unset($_tz);
103               }
104          }
105         
106          # Create schema
107          $_s = new dbStruct($core->con,$core->prefix);
108          require dirname(__FILE__).'/../../inc/dbschema/db-schema.php';
109         
110          $si = new dbStruct($core->con,$core->prefix);
111          $changes = $si->synchronize($_s);
112         
113          # Create user
114          $cur = $core->con->openCursor($core->prefix.'user');
115          $cur->user_id = $u_login;
116          $cur->user_super = 1;
117          $cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$u_pwd);
118          $cur->user_name = (string) $u_name;
119          $cur->user_firstname = (string) $u_firstname;
120          $cur->user_email = (string) $u_email;
121          $cur->user_lang = $dlang;
122          $cur->user_tz = $default_tz;
123          $cur->user_creadt = date('Y-m-d H:i:s');
124          $cur->user_upddt = date('Y-m-d H:i:s');
125          $cur->user_options = serialize($core->userDefaults());
126          $cur->insert();
127         
128          $core->auth->checkUser($u_login);
129         
130          $admin_url = preg_replace('%install/index.php$%','',$_SERVER['REQUEST_URI']);
131          $root_url = preg_replace('%/admin/install/index.php$%','',$_SERVER['REQUEST_URI']);
132         
133          # Create blog
134          $cur = $core->con->openCursor($core->prefix.'blog');
135          $cur->blog_id = 'default';
136          $cur->blog_url = http::getHost().$root_url.'/index.php?';
137          $cur->blog_name = __('My first blog');
138          $core->addBlog($cur);
139          $core->blogDefaults($cur->blog_id);
140         
141          $blog_settings = new dcSettings($core,'default');
142          $blog_settings->addNamespace('system');
143          $blog_settings->system->put('blog_timezone',$default_tz);
144          $blog_settings->system->put('lang',$dlang);
145          $blog_settings->system->put('public_url',$root_url.'/public');
146          $blog_settings->system->put('themes_url',$root_url.'/themes');
147          $blog_settings->system->put('date_format',__('%A, %B %e %Y'));
148         
149          # Add Dotclear version
150          $cur = $core->con->openCursor($core->prefix.'version');
151          $cur->module = 'core';
152          $cur->version = (string) DC_VERSION;
153          $cur->insert();
154         
155          # Create first post
156          $core->setBlog('default');
157         
158          $cur = $core->con->openCursor($core->prefix.'post');
159          $cur->user_id = $u_login;
160          $cur->post_format = 'xhtml';
161          $cur->post_lang = $dlang;
162          $cur->post_title = __('Welcome to Dotclear!');
163          $cur->post_content = '<p>'.__('This is your first entry. When you\'re ready '.
164               'to blog, log in to edit or delete it.').'</p>';
165          $cur->post_content_xhtml = $cur->post_content;
166          $cur->post_status = 1;
167          $cur->post_open_comment = 1;
168          $cur->post_open_tb = 0;
169          $post_id = $core->blog->addPost($cur);
170         
171          # Add a comment to it
172          $cur = $core->con->openCursor($core->prefix.'comment');
173          $cur->post_id = $post_id;
174          $cur->comment_tz = $default_tz;
175          $cur->comment_author = __('Dotclear Team');
176          $cur->comment_email = 'contact@dotclear.net';
177          $cur->comment_site = 'http://www.dotclear.org/';
178          $cur->comment_content = __("<p>This is a comment.</p>\n<p>To delete it, log in and ".
179               "view your blog's comments. Then you might remove or edit it.</p>");
180          $core->blog->addComment($cur);
181         
182          #  Plugins initialization
183          define('DC_CONTEXT_ADMIN',true);
184          $core->plugins->loadModules(DC_PLUGINS_ROOT);
185          $plugins_install = $core->plugins->installModules();
186         
187          $step = 1;
188     }
189     catch (Exception $e)
190     {
191          $err = $e->getMessage();
192     }
193}
194
195if (!isset($step)) {
196     $step = 0;
197}
198header('Content-Type: text/html; charset=UTF-8');
199?>
200<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
201<html xmlns="http://www.w3.org/1999/xhtml"
202xml:lang="en" lang="en">
203<head>
204  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
205  <meta http-equiv="Content-Script-Type" content="text/javascript" />
206  <meta http-equiv="Content-Style-Type" content="text/css" />
207  <meta http-equiv="Content-Language" content="en" />
208  <meta name="MSSmartTagsPreventParsing" content="TRUE" />
209  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />
210  <meta name="GOOGLEBOT" content="NOSNIPPET" />
211  <title><?php echo __('Dotclear Install'); ?></title>
212 
213  <style type="text/css">
214  @import url(../style/install.css);
215  </style>
216  <script type="text/javascript" src="../js/jquery/jquery.js"></script>
217  <script type="text/javascript">
218  //<![CDATA[
219  $(function() {
220    var login_re = new RegExp('[^A-Za-z0-9@._-]+','g');
221    $('#u_firstname').keyup(function() {
222      var login = this.value.toLowerCase().replace(login_re,'').substring(0,32);
223      $('#u_login').val(login);
224    });
225    $('#u_login').keyup(function() {
226      $(this).val(this.value.replace(login_re,''));
227    });
228   
229    $('#u_login').parent().after($('<input type="hidden" name="u_date" value="' + Date().toLocaleString() + '" />'));
230   
231    var password_link = $('<a href="#" id="obfus"><?php echo(__('show')); ?></a>').click(function() {
232               $('#password').show();
233               $(this).remove();
234               return false;
235          });
236    $('#password').hide().before(password_link);
237  });
238  //]]>
239  </script>
240</head>
241
242<body id="dotclear-admin" class="install">
243<div id="content">
244<?php
245echo
246'<h1>'.__('Dotclear installation').'</h1>'.
247'<div id="main">';
248
249if (!is_writable(DC_TPL_CACHE)) {
250     echo '<div class="error"><p>'.sprintf(__('Cache directory %s is not writable.'),DC_TPL_CACHE).'</p></div>';
251}
252
253if ($can_install && !empty($err)) {
254     echo '<div class="error"><p><strong>'.__('Errors:').'</strong></p>'.$err.'</div>';
255}
256
257if (!empty($_GET['wiz'])) {
258     echo '<p class="message">'.__('Configuration file has been successfully created.').'</p>';
259}
260
261if ($can_install && $step == 0)
262{
263     echo
264     '<h2>'.__('User information').'</h2>'.
265     
266     '<p>'.__('Please provide the following information needed to create the first user.').'</p>'.
267     
268     '<form action="index.php" method="post">'.
269     '<fieldset><legend>'.__('User information').'</legend>'.
270     '<p><label>'.__('First Name:').' '.
271     form::field('u_firstname',30,255,html::escapeHTML($u_firstname)).'</label></p>'.
272     '<p><label>'.__('Last Name:').' '.
273     form::field('u_name',30,255,html::escapeHTML($u_name)).'</label></p>'.
274     '<p><label>'.__('Email:').' '.
275     form::field('u_email',30,255,html::escapeHTML($u_email)).'</label></p>'.
276     '</fieldset>'.
277     
278     '<fieldset><legend>'.__('Username and password').'</legend>'.
279     '<p><label class="required" title="'.__('Required field').'">'.__('Username:').' '.
280     form::field('u_login',30,32,html::escapeHTML($u_login)).'</label></p>'.
281     '<p><label class="required" title="'.__('Required field').'">'.__('Password:').' '.
282     form::password('u_pwd',30,255).'</label></p>'.
283     '<p><label class="required" title="'.__('Required field').'">'.__('Confirm password:').' '.
284     form::password('u_pwd2',30,255).'</label></p>'.
285     '</fieldset>'.
286     
287     '<p><input type="submit" value="'.__('save').'" /></p>'.
288     '</form>';
289}
290elseif ($can_install && $step == 1)
291{
292     # Plugins install messages
293     $plugins_install_result = '';
294     if (!empty($plugins_install['success']))
295     {
296          $plugins_install_result .= '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
297          foreach ($plugins_install['success'] as $k => $v) {
298               $plugins_install_result .= '<li>'.$k.'</li>';
299          }
300          $plugins_install_result .= '</ul></div>';
301     }
302     if (!empty($plugins_install['failure']))
303     {
304          $plugins_install_result .= '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
305          foreach ($plugins_install['failure'] as $k => $v) {
306               $plugins_install_result .= '<li>'.$k.' ('.$v.')</li>';
307          }
308          $plugins_install_result .= '</ul></div>';
309     }
310     
311     echo
312     '<h2>'.__('All done!').'</h2>'.
313     
314     $plugins_install_result.
315     
316     '<p>'.__('Dotclear has been successfully installed. Here is some useful information you should keep.').'</p>'.
317     
318     '<h3>'.__('Your account').'</h3>'.
319     '<ul>'.
320     '<li>'.__('Username:').' <strong>'.html::escapeHTML($u_login).'</strong></li>'.
321     '<li>'.__('Password:').' <strong id="password">'.html::escapeHTML($u_pwd).'</strong></li>'.
322     '</ul>'.
323     
324     '<h3>'.__('Your blog').'</h3>'.
325     '<ul>'.
326     '<li>'.__('Blog address:').' <strong>'.html::escapeHTML(http::getHost().$root_url).'/index.php?</strong></li>'.
327     '<li>'.__('Administration interface:').' <strong>'.html::escapeHTML(http::getHost().$admin_url).'</strong></li>'.
328     '</ul>'.
329     
330     '<form action="../auth.php" method="post">'.
331     '<p><input type="submit" value="'.__('Manage your blog now').'" />'.
332     form::hidden(array('user_id'),html::escapeHTML($u_login)).
333     form::hidden(array('user_pwd'),html::escapeHTML($u_pwd)).
334     '</p>'.
335     '</form>';
336}
337elseif (!$can_install)
338{
339     echo '<h2>'.__('Installation can not be completed').'</h2>'.
340     '<div class="error"><p><strong>'.__('Errors:').'</strong></p>'.$err.'</div>'.
341     '<p>'.__('For the said reasons, Dotclear can not be installed. '.
342          'Please refer to <a href="http://dotclear.org/documentation/2.0/admin/install">'.
343          'the documentation</a> to learn how to correct the problem.').'</p>';
344}
345?>
346</div>
347</div>
348</body>
349</html>
Note: See TracBrowser for help on using the repository browser.

Sites map