~alexharrington/xibo/pyclient-1.1.0a22

« back to all changes in this revision

Viewing changes to server/install.php

  • Committer: Alex Harrington
  • Date: 2009-03-02 17:27:19 UTC
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: alex@longhill.org.uk-20090302172719-7qigtqo1mjydo4b3
[core] Created folder to hold code used for central services to Xibo instances

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
90
 
    }
91
 
    else if ($cObj->EnvironmentWarning()) {
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
 
    
 
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
DEFINE('XIBO', true);
 
23
 
 
24
include('lib/app/kit.class.php');
 
25
include('install/header.inc');
 
26
 
 
27
$fault = false;
 
28
 
 
29
$xibo_step = Kit::GetParam('xibo_step',_POST,_INT,'0');
 
30
 
 
31
if (!isset($xibo_step) || $xibo_step == 0) {
 
32
  # First step of the process.
 
33
  # Show a welcome screen and next button
 
34
  ?>
 
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>
 
41
  </form>
 
42
  <?php
 
43
}
 
44
elseif ($xibo_step == 1) {
 
45
  # Check environment
 
46
  ?>
 
47
  <p>First we need to check if your server meets Xibo's requirements.</p>
 
48
  <div class="checks">
 
49
  <?php
 
50
## Filesystem Permissions
 
51
    if (checkFsPermissions()) {
 
52
    ?>
 
53
      <img src="install/dot_green.gif"> Filesystem Permissions<br />
 
54
    <?php
 
55
    }
 
56
    else {
 
57
      $fault = true;
 
58
    ?>
 
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
 
62
      <ul>
 
63
        <li> settings.php
 
64
        <li> install.php
 
65
      </ul>
 
66
      Please fix this, and retest.<br />
 
67
      </div>
 
68
    <?php
 
69
    }
 
70
## PHP5
 
71
    if (checkPHP()) {
 
72
    ?>
 
73
      <img src="install/dot_green.gif"> PHP Version<br />
 
74
    <?php
 
75
    }
 
76
    else {
 
77
      $fault = true;
 
78
    ?>
 
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 />
 
83
      </div>
 
84
    <?php
 
85
    }
 
86
## MYSQL
 
87
  if (checkMySQL()) {
 
88
    ?>
 
89
      <img src="install/dot_green.gif"> PHP MySQL Extension<br />
 
90
    <?php
 
91
    }
 
92
    else {
 
93
      $fault = true;
 
94
    ?>
 
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 />
 
99
      </div>
 
100
    <?php
 
101
    }
 
102
## JSON
 
103
  if (checkJson()) {
 
104
    ?>
 
105
      <img src="install/dot_green.gif"> PHP JSON Extension<br />
 
106
    <?php
 
107
    }
 
108
    else {
 
109
      $fault = true;
 
110
    ?>
 
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 />
 
115
      </div>
 
116
    <?php
 
117
    }
 
118
    ?>
 
119
    <br /><br />
 
120
    </div>
 
121
    <?php
 
122
    if ($fault) {
 
123
    ?>
 
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>
 
127
      </form>
 
128
    <?php
 
129
    }
 
130
    else {
 
131
    ?>
 
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>
 
135
      </form>
 
136
    <?php
 
137
    }    
 
138
}
 
139
elseif ($xibo_step == 2) {
 
140
# Create database
 
141
## Does database exist already?
 
142
 
 
143
  ?>
 
144
  <div class="info">
 
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>
 
150
  </div>
 
151
  <form action="install.php" method="POST">
 
152
    <input type="hidden" name="xibo_step" value="3" />
 
153
    <button type="submit">Create New</button>
 
154
  </form>
 
155
  <form action="install.php" method="POST">
 
156
    <input type="hidden" name="xibo_step" value="4" />
 
157
    <button type="submit">Use Existing</button>
 
158
  </form>
 
159
  <?php
 
160
}
 
161
elseif ($xibo_step == 3) {
 
162
## If not, gather admin password and use to create empty db and new user.
 
163
?>
 
164
<div class="info">
 
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
 
167
user for Xibo.</p>
 
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>
 
180
</div>
 
181
</div>
 
182
<button type="submit">Create</button>
 
183
</form>
 
184
<?php
 
185
}
 
186
elseif ($xibo_step == 4) {
 
187
## Get details of db that's been created already for us
 
188
?>
 
189
<div class="info">
 
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>
 
200
</div>
 
201
</div>
 
202
<button type="submit">Create</button>
 
203
</form>
 
204
<?php
 
205
}
 
206
elseif ($xibo_step == 5) {
 
207
 
 
208
  $db_create = Kit::GetParam('db_create',_POST,_BOOL);
 
209
 
 
210
  if (!isset($db_create)) {
 
211
    reportError("2","Something went wrong");
 
212
  }
 
213
  else {
 
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);
 
218
    ?>
 
219
    <div class="info">
 
220
    <?php
 
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);
 
224
      
 
225
      if (! ($db_host && $db_name && $db_user && $db_pass && $db_admin_user && $db_admin_pass)) {
 
226
        # Something was blank.
 
227
        # Throw an error.
 
228
        reportError("3", "A field was blank. Please fill in all fields.");
 
229
      }
 
230
      
 
231
      $db = @mysql_connect($db_host,$db_admin_user,$db_admin_pass);
 
232
      
 
233
      if (! $db) {
 
234
        reportError("3", "Could not connect to MySQL with the administrator details. Please check and try again.<br /><br />MySQL Error:<br />" . mysql_error());
 
235
      }
 
236
      
 
237
      ?>
 
238
      <p>Creating new database.</p>
 
239
      <?php
 
240
      flush();
 
241
      
 
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());
 
