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/>.
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/>.
22
22
DEFINE('XIBO', true);
24
24
include('lib/app/kit.class.php');
54
54
define('_INPUTBOX', "inputbox");
55
55
define('_PASSWORDBOX', "password");
57
// create a database class instance
57
// create a database class instance
60
if (!$db->connect_db($dbhost, $dbuser, $dbpass)) reportError(0, "Unable to connect to the MySQL database using the settings stored in settings.php.<br /><br />MySQL Error:<br />" . $db->error());
60
if (!$db->connect_db($dbhost, $dbuser, $dbpass)) reportError(0, "Unable to connect to the MySQL database using the settings stored in settings.php.<br /><br />MySQL Error:<br />" . $db->error());
61
61
if (!$db->select_db($dbname)) reportError(0, "Unable to select the MySQL database using the settings stored in settings.php.<br /><br />MySQL Error:<br />" . $db->error());
63
include('install/header_upgrade.inc');
63
include('install/header_upgrade.inc');
65
65
if (! $_SESSION['step']) {
66
66
$_SESSION['step'] = 0;
69
69
if (Kit::GetParam('skipstep',_POST,_INT) == 1) {
70
70
// Cheat the $_SESSION['step'] variable if required
71
71
// Used if there are environment warnings and we want to retest.
72
72
$_SESSION['step'] = 1;
75
75
if ($_SESSION['step'] == 0) {
77
$_SESSION['step'] = 1;
77
$_SESSION['step'] = 1;
79
# First step of the process.
80
# Show a welcome screen and authenticate the user
82
Welcome to the Xibo Upgrade!<br /><br />
83
The upgrade program will take you through the process one step at a time.<br /><br />
79
# First step of the process.
80
# Show a welcome screen and authenticate the user
82
Welcome to the Xibo Upgrade!<br /><br />
83
The upgrade program will take you through the process one step at a time.<br /><br />
84
84
Lets get started!<br /><br />
85
Please enter your xibo_admin password:<br /><br />
85
Please enter your xibo_admin password:<br /><br />
86
86
<form action="upgrade.php" method="POST">
87
87
<div class="install_table">
88
88
<input type="password" name="password" length="12" />
90
<div class="loginbutton"><button type="submit">Next ></button></div>
90
<div class="loginbutton"><button type="submit">Next ></button></div>
94
94
elseif ($_SESSION['step'] == 1) {
95
$_SESSION['step'] = 2;
95
$_SESSION['step'] = 2;
97
97
if (! $_SESSION['auth']) {
101
101
$password = Kit::GetParam('password',_POST,_PASSWORD);
102
$password_hash = md5($password);
104
$SQL = sprintf("SELECT `UserID` FROM `user` WHERE UserPassword='%s' AND UserName='xibo_admin'",
105
$db->escape_string($password_hash));
106
if (! $result = $db->query($SQL)) {
107
reportError("0", "An error occured checking your password.<br /><br />MySQL Error:<br />" . mysql_error());
102
$password_hash = md5($password);
104
$SQL = sprintf("SELECT `UserID` FROM `user` WHERE UserPassword='%s' AND UserName='xibo_admin'",
105
$db->escape_string($password_hash));
106
if (! $result = $db->query($SQL)) {
107
reportError("0", "An error occured checking your password.<br /><br />MySQL Error:<br />" . mysql_error());
110
110
if ($db->num_rows($result) == 0) {
111
111
$_SESSION['auth'] = false;
115
115
$_SESSION['auth'] = true;
116
116
$_SESSION['db'] = $db;
120
## Check server meets specs (as specs might have changed in this release)
122
<p>First we need to check if your server meets Xibo's requirements.</p>
124
$db = new Database();
125
$cObj = new Config($db);
126
echo $cObj->CheckEnvironment();
120
## Check server meets specs (as specs might have changed in this release)
122
<p>First we need to check if your server meets Xibo's requirements.</p>
124
$db = new Database();
125
$cObj = new Config($db);
126
echo $cObj->CheckEnvironment();
127
127
if ($cObj->EnvironmentFault()) {
128
$_SESSION['step'] = 1;
130
<form action="upgrade.php" method="POST">
131
<div class="loginbutton"><button type="submit">Retest</button></div>
128
$_SESSION['step'] = 1;
130
<form action="upgrade.php" method="POST">
131
<div class="loginbutton"><button type="submit">Retest</button></div>
135
135
else if ($cObj->EnvironmentWarning()) {
137
137
<form action="upgrade.php" method="POST">
138
<input type="hidden" name="skipstep" value="1">
139
<div class="loginbutton"><button type="submit">Retest</button></div>
141
<form action="upgrade.php" method="POST">
142
<div class="loginbutton"><button type="submit">Next ></button></div>
148
<form action="upgrade.php" method="POST">
149
<div class="loginbutton"><button type="submit">Next ></button></div>
138
<input type="hidden" name="skipstep" value="1">
139
<div class="loginbutton"><button type="submit">Retest</button></div>
141
<form action="upgrade.php" method="POST">
142
<div class="loginbutton"><button type="submit">Next ></button></div>
148
<form action="upgrade.php" method="POST">
149
<div class="loginbutton"><button type="submit">Next ></button></div>
154
154
elseif ($_SESSION['step'] == 2) {
156
# Calculate the upgrade
156
# Calculate the upgrade
158
158
$_SESSION['upgradeFrom'] = Config::Version($db, 'DBVersion');
160
160
if ($_SESSION['upgradeFrom'] < 1) {
268
268
if (file_exists('install/database/' . $i . '.sql')) {
269
269
echo '<p>' . $i . '.sql ';
272
$sql_file = @file_get_contents('install/database/' . $i . '.sql');
273
$sql_file = remove_remarks($sql_file);
274
$sql_file = split_sql_file($sql_file, $delimiter);
276
foreach ($sql_file as $sql) {
272
$sql_file = @file_get_contents('install/database/' . $i . '.sql');
273
$sql_file = remove_remarks($sql_file);
274
$sql_file = split_sql_file($sql_file, $delimiter);
276
foreach ($sql_file as $sql) {
278
$sqlStatementCount++;
278
$sqlStatementCount++;
280
280
if (! $db->query($sql)) {
282
reportError("0", "An error occured populating the database.<br /><br />MySQL Error:<br />" . $db->error() . "<br /><br />SQL executed:<br />" . $sql . "<br /><br />Statement number: " . $sqlStatementCount);
282
reportError("0", "An error occured populating the database.<br /><br />MySQL Error:<br />" . $db->error() . "<br /><br />SQL executed:<br />" . $sql . "<br /><br />Statement number: " . $sqlStatementCount);
314
314
session_destroy();
318
reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again");
321
include('install/footer.inc');
324
function checkPHP() {
325
# Check PHP version > 5
326
return (version_compare("5.1.0",phpversion(), "<="));
318
reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again");
321
include('install/footer.inc');
324
function checkPHP() {
325
# Check PHP version > 5
326
return (version_compare("5.1.0",phpversion(), "<="));
329
329
function reportError($step, $message, $button_text="< Back") {
330
$_SESSION['step'] = $step;
333
<?php print $message; ?>
335
<form action="upgrade.php" method="POST">
336
<button type="submit"><?php print $button_text; ?></button>
339
include('install/footer.inc');
330
$_SESSION['step'] = $step;
333
<?php print $message; ?>
335
<form action="upgrade.php" method="POST">
336
<button type="submit"><?php print $button_text; ?></button>
339
include('install/footer.inc');
343
343
function checkAuth() {
344
344
if (! $_SESSION['auth']) {
345
345
reportError(1, "You must authenticate to run the upgrade.");
349
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
352
* remove_remarks will strip the sql comment lines out of an uploaded sql file
354
function remove_remarks($sql){
355
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
356
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
360
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
363
* split_sql_file will split an uploaded sql file into single sql statements.
364
* Note: expects trim() to have already been run on $sql.
366
function split_sql_file($sql, $delimiter){
367
$sql = str_replace("\r" , '', $sql);
368
$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
369
$data = array_map('trim', $data);
371
$end_data = end($data);
372
if (empty($end_data))
374
unset($data[key($data)]);
349
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
352
* remove_remarks will strip the sql comment lines out of an uploaded sql file
354
function remove_remarks($sql){
355
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql));
356
$sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql));
360
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
363
* split_sql_file will split an uploaded sql file into single sql statements.
364
* Note: expects trim() to have already been run on $sql.
366
function split_sql_file($sql, $delimiter){
367
$sql = str_replace("\r" , '', $sql);
368
$data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql);
369
$data = array_map('trim', $data);
371
$end_data = end($data);
372
if (empty($end_data))
374
unset($data[key($data)]);
380
380
* This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of
509
function gen_secret() {
510
# Generates a random 12 character alphanumeric string to use as a salt
511
mt_srand((double)microtime()*1000000);
513
for ($i=0; $i < 12; $i++) {
516
$key .= chr(mt_rand(65,90));
519
$key .= chr(mt_rand(97,122));
522
$key .= chr(mt_rand(48,57));
509
function gen_secret() {
510
# Generates a random 12 character alphanumeric string to use as a salt
511
mt_srand((double)microtime()*1000000);
513
for ($i=0; $i < 12; $i++) {
516
$key .= chr(mt_rand(65,90));
519
$key .= chr(mt_rand(97,122));
522
$key .= chr(mt_rand(48,57));
529
529
function createQuestions($step, $questions) {