~alexharrington/xibo/pyclient-1.1.0a22

« back to all changes in this revision

Viewing changes to server/install.php

  • Committer: Alex Harrington
  • Date: 2009-12-31 11:38:50 UTC
  • Revision ID: alex@longhill.org.uk-20091231113850-bz5flhqq2gsw0qxf
Converted to 2.0 repo format and fixed lineendings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Xibo - Digitial Signage - http://www.xibo.org.uk
4
 
 * Copyright (C) 2009 Alex Harrington
5
 
 *
6
 
 * This file is part of Xibo.
7
 
 *
8
 
 * Xibo is free software: you can redistribute it and/or modify
9
 
 * it under the terms of the GNU Affero General Public License as published by
10
 
 * the Free Software Foundation, either version 3 of the License, or
11
 
 * any later version. 
12
 
 *
13
 
 * Xibo is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU Affero General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Affero General Public License
19
 
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
20
 
 */ 
21
 
DEFINE('XIBO', true);
22
 
 
23
 
if (! checkPHP()) 
24
 
{
25
 
        die('Xibo requires PHP 5.2.4 or later');
26
 
}
27
 
 
28
 
include('lib/app/kit.class.php');
29
 
include('install/header.inc');
30
 
include('config/config.class.php');
31
 
include('config/db_config.php');
32
 
 
33
 
// Setup for the Translations using Gettext.
34
 
// There is normally a class that will do this for us - but it requires a DB object (which we do not have at install time)
35
 
// Would be nice to include a method on the TranslationEngine that did this for us - but without the debugging
36
 
// The actual translation function __() is included later in this file.
37
 
$langs          = Kit::GetParam('HTTP_ACCEPT_LANGUAGE', $_SERVER, _STRING);
38
 
$lang           = 'en-gb';              // Default language
39
 
$encoding       = '';                   // We do not seem to need an encoding, but I read somewhere that we might - left as a reminder of this.
40
 
 
41
 
if ($langs != '') 
42
 
{
43
 
        $langs  = explode(',', $langs);
44
 
        $lang   = $langs[0];
45
 
}
46
 
 
47
 
// For windows
48
 
putenv('LANG='.$lang.'.'.$encoding);
49
 
putenv('LANGUAGE='.$lang.'.'.$encoding); 
50
 
putenv('LC_ALL='.$lang.'.'.$encoding); 
51
 
 
52
 
// Set local
53
 
setlocale(LC_ALL, $lang.'.'.$encoding);
54
 
 
55
 
// Translations have been setup.
56
 
 
57
 
$fault = false;
58
 
 
59
 
$xibo_step = Kit::GetParam('xibo_step',_POST,_INT,'0');
60
 
 
61
 
if (!isset($xibo_step) || $xibo_step == 0) {
62
 
  # First step of the process.
63
 
  # Show a welcome screen and next button
64
 
  ?>
65
 
  <?php echo __("Welcome to the Xibo Installer!"); ?><br /><br />
66
 
  <?php echo __("The installer will take you through setting up Xibo one step at a time."); ?><br /><br />
67
 
  <?php echo __("Lets get started!"); ?><br /><br />
68
 
  <form action="install.php" method="POST">
69
 
    <input type="hidden" name="xibo_step" value="1" />
70
 
    <div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
71
 
  </form>
72
 
  <?php
73
 
}
74
 
