~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Xmds/Soap3.php

  • Committer: Dan Garner
  • Date: 2016-02-15 17:54:45 UTC
  • mto: (454.4.130)
  • mto: This revision was merged to the branch mainline in revision 484.
  • Revision ID: git-v1:dd226a6f84464ff28758a249e1fd52ca4a35d911
Correction to Layout Duration ToolTip
xibosignage/xibo#721

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
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;
 
29
use Xibo\Helper\Log;
 
30
use Xibo\Helper\Sanitize;
25
31
 
26
 
/**
27
 
 * Class Soap3
28
 
 * @package Xibo\Xmds
29
 
 */
30
32
class Soap3 extends Soap
31
33
{
32
34
    /**
43
45
        $this->logProcessor->setRoute('RegisterDisplay');
44
46
 
45
47
        // Sanitize
46
 
        $serverKey = $this->getSanitizer()->string($serverKey);
47
 
        $hardwareKey = $this->getSanitizer()->string($hardwareKey);
 
48
        $serverKey = Sanitize::string($serverKey);
 
49
        $hardwareKey = Sanitize::string($hardwareKey);
48
50
 
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');
52
54
 
53
55
        // Check the Length of the hardwareKey
56
58
 
57
59
        // Check in the database for this hardwareKey
58
60
        try {
59
 
            $display = $this->displayFactory->getByLicence($hardwareKey);
 
61
            $display = DisplayFactory::getByLicence($hardwareKey);
60
62
 
61
 
            $this->logProcessor->setDisplay($display->displayId, ($display->isAuditing()));
 
63
            $this->logProcessor->setDisplay($display->displayId);
62
64
 
63
65
            if ($display->licensed == 0) {
64
66
                $active = 'Display is awaiting licensing approval from an Administrator.';
74
76
            // Log Bandwidth
75
77
            $this->logBandwidth($display->displayId, Bandwidth::$REGISTER, strlen($active));
76
78
 
77
 
            $this->getLog()->debug($active, $display->displayId);
 
79
            Log::debug($active, $display->displayId);
78
80
 
79
81
            return $active;
80
82
 
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);
83
85
 
84
86
            throw new \SoapFault('Sender', 'You cannot register an old display against this CMS.');
85
87
        }
116
118
        $this->logProcessor->setRoute('GetFile');
117
119
 
118
120
        // Sanitize
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);
125
127
 
126
 
        $libraryLocation = $this->getConfig()->GetSetting("LIBRARY_LOCATION");
 
128
        $libraryLocation = Config::GetSetting("LIBRARY_LOCATION");
127
129
 
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');
131
133
 
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");
139
141
 
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]");
142
144
 
143
145
        $file = null;
144
146
 
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?');
148
 
        }
149
 
 
150
147
        try {
151
148
            // Handle fetching the file
152
149
            if ($fileType == "layout") {
153
 
                $fileId = $this->getSanitizer()->int($filePath);
 
150
                $fileId = Sanitize::int($filePath);
154
151
 
155
152
                // Validate the nonce
156
 
                $requiredFile = $this->requiredFileFactory->getByDisplayAndLayout($this->display->displayId, $fileId);
 
153
                $requiredFile = RequiredFileFactory::getByDisplayAndLayout($this->display->displayId, $fileId);
157
154
 
158
155
                // Load the layout
159
 
                $layout = $this->layoutFactory->getById($fileId);
 
156
                $layout = LayoutFactory::getById($fileId);
160
157
                $path = $layout->xlfToDisk();
161
158
 
162
159
                $file = file_get_contents($path);
163
160
                $chunkSize = filesize($path);
164
161
 
165
162
                $requiredFile->bytesRequested = $requiredFile->bytesRequested + $chunkSize;
166
 
                $requiredFile->save();
 
163
                $requiredFile->markUsed();
167
164
 
168
165
            } else if ($fileType == "media") {
169
166
                // Get the ID
173
170
                $fileId = explode('.', $filePath);
174
171
 
175
172
                // Validate the nonce
176
 
                $requiredFile = $this->requiredFileFactory->getByDisplayAndMedia($this->display->displayId, $fileId[0]);
 
173
                $requiredFile = RequiredFileFactory::getByDisplayAndMedia($this->display->displayId, $fileId[0]);
177
174
 
178
175
                // Return the Chunk size specified
179
176
                $f = fopen($libraryLocation . $filePath, 'r');
186
183
                $chunkSize = strlen($file);
187
184
 
188
185
                $requiredFile->bytesRequested = $requiredFile->bytesRequested + $chunkSize;
189
 
                $requiredFile->save();
 
186
                $requiredFile->markUsed();
190
187
 
191
188
            } else {
192
189
                throw new NotFoundException('Unknown FileType Requested.');
193
190
            }
194
191
        }
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.');
198
195
        }
199
196