forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
312 lines (273 loc) · 8.56 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
/*=========================================================================
Program: CDash - Cross-Platform Dashboard System
Module: $Id$
Language: PHP
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
set_time_limit(0);
// This is the installation script for CDash
if (class_exists('XsltProcessor') == FALSE)
{
echo "<font color=\"#FF0000\">Your PHP install does not support xslt, please install the PHP_XSLT package.<br> ";
echo "WAMP Hint: uncomment extension=php_xsl.dll in php.ini.<br></font>";
return;
}
if (function_exists('imagecreatefromstring') == FALSE)
{
echo "<font color=\"#FF0000\">Your PHP install does not support the imagecreatefromstring() function, please install the PHP_GD package.<br> ";
echo "WAMP Hint: uncomment extension=php_gd.dll in php.ini.<br></font>";
return;
}
include("cdash/config.php");
require_once("cdash/pdo.php");
require_once("cdash/common.php");
require_once("cdash/version.php");
if($CDASH_PRODUCTION_MODE)
{
echo "CDash is in production mode. Install cannot be accessed. Change the variable in your config.php if you want to access the installation.";
return;
}
$xml = begin_XML_for_XSLT();
if(!isset($CDASH_DB_TYPE))
{
$db_type = 'mysql';
}
else
{
$db_type = $CDASH_DB_TYPE;
}
$xml .= "<connectiondb_type>".$db_type."</connectiondb_type>";
$xml .= "<connectiondb_host>".$CDASH_DB_HOST."</connectiondb_host>";
$xml .= "<connectiondb_login>".$CDASH_DB_LOGIN."</connectiondb_login>";
$xml .= "<connectiondb_name>".$CDASH_DB_NAME."</connectiondb_name>";
// Step 1: Check if we can connect to the database
@$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
if(!$db)
{
$xml .= "<connectiondb>0</connectiondb>";
}
else
{
// If we are installing a database other than mysql we need to
// have the database already created
if(isset($CDASH_DB_TYPE) && $CDASH_DB_TYPE!="mysql")
{
if(!pdo_select_db($CDASH_DB_NAME,$link))
{
$xml .= "<connectiondb>0</connectiondb>";
}
else
{
$xml .= "<connectiondb>1</connectiondb>";
}
}
if(isset($CDASH_DB_TYPE) && $CDASH_DB_TYPE=="mysql")
{
if(@!mysql_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS"))
{
$xml .= "<connectiondb>0</connectiondb>";
}
else
{
$xml .= "<connectiondb>1</connectiondb>";
}
}
else
{
$xml .= "<connectiondb>1</connectiondb>";
}
}
if(xslt_create() == FALSE)
{
$xml .= "<xslt>0</xslt>";
}
else
{
$xml .= "<xslt>1</xslt>";
}
// Check if curl is installed
if(function_exists("curl_init") == FALSE)
{
$xml .= "<phpcurl>0</phpcurl>";
}
else
{
$xml .= "<phpcurl>1</phpcurl>";
}
// check if the backup directory is writable
if(!is_writable($CDASH_BACKUP_DIRECTORY))
{
$xml .= "<backupwritable>0</backupwritable>";
}
else
{
$xml .= "<backupwritable>1</backupwritable>";
}
// check if the upload directory is writable
if(!is_writable($CDASH_UPLOAD_DIRECTORY))
{
$xml .= "<uploadwritable>0</uploadwritable>";
}
else
{
$xml .= "<uploadwritable>1</uploadwritable>";
}
// check if the rss directory is writable
if(!is_writable("rss"))
{
$xml .= "<rsswritable>0</rsswritable>";
}
else
{
$xml .= "<rsswritable>1</rsswritable>";
}
// If the database already exists and we have all the tables
if(@pdo_select_db("$CDASH_DB_NAME",$db) === TRUE
&& pdo_query("SELECT id FROM ".qid("user")." LIMIT 1",$db))
{
$xml .= "<database>1</database>";
}
else
{
$xml .= "<database>0</database>";
$xml .= "<dashboard_timeframe>24</dashboard_timeframe>";
// If we should create the tables
@$Submit = $_POST["Submit"];
if($Submit)
{
$admin_email = htmlspecialchars(pdo_real_escape_string($_POST["admin_email"]));
$admin_password = htmlspecialchars(pdo_real_escape_string($_POST["admin_password"]));
$valid_email = true;
if(strlen($admin_email) < 6 || strstr($admin_email,'@') === FALSE)
{
$xml .= "<db_created>0</db_created>";
$xml .= "<alert>* Administrator's email should be a valid email address</alert>";
$valid_email = false;
}
if($valid_email && strlen($admin_password)<5)
{
$xml .= "<db_created>0</db_created>";
$xml .= "<alert>* Administrator's password should be at least 5 characters</alert>";
$valid_email = false;
}
if($valid_email)
{
$db_created = true;
// If this is MySQL we try to create the database
if($db_type=='mysql')
{
mysql_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
if(!mysql_query("CREATE DATABASE IF NOT EXISTS `$CDASH_DB_NAME`"))
{
$xml .= "<db_created>0</db_created>";
$xml .= "<alert>".mysql_error()."</alert>";
$db_created = false;
}
}
/** process an SQL file */
function _processSQLfile($filename)
{
$file_content = file($filename);
$query = "";
foreach($file_content as $sql_line)
{
$tsl = trim($sql_line);
if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#"))
{
$query .= $sql_line;
if(preg_match("/;\s*$/", $sql_line))
{
// We need to remove only the last semicolon
$pos = strrpos($query,";");
if($pos !== false)
{
$query = substr($query,0,$pos).substr($query,$pos+1);
}
$result = pdo_query($query);
if (!$result)
{
$xml .= "<db_created>0</db_created>";
die(pdo_error());
}
$query = "";
}
}
} // end for each line
} // end _processSQLfile
if($db_created)
{
pdo_select_db("$CDASH_DB_NAME",$db);
$sqlfile = "sql/".$db_type."/cdash.sql";
_processSQLfile($sqlfile);
// If we have a local directory we process the sql in that directory
if($CDASH_USE_LOCAL_DIRECTORY)
{
$sqlfile = "local/sql/".$db_type."/cdash.sql";
if(file_exists($sqlfile))
{
_processSQLfile($sqlfile);
}
}
// If we are with PostGreSQL we need to add some extra functions
if($db_type == 'pgsql')
{
$sqlfile = "sql/pgsql/cdash.ext.sql";
// Create the language. PgSQL has no way to know if the language already
// exists
@pdo_query("CREATE LANGUAGE plpgsql");
$file_content = file($sqlfile);
$query = "";
foreach($file_content as $sql_line)
{
$tsl = trim($sql_line);
if (($sql_line != "") && (substr($tsl, 0, 2) != "--"))
{
$query .= $sql_line;
$possemicolon = strrpos($query,";");
if($possemicolon !== false && substr_count($query,'\'',0,$possemicolon)%2==0)
{
// We need to remove only the last semicolon
$pos = strrpos($query,";");
if($pos !== false)
{
$query = substr($query,0,$pos).substr($query,$pos+1);
}
$result = pdo_query($query);
if (!$result)
{
$xml .= "<db_created>0</db_created>";
die(pdo_error());
}
$query = "";
}
}
} // end foreach line
// Check the version of PostgreSQL
$result_version = pdo_query("SELECT version()");
$version_array = pdo_fetch_array($result_version);
if(strpos(strtolower($version_array[0]),"postgresql 9.") !== FALSE)
{
// For PgSQL 9.0 we need to set the bytea_output to 'escape' (it was changed to hexa)
@pdo_query("ALTER DATABASE ".$CDASH_DB_NAME." SET bytea_output TO 'escape'");
}
} // end pgsql functions
pdo_query("INSERT INTO ".qid("user")." (email,password,firstname,lastname,institution,admin) VALUES ('".$admin_email."', '".md5($admin_password)."', 'administrator', '','Kitware Inc.', 1)");
echo pdo_error();
$xml .= "<db_created>1</db_created>";
// Set the database version
setVersion();
} // end database created
} // end check valid username and password
} // end submit
} // end database doesn't exists
$xml .= "</cdash>";
// Now doing the xslt transition
generate_XSLT($xml,"install");
?>