46
49
* @throws \SoapFault
48
public function RegisterDisplay($serverKey, $hardwareKey, $displayName, $clientType, $clientVersion, $clientCode, $operatingSystem, $macAddress, $xmrChannel = null, $xmrPubKey = null)
51
public function RegisterDisplay($serverKey, $hardwareKey, $displayName, $clientType, $clientVersion, $clientCode, $operatingSystem, $macAddress)
50
$this->logProcessor->setRoute('RegisterDisplay');
53
$serverKey = $this->getSanitizer()->string($serverKey);
54
$hardwareKey = $this->getSanitizer()->string($hardwareKey);
55
$displayName = $this->getSanitizer()->string($displayName);
56
$clientType = $this->getSanitizer()->string($clientType);
57
$clientVersion = $this->getSanitizer()->string($clientVersion);
58
$clientCode = $this->getSanitizer()->int($clientCode);
59
$macAddress = $this->getSanitizer()->string($macAddress);
60
$clientAddress = $this->getIp();
54
$serverKey = Sanitize::string($serverKey);
55
$hardwareKey = Sanitize::string($hardwareKey);
56
$displayName = Sanitize::string($displayName);
57
$clientType = Sanitize::string($clientType);
58
$clientVersion = Sanitize::string($clientVersion);
59
$clientCode = Sanitize::int($clientCode);
60
$macAddress = Sanitize::string($macAddress);
61
$clientAddress = Sanitize::getString('REMOTE_ADDR');
64
Log::debug('serverKey: ' . $serverKey . ', hardwareKey: ' . $hardwareKey . ', displayName: ' . $displayName);
62
66
// Check the serverKey matches
63
if ($serverKey != $this->getConfig()->GetSetting('SERVER_KEY'))
67
if ($serverKey != Config::GetSetting('SERVER_KEY'))
64
68
throw new \SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
66
70
// Check the Length of the hardwareKey
75
79
// Check in the database for this hardwareKey
77
$display = $this->displayFactory->getByLicence($hardwareKey);
78
$this->display = $display;
80
$this->logProcessor->setDisplay($display->displayId, ($display->isAuditing()));
83
$this->getLog()->debug('serverKey: ' . $serverKey . ', hardwareKey: ' . $hardwareKey . ', displayName: ' . $displayName . ', macAddress: ' . $macAddress);
86
$dateNow = $this->getDate()->parse();
89
$displayElement->setAttribute('date', $this->getDate()->getLocalDate($dateNow));
90
$displayElement->setAttribute('timezone', $this->getConfig()->GetSetting('defaultTimezone'));
81
$display = DisplayFactory::getByLicence($hardwareKey);
92
83
// Determine if we are licensed or not
93
84
if ($display->licensed == 0) {
109
100
// Create the XML nodes
110
101
foreach ($settings as $arrayItem) {
112
102
$node = $return->createElement($arrayItem['name'], (isset($arrayItem['value']) ? $arrayItem['value'] : $arrayItem['default']));
113
103
$node->setAttribute('type', $arrayItem['type']);
114
104
$displayElement->appendChild($node);
117
107
// Add some special settings
118
$nodeName = ($clientType == 'windows') ? 'DisplayName' : 'displayName';
119
$node = $return->createElement($nodeName);
120
$node->appendChild($return->createTextNode($display->display));
108
$nodeName = ($display->clientType == 'windows') ? 'DisplayName' : 'displayName';
109
$node = $return->createElement($nodeName, $display->display);
121
110
$node->setAttribute('type', 'string');
122
111
$displayElement->appendChild($node);
124
$nodeName = ($clientType == 'windows') ? 'ScreenShotRequested' : 'screenShotRequested';
113
$nodeName = ($display->clientType == 'windows') ? 'ScreenShotRequested' : 'screenShotRequested';
125
114
$node = $return->createElement($nodeName, $display->screenShotRequested);
126
115
$node->setAttribute('type', 'checkbox');
127
116
$displayElement->appendChild($node);
129
$nodeName = ($clientType == 'windows') ? 'DisplayTimeZone' : 'displayTimeZone';
130
$node = $return->createElement($nodeName, (!empty($display->timeZone)) ? $display->timeZone : '');
131
$node->setAttribute('type', 'string');
132
$displayElement->appendChild($node);
134
if (!empty($display->timeZone)) {
135
// Calculate local time
136
$dateNow->timezone($display->timeZone);
139
$displayElement->setAttribute('localDate', $this->getDate()->getLocalDate($dateNow));
142
118
// Send Notification if required
143
$this->alertDisplayUp();
119
$this->AlertDisplayUp($display->displayId, $display->display, $display->loggedIn, $display->emailAlert);
146
122
} catch (NotFoundException $e) {
148
124
// Add a new display
150
$display = $this->displayFactory->createEmpty();
151
$this->display = $display;
126
$display = new Display();
152
127
$display->display = $displayName;
153
$display->auditingUntil = 0;
154
$display->defaultLayoutId = $this->getConfig()->GetSetting('DEFAULT_LAYOUT', 4);
128
$display->isAuditing = 0;
129
$display->defaultLayoutId = 4;
155
130
$display->license = $hardwareKey;
156
131
$display->licensed = 0;
157
132
$display->incSchedule = 0;
174
149
$display->clientType = $clientType;
175
150
$display->clientVersion = $clientVersion;
176
151
$display->clientCode = $clientCode;
177
//$display->operatingSystem = $operatingSystem;
178
$display->save(['validate' => false, 'audit' => false]);
152
$display->save(false);
181
155
$returnXml = $return->saveXML();
182
$this->logBandwidth($display->displayId, Bandwidth::$REGISTER, strlen($returnXml));
156
$this->LogBandwidth($display->displayId, Bandwidth::$REGISTER, strlen($returnXml));
184
158
// Audit our return
185
$this->getLog()->debug($returnXml);
159
if ($display->isAuditing == 1)
160
Log::debug($returnXml, $display->displayId);
187
162
return $returnXml;
214
189
function GetFile($serverKey, $hardwareKey, $fileId, $fileType, $chunkOffset, $chunkSize)
216
$this->logProcessor->setRoute('GetFile');
219
$serverKey = $this->getSanitizer()->string($serverKey);
220
$hardwareKey = $this->getSanitizer()->string($hardwareKey);
221
$fileId = $this->getSanitizer()->int($fileId);
222
$fileType = $this->getSanitizer()->string($fileType);
223
$chunkOffset = $this->getSanitizer()->int($chunkOffset);
224
$chunkSize = $this->getSanitizer()->int($chunkSize);
192
$serverKey = Sanitize::string($serverKey);
193
$hardwareKey = Sanitize::string($hardwareKey);
194
$fileId = Sanitize::int($fileId);
195
$fileType = Sanitize::string($fileType);
196
$chunkOffset = Sanitize::int($chunkOffset);
197
$chunkSize = Sanitize::int($chunkSize);
226
$libraryLocation = $this->getConfig()->GetSetting("LIBRARY_LOCATION");
199
$libraryLocation = Config::GetSetting("LIBRARY_LOCATION");
228
201
// Check the serverKey matches
229
if ($serverKey != $this->getConfig()->GetSetting('SERVER_KEY'))
202
if ($serverKey != Config::GetSetting('SERVER_KEY'))
230
203
throw new \SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
232
205
// Make sure we are sticking to our bandwidth limit
233
if (!$this->checkBandwidth())
206
if (!$this->CheckBandwidth())
234
207
throw new \SoapFault('Receiver', "Bandwidth Limit exceeded");
236
209
// Authenticate this request...
237
if (!$this->authDisplay($hardwareKey))
210
if (!$this->AuthDisplay($hardwareKey))
238
211
throw new \SoapFault('Receiver', "This display client is not licensed");
240
if ($this->display->isAuditing())
241
$this->getLog()->debug('hardwareKey: ' . $hardwareKey . ', fileId: ' . $fileId . ', fileType: ' . $fileType . ', chunkOffset: ' . $chunkOffset . ', chunkSize: ' . $chunkSize);
213
if ($this->display->isAuditing == 1)
214
Log::debug('hardwareKey: ' . $hardwareKey . ', fileId: ' . $fileId . ', fileType: ' . $fileType . ', chunkOffset: ' . $chunkOffset . ', chunkSize: ' . $chunkSize);
244
217
if ($fileType == "layout") {
245
$fileId = $this->getSanitizer()->int($fileId);
218
$fileId = Sanitize::int($fileId);
247
220
// Validate the nonce
248
$requiredFile = $this->requiredFileFactory->getByDisplayAndLayout($this->display->displayId, $fileId);
221
if (count(XmdsNonceFactory::getByDisplayAndLayout($this->display->displayId, $fileId)) <= 0)
222
throw new NotFoundException('Invalid Nonce for ' . $fileId);
250
224
// Load the layout
251
$layout = $this->layoutFactory->getById($fileId);
225
$layout = LayoutFactory::getById($fileId);
252
226
$path = $layout->xlfToDisk();
254
228
$file = file_get_contents($path);
255
229
$chunkSize = filesize($path);
257
$requiredFile->bytesRequested = $requiredFile->bytesRequested + $chunkSize;
258
$requiredFile->save();
260
231
} else if ($fileType == "media") {
261
232
// Validate the nonce
262
$requiredFile = $this->requiredFileFactory->getByDisplayAndMedia($this->display->displayId, $fileId);
264
$media = $this->mediaFactory->getById($fileId);
265
$this->getLog()->debug(json_encode($media));
267
if (!file_exists($libraryLocation . $media->storedAs))
268
throw new NotFoundException('Media exists but file missing from library. ' . $libraryLocation);
233
if (count(XmdsNonceFactory::getByDisplayAndMedia($this->display->displayId, $fileId)) <= 0)
234
throw new NotFoundException('Invalid Nonce for ' . $fileId);
236
$media = MediaFactory::getById($fileId);
270
238
// Return the Chunk size specified
271
if (!$f = fopen($libraryLocation . $media->storedAs, 'r'))
272
throw new NotFoundException('Unable to get file pointer');
239
$f = fopen($libraryLocation . $media->storedAs, 'r');
274
241
fseek($f, $chunkOffset);
278
245
// Store file size for bandwidth log
279
246
$chunkSize = strlen($file);
281
if ($chunkSize === 0)
282
throw new NotFoundException('Empty file');
284
$requiredFile->bytesRequested = $requiredFile->bytesRequested + $chunkSize;
285
$requiredFile->save();
288
249
throw new NotFoundException('Unknown FileType Requested.');
291
252
catch (NotFoundException $e) {
292
$this->getLog()->error('Not found FileId: ' . $fileId . '. FileType: ' . $fileType . '. ' . $e->getMessage());
253
Log::error($e->getMessage());
293
254
throw new \SoapFault('Receiver', 'Requested an invalid file.');
297
$this->logBandwidth($this->display->displayId, Bandwidth::$GETFILE, $chunkSize);
258
$this->LogBandwidth($this->display->displayId, Bandwidth::$GETFILE, $chunkSize);
391
352
public function NotifyStatus($serverKey, $hardwareKey, $status)
393
$this->logProcessor->setRoute('NotifyStatus');
396
$serverKey = $this->getSanitizer()->string($serverKey);
397
$hardwareKey = $this->getSanitizer()->string($hardwareKey);
355
$serverKey = Sanitize::string($serverKey);
356
$hardwareKey = Sanitize::string($hardwareKey);
399
358
// Check the serverKey matches
400
if ($serverKey != $this->getConfig()->GetSetting('SERVER_KEY'))
359
if ($serverKey != Config::GetSetting('SERVER_KEY'))
401
360
throw new \SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
403
362
// Make sure we are sticking to our bandwidth limit
404
if (!$this->checkBandwidth())
363
if (!$this->CheckBandwidth())
405
364
throw new \SoapFault('Receiver', "Bandwidth Limit exceeded");
407
366
// Auth this request...
408
if (!$this->authDisplay($hardwareKey))
367
if (!$this->AuthDisplay($hardwareKey))
409
368
throw new \SoapFault('Receiver', 'This display client is not licensed');
411
// Important to keep this logging in place (status screen notification gets logged)
412
if ($this->display->isAuditing())
413
$this->getLog()->debug($status);
370
if ($this->display->isAuditing == 1)
415
$this->logBandwidth($this->display->displayId, Bandwidth::$NOTIFYSTATUS, strlen($status));
373
$this->LogBandwidth($this->display->displayId, Bandwidth::$NOTIFYSTATUS, strlen($status));
417
375
$status = json_decode($status, true);
419
$this->display->storageAvailableSpace = $this->getSanitizer()->getInt('availableSpace', $this->display->storageAvailableSpace, $status);
420
$this->display->storageTotalSpace = $this->getSanitizer()->getInt('totalSpace', $this->display->storageTotalSpace, $status);
421
$this->display->lastCommandSuccess = $this->getSanitizer()->getCheckbox('lastCommandSuccess', $this->display->lastCommandSuccess, $status);
422
$this->display->deviceName = $this->getSanitizer()->getString('deviceName', $this->display->deviceName, $status);
424
if ($this->getConfig()->GetSetting('DISPLAY_LOCK_NAME_TO_DEVICENAME') == 1 && $this->display->hasPropertyChanged('deviceName')) {
425
$this->display->display = $this->display->deviceName;
429
$timeZone = $this->getSanitizer()->getString('timeZone', $status);
431
if (!empty($timeZone)) {
432
// Validate the provided data and log/ignore if not well formatted
433
if (array_key_exists($timeZone, $this->getDate()->timezoneList())) {
434
$this->display->timeZone = $timeZone;
436
$this->getLog()->info('Ignoring Incorrect timezone string: ' . $timeZone);
441
$currentLayoutId = $this->getSanitizer()->getInt('currentLayoutId', $status);
443
if ($currentLayoutId !== null) {
444
$this->display->setCurrentLayoutId($this->getPool(), $currentLayoutId);
377
$this->display->currentLayoutId = Sanitize::getInt('currentLayoutId', $this->display->currentLayoutId, $status);
378
$this->display->storageAvailableSpace = Sanitize::getInt('availableSpace', $this->display->storageAvailableSpace, $status);
379
$this->display->storageTotalSpace = Sanitize::getInt('totalSpace', $this->display->storageTotalSpace, $status);
447
381
// Touch the display record
449
if (count($this->display->getChangedProperties()) > 0)
450
$this->display->save(Display::$saveOptionsMinimum);
451
} catch (XiboException $xiboException) {
452
$this->getLog()->error($xiboException->getMessage());
453
throw new \SoapFault('Receiver', 'Unable to save status update');
382
$this->display->save(false, false);
467
395
public function SubmitScreenShot($serverKey, $hardwareKey, $screenShot)
469
$this->logProcessor->setRoute('SubmitScreenShot');
472
$serverKey = $this->getSanitizer()->string($serverKey);
473
$hardwareKey = $this->getSanitizer()->string($hardwareKey);
475
$screenShotFmt = "jpg";
476
$screenShotMime = "image/jpeg";
477
$screenShotImg = false;
480
$needConversion = false;
398
$serverKey = Sanitize::string($serverKey);
399
$hardwareKey = Sanitize::string($hardwareKey);
482
401
// Check the serverKey matches
483
if ($serverKey != $this->getConfig()->GetSetting('SERVER_KEY'))
402
if ($serverKey != Config::GetSetting('SERVER_KEY'))
484
403
throw new \SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
486
405
// Make sure we are sticking to our bandwidth limit
487
if (!$this->checkBandwidth())
406
if (!$this->CheckBandwidth())
488
407
throw new \SoapFault('Receiver', "Bandwidth Limit exceeded");
490
409
// Auth this request...
491
if (!$this->authDisplay($hardwareKey))
410
if (!$this->AuthDisplay($hardwareKey))
492
411
throw new \SoapFault('Receiver', 'This display client is not licensed');
494
if ($this->display->isAuditing())
495
$this->getLog()->debug('Received Screen shot');
413
if ($this->display->isAuditing == 1)
414
Log::debug('Received Screen shot');
497
416
// Open this displays screen shot file and save this.
498
$location = $this->getConfig()->GetSetting('LIBRARY_LOCATION') . 'screenshots/' . $this->display->displayId . '_screenshot.' . $screenShotFmt;
500
foreach(array('imagick', 'gd') as $imgDriver) {
501
Img::configure(array('driver' => $imgDriver));
503
$screenShotImg = Img::make($screenShot);
504
} catch (\Exception $e) {
505
if ($this->display->isAuditing())
506
$this->getLog()->debug($imgDriver . " - " . $e->getMessage());
508
if($screenShotImg !== false) {
509
if ($this->display->isAuditing())
510
$this->getLog()->debug("Use " . $imgDriver);
515
if ($screenShotImg !== false) {
516
$imgMime = $screenShotImg->mime();
518
if($imgMime != $screenShotMime) {
519
$needConversion = true;
521
if ($this->display->isAuditing())
522
$this->getLog()->debug("converting: '" . $imgMime . "' to '" . $screenShotMime . "'");
523
$screenShot = (string) $screenShotImg->encode($screenShotFmt);
525
} catch (\Exception $e) {
526
if ($this->display->isAuditing())
527
$this->getLog()->debug($e->getMessage());
532
// return early with false, keep screenShotRequested intact, let the Player retry.
533
if ($needConversion && !$converted) {
534
$this->logBandwidth($this->display->displayId, Bandwidth::$SCREENSHOT, filesize($location));
535
throw new \SoapFault('Receiver', __('Incorrect Screen shot Format'));
417
Library::ensureLibraryExists();
418
$location = Config::GetSetting('LIBRARY_LOCATION') . 'screenshots/' . $this->display->displayId . '_screenshot.jpg';
539
419
$fp = fopen($location, 'wb');
540
420
fwrite($fp, $screenShot);
543
423
// Touch the display record
544
424
$this->display->screenShotRequested = 0;
545
$this->display->save(Display::$saveOptionsMinimum);
425
$this->display->save(false, false);
547
$this->logBandwidth($this->display->displayId, Bandwidth::$SCREENSHOT, filesize($location));
427
$this->LogBandwidth($this->display->displayId, Bandwidth::$SCREENSHOT, filesize($location));