PageRenderTime 151ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

http://lansuite.googlecode.com/
PHP | 385 lines | 224 code | 83 blank | 78 comment | 75 complexity | 7d08cb3d85ca1d60ff807cf1499f9127 MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. ### Set Error Reporting & INI-Settings
  3. if (defined('E_STRICT')) error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_STRICT); // Will work for PHP >= 5.3
  4. elseif (defined('E_DEPRECATED')) error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); // Will work for PHP >= 5.3
  5. else error_reporting(E_ALL ^ E_NOTICE); // For PHP < 5.3
  6. if (function_exists('date_default_timezone_set')) date_default_timezone_set('Europe/Berlin'); // As of PHP 5.3 this needs to be set. Otherwise some webservers will throw warnings
  7. if (function_exists('ini_set')) {
  8. #ini_set('display_errors', 0);
  9. #ini_set('log_errors', 1);
  10. #ini_set('error_log', 'log/php/');
  11. // Disable SID in URL
  12. ini_set('url_rewriter.tags', '');
  13. }
  14. function myErrorHandler($errno, $errstr, $errfile, $errline) {
  15. global $PHPErrors, $PHPErrorsFound, $db, $auth;
  16. // Only show errors, which sould be reported according to error_reporting
  17. // Also filters @ (for @ will have error_reporting "0")
  18. $rep = ini_get('error_reporting');
  19. if(!($rep & $errno)) return false;
  20. // error_reporting setting currently doesn't show the following errors:
  21. // E_NOTICE
  22. // E_DEPRECATED
  23. // E_USER_NOTICE
  24. // E_USER_DEPRECATED
  25. // Should change in the future!
  26. switch($errno){
  27. case E_ERROR: $errors = "Error"; break; // not catched
  28. case E_WARNING: $errors = "Warning"; break;
  29. case E_PARSE: $errors = "Parse Error"; break; // not catched
  30. case E_NOTICE: $errors = "Notice"; break;
  31. case E_CORE_ERROR: $errors = "Core Error"; break; // not catched
  32. case E_CORE_WARNING: $errors = "Core Warning"; break; // not catched
  33. case E_COMPILE_ERROR: $errors = "Compile Error"; break; // not catched
  34. case E_COMPILE_WARNING: $errors = "Compile Warning"; break; // not catched
  35. case E_USER_ERROR: $errors = "User Error"; break;
  36. case E_USER_WARNING: $errors = "User Warning"; break;
  37. case E_USER_NOTICE: $errors = "User Notice"; break;
  38. case E_STRICT: $errors = "Strict Notice"; break; // catched only outside this file
  39. case E_RECOVERABLE_ERROR: $errors = "Recoverable Error"; break;
  40. default:
  41. if (defined('E_DEPRECATED') and $errno == E_DEPRECATED) $errors = "Deprecated";
  42. elseif (defined('E_USER_DEPRECATED') and $errno == E_USER_DEPRECATED) $errors = "User Deprecated";
  43. else $errors = "Unknown error ($errno)";
  44. break;
  45. }
  46. // Store error, to print it later
  47. #$err = '<b>'. $errors .'</b>: '. $errstr .' in <b>'. $errfile .'</b> on line <b>'. $errline .'</b><br /><br />';
  48. $err = sprintf("PHP %s: %s in %s on line %d", $errors, $errstr, $errfile, $errline);
  49. // Write error to log file
  50. if (ini_get('log_errors')) error_log($err);
  51. // Write to $PHPError for onscreen output later
  52. $PHPErrors .= $err .'<br />';
  53. $PHPErrorsFound = 1;
  54. // Write to DB-Log
  55. // Attention: Be aware of loops!
  56. if (isset($db) and $db->success) $db->qry('INSERT INTO %prefix%log
  57. SET date = NOW(), userid = %int%, type = 3, description = %string%, sort_tag = "PHP-Fehler"',
  58. (int)$auth['userid'], $err);
  59. return true;
  60. }
  61. $PHPErrorsFound = 0;
  62. $PHPErrors = '';
  63. set_error_handler("myErrorHandler");
  64. ### Start session-management
  65. #session_save_path('ext_inc/session'); Leave to hosters default value, for some don't seam to empty it and data here counts against web space quota
  66. session_start();
  67. ### Initialise Frameworkclass for Basic output
  68. include_once("inc/classes/class_framework.php");
  69. $framework = new framework();
  70. $framework->fullscreen($_GET['fullscreen']); // Switch fullscreen via GET
  71. // Notlösung... design als base und popup sollen ganz verschwinden
  72. if ($_GET['design']=='base' OR $_GET['design']=='popup' OR $_GET['design']=='ajax' OR $_GET['design']=='print' OR $_GET['design']=='beamer') $frmwrkmode = $_GET['design']; // Set Popupmode via GET (base, popup)
  73. if ($_GET['frmwrkmode']) $frmwrkmode = $_GET['frmwrkmode']; // Set Popupmode via GET (base, popup)
  74. if (isset($frmwrkmode)) $framework->set_modus($frmwrkmode);
  75. // Ende Notlösung
  76. ### Set HTTP-Headers
  77. header('Content-Type: text/html; charset=utf-8');
  78. #header('Content-Type: application/xhtml+xml; charset=utf-8');
  79. #header("Cache-Control: no-cache, must-revalidate");
  80. include_once("ext_scripts/mobile_device_detect.php");
  81. $framework->IsMobileBrowser = mobile_device_detect();
  82. // For XHTML compatibility
  83. @ini_set('arg_separator.output', '&amp;');
  84. ### load $_POST and $_GET variables
  85. // Fallback for PHP < 4.1 (still needed?)
  86. if (!is_array($_POST)) $_POST = $HTTP_POST_VARS;
  87. if (!is_array($_GET)) $_GET = $HTTP_GET_VARS;
  88. if (!is_array($_COOKIE)) $_COOKIE = $HTTP_COOKIE_VARS;
  89. // Base Functions (anything that doesnt belong elsewere)
  90. require_once("inc/classes/class_func.php");
  91. $func = new func;
  92. // Prevent XSS
  93. foreach ($_GET as $key => $val) if (!is_array($_GET[$key])) $_GET[$key] = $func->NoHTML($_GET[$key], 1);
  94. else foreach ($_GET[$key] as $key2 => $val2) if (!is_array($_GET[$key][$key2])) $_GET[$key][$key2] = $func->NoHTML($_GET[$key][$key2], 1);
  95. else foreach ($_GET[$key][$key2] as $key3 => $val3) $_GET[$key][$key2][$key3] = $func->NoHTML($_GET[$key][$key2][$key3], 1);
  96. $_SERVER['REQUEST_URI'] = $func->NoHTML($_SERVER['REQUEST_URI'], 1);
  97. $_SERVER['HTTP_REFERER'] = $func->NoHTML($_SERVER['HTTP_REFERER'], 1);
  98. $_SERVER['QUERY_STRING'] = $func->NoHTML($_SERVER['QUERY_STRING'], 1);
  99. // Save original Array
  100. if (get_magic_quotes_gpc()) {
  101. foreach ($_GET as $key => $val) if (!is_array($_GET[$key])) $__GET[$key] = stripslashes($_GET[$key]);
  102. foreach ($_POST as $key => $val) if (!is_array($_POST[$key])) $__POST[$key] = stripslashes($_POST[$key]);
  103. foreach ($_COOKIE as $key => $val) if (!is_array($_COOKIE[$key])) $__COOKIE[$key] = stripslashes($_COOKIE[$key]);
  104. } else {
  105. $__GET = $_GET;
  106. $__POST = $_POST;
  107. $__COOKIE = $_COOKIE;
  108. }
  109. // Emulate MQ, if disabled
  110. if (!get_magic_quotes_gpc()) { // and !get_magic_quotes_runtime()
  111. foreach ($_GET as $key => $val) if (!is_array($_GET[$key])) $_GET[$key] = addslashes($_GET[$key]);
  112. foreach ($_POST as $key => $val) if (!is_array($_POST[$key])) $_POST[$key] = addslashes($_POST[$key]);
  113. foreach ($_COOKIE as $key => $val) if (!is_array($_COOKIE[$key])) $_COOKIE[$key] = addslashes($_COOKIE[$key]);
  114. }
  115. // Protect from XSS
  116. #foreach ($_GET as $key => $val) $_GET[$key] = preg_replace('#&lt;script(.)*>#sUi', '', $_GET[$key]);
  117. #foreach ($_POST as $key => $val) $_POST[$key] = preg_replace('#&lt;script(.)*>#sUi', '', $_POST[$key]);
  118. ### Read Config and Definitionfiles
  119. $config = parse_ini_file('inc/base/config.php', 1); // Load Basic Config
  120. include_once('inc/base/define.php'); // Read definition file
  121. // Exit if no Configfile
  122. if (!$config) {
  123. echo HTML_FONT_ERROR. 'Öffnen oder Lesen der Konfigurations-Datei nicht möglich. Lansuite wird beendet.' .HTML_NEWLINE . "
  124. Überprüfe die Datei <b>config.php</b> im Verzeichnis inc/base/" .HTML_FONT_END;
  125. error_log('Öffnen oder Lesen der Konfigurations-Datei inc/base/config.php nicht möglich');
  126. exit();
  127. }
  128. ### Include and Initialize base classes
  129. $lang = array(); // For old $lang
  130. if ($config['lansuite']['debugmode'] > 0) {
  131. include_once "inc/classes/class_debug.php"; // Debug initialisieren
  132. $debug = new debug($config['lansuite']['debugmode']);
  133. }
  134. include_once("inc/classes/class_translation.php"); // Load Translationclass. No t()-Function before this point!
  135. $translation = new translation();
  136. include_once('ext_scripts/smarty/Smarty.class.php');
  137. $smarty = new Smarty();
  138. $smarty->template_dir = '.';
  139. $smarty->compile_dir = './ext_inc/templates_c/';
  140. $smarty->cache_dir = './ext_inc/templates_cache/';
  141. $smarty->caching = false;
  142. $smarty->cache_lifetime = 0; // sec
  143. #$smarty->compile_check = 0;
  144. if (isset($debug)) $debug->tracker("Include and Init Smarty");
  145. include_once("inc/classes/class_display.php"); // Display Functions (to load the lansuite-templates)
  146. $dsp = new display();
  147. include_once("inc/classes/class_db_mysql.php"); // DB Functions (to work with the databse)
  148. $db = new db;
  149. include_once("inc/classes/class_sec.php"); // Security Functions (to lock pages)
  150. $sec = new sec;
  151. if (isset($debug)) $debug->tracker("Include and Init Base Classes");
  152. ### Initalize Basic Parameters
  153. $language = $translation->get_lang(); // Set and Read Systemlanguage
  154. $smarty->assign('language', $language);
  155. ### Installingsystem or normal auth
  156. if ($config['environment']['configured'] == 0) {
  157. $translation->load_trans('xml', 'install'); // Filemode on Installation
  158. ### Prepare install
  159. // Force installwizard if LS not configured
  160. $_GET['mod'] = 'install';
  161. $_GET['action'] = 'wizard';
  162. // Silent connect
  163. $db->connect(1);
  164. $IsAboutToInstall = 1;
  165. // Force Adminrights for installing User
  166. $auth["type"] = 3;
  167. $auth["login"] = 1;
  168. // Load DB-Data after installwizard step 3
  169. if ($_GET["action"] == "wizard" and $_GET["step"] > 3) {
  170. $cfg = $func->read_db_config(); // read Configtable
  171. }
  172. } else {
  173. ### Normal auth cycle and Database-init
  174. $db->connect(0);
  175. $IsAboutToInstall = 0;
  176. $translation->load_trans('db', $_GET['mod']); // DB-Mode on Running System
  177. // FIX : Add function to scan DB for correkt config and Tables (prefix etc.)
  178. // Reset DB-Success in Setup if no Adm.-Account was found, because a connection could work, but prefix is wrong
  179. if (!$func->admin_exists() and (($_GET["action"] == "wizard" and $_GET["step"] <= 3) or ($_GET["action"] == "ls_conf"))) $db->success = 0;
  180. $cfg = $func->read_db_config(); // Config-Tabelle aulesen
  181. $sec->check_blacklist();
  182. // Set timezone info (php + mysql)
  183. if ($cfg['sys_timezone'] and function_exists('date_default_timezone_set')) {
  184. #date_default_timezone_set($cfg['sys_timezone']);
  185. #$db->qry('SET SESSION time_zone = %string%', $cfg['sys_timezone']);
  186. ##$db->qry('SET SESSION time_zone = \'+0:00\'');
  187. }
  188. if (!$_GET['mod']) $_GET['mod'] = 'home';
  189. $func->getActiveModules();
  190. $framework->AddToPageTitle($cfg['sys_page_title']);
  191. if ($func->isModActive($_GET['mod'], $caption) && $_GET['mod'] != 'home')
  192. $framework->AddToPageTitle($caption);
  193. ### Start autentication, just if LS is working
  194. include_once("inc/classes/class_auth.php");
  195. $authentication = new auth($frmwrkmode);
  196. $auth = $authentication->check_logon(); // Testet Cookie / Session ob User eingeloggt ist
  197. $olduserid = $authentication->get_olduserid(); // Olduserid for Switback on Boxes
  198. }
  199. // Initialize party
  200. // Needed also, when not configured for LanSurfer Import
  201. if ($func->isModActive('party')) {
  202. include_once("modules/party/class_party.php");
  203. $party = new party();
  204. } else { // If without party-module: just give a fake ID, for many modules need it
  205. class party {
  206. var $party_id;
  207. }
  208. $party = new party();
  209. $party->party_id = (int)$cfg['signon_partyid'];
  210. }
  211. if ($config['environment']['configured'] != 0) {
  212. if ($_GET['mod']=='auth'){
  213. switch ($_GET['action']){
  214. case 'login':
  215. $auth = $authentication->login($_POST['email'],$_POST['password']);
  216. break;
  217. case 'logout':
  218. $auth = $authentication->logout();
  219. $_GET['mod']='home';
  220. break;
  221. case 'switch_to': // Switch to user
  222. $authentication->switchto($_GET["userid"]);
  223. break;
  224. case 'switch_back': // Switch back to Adminuser
  225. $authentication->switchback();
  226. break;
  227. }
  228. }
  229. }
  230. ### Set Default-Design, if non is set
  231. /*
  232. * Initializes the design of lansuite.
  233. */
  234. function initializeDesign() {
  235. global $cfg, $auth, $config, $_SESSION, $_GET, $smarty;
  236. // If user is not allowed to use an own selected design, or none is selected, use default
  237. if (!$cfg['user_design_change'] or !$auth['design']) $auth['design'] = $config['lansuite']['default_design'];
  238. // Design switch by URL
  239. if ($_GET['design'] and $_GET['design'] != 'popup' and $_GET['design'] != 'base') $auth['design'] = $_GET['design'];
  240. // Fallback design is 'simple'
  241. if (!$auth['design'] or !file_exists('design/'. $auth['design'] .'/templates/main.htm')) {
  242. $auth['design'] = 'simple';
  243. if ($_GET['design'] != 'popup' and $_GET['design'] != 'base') $_GET['design'] = 'simple';
  244. }
  245. // For compaibility with old LS code
  246. $_SESSION['auth']['design'] = $auth['design'];
  247. // Assign
  248. $smarty->assign('default_design', $auth['design']);
  249. }
  250. initializeDesign();
  251. ### Load Rotation Banner
  252. if ($_GET['design'] != 'popup'
  253. and $_GET['action'] != 'wizard'
  254. and !$_SESSION['lansuite']['fullscreen']
  255. and $db->success
  256. and $func->isModActive('sponsor')
  257. ) include_once("modules/sponsor/banner.php");
  258. ### Create Boxes / load Boxmanager
  259. if (!$IsAboutToInstall and $_GET['design'] != 'base') include_once("modules/boxes/boxes.php");
  260. ### index_module.inc.php load the Modulactions and Codes
  261. $db->DisplayErrors();
  262. if ($PHPErrors) $func->error($PHPErrors);
  263. $PHPErrors = '';
  264. #$func->error($func->FormatFileSize(memory_get_usage()));
  265. #trigger_error(memory_get_usage(), E_USER_ERROR);
  266. include_once('index_module.inc.php');
  267. ### Complete Framework and Output HTML
  268. $framework->set_design($auth['design']);
  269. $db->DisplayErrors();
  270. if ($PHPErrors) $func->error($PHPErrors);
  271. $PHPErrors = '';
  272. $framework->add_content($FrameworkMessages); // Add old Frameworkmessages (sollten dann ausgetauscht werden)
  273. $framework->add_content($MainContent); // Add old MainContent-Variable (sollte auch bereinigt werden)
  274. // DEBUG:Alles
  275. if (isset($debug)) $debug->addvar('$auth',$auth);
  276. if (isset($debug)) $debug->addvar('$cfg',$cfg);
  277. if (isset($debug)) $debug->tracker("All upto HTML-Output");
  278. $framework->html_out(); // Output of all HTML
  279. unset($framework);
  280. unset($smarty);
  281. unset($templ);
  282. unset($dsp);
  283. ### Statistics will be updated only at scriptend, so pagesize and loadtime can be insert
  284. if ($db->success) {
  285. // Statistic Functions (for generating server- and usage-statistics)
  286. include_once("modules/stats/class_stats.php");
  287. $stats = new stats();
  288. unset($stats);
  289. // Check Cronjobs
  290. if (!$_GET['mod'] == 'install') {
  291. if (!isset($cron2)) {
  292. include_once('modules/cron2/class_cron2.php');
  293. $cron2 = new cron2();
  294. }
  295. $cron2->CheckJobs();
  296. unset($cron2);
  297. }
  298. // Disconnect DB
  299. $db->disconnect();
  300. unset($db);
  301. }
  302. ?>