~dangarner/xibo/107-oggcamp2010

« back to all changes in this revision

Viewing changes to server/upgrade.php

  • Committer: Alex Harrington
  • Date: 2009-12-31 11:48:37 UTC
  • Revision ID: alex@longhill.org.uk-20091231114837-90kgz9qy4us1184v
Converted to 2.0 repo format and fixed line endings.

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
 
 
 
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
 
22
22
DEFINE('XIBO', true);
23
23
 
24
24
include('lib/app/kit.class.php');
46
46
                        }
47
47
                }
48
48
        }
49
 
}
 
49
}
50
50
 
51
51
session_start();
52
52
 
54
54
define('_INPUTBOX', "inputbox");
55
55
define('_PASSWORDBOX', "password");
56
56
 
57
 
// create a database class instance
58
 
$db = new database();
 
57
// create a database class instance
 
58
$db = new database();
59
59
 
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());
62
62
 
63
 
include('install/header_upgrade.inc');
64
 
 
 
63
include('install/header_upgrade.inc');
 
64
 
65
65
if (! $_SESSION['step']) {
66
66
        $_SESSION['step'] = 0;
67
 
}
 
67
}
68
68
 
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;
73
73
}
74
 
 
 
74
 
75
75
if ($_SESSION['step'] == 0) {
76
76
 
77
 
  $_SESSION['step'] = 1;
 
77
  $_SESSION['step'] = 1;
78
78
 
79
 
  # First step of the process.
80
 
  # Show a welcome screen and authenticate the user
81
 
  ?>
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
 
81
  ?>
 
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" />
89
 
    </div>
90
 
    <div class="loginbutton"><button type="submit">Next ></button></div>
91
 
  </form>
92
 
  <?php
93
 
}
 
89
    </div>
 
90
    <div class="loginbutton"><button type="submit">Next ></button></div>
 
91
  </form>
 
92
  <?php
 
93
}
94
94
elseif ($_SESSION['step'] == 1) {
95
 
  $_SESSION['step'] = 2;
 
95
  $_SESSION['step'] = 2;
96
96
  
97
97
  if (! $_SESSION['auth']) {
98
 
 
 
98
 
99
99
        # Check password
100
100
 
101
101
        $password = Kit::GetParam('password',_POST,_PASSWORD);
102
 
        $password_hash = md5($password);
103
 
 
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());    
108
 
        }
 
102
        $password_hash = md5($password);
 
103
 
 
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());    
 
108
        }
109
109
 
110
110
        if ($db->num_rows($result) == 0) {      
111
111
                $_SESSION['auth'] = false;
114
114
        else {
115
115
                $_SESSION['auth'] = true;
116
116
                $_SESSION['db'] = $db;
117
 
        }
 
117
        }
118
118
 
119
119
   }
120
 
## Check server meets specs (as specs might have changed in this release)
121
 
  ?>
122
 
  <p>First we need to check if your server meets Xibo's requirements.</p>
123
 
  <?php
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)
 
121
  ?>
 
122
  <p>First we need to check if your server meets Xibo's requirements.</p>
 
123
  <?php
 
124
    $db = new Database();
 
125
    $cObj = new Config($db);
 
126
    echo $cObj->CheckEnvironment();
127
127
    if ($cObj->EnvironmentFault()) {
128
 
        $_SESSION['step'] = 1;
129
 
    ?>
130
 
      <form action="upgrade.php" method="POST">
131
 
        <div class="loginbutton"><button type="submit">Retest</button></div>
132
 
      </form>
133
 
    <?php
 
128
        $_SESSION['step'] = 1;
 
129
    ?>
 
130
      <form action="upgrade.php" method="POST">
 
131
        <div class="loginbutton"><button type="submit">Retest</button></div>
 
132
      </form>
 
133
    <?php
134
134
    }
135
135
    else if ($cObj->EnvironmentWarning()) {
136
136
    ?>
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>
140
 
      </form>
141
 
      <form action="upgrade.php" method="POST">
142
 
        <div class="loginbutton"><button type="submit">Next ></button></div>
143
 
      </form>
144
 
    <?php
145
 
    }
146
 
    else {
147
 
    ?>
148
 
      <form action="upgrade.php" method="POST">
149
 
        <div class="loginbutton"><button type="submit">Next ></button></div>
150
 
      </form>
151
 
    <?php
152
 
    }    
