forked from sdc/xerte_2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.php
377 lines (280 loc) · 11.1 KB
/
play.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php
/**
*
* Play page, displays the template to the end user
*
* @author Patrick Lockley
* @version 1.0
* @copyright Copyright (c) 2008,2009 University of Nottingham
* @package
*/
require_once(dirname(__FILE__) . "/config.php");
_load_language_file("/play.inc");
require_once $xerte_toolkits_site->php_library_path . "display_library.php";
require_once $xerte_toolkits_site->php_library_path . "template_library.php";
//error_reporting(E_ALL);
//ini_set(display_errors,"ON");
/**
*
* Function check_host
* This function checks http security settings
* @param string $hostname = should be the $SERVER referrer
* @param string $setting = what the security setting in play_security_details is
* @return bool True or False if two params match
* @version 1.0
* @author Patrick Lockley
*/
function check_host($hostname, $setting)
{
$hostname = substr($hostname, 0, strlen($setting));
if ($hostname == $setting) {
return true;
} else {
return false;
}
}
/**
*
* Function check_ip
* This function checks IP security settings
* @param string $hostname = should be the $_SERVER REMOTE_ADDR
* @param string $setting = what the security setting in play_security_details is
* @return bool True or False if two params match
* @version 1.0
* @author Patrick Lockley
*/
function check_ip($ip_address, $security_settings)
{
/*
* Multiple IP Addresses supported, so separate them into individual records
*/
$security_array = explode(",", $security_settings);
while ($host_ip = array_pop($security_array)) {
/*
* Check for an asterisk. An asterisk indicates you have a domain such as 10.*
*/
if (strpos($host_ip, "*") === false) {
/*
* No asterisk, so do a straight comparison
*/
if (strcmp($ip_address, $host_ip) == 0) {
$flag = true;
} else {
$flag = false;
}
} else {
/*
* Found an asterisk so loop though the individual numbers if 192, then 168 checking for equivalence
*/
$security_range = explode(".", $host_ip);
$ip_range = explode(".", $ip_address);
$flag = false;
for ($x = 0; $x <= 3; $x++) {
if ($security_range[$x] == "*") {
$x = 5;
} else {
if ($ip_range[$x] == $security_range[$x]) {
$flag = true;
} else {
$flag = false;
}
}
}
}
}
if ($flag == true) {
return true;
} else {
return false;
}
}
/**
*
* Function check_security_type
* This function checks database settings to see if non standard play security options have been met
* @param string $security_setting = the value taken from security_setting in play_security_details
* @return bool True or False if two params match
* @version 1.0
* @author Patrick Lockley
*/
function check_security_type($security_setting)
{
if ($security_setting != "") {
if (substr($security_setting, 0, 4) == "http") {
return check_host($_SERVER['HTTP_REFERER'], $security_setting);
} else {
return check_ip($_SERVER['REMOTE_ADDR'], $security_setting);
}
} else {
return false;
}
}
if (!isset($_GET['template_id']) || !is_numeric($_GET['template_id'])) {
/*
* Was not numeric, so display error message
*/
echo file_get_contents($xerte_toolkits_site->website_code_path . "error_top") . " " . PLAY_RESOURCE_FAIL . " </div></div></body></html>";
exit(0);
}
$safe_template_id = (int) $_GET['template_id'];
/*
* Check to see whether it is less than the highest ID we have created
*/
if (get_maximum_template_number() < $safe_template_id) {
echo file_get_contents($xerte_toolkits_site->website_code_path . "error_top") . " " . PLAY_RESOURCE_FAIL . " </div></div></body></html>";
die();
}
/*
* Take the query from site variable and alter it to suit this request
*/
$query_for_play_content = "select otd.template_name, ld.username, otd.template_framework, tr.user_id, tr.folder, tr.template_id, td.access_to_whom, td.extra_flags";
$query_for_play_content .= " from " . $xerte_toolkits_site->database_table_prefix . "originaltemplatesdetails otd, " . $xerte_toolkits_site->database_table_prefix . "templaterights tr, " . $xerte_toolkits_site->database_table_prefix . "templatedetails td, " . $xerte_toolkits_site->database_table_prefix . "logindetails ld";
$query_for_play_content .= " where td.template_type_id = otd.template_type_id and td.creator_id = ld.login_id and tr.template_id = td.template_id and tr.template_id=" . $safe_template_id . " and role='creator'";
$query_for_play_content_response = mysql_query($query_for_play_content);
$row_play = mysql_fetch_array($query_for_play_content_response);
$query_to_find_out_if_in_recycle_bin = "select folder_name from " . $xerte_toolkits_site->database_table_prefix . "folderdetails where folder_id =\"" . $row_play['folder'] . "\"";
$query_for_recycle_bin_response = mysql_query($query_to_find_out_if_in_recycle_bin);
/*
* Is the file in the recycle bin?
*/
$row_recycle = db_query_one("SELECT folder_name FROM {$xerte_toolkits_site->database_table_prefix}folderdetails WHERE folder_id = ?", array($row_play['folder']));
if ($row_recycle['folder_name'] == "recyclebin") {
echo file_get_contents($xerte_toolkits_site->website_code_path . "error_top") . " " . PLAY_RESOURCE_FAIL . " </div></div></body></html>";
exit(0);
}
require_once $xerte_toolkits_site->php_library_path . "screen_size_library.php";
/*
* Ge show template functions for this 'module' / 'template framework'
*/
require_once $xerte_toolkits_site->root_file_path . "modules/" . $row_play['template_framework'] . "/play.php";
/*
* Fix for NULL number_of_uses
*/
db_query("UPDATE {$xerte_toolkits_site->database_table_prefix}templatedetails SET number_of_uses = 0 WHERE ISNULL(number_of_uses)");
/*
* Start to check the access_to_whom settings from templatedetails for this template
*/
if ($row_play['access_to_whom'] == "Private") {
/*
* Private - so do nothing
*/
dont_show_template();
} else if ($row_play['access_to_whom'] == "Public") {
/*
* Public - Increment the number of users and show the template
*/
db_query("UPDATE {$xerte_toolkits_site->database_table_prefix}templatedetails SET number_of_uses=number_of_uses+1 WHERE template_id=?", array($safe_template_id));
show_template($row_play);
} else if ($row_play['access_to_whom'] == "Password") {
/*
* Password protected - Check if there has been a post
*/
// if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require_once $xerte_toolkits_site->php_library_path . "login_library.php";
_load_language_file("/website_code/php/display_library.inc");
if (!isset($mysqli)) {
$mysqli = new mysqli($xerte_toolkits_site->database_host, $xerte_toolkits_site->database_username, $xerte_toolkits_site->database_password, $xerte_toolkits_site->database_name);
if ($mysqli->error) {
try {
throw new Exception("0MySQL error $mysqli->error <br> Query:<br> $query", $mysqli->errno);
} catch (Exception $e) {
echo "Error No: " . $e->getCode() . " - " . $e->getMessage() . "<br />";
echo nl2br($e->getTraceAsString());
}
}
}
if (!isset($lti)) {
require_once('LTI/ims-lti/UoN_LTI.php');
if (strlen($xerte_toolkits_site->database_table_prefix) > 0) {
$lti = new UoN_LTI($mysqli, array('table_prefix' => $xerte_toolkits_site->database_table_prefix));
} else {
$lti = new UoN_LTI($mysqli);
}
if(session_id()=='') {
session_start();
}
$lti->init_lti();
}
if($lti->valid) {
$success=true;
unset($errors);
} else {
$returnedproc = login_processing(false);
list($success, $errors) = $returnedproc;
}
if ($success && empty($errors)) {
//sucessfull authentication
db_query("UPDATE {$xerte_toolkits_site->database_table_prefix}templatedetails SET number_of_uses=number_of_uses+1 WHERE template_id=?", array($safe_template_id));
show_template($row_play);
} else {
html_headers();
login_prompt($errors);
}
/*
* Check the password
*/
/* $auth = Xerte_Authentication_Factory::create($xerte_toolkits_site->authentication_method);
if ($auth->check() && isset($_POST['login']) && isset($_POST['password']) && $auth->login($_POST['login'], $_POST['password'])) {
/*
* Update uses and display the template
*-/
db_query("UPDATE {$xerte_toolkits_site->database_table_prefix}templatedetails SET number_of_uses=number_of_uses+1 WHERE template_id=?", array($safe_template_id));
require $xerte_toolkits_site->root_file_path . "modules/" . $row_play['template_framework'] . "/play.php";
show_template($row_play);
} else {
/*
* Login failure
*-/
$buffer = $xerte_toolkits_site->form_string . $temp[1] . "<p>" . PLAY_LOGON_FAIL . ".</p></center></body></html>";
echo $buffer;
}
} else {
/*
* There has been no postage so echo the site variable to display the login string
*-/
echo $xerte_toolkits_site->form_string;*/
// }
} else if (substr($row_play['access_to_whom'], 0, 5) == "Other") {
/*
* The Other attribute has been set - so break the string down to obtain the host
*/
$test_string = substr($row_play['access_to_whom'], 6, strlen($row_play['access_to_whom']));
_debug("'Other' security is active for '" . $test_string . "', the current referrer is: '" . $_SERVER['HTTP_REFERER'] . "'");
/*
* Can only check against this variable, if I can't find it (say pop ups) no choice but to fail
*/
if (strlen($_SERVER['HTTP_REFERER']) != 0) {
if (strpos($_SERVER['HTTP_REFERER'], $test_string) == 0) {
db_query("UPDATE {$xerte_toolkits_site->database_table_prefix}templatedetails SET number_of_uses=number_of_uses+1 WHERE template_id=?", array($safe_template_id));
show_template($row_play);
} else {
dont_show_template('Doesnt Match Referer:' . $_SERVER['HTTP_REFERER']);
}
} else {
dont_show_template('No HTTP Referer');
}
} else if (sizeof($query_for_security_content_response) > 0) {
/*
* A setting from play_security_details might be in use, as such, check to see if it is, and then loop through checking if one is valid.
*/
$flag = false;
foreach ($query_for_security_content_response as $row_security) {
/*
* Check each setting to see if true
*/
if ($row_play['access_to_whom'] == $row_security['security_setting']) {
if (check_security_type($row_security['security_data'])) {
show_template($row_play);
$flag = true;
break;
} else {
$flag == false;
}
}
}
if ($flag == false) {
dont_show_template();
}
} else {
dont_show_template();
}