~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to services.php

  • Committer: Dan Garner
  • Date: 2015-03-26 17:55:59 UTC
  • Revision ID: git-v1:58d3a02fd5045ba679384790e014ea9e0fc83027
Wired up layoutDesigner route

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Xibo - Digital Signage - http://www.xibo.org.uk
4
 
 * Copyright (C) 2006-2010 Daniel Garner
5
 
 *
6
 
 * This file is part of Xibo.
7
 
 *
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
11
 
 * any later version.
12
 
 *
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.
17
 
 *
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/>.
20
 
 */
21
 
use Xibo\Entity\User;
22
 
use Xibo\Helper\Config;
23
 
use Xibo\Helper\Log;
24
 
 
25
 
DEFINE('XIBO', true);
26
 
include_once("lib/xmds.inc.php");
27
 
 
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();
32
 
 
33
 
// Is the XRDS being requested
34
 
if (isset($_GET['xrds']))
35
 
    $serviceResponse->XRDS();
36
 
 
37
 
// We need a theme
38
 
 
39
 
 
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 != '')
42
 
{
43
 
    // Create a service to handle the method
44
 
    switch ($service)
45
 
    {
46
 
        case 'oauth':
47
 
 
48
 
            Log::notice('OAuth Webservice call');
49
 
 
50
 
 
51
 
 
52
 
            $oauth = new ServiceOAuth();
53
 
 
54
 
            if (method_exists($oauth, $method))
55
 
                $oauth->$method();
56
 
            else
57
 
                $serviceResponse->ErrorServerError('Unknown Request.');
58
 
 
59
 
            break;
60
 
 
61
 
        case 'rest':
62
 
 
63
 
            $serviceResponse->StartTransaction();
64
 
 
65
 
            // OAuth authorization.
66
 
            if (OAuthRequestVerifier::requestIsSigned())
67
 
            {
68
 
                try
69
 
                {
70
 
                    $request = new OAuthRequestVerifier();
71
 
                    $userID = $request->verify();
72
 
 
73
 
                    if ($userID)
74
 
                    {
75
 
                        // Create the login control system.
76
 
                        $userClass = Config::GetSetting('userModule');
77
 
                        $userClass = explode('.', $userClass);
78
 
 
79
 
                        \Kit::ClassLoader($userClass[0]);
80
 
 
81
 
                        // Create a user.
82
 
                        // We need to set up our user with an old style database object
83
 
                        $db = new database();
84
 
 
85
 
                        if (!$db->connect_db($dbhost, $dbuser, $dbpass))
86
 
                            die('Database connection problem.');
87
 
 
88
 
                        if (!$db->select_db($dbname))
89
 
                            die('Database connection problem.');
90
 
 
91
 
                        $user = new User($db);
92
 
 
93
 
                        // Log this user in.
94
 
                        if (!$user->setIdentity($userID))
95
 
                        {
96
 
                            $serviceResponse->ErrorServerError('Unknown User.');
97
 
                        }
98
 
                    }
99
 
                    else
100
 
                    {
101
 
                        $serviceResponse->ErrorServerError('No user id.');
102
 
                    }
103
 
                }
104
 
                catch (OAuthException $e)
105
 
                {
106
 
                    $serviceResponse->ErrorServerError('Request signed but Unauthorized.');
107
 
                }
108
 
            }
109
 
            else
110
 
            {
111
 
                // Only signed requests allowed.
112
 
                $serviceResponse->ErrorServerError('Not signed.');
113
 
            }
114
 
 
115
 
            Log::notice('Authenticated API call for [' . $method . '] with a [' . $response . '] response. Issued by UserId: ' . $user->userId, 'Services');
116
 
                
117
 
            // Authenticated with OAuth.
118
 
 
119
 
 
120
 
            // Detect response type requested.
121
 
            switch ($response)
122
 
            {
123
 
                case 'json':
124
 
 
125
 
                    
126
 
                    $rest = new RestJson($user, $_REQUEST);
127
 
 
128
 
                    break;
129
 
 
130
 
                case 'xml':
131
 
 
132
 
 
133
 
                    $rest = new RestXml($user, $_REQUEST);
134
 
 
135
 
                    break;
136
 
 
137
 
                default:
138
 
                    $serviceResponse->ErrorServerError('Unknown response type');
139
 
            }
140
 
 
141
 
            // Run the method requested.
142
 
            if (method_exists($rest, $method))
143
 
                $serviceResponse->Success($rest->$method());
144
 
            else
145
 
                $serviceResponse->ErrorServerError('Unknown Method');
146
 
 
147
 
            break;
148
 
 
149
 
        default:
150
 
            $serviceResponse->ErrorServerError('Not implemented.');
151
 
    }
152
 
    exit;
153
 
}
154
 
// No method therefore output the XMDS landing page / document
155
 
?>
156
 
<html>
157
 
    <head>
158
 
        <title>Xmds</title>
159
 
    </head>
160
 
    <body>
161
 
        <h1>XMDS</h1>
162
 
    </body>
163
 
</html>
 
 
b'\\ No newline at end of file'