-
Notifications
You must be signed in to change notification settings - Fork 100
/
install.php
362 lines (305 loc) · 12.3 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php
//Config writer for IMathAS
if (file_exists("config.php")) {
echo "<html><body>config.php already exists. Aborting. To reinstall, delete existing config.php</body></html>";
exit;
}
if (isset($_POST['dbserver'])) {
$_POST['imasroot'] = rtrim(trim($_POST['imasroot']), ' /');
$contents = "<?php
//IMathAS Math Config File. Adjust settings here!
//database access settings
\$dbserver = \"{$_POST['dbserver']}\";
\$dbname = \"{$_POST['dbname']}\";
\$dbusername = \"{$_POST['dbusername']}\";
\$dbpassword = \"{$_POST['dbpassword']}\";
//error reporting level. Set to 0 for production servers.
error_reporting(E_ALL & ~E_NOTICE);
//install name
\$installname = \"{$_POST['installname']}\";
//login prompts
\$loginprompt = \"{$_POST['loginprompt']}\";
\$longloginprompt = \"{$_POST['longloginprompt']}\";
\$loginformat = '";
if ($_POST['loginformat']==0) {
$contents .= '/^[\w+\-]+$/';
} else if ($_POST['loginformat']==1) {
$contents .= '/^(\d{9}|lti-\d+)$/';
} else if ($_POST['loginformat']==2) {
$contents .= '/^(\d{3}-\d{2}-\d{4}|lti-\d+)$/';
} else if ($_POST['loginformat']==3) {
$contents .= $_POST['loginformatother'];
}
$contents .= "';
//require email confirmation of new users?
\$emailconfirmation = {$_POST['emailconfirmation']};
//email to send notices from
\$sendfrom = \"{$_POST['sendfrom']}\";
//color shift icons as deadline approaches?
\$colorshift = {$_POST['colorshift']};
//path settings
//web path to install
\$imasroot = \"{$_POST['imasroot']}\";
//base site url - use when generating full URLs to site pages.
\$httpmode = (isset(\$_SERVER['HTTPS']) && \$_SERVER['HTTPS'] == 'on')
|| (isset(\$_SERVER['HTTP_X_FORWARDED_PROTO']) && \$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
? 'https://' : 'http://';
\$GLOBALS['basesiteurl'] = \$httpmode . Sanitize::domainNameWithPort(\$_SERVER['HTTP_HOST']) . \$imasroot;
//mimetex path
\$mathimgurl = \"{$_POST['mathimgurl']}\";
//enable lti?
\$enablebasiclti = {$_POST['enablebasiclti']};
//allow nongroup libs?
\$allownongrouplibs = {$_POST['allownongrouplibs']};
//allow course import of questions?
\$allowcourseimport = {$_POST['allowcourseimport']};
//allow macro install?
\$allowmacroinstall = {$_POST['allowmacroinstall']};
";
$hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG';
$test = crypt("password", $hash);
$pass = ($test == $hash);
if ($pass) {
$contents .= "//use more secure password hashes? requires PHP 5.3.7+
\$CFG['GEN']['newpasswords'] = 'only';
";
}
if (!empty($_POST['sessionpath'])) {
$contents .= "//session path \n\$sessionpath = \"{$_POST['sessionpath']}\";\n\n";
} else {
$contents .= "//session path \n//\$sessionpath = \"\";\n\n";
}
if (!empty($_POST['AWSkey']) && !empty($_POST['AWSsecret']) && !empty($_POST['AWSbucket'])) {
$contents .= "//Amazon S3 access for file upload \n
\$AWSkey = \"{$_POST['AWSkey']}\";\n
\$AWSsecret = \"{$_POST['AWSsecret']}\";\n
\$AWSbucket = \"{$_POST['AWSbucket']}\";\n\n";
} else {
$contents .= "//Amazon S3 access for file upload \n
//\$AWSkey = \"{$_POST['AWSkey']}\";\n
//\$AWSsecret = \"{$_POST['AWSsecret']}\";\n
//\$AWSbucket = \"{$_POST['AWSbucket']}\";\n\n";
}
$contents .= '
//Uncomment to change the default course theme, also used on the home & admin page:
//$defaultcoursetheme = "default.css"
//To change loginpage based on domain/url/etc, define $loginpage here
//no need to change anything from here on
/* Connecting, selecting database */
try {
$DBH = new PDO("mysql:host=$dbserver;dbname=$dbname", $dbusername, $dbpassword);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$GLOBALS["DBH"] = $DBH;
} catch(PDOException $e) {
die("<p>Could not connect to database: <b>" . $e->getMessage() . "</b></p></div></body></html>");
}
$DBH->query("set session sql_mode=\'\'");
unset($dbserver);
unset($dbusername);
unset($dbpassword);
?>';
$file = fopen('config.php','w');
$f = fwrite($file,$contents);
fclose($file);
?>
<html>
<body>
<?php
if ($f!==false) {
echo "config.php written.<br/>";
} else {
echo "error writing config! Copy config.php.dist to config.php and edit manually.<br/>";
}
$c1 = chmod('assessment/libs',0755);
$c2 =chmod('assessment/qimages',0755);
$c3 =chmod('admin/import',0755);
$c4 =chmod('course/files',0755);
$c5 =chmod('filter/graph/imgs',0755);
$c6 =chmod('filestore',0755);
if ($c1 && $c2 && $c3 && $c4 && $c5 && $c6) {
echo 'Permissions set on writeable directories<br/>';
} else {
echo 'Error setting directory permissions. See readme.html for a list of directories that need to be writable by the web server.<br/>';
}
$c6 =copy('infoheader.php.dist','infoheader.php');
$c7 =copy('loginpage.php.dist','loginpage.php');
$c8 =copy('newinstructor.php.dist','newinstructor.php');
if ($c6 && $c7 && $c8) {
echo 'Local copies of infoheader.php, loginpage,php, and newinstructor.php have been created. You may want to personalize these.<br/>';
} else {
echo 'Couldn\'t make copies of infoheader.php, loginpage,php, and newinstructor.php. Please copy the .dist files as described in readme.html<br/>';
}
?>
<form method="post" action="setupdb.php">
<input type="hidden" name="dbsetup" value="true" />
<input type="submit" value="Continue to creating database tables"/>
</form>
</body>
</html>
<?php
} else {
?>
<html>
<head>
<link rel="stylesheet" href="imascore.css" type="text/css" />
<style type="text/css">
p {
background: #ccf;
padding: 10px;
margin: 5px;
}
p.imp {
background: #fcc;
}
</style>
<title>IMathAS Install</title>
</head>
<body>
<h1>IMathAS Install</h1>
<?php
if (PHP_VERSION_ID < 70200) {
echo '<p><b>Warning</b>: PHP 7.2 or higher is needed for full functionality.</p>';
}
if (!extension_loaded("mbstring")) {
echo '<p><b>Warning</b>: It appears your PHP does not have the mbstring extension installed, and it is required.</p>';
}
if (!extension_loaded("pdo_mysql")) {
echo '<p><b>Warning</b>: It appears your PHP does not have the pdo_mysql extension installed, and it is required.</p>';
}
if (!function_exists('gd_info')) {
echo '<p><b>Warning</b>: It appears your PHP does not have the gd extension installed, which is needed for some functionality.</p>';
}
if (!function_exists('curl_init')) {
echo '<p><b>Warning</b>: It appears your PHP does not have the curl extension installed, which is needed for some functionality.</p>';
}
?>
<p>This page will help you configure IMathAS. The database settings <b>must</b> be
changed. The rest of the settings autopopulate to reasonable defaults but can be
changed to allow for customization.</p>
<form method="post" action="install.php?submit=true">
<h2>Database Settings</h2>
<p class="imp">
Database server. Could be localhost or mysql.yoursite.edu<br/>
<input type="text" name="dbserver" value="localhost" />
</p>
<p class="imp">
Database name.<br/>
<input type="text" name="dbname" value="imathasdb" />
</p>
<p class="imp">
Database username. The mysql user who has privileges to this database.<br/>
<input type="text" name="dbusername" value="imasuser" />
</p>
<p class="imp">
Database password. The password for the database user above.<br/>
<input type="text" name="dbpassword" value="" />
</p>
<p class="imp">
<b>The database and database user you provided above must already exist.</b>
</p>
<h2>Customization</h2>
<p>
The name of this installation. This allows you to custom-brand the site<br/>
<input type="text" name="installname" value="IMathAS" />
</p>
<p>
A small logo or name to display on the upper right of course pages. Can use <img src="/path/to/img.gif"/>
for an image, or just put in some text or your installation name. Image should be 120x80px if used.<br/>
<input type="text" name="smallheaderlogo" value="IMathAS" />
</p>
<p>
Prompt for login. Could be username, Student ID, email address, etc.<br/>
<input type="text" name="loginprompt" value="Username" />
</p>
<p>
Prompt for new users to create a username<br/>
<input type="text" size="80" name="longloginprompt" value="Enter a username. Use only numbers, letters, or the _ character." />
</p>
<p>
Login format.<br/>
<input type="radio" name="loginformat" value="0" checked="checked" />Letters, numbers, and _ are only allowed characters<br/>
<input type="radio" name="loginformat" value="1" />Require a 9-digit number<br/>
<input type="radio" name="loginformat" value="2" />SSN type format: 555-55-5555<br/>
<input type="radio" name="loginformat" value="3" />Other. Provide a regular expression: <input type="loginformatother" value="/\d{7}/" />
</p>
<p>
Require new users to respond to an email to verify their account before allowing
them to log in?<br/>
<input type="radio" name="emailconfirmation" value="true"/>Yes<br/>
<input type="radio" name="emailconfirmation" value="false" checked="checked" />No
</p>
<p>
Email address to send confirmation emails, new message notifications and new
forum post notifications from.<br/>
<input type="text" name="sendfrom" size="80" value="[email protected]" />
</p>
<p>
Color shift icons from green to red as deadlines approach?<br/>
<input type="radio" name="colorshift" value="true" checked="checked" /> Yes<br/>
<input type="radio" name="colorshift" value="false" /> No
</p>
<h2>Settings</h2>
<p>
Path to IMathAS install. Blank if install is in web root directory. Might be something like "/imathas" if in a
subdirectory.<br/>
<input type="text" name="imasroot" value="<?php echo htmlspecialchars(rtrim(dirname($_SERVER['PHP_SELF']), ' /'), ENT_QUOTES | ENT_HTML401); ?>" />
</p>
<p>
Absolute path or full url to Mimetex CGI, for math image fallback. If you cannot install it
on your local installation, you can use the default public server.<br/>
<input type="text" name="mathimgurl" size="80" value="http://www.imathas.com/cgi-bin/mimetex.cgi" />
</p>
<p>
Enable use of IMathAS as a BasicLTI producer?<br/>
<input type="radio" name="enablebasiclti" value="true" checked="checked" /> Yes<br/>
<input type="radio" name="enablebasiclti" value="false" /> No
</p>
<p>
Should non-admins be allowed to create open-to-all libraries? On a single-school
install, set to yes; for larger installs that plan to use the Instructor Groups features,
set to no<br/>
<input type="radio" name="allownongrouplibs" value="true" /> Yes<br/>
<input type="radio" name="allownongrouplibs" value="false" checked="checked" /> No
</p>
<p>
Should anyone be allowed to import/export questions and libraries from the
course page? Intended for easy sharing between systems, but the course page
is cleaner if turned off.<br/>
<input type="radio" name="allowcourseimport" value="true" /> Yes<br/>
<input type="radio" name="allowcourseimport" value="false" checked="checked" /> No
</p>
<p>
Allow installation of macro files by admins? Macro files contain a large
security risk. If you are going to have many admins, and don't trust the
security of their passwords, you should set this to false. Installing
macros is equivalent in security risk to having FTP access to the IMathAS
server.<br/>
For single-admin systems, it is recommended you leave this as false, and
change it when you need to install a macro file.<br/>
<input type="radio" name="allowmacroinstall" value="true" checked="checked" /> Yes<br/>
<input type="radio" name="allowmacroinstall" value="false" /> No
</p>
<p>
Set PHP session path away from default. Leave blank to use default, or provide
an absolute file system path.
Changing is usually not necessary unless your site is on a server farm, or
you're on a shared server and want more security of session data.
Make sure this directory has write access by the server process.
<br/>
<input type="text" name="sessionpath" size="80" value="" />
</p>
<p>
For text editor file/image uploads and assessment file uploads, you can use
Amazon S3 service to hold these files. If using this option, provide your
Amazon S3 key and secret below. You'll also need to create a bucket and
specify it below.<br/>
Amazon S3 Key:<input type="text" name="AWSkey" value=""/><br/>
Amazon S3 Secret:<input type="password" name="AWSsecret" value=""/><br/>
Amazon S3 Bucket:<input type="text" name="AWSbucket" value=""/><br/>
</p>
<input type="submit" value="Create Config, set up Database" />
<input type="reset" value="Reset Defaults"/>
</form>
<?php
}
?>