23
23
use Xibo\Entity\Bandwidth;
24
24
use Xibo\Exception\NotFoundException;
25
use Xibo\Factory\DisplayFactory;
26
use Xibo\Factory\LayoutFactory;
27
use Xibo\Factory\RequiredFileFactory;
28
use Xibo\Helper\Config;
30
use Xibo\Helper\Sanitize;
30
32
class Soap3 extends Soap
43
45
$this->logProcessor->setRoute('RegisterDisplay');
46
$serverKey = $this->getSanitizer()->string($serverKey);
47
$hardwareKey = $this->getSanitizer()->string($hardwareKey);
48
$serverKey = Sanitize::string($serverKey);
49
$hardwareKey = Sanitize::string($hardwareKey);
49
51
// Check the serverKey matches the one we have
50
if ($serverKey != $this->getConfig()->GetSetting('SERVER_KEY'))
52
if ($serverKey != Config::GetSetting('SERVER_KEY'))
51
53
throw new \SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
53
55
// Check the Length of the hardwareKey
57
59
// Check in the database for this hardwareKey
59
$display = $this->displayFactory->getByLicence($hardwareKey);
61
$display = DisplayFactory::getByLicence($hardwareKey);
61
$this->logProcessor->setDisplay($display->displayId, ($display->isAuditing()));
63
$this->logProcessor->setDisplay($display->displayId);
63
65
if ($display->licensed == 0) {
64
66
$active = 'Display is awaiting licensing approval from an Administrator.';
75
77
$this->logBandwidth($display->displayId, Bandwidth::$REGISTER, strlen($active));
77
$this->getLog()->debug($active, $display->displayId);
79
Log::debug($active, $display->displayId);
81
83
} catch (NotFoundException $e) {
82
$this->getLog()->error('Attempt to register a Version 3 Display with key %s.', $hardwareKey);
84
Log::error('Attempt to register a Version 3 Display with key %s.', $hardwareKey);
84
86
throw new \SoapFault('Sender', 'You cannot register an old display against this CMS.');
116
118
$this->logProcessor->setRoute('GetFile');
119
$serverKey = $this->getSanitizer()->string($serverKey);
120
$hardwareKey = $this->getSanitizer()->string($hardwareKey);
121
$filePath = $this->getSanitizer()->string($filePath);
122
$fileType = $this->getSanitizer()->string($fileType);
123
$chunkOffset = $this->getSanitizer()->int($chunkOffset);
124
$chunkSize = $this->getSanitizer()->int($chunkSize);
121
$serverKey = Sanitize::string($serverKey);
122
$hardwareKey = Sanitize::string($hardwareKey);
123
$filePath = Sanitize::string($filePath);
124
$fileType = Sanitize::string($fileType);
125
$chunkOffset = Sanitize::int($chunkOffset);
126
$chunkSize = Sanitize::int($chunkSize);
126
$libraryLocation = $this->getConfig()->GetSetting("LIBRARY_LOCATION");
128
$libraryLocation = Config::GetSetting("LIBRARY_LOCATION");
128
130
// Check the serverKey matches
129
if ($serverKey != $this->getConfig()->GetSetting('SERVER_KEY'))
131
if ($serverKey != Config::GetSetting('SERVER_KEY'))
130
132
throw new \SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
132
134
// Make sure we are sticking to our bandwidth limit
137
139
if (!$this->authDisplay($hardwareKey))
138
140
throw new \SoapFault('Receiver', "This display client is not licensed");
140
if ($this->display->isAuditing())
141
$this->getLog()->debug("[IN] Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]");
142
if ($this->display->isAuditing == 1)
143
Log::debug("[IN] Params: [$hardwareKey] [$filePath] [$fileType] [$chunkOffset] [$chunkSize]");
145
if (empty($filePath)) {
146
$this->getLog()->error('Soap3 GetFile request without a file path. Maybe a player missing ?v= parameter');
147
throw new \SoapFault('Receiver', 'GetFile request is missing file path - is this version compatible with this CMS?');
151
148
// Handle fetching the file
152
149
if ($fileType == "layout") {
153
$fileId = $this->getSanitizer()->int($filePath);
150
$fileId = Sanitize::int($filePath);
155
152
// Validate the nonce
156
$requiredFile = $this->requiredFileFactory->getByDisplayAndLayout($this->display->displayId, $fileId);
153
$requiredFile = RequiredFileFactory::getByDisplayAndLayout($this->display->displayId, $fileId);
158
155
// Load the layout
159
$layout = $this->layoutFactory->getById($fileId);
156
$layout = LayoutFactory::getById($fileId);
160
157
$path = $layout->xlfToDisk();
162
159
$file = file_get_contents($path);
163
160
$chunkSize = filesize($path);
165
162
$requiredFile->bytesRequested = $requiredFile->bytesRequested + $chunkSize;
166
$requiredFile->save();
163
$requiredFile->markUsed();
168
165
} else if ($fileType == "media") {
173
170
$fileId = explode('.', $filePath);
175
172
// Validate the nonce
176
$requiredFile = $this->requiredFileFactory->getByDisplayAndMedia($this->display->displayId, $fileId[0]);
173
$requiredFile = RequiredFileFactory::getByDisplayAndMedia($this->display->displayId, $fileId[0]);
178
175
// Return the Chunk size specified
179
176
$f = fopen($libraryLocation . $filePath, 'r');
186
183
$chunkSize = strlen($file);
188
185
$requiredFile->bytesRequested = $requiredFile->bytesRequested + $chunkSize;
189
$requiredFile->save();
186
$requiredFile->markUsed();
192
189
throw new NotFoundException('Unknown FileType Requested.');
195
192
catch (NotFoundException $e) {
196
$this->getLog()->error($e->getMessage());
193
Log::error($e->getMessage());
197
194
throw new \SoapFault('Receiver', 'Requested an invalid file.');