-
Notifications
You must be signed in to change notification settings - Fork 1
/
apichain.php
151 lines (128 loc) · 3.82 KB
/
apichain.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.2.0 Patch Level 3 - Licence Number VBFBED0615
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000-2012 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('CVS_REVISION', '$RCSfile$ - $Revision: 36270 $');
define('VB_API_CHAIN', true);
// Set to 1 to build correct SESSIONIDHASH
$_REQUEST['api'] = 1;
// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/class_apiclient.php');
/*
$calls = array(
'methods' => array(
'login_login', 'api_init'
),
'login_login' => array(
'POST' => array(
'vb_login_username' => 'admin',
'vb_login_password' => 'password',
),
),
'api_init' => array(
'sessionhash' => '{session.dbsessionhash}'
)
);
*/
$vbulletin->input->clean_array_gpc('r', array(
'calls' => TYPE_STR,
'sig' => TYPE_STR,
'debug' => TYPE_BOOL
));
if (!$vbulletin->GPC['calls'])
{
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
die();
}
$calls = @json_decode($vbulletin->GPC['calls'], true);
if (!$calls)
{
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
die();
}
// Validate signature
$signtoverify = md5($vbulletin->GPC['calls'] . $vbulletin->session->vars['dbsessionhash'] . $vbulletin->userinfo['securitytoken_raw']);
if ($vbulletin->GPC['sig'] !== $signtoverify AND !($vbulletin->debug AND $vbulletin->GPC['debug']))
{
$error = array(
'response' => array(
'errormessage' => array('invalid_apichain_signature')
)
);
echo json_encode($error);
die;
}
$api = new vB_APIClient($vbulletin);
$api->setSessionhash($vbulletin->session->vars['dbsessionhash']);
$api->setSecuritytoken($vbulletin->userinfo['securitytoken_raw']);
$data = array();
foreach ($calls['methods'] as $method)
{
if (!$calls[$method]['POST'])
{
$calls[$method]['POST'] = array();
}
if (!$calls[$method]['GET'])
{
$calls[$method]['GET'] = array();
}
if ($data)
{
foreach ($calls[$method]['POST'] as &$v)
{
api_chain_parse($v, $data);
}
foreach ($calls[$method]['GET'] as &$v)
{
api_chain_parse($v, $data);
}
foreach ($calls[$method] as &$v)
{
if (!is_array($v))
{
api_chain_parse($v, $data);
}
}
}
if ($calls[$method]['sessionhash'])
{
$api->setSessionhash($calls[$method]['sessionhash']);
}
if ($calls[$method]['securitytoken'])
{
$api->setSecuritytoken($calls[$method]['securitytoken']);
}
$data = $api->call($method, $calls[$method]['GET'], $calls[$method]['POST'], 1);
}
echo json_encode($data);
exit;
function api_chain_parse(&$value, &$data)
{
if (preg_match('/\{([a-z0-9.]+)\}/', $value, $match))
{
$value = $match[1];
$datacopy = $data;
foreach (explode('.', $value) as $part)
{
$datacopy = $datacopy[$part];
}
$value = $datacopy;
}
}
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 16:29, Sun Dec 9th 2012
|| # CVS: $RCSfile$ - $Revision: 35584 $
|| ####################################################################
\*======================================================================*/