elseif ($xibo_step == 1) {
75
 
  # Check environment
76
 
  $db = new Database();
77
 
  $cObj = new Config($db);
78
 
  ?>
79
 
  <p><?php echo __("First we need to check if your server meets Xibo's requirements."); ?></p>
80
 
  <div class="checks">
81
 
  <?php
82
 
    echo $cObj->CheckEnvironment();
83
 
    if ($cObj->EnvironmentFault()) {
84
 
    ?>
85
 
      <form action="install.php" method="POST">
86
 
        <input type="hidden" name="xibo_step" value="1" />
87
 
        <div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
88
 
      </form>
89
 
    <?php
 
1
<?php
 
2
/*
 
3
 * Xibo - Digitial Signage - http://www.xibo.org.uk
 
4
 * Copyright (C) 2009 Alex Harrington
 
5
 *
 
6
 * This file is part of Xibo.
 
7
 *
 
8
 * Xibo is free software: you can redistribute it and/or modify
 
9
 * it under the terms of the GNU Affero General Public License as published by
 
10
 * the Free Software Foundation, either version 3 of the License, or
 
11
 * any later version. 
 
12
 *
 
13
 * Xibo is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Affero General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Affero General Public License
 
19
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */ 
 
21
DEFINE('XIBO', true);
 
22
 
 
23
if (! checkPHP()) 
 
24
{
 
25
        die('Xibo requires PHP 5.2.4 or later');
 
26
}
 
27
 
 
28
include('lib/app/kit.class.php');
 
29
include('install/header.inc');
 
30
include('config/config.class.php');
 
31
include('config/db_config.php');
 
32
 
 
33
// Setup for the Translations using Gettext.
 
34
// There is normally a class that will do this for us - but it requires a DB object (which we do not have at install time)
 
35
// Would be nice to include a method on the TranslationEngine that did this for us - but without the debugging
 
36
// The actual translation function __() is included later in this file.
 
37
$langs          = Kit::GetParam('HTTP_ACCEPT_LANGUAGE', $_SERVER, _STRING);
 
38
$lang           = 'en-gb';              // Default language
 
39
$encoding       = '';                   // We do not seem to need an encoding, but I read somewhere that we might - left as a reminder of this.
 
40
 
 
41
if ($langs != '') 
 
42
{
 
43
        $langs  = explode(',', $langs);
 
44
        $lang   = $langs[0];
 
45
}
 
46
 
 
47
// For windows
 
48
putenv('LANG='.$lang.'.'.$encoding);
 
49
putenv('LANGUAGE='.$lang.'.'.$encoding); 
 
50
putenv('LC_ALL='.$lang.'.'.$encoding); 
 
51
 
 
52
// Set local
 
53
setlocale(LC_ALL, $lang.'.'.$encoding);
 
54
 
 
55
// Translations have been setup.
 
56
 
 
57
$fault = false;
 
58
 
 
59
$xibo_step = Kit::GetParam('xibo_step',_POST,_INT,'0');
 
60
 
 
61
if (!isset($xibo_step) || $xibo_step == 0) {
 
62
  # First step of the process.
 
63
  # Show a welcome screen and next button
 
64
  ?>
 
65
  <?php echo __("Welcome to the Xibo Installer!"); ?><br /><br />
 
66
  <?php echo __("The installer will take you through setting up Xibo one step at a time."); ?><br /><br />
 
67
  <?php echo __("Lets get started!"); ?><br /><br />
 
68
  <form action="install.php" method="POST">
 
69
    <input type="hidden" name="xibo_step" value="1" />
 
70
    <div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
 
71
  </form>
 
72
  <?php
 
73
}
 
74
elseif ($xibo_step == 1) {
 
75
  # Check environment
 
76
  $db = new Database();
 
77
  $cObj = new Config($db);
 
78
  ?>
 
79
  <p><?php echo __("First we need to check if your server meets Xibo's requirements."); ?></p>
 
80
  <div class="checks">
 
81
  <?php
 
82
    echo $cObj->CheckEnvironment();
 
83
    if ($cObj->EnvironmentFault()) {
 
84
    ?>
 
85
      <form action="install.php" method="POST">
 
86
        <input type="hidden" name="xibo_step" value="1" />
 
87
        <div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
 
88
      </form>
 
89
    <?php
90
90
    }
91
91
    else if ($cObj->EnvironmentWarning()) {
92
92
    ?>
93
 
      <form action="install.php" method="POST">
94
 
        <input type="hidden" name="xibo_step" value="1" />
95
 
        <div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
96
 
      </form>
97
 
      <form action="install.php" method="POST">
98
 
        <input type="hidden" name="xibo_step" value="2" />
99
 
        <div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
100
 
      </form>
101
 
    <?php
102
 
    }
103
 
    else {
104
 
    ?>
105
 
      <form action="install.php" method="POST">
106
 
        <input type="hidden" name="xibo_step" value="2" />
107
 
        <div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
108
 
      </form>
109
 
    <?php
110
 
    }    
111
 
}
112
 
elseif ($xibo_step == 2) {
113
 
# Create database
114
 
## Does database exist already?
115
 
 
116
 
  ?>
117
 
  <div class="info">
118
 
    <p><?php echo __("Xibo needs to setup a new database."); ?></p>
119
 
    <p><?php echo __("If you have not yet created an empty database and database user for Xibo to use, and know the username/password of a MySQL administrator, click the \"Create New\" button, otherwise click \"Use Existing\"."); ?></p>
120
 
    <p><i><?php echo __("Note that any existing database must be empty"); ?></i></p>
121
 
  </div>
122
 
  <form action="install.php" method="POST">
123
 
    <input type="hidden" name="xibo_step" value="3" />
124
 
    <button type="submit"><?php echo __("Create New"); ?></button>
125
 
  </form>
126
 
  <form action="install.php" method="POST">
127
 
    <input type="hidden" name="xibo_step" value="4" />
128
 
    <button type="submit"><?php echo __("Use Existing"); ?></button>
129
 
  </form>
130
 
  <?php
131
 
}
132
 
elseif ($xibo_step == 3) {
133
 
## If not, gather admin password and use to create empty db and new user.
134
 
?>
135
 
<div class="info">
136
 
<p><?php echo __("Since no empty database has been created for Xibo to use, we need the username and password of a MySQL administrator to create a new database, and database user for Xibo."); ?></p>
137
 
<p><?php echo __("Additionally, please give us a new username and password to create in MySQL for Xibo to use. Xibo will create this automatically for you."); ?></p>
138
 
<form action="install.php" method="POST">
139
 
<input type="hidden" name="xibo_step" value="5" />
140
 
<input type="hidden" name="db_create" value="On" />
141
 
<div class="install_table">
142
 
  <p><label for="host"><?php echo __("Host:"); ?>&nbsp;</label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
143
 
  <p><label for="admin_username"><?php echo __("Admin Username:"); ?>&nbsp;</label><input class="username" type="text" id="admin_username" name="admin_username" size="12" /></p>
144
 
  <p><label for="admin_password"><?php echo __("Admin Password:"); ?>&nbsp;</label><input class="username" type="password" id="admin_password" name="admin_password" size="12" /></p>
145
 
  <p><label for="db_name"><?php echo __("Xibo Database Name:"); ?>&nbsp;</label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
146
 
  <p><label for="db_username"><?php echo __("Xibo Database Username:"); ?>&nbsp;</label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
147
 
  <p><label for="db_password"><?php echo __("Xibo Database Password:"); ?>&nbsp;</label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
148
 
</div>
149
 
</div>
150
 
<button type="submit"><?php echo __("Create"); ?></button>
151
 
</form>
152
 
<?php
153
 
}
154
 
elseif ($xibo_step == 4) {
155
 
## Get details of db that's been created already for us
156
 
?>
157
 
<div class="info">
158
 
<p><?php echo __("Please enter the details of the database and user you have created for Xibo."); ?></p>
159
 
<form action="install.php" method="POST">
160
 
<input type="hidden" name="xibo_step" value="5" />
161
 
<input type="hidden" name="db_create" value="Off" />
162
 
<div class="install_table">
163
 
  <p><label for="host"><?php echo __("Host:"); ?>&nbsp;</label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
164
 
  <p><label for="db_name"><?php echo __("Xibo Database Name:"); ?>&nbsp;</label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
165
 
  <p><label for="db_username"><?php echo __("Xibo Database Username:"); ?>&nbsp;</label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
166
 
  <p><label for="db_password"><?php echo __("Xibo Database Password:"); ?>&nbsp;</label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
167
 
</div>
168
 
</div>
169
 
<button type="submit"><?php echo __("Create"); ?></button>
170
 
</form>
171
 
<?php
172
 
}
173
 
elseif ($xibo_step == 5) {
174
 
 
175
 
  $db_create = Kit::GetParam('db_create',_POST,_STRING);
176
 
 
177
 
  if (!isset($db_create)) {
178
 
    reportError("2",__("Something went wrong"));
179
 
  }
180
 
  else {
181
 
    $db_host = Kit::GetParam('host',_POST,_STRING,'localhost');
182
 
    $db_user = Kit::GetParam('db_username',_POST,_USERNAME);
183
 
    $db_pass = Kit::GetParam('db_password',_POST,_PASSWORD);
184
 
    $db_name = Kit::GetParam('db_name',_POST,_USERNAME);
185
 
    ?>
186
 
    <div class="info">
187
 
    <?php
188
 
    if ($db_create == 'On') {  
189
 
      $db_admin_user = Kit::GetParam('admin_username',_POST,_USERNAME);
190
 
      $db_admin_pass = Kit::GetParam('admin_password',_POST,_PASSWORD);
191
 
      
192
 
      if (! ($db_host && $db_name && $db_user && $db_pass && $db_admin_user && $db_admin_pass)) {
193
 
        # Something was blank.
194
 
        # Throw an error.
195
 
        reportError("3", __("A field was blank. Please fill in all fields."));
196
 
      }
197
 
      
198
 
      $db = @mysql_connect($db_host,$db_admin_user,$db_admin_pass);
199
 
      
200
 
      if (! $db) {
201
 
        reportError("3", __("Could not connect to MySQL with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
202
 
      }
203
 
      
204
 
      ?>
205
 
      <p><?php echo __("Creating new database."); ?></p>
206
 
      <?php
207
 
      flush();
208
 
      
209
 
      $SQL = sprintf("CREATE DATABASE `%s`",
210
 
                      mysql_real_escape_string($db_name));
211
 
      if (! @mysql_query($SQL, $db)) {
212
 
        # Create database and user
213
 
        reportError("3", __("Could not create a new database with the administrator details. Please check and try again.") . "<br /><br />" . "MySQL Error:" . "<br />" . mysql_error());
214
 
      }
215
 
      
216
 
      # Choose the MySQL DB to create a user
217
 
      @mysql_select_db("mysql", $db);
218
 
 
219
 
      # Make $db_host lowercase so it matches "localhost" if required.
220
 
      $db_host = strtolower($db_host);
221
 
      
222
 
      ?>
223
 
      <p><?php echo __("Creating new user"); ?></p>
224
 
      <?php
225
 
      flush();
226
 
      
227
 
      if ($db_host == 'localhost') {
228
 
        $SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%s' IDENTIFIED BY '%s'",
229
 
                        mysql_real_escape_string($db_name),
230
 
                        mysql_real_escape_string($db_user),
231
 
                        mysql_real_escape_string($db_host),
232
 
                        mysql_real_escape_string($db_pass));
233
 
      }
234
 
      else {
235
 
        $SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%%' IDENTIFIED BY '%s'",
236
 
                        mysql_real_escape_string($db_name),
237
 
                        mysql_real_escape_string($db_user),
238
 
                        mysql_real_escape_string($db_pass));
239
 
      }
240
 
      if (! @mysql_query($SQL, $db)) {
241
 
          reportError("3", __("Could not create a new user with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
242
 
      }
243
 
      
244
 
 
245
 
      @mysql_query("FLUSH PRIVILEGES", $db);      
246
 
      @mysql_close($db);
247
 
      
248
 
    }
249
 
    else {
250
 
      if (! ($db_host && $db_name && $db_user && $db_pass)) {
251
 
        # Something was blank
252
 
        # Throw an error.
253
 
        reportError("4", __("A field was blank. Please fill in all fields.") . " " . $db_host . " " . $db_name . " " . $db_user . " " . $db_pass);
254
 
      }
255
 
    }
256
 
    ## Populate database
257
 
    
258
 
    $db = @mysql_connect($db_host,$db_user,$db_pass);
259
 
      
260
 
    if (! $db) {
261
 
      reportError("4", __("Could not connect to MySQL with the Xibo User account details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
262
 
    }
263
 
      
264
 
    @mysql_select_db($db_name,$db);
265
 
    
266
 
    ?>
267
 
    <p>Populating the database</p>
268
 
    <?php
269
 
    flush();
270
 
    
271
 
    # Load from sql files to db - HOW?
272
 
    $sql_files = ls('*.sql','install/database',false,array('return_files'));
273
 
 
274
 
    // Sort the files in to sensible order, ie
275
 
    //   0.sql
276
 
    //   1.sql
277
 
    //  10.sql
278
 
    //
279
 
    // NOT
280
 
    //
281
 
    //   0.sql
282
 
    //  10.sql
283
 
    //   1.sql
284
 
    //
285
 
    // NB this is broken for 0 padded files
286
 
    // eg 01.sql would be incorrectly sorted in the above example.
287
 
    
 
93
      <form action="install.php" method="POST">
 
94
        <input type="hidden" name="xibo_step" value="1" />
 
95
        <div class="loginbutton"><button type="submit"><?php echo __("Retest"); ?></button></div>
 
96
      </form>
 
97
      <form action="install.php" method="POST">
 
98
        <input type="hidden" name="xibo_step" value="2" />
 
99
        <div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
 
100
      </form>
 
101
    <?php
 
102
    }
 
103
    else {
 
104
    ?>
 
105
      <form action="install.php" method="POST">
 
106
        <input type="hidden" name="xibo_step" value="2" />
 
107
        <div class="loginbutton"><button type="submit"><?php echo __("Next"); ?> ></button></div>
 
108
      </form>
 
109
    <?php
 
110
    }    
 
111
}
 
112
elseif ($xibo_step == 2) {
 
113
# Create database
 
114
## Does database exist already?
 
115
 
 
116
  ?>
 
117
  <div class="info">
 
118
    <p><?php echo __("Xibo needs to setup a new database."); ?></p>
 
119
    <p><?php echo __("If you have not yet created an empty database and database user for Xibo to use, and know the username/password of a MySQL administrator, click the \"Create New\" button, otherwise click \"Use Existing\"."); ?></p>
 
120
    <p><i><?php echo __("Note that any existing database must be empty"); ?></i></p>
 
121
  </div>
 
122
  <form action="install.php" method="POST">
 
123
    <input type="hidden" name="xibo_step" value="3" />
 
124
    <button type="submit"><?php echo __("Create New"); ?></button>
 
125
  </form>
 
126
  <form action="install.php" method="POST">
 
127
    <input type="hidden" name="xibo_step" value="4" />
 
128
    <button type="submit"><?php echo __("Use Existing"); ?></button>
 
129
  </form>
 
130
  <?php
 
131
}
 
132
elseif ($xibo_step == 3) {
 
133
## If not, gather admin password and use to create empty db and new user.
 
134
?>
 
135
<div class="info">
 
136
<p><?php echo __("Since no empty database has been created for Xibo to use, we need the username and password of a MySQL administrator to create a new database, and database user for Xibo."); ?></p>
 
137
<p><?php echo __("Additionally, please give us a new username and password to create in MySQL for Xibo to use. Xibo will create this automatically for you."); ?></p>
 
138
<form action="install.php" method="POST">
 
139
<input type="hidden" name="xibo_step" value="5" />
 
140
<input type="hidden" name="db_create" value="On" />
 
141
<div class="install_table">
 
142
  <p><label for="host"><?php echo __("Host:"); ?>&nbsp;</label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
 
143
  <p><label for="admin_username"><?php echo __("Admin Username:"); ?>&nbsp;</label><input class="username" type="text" id="admin_username" name="admin_username" size="12" /></p>
 
144
  <p><label for="admin_password"><?php echo __("Admin Password:"); ?>&nbsp;</label><input class="username" type="password" id="admin_password" name="admin_password" size="12" /></p>
 
145
  <p><label for="db_name"><?php echo __("Xibo Database Name:"); ?>&nbsp;</label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
 
146
  <p><label for="db_username"><?php echo __("Xibo Database Username:"); ?>&nbsp;</label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
 
147
  <p><label for="db_password"><?php echo __("Xibo Database Password:"); ?>&nbsp;</label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
 
148
</div>
 
149
</div>
 
150
<button type="submit"><?php echo __("Create"); ?></button>
 
151
</form>
 
152
<?php
 
153
}
 
154
elseif ($xibo_step == 4) {
 
155
## Get details of db that's been created already for us
 
156
?>
 
157
<div class="info">
 
158
<p><?php echo __("Please enter the details of the database and user you have created for Xibo."); ?></p>
 
159
<form action="install.php" method="POST">
 
160
<input type="hidden" name="xibo_step" value="5" />
 
161
<input type="hidden" name="db_create" value="Off" />
 
162
<div class="install_table">
 
163
  <p><label for="host"><?php echo __("Host:"); ?>&nbsp;</label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
 
164
  <p><label for="db_name"><?php echo __("Xibo Database Name:"); ?>&nbsp;</label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
 
165
  <p><label for="db_username"><?php echo __("Xibo Database Username:"); ?>&nbsp;</label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
 
166
  <p><label for="db_password"><?php echo __("Xibo Database Password:"); ?>&nbsp;</label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
 
167
</div>
 
168
</div>
 
169
<button type="submit"><?php echo __("Create"); ?></button>
 
170
</form>
 
171
<?php
 
172
}
 
173
elseif ($xibo_step == 5) {
 
174
 
 
175
  $db_create = Kit::GetParam('db_create',_POST,_STRING);
 
176
 
 
177
  if (!isset($db_create)) {
 
178
    reportError("2",__("Something went wrong"));
 
179
  }
 
180
  else {
 
181
    $db_host = Kit::GetParam('host',_POST,_STRING,'localhost');
 
182
    $db_user = Kit::GetParam('db_username',_POST,_USERNAME);
 
183
    $db_pass = Kit::GetParam('db_password',_POST,_PASSWORD);
 
184
    $db_name = Kit::GetParam('db_name',_POST,_USERNAME);
 
185
    ?>
 
186
    <div class="info">
 
187
    <?php
 
188
    if ($db_create == 'On') {  
 
189
      $db_admin_user = Kit::GetParam('admin_username',_POST,_USERNAME);
 
190
      $db_admin_pass = Kit::GetParam('admin_password',_POST,_PASSWORD);
 
191
      
 
192
      if (! ($db_host && $db_name && $db_user && $db_pass && $db_admin_user && $db_admin_pass)) {
 
193
        # Something was blank.
 
194
        # Throw an error.
 
195
        reportError("3", __("A field was blank. Please fill in all fields."));
 
196
      }
 
197
      
 
198
      $db = @mysql_connect($db_host,$db_admin_user,$db_admin_pass);
 
199
      
 
200
      if (! $db) {
 
201
        reportError("3", __("Could not connect to MySQL with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
 
202
      }
 
203
      
 
204
      ?>
 
205
      <p><?php echo __("Creating new database."); ?></p>
 
206
      <?php
 
207
      flush();
 
208
      
 
209
      $SQL = sprintf("CREATE DATABASE `%s`",
 
210
                      mysql_real_escape_string($db_name));
 
211
      if (! @mysql_query($SQL, $db)) {
 
212
        # Create database and user
 
213
        reportError("3", __("Could not create a new database with the administrator details. Please check and try again.") . "<br /><br />" . "MySQL Error:" . "<br />" . mysql_error());
 
214
      }
 
215
      
 
216
      # Choose the MySQL DB to create a user
 
217
      @mysql_select_db("mysql", $db);
 
218
 
 
219
      # Make $db_host lowercase so it matches "localhost" if required.
 
220
      $db_host = strtolower($db_host);
 
221
      
 
222
      ?>
 
223
      <p><?php echo __("Creating new user"); ?></p>
 
224
      <?php
 
225
      flush();
 
226
      
 
227
      if ($db_host == 'localhost') {
 
228
        $SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%s' IDENTIFIED BY '%s'",
 
229
                        mysql_real_escape_string($db_name),
 
230
                        mysql_real_escape_string($db_user),
 
231
                        mysql_real_escape_string($db_host),
 
232
                        mysql_real_escape_string($db_pass));
 
233
      }
 
234
      else {
 
235
        $SQL = sprintf("GRANT ALL PRIVILEGES ON `%s`.* to '%s'@'%%' IDENTIFIED BY '%s'",
 
236
                        mysql_real_escape_string($db_name),
 
237
                        mysql_real_escape_string($db_user),
 
238
                        mysql_real_escape_string($db_pass));
 
239
      }
 
240
      if (! @mysql_query($SQL, $db)) {
 
241
          reportError("3", __("Could not create a new user with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
 
242
      }
 
243
      
 
244
 
 
245
      @mysql_query("FLUSH PRIVILEGES", $db);      
 
246
      @mysql_close($db);
 
247
      
 
248
    }
 
249
    else {
 
250
      if (! ($db_host && $db_name && $db_user && $db_pass)) {
 
251
        # Something was blank
 
252
        # Throw an error.
 
253
        reportError("4", __("A field was blank. Please fill in all fields.") . " " . $db_host . " " . $db_name . " " . $db_user . " " . $db_pass);
 
254
      }
 
255
    }
 
256
    ## Populate database
 
257
    
 
258
    $db = @mysql_connect($db_host,$db_user,$db_pass);
 
259
      
 
260
    if (! $db) {
 
261
      reportError("4", __("Could not connect to MySQL with the Xibo User account details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
 
262
    }
 
263
      
 
264
    @mysql_select_db($db_name,$db);
 
265
    
 
266
    ?>
 
267
    <p>Populating the database</p>
 
268
    <?php
 
269
    flush();
 
270
    
 
271
    # Load from sql files to db - HOW?
 
272
    $sql_files = ls('*.sql','install/database',false,array('return_files'));
 
273
 
 
274
    // Sort the files in to sensible order, ie
 
275
    //   0.sql
 
276
    //   1.sql
 
277
    //  10.sql
 
278
    //
 
279
    // NOT
 
280
    //
 
281
    //   0.sql
 
282
    //  10.sql
 
283
    //   1.sql
 
284
    //
 
285
    // NB this is broken for 0 padded files
 
286
    // eg 01.sql would be incorrectly sorted in the above example.
 
287
    
288
288
    $sqlStatementCount = 0;
289
 
    natcasesort($sql_files);
290
 
 
291
 
    foreach ($sql_files as $filename) {
292
 
      ?>
293
 
      <p>Loading from <?php print $filename; ?>
294
 
      <?php
295
 
        flush();
296
 
        
297
 
        $delimiter = ';';
298
 
        $sql_file = @file_get_contents('install/database/' . $filename);
299
 
        $sql_file = remove_remarks($sql_file);
300
 
        $sql_file = split_sql_file($sql_file, $delimiter);
301
 
    
302
 
        foreach ($sql_file as $sql) {
 
289
    natcasesort($sql_files);
 
290
 
 
291
    foreach ($sql_files as $filename) {
 
292
      ?>
 
293
      <p>Loading from <?php print $filename; ?>
 
294
      <?php
 
295
        flush();
 
296
        
 
297
        $delimiter = ';';
 
298
        $sql_file = @file_get_contents('install/database/' . $filename);
 
299
        $sql_file = remove_remarks($sql_file);
 
300
        $sql_file = split_sql_file($sql_file, $delimiter);
 
301
    
 
302
        foreach ($sql_file as $sql) {
303
303
          print ".";
304
 
          $sqlStatementCount++;
305
 
          flush();
306
 
          if (! @mysql_query($sql,$db)) {
307
 
            reportError("4", __("An error occured populating the database.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error() . "<br /><br />SQL executed:<br />" . $sql . "<br /><br />Statement number: " . $sqlStatementCount);
308
 
          }
309
 
        }
310
 
        print "</p>";
311
 
    }
312
 
    @mysql_close($db);
313
 
  }
314
 
  # Write out a new settings.php
315
 
  $fh = fopen("settings.php", 'wt');
316
 
  
317
 
  if (! $fh) {
318
 
    reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
319
 
  }
320
 
  
321
 
  settings_strings();
322
 
  
323
 
  $settings_content = '$dbhost = \'' . $db_host . '\';' . "\n";
324
 
  $settings_content .= '$dbuser = \'' . $db_user . '\';' . "\n";
325
 
  $settings_content .= '$dbpass = \'' . $db_pass . '\';' . "\n";
326
 
  $settings_content .= '$dbname = \'' . $db_name . '\';' . "\n\n";
327
 
  $settings_content .= 'define(\'SECRET_KEY\',\'' . gen_secret() . '\');' . "\n";
328
 
  
329
 
  if (! fwrite($fh, $settings_header . $settings_content . $settings_footer)) {
330
 
    reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
331
 
  }
332
 
    
333
 
  fclose($fh);
334
 
  
335
 
  ?>
336
 
  </div>
337
 
  <div class="install_table">
338
 
    <form action="install.php" method="POST">
339
 
      <input type="hidden" name="xibo_step" value="6" />
340
 
  </div>
341
 
    <button type="submit"><?php echo __("Next"); ?> ></button>
342
 
  </form>
343
 
  <?php
344
 
}
345
 
elseif ($xibo_step == 6) {
346
 
  # Form to get new admin password
347
 
  ?>
348
 
  <div class="info">
349
 
  <p><?php echo __("Xibo needs to set the \"xibo_admin\" user password. Please enter a password for this account below."); ?></p>
350
 
  </div>
351
 
  <div class="install_table">
352
 
    <form action="install.php" method="POST">
353
 
      <input type="hidden" name="xibo_step" value="7" />
354
 
      <p><label for="password1"><?php echo __("Password:"); ?>&nbsp;</label><input type="password" name="password1" size="12" /></p>
355
 
      <p><label for="password2"><?php echo __("Retype Password:"); ?>&nbsp;</label><input type="password" name="password2" size="12" /></p>
356
 
  </div>
357
 
    <button type="submit"><?php echo __("Next"); ?> ></button>
358
 
  </form>
359
 
  <?php
360
 
}
361
 
elseif ($xibo_step == 7) {
362
 
  # Setup xibo_admin password
363
 
  $password1 = Kit::GetParam('password1',_POST,_PASSWORD);
364
 
  $password2 = Kit::GetParam('password2',_POST,_PASSWORD);
365
 
  
366
 
  if (!(($password1 && $password2) && ($password1 == $password2))) {
367
 
    reportError("6", __("Please input a new password. Ensure both password fields are identical."));
368
 
  }
369
 
  
370
 
  include('settings.php');
371
 
  
372
 
  $password_hash = md5($password1);
373
 
  
374
 
  $db = @mysql_connect($dbhost,$dbuser,$dbpass);
375
 
      
376
 
    if (! $db) {
377
 
      reportError("6", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
378
 
    }
379
 
      
380
 
    @mysql_select_db($dbname,$db);
381
 
 
382
 
    $SQL = sprintf("UPDATE `user` SET UserPassword = '%s' WHERE UserID = 1 LIMIT 1",
383
 
                    mysql_real_escape_string($password_hash));
384
 
    if (! @mysql_query($SQL, $db)) {
385
 
      reportError("6", __("An error occured changing the xibo_admin password.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
386
 
    }
387
 
 
388
 
    @mysql_close($db);
389
 
    
390
 
    ?>
391
 
    <div class="info">
392
 
      <?php echo __("Successfully changed the xibo_admin password. We're nearly there now. Just a couple more steps!"); ?>
393
 
    </div>
394
 
    <form action="install.php" method="POST">
395
 
      <input type="hidden" name="xibo_step" value="8" />
396
 
      <button type="submit"><?php echo __("Next"); ?> ></button>
397
 
    </form>
398
 
    <?php
399
 
}
400
 
elseif ($xibo_step == 8) {
401
 
  # Configure paths and keys
402
 
  ## nuSoap
403
 
  ## libraries
404
 
  ## server_key
405
 
  ?>
406
 
  <div class="info">
407
 
    <p><b><?php echo __("Library Location"); ?></b></p>
408
 
    <p><?php echo __("Xibo needs somewhere to store the things you upload to be shown. Ideally, this should be somewhere outside the root of your webserver - that is such that is not accessible by a web browser. Please input the full path to this folder. If the folder does not already exist, Xibo will attempt to create it for you."); ?></p>
409
 
    <form action="install.php" method="POST">
410
 
    <div class="install_table">
411
 
       <p><label for="library_location"><?php echo __("Library Location:"); ?>&nbsp;</label><input type="text" name="library_location" value="" /></p>
412
 
    </div>
413
 
    <p><b><?php echo __("Server Key"); ?></b></p>
414
 
    <p><?php echo __("Xibo needs you to choose a \"key\". This will be required each time you setup a new client. It should be complicated, and hard to remember. It is visible in the admin interface, so it need not be written down separately."); ?></p>
415
 
    <div class="install_table">
416
 
      <p><label for="server_key"><?php echo __("Server Key:"); ?> </label><input type="text" name="server_key" value="" /></p>
417
 
    </div>
418
 
    <p><b><?php echo __("Statistics"); ?></b></p>
419
 
    <p><?php echo __("We'd love to know you're running Xibo. If you're happy for us to collect anonymous statistics (version number, number of displays) then please leave the box ticked. Please untick the box if your server does not have direct access to the internet."); ?></p>
420
 
    <div class="install_table">
421
 
      <p><label for="stats"><?php echo __("Anonymous Statistics:"); ?>&nbsp;</label><input type="checkbox" name="stats" value="true" checked /></p>
422
 
    </div>
423
 
      <input type="hidden" name="xibo_step" value="9" />
424
 
    </div>
425
 
      <button type="submit"><?php echo __("Next"); ?> ></button>
426
 
    </form>
427
 
  <?php
428
 
}
429
 
elseif ($xibo_step == 9) {
430
 
 
431
 
  $server_key = Kit::GetParam('server_key',_POST,_WORD);
432
 
  $library_location = Kit::GetParam('library_location',_POST,_STRING);
433
 
  $stats = Kit::GetParam('stats',_POST,_BOOL);
434
 
  
435
 
  // Remove trailing whitespace from the path given.
436
 
  $library_location = trim($library_location);
437
 
 
438
 
  // Check both fields were completed
439
 
  if (! ($server_key && $library_location)) {
440
 
    reportError("8", __("A field was blank. Please make sure you complete all fields"));
441
 
  }
442
 
 
443
 
  if ($stats) {
444
 
    $stats="On"; // Fixme: translate ?
445
 
  }
446
 
  else {
447
 
    $stats="Off"; //Fixme : translate ?
448
 
  }
449
 
 
450
 
  // Does library_location exist already?
451
 
  if (! is_dir($library_location)) {
452
 
    if (is_file($library_location)) {
453
 
      reportError("8", __("A file exists with the name you gave for the Library Location. Please choose another location"));
454
 
    }
455
 
 
456
 
    // Directory does not exist. Attempt to make it
457
 
    // Using mkdir recursively, so it will attempt to make any
458
 
    // intermediate folders required.
459
 
    if (! mkdir($library_location,0755,true)) {
460
 
      reportError("8", __("Could not create the Library Location directory for you. Please ensure the webserver has permission to create a folder in this location, or create the folder manually and grant permission for the webserver to write to the folder."));
461
 
    }
462
 
    
463
 
  }
464
 
  
465
 
  // Is library_location writable?
466
 
  if (! is_writable($library_location)) {
467
 
    // Directory is not writable.
468
 
    reportError("8", __("The Library Location you gave is not writable by the webserver. Please fix the permissions and try again."));
469
 
  }
470
 
  
471
 
  // Is library_location empty?
472
 
  if (count(ls("*",$library_location,true)) > 0) {
473
 
    reportError("8", __("The Library Location you gave is not empty. Please give the location of an empty folder"));
474
 
  }
475
 
  
476
 
  // Check if the user has added a trailing slash.
477
 
  // If not, add one.
478
 
  if (!((substr($library_location, -1) == '/') || (substr($library_location, -1) == '\\'))) {
479
 
    $library_location = $library_location . '/';
480
 
  }
481
 
 
482
 
  include('settings.php');
483
 
  
484
 
  $db = @mysql_connect($dbhost,$dbuser,$dbpass);
485
 
      
486
 
    if (! $db) {
487
 
      reportError("8", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
488
 
    }
489
 
      
490
 
    @mysql_select_db($dbname,$db);
491
 
    
492
 
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'LIBRARY_LOCATION' LIMIT 1",
493
 
                    mysql_real_escape_string($library_location));
494
 
    if (! @mysql_query($SQL, $db)) {
495
 
      reportError("8", __("An error occured changing the library location.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
496
 
    }
497
 
    
498
 
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'SERVER_KEY' LIMIT 1",
499
 
                      mysql_real_escape_string($server_key));
500
 
    if (! @mysql_query($SQL, $db)) {
501
 
      reportError("8", __("An error occured changing the server key.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
502
 
    }
503
 
    
504
 
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'defaultTimezone' LIMIT 1",
505
 
                      mysql_real_escape_string(date_default_timezone_get()));
506
 
    if (! @mysql_query($SQL, $db)) {
507
 
      reportError("8", __("An error occured setting the default timezone.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
508
 
    }
509
 
 
510
 
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'PHONE_HOME' LIMIT 1",
511
 
                      mysql_real_escape_string($stats));
512
 
    if (! @mysql_query($SQL, $db)) {
513
 
      reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
514
 
    }
515
 
    $SQL = "UPDATE `setting` SET `value` = '" . md5(uniqid(rand(), true)) . "' WHERE `setting`.`setting` = 'PHONE_HOME_KEY' LIMIT 1";
516
 
    if (! @mysql_query($SQL, $db)) {
517
 
      reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
518
 
    }
519
 
    
520
 
    @mysql_close($db);
521
 
  
522
 
  ?>
523
 
  <div class="info">
524
 
    <p><?php echo __("Successfully set library location and server key."); ?></p>
525
 
  </div>
526
 
    <form action="install.php" method="POST">
527
 
      <input type="hidden" name="xibo_step" value="10" />
528
 
      <button type="submit"><?php echo __("Next"); ?> ></button>
529
 
    </form>
530
 
  <?php
531
 
}
532
 
elseif ($xibo_step == 10) {
533
 
# Delete install.php
534
 
# Redirect to login page.
535
 
  if (! unlink('install.php')) {
536
 
    reportError("10", __("Unable to delete install.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
537
 
  }
538
 
  if (! unlink('upgrade.php')) {
539
 
    reportError("10", __("Unable to delete upgrade.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
540
 
  }
541
 
  ?>
542
 
  <div class="info">
543
 
    <p><b><?php echo __("Xibo was successfully installed."); ?></b></p>
544
 
    <p><?php echo __("Please click"); ?>&nbsp;<a href="index.php"><?php echo __("here"); ?></a>&nbsp;<?php echo __("to logon to Xibo as \"xibo_admin\" with the password you chose earlier."); ?></p>
545
 
  </div>
546
 
  <?php
547
 
}
548
 
else {
549
 
  reportError("0", __("A required parameter was missing. Please go through the installer sequentially!"), __("Start Again")); // Fixme : translate "Start Again" ?
550
 
}
551
 
 
552
 
include('install/footer.inc');
553
 
 
554
 
# Functions
555
 
function checkFsPermissions() {
556
 
  # Check for appropriate filesystem permissions
557
 
  return ((is_writable("install.php") && (is_writable("settings.php")) && (is_writable("upgrade.php")) || is_writable(".")));
558
 
}
559
 
 
560
 
function checkMySQL() {
561
 
  # Check PHP has MySQL module installed
562
 
  return extension_loaded("mysql");
563
 
}
564
 
 
565
 
function checkJson() {
566
 
  # Check PHP has JSON module installed
567
 
  return extension_loaded("json");
568
 
}
569
 
 
570
 
function checkGd() {
571
 
  # Check PHP has JSON module installed
572
 
  return extension_loaded("gd");
573
 
}
574
 
 
575
 
function checkCal() {
576
 
  # Check PHP has JSON module installed
577
 
  return extension_loaded("calendar");
578
 
}
579
 
 
580
 
function reportError($step, $message, $button_text="&lt; Back") { // fixme : translate ?
581
 
?>
582
 
    <div class="info">
583
 
      <?php print $message; ?>
584
 
    </div>
585
 
    <form action="install.php" method="POST">
586
 
      <input type="hidden" name="xibo_step" value="<?php print $step; ?>"/>
587
 
      <button type="submit"><?php print $button_text; ?></button>
588
 
    </form>
589
 
  <?php
590
 
  include('install/footer.inc');
591
 
  die();
592
 
593
 
 
594
 
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
595
 
// By Crackster 
596
 
/**
597
 
 * remove_remarks will strip the sql comment lines out of an uploaded sql file
598
 
 */
599
 
function remove_remarks($sql){
600
 
  $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
601
 
  $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
602
 
  return $sql;
603
 
}
604
 
 
605
 
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
606
 
// By Crackster              
607
 
/**
608
 
 * split_sql_file will split an uploaded sql file into single sql statements.
609
 
 * Note: expects trim() to have already been run on $sql.
610
 
 */
611
 
function split_sql_file($sql, $delimiter){
612
 
  $sql = str_replace("\r" , '', $sql);
613
 
  $data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
614
 
  $data = array_map('trim', $data);
615
 
  // The empty case
616
 
  $end_data = end($data);
617
 
  if (empty($end_data))
618
 
  {
619
 
    unset($data[key($data)]);
620
 
  }
621
 
  return $data;
622
 
}
623
 
 
624
 
/**
625
 
 * This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of 
626
 
 *               all files in that folder.
627
 
 * Link             : http://www.bin-co.com/php/scripts/filesystem/ls/
628
 
 * License      : BSD
629
 
 * Arguments     :  $pattern - The pattern to look out for [OPTIONAL]
630
 
 *                    $folder - The path of the directory of which's directory list you want [OPTIONAL]
631
 
 *                    $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
632
 
 *                    $options - An array of values 'return_files' or 'return_folders' or both
633
 
 * Returns       : A flat list with the path of all the files(no folders) that matches the condition given.
634
 
 */
635
 
function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) {
636
 
    if($folder) {
637
 
        $current_folder = realpath('.');
638
 
        if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error
639
 
            if(!file_exists($folder)) return array();
640
 
        }
641
 
        
642
 
        if(!chdir($folder)) return array();
643
 
    }
644
 
    
645
 
    
646
 
    $get_files    = in_array('return_files', $options);
647
 
    $get_folders= in_array('return_folders', $options);
648
 
    $both = array();
649
 
    $folders = array();
650
 
    
651
 
    // Get the all files and folders in the given directory.
652
 
    if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK);
653
 
    if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
654
 
    
655
 
    //If a pattern is specified, make sure even the folders match that pattern.
656
 
    $matching_folders = array();
657
 
    if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
658
 
    
659
 
    //Get just the files by removing the folders from the list of all files.
660
 
    $all = array_values(array_diff($both,$folders));
661
 
        
662
 
    if($recursivly or $get_folders) {
663
 
        foreach ($folders as $this_folder) {
664
 
            if($get_folders) {
665
 
                //If a pattern is specified, make sure even the folders match that pattern.
666
 
                if($pattern !== '*') {
667
 
                    if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder);
668
 
                }
669
 
                else array_push($all, $this_folder);
670
 
            }
671
 
            
672
 
            if($recursivly) {
673
 
                // Continue calling this function for all the folders
674
 
                $deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION:
675
 
                foreach ($deep_items as $item) {
676
 
                    array_push($all, $this_folder . $item);
677
 
                }
678
 
            }
679
 
        }
680
 
    }
681
 
    
682
 
    if($folder) chdir($current_folder);
683
 
    return $all;
684
 
}
685
 
 
686
 
function gen_secret() {
687
 
  # Generates a random 12 character alphanumeric string to use as a salt
688
 
  mt_srand((double)microtime()*1000000);
689
 
  $key = "";
690
 
  for ($i=0; $i < 12; $i++) {
691
 
    $c = mt_rand(0,2);
692
 
    if ($c == 0) {
693
 
      $key .= chr(mt_rand(65,90));
694
 
    }
695
 
    elseif ($c == 1) {
696
 
      $key .= chr(mt_rand(97,122));
697
 
    }
698
 
    else {
699
 
      $key .= chr(mt_rand(48,57));
700
 
    }
701
 
  } 
702
 
  
703
 
  return $key;
704
 
}
705
 
 
706
 
function checkPHP() 
707
 
{
708
 
        return (version_compare("5.2.4",phpversion(), "<="));
709
 
}
710
 
 
711
 
function CheckGettext() 
712
 
{
713
 
        return extension_loaded("gettext");
714
 
}
715
 
 
716
 
// Setup the translations for gettext
717
 
function __($string)
718
 
{
719
 
        if (CheckGettext())
720
 
        {
721
 
                return _($string);
722
 
        }
723
 
        else
724
 
        {
725
 
                return $string;
726
 
        }
727
 
}
728
 
 
729
 
function settings_strings() {
730
 
global $settings_header;
731
 
global $settings_footer;
732
 
 
733
 
  $settings_header = <<<END
734
 
<?php
735
 
 
736
 
/*
737
 
 * Xibo - Digital Signage - http://www.xibo.org.uk
738
 
 *
739
 
 * This file is part of Xibo - and is automatically generated by the installer
740
 
 *
741
 
 * You should not need to edit this file, unless your SQL connection details have changed.
742
 
 */
743
 
 
744
 
defined('XIBO') or die(__("Sorry, you are not allowed to directly access this page.") . "<br />" . __("Please press the back button in your browser."));
745
 
 
746
 
global \$dbhost;
747
 
global \$dbuser;
748
 
global \$dbpass;
749
 
global \$dbname;
750
 
 
751
 
 
752
 
END;
753
 
 
754
 
$settings_footer = <<<END
755
 
?>
756
 
END;
757
 
 
758
 
  return;
759
 
}
 
304
          $sqlStatementCount++;
 
305
          flush();
 
306
          if (! @mysql_query($sql,$db)) {
 
307
            reportError("4", __("An error occured populating the database.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error() . "<br /><br />SQL executed:<br />" . $sql . "<br /><br />Statement number: " . $sqlStatementCount);
 
308
          }
 
309
        }
 
310
        print "</p>";
 
311
    }
 
312
    @mysql_close($db);
 
313
  }
 
314
  # Write out a new settings.php
 
315
  $fh = fopen("settings.php", 'wt');
 
316
  
 
317
  if (! $fh) {
 
318
    reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
 
319
  }
 
320
  
 
321
  settings_strings();
 
322
  
 
323
  $settings_content = '$dbhost = \'' . $db_host . '\';' . "\n";
 
324
  $settings_content .= '$dbuser = \'' . $db_user . '\';' . "\n";
 
325
  $settings_content .= '$dbpass = \'' . $db_pass . '\';' . "\n";
 
326
  $settings_content .= '$dbname = \'' . $db_name . '\';' . "\n\n";
 
327
  $settings_content .= 'define(\'SECRET_KEY\',\'' . gen_secret() . '\');' . "\n";
 
328
  
 
329
  if (! fwrite($fh, $settings_header . $settings_content . $settings_footer)) {
 
330
    reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
 
331
  }
 
332
    
 
333
  fclose($fh);
 
334
  
 
335
  ?>
 
336
  </div>
 
337
  <div class="install_table">
 
338
    <form action="install.php" method="POST">
 
339
      <input type="hidden" name="xibo_step" value="6" />
 
340
  </div>
 
341
    <button type="submit"><?php echo __("Next"); ?> ></button>
 
342
  </form>
 
343
  <?php
 
344
}
 
345
elseif ($xibo_step == 6) {
 
346
  # Form to get new admin password
 
347
  ?>
 
348
  <div class="info">
 
349
  <p><?php echo __("Xibo needs to set the \"xibo_admin\" user password. Please enter a password for this account below."); ?></p>
 
350
  </div>
 
351
  <div class="install_table">
 
352
    <form action="install.php" method="POST">
 
353
      <input type="hidden" name="xibo_step" value="7" />
 
354
      <p><label for="password1"><?php echo __("Password:"); ?>&nbsp;</label><input type="password" name="password1" size="12" /></p>
 
355
      <p><label for="password2"><?php echo __("Retype Password:"); ?>&nbsp;</label><input type="password" name="password2" size="12" /></p>
 
356
  </div>
 
357
    <button type="submit"><?php echo __("Next"); ?> ></button>
 
358
  </form>
 
359
  <?php
 
360
}
 
361
elseif ($xibo_step == 7) {
 
362
  # Setup xibo_admin password
 
363
  $password1 = Kit::GetParam('password1',_POST,_PASSWORD);
 
364
  $password2 = Kit::GetParam('password2',_POST,_PASSWORD);
 
365
  
 
366
  if (!(($password1 && $password2) && ($password1 == $password2))) {
 
367
    reportError("6", __("Please input a new password. Ensure both password fields are identical."));
 
368
  }
 
369
  
 
370
  include('settings.php');
 
371
  
 
372
  $password_hash = md5($password1);
 
373
  
 
374
  $db = @mysql_connect($dbhost,$dbuser,$dbpass);
 
375
      
 
376
    if (! $db) {
 
377
      reportError("6", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
 
378
    }
 
379
      
 
380
    @mysql_select_db($dbname,$db);
 
381
 
 
382
    $SQL = sprintf("UPDATE `user` SET UserPassword = '%s' WHERE UserID = 1 LIMIT 1",
 
383
                    mysql_real_escape_string($password_hash));
 
384
    if (! @mysql_query($SQL, $db)) {
 
385
      reportError("6", __("An error occured changing the xibo_admin password.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
 
386
    }
 
387
 
 
388
    @mysql_close($db);
 
389
    
 
390
    ?>
 
391
    <div class="info">
 
392
      <?php echo __("Successfully changed the xibo_admin password. We're nearly there now. Just a couple more steps!"); ?>
 
393
    </div>
 
394
    <form action="install.php" method="POST">
 
395
      <input type="hidden" name="xibo_step" value="8" />
 
396
      <button type="submit"><?php echo __("Next"); ?> ></button>
 
397
    </form>
 
398
    <?php
 
399
}
 
400
elseif ($xibo_step == 8) {
 
401
  # Configure paths and keys
 
402
  ## nuSoap
 
403
  ## libraries
 
404
  ## server_key
 
405
  ?>
 
406
  <div class="info">
 
407
    <p><b><?php echo __("Library Location"); ?></b></p>
 
408
    <p><?php echo __("Xibo needs somewhere to store the things you upload to be shown. Ideally, this should be somewhere outside the root of your webserver - that is such that is not accessible by a web browser. Please input the full path to this folder. If the folder does not already exist, Xibo will attempt to create it for you."); ?></p>
 
409
    <form action="install.php" method="POST">
 
410
    <div class="install_table">
 
411
       <p><label for="library_location"><?php echo __("Library Location:"); ?>&nbsp;</label><input type="text" name="library_location" value="" /></p>
 
412
    </div>
 
413
    <p><b><?php echo __("Server Key"); ?></b></p>
 
414
    <p><?php echo __("Xibo needs you to choose a \"key\". This will be required each time you setup a new client. It should be complicated, and hard to remember. It is visible in the admin interface, so it need not be written down separately."); ?></p>
 
415
    <div class="install_table">
 
416
      <p><label for="server_key"><?php echo __("Server Key:"); ?> </label><input type="text" name="server_key" value="" /></p>
 
417
    </div>
 
418
    <p><b><?php echo __("Statistics"); ?></b></p>
 
419
    <p><?php echo __("We'd love to know you're running Xibo. If you're happy for us to collect anonymous statistics (version number, number of displays) then please leave the box ticked. Please untick the box if your server does not have direct access to the internet."); ?></p>
 
420
    <div class="install_table">
 
421
      <p><label for="stats"><?php echo __("Anonymous Statistics:"); ?>&nbsp;</label><input type="checkbox" name="stats" value="true" checked /></p>
 
422
    </div>
 
423
      <input type="hidden" name="xibo_step" value="9" />
 
424
    </div>
 
425
      <button type="submit"><?php echo __("Next"); ?> ></button>
 
426
    </form>
 
427
  <?php
 
428
}
 
429
elseif ($xibo_step == 9) {
 
430
 
 
431
  $server_key = Kit::GetParam('server_key',_POST,_WORD);
 
432
  $library_location = Kit::GetParam('library_location',_POST,_STRING);
 
433
  $stats = Kit::GetParam('stats',_POST,_BOOL);
 
434
  
 
435
  // Remove trailing whitespace from the path given.
 
436
  $library_location = trim($library_location);
 
437
 
 
438
  // Check both fields were completed
 
439
  if (! ($server_key && $library_location)) {
 
440
    reportError("8", __("A field was blank. Please make sure you complete all fields"));
 
441
  }
 
442
 
 
443
  if ($stats) {
 
444
    $stats="On"; // Fixme: translate ?
 
445
  }
 
446
  else {
 
447
    $stats="Off"; //Fixme : translate ?
 
448
  }
 
449
 
 
450
  // Does library_location exist already?
 
451
  if (! is_dir($library_location)) {
 
452
    if (is_file($library_location)) {
 
453
      reportError("8", __("A file exists with the name you gave for the Library Location. Please choose another location"));
 
454
    }
 
455
 
 
456
    // Directory does not exist. Attempt to make it
 
457
    // Using mkdir recursively, so it will attempt to make any
 
458
    // intermediate folders required.
 
459
    if (! mkdir($library_location,0755,true)) {
 
460
      reportError("8", __("Could not create the Library Location directory for you. Please ensure the webserver has permission to create a folder in this location, or create the folder manually and grant permission for the webserver to write to the folder."));
 
461
    }
 
462
    
 
463
  }
 
464
  
 
465
  // Is library_location writable?
 
466
  if (! is_writable($library_location)) {
 
467
    // Directory is not writable.
 
468
    reportError("8", __("The Library Location you gave is not writable by the webserver. Please fix the permissions and try again."));
 
469
  }
 
470
  
 
471
  // Is library_location empty?
 
472
  if (count(ls("*",$library_location,true)) > 0) {
 
473
    reportError("8", __("The Library Location you gave is not empty. Please give the location of an empty folder"));
 
474
  }
 
475
  
 
476
  // Check if the user has added a trailing slash.
 
477
  // If not, add one.
 
478
  if (!((substr($library_location, -1) == '/') || (substr($library_location, -1) == '\\'))) {
 
479
    $library_location = $library_location . '/';
 
480
  }
 
481
 
 
482
  include('settings.php');
 
483
  
 
484
  $db = @mysql_connect($dbhost,$dbuser,$dbpass);
 
485
      
 
486
    if (! $db) {
 
487
      reportError("8", __("Could not connect to MySQL with the Xibo User account details saved in settings.php. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
 
488
    }
 
489
      
 
490
    @mysql_select_db($dbname,$db);
 
491
    
 
492
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'LIBRARY_LOCATION' LIMIT 1",
 
493
                    mysql_real_escape_string($library_location));
 
494
    if (! @mysql_query($SQL, $db)) {
 
495
      reportError("8", __("An error occured changing the library location.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
 
496
    }
 
497
    
 
498
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'SERVER_KEY' LIMIT 1",
 
499
                      mysql_real_escape_string($server_key));
 
500
    if (! @mysql_query($SQL, $db)) {
 
501
      reportError("8", __("An error occured changing the server key.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
 
502
    }
 
503
    
 
504
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'defaultTimezone' LIMIT 1",
 
505
                      mysql_real_escape_string(date_default_timezone_get()));
 
506
    if (! @mysql_query($SQL, $db)) {
 
507
      reportError("8", __("An error occured setting the default timezone.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());    
 
508
    }
 
509
 
 
510
    $SQL = sprintf("UPDATE `setting` SET `value` = '%s' WHERE `setting`.`setting` = 'PHONE_HOME' LIMIT 1",
 
511
                      mysql_real_escape_string($stats));
 
512
    if (! @mysql_query($SQL, $db)) {
 
513
      reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
 
514
    }
 
515
    $SQL = "UPDATE `setting` SET `value` = '" . md5(uniqid(rand(), true)) . "' WHERE `setting`.`setting` = 'PHONE_HOME_KEY' LIMIT 1";
 
516
    if (! @mysql_query($SQL, $db)) {
 
517
      reportError("8", __("An error occured setting anonymous statistics.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
 
518
    }
 
519
    
 
520
    @mysql_close($db);
 
521
  
 
522
  ?>
 
523
  <div class="info">
 
524
    <p><?php echo __("Successfully set library location and server key."); ?></p>
 
525
  </div>
 
526
    <form action="install.php" method="POST">
 
527
      <input type="hidden" name="xibo_step" value="10" />
 
528
      <button type="submit"><?php echo __("Next"); ?> ></button>
 
529
    </form>
 
530
  <?php
 
531
}
 
532
elseif ($xibo_step == 10) {
 
533
# Delete install.php
 
534
# Redirect to login page.
 
535
  if (! unlink('install.php')) {
 
536
    reportError("10", __("Unable to delete install.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
 
537
  }
 
538
  if (! unlink('upgrade.php')) {
 
539
    reportError("10", __("Unable to delete upgrade.php. Please ensure the webserver has permission to unlink this file and retry"), __("Retry")); // Fixme : translate "Retry" ?
 
540
  }
 
541
  ?>
 
542
  <div class="info">
 
543
    <p><b><?php echo __("Xibo was successfully installed."); ?></b></p>
 
544
    <p><?php echo __("Please click"); ?>&nbsp;<a href="index.php"><?php echo __("here"); ?></a>&nbsp;<?php echo __("to logon to Xibo as \"xibo_admin\" with the password you chose earlier."); ?></p>
 
545
  </div>
 
546
  <?php
 
547
}
 
548
else {
 
549
  reportError("0", __("A required parameter was missing. Please go through the installer sequentially!"), __("Start Again")); // Fixme : translate "Start Again" ?
 
550
}
 
551
 
 
552
include('install/footer.inc');
 
553
 
 
554
# Functions
 
555
function checkFsPermissions() {
 
556
  # Check for appropriate filesystem permissions
 
557
  return ((is_writable("install.php") && (is_writable("settings.php")) && (is_writable("upgrade.php")) || is_writable(".")));
 
558
}
 
559
 
 
560
function checkMySQL() {
 
561
  # Check PHP has MySQL module installed
 
562
  return extension_loaded("mysql");
 
563
}
 
564
 
 
565
function checkJson() {
 
566
  # Check PHP has JSON module installed
 
567
  return extension_loaded("json");
 
568
}
 
569
 
 
570
function checkGd() {
 
571
  # Check PHP has JSON module installed
 
572
  return extension_loaded("gd");
 
573
}
 
574
 
 
575
function checkCal() {
 
576
  # Check PHP has JSON module installed
 
577
  return extension_loaded("calendar");
 
578
}
 
579
 
 
580
function reportError($step, $message, $button_text="&lt; Back") { // fixme : translate ?
 
581
?>
 
582
    <div class="info">
 
583
      <?php print $message; ?>
 
584
    </div>
 
585
    <form action="install.php" method="POST">
 
586
      <input type="hidden" name="xibo_step" value="<?php print $step; ?>"/>
 
587
      <button type="submit"><?php print $button_text; ?></button>
 
588
    </form>
 
589
  <?php
 
590
  include('install/footer.inc');
 
591
  die();
 
592
 
593
 
 
594
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
 
595
// By Crackster 
 
596
/**
 
597
 * remove_remarks will strip the sql comment lines out of an uploaded sql file
 
598
 */
 
599
function remove_remarks($sql){
 
600
  $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
 
601
  $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
 
602
  return $sql;
 
603
}
 
604
 
 
605
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
 
606
// By Crackster              
 
607
/**
 
608
 * split_sql_file will split an uploaded sql file into single sql statements.
 
609
 * Note: expects trim() to have already been run on $sql.
 
610
 */
 
611
function split_sql_file($sql, $delimiter){
 
612
  $sql = str_replace("\r" , '', $sql);
 
613
  $data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
 
614
  $data = array_map('trim', $data);
 
615
  // The empty case
 
616
  $end_data = end($data);
 
617
  if (empty($end_data))
 
618
  {
 
619
    unset($data[key($data)]);
 
620
  }
 
621
  return $data;
 
622
}
 
623
 
 
624
/**
 
625
 * This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of 
 
626
 *               all files in that folder.
 
627
 * Link             : http://www.bin-co.com/php/scripts/filesystem/ls/
 
628
 * License      : BSD
 
629
 * Arguments     :  $pattern - The pattern to look out for [OPTIONAL]
 
630
 *                    $folder - The path of the directory of which's directory list you want [OPTIONAL]
 
631
 *                    $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL]
 
632
 *                    $options - An array of values 'return_files' or 'return_folders' or both
 
633
 * Returns       : A flat list with the path of all the files(no folders) that matches the condition given.
 
634
 */
 
635
function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) {
 
636
    if($folder) {
 
637
        $current_folder = realpath('.');
 
638
        if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error
 
639
            if(!file_exists($folder)) return array();
 
640
        }
 
641
        
 
642
        if(!chdir($folder)) return array();
 
643
    }
 
644
    
 
645
    
 
646
    $get_files    = in_array('return_files', $options);
 
647
    $get_folders= in_array('return_folders', $options);
 
648
    $both = array();
 
649
    $folders = array();
 
650
    
 
651
    // Get the all files and folders in the given directory.
 
652
    if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK);
 
653
    if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK);
 
654
    
 
655
    //If a pattern is specified, make sure even the folders match that pattern.
 
656
    $matching_folders = array();
 
657
    if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK);
 
658
    
 
659
    //Get just the files by removing the folders from the list of all files.
 
660
    $all = array_values(array_diff($both,$folders));
 
661
        
 
662
    if($recursivly or $get_folders) {
 
663
        foreach ($folders as $this_folder) {
 
664
            if($get_folders) {
 
665
                //If a pattern is specified, make sure even the folders match that pattern.
 
666
                if($pattern !== '*') {
 
667
                    if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder);
 
668
                }
 
669
                else array_push($all, $this_folder);
 
670
            }
 
671
            
 
672
            if($recursivly) {
 
673
                // Continue calling this function for all the folders
 
674
                $deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION:
 
675
                foreach ($deep_items as $item) {
 
676
                    array_push($all, $this_folder . $item);
 
677
                }
 
678
            }
 
679
        }
 
680
    }
 
681
    
 
682
    if($folder) chdir($current_folder);
 
683
    return $all;
 
684
}
 
685
 
 
686
function gen_secret() {
 
687
  # Generates a random 12 character alphanumeric string to use as a salt
 
688
  mt_srand((double)microtime()*1000000);
 
689
  $key = "";
 
690
  for ($i=0; $i < 12; $i++) {
 
691
    $c = mt_rand(0,2);
 
692
    if ($c == 0) {
 
693
      $key .= chr(mt_rand(65,90));
 
694
    }
 
695
    elseif ($c == 1) {
 
696
      $key .= chr(mt_rand(97,122));
 
697
    }
 
698
    else {
 
699
      $key .= chr(mt_rand(48,57));
 
700
    }
 
701
  } 
 
702
  
 
703
  return $key;
 
704
}
 
705
 
 
706
function checkPHP() 
 
707
{
 
708
        return (version_compare("5.2.4",phpversion(), "<="));
 
709
}
 
710
 
 
711
function CheckGettext() 
 
712
{
 
713
        return extension_loaded("gettext");
 
714
}
 
715
 
 
716
// Setup the translations for gettext
 
717
function __($string)
 
718
{
 
719
        if (CheckGettext())
 
720
        {
 
721
                return _($string);
 
722
        }
 
723
        else
 
724
        {
 
725
                return $string;
 
726
        }
 
727
}
 
728
 
 
729
function settings_strings() {
 
730
global $settings_header;
 
731
global $settings_footer;
 
732
 
 
733
  $settings_header = <<<END
 
734
<?php
 
735
 
 
736
/*
 
737
 * Xibo - Digital Signage - http://www.xibo.org.uk
 
738
 *
 
739
 * This file is part of Xibo - and is automatically generated by the installer
 
740
 *
 
741
 * You should not need to edit this file, unless your SQL connection details have changed.
 
742
 */
 
743
 
 
744
defined('XIBO') or die(__("Sorry, you are not allowed to directly access this page.") . "<br />" . __("Please press the back button in your browser."));
 
745
 
 
746
global \$dbhost;
 
747
global \$dbuser;
 
748
global \$dbpass;
 
749
global \$dbname;
 
750
 
 
751
 
 
752
END;
 
753
 
 
754
$settings_footer = <<<END
 
755
?>
 
756
END;
 
757
 
 
758
  return;
 
759
}
760
760
?>
 
 
b'\\ No newline at end of file'