-
Notifications
You must be signed in to change notification settings - Fork 49
/
index.php
266 lines (229 loc) · 8.63 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
<?php
/****************************************************************************/
/* < MangosWeb v4 > */
/* Copyright (C) <2017> <Mistvale.com> */
/* < http://www.mistvale.com > */
/* */
/* Original MangosWeb Enhanced (C) 2010-2011 KeysWow */
/* 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('display_errors', TRUE);
if(file_exists("install/index.php"))
{
// Check if the install/ directorcy exists, redirect if so
header("location: install/");
}
elseif(file_exists("update/index.php"))
{
// Check if the update/ directorcy exists, redirect if so
header("location: update/");
}
/***************************************************************
* 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 Config
***************************************************************/
include('config/config-protected.php');
/***************************************************************
* Setup the Database class and Database connections
***************************************************************/
require('core/class.database.php');
$DB = new Database(
$dbconf['db_host'],
$dbconf['db_port'],
$dbconf['db_username'],
$dbconf['db_password'],
$dbconf['db_name']
);
// Check the database status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
if($DB->status() != 1)
{
echo "Cannot connect to the MaNGOS Web database. Please make sure you have edited the config/config-protected.php file with the correct values.<br>";
die();
}
$mwe_config = $DB->selectRow("SELECT * FROM mw_config LIMIT 1");
/***************************************************************
* Load the Core class
***************************************************************/
include('core/core.php');
$Core = new Core($mwe_config);
/***************************************************************
* Show Site Notice if enabled in config, and user cookie not set
***************************************************************/
if($mwe_config['site_notice_enable'] == 1 && !isset($_COOKIE['agreement_accepted']))
{
include('modules/notice/notice.php');
exit();
}
/***************************************************************
* 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');
// Make an array from `dbinfo` column for the selected realm..
$realm_db = $DB->selectRow("SELECT * FROM mw_realm WHERE realm_id='".$GLOBALS['cur_selected_realm']."'");
// === Establish the Realm DB connection === //
$RDB = new Database(
$mwe_config['db_logon_host'],
$mwe_config['db_logon_port'],
$mwe_config['db_logon_user'],
$mwe_config['db_logon_pass'],
$mwe_config['db_logon_name']
);
// Check the CDB status. 0 = cannot connect, 1 = success, 2 = DB doesnt exist
if($RDB->status() != 1)
{
echo "Cannot connect to the Realm database. Please make sure you have this realm setup successfully in the Admin Panel. Delete your cookies to reset realm selection back to default.<br>";
//die();
}
// === Establish the Character DB connection === //
$CDB = new Database(
$realm_db['db_char_host'],
$realm_db['db_char_port'],
$realm_db['db_char_user'],
$realm_db['db_char_pass'],
$realm_db['db_char_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.<br>";
//die();
}
// === Establish the World DB connection === //
$WDB = new Database(
$realm_db['db_world_host'],
$realm_db['db_world_port'],
$realm_db['db_world_user'],
$realm_db['db_world_pass'],
$realm_db['db_world_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.<br>";
//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)$mwe_config['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();
ob_start();
include($template_file);
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($Template['footer']);
}
}
/***************************************************************
* End Page Loading
***************************************************************/
// Close all DB Connections
$DB->__destruct();
$CDB->__destruct();
$WDB->__destruct();
?>