PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/index.php

https://bitbucket.org/chaosdeveloper/old-chaosweb
PHP | 357 lines | 233 code | 57 blank | 67 comment | 70 complexity | 17996db96310ab8421664143c5441b33 MD5 | raw file
  1. <?php
  2. /********************************************************************************/
  3. /* */
  4. /* < MangosWeb is a Web-Fonted for Mangos (mangosproject.org) > */
  5. /* Copyright (C) <2007> <Sasha,TGM,Peec,Nafe> */
  6. /* */
  7. /* < ChaosWeb ist eine Weiterentwicklung von MangosWeb (chaosweb.ohost.de) > */
  8. /* Copyright (C) <2009> <Sternedeslichts,Magge> */
  9. /* */
  10. /* This program is free software: you can redistribute it and/or modify */
  11. /* it under the terms of the GNU General Public License as published by */
  12. /* the Free Software Foundation, either version 2 of the License, or */
  13. /* (at your option) any later version. */
  14. /* */
  15. /* This program is distributed in the hope that it will be useful, */
  16. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  17. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  18. /* GNU General Public License for more details. */
  19. /* */
  20. /* You should have received a copy of the GNU General Public License */
  21. /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
  22. /* */
  23. /********************************************************************************/
  24. // wurde ChaosWeb schon installiert?
  25. if(file_exists('install/index.php')) {
  26. include('install/index.php');
  27. exit();
  28. }
  29. // Set error reporting to only a few things.
  30. error_reporting(E_ERROR | E_PARSE | E_WARNING);
  31. ini_set('display_errors', '0');
  32. // Define INCLUDED so that we can check other pages if they are included by this file
  33. define('INCLUDED', true);
  34. // Start a variable that shows how fast page loaded.
  35. $time_start = microtime(1);
  36. $_SERVER['REQUEST_TIME'] = time();
  37. // Initialize config's.
  38. include('core/class.mangosweb.php');
  39. $MW = new mangosweb; // Super global.
  40. // Site functions & classes ...
  41. include('core/common.php');
  42. include('core/mangos.class.php');
  43. include('core/class.auth.php');
  44. require_once('core/dbsimple/Generic.php');
  45. require('core/class.captcha.php');
  46. include('core/cache_class/safeIO.php');
  47. include('core/cache_class/gCache.php');
  48. // Inizialize difrent variables.
  49. global $MW, $mangos;
  50. // Super-Global variables.
  51. $GLOBALS['users_online']=array();
  52. $GLOBALS['guests_online']=0;
  53. $GLOBALS['messages'] = '';
  54. $GLOBALS['redirect'] = '';
  55. $GLOBALS['sidebarmessages'] = '';
  56. $GLOBALS['context_menu'] = array();
  57. $GLOBALS['user_cur_lang'] = (string)$MW->getConfig->generic->default_lang;
  58. // Inzizalize Cache class
  59. $cache = new gCache;
  60. $cache->folder = './core/cache/sites';
  61. $cache->timeout = $MW->getConfig->generic->cache_expiretime;
  62. // Assign a connect variable to class call.
  63. // DB layer documentation at http://en.dklab.ru/lib/DbSimple/
  64. $DB = dbsimple_Generic::connect("".$MW->getDbInfo['db_type']."://".$MW->getDbInfo['db_username'].":".$MW->getDbInfo['db_password']."@".$MW->getDbInfo['db_host'].":".$MW->getDbInfo['db_port']."/".$MW->getDbInfo['db_name']."");
  65. // Set error handler for $DB.
  66. $DB->setErrorHandler('databaseErrorHandler');
  67. // Also set to default encoding for $DB
  68. $DB->query("SET NAMES ".$MW->getDbInfo['db_encoding']);
  69. // Play arround for IIS lake on $_SERVER['REQUEST_URI']
  70. if ($_SERVER['REQUEST_URI'] == "") {
  71. if ($_SERVER['QUERY_STRING'] != "") {
  72. $__SERVER['REQUEST_URI'] = $_SERVER["SCRIPT_NAME"] ."?". $_SERVER['QUERY_STRING'];
  73. } else {
  74. $__SERVER['REQUEST_URI'] = $_SERVER["SCRIPT_NAME"];
  75. }
  76. } else {
  77. $__SERVER['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
  78. }
  79. // Build path vars //
  80. $MW->add_temp_confs(array(
  81. 'site_href' => str_replace('//','/',str_replace('\\','/',dirname($_SERVER['SCRIPT_NAME']).'/'))
  82. ));
  83. $MW->add_temp_confs(array(
  84. 'site_domain' => $_SERVER['HTTP_HOST'],
  85. 'email_href' => $_SERVER['HTTP_HOST']
  86. ));
  87. $MW->add_temp_confs(array(
  88. 'base_href' => 'http://'.$MW->getConfig->temp->email_href.''.$MW->getConfig->temp->site_href,
  89. ));
  90. // Check lang ======================================
  91. if(isset($_COOKIE['Language'])) $GLOBALS['user_cur_lang'] = $_COOKIE['Language'];
  92. loadLanguages();
  93. // ================================================
  94. // Load auth system //
  95. $auth = new AUTH($DB,$MW->getConfig);
  96. $user = $auth->user;
  97. // ================== //
  98. //Determine Current Template
  99. if ($user['id'] == -1)
  100. { $currtmp = "templates/offlike"; }
  101. else {
  102. $currtmp = $DB->selectCell("SELECT theme FROM `account_extend` WHERE account_id=?d", $user['id']);
  103. foreach ($MW->getConfig->templates->template as $template) { $currtmp2[] = $template; }
  104. $currtmp = "templates/" . $currtmp2[$currtmp];
  105. }
  106. // Load Permissions and aviable sites.
  107. include('core/default_components.php');
  108. // Start of context menu. ( Only make an array for later output )
  109. $GLOBALS['context_menu'][] = array('title'=>$lang['mainpage'],'link'=>'index.php');
  110. if($user['id']<=0){
  111. $GLOBALS['context_menu'][] = array('title'=>$lang['register'],'link'=>mw_url('account', 'register'));
  112. }
  113. $GLOBALS['context_menu'][] = array('title'=>'Forum','link'=>'index.php?n=forum');
  114. $GLOBALS['context_menu'][] = array('title'=>$lang['players_online'],'link'=>mw_url('server', 'playersonline'));
  115. if((isset($user['g_is_admin']) || isset($user['g_is_supadmin'])) && ($user['g_is_admin']==1 || $user['g_is_supadmin']==1)){
  116. $allowed_ext[] = 'admin';
  117. $GLOBALS['context_menu'][] = array('title'=>'------------------','link'=>'#');
  118. $GLOBALS['context_menu'][] = array('title'=>$lang['admin_panel'],'link'=>'index.php?n=admin');
  119. }
  120. // for mod_rewrite query_string fix //
  121. global $_GETVARS;
  122. $req_vars = parse_url($__SERVER['REQUEST_URI']);
  123. if(isset($req_vars['query'])){
  124. parse_str($req_vars['query'], $req_arr);
  125. $_GETVARS = $req_arr;
  126. }
  127. unset($req_arr, $req_vars);
  128. // ======================================================= //
  129. // Finds out what realm we are viewing.
  130. if ((int)$MW->getConfig->generic_values->realm_info->multirealm && isset($_REQUEST['changerealm_to'])){
  131. setcookie("cur_selected_realmd", intval($_REQUEST['changerealm_to']), time()+(3600*24)); // expire in 24 hour
  132. $user['cur_selected_realmd'] = intval($_REQUEST['changerealm_to']);
  133. }elseif ((int)$MW->getConfig->generic_values->realm_info->multirealm && isset($_COOKIE['cur_selected_realmd'])){
  134. $user['cur_selected_realmd'] = intval($_COOKIE['cur_selected_realmd']);
  135. }else{
  136. $user['cur_selected_realmd'] = $MW->getConfig->generic_values->realm_info->default_realm_id;
  137. }
  138. // Make an array from `dbinfo` column for the selected realm..
  139. $mangos_info = $DB->selectCell("SELECT dbinfo FROM `realmlist` WHERE id=?d",$user['cur_selected_realmd']);
  140. $dbinfo_mangos = explode(';', $mangos_info);
  141. if((int)$MW->getConfig->generic->use_archaeic_dbinfo_format) {
  142. //alternate config - for users upgrading from Modded MaNGOS Web
  143. //DBinfo column: host;port;username;password;WorldDBname;CharDBname
  144. $mangos = array(
  145. 'db_type' => 'mysql',
  146. 'db_host' => $dbinfo_mangos['0'], //ip of db world
  147. 'db_port' => $dbinfo_mangos['1'], //port
  148. 'db_username' => $dbinfo_mangos['2'], //world user
  149. 'db_password' => $dbinfo_mangos['3'], //world password
  150. 'db_name' => $dbinfo_mangos['4'], //world db name
  151. 'db_char' => $dbinfo_mangos['5'], //character db name
  152. 'db_encoding' => 'utf8', // don't change
  153. );
  154. }
  155. else {
  156. //normal config, as outlined in how-to
  157. //DBinfo column: username;password;port;host;WorldDBname;CharDBname
  158. $mangos = array(
  159. 'db_type' => 'mysql',
  160. 'db_host' => $dbinfo_mangos['3'], //ip of db world
  161. 'db_port' => $dbinfo_mangos['2'], //port
  162. 'db_username' => $dbinfo_mangos['0'], //world user
  163. 'db_password' => $dbinfo_mangos['1'], //world password
  164. 'db_name' => $dbinfo_mangos['4'], //world db name
  165. 'db_char' => $dbinfo_mangos['5'], //character db name
  166. 'db_encoding' => 'utf8', // don't change
  167. );
  168. }
  169. unset($dbinfo_mangos, $mangos_info); // Free up memory.
  170. if((int)$MW->getConfig->generic->use_alternate_mangosdb_port) {
  171. $mangos['db_port'] = (int)$MW->getConfig->generic->use_alternate_mangosdb_port;
  172. }
  173. // Output error message and die if user has not changed info in realmd.realmlist.`dbinfo` .
  174. if($mangos['db_host'] == '127.0.0.1' && $mangos['db_port'] == '3306' && $mangos['db_username'] == 'username' && $mangos['db_password'] == 'password' && $mangos['db_name'] == 'DBName'){
  175. echo "Please read README_HOWTO.txt, This is a error message btw. You must remember to setup the WORLD database information in the realm.realmlist database! :)<br />Edit the `dbinfo` to: World database info: username;password;3306;127.0.0.1;DBName";
  176. die;
  177. }
  178. //Connects to WORLD DB
  179. $WSDB = DbSimple_Generic::connect("".$mangos['db_type']."://".$mangos['db_username'].":".$mangos['db_password']."@".$mangos['db_host'].":".$mangos['db_port']."/".$mangos['db_name']."");
  180. if($WSDB)$WSDB->setErrorHandler('databaseErrorHandler');
  181. if($WSDB)$WSDB->query("SET NAMES ".$mangos['db_encoding']);
  182. $CHDB = DbSimple_Generic::connect("".$mangos['db_type']."://".$mangos['db_username'].":".$mangos['db_password']."@".$mangos['db_host'].":".$mangos['db_port']."/".$mangos['db_char']."");
  183. if($CHDB)$CHDB->setErrorHandler('databaseErrorHandler');
  184. if($CHDB)$CHDB->query("SET NAMES ".$mangos['db_encoding']);
  185. //Load characters list
  186. if (isset($user['id']) && $user['id']>0) {
  187. $characters = $CHDB->select('SELECT guid,name FROM `characters` WHERE account=?d', $user['id']);
  188. if (isset($_REQUEST['cur_selected_character'])) {
  189. foreach($characters as $character) {
  190. if ($character['guid']==$_REQUEST['cur_selected_character']) {
  191. $DB->query('UPDATE account_extend SET character_id=?d,character_name=? WHERE account_id=?d', $character['guid'], $character['name'], $user['id']);
  192. }
  193. }
  194. }
  195. }else{
  196. $characters = array();
  197. }
  198. if(empty($_GET['p']) OR $_GET['p'] < 1)$p = 1;else $p = $_GET['p'];
  199. $ext = (isset($_REQUEST['n'])?$_REQUEST['n']:(string)$MW->getConfig->generic->default_component);
  200. if (strpos($ext, '/')!==false)
  201. list($ext, $sub) = explode('/', $ext);
  202. else
  203. $sub = (isset($_REQUEST['sub'])?$_REQUEST['sub']:'index');
  204. $req_tpl = false;
  205. //initialize modules
  206. //if installing a new module, please delete the cache file
  207. include('components/modules/initialize.php');
  208. if(in_array($ext,$allowed_ext)){
  209. // load component
  210. //set defaults here to be loaded -- these can be changed via the main.php or whatnot
  211. //this is used especially in the case of the module system
  212. $script_file = 'components/'.$ext.'/'.$ext.'.'.$sub.'.php';
  213. $template_file = 'templates/'.(string)$MW->getConfig->generic->template.'/'.$ext.'/'.$ext.'.'.$sub.'.php';
  214. require('components/'.$ext.'/'.'main.php');
  215. $group_privilege = $com_content[$ext][$sub][0];
  216. $expectation = (substr($group_privilege,0,1)=='!') ? 0 : 1;
  217. if ($expectation==0) $group_privilege = substr($group_privilege,1);
  218. if($group_privilege && $user[$group_privilege] != $expectation)
  219. exit('<h2>Forbidden</h2><meta http-equiv=refresh content="3;url=\'./\'">');
  220. // ==================== //
  221. if(isset($_REQUEST['n']) && isset($lang[$com_content[$ext]['index'][1]]))$pathway_info[] = array('title'=>$lang[$com_content[$ext]['index'][1]],'link'=>$com_content[$ext]['index'][2]);
  222. // ==================== //
  223. foreach ($com_content[(string)$ext] as $sub_name => $sub_conf){
  224. if($sub_conf[4]==1){
  225. if($sub_conf[0]){
  226. if($user[$sub_conf[0]]==1){
  227. $GLOBALS['context_menu'][] = array('title'=>(isset($lang[$sub_conf[1]]) ? $lang[$sub_conf[1]] : '??title??'),'link'=>(isset($sub_conf[2]) ? $sub_conf[2] : '?link?'));
  228. }
  229. }
  230. else{
  231. if(isset($lang[$sub_conf[1]]))$GLOBALS['context_menu'][] = array('title'=>$lang[$sub_conf[1]],'link'=>$sub_conf[2]);
  232. }
  233. }
  234. }
  235. if($sub){
  236. if($com_content[$ext][$sub]){
  237. if($com_content[$ext][$sub][0]){
  238. if($user[$com_content[$ext][$sub][0]]==1){
  239. $req_tpl = TRUE;
  240. @include($script_file);
  241. }
  242. }
  243. else{
  244. $req_tpl = TRUE;
  245. @include($script_file);
  246. }
  247. }
  248. }
  249. if(empty($_GET['nobody'])){
  250. // DEBUG //
  251. if((int)$MW->getConfig->generic->debuginfo){
  252. output_message('debug','DEBUG://'.$DB->_statistics['count']);
  253. output_message('debug','<pre>'.print_r($_SERVER,true).'</pre>');
  254. }
  255. // =======//
  256. include('templates/'.(string)$MW->getConfig->generic->template.'/body_functions.php');
  257. ob_start();
  258. include('templates/'.(string)$MW->getConfig->generic->template.'/body_header.php');
  259. ob_end_flush();
  260. if($req_tpl){
  261. if(file_exists($template_file)){
  262. // Only cache if user is not logged in.
  263. if ($user['id'] < 0 && (int)$MW->getConfig->generic->cache_expiretime != 0){
  264. // Start caching process But we want to exclude some cases.
  265. if (
  266. isset($_REQUEST['n']) && $_REQUEST['n'] != 'account'
  267. ){
  268. $cache->contentId = md5('CONTENT'.$_SERVER['REQUEST_URI']);
  269. if ($cache->Valid()) {
  270. echo $cache->content;
  271. }else{
  272. $cache->capture();
  273. include($template_file);
  274. $cache->endcapture();
  275. }
  276. }else{
  277. include($template_file);
  278. }
  279. }else{
  280. // Create output buffer
  281. ob_start();
  282. include($template_file);
  283. ob_end_flush();
  284. }
  285. }
  286. }
  287. $time_end = microtime(1);
  288. $exec_time = $time_end - $time_start;
  289. include('templates/'.(string)$MW->getConfig->generic->template.'/body_footer.php');
  290. }
  291. else{
  292. if(file_exists($template_file)){
  293. include($template_file);
  294. }
  295. }
  296. }
  297. else{
  298. echo'<h2>Forbidden</h2><meta http-equiv=refresh content="3;url=\'./\'">';
  299. }
  300. ?>