-
Notifications
You must be signed in to change notification settings - Fork 30
/
index.php
518 lines (413 loc) · 16.2 KB
/
index.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<?php
#apd_set_pprof_trace();
/*======================================================================*\
|| ######################################################################## ||
|| # vBulletin Impex
|| # ----------------------------------------------------------------
|| # All PHP code in this file is Copyright 2000-2014 vBulletin Solutions Inc.
|| # This code is made available under the Modified BSD License -- see license.txt
|| # http://www.vbulletin.com
|| ######################################################################## ||
\*======================================================================*/
// #############################################################################
// Set time limit, error handeling and aborting
// #############################################################################
if (function_exists('set_time_limit') AND get_cfg_var('safe_mode')==0)
{
@set_time_limit(0);
}
ignore_user_abort(true);
error_reporting(E_ALL & ~E_NOTICE);
// #############################################################################
// Define constants
// #############################################################################
define('IDIR', (($getcwd = getcwd()) ? $getcwd : '.'));
define('VB_AREA', 'ImpEx');
// #############################################################################
// Require config & Language
// #############################################################################
if(!is_file(IDIR . '/ImpExConfig.php'))
{
echo 'Cannot find ImpExConfig.php, have you configured the file and renamed it ?';
exit;
}
else
{
require_once (IDIR . '/ImpExConfig.php');
require_once (IDIR . $impexconfig['system']['language']);
}
// #############################################################################
// Requires
// #############################################################################
$auth_redirect = 'index.php';
require_once (IDIR . '/impex_auth.php');
require_once (IDIR . '/db_mysql.php');
require_once (IDIR . '/ImpExFunction.php');
require_once (IDIR . '/ImpExSession.php');
require_once (IDIR . '/ImpExController.php');
require_once (IDIR . '/ImpExDisplay.php');
require_once (IDIR . '/ImpExDisplayWrapper.php');
// #############################################################################
// Checking for standalnoe
// #############################################################################
if (file_exists('../includes/config.php')) // If that is there then its installed
{
// If the admincp was renamed, lets try and find it depending on vBulletin version
$admincpdir = '';
require('../includes/config.php');
if (!empty($admincpdir)) // 3.0.x will overwrite this
{
// Version 3.0.x
chdir("../{$admincpdir}/");
}
else if (!empty($config['Misc']['admincpdir']))
{
if(is_dir("../{$config['Misc']['admincpdir']}/"))
{
// Version 3.6.x
chdir("../");
include ('./includes/adminfunctions.php'); // Only for 3.6.x
}
else
{
// The config.php path is invalid
die('config.php admincp path does not exsist');
}
}
else
{
// Should never be here.
}
// Get the admincp global
require_once('./global.php'); // Works for 3.6.x and 3.0.x as global didn't change/move.
$usewrapper = true;
}
else
{
// Running standalone
chdir('../'); // make sure our includes use the same paths
$usewrapper = false;
}
// #############################################################################
// Try to locate vBulletin config, or use ImpExConfig
// #############################################################################
// $usewrapper is a flag for standalone, so if its true were installed
if ($usewrapper)
{
include ('./includes/config.php');
$using_local_config = '<p>' . $impex_phrases['using_local_config'] . '</p>';
// Only if it is all there or a 3.5 config file
if ($config['Database']['dbtype'] AND $config['MasterServer']['servername'] AND $config['MasterServer']['username'] AND $config['MasterServer']['password'] AND $config['Database']['dbname'])
{
// Over write ImpExConfig.php
$impexconfig['target']['databasetype'] = 'mysql';
$impexconfig['target']['server'] = trim($config['MasterServer']['servername']) . ":" . trim($config['MasterServer']['port']);
$impexconfig['target']['user'] = trim($config['MasterServer']['username']);
$impexconfig['target']['password'] = trim($config['MasterServer']['password']);
$impexconfig['target']['database'] = trim($config['Database']['dbname']);
$impexconfig['target']['tableprefix'] = trim($config['Database']['tableprefix']);
$impexconfig['target']['charset'] = trim($config['Mysqli']['charset']);
}
}
else
{
$using_local_config = '<p>' . $impex_phrases['using_impex_config'] . '</p>';
}
// #############################################################################
// Database connect
// #############################################################################
$Db_target = new DB_Sql_vb_impex();
$Db_source = new DB_Sql_vb_impex();
$Db_target->appname = 'vBulletin:ImpEx Target';
$Db_target->appshortname = 'vBulletin:ImpEx Target';
$Db_target->database = $impexconfig['target']['database'];
$Db_target->type = $impexconfig['target']['databasetype'];
$Db_target->connect($impexconfig['target']['server'], $impexconfig['target']['user'], $impexconfig['target']['password'], $impexconfig['target']['persistent'], $impexconfig['target']['charset']);
$Db_target->select_db($impexconfig['target']['database']);
// #############################################################################
// Session start
// #############################################################################
$ImpEx = new ImpExController();
$session_state = $ImpEx->return_session($Db_target, $impexconfig['target']['tableprefix']);
if ($session_state)
{
$ImpExSession = $session_state;
}
else
{
$ImpExSession = new ImpExSession();
}
// #############################################################################
// Requires ImpExDatabase version (has to be done here as it needs the session)
// #############################################################################
require_once (IDIR . '/ImpExDatabaseCore.php');
#ImpExDatabase_<product>_version.php
switch ($ImpExSession->get_session_var('targetsystem'))
{
case 400:
require_once (IDIR . '/ImpExDatabase_400.php');
break;
case 360:
require_once (IDIR . '/ImpExDatabase_360.php');
break;
case 350:
require_once (IDIR . '/ImpExDatabase_350.php');
break;
case 309:
require_once (IDIR . '/ImpExDatabase_309.php');
break;
case 'blog10':
require_once (IDIR . '/ImpExDatabase_blog_001.php');
break;
case 'blog40':
require_once (IDIR . '/ImpExDatabase_blog_400.php');
break;
case 'cms10':
require_once (IDIR . '/ImpExDatabase_cms_001.php');
break;
default:
require_once (IDIR . '/ImpExDatabase_360.php');
break;
}
// Module extends database
require_once (IDIR . '/ImpExModule.php');
require_once (IDIR . '/ImpExData.php');
// #############################################################################
// Instantiate ImpExDisplay
// #############################################################################
if($usewrapper)
{
$ImpExDisplay = new ImpExDisplayWrapper();
}
else
{
$ImpExDisplay = new ImpExDisplay();
}
$ImpExDisplay->phrases =& $impex_phrases;
// #############################################################################
// create vbfields
// #############################################################################
if($ImpExSession->get_session_var('vbfields') != 'done')
{
require_once(IDIR. '/vbfields.php');
$queries = &retrieve_vbfields_queries($impexconfig['target']['tableprefix']);
foreach ($queries AS $query)
{
$Db_target->query($query);
}
$ImpExSession->add_session_var('vbfields', 'done');
}
// #############################################################################
// initalise error store
// #############################################################################
if($ImpExSession->get_session_var('errortable') != 'done')
{
// Just incase the session was removed and the error table is still there.
$Db_target->query("DROP TABLE IF EXISTS {$impexconfig['target']['tableprefix']}impexerror");
// Create a new one.
$error_table = "CREATE TABLE {$impexconfig['target']['tableprefix']}impexerror (
errorid bigint(20) unsigned NOT NULL auto_increment,
errortype varchar(10) NOT NULL default '',
classnumber varchar(3) NOT NULL default '',
importid bigint(20) NOT NULL default 0,
error varchar(250) default 'NULL',
remedy varchar(250) default 'NULL',
PRIMARY KEY (errorid)
) ENGINE=MyISAM";
$Db_target->query($error_table);
$ImpExSession->add_session_var('errortable', 'done');
}
$ImpExSession->_target_db =& $Db_target;
// #############################################################################
// Add vars to session
// #############################################################################
$ImpExSession->add_session_var('systempath', IDIR);
$ImpExSession->add_session_var('sourceexists', $impexconfig['sourceexists']);
$ImpExSession->add_session_var('targettableprefix', $impexconfig['target']['tableprefix']);
$ImpExSession->add_session_var('targetdatabasetype', strtolower($impexconfig['target']['databasetype']));
$ImpExSession->add_session_var('sourcetableprefix', $impexconfig['source']['tableprefix']);
$ImpExSession->add_session_var('sourcedatabasetype', strtolower($impexconfig['source']['databasetype']));
$ImpExSession->add_session_var('errorlogging', $impexconfig['system']['errorlogging']);
$ImpExSession->add_session_var('pagespeed', $impexconfig['system']['pagespeed']);
if($impexconfig['sourceexists'])
{
if ($impexconfig['source']['databasetype'] == 'mssql')
{// Check if mssql support is in php or should a connection be made via pure style .......
if(!function_exists('mssql_connect'))
{
if(function_exists('sqlsrv_connect'))
{
$impexconfig['source']['databasetype'] = 'sqlsrv';
}
else
{
$ImpExDisplay->display_error($ImpExDisplay->phrases['no_mssql_support']);
$ImpExDisplay->display_error($ImpExDisplay->phrases['no_mssql_support_link']);
exit;
}
}
}
$Db_source->appname = 'vBulletin:ImpEx Source';
$Db_source->appshortname = 'vBulletin:ImpEx Source';
$Db_source->database = $impexconfig['source']['database'];
if (strtolower(trim($impexconfig['source']['databasetype'])) == 'mysql' OR strtolower(trim($impexconfig['source']['databasetype'])) == 'mysqli')
{
$Db_source->type = 'mysql';
}
else
{
$Db_source->type = $impexconfig['source']['databasetype'];
}
$Db_source->connect($impexconfig['source']['server'], $impexconfig['source']['user'], $impexconfig['source']['password'], $impexconfig['source']['persistent'], $impexconfig['source']['charset']);
if ($Db_source->link_id)
{ // got connected
switch ($Db_source->geterrno())
{
case 1046:
$ImpExDisplay->display_error($ImpExDisplay->phrases['no_source_set']);
exit;
break;
case 1049:
$ImpExDisplay->display_error($ImpExDisplay->phrases['source_not_exsist']);
exit;
break;
}
}
else
{
$ImpExDisplay->display_error($ImpExDisplay->phrases['failed_connection']);
exit;
}
// php versions before 4.2.0 do nasty things with multiple connections to the same server
// See http://uk.php.net/manual/en/function.mysql-connect.php
if (($Db_target->link_id === $Db_source->link_id) AND phpversion() < '4.2.0')
{
$Db_target->require_db_reselect = true;
$Db_source->require_db_reselect = true;
}
}
$ImpEx->get_post_values($ImpExSession,$_POST);
// #############################################################################
// Autosubmit
// #############################################################################
$ImpExDisplay->update_basic('autosubmit',$ImpExSession->get_session_var('autosubmit'));
// #############################################################################
// Autosubmit & Home
// #############################################################################
$currentmoduleworking = $ImpExSession->any_working();
$system = $ImpExSession->get_session_var('system');
$module = $ImpExSession->get_session_var('module');
if ($currentmoduleworking != NULL)
{
$start_at = intval($ImpExSession->get_session_var('startat'));
$per_page = intval($ImpExSession->get_session_var('perpage'));
// Set the title here before the default is set
$ImpExDisplay->_screenbasic['title'] = $ImpExSession->_moduletitles[$module] . " {$start_at} :: " . ($start_at + $per_page);
}
if ($module == '000' OR $module == NULL)
{
if ($system != '' AND $system != 'NONE')
{
// When there is a system chosen, but not running, build the module list.
require_once (IDIR . "/systems/{$system}/000.php");
$ImpExSession->build_module_list($ImpExDisplay);
}
else
{
if ($system == '')
{
// Catching a blank string
$ImpExSession->set_session_var('system', 'NONE');
}
else
{
// Nothing chosen yet
$ImpExSession->set_session_var('system', $system);
$ImpExDisplay->update_basic('title', $system);
}
}
}
echo $ImpExDisplay->page_header() .
'<br> <div align="center"><a href="help.php">' . $ImpExDisplay->phrases['db_cleanup'] .
'</a> ||| <a href="http://www.vbulletin.com/docs/html/impex" target="blank_"> ' .
$ImpExDisplay->phrases['online_manual'] . '</a></div>';
if ($using_local_config) { echo '<div align="center"> ' . $using_local_config . '</div><br>'; }
// #############################################################################
// Resume
// #############################################################################
if ($currentmoduleworking != NULL)
{
// Ensure we have the $system_000.php module to extend from
require_once (IDIR . "/systems/{$system}/000.php");
// Get the one we are working with.
require_once (IDIR . "/systems/{$system}/{$currentmoduleworking}.php");
// Create that class
$classname = "{$system}_{$currentmoduleworking}";
$ModuleCall = new $classname($ImpExSession);
$ModuleCall->system = $system;
if ($module == '001' AND $ImpExSession->get_session_var('targetsystem') == 400)
{
$ModuleCall->_import_ids = array_merge($ModuleCall->_import_ids, $ModuleCall->_import_ids_400);
}
// Then call resume on it
$ModuleCall->resume($ImpExSession, $ImpExDisplay, $Db_target, $Db_source);
}
// #############################################################################
// Init
// #############################################################################
if ($module != '000' AND $module != NULL AND $currentmoduleworking == FALSE)
{
$ImpExDisplay->update_basic('displaymodules', 'FALSE');
// Ensure we have the $system_000.php module to extend from
if (is_file(IDIR . "/systems/{$system}/000.php"))
{
require_once(IDIR . "/systems/{$system}/000.php");
}
else
{
die($ImpExDisplay->phrases['no_system']);
}
// Check if its a core module
if ($module < 900)
{
require_once (IDIR . "/systems/{$system}/{$module}.php");
// Create the name of the class to instantiate
$classname = "{$system}_{$module}";
}
else
{
require_once (IDIR . "/cleanup.php");
// Create the name of the class to instantiate
$classname = "core_{$module}";
}
// Instantiate it
$ModuleCall = new $classname($ImpExDisplay);
// If its been FINISHED, then we are restarting it
if ($ImpExSession->get_session_var($module) == 'FINISHED')
{
$ModuleCall->restarted();
}
// Sets the current to working
$ModuleCall->using($ImpExSession);
// Actually calls the init and does the work
$ModuleCall->init($ImpExSession, $ImpExDisplay, $Db_target, $Db_source);
}
// #############################################################################
// Update & Display
// #############################################################################
$ImpEx->updateDisplay($ImpExSession, $ImpExDisplay);
echo $ImpExDisplay->display($ImpExSession);
if ($displayerrors)
{
echo $ImpExSession->display_errors('all');
}
// #############################################################################
// Session End
// #############################################################################
$ImpEx->store_session($Db_target, $impexconfig['target']['tableprefix'], $ImpExSession);
echo "\n<!-- From {$system} to " . $ImpExSession->get_session_var('targetsystem') . "-->\n";
echo "\n<!-- PWD " . getcwd() . "-->\n";
echo $ImpExDisplay->page_footer();
// New comment
/*======================================================================*/
?>