Merge lp:~dangarner/xibo/bug-455630 into lp:~xibo-maintainers/xibo/encke
- bug-455630
- Merge into encke
Proposed by
Dan Garner
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~dangarner/xibo/bug-455630 |
Merge into: | lp:~xibo-maintainers/xibo/encke |
Diff against target: |
1933 lines (+1742/-43) 10 files modified
server/install/database/7.sql (+4/-0) server/install/database/8.sql (+36/-16) server/lib/modules/module.class.php (+19/-0) server/lib/pages/content.class.php (+3/-18) server/modules/flash.module.php (+1/-1) server/modules/image.module.php (+1/-1) server/modules/powerpoint.module.php (+17/-6) server/modules/video.module.php (+1/-1) server/upgrade.php.OTHER (+598/-0) server/xmds.php (+1062/-0) |
To merge this branch: | bzr merge lp:~dangarner/xibo/bug-455630 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Xibo Maintainters | Pending | ||
Review via email: mp+15374@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'server/install/database/7.sql' |
2 | --- server/install/database/7.sql 2009-09-26 12:09:58 +0000 |
3 | +++ server/install/database/7.sql 2009-11-29 18:45:38 +0000 |
4 | @@ -21,4 +21,8 @@ |
5 | |
6 | UPDATE `version` SET `app_ver` = '1.0.3'; |
7 | UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE'; |
8 | +<<<<<<< TREE |
9 | UPDATE `version` SET `DBVersion` = '7'; |
10 | +======= |
11 | +UPDATE `version` SET `DBVersion` = '7'; |
12 | +>>>>>>> MERGE-SOURCE |
13 | |
14 | === modified file 'server/install/database/8.sql' |
15 | --- server/install/database/8.sql 2009-10-04 17:40:01 +0000 |
16 | +++ server/install/database/8.sql 2009-11-29 18:45:38 +0000 |
17 | @@ -1,16 +1,36 @@ |
18 | -ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` , |
19 | -ADD `FileSize` BIGINT NULL AFTER `MD5` ; |
20 | - |
21 | -ALTER TABLE `module` ADD `ValidExtensions` VARCHAR( 254 ) NULL ; |
22 | - |
23 | -UPDATE `module` SET `ValidExtensions` = 'jpg,jpeg,png,bmp,gif' WHERE `module`.`ModuleID` =1 LIMIT 1 ; |
24 | - |
25 | -UPDATE `module` SET `ValidExtensions` = 'wmv,avi,mpg,mpeg' WHERE `module`.`ModuleID` =2 LIMIT 1 ; |
26 | - |
27 | -UPDATE `module` SET `ValidExtensions` = 'swf' WHERE `module`.`ModuleID` =3 LIMIT 1 ; |
28 | - |
29 | -UPDATE `module` SET `ValidExtensions` = 'ppt,pps' WHERE `module`.`ModuleID` =4 LIMIT 1 ; |
30 | - |
31 | -UPDATE `version` SET `app_ver` = '1.0.4'; |
32 | -UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE'; |
33 | -UPDATE `version` SET `DBVersion` = '8'; |
34 | +<<<<<<< TREE |
35 | +ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` , |
36 | +ADD `FileSize` BIGINT NULL AFTER `MD5` ; |
37 | + |
38 | +ALTER TABLE `module` ADD `ValidExtensions` VARCHAR( 254 ) NULL ; |
39 | + |
40 | +UPDATE `module` SET `ValidExtensions` = 'jpg,jpeg,png,bmp,gif' WHERE `module`.`ModuleID` =1 LIMIT 1 ; |
41 | + |
42 | +UPDATE `module` SET `ValidExtensions` = 'wmv,avi,mpg,mpeg' WHERE `module`.`ModuleID` =2 LIMIT 1 ; |
43 | + |
44 | +UPDATE `module` SET `ValidExtensions` = 'swf' WHERE `module`.`ModuleID` =3 LIMIT 1 ; |
45 | + |
46 | +UPDATE `module` SET `ValidExtensions` = 'ppt,pps' WHERE `module`.`ModuleID` =4 LIMIT 1 ; |
47 | + |
48 | +UPDATE `version` SET `app_ver` = '1.0.4'; |
49 | +UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE'; |
50 | +UPDATE `version` SET `DBVersion` = '8'; |
51 | +======= |
52 | +ALTER TABLE `module` ADD `ValidExtensions` VARCHAR( 254 ) NULL ; |
53 | + |
54 | +UPDATE `module` SET `ValidExtensions` = 'jpg,jpeg,png,bmp,gif' WHERE `module`.`ModuleID` =1 LIMIT 1 ; |
55 | + |
56 | +UPDATE `module` SET `ValidExtensions` = 'wmv,avi,mpg,mpeg' WHERE `module`.`ModuleID` =2 LIMIT 1 ; |
57 | + |
58 | +UPDATE `module` SET `ValidExtensions` = 'swf' WHERE `module`.`ModuleID` =3 LIMIT 1 ; |
59 | + |
60 | +UPDATE `module` SET `ValidExtensions` = 'ppt,pps' WHERE `module`.`ModuleID` =4 LIMIT 1 ; |
61 | + |
62 | +/* Add the MD5 and FileSize as columns to the media table */ |
63 | +ALTER TABLE `media` ADD `MD5` VARCHAR( 32 ) NULL AFTER `storedAs` , |
64 | +ADD `FileSize` BIGINT NULL AFTER `MD5` ; |
65 | + |
66 | +UPDATE `version` SET `app_ver` = '1.0.4'; |
67 | +UPDATE `setting` SET `value` = 0 WHERE `setting` = 'PHONE_HOME_DATE'; |
68 | +UPDATE `version` SET `DBVersion` = '8'; |
69 | +>>>>>>> MERGE-SOURCE |
70 | |
71 | === modified file 'server/lib/modules/module.class.php' |
72 | --- server/lib/modules/module.class.php 2009-10-04 17:40:01 +0000 |
73 | +++ server/lib/modules/module.class.php 2009-11-29 18:45:38 +0000 |
74 | @@ -516,8 +516,15 @@ |
75 | */ |
76 | public function EditForm() |
77 | { |
78 | +<<<<<<< TREE |
79 | $form = '<p>' . __('Not yet implemented by this module.') . '</p>'; |
80 | |
81 | +======= |
82 | + $form = <<<END |
83 | + <p>Not yet implemented by this module.</p> |
84 | +END; |
85 | + |
86 | +>>>>>>> MERGE-SOURCE |
87 | $this->response->html = $form; |
88 | $this->response->dialogTitle = __('Add Item'); |
89 | $this->response->dialogSize = true; |
90 | @@ -534,9 +541,15 @@ |
91 | public function AddMedia() |
92 | { |
93 | // We want to load a new form |
94 | +<<<<<<< TREE |
95 | $this->response->message = __('Add Media has not been implemented for this module.'); |
96 | |
97 | return $this->response; |
98 | +======= |
99 | + $this->response->message = 'Add Media has not been implemented for this module.'; |
100 | + |
101 | + return $this->response; |
102 | +>>>>>>> MERGE-SOURCE |
103 | } |
104 | |
105 | /** |
106 | @@ -546,9 +559,15 @@ |
107 | public function EditMedia() |
108 | { |
109 | // We want to load a new form |
110 | +<<<<<<< TREE |
111 | $this->response->message = __('Edit Media has not been implemented for this module.'); |
112 | |
113 | return $this->response; |
114 | +======= |
115 | + $this->response->message = 'Edit Media has not been implemented for this module.'; |
116 | + |
117 | + return $this->response; |
118 | +>>>>>>> MERGE-SOURCE |
119 | } |
120 | |
121 | /** |
122 | |
123 | === modified file 'server/lib/pages/content.class.php' |
124 | --- server/lib/pages/content.class.php 2009-10-09 20:27:08 +0000 |
125 | +++ server/lib/pages/content.class.php 2009-11-29 18:45:38 +0000 |
126 | @@ -27,22 +27,6 @@ |
127 | private $isadmin = false; |
128 | private $has_permissions = true; |
129 | private $sub_page = ""; |
130 | - |
131 | - //Table Fields |
132 | - private $mediaid; |
133 | - private $name = ""; |
134 | - private $filepath = ""; |
135 | - private $type = ""; |
136 | - private $length = ""; |
137 | - private $width = ""; |
138 | - private $height = ""; |
139 | - private $permissionid; |
140 | - private $media_class = ""; |
141 | - private $retired; |
142 | - |
143 | - //are we redirecting to another page once we are done? |
144 | - private $redirect = false; |
145 | - private $redirect_addr = ""; |
146 | |
147 | function __construct(database $db, user $user) |
148 | { |
149 | @@ -653,8 +637,8 @@ |
150 | |
151 | if (isset($_FILES["media_file"]) && is_uploaded_file($_FILES["media_file"]["tmp_name"]) && $_FILES["media_file"]["error"] == 0) |
152 | { |
153 | - $error = 0; |
154 | - $fileName = $_FILES["media_file"]["name"]; |
155 | + $error = 0; |
156 | + $fileName = Kit::ValidateParam($_FILES["media_file"]["name"], _FILENAME); |
157 | $fileLocation = $libraryFolder."temp/".$fileId; |
158 | |
159 | // Save the FILE |
160 | @@ -697,6 +681,7 @@ |
161 | |
162 | echo $complete_page; |
163 | |
164 | + Debug::LogEntry($db, "audit", $complete_page, "FileUpload"); |
165 | Debug::LogEntry($db, "audit", "[OUT]", "FileUpload"); |
166 | exit; |
167 | } |
168 | |
169 | === modified file 'server/modules/flash.module.php' |
170 | --- server/modules/flash.module.php 2009-10-04 17:40:01 +0000 |
171 | +++ server/modules/flash.module.php 2009-11-29 18:45:38 +0000 |
172 | @@ -706,7 +706,7 @@ |
173 | } |
174 | |
175 | // Ensure the name is not already in the database |
176 | - $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid); |
177 | + $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0 ", $db->escape_string($name), $userid, $mediaid); |
178 | |
179 | if(!$result = $db->query($SQL)) |
180 | { |
181 | |
182 | === modified file 'server/modules/image.module.php' |
183 | --- server/modules/image.module.php 2009-10-04 17:40:01 +0000 |
184 | +++ server/modules/image.module.php 2009-11-29 18:45:39 +0000 |
185 | @@ -709,7 +709,7 @@ |
186 | } |
187 | |
188 | // Ensure the name is not already in the database |
189 | - $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid); |
190 | + $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0", $db->escape_string($name), $userid, $mediaid); |
191 | |
192 | if(!$result = $db->query($SQL)) |
193 | { |
194 | |
195 | === modified file 'server/modules/powerpoint.module.php' |
196 | --- server/modules/powerpoint.module.php 2009-10-04 17:40:01 +0000 |
197 | +++ server/modules/powerpoint.module.php 2009-11-29 18:45:39 +0000 |
198 | @@ -599,9 +599,14 @@ |
199 | $fileSize = filesize($databaseDir.$storedAs); |
200 | |
201 | // Update the media record to include this information |
202 | - |
203 | - $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid); |
204 | - |
205 | +<<<<<<< TREE |
206 | + |
207 | + $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid); |
208 | + |
209 | +======= |
210 | + $SQL = sprintf("UPDATE media SET storedAs = '%s', `MD5` = '%s', FileSize = %d WHERE mediaid = %d", $storedAs, $md5, $fileSize, $mediaid); |
211 | + |
212 | +>>>>>>> MERGE-SOURCE |
213 | if (!$db->query($SQL)) |
214 | { |
215 | trigger_error($db->error()); |
216 | @@ -663,8 +668,14 @@ |
217 | $fileName = Kit::GetParam('txtFileName', _POST, _STRING); |
218 | $fileName = basename($fileName); |
219 | $ext = strtolower(substr(strrchr($fileName, "."), 1)); |
220 | - |
221 | - if (!$this->IsValidExtension($ext)) |
222 | +<<<<<<< TREE |
223 | + |
224 | + if (!$this->IsValidExtension($ext)) |
225 | +======= |
226 | + |
227 | + |
228 | + if (!$this->IsValidExtension($ext)) |
229 | +>>>>>>> MERGE-SOURCE |
230 | { |
231 | $this->response->SetError('Your file has an extension not supported by this Media Type.'); |
232 | $this->response->keepOpen = true; |
233 | @@ -707,7 +718,7 @@ |
234 | } |
235 | |
236 | // Ensure the name is not already in the database |
237 | - $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid); |
238 | + $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0", $db->escape_string($name), $userid, $mediaid); |
239 | |
240 | if(!$result = $db->query($SQL)) |
241 | { |
242 | |
243 | === modified file 'server/modules/video.module.php' |
244 | --- server/modules/video.module.php 2009-10-04 17:40:01 +0000 |
245 | +++ server/modules/video.module.php 2009-11-29 18:45:39 +0000 |
246 | @@ -693,7 +693,7 @@ |
247 | } |
248 | |
249 | // Ensure the name is not already in the database |
250 | - $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d ", $db->escape_string($name), $userid, $mediaid); |
251 | + $SQL = sprintf("SELECT name FROM media WHERE name = '%s' AND userid = %d AND mediaid <> %d AND IsEdited = 0", $db->escape_string($name), $userid, $mediaid); |
252 | |
253 | if(!$result = $db->query($SQL)) |
254 | { |
255 | |
256 | === added file 'server/upgrade.php.OTHER' |
257 | --- server/upgrade.php.OTHER 1970-01-01 00:00:00 +0000 |
258 | +++ server/upgrade.php.OTHER 2009-11-29 18:45:38 +0000 |
259 | @@ -0,0 +1,598 @@ |
260 | +<?php |
261 | +/* |
262 | + * Xibo - Digitial Signage - http://www.xibo.org.uk |
263 | + * Copyright (C) 2009 Alex Harrington |
264 | + * |
265 | + * This file is part of Xibo. |
266 | + * |
267 | + * Xibo is free software: you can redistribute it and/or modify |
268 | + * it under the terms of the GNU Affero General Public License as published by |
269 | + * the Free Software Foundation, either version 3 of the License, or |
270 | + * any later version. |
271 | + * |
272 | + * Xibo is distributed in the hope that it will be useful, |
273 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
274 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
275 | + * GNU Affero General Public License for more details. |
276 | + * |
277 | + * You should have received a copy of the GNU Affero General Public License |
278 | + * along with Xibo. If not, see <http://www.gnu.org/licenses/>. |
279 | + */ |
280 | + |
281 | +DEFINE('XIBO', true); |
282 | + |
283 | +include('lib/app/kit.class.php'); |
284 | +include('config/db_config.php'); |
285 | +include('config/config.class.php'); |
286 | +require('settings.php'); |
287 | + |
288 | +// Once we've calculated the upgrade in step 2 below, we need |
289 | +// to have included the appropriate upgrade php files |
290 | +// before we restore the session, so objects get recreated properly. |
291 | +// |
292 | +// Check to see if we've passed that point, and if so look at what was posted |
293 | +// to include those classes. |
294 | + |
295 | +if (Kit::GetParam("includes", _POST, _BOOL)) { |
296 | + foreach ($_POST as $key => $post) { |
297 | + // $key should be like 1-2, 1-3 etc |
298 | + // Split $key on - character. |
299 | + |
300 | + $parts = explode('-', $key); |
301 | + if (count($parts) == 2) { |
302 | + $step = Kit::ValidateParam($parts[0], _INT); |
303 | + if (file_exists('install/database/' . $step . '.php')) { |
304 | + include_once('install/database/' . $step . '.php'); |
305 | + } |
306 | + } |
307 | + } |
308 | +} |
309 | + |
310 | +session_start(); |
311 | + |
312 | +define('_CHECKBOX', "checkbox"); |
313 | +define('_INPUTBOX', "inputbox"); |
314 | +define('_PASSWORDBOX', "password"); |
315 | + |
316 | +// create a database class instance |
317 | +$db = new database(); |
318 | + |
319 | +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()); |
320 | +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()); |
321 | + |
322 | +include('install/header_upgrade.inc'); |
323 | + |
324 | +if (! $_SESSION['step']) { |
325 | + $_SESSION['step'] = 0; |
326 | +} |
327 | + |
328 | +if (Kit::GetParam('skipstep',_POST,_INT) == 1) { |
329 | + // Cheat the $_SESSION['step'] variable if required |
330 | + // Used if there are environment warnings and we want to retest. |
331 | + $_SESSION['step'] = 1; |
332 | +} |
333 | + |
334 | +if ($_SESSION['step'] == 0) { |
335 | + |
336 | + $_SESSION['step'] = 1; |
337 | + |
338 | + # First step of the process. |
339 | + # Show a welcome screen and authenticate the user |
340 | + ?> |
341 | + Welcome to the Xibo Upgrade!<br /><br /> |
342 | + The upgrade program will take you through the process one step at a time.<br /><br /> |
343 | + Lets get started!<br /><br /> |
344 | + Please enter your xibo_admin password:<br /><br /> |
345 | + <form action="upgrade.php" method="POST"> |
346 | + <div class="install_table"> |
347 | + <input type="password" name="password" length="12" /> |
348 | + </div> |
349 | + <div class="loginbutton"><button type="submit">Next ></button></div> |
350 | + </form> |
351 | + <?php |
352 | +} |
353 | +elseif ($_SESSION['step'] == 1) { |
354 | + $_SESSION['step'] = 2; |
355 | + |
356 | + if (! $_SESSION['auth']) { |
357 | + |
358 | + # Check password |
359 | + |
360 | + $password = Kit::GetParam('password',_POST,_PASSWORD); |
361 | + $password_hash = md5($password); |
362 | + |
363 | + $SQL = sprintf("SELECT `UserID` FROM `user` WHERE UserPassword='%s' AND UserName='xibo_admin'", |
364 | + $db->escape_string($password_hash)); |
365 | + if (! $result = $db->query($SQL)) { |
366 | + reportError("0", "An error occured checking your password.<br /><br />MySQL Error:<br />" . mysql_error()); |
367 | + } |
368 | + |
369 | + if ($db->num_rows($result) == 0) { |
370 | + $_SESSION['auth'] = false; |
371 | + reportError("0", "Password incorrect. Please try again."); |
372 | + } |
373 | + else { |
374 | + $_SESSION['auth'] = true; |
375 | + $_SESSION['db'] = $db; |
376 | + } |
377 | + |
378 | + } |
379 | +## Check server meets specs (as specs might have changed in this release) |
380 | + ?> |
381 | + <p>First we need to check if your server meets Xibo's requirements.</p> |
382 | + <?php |
383 | + $db = new Database(); |
384 | + $cObj = new Config($db); |
385 | + echo $cObj->CheckEnvironment(); |
386 | + if ($cObj->EnvironmentFault()) { |
387 | + $_SESSION['step'] = 1; |
388 | + ?> |
389 | + <form action="upgrade.php" method="POST"> |
390 | + <div class="loginbutton"><button type="submit">Retest</button></div> |
391 | + </form> |
392 | + <?php |
393 | + } |
394 | + else if ($cObj->EnvironmentWarning()) { |
395 | + ?> |
396 | + <form action="upgrade.php" method="POST"> |
397 | + <input type="hidden" name="skipstep" value="1"> |
398 | + <div class="loginbutton"><button type="submit">Retest</button></div> |
399 | + </form> |
400 | + <form action="upgrade.php" method="POST"> |
401 | + <div class="loginbutton"><button type="submit">Next ></button></div> |
402 | + </form> |
403 | + <?php |
404 | + } |
405 | + else { |
406 | + ?> |
407 | + <form action="upgrade.php" method="POST"> |
408 | + <div class="loginbutton"><button type="submit">Next ></button></div> |
409 | + </form> |
410 | + <?php |
411 | + } |
412 | +} |
413 | +elseif ($_SESSION['step'] == 2) { |
414 | + checkAuth(); |
415 | +# Calculate the upgrade |
416 | + |
417 | + $_SESSION['upgradeFrom'] = Config::Version($db, 'DBVersion'); |
418 | + |
419 | + if ($_SESSION['upgradeFrom'] < 1) { |
420 | + $_SESSION['upgradeFrom'] = 1; |
421 | + } |
422 | + |
423 | + // Get a list of .sql and .php files for the upgrade |
424 | + $sql_files = ls('*.sql','install/database',false,array('return_files')); |
425 | + $php_files = ls('*.php','install/database',false,array('return_files')); |
426 | + |
427 | + // Sort by natural filename (eg 10 is bigger than 2) |
428 | + natcasesort($sql_files); |
429 | + natcasesort($php_files); |
430 | + |
431 | + $_SESSION['phpFiles'] = $php_files; |
432 | + $_SESSION['sqlFiles'] = $sql_files; |
433 | + |
434 | + $max_sql = Kit::ValidateParam(substr(end($sql_files),0,-4),_INT); |
435 | + $max_php = Kit::ValidateParam(substr(end($php_files),0,-4),_INT); |
436 | + $_SESSION['upgradeTo'] = max($max_sql, $max_php); |
437 | + |
438 | + if (! $_SESSION['upgradeTo']) { |
439 | + reportError("2", "Unable to calculate the upgradeTo value. Check for non-numeric SQL and PHP files in the 'install/datbase' directory.", "Retry"); |
440 | + } |
441 | + |
442 | + echo '<div class="info">'; |
443 | + echo '<p>Upgrading from database version ' . $_SESSION['upgradeFrom'] . ' to ' . $_SESSION['upgradeTo']; |
444 | + echo '</p></div><hr width="25%"/>'; |
445 | + echo '<form action="upgrade.php" method="POST">'; |
446 | + |
447 | + // Loop for $i between upgradeFrom + 1 and upgradeTo. |
448 | + // If a php file exists for that upgrade, make an instance of it and call Questions so we can |
449 | + // Ask the user for input. |
450 | + for ($i=$_SESSION['upgradeFrom'] + 1; $i <= $_SESSION['upgradeTo']; $i++) { |
451 | + if (file_exists('install/database/' . $i . '.php')) { |
452 | + include_once('install/database/' . $i . '.php'); |
453 | + $stepName = 'Step' . $i; |
454 | + |
455 | + // Check that a class called Step$i exists |
456 | + if (class_exists($stepName)) { |
457 | + $_SESSION['Step' . $i] = new $stepName($db); |
458 | + // Call Questions on the object and send the resulting hash to createQuestions routine |
459 | + createQuestions($i, $_SESSION['Step' . $i]->Questions()); |
460 | + } |
461 | + else { |
462 | + print "Warning: We included $i.php, but it did not include a class of appropriate name."; |
463 | + } |
464 | + } |
465 | + } |
466 | + |
467 | + echo '<div class="info"><p>'; |
468 | + echo "Perform automatic database upgrade?"; |
469 | + echo '</p></div><div class="install-table">'; |
470 | + echo '<input type="checkbox" name="doBackup" checked />'; |
471 | + echo '</div><hr width="25%" />'; |
472 | + |
473 | + $_SESSION['step'] = 3; |
474 | + echo '<input type="hidden" name="includes" value="true" />'; |
475 | + echo '<p><input type="submit" value="Next >" /></p>'; |
476 | + echo '</form>'; |
477 | + |
478 | +?> |
479 | + <?php |
480 | +} |
481 | +elseif ($_SESSION['step'] == 3) { |
482 | + // $_SESSION['step'] = 0; |
483 | + $fault = false; |
484 | + $fault_string = ""; |
485 | + |
486 | + foreach ($_POST as $key => $post) { |
487 | + // $key should be like 1-2, 1-3 etc |
488 | + // Split $key on - character. |
489 | + |
490 | + $parts = explode('-', $key); |
491 | + if (count($parts) == 2) { |
492 | + $step_num = 'Step' . $parts[0]; |
493 | + include_once('install/database/' . $parts[0] . '.php'); |
494 | + // $_SESSION['q'][$step_num] = unserialize($_SESSION['q'][$step_num]); |
495 | +; |
496 | + $response = $_SESSION[$step_num]->ValidateQuestion($parts[1], $post); |
497 | + if (! $response == true) { |
498 | + // The upgrade routine for this step wasn't happy. |
499 | + $fault = true; |
500 | + $fault_string .= $response . "<br />\n"; |
501 | + } |
502 | + } |
503 | + } |
504 | + |
505 | + if ($fault) { |
506 | + // Report the error, and a back button |
507 | + echo "FAIL: " . $fault_string; |
508 | + } |
509 | + else { |
510 | + $doBackup = Kit::GetParam("doBackup", $_POST, _BOOL); |
511 | + |
512 | + set_time_limit(0); |
513 | + // Backup the database |
514 | + echo '<div class="info"><p>'; |
515 | + if ($doBackup) { |
516 | + echo 'Backing up your database'; |
517 | + backup_tables($db, '*'); |
518 | + } |
519 | + else { |
520 | + echo 'Skipping database backup'; |
521 | + } |
522 | + echo '</p>'; |
523 | + |
524 | + $sqlStatementCount = 0; |
525 | + // Now loop over the entire upgrade. Run the SQLs and PHP interleaved. |
526 | + for ($i=$_SESSION['upgradeFrom'] + 1; (($i <= $_SESSION['upgradeTo']) && ($fault==false)) ; $i++) { |
527 | + if (file_exists('install/database/' . $i . '.sql')) { |
528 | + echo '<p>' . $i . '.sql '; |
529 | + flush(); |
530 | + $delimiter = ';'; |
531 | + $sql_file = @file_get_contents('install/database/' . $i . '.sql'); |
532 | + $sql_file = remove_remarks($sql_file); |
533 | + $sql_file = split_sql_file($sql_file, $delimiter); |
534 | + |
535 | + foreach ($sql_file as $sql) { |
536 | + print "."; |
537 | + $sqlStatementCount++; |
538 | + flush(); |
539 | + if (! $db->query($sql)) { |
540 | + $fault = true; |
541 | + 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); |
542 | + } |
543 | + } |
544 | + echo '</p>'; |
545 | + } |
546 | + if (file_exists('install/database/' . $i . '.php')) { |
547 | + $stepName = 'Step' . $i; |
548 | + echo '<p>' . $i . '.php '; |
549 | + flush(); |
550 | + if (! $_SESSION[$stepName]->Boot()) { |
551 | + $fault = true; |
552 | + } |
553 | + echo '</p>'; |
554 | + } |
555 | + } |
556 | + echo '</div>'; |
557 | + if (! $fault) { |
558 | + if (! unlink('install.php')) { |
559 | + echo "Unable to delete install.php. Please remove this file manually."; |
560 | + } |
561 | + if (! unlink('upgrade.php')) { |
562 | + echo "Unable to delete upgrade.php. Please remove this file manually."; |
563 | + } |
564 | + |
565 | + echo '<b>Upgrade is complete!</b><br /><br />'; |
566 | + echo '<form method="POST" action="index.php">'; |
567 | + echo '<input type="submit" value="Login" />'; |
568 | + echo '</form>'; |
569 | + } |
570 | + else { |
571 | + echo '<b>There was an error during the upgrade. Please take a screenshot of this page and seek help!</b>'; |
572 | + } |
573 | + session_destroy(); |
574 | + } |
575 | +} |
576 | +else { |
577 | + reportError("0","A required parameter was missing. Please go through the installer sequentially!","Start Again"); |
578 | +} |
579 | + |
580 | +include('install/footer.inc'); |
581 | + |
582 | +# Functions |
583 | +function checkPHP() { |
584 | + # Check PHP version > 5 |
585 | + return (version_compare("5.1.0",phpversion(), "<=")); |
586 | +} |
587 | + |
588 | +function reportError($step, $message, $button_text="< Back") { |
589 | + $_SESSION['step'] = $step; |
590 | +?> |
591 | + <div class="info"> |
592 | + <?php print $message; ?> |
593 | + </div> |
594 | + <form action="upgrade.php" method="POST"> |
595 | + <button type="submit"><?php print $button_text; ?></button> |
596 | + </form> |
597 | + <?php |
598 | + include('install/footer.inc'); |
599 | + die(); |
600 | +} |
601 | + |
602 | +function checkAuth() { |
603 | + if (! $_SESSION['auth']) { |
604 | + reportError(1, "You must authenticate to run the upgrade."); |
605 | + } |
606 | +} |
607 | + |
608 | +// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html |
609 | +// By Crackster |
610 | +/** |
611 | + * remove_remarks will strip the sql comment lines out of an uploaded sql file |
612 | + */ |
613 | +function remove_remarks($sql){ |
614 | + $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^[-].*$/m', "\n", $sql)); |
615 | + $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql)); |
616 | + return $sql; |
617 | +} |
618 | + |
619 | +// Taken from http://forums.devshed.com/php-development-5/php-wont-load-sql-from-file-515902.html |
620 | +// By Crackster |
621 | +/** |
622 | + * split_sql_file will split an uploaded sql file into single sql statements. |
623 | + * Note: expects trim() to have already been run on $sql. |
624 | + */ |
625 | +function split_sql_file($sql, $delimiter){ |
626 | + $sql = str_replace("\r" , '', $sql); |
627 | + $data = preg_split('/' . preg_quote($delimiter, '/') . '$/m', $sql); |
628 | + $data = array_map('trim', $data); |
629 | + // The empty case |
630 | + $end_data = end($data); |
631 | + if (empty($end_data)) |
632 | + { |
633 | + unset($data[key($data)]); |
634 | + } |
635 | + return $data; |
636 | +} |
637 | + |
638 | +/** |
639 | + * This funtion will take a pattern and a folder as the argument and go thru it(recursivly if needed)and return the list of |
640 | + * all files in that folder. |
641 | + * Link : http://www.bin-co.com/php/scripts/filesystem/ls/ |
642 | + * License : BSD |
643 | + * Arguments : $pattern - The pattern to look out for [OPTIONAL] |
644 | + * $folder - The path of the directory of which's directory list you want [OPTIONAL] |
645 | + * $recursivly - The funtion will traverse the folder tree recursivly if this is true. Defaults to false. [OPTIONAL] |
646 | + * $options - An array of values 'return_files' or 'return_folders' or both |
647 | + * Returns : A flat list with the path of all the files(no folders) that matches the condition given. |
648 | + */ |
649 | +function ls($pattern="*", $folder="", $recursivly=false, $options=array('return_files','return_folders')) { |
650 | + if($folder) { |
651 | + $current_folder = realpath('.'); |
652 | + if(in_array('quiet', $options)) { // If quiet is on, we will suppress the 'no such folder' error |
653 | + if(!file_exists($folder)) return array(); |
654 | + } |
655 | + |
656 | + if(!chdir($folder)) return array(); |
657 | + } |
658 | + |
659 | + |
660 | + $get_files = in_array('return_files', $options); |
661 | + $get_folders= in_array('return_folders', $options); |
662 | + $both = array(); |
663 | + $folders = array(); |
664 | + |
665 | + // Get the all files and folders in the given directory. |
666 | + if($get_files) $both = glob($pattern, GLOB_BRACE + GLOB_MARK); |
667 | + if($recursivly or $get_folders) $folders = glob("*", GLOB_ONLYDIR + GLOB_MARK); |
668 | + |
669 | + //If a pattern is specified, make sure even the folders match that pattern. |
670 | + $matching_folders = array(); |
671 | + if($pattern !== '*') $matching_folders = glob($pattern, GLOB_ONLYDIR + GLOB_MARK); |
672 | + |
673 | + //Get just the files by removing the folders from the list of all files. |
674 | + $all = array_values(array_diff($both,$folders)); |
675 | + |
676 | + if($recursivly or $get_folders) { |
677 | + foreach ($folders as $this_folder) { |
678 | + if($get_folders) { |
679 | + //If a pattern is specified, make sure even the folders match that pattern. |
680 | + if($pattern !== '*') { |
681 | + if(in_array($this_folder, $matching_folders)) array_push($all, $this_folder); |
682 | + } |
683 | + else array_push($all, $this_folder); |
684 | + } |
685 | + |
686 | + if($recursivly) { |
687 | + // Continue calling this function for all the folders |
688 | + $deep_items = ls($pattern, $this_folder, $recursivly, $options); # :RECURSION: |
689 | + foreach ($deep_items as $item) { |
690 | + array_push($all, $this_folder . $item); |
691 | + } |
692 | + } |
693 | + } |
694 | + } |
695 | + |
696 | + if($folder) chdir($current_folder); |
697 | + return $all; |
698 | +} |
699 | + |
700 | +// Taken from http://davidwalsh.name/backup-mysql-database-php |
701 | +// No explicit license. Assumed public domain. |
702 | +// Ammended to use a database object by Alex Harrington. |
703 | +// If this is your code, and wish for us to remove it, please contact |
704 | +// info@xibo.org.uk |
705 | +/* backup the db OR just a table */ |
706 | +function backup_tables($db,$tables = '*') |
707 | +{ |
708 | + //get all of the tables |
709 | + if($tables == '*') |
710 | + { |
711 | + $tables = array(); |
712 | + $result = $db->query('SHOW TABLES'); |
713 | + while($row = $db->get_row($result)) |
714 | + { |
715 | + $tables[] = $row[0]; |
716 | + } |
717 | + } |
718 | + else |
719 | + { |
720 | + $tables = is_array($tables) ? $tables : explode(',',$tables); |
721 | + } |
722 | + |
723 | + // Open file for writing at length 0. |
724 | + $handle = fopen(Config::GetSetting($db,'LIBRARY_LOCATION') . 'db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); |
725 | + |
726 | + //cycle through |
727 | + foreach($tables as $table) |
728 | + { |
729 | + echo '.'; |
730 | + flush(); |
731 | + $result = $db->query('SELECT * FROM `'.$table .'`'); |
732 | + $num_fields = $db->num_fields($result); |
733 | + |
734 | + $return = 'DROP TABLE IF EXISTS `'.$table.'`;'; |
735 | + fwrite($handle, $return); |
736 | + |
737 | + $row2 = $db->get_row($db->query('SHOW CREATE TABLE `'.$table.'`')); |
738 | + $return = "\n\n".$row2[1].";\n\n"; |
739 | + fwrite($handle,$return); |
740 | + |
741 | + for ($i = 0; $i < $num_fields; $i++) |
742 | + { |
743 | + while($row = $db->get_row($result)) |
744 | + { |
745 | + $return = 'INSERT INTO `'.$table.'` VALUES('; |
746 | + fwrite($handle, $return); |
747 | + for($j=0; $j<$num_fields; $j++) |
748 | + { |
749 | + $return = ''; |
750 | + $row[$j] = addslashes($row[$j]); |
751 | + $row[$j] = ereg_replace("\n","\\n",$row[$j]); |
752 | + if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } |
753 | + if ($j<($num_fields-1)) { $return.= ','; } |
754 | + fwrite($handle, $return); |
755 | + } |
756 | + $return = ");\n"; |
757 | + fwrite($handle, $return); |
758 | + } |
759 | + } |
760 | + $return ="\n\n\n"; |
761 | + fwrite ($handle, $return); |
762 | + } |
763 | + |
764 | + fclose($handle); |
765 | +} |
766 | + |
767 | + |
768 | +function gen_secret() { |
769 | + # Generates a random 12 character alphanumeric string to use as a salt |
770 | + mt_srand((double)microtime()*1000000); |
771 | + $key = ""; |
772 | + for ($i=0; $i < 12; $i++) { |
773 | + $c = mt_rand(0,2); |
774 | + if ($c == 0) { |
775 | + $key .= chr(mt_rand(65,90)); |
776 | + } |
777 | + elseif ($c == 1) { |
778 | + $key .= chr(mt_rand(97,122)); |
779 | + } |
780 | + else { |
781 | + $key .= chr(mt_rand(48,57)); |
782 | + } |
783 | + } |
784 | + |
785 | + return $key; |
786 | +} |
787 | + |
788 | +function createQuestions($step, $questions) { |
789 | + // Takes a multi-dimensional array eg: |
790 | + // $q[0]['question'] = "May we collect anonymous usage statistics?"; |
791 | + // $q[0]['type'] = _CHECKBOX; |
792 | + // $q[0]['default'] = true; |
793 | + // |
794 | + // And turns it in to an HTML form for the user to complete. |
795 | + foreach ($questions as $qnum => $question) { |
796 | + echo '<div class="info"><p>'; |
797 | + echo $question['question']; |
798 | + echo '</p></div><div class="install-table">'; |
799 | + |
800 | + if (($question['type'] == _INPUTBOX) || ($question['type'] == _PASSWORD)) { |
801 | + echo '<input type="'; |
802 | + if ($question['type'] == _INPUTBOX) { |
803 | + echo 'text'; |
804 | + } |
805 | + else { |
806 | + echo 'password'; |
807 | + } |
808 | + echo '" name="' . $step . '-' . $qnum .'" value="'. $question['default'] .'" length="12" />'; |
809 | + } |
810 | + elseif ($question['type'] == _CHECKBOX) { |
811 | + echo '<input type="checkbox" name="' . $step . '-' . $qnum . '" '; |
812 | + if ($question['default']) { |
813 | + echo 'checked '; |
814 | + } |
815 | + echo '/>'; |
816 | + } |
817 | + echo '</div><hr width="25%" />'; |
818 | + } |
819 | +} |
820 | + |
821 | +//function __autoload($class_name) { |
822 | +// if (substr($class_name,0,4) == "Step") { |
823 | +// $class_name = substr($class_name,4); |
824 | +// require_once install/database/$class_name . '.php'; |
825 | +// } |
826 | +//} |
827 | + |
828 | +class UpgradeStep |
829 | +{ |
830 | + protected $db; |
831 | + protected $q; |
832 | + protected $a; |
833 | + |
834 | + public function __construct($db) |
835 | + { |
836 | + $this->db =& $db; |
837 | + $this->q = array(); |
838 | + $this->a = array(); |
839 | + } |
840 | + |
841 | + public function Boot() |
842 | + { |
843 | + |
844 | + } |
845 | + |
846 | + public function Questions() |
847 | + { |
848 | + return array(); |
849 | + } |
850 | + |
851 | + public function ValidateQuestion($questionNumber,$response) |
852 | + { |
853 | + return true; |
854 | + } |
855 | +} |
856 | + |
857 | +?> |
858 | |
859 | === modified file 'server/xmds.php' |
860 | --- server/xmds.php 2009-11-26 20:03:41 +0000 |
861 | +++ server/xmds.php 2009-11-29 18:45:38 +0000 |
862 | @@ -1,3 +1,4 @@ |
863 | +<<<<<<< TREE |
864 | <?php |
865 | /* |
866 | * Xibo - Digitial Signage - http://www.xibo.org.uk |
867 | @@ -1060,4 +1061,1065 @@ |
868 | |
869 | //Debug::LogEntry($db, 'audit', $service->debug_str, "xmds", "NuSOAP"); |
870 | |
871 | +======= |
872 | +<?php |
873 | +/* |
874 | + * Xibo - Digitial Signage - http://www.xibo.org.uk |
875 | + * Copyright (C) 2006,2007,2008 Daniel Garner and James Packer |
876 | + * |
877 | + * This file is part of Xibo. |
878 | + * |
879 | + * Xibo is free software: you can redistribute it and/or modify |
880 | + * it under the terms of the GNU Affero General Public License as published by |
881 | + * the Free Software Foundation, either version 3 of the License, or |
882 | + * any later version. |
883 | + * |
884 | + * Xibo is distributed in the hope that it will be useful, |
885 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
886 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
887 | + * GNU Affero General Public License for more details. |
888 | + * |
889 | + * You should have received a copy of the GNU Affero General Public License |
890 | + * along with Xibo. If not, see <http://www.gnu.org/licenses/>. |
891 | + */ |
892 | + DEFINE('XIBO', true); |
893 | + include_once("lib/xmds.inc.php"); |
894 | + |
895 | +/** |
896 | + * Auths the hardwareKey |
897 | + * @return True is licensed, False if not |
898 | + * @param $hardwareKey Object |
899 | + */ |
900 | +function Auth($hardwareKey) |
901 | +{ |
902 | + global $db; |
903 | + |
904 | + //check in the database for this hardwareKey |
905 | + $SQL = "SELECT licensed, inc_schedule, isAuditing, displayID FROM display WHERE license = '$hardwareKey'"; |
906 | + if (!$result = $db->query($SQL)) |
907 | + { |
908 | + trigger_error("License key query failed:" .$db->error()); |
909 | + return false; |
910 | + } |
911 | + |
912 | + //Is it there? |
913 | + if ($db->num_rows($result) == 0) |
914 | + { |
915 | + return false; |
916 | + } |
917 | + else |
918 | + { |
919 | + //we have seen this display before, so check the licensed value |
920 | + $row = $db->get_row($result); |
921 | + if ($row[0] == 0) |
922 | + { |
923 | + return false; |
924 | + } |
925 | + else |
926 | + { |
927 | + $time = date("Y-m-d H:i:s", time()); |
928 | + |
929 | + //Set the last accessed flag on the display |
930 | + $SQL = "UPDATE display SET lastaccessed = '$time', loggedin = 1 WHERE license = '$hardwareKey' "; |
931 | + if (!$result = $db->query($SQL)) |
932 | + { |
933 | + trigger_error("Display update access failure: " .$db->error()); |
934 | + } |
935 | + |
936 | + //It is licensed |
937 | + return array("licensed" => true, "inc_schedule" => $row[1], "isAuditing" => $row[2], "displayid" => $row[3]); |
938 | + } |
939 | + } |
940 | + |
941 | + return false; |
942 | +} |
943 | + |
944 | +/** |
945 | + * Checks that the calling service is talking the correct version |
946 | + * @return |
947 | + * @param $version Object |
948 | + */ |
949 | +function CheckVersion($version) |
950 | +{ |
951 | + global $db; |
952 | + |
953 | + // Look up the Service XMDS version from the Version table |
954 | + $serverVersion = Config::Version($db, 'XmdsVersion'); |
955 | + |
956 | + if ($version != $serverVersion) |
957 | + { |
958 | + Debug::LogEntry($db, 'audit', sprintf('A Client with an incorrect version connected. Client Version: [%s] Server Version [%s]', $version, $serverVersion)); |
959 | + return false; |
960 | + } |
961 | + |
962 | + return true; |
963 | +} |
964 | + |
965 | +/** |
966 | + * Registers the Display with the server - if there is an available slot |
967 | + * @return |
968 | + * @param $serverKey Object |
969 | + * @param $hardwareKey Object |
970 | + * @param $displayName Object |
971 | + */ |
972 | +function RegisterDisplay($serverKey, $hardwareKey, $displayName, $version) |
973 | +{ |
974 | + global $db; |
975 | + |
976 | + // Sanitize |
977 | + $serverKey = Kit::ValidateParam($serverKey, _STRING); |
978 | + $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); |
979 | + $displayName = Kit::ValidateParam($displayName, _STRING); |
980 | + $version = Kit::ValidateParam($version, _STRING); |
981 | + |
982 | + // Make sure we are talking the same language |
983 | + if (!CheckVersion($version)) |
984 | + { |
985 | + return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey); |
986 | + } |
987 | + |
988 | + define('SERVER_KEY', Config::GetSetting($db, 'SERVER_KEY')); |
989 | + |
990 | + Debug::LogEntry($db, "audit", "[IN]", "xmds", "RegisterDisplay"); |
991 | + Debug::LogEntry($db, "audit", "serverKey [$serverKey], hardwareKey [$hardwareKey], displayName [$displayName]", "xmds", "RegisterDisplay"); |
992 | + |
993 | + //Check the serverKey matches the one we have stored in this servers lic.txt file |
994 | + if ($serverKey != SERVER_KEY) |
995 | + { |
996 | + return new soap_fault("SOAP-ENV:Client", "", "The Server key you entered does not match with the server key at this address", $serverKey); |
997 | + } |
998 | + |
999 | + // Check the Length of the hardwareKey |
1000 | + if (strlen($hardwareKey) > 40) |
1001 | + { |
1002 | + return new soap_fault("SOAP-ENV:Client", "", "The Hardware Key you sent was too long. Only 40 characters are allowed (SHA1).", $hardwareKey); |
1003 | + } |
1004 | + |
1005 | + //check in the database for this hardwareKey |
1006 | + $SQL = "SELECT licensed, display FROM display WHERE license = '$hardwareKey'"; |
1007 | + if (!$result = $db->query($SQL)) |
1008 | + { |
1009 | + trigger_error("License key query failed:" .$db->error()); |
1010 | + return new soap_fault("SOAP-ENV:Server", "", "License Key Query Failed, see server errorlog", $db->error()); |
1011 | + } |
1012 | + |
1013 | + //Is it there? |
1014 | + if ($db->num_rows($result) == 0) |
1015 | + { |
1016 | + //Add this display record |
1017 | + $SQL = sprintf("INSERT INTO display (display, defaultlayoutid, license, licensed) VALUES ('%s', 1, '%s', 0)", $displayName, $hardwareKey); |
1018 | + if (!$displayid = $db->insert_query($SQL)) |
1019 | + { |
1020 | + trigger_error($db->error()); |
1021 | + return new soap_fault("SOAP-ENV:Server", "", "Error adding display"); |
1022 | + } |
1023 | + $active = "Display added and is awaiting licensing approval from an Administrator"; |
1024 | + } |
1025 | + else |
1026 | + { |
1027 | + //we have seen this display before, so check the licensed value |
1028 | + $row = $db->get_row($result); |
1029 | + if ($row[0] == 0) |
1030 | + { |
1031 | + //Its Not licensed |
1032 | + $active = "Display is awaiting licensing approval from an Administrator."; |
1033 | + } |
1034 | + else |
1035 | + { |
1036 | + //It is licensed |
1037 | + //Now check the names |
1038 | + if ($row[1] == $displayName) |
1039 | + { |
1040 | + $active = "Display is active and ready to start."; |
1041 | + } |
1042 | + else |
1043 | + { |
1044 | + //Update the name |
1045 | + $SQL = sprintf("UPDATE display SET display = '%s' WHERE license = '%s' ", $displayName, $hardwareKey); |
1046 | + |
1047 | + if (!$db->query($SQL)) |
1048 | + { |
1049 | + trigger_error($db->error()); |
1050 | + return new soap_fault("SOAP-ENV:Server", "", "Error editing the display name"); |
1051 | + } |
1052 | + |
1053 | + $active = "Changed display name from '{$row[1]}' to '$displayName' Display is active and ready to start."; |
1054 | + } |
1055 | + } |
1056 | + } |
1057 | + |
1058 | + Debug::LogEntry($db, "audit", "$active", "xmds", "RegisterDisplay"); |
1059 | + Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RegisterDisplay"); |
1060 | + |
1061 | + return $active; |
1062 | +} |
1063 | + |
1064 | +/** |
1065 | + * Returns a string containing the required files xml for the requesting display |
1066 | + * @param string $hardwareKey Display Hardware Key |
1067 | + * @return string $requiredXml Xml Formatted String |
1068 | + */ |
1069 | +function RequiredFiles($serverKey, $hardwareKey, $version) |
1070 | +{ |
1071 | + global $db; |
1072 | + |
1073 | + // Sanitize |
1074 | + $serverKey = Kit::ValidateParam($serverKey, _STRING); |
1075 | + $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); |
1076 | + $version = Kit::ValidateParam($version, _STRING); |
1077 | + |
1078 | + // Make sure we are talking the same language |
1079 | + if (!CheckVersion($version)) |
1080 | + { |
1081 | + return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey); |
1082 | + } |
1083 | + |
1084 | + $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION"); |
1085 | + |
1086 | + //auth this request... |
1087 | + if (!$displayInfo = Auth($hardwareKey)) |
1088 | + { |
1089 | + trigger_error("This display is not licensed [$hardwareKey]"); |
1090 | + return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed"); |
1091 | + } |
1092 | + |
1093 | + if ($displayInfo['isAuditing'] == 1) |
1094 | + { |
1095 | + Debug::LogEntry($db, "audit", "[IN]", "xmds", "RequiredFiles"); |
1096 | + Debug::LogEntry($db, "audit", "$hardwareKey", "xmds", "RequiredFiles"); |
1097 | + } |
1098 | + |
1099 | + $requiredFilesXml = new DOMDocument("1.0"); |
1100 | + $fileElements = $requiredFilesXml->createElement("files"); |
1101 | + |
1102 | + $requiredFilesXml->appendChild($fileElements); |
1103 | + |
1104 | + $currentdate = date("Y-m-d H:i:s"); |
1105 | + $time = time(); |
1106 | + $plus4hours = date("Y-m-d H:i:s",$time + 86400); |
1107 | + |
1108 | + //Add file nodes to the $fileElements |
1109 | + //Firstly get all the scheduled layouts |
1110 | + $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, layout.xml, layout.background "; |
1111 | + $SQL .= " FROM layout "; |
1112 | + $SQL .= " INNER JOIN schedule_detail ON schedule_detail.layoutID = layout.layoutID "; |
1113 | + $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID "; |
1114 | + $SQL .= sprintf(" WHERE display.license = '%s' ", $hardwareKey); |
1115 | + |
1116 | + $SQLBase = $SQL; |
1117 | + |
1118 | + //Do we include the default display |
1119 | + if ($displayInfo['inc_schedule'] == 1) |
1120 | + { |
1121 | + $SQL .= sprintf(" AND ((schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate); |
1122 | + $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))"; |
1123 | + } |
1124 | + else |
1125 | + { |
1126 | + $SQL .= sprintf(" AND (schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate); |
1127 | + } |
1128 | + |
1129 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "RequiredFiles"); |
1130 | + |
1131 | + if (!$results = $db->query($SQL)) |
1132 | + { |
1133 | + trigger_error($db->error()); |
1134 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error()); |
1135 | + } |
1136 | + |
1137 | + // Was there anything? |
1138 | + if ($db->num_rows($results) == 0) |
1139 | + { |
1140 | + // No rows, run the query for default layout |
1141 | + $SQL = $SQLBase; |
1142 | + $SQL .= sprintf(" AND ((schedule_detail.starttime < '%s' AND schedule_detail.endtime > '%s' )", $plus4hours, $currentdate); |
1143 | + $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))"; |
1144 | + |
1145 | + if (!$results = $db->query($SQL)) |
1146 | + { |
1147 | + trigger_error($db->error()); |
1148 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error()); |
1149 | + } |
1150 | + } |
1151 | + |
1152 | + while ($row = $db->get_row($results)) |
1153 | + { |
1154 | + $layoutid = $row[0]; |
1155 | + $layoutXml = $row[3]; |
1156 | + $background = $row[4]; |
1157 | + |
1158 | + // Add all the associated media first |
1159 | + $SQL = "SELECT storedAs, media.mediaID, media.`MD5`, media.FileSize |
1160 | + FROM media |
1161 | + INNER JOIN lklayoutmedia ON lklayoutmedia.mediaID = media.mediaID |
1162 | + WHERE storedAs IS NOT NULL |
1163 | + AND lklayoutmedia.layoutID = $layoutid |
1164 | + AND media.mediaID NOT IN (SELECT MediaID |
1165 | + FROM blacklist |
1166 | + WHERE DisplayID = " . $displayInfo['displayid'] . " |
1167 | + AND isIgnored = 0 )"; |
1168 | + |
1169 | + if (!$mediaResults = $db->query($SQL)) |
1170 | + { |
1171 | + trigger_error($db->error()); |
1172 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of media for the layout [$layoutid]"); |
1173 | + } |
1174 | + |
1175 | + while ($row = $db->get_row($mediaResults)) |
1176 | + { |
1177 | + $storedAs = Kit::ValidateParam($row[0], _STRING); |
1178 | + $mediaId = Kit::ValidateParam($row[1], _INT); |
1179 | + $md5 = Kit::ValidateParam($row[2], _STRING); |
1180 | + $fileSize = Kit::ValidateParam($row[3], _INT); |
1181 | + |
1182 | + // If they are empty calculate them and save them back to the media. |
1183 | + if ($md5 == '' || $fileSize == 0) |
1184 | + { |
1185 | + |
1186 | + $md5 = md5_file($libraryLocation.$row[0]); |
1187 | + $fileSize = filesize($libraryLocation.$row[0]); |
1188 | + |
1189 | + // Update the media record with this information |
1190 | + $SQL = sprintf("UPDATE media SET `MD5` = '%s', FileSize = %d WHERE MediaID = %d", $md5, $fileSize, $mediaId); |
1191 | + |
1192 | + if (!$db->query($SQL)) |
1193 | + trigger_error($db->error()); |
1194 | + } |
1195 | + |
1196 | + //Add the file node |
1197 | + $file = $requiredFilesXml->createElement("file"); |
1198 | + |
1199 | + $file->setAttribute("type", "media"); |
1200 | + $file->setAttribute("path", $storedAs); |
1201 | + $file->setAttribute("id", $mediaId); |
1202 | + $file->setAttribute("size", $fileSize); |
1203 | + $file->setAttribute("md5", $md5); |
1204 | + |
1205 | + $fileElements->appendChild($file); |
1206 | + } |
1207 | + |
1208 | + //Also append another file node for the background image (if there is one) |
1209 | + if ($background != "") |
1210 | + { |
1211 | + //firstly add this as a node |
1212 | + $file = $requiredFilesXml->createElement("file"); |
1213 | + |
1214 | + $file->setAttribute("type", "media"); |
1215 | + $file->setAttribute("path", $background); |
1216 | + $file->setAttribute("md5", md5_file($libraryLocation.$background)); |
1217 | + $file->setAttribute("size", filesize($libraryLocation.$background)); |
1218 | + |
1219 | + $fileElements->appendChild($file); |
1220 | + } |
1221 | + |
1222 | + // Add this layout as node |
1223 | + $file = $requiredFilesXml->createElement("file"); |
1224 | + |
1225 | + $file->setAttribute("type", "layout"); |
1226 | + $file->setAttribute("path", $layoutid); |
1227 | + $file->setAttribute("md5", md5($layoutXml . "\n")); |
1228 | + |
1229 | + $fileElements->appendChild($file); |
1230 | + } |
1231 | + |
1232 | + // |
1233 | + // Add a blacklist node |
1234 | + // |
1235 | + $blackList = $requiredFilesXml->createElement("file"); |
1236 | + $blackList->setAttribute("type", "blacklist"); |
1237 | + |
1238 | + $fileElements->appendChild($blackList); |
1239 | + |
1240 | + // Populate |
1241 | + $SQL = "SELECT MediaID |
1242 | + FROM blacklist |
1243 | + WHERE DisplayID = " . $displayInfo['displayid'] . " |
1244 | + AND isIgnored = 0"; |
1245 | + |
1246 | + if (!$results = $db->query($SQL)) |
1247 | + { |
1248 | + trigger_error($db->error()); |
1249 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of blacklisted files", $db->error()); |
1250 | + } |
1251 | + |
1252 | + // Add a black list element for each file |
1253 | + while ($row = $db->get_row($results)) |
1254 | + { |
1255 | + $file = $requiredFilesXml->createElement("file"); |
1256 | + $file->setAttribute("id", $row[0]); |
1257 | + |
1258 | + $blackList->appendChild($file); |
1259 | + } |
1260 | + |
1261 | + // PHONE_HOME if required. |
1262 | + if (Config::GetSetting($db,'PHONE_HOME') == 'On') { |
1263 | + // Find out when we last PHONED_HOME :D |
1264 | + // If it's been > 28 days since last PHONE_HOME then |
1265 | + if (Config::GetSetting($db,'PHONE_HOME_DATE') < (time() - (60 * 60 * 24 * 28))) { |
1266 | + |
1267 | + if ($displayInfo['isAuditing'] == 1) |
1268 | + { |
1269 | + Debug::LogEntry($db, "audit", "PHONE_HOME [IN]", "xmds", "RequiredFiles"); |
1270 | + } |
1271 | + |
1272 | + // Retrieve number of displays |
1273 | + $SQL = "SELECT COUNT(*) |
1274 | + FROM `display` |
1275 | + WHERE `licensed` = '1'"; |
1276 | + if (!$results = $db->query($SQL)) |
1277 | + { |
1278 | + trigger_error($db->error()); |
1279 | + } |
1280 | + while ($row = $db->get_row($results)) |
1281 | + { |
1282 | + $PHONE_HOME_CLIENTS = Kit::ValidateParam($row[0],_INT); |
1283 | + } |
1284 | + |
1285 | + // Retrieve version number |
1286 | + $PHONE_HOME_VERSION = Config::Version($db, 'app_ver'); |
1287 | + |
1288 | + $PHONE_HOME_URL = Config::GetSetting($db,'PHONE_HOME_URL') . "?id=" . urlencode(Config::GetSetting($db,'PHONE_HOME_KEY')) . "&version=" . urlencode($PHONE_HOME_VERSION) . "&numClients=" . urlencode($PHONE_HOME_CLIENTS); |
1289 | + |
1290 | + if ($displayInfo['isAuditing'] == 1) |
1291 | + { |
1292 | + Debug::LogEntry($db, "audit", "PHONE_HOME_URL " . $PHONE_HOME_URL , "xmds", "RequiredFiles"); |
1293 | + } |
1294 | + |
1295 | + // Set PHONE_HOME_TIME to NOW. |
1296 | + $SQL = "UPDATE `setting` |
1297 | + SET `value` = '" . time() . "' |
1298 | + WHERE `setting`.`setting` = 'PHONE_HOME_DATE' LIMIT 1"; |
1299 | + |
1300 | + if (!$results = $db->query($SQL)) |
1301 | + { |
1302 | + trigger_error($db->error()); |
1303 | + } |
1304 | + |
1305 | + @file_get_contents($PHONE_HOME_URL); |
1306 | + |
1307 | + if ($displayInfo['isAuditing'] == 1) |
1308 | + { |
1309 | + Debug::LogEntry($db, "audit", "PHONE_HOME [OUT]", "xmds", "RequiredFiles"); |
1310 | + } |
1311 | + //endif |
1312 | + } |
1313 | + } |
1314 | + // END OF PHONE_HOME CODE |
1315 | + |
1316 | + if ($displayInfo['isAuditing'] == 1) |
1317 | + { |
1318 | + Debug::LogEntry($db, "audit", $requiredFilesXml->saveXML(), "xmds", "RequiredFiles"); |
1319 | + Debug::LogEntry($db, "audit", "[OUT]", "xmds", "RequiredFiles"); |
1320 | + } |
1321 | + |
1322 | + // Return the results of requiredFiles() |
1323 | + return $requiredFilesXml->saveXML(); |
1324 | +} |
1325 | + |
1326 | +/** |
1327 | + * Gets the specified file |
1328 | + * @return |
1329 | + * @param $hardwareKey Object |
1330 | + * @param $filePath Object |
1331 | + * @param $fileType Object |
1332 | + */ |
1333 | +function GetFile($serverKey, $hardwareKey, $filePath, $fileType, $chunkOffset, $chunkSize, $version) |
1334 | +{ |
1335 | + global $db; |
1336 | + |
1337 | + // Sanitize |
1338 | + $serverKey = Kit::ValidateParam($serverKey, _STRING); |
1339 | + $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); |
1340 | + $fileType = Kit::ValidateParam($fileType, _WORD); |
1341 | + $chunkOffset = Kit::ValidateParam($chunkOffset, _INT); |
1342 | + $chunkSize = Kit::ValidateParam($chunkSize, _INT); |
1343 | + $version = Kit::ValidateParam($version, _STRING); |
1344 | + |
1345 | + $libraryLocation = Config::GetSetting($db, "LIBRARY_LOCATION"); |
1346 | + |
1347 | + // Make sure we are talking the same language |
1348 | + if (!CheckVersion($version)) |
1349 | + { |
1350 | + return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey); |
1351 | + } |
1352 | + |
1353 | + //auth this request... |
1354 | + if (!$displayInfo = Auth($hardwareKey)) |
1355 | + { |
1356 | + return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed"); |
1357 | + } |
1358 | + |
1359 | + if ($displayInfo['isAuditing'] == 1) |
1360 | + { |
1361 | + Debug::LogEntry($db, "audit", "[IN]", "xmds", "GetFile"); |
1362 | + Debug::LogEntry($db, "audit", "Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]", "xmds", "GetFile"); |
1363 | + } |
1364 | + |
1365 | + if ($fileType == "layout") |
1366 | + { |
1367 | + $filePath = Kit::ValidateParam($filePath, _INT); |
1368 | + |
1369 | + $SQL = sprintf("SELECT xml FROM layout WHERE layoutid = %d", $filePath); |
1370 | + if (!$results = $db->query($SQL)) |
1371 | + { |
1372 | + trigger_error($db->error()); |
1373 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get a list of files", $db->error()); |
1374 | + } |
1375 | + |
1376 | + $row = $db->get_row($results); |
1377 | + |
1378 | + $file = $row[0]; |
1379 | + } |
1380 | + elseif ($fileType == "media") |
1381 | + { |
1382 | + $filePath = Kit::ValidateParam($filePath, _STRING); |
1383 | + |
1384 | + if (strstr($filePath, '/') || strstr($filePath, '\\')) |
1385 | + { |
1386 | + return new soap_fault("SOAP-ENV:Client", "", "Invalid file path.", $serverKey); |
1387 | + } |
1388 | + |
1389 | + // Return the Chunk size specified |
1390 | + $f = fopen($libraryLocation.$filePath,"r"); |
1391 | + |
1392 | + fseek($f, $chunkOffset); |
1393 | + |
1394 | + $file = fread($f, $chunkSize); |
1395 | + } |
1396 | + else |
1397 | + { |
1398 | + return new soap_fault("SOAP-ENV:Client", "", "Unknown FileType Requested."); |
1399 | + } |
1400 | + |
1401 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "GetFile"); |
1402 | + |
1403 | + return base64_encode($file); |
1404 | +} |
1405 | + |
1406 | +/** |
1407 | + * Returns the schedule for the hardware key specified |
1408 | + * @return |
1409 | + * @param $hardwareKey Object |
1410 | + */ |
1411 | +function Schedule($serverKey, $hardwareKey, $version) |
1412 | +{ |
1413 | + global $db; |
1414 | + |
1415 | + // Sanitize |
1416 | + $serverKey = Kit::ValidateParam($serverKey, _STRING); |
1417 | + $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); |
1418 | + $version = Kit::ValidateParam($version, _STRING); |
1419 | + |
1420 | + // Make sure we are talking the same language |
1421 | + if (!CheckVersion($version)) |
1422 | + { |
1423 | + return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey); |
1424 | + } |
1425 | + |
1426 | + //auth this request... |
1427 | + if (!$displayInfo = Auth($hardwareKey)) |
1428 | + { |
1429 | + return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey); |
1430 | + } |
1431 | + |
1432 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[IN] $hardwareKey", "xmds", "Schedule"); |
1433 | + |
1434 | + $scheduleXml = new DOMDocument("1.0"); |
1435 | + $layoutElements = $scheduleXml->createElement("schedule"); |
1436 | + |
1437 | + $scheduleXml->appendChild($layoutElements); |
1438 | + |
1439 | + $currentdate = date("Y-m-d H:i:s"); |
1440 | + $time = time(); |
1441 | + $plus4hours = date("Y-m-d H:i:s",$time + 86400); |
1442 | + |
1443 | + //Add file nodes to the $fileElements |
1444 | + //Firstly get all the scheduled layouts |
1445 | + $SQL = " SELECT layout.layoutID, schedule_detail.starttime, schedule_detail.endtime, schedule_detail.eventID "; |
1446 | + $SQL .= " FROM layout "; |
1447 | + $SQL .= " INNER JOIN schedule_detail ON schedule_detail.layoutID = layout.layoutID "; |
1448 | + $SQL .= " INNER JOIN display ON schedule_detail.displayID = display.displayID "; |
1449 | + $SQL .= " WHERE display.license = '$hardwareKey' "; |
1450 | + $SQL .= " AND layout.retired = 0 "; |
1451 | + |
1452 | + // Store the Base SQL for this display |
1453 | + $SQLBase = $SQL; |
1454 | + |
1455 | + // Run the query |
1456 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule"); |
1457 | + |
1458 | + |
1459 | + |
1460 | + // Do we include the default display |
1461 | + if ($displayInfo['inc_schedule'] == 1) |
1462 | + { |
1463 | + $SQL .= " AND ((schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )"; |
1464 | + $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))"; |
1465 | + } |
1466 | + else |
1467 | + { |
1468 | + $SQL .= " AND (schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )"; |
1469 | + } |
1470 | + |
1471 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "$SQL", "xmds", "Schedule"); |
1472 | + |
1473 | + |
1474 | + // Before we run the main query we should check to see if there are any priority layouts to deal with |
1475 | + $SQLp = " AND schedule_detail.is_priority = 1 "; |
1476 | + |
1477 | + // Run the query |
1478 | + if (!$results = $db->query($SQL . $SQLp)) |
1479 | + { |
1480 | + trigger_error($db->error()); |
1481 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error()); |
1482 | + } |
1483 | + |
1484 | + // If there were no results then continue to get the full schedule |
1485 | + if ($db->num_rows($results) == 0) |
1486 | + { |
1487 | + // Run the query |
1488 | + if (!$results = $db->query($SQL)) |
1489 | + { |
1490 | + trigger_error($db->error()); |
1491 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error()); |
1492 | + } |
1493 | + |
1494 | + // Was there anything? |
1495 | + if ($db->num_rows($results) == 0) |
1496 | + { |
1497 | + // No rows, run the query for default layout |
1498 | + $SQL = $SQLBase; |
1499 | + $SQL .= " AND ((schedule_detail.starttime < '$currentdate' AND schedule_detail.endtime > '$currentdate' )"; |
1500 | + $SQL .= " OR (schedule_detail.starttime = '2050-12-31 00:00:00' AND schedule_detail.endtime = '2050-12-31 00:00:00' ))"; |
1501 | + |
1502 | + if (!$results = $db->query($SQL)) |
1503 | + { |
1504 | + trigger_error($db->error()); |
1505 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to get A list of layouts for the schedule", $db->error()); |
1506 | + } |
1507 | + } |
1508 | + } |
1509 | + |
1510 | + // We must have some results in here by this point |
1511 | + while ($row = $db->get_row($results)) |
1512 | + { |
1513 | + $layoutid = $row[0]; |
1514 | + $fromdt = $row[1]; |
1515 | + $todt = $row[2]; |
1516 | + $scheduleid = $row[3]; |
1517 | + |
1518 | + //firstly add this as a node |
1519 | + $layout = $scheduleXml->createElement("layout"); |
1520 | + |
1521 | + $layout->setAttribute("file", $layoutid); |
1522 | + $layout->setAttribute("fromdt", $fromdt); |
1523 | + $layout->setAttribute("todt", $todt); |
1524 | + $layout->setAttribute("scheduleid", $scheduleid); |
1525 | + |
1526 | + $layoutElements->appendChild($layout); |
1527 | + } |
1528 | + |
1529 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", $scheduleXml->saveXML(), "xmds", "Schedule"); |
1530 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry($db, "audit", "[OUT]", "xmds", "Schedule"); |
1531 | + |
1532 | + return $scheduleXml->saveXML(); |
1533 | +} |
1534 | + |
1535 | +/** |
1536 | + * Recieves the XmlLog from the display |
1537 | + * @return |
1538 | + * @param $hardwareKey String |
1539 | + * @param $xml String |
1540 | + */ |
1541 | +function RecieveXmlLog($serverKey, $hardwareKey, $xml, $version) |
1542 | +{ |
1543 | + global $db; |
1544 | + |
1545 | + return new soap_fault("SOAP-ENV:Client", "", "This is a depricated service call. You should instead call either SubmitLog or SubmitStats", $serverKey); |
1546 | +} |
1547 | + |
1548 | +define('BLACKLIST_ALL', "All"); |
1549 | +define('BLACKLIST_SINGLE', "Single"); |
1550 | +/** |
1551 | + * |
1552 | + * @return |
1553 | + * @param $hardwareKey Object |
1554 | + * @param $mediaId Object |
1555 | + * @param $type Object |
1556 | + */ |
1557 | +function BlackList($serverKey, $hardwareKey, $mediaId, $type, $reason, $version) |
1558 | +{ |
1559 | + global $db; |
1560 | + |
1561 | + // Sanitize |
1562 | + $serverKey = Kit::ValidateParam($serverKey, _STRING); |
1563 | + $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); |
1564 | + $mediaId = Kit::ValidateParam($mediaId, _STRING); |
1565 | + $type = Kit::ValidateParam($type, _STRING); |
1566 | + $reason = Kit::ValidateParam($reason, _STRING); |
1567 | + $version = Kit::ValidateParam($version, _STRING); |
1568 | + |
1569 | + // Make sure we are talking the same language |
1570 | + if (!CheckVersion($version)) |
1571 | + { |
1572 | + return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey); |
1573 | + } |
1574 | + |
1575 | + // Auth this request... |
1576 | + if (!$displayInfo = Auth($hardwareKey)) |
1577 | + { |
1578 | + return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey); |
1579 | + } |
1580 | + |
1581 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[IN]", "xmds", "BlackList", "", $displayInfo['displayid']); |
1582 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "$xml", "xmds", "BlackList", "", $displayInfo['displayid']); |
1583 | + |
1584 | + // Check to see if this media/display is already blacklisted (and not ignored) |
1585 | + $SQL = "SELECT BlackListID FROM blacklist WHERE MediaID = $mediaId AND isIgnored = 0 AND DisplayID = " . $displayInfo['displayid']; |
1586 | + |
1587 | + if (!$results = $db->query($SQL)) |
1588 | + { |
1589 | + trigger_error($db->error()); |
1590 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList records.", $db->error()); |
1591 | + } |
1592 | + |
1593 | + if ($db->num_rows($results) == 0) |
1594 | + { |
1595 | + // Insert the black list record |
1596 | + // Get all the displays and create a blacklist records |
1597 | + $SQL = "SELECT displayID FROM display"; |
1598 | + if ($type == BLACKLIST_SINGLE) |
1599 | + { |
1600 | + // Only the current display |
1601 | + $SQL .= " WHERE displayID = " . $displayInfo['displayid']; |
1602 | + } |
1603 | + |
1604 | + if (!$displays = $db->query($SQL)) |
1605 | + { |
1606 | + trigger_error($db->error()); |
1607 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to query for BlackList Displays.", $db->error()); |
1608 | + } |
1609 | + |
1610 | + while ($row = $db->get_row($displays)) |
1611 | + { |
1612 | + $displayId = $row[0]; |
1613 | + |
1614 | + $SQL = "INSERT INTO blacklist (MediaID, DisplayID, ReportingDisplayID, Reason) |
1615 | + VALUES ($mediaId, $displayId, " . $displayInfo['displayid'] . ", '$reason') "; |
1616 | + |
1617 | + if (!$db->query($SQL)) |
1618 | + { |
1619 | + trigger_error($db->error()); |
1620 | + return new soap_fault("SOAP-ENV:Server", "", "Unable to insert BlackList records.", $db->error()); |
1621 | + } |
1622 | + } |
1623 | + } |
1624 | + else |
1625 | + { |
1626 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "Media Already BlackListed [$mediaId]", "xmds", "BlackList", "", $displayInfo['displayid']); |
1627 | + } |
1628 | + |
1629 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "[OUT]", "xmds", "BlackList", "", $displayInfo['displayid']); |
1630 | + |
1631 | + return true; |
1632 | +} |
1633 | + |
1634 | +/** |
1635 | + * Submit client logging |
1636 | + * @return |
1637 | + * @param $version Object |
1638 | + * @param $serverKey Object |
1639 | + * @param $hardwareKey Object |
1640 | + * @param $logXml Object |
1641 | + */ |
1642 | +function SubmitLog($version, $serverKey, $hardwareKey, $logXml) |
1643 | +{ |
1644 | + global $db; |
1645 | + |
1646 | + // Sanitize |
1647 | + $serverKey = Kit::ValidateParam($serverKey, _STRING); |
1648 | + $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); |
1649 | + $version = Kit::ValidateParam($version, _STRING); |
1650 | + $logXml = Kit::ValidateParam($logXml, _HTMLSTRING); |
1651 | + |
1652 | + // Make sure we are talking the same language |
1653 | + if (!CheckVersion($version)) |
1654 | + { |
1655 | + return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey); |
1656 | + } |
1657 | + |
1658 | + // Auth this request... |
1659 | + if (!$displayInfo = Auth($hardwareKey)) |
1660 | + { |
1661 | + return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey); |
1662 | + } |
1663 | + |
1664 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitLog", "", $displayInfo['displayid']); |
1665 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", 'XML [' . $logXml . ']', "xmds", "SubmitLog", "", $displayInfo['displayid']); |
1666 | + |
1667 | + // Load the XML into a DOMDocument |
1668 | + $document = new DOMDocument("1.0"); |
1669 | + |
1670 | + if (!$document->loadXML($logXml)) |
1671 | + { |
1672 | + return new soap_fault("SOAP-ENV:Client", "", "XML Cannot be loaded into DOM Document.", $hardwareKey); |
1673 | + } |
1674 | + |
1675 | + foreach ($document->documentElement->childNodes as $node) |
1676 | + { |
1677 | + // Make sure we dont consider any text nodes |
1678 | + if ($node->nodeType == XML_TEXT_NODE) continue; |
1679 | + |
1680 | + // Zero out the common vars |
1681 | + $date = ""; |
1682 | + $message = ""; |
1683 | + $scheduleID = ""; |
1684 | + $layoutID = ""; |
1685 | + $mediaID = ""; |
1686 | + $cat = ''; |
1687 | + $method = ''; |
1688 | + |
1689 | + // This will be a bunch of trace nodes |
1690 | + $message = $node->textContent; |
1691 | + |
1692 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", 'Trace Message: [' . $message . ']', "xmds", "SubmitLog", "", $displayInfo['displayid']); |
1693 | + |
1694 | + // Each element should have a category and a date |
1695 | + $date = $node->getAttribute('date'); |
1696 | + $cat = $node->getAttribute('category'); |
1697 | + |
1698 | + if ($date == '' || $cat == '') |
1699 | + { |
1700 | + trigger_error('Log submitted without a date or category attribute'); |
1701 | + continue; |
1702 | + } |
1703 | + |
1704 | + // Get the date and the message (all log types have these) |
1705 | + foreach ($node->childNodes as $nodeElements) |
1706 | + { |
1707 | + if ($nodeElements->nodeName == "scheduleID") |
1708 | + { |
1709 | + $scheduleID = $nodeElements->textContent; |
1710 | + } |
1711 | + else if ($nodeElements->nodeName == "layoutID") |
1712 | + { |
1713 | + $layoutID = $nodeElements->textContent; |
1714 | + } |
1715 | + else if ($nodeElements->nodeName == "mediaID") |
1716 | + { |
1717 | + $mediaID = $nodeElements->textContent; |
1718 | + } |
1719 | + else if ($nodeElements->nodeName == "type") |
1720 | + { |
1721 | + $type = $nodeElements->textContent; |
1722 | + } |
1723 | + else if ($nodeElements->nodeName == "method") |
1724 | + { |
1725 | + $method = $nodeElements->textContent; |
1726 | + } |
1727 | + } |
1728 | + |
1729 | + // We should have enough information to log this now. |
1730 | + if ($cat == 'error' || $cat == 'Error') |
1731 | + { |
1732 | + Debug::LogEntry($db, $cat, $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID); |
1733 | + } |
1734 | + else |
1735 | + { |
1736 | + Debug::LogEntry($db, 'audit', $message, 'Client', $method, $date, $displayInfo['displayid'], $scheduleID, $layoutID, $mediaID); |
1737 | + } |
1738 | + } |
1739 | + |
1740 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitLog", "", $displayInfo['displayid']); |
1741 | + |
1742 | + return true; |
1743 | +} |
1744 | + |
1745 | +/** |
1746 | + * Submit display statistics to the server |
1747 | + * @return |
1748 | + * @param $version Object |
1749 | + * @param $serverKey Object |
1750 | + * @param $hardwareKey Object |
1751 | + * @param $statXml Object |
1752 | + */ |
1753 | +function SubmitStats($version, $serverKey, $hardwareKey, $statXml) |
1754 | +{ |
1755 | + global $db; |
1756 | + |
1757 | + // Sanitize |
1758 | + $serverKey = Kit::ValidateParam($serverKey, _STRING); |
1759 | + $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); |
1760 | + $version = Kit::ValidateParam($version, _STRING); |
1761 | + $statXml = Kit::ValidateParam($statXml, _HTMLSTRING); |
1762 | + |
1763 | + // Make sure we are talking the same language |
1764 | + if (!CheckVersion($version)) |
1765 | + { |
1766 | + return new soap_fault("SOAP-ENV:Client", "", "Your client is not of the correct version for communication with this server. You can get the latest from http://www.xibo.org.uk", $serverKey); |
1767 | + } |
1768 | + |
1769 | + // Auth this request... |
1770 | + if (!$displayInfo = Auth($hardwareKey)) |
1771 | + { |
1772 | + return new soap_fault("SOAP-ENV:Client", "", "This display client is not licensed", $hardwareKey); |
1773 | + } |
1774 | + |
1775 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "IN", "xmds", "SubmitStats", "", $displayInfo['displayid']); |
1776 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "StatXml: [" . $statXml . "]", "xmds", "SubmitStats", "", $displayInfo['displayid']); |
1777 | + |
1778 | + if ($statXml == "") |
1779 | + { |
1780 | + return new soap_fault("SOAP-ENV:Client", "", "Stat XML is empty.", $hardwareKey); |
1781 | + } |
1782 | + |
1783 | + // Log |
1784 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to create Stat Object.", "xmds", "SubmitStats", "", $displayInfo['displayid']); |
1785 | + |
1786 | + $statObject = new Stat($db); |
1787 | + |
1788 | + // Log |
1789 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "About to Create DOMDocument.", "xmds", "SubmitStats", "", $displayInfo['displayid']); |
1790 | + |
1791 | + // Load the XML into a DOMDocument |
1792 | + $document = new DOMDocument("1.0"); |
1793 | + $document->loadXML($statXml); |
1794 | + |
1795 | + foreach ($document->documentElement->childNodes as $node) |
1796 | + { |
1797 | + // Make sure we dont consider any text nodes |
1798 | + if ($node->nodeType == XML_TEXT_NODE) continue; |
1799 | + |
1800 | + //Zero out the common vars |
1801 | + $fromdt = ''; |
1802 | + $todt = ''; |
1803 | + $type = ''; |
1804 | + |
1805 | + $scheduleID = 0; |
1806 | + $layoutID = 0; |
1807 | + $mediaID = ''; |
1808 | + $tag = ''; |
1809 | + |
1810 | + // Each element should have these attributes |
1811 | + $fromdt = $node->getAttribute('fromdt'); |
1812 | + $todt = $node->getAttribute('todt'); |
1813 | + $type = $node->getAttribute('type'); |
1814 | + |
1815 | + if ($fromdt == '' || $todt == '' || $type == '') |
1816 | + { |
1817 | + trigger_error('Stat submitted without the fromdt, todt or type attributes.'); |
1818 | + continue; |
1819 | + } |
1820 | + |
1821 | + $scheduleID = $node->getAttribute('scheduleid'); |
1822 | + $layoutID = $node->getAttribute('layoutid'); |
1823 | + $mediaID = $node->getAttribute('mediaid'); |
1824 | + $tag = $node->getAttribute('tag'); |
1825 | + |
1826 | + // Write the stat record with the information we have available to us. |
1827 | + if (!$statObject->Add($type, $fromdt, $todt, $scheduleID, $displayInfo['displayid'], $layoutID, $mediaID, $tag)) |
1828 | + { |
1829 | + trigger_error(sprintf('Stat Add failed with error: %s', $statObject->GetErrorMessage())); |
1830 | + continue; |
1831 | + } |
1832 | + } |
1833 | + |
1834 | + if ($displayInfo['isAuditing'] == 1) Debug::LogEntry ($db, "audit", "OUT", "xmds", "SubmitStats", "", $displayInfo['displayid']); |
1835 | + |
1836 | + return true; |
1837 | +} |
1838 | + |
1839 | +//$debug = 1; |
1840 | +$service = new soap_server(); |
1841 | + |
1842 | +$service->configureWSDL("xmds", "urn:xmds"); |
1843 | + |
1844 | +$service->register("RegisterDisplay", |
1845 | + array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'displayName' => 'xsd:string', 'version' => 'xsd:string'), |
1846 | + array('ActivationMessage' => 'xsd:string'), |
1847 | + 'urn:xmds', |
1848 | + 'urn:xmds#RegisterDisplay', |
1849 | + 'rpc', |
1850 | + 'encoded', |
1851 | + 'Registered the Display on the Xibo Network' |
1852 | + ); |
1853 | + |
1854 | +$service->register("RequiredFiles", |
1855 | + array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'), |
1856 | + array('RequiredFilesXml' => 'xsd:string'), |
1857 | + 'urn:xmds', |
1858 | + 'urn:xmds#RequiredFiles', |
1859 | + 'rpc', |
1860 | + 'encoded', |
1861 | + 'The files required by the requesting display' |
1862 | + ); |
1863 | + |
1864 | +$service->register("GetFile", |
1865 | + array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'filePath' => 'xsd:string', 'fileType' => 'xsd:string', 'chunkOffset' => 'xsd:int', 'chuckSize' => 'xsd:int', 'version' => 'xsd:string'), |
1866 | + array('file' => 'xsd:base64Binary'), |
1867 | + 'urn:xmds', |
1868 | + 'urn:xmds#GetFile', |
1869 | + 'rpc', |
1870 | + 'encoded', |
1871 | + 'Gets the file requested' |
1872 | + ); |
1873 | + |
1874 | +$service->register("Schedule", |
1875 | + array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'version' => 'xsd:string'), |
1876 | + array('ScheduleXml' => 'xsd:string'), |
1877 | + 'urn:xmds', |
1878 | + 'urn:xmds#Schedule', |
1879 | + 'rpc', |
1880 | + 'encoded', |
1881 | + 'Gets the schedule' |
1882 | + ); |
1883 | + |
1884 | +$service->register("RecieveXmlLog", |
1885 | + array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'xml' => 'xsd:string', 'version' => 'xsd:string'), |
1886 | + array('success' => 'xsd:boolean'), |
1887 | + 'urn:xmds', |
1888 | + 'urn:xmds#RecieveXmlLog', |
1889 | + 'rpc', |
1890 | + 'encoded', |
1891 | + 'Recieves the Log Xml' |
1892 | + ); |
1893 | + |
1894 | +$service->register("BlackList", |
1895 | + array('serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'mediaId' => 'xsd:int', 'type' => 'xsd:string', 'reason'=>'xsd:string', 'version' => 'xsd:string'), |
1896 | + array('success' => 'xsd:boolean'), |
1897 | + 'urn:xmds', |
1898 | + 'urn:xmds#BlackList', |
1899 | + 'rpc', |
1900 | + 'encoded', |
1901 | + 'Set media to be blacklisted' |
1902 | + ); |
1903 | + |
1904 | +$service->register("SubmitLog", |
1905 | + array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'logXml' => 'xsd:string'), |
1906 | + array('success' => 'xsd:boolean'), |
1907 | + 'urn:xmds', |
1908 | + 'urn:xmds#SubmitLog', |
1909 | + 'rpc', |
1910 | + 'encoded', |
1911 | + 'Submit Logging from the Client' |
1912 | + ); |
1913 | + |
1914 | +$service->register("SubmitStats", |
1915 | + array('version' => 'xsd:string', 'serverKey' => 'xsd:string', 'hardwareKey' => 'xsd:string', 'statXml' => 'xsd:string'), |
1916 | + array('success' => 'xsd:boolean'), |
1917 | + 'urn:xmds', |
1918 | + 'urn:xmds#SubmitLog', |
1919 | + 'rpc', |
1920 | + 'encoded', |
1921 | + 'Submit Display statistics from the Client' |
1922 | + ); |
1923 | + |
1924 | + |
1925 | + |
1926 | +$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; |
1927 | +$service->service($HTTP_RAW_POST_DATA); |
1928 | + |
1929 | +//Debug::LogEntry($db, 'audit', $service->debug_str, "xmds", "NuSOAP"); |
1930 | + |
1931 | +>>>>>>> MERGE-SOURCE |
1932 | ?> |
1933 | \ No newline at end of file |