153
 
}
 
138
        <input type="hidden" name="skipstep" value="1">
 
139
        <div class="loginbutton"><button type="submit">Retest</button></div>
 
140
      </form>
 
141
      <form action="upgrade.php" method="POST">
 
142
        <div class="loginbutton"><button type="submit">Next ></button></div>
 
143
      </form>
 
144
    <?php
 
145
    }
 
146
    else {
 
147
    ?>
 
148
      <form action="upgrade.php" method="POST">
 
149
        <div class="loginbutton"><button type="submit">Next ></button></div>
 
150
      </form>
 
151
    <?php
 
152
    }    
 
153
}
154
154
elseif ($_SESSION['step'] == 2) {
155
 
        checkAuth();
156
 
# Calculate the upgrade
157
 
      
 
155
        checkAuth();
 
156
# Calculate the upgrade
 
157
      
158
158
        $_SESSION['upgradeFrom'] = Config::Version($db, 'DBVersion');
159
159
 
160
160
        if ($_SESSION['upgradeFrom'] < 1) {
163
163
 
164
164
        // Get a list of .sql and .php files for the upgrade
165
165
        $sql_files = ls('*.sql','install/database',false,array('return_files'));
166
 
        $php_files = ls('*.php','install/database',false,array('return_files'));
167
 
    
 
166
        $php_files = ls('*.php','install/database',false,array('return_files'));
 
167
    
168
168
        // Sort by natural filename (eg 10 is bigger than 2)
169
169
        natcasesort($sql_files);
170
170
        natcasesort($php_files);
217
217
        echo '</form>';
218
218
 
219
219
?>
220
 
  <?php
221
 
}
 
220
  <?php
 
221
}
222
222
elseif ($_SESSION['step'] == 3) {
223
223
        // $_SESSION['step'] = 0;
224
224
        $fault = false;
247
247
                // Report the error, and a back button
248
248
                echo "FAIL: " . $fault_string;
249
249
        }
250
 
        else {
 
250
        else {
251
251
        $doBackup = Kit::GetParam("doBackup", $_POST, _BOOL);
252
252
 
253
253
                set_time_limit(0);
268
268
                        if (file_exists('install/database/' . $i . '.sql')) {
269
269
                                echo '<p>' . $i . '.sql ';
270
270
                                flush();
271
 
                                $delimiter = ';';
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);
275
 
    
276
 
                                foreach ($sql_file as $sql) {
 
271
                                $delimiter = ';';
 
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);
 
275
    
 
276
                                foreach ($sql_file as $sql) {
277
277
                                  print ".";
278
 
                                  $sqlStatementCount++;
279
 
                                  flush();
 
278
                                  $sqlStatementCount++;
 
279
                                  flush();
280
280
                                  if (! $db->query($sql)) {
281
281
                                    $fault = true;
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);
283
 
                                  }
 
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);
 
283
                                  }
284
284
                                }
285
285
                                echo '</p>';
286
286
                        }
296
296
                }
297
297
                echo '</div>';
298
298
                if (! $fault) {
299
 
                        if (! unlink('install.php')) {
300
 
                                echo "Unable to delete install.php. Please remove this file manually.";
 
299
                        if (! unlink('install.php')) {
 
300
                                echo "Unable to delete install.php. Please remove this file manually.";
301
301
                        }
302
 
                        if (! unlink('upgrade.php')) {
303
 
                                echo "Unable to delete upgrade.php. Please remove this file manually.";
 
302
                        if (! unlink('upgrade.php')) {
 
303
                                echo "Unable to delete upgrade.php. Please remove this file manually.";
304
304
                        }
305
305
 
306
306
                        echo '<b>Upgrade is complete!</b><br /><br />';
313
313
                }
314
314
                session_destroy();
315
315
        }
316
 
}
317
 
else {
318
 
  reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again");
319
 
}
320
 
 
321
 
include('install/footer.inc');
322
 
 
323
 
# Functions
324
 
function checkPHP() {
325
 
  # Check PHP version > 5
326
 
  return (version_compare("5.1.0",phpversion(), "<="));
327
 
}
328
 
 
 
316
}
 
