PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/torrentpier/upload/admin/index.php

https://github.com/andalit/torrents
PHP | 428 lines | 369 code | 35 blank | 24 comment | 36 complexity | 020a88a1513598ce78701061607aa8ce MD5 | raw file
  1. <?php
  2. require('./pagestart.php');
  3. //
  4. // Generate relevant output
  5. //
  6. if( isset($_GET['pane']) && $_GET['pane'] == 'left' )
  7. {
  8. $dir = @opendir(".");
  9. $setmodules = 1;
  10. while( $file = @readdir($dir) )
  11. {
  12. if( preg_match("/^admin_.*?\.php$/", $file) )
  13. {
  14. include('./' . $file);
  15. }
  16. }
  17. @closedir($dir);
  18. unset($setmodules);
  19. $template->assign_vars(array(
  20. 'TPL_ADMIN_NAVIGATE' => true,
  21. "L_FRAME_NO_SUPPORT" => $lang['IDX_BROWSER_NSP_FRAME'],
  22. "U_FORUM_INDEX" => append_sid("../index.php"),
  23. "U_ADMIN_INDEX" => append_sid("index.php?pane=right"))
  24. );
  25. ksort($module);
  26. while( list($cat, $action_array) = each($module) )
  27. {
  28. $cat = ( !empty($lang[strtoupper($cat)]) ) ? $lang[strtoupper($cat)] : preg_replace("/_/", " ", $cat);
  29. $template->assign_block_vars("catrow", array(
  30. "ADMIN_CATEGORY" => $cat)
  31. );
  32. ksort($action_array);
  33. $row_count = 0;
  34. while( list($action, $file) = each($action_array) )
  35. {
  36. $row_class = !($row_count % 2) ? 'row1' : 'row2';
  37. $action = ( !empty($lang[strtoupper($action)]) ) ? $lang[strtoupper($action)] : preg_replace("/_/", " ", $action);
  38. $template->assign_block_vars("catrow.modulerow", array(
  39. "ROW_CLASS" => $row_class,
  40. "ADMIN_MODULE" => $action,
  41. "U_ADMIN_MODULE" => append_sid($file))
  42. );
  43. $row_count++;
  44. }
  45. }
  46. }
  47. else if( isset($_GET['pane']) && $_GET['pane'] == 'right' )
  48. {
  49. $template->assign_vars(array(
  50. 'TPL_ADMIN_MAIN' => true,
  51. "L_LAST_UPDATE" => $lang['LAST_UPDATED'],
  52. "L_DB_SIZE" => $lang['DATABASE_SIZE'])
  53. );
  54. //
  55. // Get forum statistics
  56. //
  57. $total_posts = get_db_stat('postcount');
  58. $total_users = get_db_stat('usercount');
  59. $total_topics = get_db_stat('topiccount');
  60. $start_date = create_date($bb_cfg['default_dateformat'], $bb_cfg['board_startdate'], $bb_cfg['board_timezone']);
  61. $boarddays = ( time() - $bb_cfg['board_startdate'] ) / 86400;
  62. $posts_per_day = sprintf("%.2f", $total_posts / $boarddays);
  63. $topics_per_day = sprintf("%.2f", $total_topics / $boarddays);
  64. $users_per_day = sprintf("%.2f", $total_users / $boarddays);
  65. $avatar_dir_size = 0;
  66. if ($avatar_dir = @opendir($phpbb_root_path . $bb_cfg['avatar_path']))
  67. {
  68. while( $file = @readdir($avatar_dir) )
  69. {
  70. if( $file != "." && $file != ".." )
  71. {
  72. $avatar_dir_size += @filesize($phpbb_root_path . $bb_cfg['avatar_path'] . "/" . $file);
  73. }
  74. }
  75. @closedir($avatar_dir);
  76. //
  77. // This bit of code translates the avatar directory size into human readable format
  78. // Borrowed the code from the PHP.net annoted manual, origanally written by:
  79. // Jesse (jesse@jess.on.ca)
  80. //
  81. if($avatar_dir_size >= 1048576)
  82. {
  83. $avatar_dir_size = round($avatar_dir_size / 1048576 * 100) / 100 . " MB";
  84. }
  85. else if($avatar_dir_size >= 1024)
  86. {
  87. $avatar_dir_size = round($avatar_dir_size / 1024 * 100) / 100 . " KB";
  88. }
  89. else
  90. {
  91. $avatar_dir_size = $avatar_dir_size . " Bytes";
  92. }
  93. }
  94. else
  95. {
  96. // Couldn't open Avatar dir.
  97. $avatar_dir_size = $lang['NOT_AVAILABLE'];
  98. }
  99. if(intval($posts_per_day) > $total_posts)
  100. {
  101. $posts_per_day = $total_posts;
  102. }
  103. if(intval($topics_per_day) > $total_topics)
  104. {
  105. $topics_per_day = $total_topics;
  106. }
  107. if($users_per_day > $total_users)
  108. {
  109. $users_per_day = $total_users;
  110. }
  111. //
  112. // DB size ... MySQL only
  113. //
  114. // This code is heavily influenced by a similar routine
  115. // in phpMyAdmin 2.2.0
  116. //
  117. if( preg_match("/^mysql/", SQL_LAYER) )
  118. {
  119. $sql = "SELECT VERSION() AS mysql_version";
  120. if($result = $db->sql_query($sql))
  121. {
  122. $row = $db->sql_fetchrow($result);
  123. $version = $row['mysql_version'];
  124. if( preg_match("/^(3\.23|4\.|5\.)/", $version) )
  125. {
  126. $db_name = ( preg_match("/^(3\.23\.[6-9])|(3\.23\.[1-9][1-9])|(4\.)|(5\.)/", $version) ) ? "`".DBNAME."`" : DBNAME;
  127. $sql = "SHOW TABLE STATUS FROM " . $db_name;
  128. if($result = $db->sql_query($sql))
  129. {
  130. $tabledata_ary = $db->sql_fetchrowset($result);
  131. $dbsize = 0;
  132. for($i = 0; $i < count($tabledata_ary); $i++)
  133. {
  134. if( @$tabledata_ary[$i]['Type'] != "MRG_MyISAM" )
  135. {
  136. $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
  137. }
  138. }
  139. } // Else we couldn't get the table status.
  140. }
  141. else
  142. {
  143. $dbsize = $lang['NOT_AVAILABLE'];
  144. }
  145. }
  146. else
  147. {
  148. $dbsize = $lang['NOT_AVAILABLE'];
  149. }
  150. }
  151. else if( preg_match("/^mssql/", SQL_LAYER) )
  152. {
  153. $sql = "SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize
  154. FROM sysfiles";
  155. if( $result = $db->sql_query($sql) )
  156. {
  157. $dbsize = ( $row = $db->sql_fetchrow($result) ) ? intval($row['dbsize']) : $lang['NOT_AVAILABLE'];
  158. }
  159. else
  160. {
  161. $dbsize = $lang['NOT_AVAILABLE'];
  162. }
  163. }
  164. else
  165. {
  166. $dbsize = $lang['NOT_AVAILABLE'];
  167. }
  168. if ( is_integer($dbsize) )
  169. {
  170. if( $dbsize >= 1048576 )
  171. {
  172. $dbsize = sprintf("%.2f MB", ( $dbsize / 1048576 ));
  173. }
  174. else if( $dbsize >= 1024 )
  175. {
  176. $dbsize = sprintf("%.2f KB", ( $dbsize / 1024 ));
  177. }
  178. else
  179. {
  180. $dbsize = sprintf("%.2f Bytes", $dbsize);
  181. }
  182. }
  183. $template->assign_vars(array(
  184. "NUMBER_OF_POSTS" => $total_posts,
  185. "NUMBER_OF_TOPICS" => $total_topics,
  186. "NUMBER_OF_USERS" => $total_users,
  187. "START_DATE" => $start_date,
  188. "POSTS_PER_DAY" => $posts_per_day,
  189. "TOPICS_PER_DAY" => $topics_per_day,
  190. "USERS_PER_DAY" => $users_per_day,
  191. "AVATAR_DIR_SIZE" => $avatar_dir_size,
  192. "DB_SIZE" => $dbsize,
  193. "GZIP_COMPRESSION" => ( $board_config['gzip_compress'] ) ? $lang['ON'] : $lang['OFF'])
  194. );
  195. //
  196. // End forum statistics
  197. //
  198. if (@$_GET['users_online'])
  199. {
  200. $template->assign_vars(array(
  201. 'SHOW_USERS_ONLINE' => true,
  202. ));
  203. //
  204. // Get users online information.
  205. //
  206. $sql = "SELECT u.user_id, u.username, s.session_time AS user_session_time, u.user_allow_viewonline, s.session_logged_in, s.session_ip, s.session_start
  207. FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s
  208. WHERE s.session_logged_in = 1
  209. AND u.user_id = s.session_user_id
  210. AND u.user_id <> " . ANONYMOUS . "
  211. AND s.session_time >= " . ( time() - 300 ) . "
  212. ORDER BY s.session_ip ASC, s.session_time DESC";
  213. if(!$result = $db->sql_query($sql))
  214. {
  215. message_die(GENERAL_ERROR, "Couldn't obtain regd user/online information.", "", __LINE__, __FILE__, $sql);
  216. }
  217. $onlinerow_reg = $db->sql_fetchrowset($result);
  218. $sql = "SELECT session_logged_in, session_time, session_ip, session_start
  219. FROM " . SESSIONS_TABLE . "
  220. WHERE session_logged_in = 0
  221. AND session_time >= " . ( time() - 300 ) . "
  222. ORDER BY session_ip ASC, session_time DESC";
  223. if(!$result = $db->sql_query($sql))
  224. {
  225. message_die(GENERAL_ERROR, "Couldn't obtain guest user/online information.", "", __LINE__, __FILE__, $sql);
  226. }
  227. $onlinerow_guest = $db->sql_fetchrowset($result);
  228. $sql = "SELECT forum_name, forum_id
  229. FROM " . FORUMS_TABLE;
  230. if($forums_result = $db->sql_query($sql))
  231. {
  232. while($forumsrow = $db->sql_fetchrow($forums_result))
  233. {
  234. $forum_data[$forumsrow['forum_id']] = $forumsrow['forum_name'];
  235. }
  236. }
  237. else
  238. {
  239. message_die(GENERAL_ERROR, "Couldn't obtain user/online forums information.", "", __LINE__, __FILE__, $sql);
  240. }
  241. $reg_userid_ary = array();
  242. if( count($onlinerow_reg) )
  243. {
  244. $registered_users = 0;
  245. for($i=0, $cnt=count($onlinerow_reg); $i < $cnt; $i++)
  246. {
  247. if( !inarray($onlinerow_reg[$i]['user_id'], $reg_userid_ary) )
  248. {
  249. $reg_userid_ary[] = $onlinerow_reg[$i]['user_id'];
  250. $username = $onlinerow_reg[$i]['username'];
  251. if( $onlinerow_reg[$i]['user_allow_viewonline'] )
  252. {
  253. $registered_users++;
  254. $hidden = FALSE;
  255. }
  256. else
  257. {
  258. @$hidden_users++;
  259. $hidden = TRUE;
  260. }
  261. $row_class = 'row1';
  262. $reg_ip = decode_ip($onlinerow_reg[$i]['session_ip']);
  263. $template->assign_block_vars("reg_user_row", array(
  264. "ROW_CLASS" => $row_class,
  265. "USERNAME" => $username,
  266. "STARTED" => create_date('H:i', $onlinerow_reg[$i]['session_start'], $board_config['board_timezone']),
  267. "LASTUPDATE" => create_date('H:i', $onlinerow_reg[$i]['user_session_time'], $board_config['board_timezone']),
  268. "IP_ADDRESS" => $reg_ip,
  269. "U_WHOIS_IP" => "http://www.dnsstuff.com/tools/whois/?ip=$reg_ip",
  270. "U_USER_PROFILE" => append_sid("admin_users.php?mode=edit&amp;" . POST_USERS_URL . "=" . $onlinerow_reg[$i]['user_id']),
  271. ));
  272. }
  273. }
  274. }
  275. else
  276. {
  277. $template->assign_vars(array(
  278. "L_NO_REGISTERED_USERS_BROWSING" => $lang['NO_USERS_BROWSING'])
  279. );
  280. }
  281. //
  282. // Guest users
  283. //
  284. if( count($onlinerow_guest) )
  285. {
  286. $guest_users = 0;
  287. for($i = 0; $i < count($onlinerow_guest); $i++)
  288. {
  289. $guest_userip_ary[] = $onlinerow_guest[$i]['session_ip'];
  290. $guest_users++;
  291. $row_class = 'row2';
  292. $guest_ip = decode_ip($onlinerow_guest[$i]['session_ip']);
  293. $template->assign_block_vars("guest_user_row", array(
  294. "ROW_CLASS" => $row_class,
  295. "USERNAME" => $lang['GUEST'],
  296. "STARTED" => create_date('H:i', $onlinerow_guest[$i]['session_start'], $board_config['board_timezone']),
  297. "LASTUPDATE" => create_date('H:i', $onlinerow_guest[$i]['session_time'], $board_config['board_timezone']),
  298. "IP_ADDRESS" => $guest_ip,
  299. "U_WHOIS_IP" => "http://www.dnsstuff.com/tools/whois/?ip=$guest_ip",
  300. ));
  301. }
  302. }
  303. else
  304. {
  305. $template->assign_vars(array(
  306. "L_NO_GUESTS_BROWSING" => $lang['NO_USERS_BROWSING'])
  307. );
  308. }
  309. }
  310. else
  311. {
  312. $template->assign_vars(array(
  313. 'USERS_ONLINE_HREF' => "index.php?pane=right&users_online=1&sid={$userdata['session_id']}",
  314. ));
  315. }
  316. $template->assign_vars(array(
  317. 'U_CLEAR_DATASTORE' => "index.php?clear_datastore=1",
  318. 'U_CLEAR_TPL_CACHE' => "xs_cache.php?clear=",
  319. 'U_UPDATE_USER_LEVEL' => "index.php?update_user_level=1",
  320. 'U_SYNC_TOPICS' => "index.php?sync_topics=1",
  321. 'U_SYNC_USER_POSTS' => "index.php?sync_user_posts=1",
  322. ));
  323. }
  324. else if (isset($_REQUEST['clear_datastore']))
  325. {
  326. $datastore->clean();
  327. bb_die($lang['DATASTORE_CLEARED']);
  328. }
  329. else if (isset($_REQUEST['update_user_level']))
  330. {
  331. require(INC_DIR .'functions_group.php');
  332. update_user_level('all');
  333. bb_die($lang['USER_LEVELS_UPDATED']);
  334. }
  335. else if (isset($_REQUEST['sync_topics']))
  336. {
  337. sync('topic', 'all');
  338. sync('forum', 'all');
  339. bb_die($lang['TOPICS_DATA_SYNCHRONIZED']);
  340. }
  341. else if (isset($_REQUEST['sync_user_posts']))
  342. {
  343. sync('user_posts', 'all');
  344. bb_die($lang['USER POSTS COUNT SYNCHRONIZED']);
  345. }
  346. else
  347. {
  348. //
  349. // Generate frameset
  350. //
  351. $template->assign_vars(array(
  352. 'TPL_ADMIN_FRAMESET' => true,
  353. 'S_FRAME_NAV' => "index.php?pane=left",
  354. 'S_FRAME_MAIN' => "index.php?pane=right",
  355. ));
  356. send_no_cache_headers();
  357. print_page('index.tpl', 'admin', 'no_header');
  358. }
  359. print_page('index.tpl', 'admin');
  360. //
  361. // Functions
  362. //
  363. function inarray($needle, $haystack)
  364. {
  365. for($i = 0; $i < sizeof($haystack); $i++ )
  366. {
  367. if( $haystack[$i] == $needle )
  368. {
  369. return true;
  370. }
  371. }
  372. return false;
  373. }