3
* Xibo - Digitial Signage - http://www.xibo.org.uk
4
* Copyright (C) 2009 Alex Harrington
6
* This file is part of Xibo.
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
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.
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/>.
25
die('Xibo requires PHP 5.2.4 or later');
28
include('lib/app/kit.class.php');
29
include('install/header.inc');
30
include('config/config.class.php');
31
include('config/db_config.php');
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.
43
$langs = explode(',', $langs);
48
putenv('LANG='.$lang.'.'.$encoding);
49
putenv('LANGUAGE='.$lang.'.'.$encoding);
50
putenv('LC_ALL='.$lang.'.'.$encoding);
53
setlocale(LC_ALL, $lang.'.'.$encoding);
55
// Translations have been setup.
59
$xibo_step = Kit::GetParam('xibo_step',_POST,_INT,'0');
61
if (!isset($xibo_step) || $xibo_step == 0) {
62
# First step of the process.
63
# Show a welcome screen and next button
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>
74
elseif ($xibo_step == 1) {
77
$cObj = new Config($db);
79
<p><?php echo __("First we need to check if your server meets Xibo's requirements."); ?></p>
82
echo $cObj->CheckEnvironment();
83
if ($cObj->EnvironmentFault()) {
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>
91
else if ($cObj->EnvironmentWarning()) {
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>
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>
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>
112
elseif ($xibo_step == 2) {
114
## Does database exist already?
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>
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>
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>
132
elseif ($xibo_step == 3) {
133
## If not, gather admin password and use to create empty db and new user.
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:"); ?> </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:"); ?> </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:"); ?> </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:"); ?> </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:"); ?> </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:"); ?> </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
150
<button type="submit"><?php echo __("Create"); ?></button>
154
elseif ($xibo_step == 4) {
155
## Get details of db that's been created already for us
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:"); ?> </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:"); ?> </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:"); ?> </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:"); ?> </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
169
<button type="submit"><?php echo __("Create"); ?></button>
173
elseif ($xibo_step == 5) {
175
$db_create = Kit::GetParam('db_create',_POST,_STRING);
177
if (!isset($db_create)) {
178
reportError("2",__("Something went wrong"));
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);
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);
192
if (! ($db_host && $db_name && $db_user && $db_pass && $db_admin_user && $db_admin_pass)) {
193
# Something was blank.
195
reportError("3", __("A field was blank. Please fill in all fields."));
198
$db = @mysql_connect($db_host,$db_admin_user,$db_admin_pass);
201
reportError("3", __("Could not connect to MySQL with the administrator details. Please check and try again.") . "<br /><br />" . __("MySQL Error:") . "<br />" . mysql_error());
205
<p><?php echo __("Creating new database."); ?></p>
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());
216
# Choose the MySQL DB to create a user
217
@mysql_select_db("mysql", $db);
219
# Make $db_host lowercase so it matches "localhost" if required.
220
$db_host = strtolower($db_host);
223
<p><?php echo __("Creating new user"); ?></p>
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));
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));
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());
245
@mysql_query("FLUSH PRIVILEGES", $db);
250
if (! ($db_host && $db_name && $db_user && $db_pass)) {
251
# Something was blank
253
reportError("4", __("A field was blank. Please fill in all fields.") . " " . $db_host . " " . $db_name . " " . $db_user . " " . $db_pass);
258
$db = @mysql_connect($db_host,$db_user,$db_pass);
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());
264
@mysql_select_db($db_name,$db);
267
<p>Populating the database</p>
3
* Xibo - Digitial Signage - http://www.xibo.org.uk
4
* Copyright (C) 2009 Alex Harrington
6
* This file is part of Xibo.
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
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.
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/>.
24
include('lib/app/kit.class.php');
25
include('install/header.inc');
29
$xibo_step = Kit::GetParam('xibo_step',_POST,_INT,'0');
31
if (!isset($xibo_step) || $xibo_step == 0) {
32
# First step of the process.
33
# Show a welcome screen and next button
35
Welcome to the Xibo Installer!<br /><br />
36
The installer will take you through setting up Xibo one step at a time.<br /><br />
37
Lets get started!<br /><br />
38
<form action="install.php" method="POST">
39
<input type="hidden" name="xibo_step" value="1" />
40
<div class="loginbutton"><button type="submit">Next ></button></div>
44
elseif ($xibo_step == 1) {
47
<p>First we need to check if your server meets Xibo's requirements.</p>
50
## Filesystem Permissions
51
if (checkFsPermissions()) {
53
<img src="install/dot_green.gif"> Filesystem Permissions<br />
59
<img src="install/dot_red.gif"> Filesystem Permissions</br>
60
<div class="check_explain">
61
Xibo needs to be able to write to the following
66
Please fix this, and retest.<br />
73
<img src="install/dot_green.gif"> PHP Version<br />
79
<img src="install/dot_red.gif"> PHP Version<br />
80
<div class="check_explain">
81
Xibo requires PHP version 5 or later.<br />
82
Please fix this, and retest.<br />
89
<img src="install/dot_green.gif"> PHP MySQL Extension<br />
95
<img src="install/dot_red.gif"> PHP MySQL Extension<br />
96
<div class="check_explain">
97
Xibo needs to access a MySQL database to function.<br />
98
Please install MySQL and the appropriate MySQL extension and retest.<br />
105
<img src="install/dot_green.gif"> PHP JSON Extension<br />
111
<img src="install/dot_red.gif"> PHP JSON Extension<br />
112
<div class="check_explain">
113
Xibo needs the PHP JSON extension to function.<br />
114
Please install the PHP JSON extension and retest.<br />
124
<form action="install.php" method="POST">
125
<input type="hidden" name="xibo_step" value="1" />
126
<div class="loginbutton"><button type="submit">Retest</button></div>
132
<form action="install.php" method="POST">
133
<input type="hidden" name="xibo_step" value="2" />
134
<div class="loginbutton"><button type="submit">Next ></button></div>
139
elseif ($xibo_step == 2) {
141
## Does database exist already?
145
<p>Xibo needs to setup a new database.</p>
146
<p>If you have not yet created an empty database and database user for
147
Xibo to use, and know the username/password of a MySQL administrator,
148
click the "Create New" button, otherwise click "Use Existing".</p>
149
<p><i>Note that any existing database must be empty</i></p>
151
<form action="install.php" method="POST">
152
<input type="hidden" name="xibo_step" value="3" />
153
<button type="submit">Create New</button>
155
<form action="install.php" method="POST">
156
<input type="hidden" name="xibo_step" value="4" />
157
<button type="submit">Use Existing</button>
161
elseif ($xibo_step == 3) {
162
## If not, gather admin password and use to create empty db and new user.
165
<p>Since no empty database has been created for Xibo to use, we need the username
166
and password of a MySQL administrator to create a new database, and database
168
<p>Additionally, please give us a new username and password to create in MySQL
169
for Xibo to use. Xibo will create this automatically for you.</p>
170
<form action="install.php" method="POST">
171
<input type="hidden" name="xibo_step" value="5" />
172
<input type="hidden" name="db_create" value="true" />
173
<div class="install_table">
174
<p><label for="host">Host: </label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
175
<p><label for="admin_username">Admin Username: </label><input class="username" type="text" id="admin_username" name="admin_username" size="12" /></p>
176
<p><label for="admin_password">Admin Password: </label><input class="username" type="password" id="admin_password" name="admin_password" size="12" /></p>
177
<p><label for="db_name">Xibo Database Name: </label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
178
<p><label for="db_username">Xibo Database Username: </label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
179
<p><label for="db_password">Xibo Database Password: </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
182
<button type="submit">Create</button>
186
elseif ($xibo_step == 4) {
187
## Get details of db that's been created already for us
190
<p>Please enter the details of the database and user you have
191
created for Xibo.</p>
192
<form action="install.php" method="POST">
193
<input type="hidden" name="xibo_step" value="5" />
194
<input type="hidden" name="db_create" value="false" />
195
<div class="install_table">
196
<p><label for="host">Host: </label><input class="username" type="text" id="host" name="host" size="12" value="localhost" /></p>
197
<p><label for="db_name">Xibo Database Name: </label><input class="username" type="text" id="db_name" name="db_name" size="12" value="xibo" /></p>
198
<p><label for="db_username">Xibo Database Username: </label><input class="username" type="text" id="db_username" name="db_username" size="12" value="xibo" /></p>
199
<p><label for="db_password">Xibo Database Password: </label><input class="username" type="password" id="db_password" name="db_password" size="12" /></p>
202
<button type="submit">Create</button>
206
elseif ($xibo_step == 5) {
208
$db_create = Kit::GetParam('db_create',_POST,_BOOL);
210
if (!isset($db_create)) {
211
reportError("2","Something went wrong");
214
$db_host = Kit::GetParam('host',_POST,_STRING,'localhost');
215
$db_user = Kit::GetParam('db_username',_POST,_USERNAME);
216
$db_pass = Kit::GetParam('db_password',_POST,_PASSWORD);
217
$db_name = Kit::GetParam('db_name',_POST,_USERNAME);
221
if ($db_create == true) {
222
$db_admin_user = Kit::GetParam('admin_username',_POST,_USERNAME);
223
$db_admin_pass = Kit::GetParam('admin_password',_POST,_PASSWORD);
225
if (! ($db_host && $db_name && $db_user && $db_pass && $db_admin_user && $db_admin_pass)) {
226
# Something was blank.
228
reportError("3", "A field was blank. Please fill in all fields.");
231
$db = @mysql_connect($db_host,$db_admin_user,$db_admin_pass);
234
reportError("3", "Could not connect to MySQL with the administrator details. Please check and try again.<br /><br />MySQL Error:<br />" . mysql_error());
238
<p>Creating new database.</p>
242
if (! @mysql_query("CREATE DATABASE " . $db_name, $db)) {
243
# Create database and user
244
reportError("3", "Could not create a new database with the administrator details. Please check and try again.<br /><br />MySQL Error:<br />" . mysql_error());
247
# Choose the MySQL DB to create a user
248
@mysql_select_db("mysql", $db);
250
# Make $db_host lowercase so it matches "localhost" if required.
251
$db_host = strtolower($db_host);
254
<p>Creating new user</p>
258
if ($db_host == "localhost") {
259
if (! @mysql_query("GRANT ALL PRIVILEGES ON " . $db_name . ".* to '" . $db_user . "'@'localhost' IDENTIFIED BY '" . $db_pass . "'", $db)) {
260
reportError("3", "Could not create a new user with the administrator details. Please check and try again.<br /><br />MySQL Error:<br />" . mysql_error());
264
if (! @mysql_query("GRANT ALL PRIVILEGES ON " . $db_name . ".* to '" . $db_user . "'@'%' IDENTIFIED BY '" . $db_pass . "'", $db)) {
265
reportError("3", "Could not create a new user with the administrator details. Please check and try again.<br /><br />MySQL Error:<br />" . mysql_error());
270
@mysql_query("FLUSH PRIVILEGES", $db);
275
if (! ($db_host && $db_name && $db_user && $db_pass)) {
276
# Something was blank
278
reportError("4", "A field was blank. Please fill in all fields.");
283
$db = @mysql_connect($db_host,$db_user,$db_pass);
286
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());
289
@mysql_select_db($db_name,$db);
292
<p>Populating the database</p>
271
296
# Load from sql files to db - HOW?
272
297
$sql_files = ls('*.sql','install/database',false,array('return_files'));
274
// Sort the files in to sensible order, ie
285
// NB this is broken for 0 padded files
286
// eg 01.sql would be incorrectly sorted in the above example.
288
$sqlStatementCount = 0;
289
natcasesort($sql_files);
291
foreach ($sql_files as $filename) {
293
<p>Loading from <?php print $filename; ?>
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);
302
foreach ($sql_file as $sql) {
304
$sqlStatementCount++;
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);
299
// Sort the files in to sensible order, ie
310
// NB this is broken for 0 padded files
311
// eg 01.sql would be incorrectly sorted in the above example.
313
natcasesort($sql_files);
315
foreach ($sql_files as $filename) {
317
<p>Loading from <?php print $filename; ?>
322
$sql_file = @file_get_contents('install/database/' . $filename);
323
$sql_file = remove_remarks($sql_file);
324
$sql_file = split_sql_file($sql_file, $delimiter);
326
foreach ($sql_file as $sql) {
329
if (! @mysql_query($sql,$db)) {
330
reportError("4", "An error occured populating the database.<br /><br />MySQL Error:<br />" . mysql_error());
314
# Write out a new settings.php
315
$fh = fopen("settings.php", 'wt');
318
reportError("0", __("Unable to write to settings.php. We already checked this was possible earlier, so something changed."));
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";
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."));
337
<div class="install_table">
338
<form action="install.php" method="POST">
339
<input type="hidden" name="xibo_step" value="6" />
341
<button type="submit"><?php echo __("Next"); ?> ></button>
345
elseif ($xibo_step == 6) {
346
# Form to get new admin password
349
<p><?php echo __("Xibo needs to set the \"xibo_admin\" user password. Please enter a password for this account below."); ?></p>
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:"); ?> </label><input type="password" name="password1" size="12" /></p>
355
<p><label for="password2"><?php echo __("Retype Password:"); ?> </label><input type="password" name="password2" size="12" /></p>
357
<button type="submit"><?php echo __("Next"); ?> ></button>
361
elseif ($xibo_step == 7) {
362
# Setup xibo_admin password
363
$password1 = Kit::GetParam('password1',_POST,_PASSWORD);
364
$password2 = Kit::GetParam('password2',_POST,_PASSWORD);
366
if (!(($password1 && $password2) && ($password1 == $password2))) {
367
reportError("6", __("Please input a new password. Ensure both password fields are identical."));
370
include('settings.php');
372
$password_hash = md5($password1);
374
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
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());
380
@mysql_select_db($dbname,$db);
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());
392
<?php echo __("Successfully changed the xibo_admin password. We're nearly there now. Just a couple more steps!"); ?>
394
<form action="install.php" method="POST">
395
<input type="hidden" name="xibo_step" value="8" />
396
<button type="submit"><?php echo __("Next"); ?> ></button>
400
elseif ($xibo_step == 8) {
401
# Configure paths and keys
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:"); ?> </label><input type="text" name="library_location" value="" /></p>
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>
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:"); ?> </label><input type="checkbox" name="stats" value="true" checked /></p>
423
<input type="hidden" name="xibo_step" value="9" />
425
<button type="submit"><?php echo __("Next"); ?> ></button>
429
elseif ($xibo_step == 9) {
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);
435
// Remove trailing whitespace from the path given.
436
$library_location = trim($library_location);
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"));
444
$stats="On"; // Fixme: translate ?
447
$stats="Off"; //Fixme : translate ?
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"));
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."));
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."));
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"));
476
// Check if the user has added a trailing slash.
478
if (!((substr($library_location, -1) == '/') || (substr($library_location, -1) == '\\'))) {
479
$library_location = $library_location . '/';
482
include('settings.php');
484
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
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());
490
@mysql_select_db($dbname,$db);
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());
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());
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());
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());
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());
524
<p><?php echo __("Successfully set library location and server key."); ?></p>
526
<form action="install.php" method="POST">
527
<input type="hidden" name="xibo_step" value="10" />
528
<button type="submit"><?php echo __("Next"); ?> ></button>
532
elseif ($xibo_step == 10) {
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" ?
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" ?
543
<p><b><?php echo __("Xibo was successfully installed."); ?></b></p>
544
<p><?php echo __("Please click"); ?> <a href="index.php"><?php echo __("here"); ?></a> <?php echo __("to logon to Xibo as \"xibo_admin\" with the password you chose earlier."); ?></p>
549
reportError("0", __("A required parameter was missing. Please go through the installer sequentially!"), __("Start Again")); // Fixme : translate "Start Again" ?
552
include('install/footer.inc');
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(".")));
560
function checkMySQL() {
561
# Check PHP has MySQL module installed
562
return extension_loaded("mysql");
565
function checkJson() {
566
# Check PHP has JSON module installed
567
return extension_loaded("json");
571
# Check PHP has JSON module installed
572
return extension_loaded("gd");
575
function checkCal() {
576
# Check PHP has JSON module installed
577
return extension_loaded("calendar");
580
function reportError($step, $message, $button_text="< Back") { // fixme : translate ?
583
<?php print $message; ?>
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>
590
include('install/footer.inc');
594
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
597
* remove_remarks will strip the sql comment lines out of an uploaded sql file
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));
605
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
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.
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);
616
$end_data = end($data);
617
if (empty($end_data))
619
unset($data[key($data)]);
337
# Write out a new settings.php
338
$fh = fopen("settings.php", 'wt');
341
reportError("0", "Unable to write to settings.php. We already checked this was possible earlier, so something changed.");
346
$settings_content = '$dbhost = \'' . $db_host . '\';' . "\n";
347
$settings_content .= '$dbuser = \'' . $db_user . '\';' . "\n";
348
$settings_content .= '$dbpass = \'' . $db_pass . '\';' . "\n";
349
$settings_content .= '$dbname = \'' . $db_name . '\';' . "\n\n";
350
$settings_content .= 'define(\'SECRET_KEY\',\'' . gen_secret() . '\');' . "\n";
352
if (! fwrite($fh, $settings_header . $settings_content . $settings_footer)) {
353
reportError("0", "Unable to write to settings.php. We already checked this was possible earlier, so something changed.");
360
<div class="install_table">
361
<form action="install.php" method="POST">
362
<input type="hidden" name="xibo_step" value="6" />
364
<button type="submit">Next ></button>
368
elseif ($xibo_step == 6) {
369
# Form to get new admin password
372
<p>Xibo needs to set the "xibo_admin" user password. Please enter a password for this account below.</p>
374
<div class="install_table">
375
<form action="install.php" method="POST">
376
<input type="hidden" name="xibo_step" value="7" />
377
<p><label for="password1">Password: </label><input type="password" name="password1" size="12" /></p>
378
<p><label for="password2">Retype Password: </label><input type="password" name="password2" size="12" /></p>
380
<button type="submit">Next ></button>
384
elseif ($xibo_step == 7) {
385
# Setup xibo_admin password
386
$password1 = Kit::GetParam('password1',_POST,_PASSWORD);
387
$password2 = Kit::GetParam('password2',_POST,_PASSWORD);
389
if (!(($password1 && $password2) && ($password1 == $password2))) {
390
reportError("6", "Please input a new password. Ensure both password fields are identical.");
393
include('settings.php');
395
$password_hash = md5($password1);
397
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
400
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());
403
@mysql_select_db($dbname,$db);
405
if (! @mysql_query("UPDATE `user` SET UserPassword = '" . $password_hash . "' WHERE UserID = 1 LIMIT 1", $db)) {
406
reportError("6", "An error occured changing the xibo_admin password.<br /><br />MySQL Error:<br />" . mysql_error());
413
Successfully changed the xibo_admin password. We're nearly there now. Just a couple more steps!
415
<form action="install.php" method="POST">
416
<input type="hidden" name="xibo_step" value="8" />
417
<button type="submit">Next ></button>
421
elseif ($xibo_step == 8) {
422
# Configure paths and keys
428
<p>Library Location</p>
429
<p>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>
430
<form action="install.php" method="POST">
431
<div class="install_table">
432
<p><label for="library_location">Library Location: </label><input type="text" name="library_location" value="" /></p>
435
<p>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>
436
<div class="install_table">
437
<p><label for="server_key">Server Key: </label><input type="text" name="server_key" value="" /></p>
439
<input type="hidden" name="xibo_step" value="9" />
441
<button type="submit">Next ></button>
445
elseif ($xibo_step == 9) {
447
$server_key = Kit::GetParam('server_key',_POST,_WORD);
448
$library_location = Kit::GetParam('library_location',_POST,_STRING);
450
// Remove trailing whitespace from the path given.
451
$library_location = trim($library_location);
453
// Check both fields were completed
454
if (! ($server_key && $library_location)) {
455
reportError("8","A field was blank. Please make sure you complete all fields");
458
// Does library_location exist already?
459
if (! is_dir($library_location)) {
460
if (is_file($library_location)) {
461
reportError("8", "A file exists with the name you gave for the Library Location. Please choose another location");
464
// Directory does not exist. Attempt to make it
465
// Using mkdir recursively, so it will attempt to make any
466
// intermediate folders required.
467
if (! mkdir($library_location,0755,true)) {
468
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.");
473
// Is library_location writable?
474
if (! is_writable($library_location)) {
475
// Directory is not writable.
476
reportError("8","The Library Location you gave is not writable by the webserver. Please fix the permissions and try again.");
479
// Is library_location empty?
480
if (count(ls("*",$library_location,true)) > 0) {
481
reportError("8","The Library Location you gave is not empty. Please give the location of an empty folder");
484
// Check if the user has added a trailing slash.
486
if (!((substr($library_location, -1) == '/') || (substr($library_location, -1) == '\\'))) {
487
$library_location = $library_location . '/';
490
include('settings.php');
492
$db = @mysql_connect($dbhost,$dbuser,$dbpass);
495
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());
498
@mysql_select_db($dbname,$db);
500
if (! @mysql_query("UPDATE `setting` SET `value` = '" . $library_location . "' WHERE `setting`.`setting` = 'LIBRARY_LOCATION' LIMIT 1", $db)) {
501
reportError("8", "An error occured changing the library location.<br /><br />MySQL Error:<br />" . mysql_error());
504
if (! @mysql_query("UPDATE `setting` SET `value` = '" . $server_key . "' WHERE `setting`.`setting` = 'SERVER_KEY' LIMIT 1", $db)) {
505
reportError("8", "An error occured changing the server key.<br /><br />MySQL Error:<br />" . mysql_error());
512
<p>Successfully set LIBRARY_LOCATION and SERVER_KEY.</p>
514
<form action="install.php" method="POST">
515
<input type="hidden" name="xibo_step" value="10" />
516
<button type="submit">Next ></button>
520
elseif ($xibo_step == 10) {
522
# Redirect to login page.
523
if (! unlink('install.php')) {
524
reportError("10", "Unable to delete install.php. Please ensure the webserver has permission to unlink this file and retry", "Retry");
528
<p><b>Xibo was successfully installed.</b></p>
529
<p>Please click <a href="index.php">here</a> to logon to Xibo as "xibo_admin" with the password you chose earlier.</p>
534
reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again");
537
include('install/footer.inc');
541
function checkFsPermissions() {
542
# Check for appropriate filesystem permissions
543
return (is_writable("install.php") && (is_writable("settings.php") || is_writable(".")));
546
function checkPHP() {
547
# Check PHP version > 5
548
return (version_compare("5",phpversion(), "<="));
551
function checkMySQL() {
552
# Check PHP has MySQL module installed
553
return extension_loaded("mysql");
556
function checkJson() {
557
# Check PHP has JSON module installed
558
return extension_loaded("json");
561
function reportError($step, $message, $button_text="< Back") {
564
<?php print $message; ?>
566
<form action="install.php" method="POST">
567
<input type="hidden" name="xibo_step" value="<?php print $step; ?>"/>
568
<button type="submit"><?php print $button_text; ?></button>
571
include('install/footer.inc');
575
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
578
* remove_remarks will strip the sql comment lines out of an uploaded sql file
580
function remove_remarks($sql){
581
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
582
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
586
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
589
* split_sql_file will split an uploaded sql file into single sql statements.
590
* Note: expects trim() to have already been run on $sql.
592
function split_sql_file($sql, $delimiter){
593
$sql = str_replace("\r" , '', $sql);
594
$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
595
$data = array_map('trim', $data);
597
$end_data = end($data);
598
if (empty($end_data))
600
unset($data[key($data)]);
625
606
* This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of