3
* Xibo - Digital Signage - http://www.xibo.org.uk
4
* Copyright (C) 2006-2010 Daniel Garner
6
* This file is part of Xibo.
8
* Xibo is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Affero General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
13
* Xibo is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Affero General Public License for more details.
18
* You should have received a copy of the GNU Affero General Public License
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
22
use Xibo\Helper\Config;
26
include_once("lib/xmds.inc.php");
28
$method = \Kit::GetParam('method', _REQUEST, _WORD, '');
29
$service = \Kit::GetParam('service', _REQUEST, _WORD, 'rest');
30
$response = \Kit::GetParam('response', _REQUEST, _WORD, 'xml');
31
$serviceResponse = new XiboServiceResponse();
33
// Is the XRDS being requested
34
if (isset($_GET['xrds']))
35
$serviceResponse->XRDS();
40
// Check to see if we are going to consume a service (if we came from xmds.php then we will always use the SOAP service)
41
if (defined('XMDS') || $method != '')
43
// Create a service to handle the method
48
Log::notice('OAuth Webservice call');
52
$oauth = new ServiceOAuth();
54
if (method_exists($oauth, $method))
57
$serviceResponse->ErrorServerError('Unknown Request.');
63
$serviceResponse->StartTransaction();
65
// OAuth authorization.
66
if (OAuthRequestVerifier::requestIsSigned())
70
$request = new OAuthRequestVerifier();
71
$userID = $request->verify();
75
// Create the login control system.
76
$userClass = Config::GetSetting('userModule');
77
$userClass = explode('.', $userClass);
79
\Kit::ClassLoader($userClass[0]);
82
// We need to set up our user with an old style database object
85
if (!$db->connect_db($dbhost, $dbuser, $dbpass))
86
die('Database connection problem.');
88
if (!$db->select_db($dbname))
89
die('Database connection problem.');
91
$user = new User($db);
94
if (!$user->setIdentity($userID))
96
$serviceResponse->ErrorServerError('Unknown User.');
101
$serviceResponse->ErrorServerError('No user id.');
104
catch (OAuthException $e)
106
$serviceResponse->ErrorServerError('Request signed but Unauthorized.');
111
// Only signed requests allowed.
112
$serviceResponse->ErrorServerError('Not signed.');
115
Log::notice('Authenticated API call for [' . $method . '] with a [' . $response . '] response. Issued by UserId: ' . $user->userId, 'Services');
117
// Authenticated with OAuth.
120
// Detect response type requested.
126
$rest = new RestJson($user, $_REQUEST);
133
$rest = new RestXml($user, $_REQUEST);
138
$serviceResponse->ErrorServerError('Unknown response type');
141
// Run the method requested.
142
if (method_exists($rest, $method))
143
$serviceResponse->Success($rest->$method());
145
$serviceResponse->ErrorServerError('Unknown Method');
150
$serviceResponse->ErrorServerError('Not implemented.');
154
// No method therefore output the XMDS landing page / document
b'\\ No newline at end of file'