317
else {
 
318
  reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again");
 
319
}
 
320
 
 
321
include('install/footer.inc');
 
322
 
 
323
# Functions
 
324
function checkPHP() {
 
325
  # Check PHP version > 5
 
326
  return (version_compare("5.1.0",phpversion(), "<="));
 
327
}
 
328
 
329
329
function reportError($step, $message, $button_text="&lt; Back") {
330
 
        $_SESSION['step'] = $step;
331
 
?>
332
 
    <div class="info">
333
 
      <?php print $message; ?>
334
 
    </div>
335
 
    <form action="upgrade.php" method="POST">
336
 
      <button type="submit"><?php print $button_text; ?></button>
337
 
    </form>
338
 
  <?php
339
 
  include('install/footer.inc');
340
 
  die();
 
330
        $_SESSION['step'] = $step;
 
331
?>
 
332
    <div class="info">
 
333
      <?php print $message; ?>
 
334
    </div>
 
335
    <form action="upgrade.php" method="POST">
 
336
      <button type="submit"><?php print $button_text; ?></button>
 
337
    </form>
 
338
  <?php
 
339
  include('install/footer.inc');
 
340
  die();
341
341
342
342
 
343
343
function checkAuth() {
344
344
        if (! $_SESSION['auth']) {
345
345
                reportError(1, "You must authenticate to run the upgrade.");
346
346
        }
347
 
}
348
 
 
349
 
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
350
 
// By Crackster 
351
 
/**
352
 
 * remove_remarks will strip the sql comment lines out of an uploaded sql file
353
 
 */
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));
357
 
  return $sql;
358
 
}
359
 
 
360
 
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
361
 
// By Crackster              
362
 
/**
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.
365
 
 */
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);
370
 
  // The empty case
371
 
  $end_data = end($data);
372
 
  if (empty($end_data))
373
 
  {
374
 
    unset($data[key($data)]);
375
 
  }
376
 
  return $data;
377
 
}
 
347
}
 
348
 
 
349
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
 
350
// By Crackster 
 
351
/**
 
352
 * remove_remarks will strip the sql comment lines out of an uploaded sql file
 
353
 */
 
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));
 
357
  return $sql;
 
358
}
 
359
 
 
360
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
 
361
// By Crackster              
 
362
/**
 
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.
 
365
 */
 
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);
 
370
  // The empty case
 
371
  $end_data = end($data);
 
372
  if (empty($end_data))
 
373
  {
 
374
    unset($data[key($data)]);
 
375
  }
 
376
  return $data;
 
377
}
378
378
 
379
379
/**
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 
505
505
        fclose($handle);
506
506
}
507
507
 
508
 
 
509
 
function gen_secret() {
510
 
  # Generates a random 12 character alphanumeric string to use as a salt
511
 
  mt_srand((double)microtime()*1000000);
512
 
  $key = "";
513
 
  for ($i=0; $i < 12; $i++) {
514
 
    $c = mt_rand(0,2);
515
 
    if ($c == 0) {
516
 
      $key .= chr(mt_rand(65,90));
517
 
    }
518
 
    elseif ($c == 1) {
519
 
      $key .= chr(mt_rand(97,122));
520
 
    }
521
 
    else {
522
 
      $key .= chr(mt_rand(48,57));
523
 
    }
524
 
  } 
525
 
  
526
 
  return $key;
 
508
 
 
509
function gen_secret() {
 
510
  # Generates a random 12 character alphanumeric string to use as a salt
 
511
  mt_srand((double)microtime()*1000000);
 
512
  $key = "";
 
513
  for ($i=0; $i < 12; $i++) {
 
514
    $c = mt_rand(0,2);
 
515
    if ($c == 0) {
 
516
      $key .= chr(mt_rand(65,90));
 
517
    }
 
518
    elseif ($c == 1) {
 
519
      $key .= chr(mt_rand(97,122));
 
520
    }
 
521
    else {
 
522
      $key .= chr(mt_rand(48,57));
 
523
    }
 
524
  } 
 
525
  
 
526
  return $key;
527
527
}
528
528
 
529
529
function createQuestions($step, $questions) {
593
593
        {
594
594
                return true;
595
595
        }
596
 
}
597
 
 
 
596
}
 
597
 
598
598
?>