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