-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
381 lines (319 loc) · 12.7 KB
/
upload.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php
/*======================================================================*\
|| #################################################################### ||
|| # Copyright ©2009 Quoord Systems Ltd. All Rights Reserved. # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # This file is part of the Tapatalk package and should not be used # ||
|| # and distributed for any other purpose that is not approved by # ||
|| # Quoord Systems Ltd. # ||
|| # http://www.tapatalk.com | http://www.tapatalk.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
define('IN_MOBIQUO', true);
if(isset($_GET['checkAccess']))
{
echo "yes";
exit;
}
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
showTestScreen();
}
if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
include("./include/xmlrpc.inc");
include("./include/xmlrpcs.inc");
}
else
{
include("./include/xmlrpc.legacy.inc");
include("./include/xmlrpcs.legacy.inc");
}
// ####################### SET PHP ENVIRONMENT ###########################
@set_time_limit(0);
define('CWD1', (($getcwd = getcwd()) ? $getcwd : '.'));
error_reporting(0);
$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array();
$actiontemplates = array();
@ob_start();
require_once("./include/common.php");
define('SCRIPT_ROOT', get_root_dir());
chdir(SCRIPT_ROOT);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('GET_EDIT_TEMPLATES', true);
define('THIS_SCRIPT', 'newattachment');
define('CSRF_PROTECTION', false);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array('posting');
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array();
// pre-cache templates used by specific actions
$actiontemplates = array();
$_POST['f'] = $_POST['forum_id'];
$_REQUEST['f'] = $_REQUEST['forum_id'];
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_newpost.php');
require_once(DIR . '/includes/functions_file.php');
if(isset($vbulletin) && $vbulletin->userinfo['userid'] != 0){
header('Mobiquo_is_login:true');
} else {
header('Mobiquo_is_login:false');
}
$method = $_POST['method_name'];
$server_param = array(
"upload_attach" => array(
"function" => "upload_attach_func",
"signature" => array(array($xmlrpcStruct)),
"docstring" => 'no parameters matched'
),
"upload_avatar" => array(
"function" => "upload_avatar_func",
"signature" => array(array($xmlrpcStruct)),
"docstring" => 'no parameters matched'
),
);
$rpcServer = new xmlrpc_server($server_param,false);
$xml = new xmlrpcmsg($method);
$request = $xml->serialize();
$rpcServer->compress_response = 'true';
$rpcServer->response_charset_encoding ='UTF-8';
$response = $rpcServer->service($request);
function upload_attach_func()
{
global $vbulletin, $db, $forumperms, $permissions, $foruminfo;
$vbulletin->input->clean_array_gpc('r', array(
'group_id' => TYPE_UINT,
));
$attachmentid = 0;
$vbulletin->input->clean_gpc('f', 'attachment', TYPE_FILE);
$group_id = $_POST['group_id'];
if (!$vbulletin->userinfo['userid']) // Guests can not post attachments
{
$return = array(20, 'You need login to upload image.');
return return_fault($return);
}
if(isset($group_id) && $group_id != null && strlen($group_id) == 32 && preg_match('/[\w]{32}/', $group_id)){
$posthash = $group_id;
} else {
$posthash = md5(TIMENOW . $vbulletin->userinfo['userid'] . $vbulletin->userinfo['salt']);
}
$forumperms = fetch_permissions($foruminfo['forumid']);
// No permissions to post attachments in this forum or no permission to view threads in this forum.
if (empty($vbulletin->userinfo['attachmentextensions']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
{
$return = array(20, 'You do not have permission to post attachment in this forum');
return return_fault($return);
}
if ((!$postid AND !$foruminfo['allowposting']) OR $foruminfo['link'] OR !$foruminfo['cancontainthreads'])
{
$return = array(20, 'You can not post in this forum');
return return_fault($return);
}
if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew']) && !($forumperms & $vbulletin->bf_ugp_forumpermissions['canreplyothers'])) // newthread.php
{
$return = array(20, 'security error (user may not have permission to access this feature)');
return return_fault($return);
}
$_POST['add_file'] = true;
$parentattach = '';
$parentclickattach = '';
$new_attachlist_js = '';
// check if there is a forum password and if so, ensure the user has it set
verify_forum_password($foruminfo['forumid'], $foruminfo['password']);
$show['errors'] = false;
$currentattaches = $db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "attachment
WHERE posthash = '$posthash'
AND userid = " . $vbulletin->userinfo['userid']
);
$attachcount = $currentattaches['count'];
if ($postid)
{
$currentattaches = $db->query_first("
SELECT COUNT(*) AS count
FROM " . TABLE_PREFIX . "attachment
WHERE postid = $postid
");
$attachcount += $currentattaches['count'];
$show['postowner'] = true;
$attach_username = $postinfo['username'];
}
else
{
$show['postowner'] = false;
$attach_username = $vbulletin->userinfo['username'];
}
if (!$foruminfo['allowposting'] AND !$attachcount)
{
$return = array(20, 'security error (user may not have permission to access this feature.)');
return return_fault($return);
}
$errors = array();
require_once(DIR."/includes/class_upload.php");
require_once(DIR.'/includes/class_image.php');
$postinfo = array('posthash' => $posthash);
// check for any funny business
$filecount = 1;
if (!empty($vbulletin->GPC['attachment']['tmp_name']))
{
foreach ($vbulletin->GPC['attachment']['tmp_name'] AS $filename)
{
if (!empty($filename))
{
if ($filecount > $vbulletin->options['attachboxcount'])
{
@unlink($filename);
}
$filecount++;
}
}
}
// These are created each go around to insure memory has been freed
$attachdata =& datamanager_init('Attachment', $vbulletin, ERRTYPE_ARRAY);
$upload = new vB_Upload_Attachment($vbulletin);
$image =& vB_Image::fetch_library($vbulletin);
$upload->data =& $attachdata;
$upload->image =& $image;
if ($uploadsum > 1)
{
$upload->emptyfile = false;
}
$upload->foruminfo =& $foruminfo;
$upload->postinfo =& $postinfo;
$attachment = array(
'name' =>& $vbulletin->GPC['attachment']['name'][0],
'tmp_name' =>& $vbulletin->GPC['attachment']['tmp_name'][0],
'error' =>& $vbulletin->GPC['attachment']['error'][0],
'size' =>& $vbulletin->GPC['attachment']['size'][0],
);
if (!$foruminfo['allowposting'])
{
$error = $vbphrase['this_forum_is_not_accepting_new_attachments'];
$errors[] = array(
'filename' => $attachment['name'],
'error' => $error
);
}
else if ($vbulletin->options['attachlimit'] AND $attachcount > $vbulletin->options['attachlimit'])
{
$error = construct_phrase($vbphrase['you_may_only_attach_x_files_per_post'], $vbulletin->options['attachlimit']);
$errors[] = array(
'filename' => $attachment['name'],
'error' => $error
);
}
else
{
if ($attachmentid = $upload->process_upload($attachment))
{
if ($vbulletin->userinfo['userid'] != $postinfo['userid'] AND can_moderate($threadinfo['forumid'], 'caneditposts'))
{
$postinfo['attachmentid'] =& $attachmentid;
$postinfo['forumid'] =& $foruminfo['forumid'];
require_once(DIR . '/includes/functions_log_error.php');
log_moderator_action($postinfo, 'attachment_uploaded');
}
}
else
{
$attachcount--;
}
if ($error = $upload->fetch_error())
{
$errors[] = array(
'filename' => is_array($attachment) ? $attachment['name'] : $attachment,
'error' => $error,
);
}
}
if (!empty($errors))
{
$errorlist = '';
foreach ($errors AS $error)
{
$filename = htmlspecialchars_uni($error['filename']);
$errorlist .= $error['error'];
}
return new xmlrpcresp(new xmlrpcval(array(
'attachment_id' => new xmlrpcval(0, 'string'),
'group_id' => new xmlrpcval('', 'string'),
'result' => new xmlrpcval(false, 'boolean'),
'result_text' => new xmlrpcval(mobiquo_encode($errorlist), 'base64')
), 'struct'));
}
else
{
return new xmlrpcresp(new xmlrpcval(array(
'attachment_id' => new xmlrpcval($attachmentid, 'string'),
'group_id' => new xmlrpcval($posthash, 'string'),
'result' => new xmlrpcval(true, 'boolean'),
'result_text' => new xmlrpcval('', 'base64')
), 'struct' ) );
}
}
function upload_avatar_func()
{
global $vbulletin, $db, $forumperms,$permissions, $foruminfo;
if (!($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canmodifyprofile']))
{
$return = array(20, 'You can not modify your profile');
return return_fault($return);
}
if (!$vbulletin->options['avatarenabled'])
{
$return = array(20, 'Avatar is not enabled in this forum');
return return_fault($return);
}
$vbulletin->GPC['avatarid'] = 0;
if ($vbulletin->GPC['avatarid'] == 0 AND ($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar']))
{
$vbulletin->input->clean_gpc('f', 'upload', TYPE_FILE);
// begin custom avatar code
require_once(DIR . '/includes/class_upload.php');
require_once(DIR . '/includes/class_image.php');
$upload = new vB_Upload_Userpic($vbulletin);
$upload->data =& datamanager_init('Userpic_Avatar', $vbulletin, ERRTYPE_STANDARD, 'userpic');
$upload->image =& vB_Image::fetch_library($vbulletin);
$upload->maxwidth = $vbulletin->userinfo['permissions']['avatarmaxwidth'];
$upload->maxheight = $vbulletin->userinfo['permissions']['avatarmaxheight'];
$upload->maxuploadsize = $vbulletin->userinfo['permissions']['avatarmaxsize'];
$upload->allowanimation = ($vbulletin->userinfo['permissions']['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['cananimateavatar']) ? true : false;
if (!$upload->process_upload($vbulletin->GPC['avatarurl']))
{
$errors = $upload->fetch_error();
$errorlist = '';
foreach ($errors AS $error)
{
$filename = htmlspecialchars_uni($error['filename']);
$errorlist .= $error['error'];
}
return new xmlrpcresp(new xmlrpcval(array(
'result' => new xmlrpcval(false, 'boolean'),
'result_text' => new xmlrpcval(mobiquo_encode($errorlist), 'base64')
), 'struct' ) );
}
}
// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('avatarid', $vbulletin->GPC['avatarid']);
$userdata->save();
return new xmlrpcresp(new xmlrpcval(array(
'result' => new xmlrpcval(true, 'boolean'),
'result_text' => new xmlrpcval('', 'base64')
), 'struct'));
}
function showTestScreen()
{
echo "Attachment Upload Interface for Tapatalk Application<br>";
echo "<br>
<a href=\"https://tapatalk.com/api.php\" target=\"_blank\">Tapatalk API for Universal Forum Access</a><br>
For more details, please visit <a href=\"https://tapatalk.com\" target=\"_blank\">https://tapatalk.com</a>";
exit;
}