245
      }
 
246
      
 
247
      # Choose the MySQL DB to create a user
 
248
      @mysql_select_db("mysql", $db);
 
249
 
 
250
      # Make $db_host lowercase so it matches "localhost" if required.
 
251
      $db_host = strtolower($db_host);
 
252
      
 
253
      ?>
 
254
      <p>Creating new user</p>
 
255
      <?php
 
256
      flush();
 
257
      
 
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());
 
261
        }
 
262
      }
 
263
      else {
 
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());
 
266
        }
 
267
      }
 
268
      
 
269
 
 
270
      @mysql_query("FLUSH PRIVILEGES", $db);      
 
271
      @mysql_close($db);
 
272
      
 
273
    }
 
274
    else {
 
275
      if (! ($db_host && $db_name && $db_user && $db_pass)) {
 
276
        # Something was blank
 
277
        # Throw an error.
 
278
        reportError("4", "A field was blank. Please fill in all fields.");
 
279
      }
 
280
    }
 
281
    ## Populate database
 
282
    
 
283
    $db = @mysql_connect($db_host,$db_user,$db_pass);
 
284
      
 
285
    if (! $db) {
 
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());
 
287
    }
 
288
      
 
289
    @mysql_select_db($db_name,$db);
 
290
    
 
291
    ?>
 
292
    <p>Populating the database</p>
 
293
    <?php
 
294
    flush();
 
295
    
271
296
    # Load from sql files to db - HOW?
272
297
    $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
 
    $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) {
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
 
        }
 
298
 
 
299
    // Sort the files in to sensible order, ie
 
300
    //   0.sql
 
301
    //   1.sql
 
302
    //  10.sql
 
303
    //
 
304
    // NOT
 
305
    //
 
306
    //   0.sql
 
307
    //  10.sql
 
308
    //   1.sql
 
309
    //
 
310
    // NB this is broken for 0 padded files
 
311
    // eg 01.sql would be incorrectly sorted in the above example.
 
312
    
 
313
    natcasesort($sql_files);
 
314
 
 
315
    foreach ($sql_files as $filename) {
 
316
      ?>
 
317
      <p>Loading from <?php print $filename; ?>
 
318
      <?php
 
319
        flush();
 
320
        
 
321
        $delimiter = ';';
 
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);
 
325
    
 
326
        foreach ($sql_file as $sql) {
 
327
          print ".";
 
328
          flush();
 
329
          if (! @mysql_query($sql,$db)) {
 
330
            reportError("4", "An error occured populating the database.<br /><br />MySQL Error:<br />" . mysql_error());
 
331
          }
 
332
        }
310
333
        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
 
}
 
334
    }
 
335
    @mysql_close($db);
 
336
  }
 
337
  # Write out a new settings.php
 
338
  $fh = fopen("settings.php", 'wt');
 
