-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
299 lines (261 loc) · 9.73 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
<?php
/****************************************************************************/
/* < MangosWeb Enhanced v3 > */
/* Copyright (C) <2009 - 2011> <Wilson212> */
/* < http://keyswow.com > */
/* */
/* Original MangosWeb (C) 2007, Sasha, Nafe, TGM, Peec */
/****************************************************************************/
/***************************************************************
* SET ERROR REPORTING
***************************************************************/
error_reporting(E_ALL);
ini_set('log_errors', TRUE);
ini_set('html_errors', FALSE);
ini_set('error_log', 'core/logs/error_log.txt');
ini_set('display_errors', TRUE);
/***************************************************************
* Define INCLUDED so we can see if pages are included by this one
***************************************************************/
define('INCLUDED', TRUE);
/***************************************************************
* Define page loading time start
***************************************************************/
define('TIME_START', microtime(1));
$_SERVER['REQUEST_TIME'] = time();
/***************************************************************
* Load the Core and Config Classes
***************************************************************/
include('core/class.config.php');
$Config = new Config;
include('core/core.php');
$Core = new Core;
/***************************************************************
* Show Site Notice if enabled in config, and user cookie not set
***************************************************************/
if($Config->get('site_notice_enable') == 1 && !isset($_COOKIE['agreement_accepted']))
{
include('modules/notice/notice.php');
exit();
}
/***************************************************************
* See if the site is installed by checking config defualts
***************************************************************/
if($Config->getDbInfo('db_username') == 'default')
{
header('location: install/');
}
/***************************************************************
* Include the site functions and classes
***************************************************************/
include('core/common.php'); // Holds most of the sites common functions
include('core/class.template.php'); // Sets up the template system
include('core/SDL/class.account.php'); // contains account related scripts and functions
/***************************************************************
* Set the site globals, selected realm, language etc etc
***************************************************************/
$Core->setGlobals();
// Load language file
include('lang/' . $GLOBALS["user_cur_lang"] . '/common.php');
/***************************************************************
* Setup the Database class and Database connections
***************************************************************/
require ('core/class.database.php');
$DB = new Database(
$Config->getDbInfo('db_host'),
$Config->getDbInfo('db_port'),
$Config->getDbInfo('db_username'),
$Config->getDbInfo('db_password'),
$Config->getDbInfo('db_name')
);
// Check the database status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
if($DB->status() != 1)
{
echo "Cannot connect to the Realm database. Please make sure you have run the installer to properly set the DB info in the database.";
die();
}
// Make an array from `dbinfo` column for the selected realm..
$DB_info = $DB->selectRow("SELECT * FROM realmlist WHERE id='".$GLOBALS['cur_selected_realm']."'");
$dbinfo = explode(';', $DB_info['dbinfo']);
// DBinfo column: char_host;char_port;char_username;char_password;charDBname;
// world_host;world_port;world_username;world_pass;worldDBname
$Realm_DB_Info = array(
'char_db_host' => $dbinfo['0'], // char host
'char_db_port' => $dbinfo['1'], // char port
'char_db_username' => $dbinfo['2'], // char user
'char_db_password' => $dbinfo['3'], // char password
'char_db_name' => $dbinfo['4'], //char db name
'w_db_host' => $dbinfo['5'], // world host
'w_db_port' => $dbinfo['6'], // world port
'w_db_username' => $dbinfo['7'], // world user
'w_db_password' => $dbinfo['8'], // world password
'w_db_name' => $dbinfo['9'], // world db name
);
// Free up memory.
unset($dbinfo, $DB_info);
// === Establish the Character DB connection === //
$CDB = new Database(
$Realm_DB_Info['char_db_host'],
$Realm_DB_Info['char_db_port'],
$Realm_DB_Info['char_db_username'],
$Realm_DB_Info['char_db_password'],
$Realm_DB_Info['char_db_name']
);
// Check the CDB status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
if($CDB->status() != 1)
{
echo "Cannot connect to the Character database. Please make sure you have this realm setup successfully in the Admin Panel.
Delete your cookies to reset realm selection back to default";
die();
}
// === Establish the World DB connection === //
$WDB = new Database(
$Realm_DB_Info['w_db_host'],
$Realm_DB_Info['w_db_port'],
$Realm_DB_Info['w_db_username'],
$Realm_DB_Info['w_db_password'],
$Realm_DB_Info['w_db_name']
);
// Check the CDB status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
if($WDB->status() != 1)
{
echo "Cannot connect to the World database. Please make sure you have this realm setup successfully in the Admin Panel.
Delete your cookies to reset realm selection back to default";
die();
}
// Free up memory
unset($Realm_DB_Info);
/***************************************************************
* Load the Account / Auth Class
***************************************************************/
$Account = new Account();
$user = $Account->user;
$user['cur_selected_realm'] = $GLOBALS['cur_selected_realm'];
/***************************************************************
* Load the Template class and setup the template system
***************************************************************/
$Template = new MangosTemplate;
// Lets get the template information
$Template = $Template->loadTemplateXML();
if($Template == FALSE)
{
echo "Fetal Error: Template XML Not Found!";
die();
}
/***************************************************************
* Start of page loading
***************************************************************/
// Start off by checking if the requested page is a module or not
if(!isset($_GET['p']) && isset($_GET['module']))
{
// Scan the directory for installed modules to prevent XSS
$Modulelist = scandir("modules/");
if(in_array($_GET['module'], $Modulelist))
{
include("modules/".$_GET['module']."/module.php");
}
else
{
echo "No Module of that name found!";
}
}
// If page is not a module, then lets load our template pages.
else
{
// if empty page, then load default component(frontpage)
$ext = (isset($_GET['p']) ? $_GET['p'] : (string)$Config->get('default_component'));
// If url looks like so: ?p=account/login (This is a avalid url)
if(strpos($ext, '/') !== FALSE)
{
list($ext, $sub) = explode('/', $ext);
}
else
{
// If empty sub page, load page.index.php
$sub = (isset($_GET['sub']) ? $_GET['sub'] : 'index');
}
$script_file = 'inc/' . $ext . '/' . $ext . '.' . $sub . '.php';
$template_file = $Template['script_path'] . '/' . $ext . '/' . $ext . '.' . $sub . '.php';
// === Start Loading of the Page files === //
// If the requested page is the admin Panel, then we load the admin template
if($ext == 'admin')
{
if(file_exists('inc/admin/body_functions.php'))
{
include('inc/admin/body_functions.php');
}
@include('inc/admin/script_files/admin.' . $sub .'.php');
ob_start();
include('inc/admin/body_header.php');
ob_end_flush();
ob_start();
include('inc/admin/template_files/admin.' . $sub .'.php');
ob_end_flush();
// Set our time end, so we can see how fast the page loaded.
define('TIME_END', microtime(1));
define('PAGE_LOAD_TIME', TIME_END - TIME_START);
include('inc/admin/body_footer.php');
}
// Else, if requested page isnt the admin panel, then load the template
else
{
// Start Loading Of Script Files
@include($script_file);
// If a body functions file exists, include it.
if(file_exists($Template['functions']))
{
include($Template['functions']);
}
ob_start();
include($Template['header']);
ob_end_flush();
// === Start the loading of the template cache === //
// Lets check to see if the page is flagged to cache or not. defined in scriptfile of each page
if(defined('CACHE_FILE'))
{
$CacheFile = CACHE_FILE;
}
else # Not defined
{
$CacheFile = FALSE;
}
// Check if admin has enabled caching, and CACHE_FILE is enabled
if($Config->get('enable_cache') && $CacheFile == TRUE)
{
// If file is cached
if($Core->isCached($Template['number']."_".$ext.".".$sub."_".$GLOBALS['user_cur_lang']))
{
$Contents = $Core->getCache($Template['number']."_".$ext.".".$sub."_".$GLOBALS['user_cur_lang']);
echo $Contents;
}
// If not cached, then get contents of the page and cache them.
else
{
ob_start();
include($template_file);
$Contents = ob_get_flush();
$Core->writeCache($Template['number']."_".$ext.".".$sub."_".$GLOBALS['user_cur_lang'], $Contents);
}
unset($Contents);
}
else
{
ob_start();
include($template_file);
ob_end_flush();
}
// === End cache system, Load the footer === //
// Set our time end, so we can see how fast the page loaded.
define('TIME_END', microtime(1));
define('PAGE_LOAD_TIME', TIME_END - TIME_START);
include($Template['footer']);
}
}
/***************************************************************
* End Page Loading
***************************************************************/
// Close all DB Connections
$DB->__destruct();
$CDB->__destruct();
$WDB->__destruct();
?>