main.core.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /* $Id: main.core.php 3110 2007-06-16 23:10:56Z b4rt $ */
  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. // cache
  16. require_once('inc/main.cache.php');
  17. // core classes
  18. require_once("inc/classes/CoreClasses.php");
  19. // core functions
  20. require_once('inc/functions/functions.core.php');
  21. // common functions
  22. require_once('inc/functions/functions.common.php');
  23. // torrentflux-b4rt Version from version-file
  24. if (@is_file('version.php')) {
  25. require_once('version.php');
  26. $cfg["version"] = _VERSION;
  27. } else {
  28. $cfg["version"] = "unknown";
  29. }
  30. // constants
  31. $cfg["constants"] = array();
  32. $cfg["constants"]["url_upload"] = "URL Upload";
  33. $cfg["constants"]["reset_owner"] = "Reset Owner";
  34. $cfg["constants"]["start_torrent"] = "Started Transfer";
  35. $cfg["constants"]["stop_transfer"] = "Stopped Transfer";
  36. $cfg["constants"]["queued_transfer"] = "Added to Queue";
  37. $cfg["constants"]["unqueued_transfer"] = "Removed from Queue";
  38. $cfg["constants"]["QManager"] = "QManager";
  39. $cfg["constants"]["fluxd"] = "fluxd";
  40. $cfg["constants"]["access_denied"] = "ACCESS DENIED";
  41. $cfg["constants"]["delete_transfer"] = "Delete Transfer";
  42. $cfg["constants"]["fm_delete"] = "File Manager Delete";
  43. $cfg["constants"]["fm_download"] = "File Download";
  44. $cfg["constants"]["kill_transfer"] = "Kill Transfer";
  45. $cfg["constants"]["file_upload"] = "File Upload";
  46. $cfg["constants"]["error"] = "ERROR";
  47. $cfg["constants"]["hit"] = "HIT";
  48. $cfg["constants"]["update"] = "UPDATE";
  49. $cfg["constants"]["admin"] = "ADMIN";
  50. $cfg["constants"]["debug"] = "DEBUG";
  51. asort($cfg["constants"]);
  52. // valid file extensions
  53. $cfg["file_types_array"] = array(".torrent", ".wget", ".nzb");
  54. // do NOT (!) touch the next 2 lines
  55. $cfg["file_types_regexp"] = implode("|", $cfg["file_types_array"]);
  56. $cfg["file_types_label"] = implode(", ", $cfg["file_types_array"]);
  57. // upload-limit (metafiles)
  58. $cfg["upload_limit"] = 8000000;
  59. // username
  60. $cfg["user"] = "";
  61. // ip + hostname
  62. if (isset($_SERVER['REMOTE_ADDR'])) {
  63. $cfg['ip'] = htmlentities($_SERVER['REMOTE_ADDR'], ENT_QUOTES);
  64. $cfg['ip_resolved'] = htmlentities(@gethostbyaddr($_SERVER['REMOTE_ADDR']), ENT_QUOTES);
  65. } else {
  66. $cfg['ip'] = "127.0.0.1";
  67. $cfg['ip_resolved'] = "localhost";
  68. }
  69. // user-agent
  70. $cfg['user_agent'] = (isset($_SERVER['HTTP_USER_AGENT']))
  71. ? htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES)
  72. : "torrentflux-b4rt/".$cfg["version"];
  73. // get os
  74. $osString = @php_uname('s');
  75. if (isset($osString)) {
  76. if (!(stristr($osString, 'linux') === false)) /* linux */
  77. $cfg["_OS"] = 1;
  78. elseif (!(stristr($osString, 'bsd') === false)) /* bsd */
  79. $cfg["_OS"] = 2;
  80. elseif (!(stristr($osString, 'darwin') === false)) /* darwin */
  81. $cfg["_OS"] = 2;
  82. else /* well... linux ;) */
  83. $cfg["_OS"] = 1;
  84. } else { /* well... linux ;) */
  85. $cfg["_OS"] = 1;
  86. }
  87. // main menu
  88. $cfg['mainMenu'] = array(
  89. "index" => "home",
  90. "readrss" => "home",
  91. "multiup" => "home",
  92. "serverStats" => "home",
  93. "images" => "home",
  94. "dir" => "dir",
  95. "history" => "history",
  96. "profile" => "profile",
  97. "readmsg" => "msg",
  98. "message" => "msg",
  99. "admin" => "admin"
  100. );
  101. // db
  102. if (@is_file('inc/config/config.db.php')) {
  103. // db-config
  104. require_once('inc/config/config.db.php');
  105. // check db-type
  106. $databaseTypes = array();
  107. $databaseTypes['mysql'] = 'mysql_connect';
  108. $databaseTypes['mysqli'] = 'mysqli_connect';
  109. $databaseTypes['sqlite'] = 'sqlite_open';
  110. $databaseTypes['postgres'] = 'pg_connect';
  111. if (array_key_exists($cfg["db_type"], $databaseTypes)) {
  112. if (!function_exists($databaseTypes[$cfg["db_type"]]))
  113. @error("Database Problems", "", "", array('This PHP installation does not have support for '.$cfg["db_type"].' built into it. Please reinstall PHP and ensure support for the selected database is built in.'));
  114. } else {
  115. @error("Database Problems", "", "", array('Error in database-config, database-type '.$cfg["db_type"].' is not supported.', "Check your database-config-file. (inc/config/config.db.php)"));
  116. }
  117. // initialize database
  118. dbInitialize();
  119. // load global settings
  120. loadSettings('tf_settings');
  121. // load dir-settings
  122. loadSettings('tf_settings_dir');
  123. // load stats-settings
  124. loadSettings('tf_settings_stats');
  125. // load users
  126. $arUsers = GetUsers();
  127. $cfg['users'] = ((isset($arUsers)) && (is_array($arUsers)))
  128. ? $arUsers
  129. : array($cfg['user']);
  130. // load links
  131. $arLinks = GetLinks();
  132. if ((isset($arLinks)) && (is_array($arLinks))) {
  133. $linklist = array();
  134. foreach ($arLinks as $link) {
  135. array_push($linklist, array(
  136. 'link_url' => $link['url'],
  137. 'link_sitename' => $link['sitename']
  138. )
  139. );
  140. }
  141. $cfg['linklist'] = $linklist;
  142. }
  143. // Path to where the meta files will be stored... usually a sub of $cfg["path"]
  144. $cfg["transfer_file_path"] = $cfg["path"].".transfers/";
  145. // Free space in MB
  146. $cfg["free_space"] = @disk_free_space($cfg["path"]) / (1048576);
  147. } else {
  148. // error in cli-mode, send redir in webapp
  149. if (empty($argv[0])) {
  150. if (!isset($_SESSION['check']['dbconf'])) {
  151. $_SESSION['check']['dbconf'] = 1;
  152. // redir to login ... (which may redir to upgrade.php / setup.php)
  153. @ob_end_clean();
  154. @header("location: login.php");
  155. exit();
  156. } else {
  157. @error("database-settings-file config.db.php is missing");
  158. }
  159. } else {
  160. @error("database-settings-file config.db.php is missing");
  161. }
  162. }
  163. // load configs
  164. $configs = array(
  165. 'config.clients.php' => 'clients-config-file config.clients.php is missing',
  166. 'config.profile.php' => 'profile-config-file config.profile.php is missing',
  167. 'config.fluxd.php' => 'fluxd-config-file config.fluxd.php is missing'
  168. );
  169. foreach ($configs as $configFile => $configError) {
  170. if (@is_file('inc/config/'.$configFile)) {
  171. // load config-file
  172. require_once('inc/config/'.$configFile);
  173. } else {
  174. // error
  175. @error($configError);
  176. }
  177. }
  178. ?>