339
  
 
340
  if (! $fh) {
 
341
    reportError("0", "Unable to write to settings.php. We already checked this was possible earlier, so something changed.");
 
342
  }
 
343
  
 
344
  settings_strings();
 
345
  
 
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";
 
351
  
 
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.");
 
354
  }
 
355
    
 
356
  fclose($fh);
 
357
  
 
358
  ?>
 
359
  </div>
 
360
  <div class="install_table">
 
361
    <form action="install.php" method="POST">
 
362
      <input type="hidden" name="xibo_step" value="6" />
 
363
  </div>
 
364
    <button type="submit">Next ></button>
 
365
  </form>
 
366
  <?php
 
367
}
 
368
elseif ($xibo_step == 6) {
 
369
  # Form to get new admin password
 
370
  ?>
 
371
  <div class="info">
 
372
  <p>Xibo needs to set the "xibo_admin" user password. Please enter a password for this account below.</p>
 
373
  </div>
 
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>
 
379
  </div>
 
380
    <button type="submit">Next ></button>
 
381
  </form>
 
382
  <?php
 
383
}
 
384
elseif ($xibo_step == 7) {
 
385
  # Setup xibo_admin password
 
386
  $password1 = Kit::GetParam('password1',_POST,_PASSWORD);
 
387
  $password2 = Kit::GetParam('password2',_POST,_PASSWORD);
 
388
  
 
389
  if (!(($password1 && $password2) && ($password1 == $password2))) {
 
390
    reportError("6", "Please input a new password. Ensure both password fields are identical.");
 
391
  }
 
392
  
 
393
  include('settings.php');
 
394
  
 
395
  $password_hash = md5($password1);
 
396
  
 
397
  $db = @mysql_connect($dbhost,$dbuser,$dbpass);
 
398
      
 
399
    if (! $db) {
 
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());
 
401
    }
 
402
      
 
403
    @mysql_select_db($dbname,$db);
 
404
    
 
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());    
 
407
    }
 
408
 
 
409
    @mysql_close($db);
 
410
    
 
411
    ?>
 
412
    <div class="info">
 
413
      Successfully changed the xibo_admin password. We're nearly there now. Just a couple more steps!
 
414
    </div>
 
415
    <form action="install.php" method="POST">
 
416
      <input type="hidden" name="xibo_step" value="8" />
 
417
      <button type="submit">Next ></button>
 
418
    </form>
 
419
    <?php
 
420
}
 
421
elseif ($xibo_step == 8) {
 
422
  # Configure paths and keys
 
423
  ## nuSoap
 
424
  ## libraries
 
425
  ## server_key
 
426
  ?>
 
427
  <div class="info">
 
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>
 
433
    </div>
 
434
    <p>Server Key</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>
 
438
    </div>
 
439
      <input type="hidden" name="xibo_step" value="9" />
 
440
    </div>
 
441
      <button type="submit">Next ></button>
 
442
    </form>
 
443
  <?php
 
444
}
 
445
elseif ($xibo_step == 9) {
 
446
 
 
447
  $server_key = Kit::GetParam('server_key',_POST,_WORD);
 
448
  $library_location = Kit::GetParam('library_location',_POST,_STRING);
 
449
  
 
450
  // Remove trailing whitespace from the path given.
 
451
  $library_location = trim($library_location);
 
452
 
 
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");
 
456
  }
 
457
 
 
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");
 
462
    }
 
463
 
 
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.");
 
469
    }
 
470
    
 
471
  }
 
472
  
 
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.");
 
477
  }
 
478
  
 
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");
 
482
  }
 
483
  
 
484
  // Check if the user has added a trailing slash.
 
485
  // If not, add one.
 
486
  if (!((substr($library_location, -1) == '/') || (substr($library_location, -1) == '\\'))) {
 
487
    $library_location = $library_location . '/';
 
488
  }
 
489
 
 
490
  include('settings.php');
 
491
  
 
492
  $db = @mysql_connect($dbhost,$dbuser,$dbpass);
 
493
      
 
494
    if (! $db) {
 
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());
 
496
    }
 
497
      
 
498
    @mysql_select_db($dbname,$db);
 
499
    
 
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());    
 
502
    }
 
503
    
 
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());    
 
506
    }
 
507
 
 
508
    @mysql_close($db);
 
