PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/remote/inc/global.php

https://github.com/messyo/rEmote
PHP | 197 lines | 136 code | 38 blank | 23 comment | 19 complexity | 71a65afb97b37a577c42cb4ca9ef62e5 MD5 | raw file
  1. <?php
  2. $starttime = microtime('true');
  3. /***************************
  4. * define IMPORTANT VALUES *
  5. ***************************/
  6. //LOGLEVELS
  7. define('LOGDEBUG', 1);
  8. define('LOGERROR', 2);
  9. define('LOGSECURITY', 4);
  10. define('LOGADDDEL', 8);
  11. define('LOGINFOS', 16);
  12. define('LOGSETTINGS', 32);
  13. define('LOGUSERS', 64);
  14. //USERCLASSES
  15. define('GUEST', 0);
  16. define('USER', 1);
  17. define('ADMIN', 2);
  18. define('SUADMIN', 3);
  19. //BOXAREAS
  20. define('BOX_NONE', -1);
  21. define('BOX_SIDE', 0);
  22. define('BOX_TOP', 1);
  23. define('BOX_BOTTOM', 2);
  24. define('BOX_RIGHT', 3);
  25. define('REMOTE_BUILD', 4);
  26. define('REMOTE_VERSION', '2.0.0-B1');
  27. //VIEW/SOURCE/GROUP
  28. $view_arr = array('main', 'started', 'stopped', 'complete', 'incomplete', 'seeding');
  29. $group_arr = array('grpnone', 'tracker', 'status', 'message', 'traffic');
  30. $refresh_arr = array('refoff', 'refwhole', 'refall', 'refsidebar' );
  31. $source_arr = array('private', 'public', 'both');
  32. // What the hell?
  33. // Why can't this be php default?
  34. if(function_exists('date_default_timezone_set'))
  35. date_default_timezone_set(date_default_timezone_get());
  36. require_once(TO_ROOT.'config.php');
  37. require_once(TO_ROOT.'inc/render.php');
  38. require_once(TO_ROOT.'inc/sql/database.php');
  39. require_once(TO_ROOT.'inc/sql/'.$sql['type'].'.php');
  40. require_once(TO_ROOT.'inc/functions/base.fun.php');
  41. require_once(TO_ROOT.'inc/sessions.php');
  42. require_once(TO_ROOT.'inc/rpc.php');
  43. $out = new Render();
  44. $db = new Database($sql);
  45. $rpc = new RpcHandler($rpc_connect);
  46. $result = $rpc->simple_multicall('system.client_version',
  47. 'system.library_version',
  48. 'get_down_rate',
  49. 'get_up_rate',
  50. 'get_download_rate',
  51. 'get_upload_rate');
  52. $global['versions']['remote'] = REMOTE_VERSION.'-'.REMOTE_BUILD;
  53. $global['versions']['rtorrent'] = $result[0][0];
  54. $global['versions']['libtorrent'] = $result[1][0];
  55. $global['downspeed'] = $result[2][0];
  56. $global['upspeed'] = $result[3][0];
  57. $global['downlimit'] = $result[4][0];
  58. $global['uplimit'] = $result[5][0];
  59. /*
  60. * Try to get settings out of cache.
  61. * If not successfull, get settings out of settingstable and write to cache
  62. */
  63. if(!($settings = simple_cache_get('settings')))
  64. {
  65. require_once(TO_ROOT.'inc/functions/settings.fun.php');
  66. $settings = get_and_rebuild_settings();
  67. }
  68. ini_set('error_reporting', E_ALL);
  69. ini_set('session.gc_divisor', 1000);// Let's set to a very high value... as Ubuntu/Debian do not call the php-Session-GC, we have to call it by ourselves anyway...
  70. ini_set('session.gc_propability', 1);
  71. ini_set('session.use_cookies', $settings['session_use_cookies']);
  72. ini_set('session.use_only_cookies', 0);
  73. ini_set('max_execution_time', $settings['max_exec_time']);
  74. ini_set('magic_quotes_runtime', 0);
  75. session_name($settings['session_name']);
  76. // if(isset($_GET[session_name()]))
  77. // session_id($_GET[session_name()]);
  78. // else if(isset($_COOKIE[session_name()]))
  79. // session_id($_COOKIE[session_name()]);
  80. // So here is our own GC-Call
  81. if(!defined('NO_GC') && mt_rand(1, SESSION_GC_DIVISOR) == SESSION_GC_DIVISOR)
  82. {
  83. REmoteSessionHandler::gc($settings['session_lifetime']);
  84. // Also cleanup cache
  85. $db->query('DELETE FROM cache WHERE expires > 0 AND expires < ?', 'i', time());
  86. }
  87. // Strip MagicQuotes GetPostCookie
  88. if(get_magic_quotes_gpc())
  89. {
  90. $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
  91. while(list($key, $val) = each($process))
  92. {
  93. foreach($val as $k => $v)
  94. {
  95. unset($process[$key][$k]);
  96. if(is_array($v))
  97. {
  98. $process[$key][stripslashes($k)] = $v;
  99. $process[] = &$process[$key][stripslashes($k)];
  100. }
  101. else
  102. {
  103. $process[$key][stripslashes($k)] = stripslashes($v);
  104. }
  105. }
  106. }
  107. unset($process);
  108. }
  109. session_set_cookie_params( $settings['session_lifetime'], $settings['cookie_path']);
  110. session_start();
  111. if(SID != '')
  112. {
  113. $sid = '&amp;'.SID;
  114. $qsid = '?'.SID;
  115. }
  116. else
  117. {
  118. $sid = '';
  119. $qsid = '';
  120. }
  121. if(isset($_GET['logout']))
  122. session_destroy();
  123. $jsinfos = array();
  124. /* Check if Logedin... if not make Login-Field and Die or take login */
  125. if(!isset($_SESSION['status']) || $_SESSION['status'] < 1)
  126. {
  127. if(TO_ROOT != './')
  128. {
  129. session_write_close();
  130. require_once(TO_ROOT."languages/{$settings['default_lng']}/base.lng.php");
  131. exit('ERROR: '.$lng['sexpired']);
  132. }
  133. else
  134. {
  135. require_once(TO_ROOT.'inc/login.php');
  136. }
  137. }
  138. /* Load the Style and language... if set by login already, variables will be overwritten */
  139. if(!(@include(TO_ROOT."styles/{$_SESSION['style']}/style.php")))
  140. {
  141. require(TO_ROOT."styles/{$settings['default_style']}/style.php");
  142. logger(LOGERROR, "Could not load {$_SESSION['style']}/style.php", __FILE__, __LINE__);
  143. }
  144. if(!(@include(TO_ROOT."languages/{$_SESSION['lng']}/base.lng.php")))
  145. {
  146. require(TO_ROOT."languages/{$settings['default_lng']}/base.lng.php");
  147. logger(LOGERROR, "Could not load {$_SESSION['lng']}/base.lng.php", __FILE__, __LINE__);
  148. }
  149. $out->setStyleJavascripts($stylejs);
  150. $out->setStylesheets($stylesheets);
  151. $out->setPrecache($precache);
  152. $out->jsinfos['imagedir'] = "'$imagedir'";
  153. $out->jsinfos['sid'] = '"'.SID.'"';
  154. //Administrator can view all Torrents
  155. if(isset($_SESSION['status']) && ($_SESSION['status'] >= ADMIN))
  156. $source_arr[3] = 'all';
  157. if($settings['real_multiuser'])
  158. $group_arr[5] = 'user';
  159. ?>