main.internal.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. /* $Id: main.internal.php 3193 2007-08-21 20:23:13Z warion $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // start session
  16. @session_start();
  17. // unregister globals
  18. if (@ini_get('register_globals')) {
  19. require_once('inc/functions/functions.compat.php');
  20. unregister_GLOBALS();
  21. }
  22. // init
  23. if (isset($_SESSION['user'])) {
  24. // cache
  25. require_once("inc/main.cache.php");
  26. // set current user
  27. $currentUser = $_SESSION['user'];
  28. // check if cache set
  29. if (cacheIsSet($currentUser)) {
  30. // core classes
  31. require_once("inc/classes/CoreClasses.php");
  32. // core functions
  33. require_once('inc/functions/functions.core.php');
  34. // init cache
  35. cacheInit($currentUser);
  36. // init transfers-cache
  37. cacheTransfersInit();
  38. // initialize database
  39. dbInitialize();
  40. } else {
  41. // main.core
  42. require_once('inc/main.core.php');
  43. }
  44. $cfg["user"] = $currentUser;
  45. } else {
  46. // reset user
  47. $cfg["user"] = "";
  48. $currentUser = "";
  49. // main.core
  50. require_once('inc/main.core.php');
  51. }
  52. // authenticate
  53. if (isAuthenticated() == 1) {
  54. // check if we are locked
  55. if ($cfg["webapp_locked"] == 1) {
  56. // only superadmin can login when we are locked
  57. if (! IsSuperAdmin()) {
  58. @header('location: locked.php');
  59. exit();
  60. }
  61. }
  62. } else {
  63. // try to auth with supplied credentials
  64. $credentials = getCredentials();
  65. if ($credentials !== false) {
  66. if (performAuthentication($credentials['username'], $credentials['password'], $credentials['md5pass']) == 1) {
  67. if (isAuthenticated() != 1) {
  68. @header('location: login.php');
  69. exit();
  70. }
  71. $currentUser = $cfg["user"];
  72. // check if we are locked
  73. if ($cfg["webapp_locked"] == 1) {
  74. // only superadmin can login when we are locked
  75. if (! IsSuperAdmin()) {
  76. @header('location: locked.php');
  77. exit();
  78. }
  79. }
  80. } else {
  81. @header('location: login.php');
  82. exit();
  83. }
  84. } else {
  85. @header('location: login.php');
  86. exit();
  87. }
  88. }
  89. // log the hit
  90. AuditAction($cfg["constants"]["hit"], $_SERVER['PHP_SELF']);
  91. // if at this moment no user is set there is something wrong
  92. if(!isset($currentUser) || empty($currentUser))
  93. {
  94. @header('location: login.php');
  95. exit();
  96. }
  97. // cache is not set
  98. if (!cacheIsSet($currentUser)) {
  99. // login-check-tasks
  100. if (!isset($_SESSION['login_tasks'])) {
  101. // check for setup.php
  102. if (!isset($_SESSION['check']['setup'])) {
  103. $_SESSION['check']['setup'] = 1;
  104. // check for setup.php and upgrade.php
  105. if (@file_exists("setup.php") === true)
  106. @error("setup.php must be deleted", "index.php?iid=index", "");
  107. }
  108. // check for upgrade.php
  109. if (!isset($_SESSION['check']['upgrade'])) {
  110. $_SESSION['check']['upgrade'] = 1;
  111. if (@file_exists("upgrade.php") === true)
  112. @error("upgrade.php must be deleted", "index.php?iid=index", "");
  113. }
  114. // safe_mode
  115. if (!isset($_SESSION['check']['safe_mode'])) {
  116. $_SESSION['check']['safe_mode'] = 1;
  117. if (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) == 'on')
  118. @error("safe_mode enabled", "index.php?iid=index", "", array("tf-b4rt will not run with this setting", "PHP-setting : safe_mode"));
  119. }
  120. // allow_url_fopen
  121. if (!isset($_SESSION['check']['allow_url_fopen'])) {
  122. $_SESSION['check']['allow_url_fopen'] = 1;
  123. if (@ini_get('allow_url_fopen') == '0' || strtolower(@ini_get('allow_url_fopen')) == 'off')
  124. @error("allow_url_fopen disabled", "index.php?iid=index", "", array("tf-b4rt will not run flawless with this setting", "PHP-setting : allow_url_fopen"));
  125. }
  126. // register_globals
  127. if (!isset($_SESSION['check']['register_globals'])) {
  128. $_SESSION['check']['register_globals'] = 1;
  129. if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
  130. @error("register_globals enabled", "index.php?iid=index", "", array("tf-b4rt may not run flawless with this setting", "PHP-setting : register_globals"));
  131. }
  132. }
  133. // set admin-var
  134. $cfg['isAdmin'] = IsAdmin();
  135. // load some settings from users-table
  136. $sql = "SELECT hide_offline, theme, language_file FROM tf_users WHERE user_id=".$db->qstr($cfg["user"]);
  137. $recordset = $db->Execute($sql);
  138. if ($db->ErrorNo() != 0) dbError($sql);
  139. list ($cfg["hide_offline"], $cfg["theme"], $cfg["language_file"]) = $recordset->FetchRow();
  140. // Check for valid language file
  141. if (!preg_match('/^[^.\/][^\/]*$/', $cfg["language_file"])) {
  142. AuditAction($cfg["constants"]["error"], "LANGUAGE VARIABLE CHANGE ATTEMPT: ".$cfg["language_file"]." from ".$cfg["user"]);
  143. $cfg["language_file"] = $cfg["default_language"];
  144. }
  145. if (!is_file("inc/language/".$cfg["language_file"]))
  146. $cfg["language_file"] = $cfg["default_language"];
  147. // load per user settings
  148. // activated ?
  149. if ($cfg["enable_personal_settings"] == 1)
  150. loadUserSettingsToConfig($cfg["uid"]);
  151. $cfg["theme"] = CheckandSetUserTheme();
  152. // theme
  153. require_once("themes/".$cfg["theme"]."/index.php");
  154. // load language
  155. loadLanguageFile($cfg["language_file"]);
  156. // set cache
  157. cacheSet($currentUser);
  158. // login-tasks
  159. if (!isset($_SESSION['login_tasks'])) {
  160. // check main-directories.
  161. checkMainDirectories();
  162. // maintenance-run
  163. require_once("inc/classes/MaintenanceAndRepair.php");
  164. MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_STD);
  165. $_SESSION['next_int_maintenance'] = null;
  166. // set flag
  167. $_SESSION['login_tasks'] = 1;
  168. }
  169. // set transfers-cache
  170. cacheTransfersSet();
  171. // set session-settings
  172. $_SESSION['settings']['index_meta_refresh'] = ($cfg["enable_index_meta_refresh"] != 0) ? 1 : 0;
  173. $_SESSION['settings']['index_ajax_update'] = ($cfg["enable_index_ajax_update"] != 0) ? 1 : 0;
  174. $_SESSION['settings']['index_show_seeding'] = ($cfg["index_show_seeding"] != 0) ? 1 : 0;
  175. // xfer
  176. if ($cfg['enable_xfer'] == 1) {
  177. // xfer-init
  178. Xfer::init();
  179. }
  180. }
  181. else
  182. {
  183. // Check for valid theme
  184. if(isset($cfg["theme"]))
  185. $cfg["theme"] = CheckandSetUserTheme();
  186. // Run internal maintenance regularly
  187. if (!empty($_SESSION['next_int_maintenance']) && $_SESSION['next_int_maintenance'] < time()) {
  188. require_once("inc/classes/MaintenanceAndRepair.php");
  189. MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_INT);
  190. $_SESSION['next_int_maintenance'] = null;
  191. }
  192. }
  193. // schedule next internal maintenance if needed
  194. if (empty($_SESSION['next_int_maintenance']))
  195. $_SESSION['next_int_maintenance'] = time() + 2 * 3600 + mt_rand(-1200, 1200); // 2h (+/- 20m)
  196. // free space in MB var
  197. $cfg["free_space"] = @disk_free_space($cfg["path"]) / 1048576;
  198. // drive space var
  199. $cfg['driveSpace'] = getDriveSpace($cfg["path"]);
  200. // free space formatted var
  201. $cfg['freeSpaceFormatted'] = formatFreeSpace($cfg["free_space"]);
  202. // Fluxd
  203. Fluxd::initialize();
  204. // Qmgr
  205. FluxdServiceMod::initializeServiceMod('Qmgr');
  206. // xfer
  207. if (($cfg['enable_xfer'] == 1) && ($cfg['xfer_realtime'] == 1)) {
  208. // set xfer-newday
  209. Xfer::setNewday();
  210. }
  211. // vlib
  212. require_once("inc/lib/vlib/vlibTemplate.php");
  213. ?>