509
  
 
510
  ?>
 
511
  <div class="info">
 
512
    <p>Successfully set LIBRARY_LOCATION and SERVER_KEY.</p>
 
513
  </div>
 
514
    <form action="install.php" method="POST">
 
515
      <input type="hidden" name="xibo_step" value="10" />
 
516
      <button type="submit">Next ></button>
 
517
    </form>
 
518
  <?php
 
519
}
 
520
elseif ($xibo_step == 10) {
 
521
# Delete install.php
 
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");
 
525
  }
 
526
  ?>
 
527
  <div class="info">
 
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>
 
530
  </div>
 
531
  <?php
 
532
}
 
533
else {
 
534
  reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again");
 
535
}
 
536
 
 
537
include('install/footer.inc');
 
538
 
 
539
# Functions
 
540
 
 
541
function checkFsPermissions() {
 
542
  # Check for appropriate filesystem permissions
 
543
  return (is_writable("install.php") && (is_writable("settings.php") || is_writable(".")));
 
544
}
 
545
 
 
546
function checkPHP() {
 
547
  # Check PHP version > 5
 
548
  return (version_compare("5",phpversion(), "<="));
 
549
}
 
550
 
 
551
function checkMySQL() {
 
552
  # Check PHP has MySQL module installed
 
553
  return extension_loaded("mysql");
 
554
}
 
555
 
 
556
function checkJson() {
 
557
  # Check PHP has JSON module installed
 
558
  return extension_loaded("json");
 
559
}
 
560
 
 
561
function reportError($step, $message, $button_text="&lt; Back") {
 
562
?>
 
563
    <div class="info">
 
564
      <?php print $message; ?>
 
565
    </div>
 
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>
 
569
    </form>
 
570
  <?php
 
571
  include('install/footer.inc');
 
572
  die();
 
573
 
574
 
 
575
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
 
576
// By Crackster 
 
577
/**
 
578
 * remove_remarks will strip the sql comment lines out of an uploaded sql file
 
579
 */
 
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));
 
583
  return $sql;
 
584
}
 
585
 
 
586
// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html
 
587
// By Crackster              
 
588
/**
 
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.
 
591
 */
 
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);
 
596
  // The empty case
 
597
  $end_data = end($data);
 
598
  if (empty($end_data))
 
599
  {
 
600
    unset($data[key($data)]);
 
601
  }
 
602
  return $data;
 
603
}
623
604
 
624
605
/**
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 
682
663
    if($folder) chdir($current_folder);
683
664
    return $all;
684
665
}
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
 
666
 
 
667
function gen_secret() {
 
668
  # Generates a random 12 character alphanumeric string to use as a salt
 
669
  mt_srand((double)microtime()*1000000);
 
670
  $key = "";
 
671
  for ($i=0; $i < 12; $i++) {
 
672
    $c = mt_rand(0,2);
 
673
    if ($c == 0) {
 
674
      $key .= chr(mt_rand(65,90));
 
675
    }
 
676
    elseif ($c == 1) {
 
677
      $key .= chr(mt_rand(97,122));
 
678
    }
 
679
    else {
 
680
      $key .= chr(mt_rand(48,57));
 
681
    }
 
682
  } 
 
683
  
 
684
  return $key;
 
685
}
 
686
 
 
687
function settings_strings() {
 
688
global $settings_header;
 
689
global $settings_footer;
 
690
 
 
691
  $settings_header = <<<END
 
692
<?php
 
693
 
 
694
/*
 
695
 * Xibo - Digital Signage - http://www.xibo.org.uk
 
696
 *
 
697
 * This file is part of Xibo - and is automatically generated by the installer
 
698
 *
 
699
 * You should not need to edit this file, unless your SQL connection details have changed.
 
700
 */
 
701
 
 
702
defined('XIBO') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");
 
703
 
 
704
global \$dbhost;
 
705
global \$dbuser;
 
706
global \$dbpass;
 
707
global \$dbname;
 
708
 
 
709
 
 
710
END;
 
711
 
 
712
$settings_footer = <<<END
 
713
?>
 
714
END;
 
715
 
 
716
  return;
 
717
}
 
718
 
755
719
?>
756
 
END;
757
 
 
758
 
  return;
759
 
}
760
 
?>
 
 
b'\\ No newline at end of file'