Rev Author Line No. Line
130 kaklik 1 <?php
2 /***************************************************************************
3 * (admin) index.php
4 * -------------------
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
8 *
9 * $Id: index.php,v 1.40.2.10 2005/12/04 12:55:28 grahamje Exp $
10 *
11 *
12 ***************************************************************************/
13  
14 /***************************************************************************
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 ***************************************************************************/
22  
23 define('IN_PHPBB', 1);
24  
25 //
26 // Load default header
27 //
28 $no_page_header = TRUE;
29 $phpbb_root_path = "./../";
30 require($phpbb_root_path . 'extension.inc');
31 require('./pagestart.' . $phpEx);
32  
33 // ---------------
34 // Begin functions
35 //
36 function inarray($needle, $haystack)
37 {
38 for($i = 0; $i < sizeof($haystack); $i++ )
39 {
40 if( $haystack[$i] == $needle )
41 {
42 return true;
43 }
44 }
45 return false;
46 }
47 //
48 // End functions
49 // -------------
50  
51 //
52 // Generate relevant output
53 //
54 if( isset($HTTP_GET_VARS['pane']) && $HTTP_GET_VARS['pane'] == 'left' )
55 {
56 $dir = @opendir(".");
57  
58 $setmodules = 1;
59 while( $file = @readdir($dir) )
60 {
61 if( preg_match("/^admin_.*?\." . $phpEx . "$/", $file) )
62 {
63 include('./' . $file);
64 }
65 }
66  
67 @closedir($dir);
68  
69 unset($setmodules);
70  
71 include('./page_header_admin.'.$phpEx);
72  
73 $template->set_filenames(array(
74 "body" => "admin/index_navigate.tpl")
75 );
76  
77 $template->assign_vars(array(
78 "U_FORUM_INDEX" => append_sid("../index.$phpEx"),
79 "U_ADMIN_INDEX" => append_sid("index.$phpEx?pane=right"),
80  
81 "L_FORUM_INDEX" => $lang['Main_index'],
82 "L_ADMIN_INDEX" => $lang['Admin_Index'],
83 "L_PREVIEW_FORUM" => $lang['Preview_forum'])
84 );
85  
86 ksort($module);
87  
88 while( list($cat, $action_array) = each($module) )
89 {
90 $cat = ( !empty($lang[$cat]) ) ? $lang[$cat] : preg_replace("/_/", " ", $cat);
91  
92 $template->assign_block_vars("catrow", array(
93 "ADMIN_CATEGORY" => $cat)
94 );
95  
96 ksort($action_array);
97  
98 $row_count = 0;
99 while( list($action, $file) = each($action_array) )
100 {
101 $row_color = ( !($row_count%2) ) ? $theme['td_color1'] : $theme['td_color2'];
102 $row_class = ( !($row_count%2) ) ? $theme['td_class1'] : $theme['td_class2'];
103  
104 $action = ( !empty($lang[$action]) ) ? $lang[$action] : preg_replace("/_/", " ", $action);
105  
106 $template->assign_block_vars("catrow.modulerow", array(
107 "ROW_COLOR" => "#" . $row_color,
108 "ROW_CLASS" => $row_class,
109  
110 "ADMIN_MODULE" => $action,
111 "U_ADMIN_MODULE" => append_sid($file))
112 );
113 $row_count++;
114 }
115 }
116  
117 $template->pparse("body");
118  
119 include('./page_footer_admin.'.$phpEx);
120 }
121 elseif( isset($HTTP_GET_VARS['pane']) && $HTTP_GET_VARS['pane'] == 'right' )
122 {
123  
124 include('./page_header_admin.'.$phpEx);
125  
126 $template->set_filenames(array(
127 "body" => "admin/index_body.tpl")
128 );
129  
130 $template->assign_vars(array(
131 "L_WELCOME" => $lang['Welcome_phpBB'],
132 "L_ADMIN_INTRO" => $lang['Admin_intro'],
133 "L_FORUM_STATS" => $lang['Forum_stats'],
134 "L_WHO_IS_ONLINE" => $lang['Who_is_Online'],
135 "L_USERNAME" => $lang['Username'],
136 "L_LOCATION" => $lang['Location'],
137 "L_LAST_UPDATE" => $lang['Last_updated'],
138 "L_IP_ADDRESS" => $lang['IP_Address'],
139 "L_STATISTIC" => $lang['Statistic'],
140 "L_VALUE" => $lang['Value'],
141 "L_NUMBER_POSTS" => $lang['Number_posts'],
142 "L_POSTS_PER_DAY" => $lang['Posts_per_day'],
143 "L_NUMBER_TOPICS" => $lang['Number_topics'],
144 "L_TOPICS_PER_DAY" => $lang['Topics_per_day'],
145 "L_NUMBER_USERS" => $lang['Number_users'],
146 "L_USERS_PER_DAY" => $lang['Users_per_day'],
147 "L_BOARD_STARTED" => $lang['Board_started'],
148 "L_AVATAR_DIR_SIZE" => $lang['Avatar_dir_size'],
149 "L_DB_SIZE" => $lang['Database_size'],
150 "L_FORUM_LOCATION" => $lang['Forum_Location'],
151 "L_STARTED" => $lang['Login'],
152 "L_GZIP_COMPRESSION" => $lang['Gzip_compression'])
153 );
154  
155 //
156 // Get forum statistics
157 //
158 $total_posts = get_db_stat('postcount');
159 $total_users = get_db_stat('usercount');
160 $total_topics = get_db_stat('topiccount');
161  
162 $start_date = create_date($board_config['default_dateformat'], $board_config['board_startdate'], $board_config['board_timezone']);
163  
164 $boarddays = ( time() - $board_config['board_startdate'] ) / 86400;
165  
166 $posts_per_day = sprintf("%.2f", $total_posts / $boarddays);
167 $topics_per_day = sprintf("%.2f", $total_topics / $boarddays);
168 $users_per_day = sprintf("%.2f", $total_users / $boarddays);
169  
170 $avatar_dir_size = 0;
171  
172 if ($avatar_dir = @opendir($phpbb_root_path . $board_config['avatar_path']))
173 {
174 while( $file = @readdir($avatar_dir) )
175 {
176 if( $file != "." && $file != ".." )
177 {
178 $avatar_dir_size += @filesize($phpbb_root_path . $board_config['avatar_path'] . "/" . $file);
179 }
180 }
181 @closedir($avatar_dir);
182  
183 //
184 // This bit of code translates the avatar directory size into human readable format
185 // Borrowed the code from the PHP.net annoted manual, origanally written by:
186 // Jesse (jesse@jess.on.ca)
187 //
188 if($avatar_dir_size >= 1048576)
189 {
190 $avatar_dir_size = round($avatar_dir_size / 1048576 * 100) / 100 . " MB";
191 }
192 else if($avatar_dir_size >= 1024)
193 {
194 $avatar_dir_size = round($avatar_dir_size / 1024 * 100) / 100 . " KB";
195 }
196 else
197 {
198 $avatar_dir_size = $avatar_dir_size . " Bytes";
199 }
200  
201 }
202 else
203 {
204 // Couldn't open Avatar dir.
205 $avatar_dir_size = $lang['Not_available'];
206 }
207  
208 if($posts_per_day > $total_posts)
209 {
210 $posts_per_day = $total_posts;
211 }
212  
213 if($topics_per_day > $total_topics)
214 {
215 $topics_per_day = $total_topics;
216 }
217  
218 if($users_per_day > $total_users)
219 {
220 $users_per_day = $total_users;
221 }
222  
223 //
224 // DB size ... MySQL only
225 //
226 // This code is heavily influenced by a similar routine
227 // in phpMyAdmin 2.2.0
228 //
229 if( preg_match("/^mysql/", SQL_LAYER) )
230 {
231 $sql = "SELECT VERSION() AS mysql_version";
232 if($result = $db->sql_query($sql))
233 {
234 $row = $db->sql_fetchrow($result);
235 $version = $row['mysql_version'];
236  
237 if( preg_match("/^(3\.23|4\.|5\.)/", $version) )
238 {
239 $db_name = ( preg_match("/^(3\.23\.[6-9])|(3\.23\.[1-9][1-9])|(4\.)|(5\.)/", $version) ) ? "`$dbname`" : $dbname;
240  
241 $sql = "SHOW TABLE STATUS
242 FROM " . $db_name;
243 if($result = $db->sql_query($sql))
244 {
245 $tabledata_ary = $db->sql_fetchrowset($result);
246  
247 $dbsize = 0;
248 for($i = 0; $i < count($tabledata_ary); $i++)
249 {
250 if( $tabledata_ary[$i]['Type'] != "MRG_MyISAM" )
251 {
252 if( $table_prefix != "" )
253 {
254 if( strstr($tabledata_ary[$i]['Name'], $table_prefix) )
255 {
256 $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
257 }
258 }
259 else
260 {
261 $dbsize += $tabledata_ary[$i]['Data_length'] + $tabledata_ary[$i]['Index_length'];
262 }
263 }
264 }
265 } // Else we couldn't get the table status.
266 }
267 else
268 {
269 $dbsize = $lang['Not_available'];
270 }
271 }
272 else
273 {
274 $dbsize = $lang['Not_available'];
275 }
276 }
277 else if( preg_match("/^mssql/", SQL_LAYER) )
278 {
279 $sql = "SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize
280 FROM sysfiles";
281 if( $result = $db->sql_query($sql) )
282 {
283 $dbsize = ( $row = $db->sql_fetchrow($result) ) ? intval($row['dbsize']) : $lang['Not_available'];
284 }
285 else
286 {
287 $dbsize = $lang['Not_available'];
288 }
289 }
290 else
291 {
292 $dbsize = $lang['Not_available'];
293 }
294  
295 if ( is_integer($dbsize) )
296 {
297 if( $dbsize >= 1048576 )
298 {
299 $dbsize = sprintf("%.2f MB", ( $dbsize / 1048576 ));
300 }
301 else if( $dbsize >= 1024 )
302 {
303 $dbsize = sprintf("%.2f KB", ( $dbsize / 1024 ));
304 }
305 else
306 {
307 $dbsize = sprintf("%.2f Bytes", $dbsize);
308 }
309 }
310  
311 $template->assign_vars(array(
312 "NUMBER_OF_POSTS" => $total_posts,
313 "NUMBER_OF_TOPICS" => $total_topics,
314 "NUMBER_OF_USERS" => $total_users,
315 "START_DATE" => $start_date,
316 "POSTS_PER_DAY" => $posts_per_day,
317 "TOPICS_PER_DAY" => $topics_per_day,
318 "USERS_PER_DAY" => $users_per_day,
319 "AVATAR_DIR_SIZE" => $avatar_dir_size,
320 "DB_SIZE" => $dbsize,
321 "GZIP_COMPRESSION" => ( $board_config['gzip_compress'] ) ? $lang['ON'] : $lang['OFF'])
322 );
323 //
324 // End forum statistics
325 //
326  
327 //
328 // Get users online information.
329 //
330 $sql = "SELECT u.user_id, u.username, u.user_session_time, u.user_session_page, s.session_logged_in, s.session_ip, s.session_start
331 FROM " . USERS_TABLE . " u, " . SESSIONS_TABLE . " s
332 WHERE s.session_logged_in = " . TRUE . "
333 AND u.user_id = s.session_user_id
334 AND u.user_id <> " . ANONYMOUS . "
335 AND s.session_time >= " . ( time() - 300 ) . "
336 ORDER BY u.user_session_time DESC";
337 if(!$result = $db->sql_query($sql))
338 {
339 message_die(GENERAL_ERROR, "Couldn't obtain regd user/online information.", "", __LINE__, __FILE__, $sql);
340 }
341 $onlinerow_reg = $db->sql_fetchrowset($result);
342  
343 $sql = "SELECT session_page, session_logged_in, session_time, session_ip, session_start
344 FROM " . SESSIONS_TABLE . "
345 WHERE session_logged_in = 0
346 AND session_time >= " . ( time() - 300 ) . "
347 ORDER BY session_time DESC";
348 if(!$result = $db->sql_query($sql))
349 {
350 message_die(GENERAL_ERROR, "Couldn't obtain guest user/online information.", "", __LINE__, __FILE__, $sql);
351 }
352 $onlinerow_guest = $db->sql_fetchrowset($result);
353  
354 $sql = "SELECT forum_name, forum_id
355 FROM " . FORUMS_TABLE;
356 if($forums_result = $db->sql_query($sql))
357 {
358 while($forumsrow = $db->sql_fetchrow($forums_result))
359 {
360 $forum_data[$forumsrow['forum_id']] = $forumsrow['forum_name'];
361 }
362 }
363 else
364 {
365 message_die(GENERAL_ERROR, "Couldn't obtain user/online forums information.", "", __LINE__, __FILE__, $sql);
366 }
367  
368 $reg_userid_ary = array();
369  
370 if( count($onlinerow_reg) )
371 {
372 $registered_users = 0;
373  
374 for($i = 0; $i < count($onlinerow_reg); $i++)
375 {
376 if( !inarray($onlinerow_reg[$i]['user_id'], $reg_userid_ary) )
377 {
378 $reg_userid_ary[] = $onlinerow_reg[$i]['user_id'];
379  
380 $username = $onlinerow_reg[$i]['username'];
381  
382 if( $onlinerow_reg[$i]['user_allow_viewonline'] || $userdata['user_level'] == ADMIN )
383 {
384 $registered_users++;
385 $hidden = FALSE;
386 }
387 else
388 {
389 $hidden_users++;
390 $hidden = TRUE;
391 }
392  
393 if( $onlinerow_reg[$i]['user_session_page'] < 1 )
394 {
395 switch($onlinerow_reg[$i]['user_session_page'])
396 {
397 case PAGE_INDEX:
398 $location = $lang['Forum_index'];
399 $location_url = "index.$phpEx?pane=right";
400 break;
401 case PAGE_POSTING:
402 $location = $lang['Posting_message'];
403 $location_url = "index.$phpEx?pane=right";
404 break;
405 case PAGE_LOGIN:
406 $location = $lang['Logging_on'];
407 $location_url = "index.$phpEx?pane=right";
408 break;
409 case PAGE_SEARCH:
410 $location = $lang['Searching_forums'];
411 $location_url = "index.$phpEx?pane=right";
412 break;
413 case PAGE_PROFILE:
414 $location = $lang['Viewing_profile'];
415 $location_url = "index.$phpEx?pane=right";
416 break;
417 case PAGE_VIEWONLINE:
418 $location = $lang['Viewing_online'];
419 $location_url = "index.$phpEx?pane=right";
420 break;
421 case PAGE_VIEWMEMBERS:
422 $location = $lang['Viewing_member_list'];
423 $location_url = "index.$phpEx?pane=right";
424 break;
425 case PAGE_PRIVMSGS:
426 $location = $lang['Viewing_priv_msgs'];
427 $location_url = "index.$phpEx?pane=right";
428 break;
429 case PAGE_FAQ:
430 $location = $lang['Viewing_FAQ'];
431 $location_url = "index.$phpEx?pane=right";
432 break;
433 default:
434 $location = $lang['Forum_index'];
435 $location_url = "index.$phpEx?pane=right";
436 }
437 }
438 else
439 {
440 $location_url = append_sid("admin_forums.$phpEx?mode=editforum&amp;" . POST_FORUM_URL . "=" . $onlinerow_reg[$i]['user_session_page']);
441 $location = $forum_data[$onlinerow_reg[$i]['user_session_page']];
442 }
443  
444 $row_color = ( $registered_users % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
445 $row_class = ( $registered_users % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
446  
447 $reg_ip = decode_ip($onlinerow_reg[$i]['session_ip']);
448  
449 $template->assign_block_vars("reg_user_row", array(
450 "ROW_COLOR" => "#" . $row_color,
451 "ROW_CLASS" => $row_class,
452 "USERNAME" => $username,
453 "STARTED" => create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['session_start'], $board_config['board_timezone']),
454 "LASTUPDATE" => create_date($board_config['default_dateformat'], $onlinerow_reg[$i]['user_session_time'], $board_config['board_timezone']),
455 "FORUM_LOCATION" => $location,
456 "IP_ADDRESS" => $reg_ip,
457  
458 "U_WHOIS_IP" => "http://network-tools.com/default.asp?host=$reg_ip",
459 "U_USER_PROFILE" => append_sid("admin_users.$phpEx?mode=edit&amp;" . POST_USERS_URL . "=" . $onlinerow_reg[$i]['user_id']),
460 "U_FORUM_LOCATION" => append_sid($location_url))
461 );
462 }
463 }
464  
465 }
466 else
467 {
468 $template->assign_vars(array(
469 "L_NO_REGISTERED_USERS_BROWSING" => $lang['No_users_browsing'])
470 );
471 }
472  
473 //
474 // Guest users
475 //
476 if( count($onlinerow_guest) )
477 {
478 $guest_users = 0;
479  
480 for($i = 0; $i < count($onlinerow_guest); $i++)
481 {
482 $guest_userip_ary[] = $onlinerow_guest[$i]['session_ip'];
483 $guest_users++;
484  
485 if( $onlinerow_guest[$i]['session_page'] < 1 )
486 {
487 switch( $onlinerow_guest[$i]['session_page'] )
488 {
489 case PAGE_INDEX:
490 $location = $lang['Forum_index'];
491 $location_url = "index.$phpEx?pane=right";
492 break;
493 case PAGE_POSTING:
494 $location = $lang['Posting_message'];
495 $location_url = "index.$phpEx?pane=right";
496 break;
497 case PAGE_LOGIN:
498 $location = $lang['Logging_on'];
499 $location_url = "index.$phpEx?pane=right";
500 break;
501 case PAGE_SEARCH:
502 $location = $lang['Searching_forums'];
503 $location_url = "index.$phpEx?pane=right";
504 break;
505 case PAGE_PROFILE:
506 $location = $lang['Viewing_profile'];
507 $location_url = "index.$phpEx?pane=right";
508 break;
509 case PAGE_VIEWONLINE:
510 $location = $lang['Viewing_online'];
511 $location_url = "index.$phpEx?pane=right";
512 break;
513 case PAGE_VIEWMEMBERS:
514 $location = $lang['Viewing_member_list'];
515 $location_url = "index.$phpEx?pane=right";
516 break;
517 case PAGE_PRIVMSGS:
518 $location = $lang['Viewing_priv_msgs'];
519 $location_url = "index.$phpEx?pane=right";
520 break;
521 case PAGE_FAQ:
522 $location = $lang['Viewing_FAQ'];
523 $location_url = "index.$phpEx?pane=right";
524 break;
525 default:
526 $location = $lang['Forum_index'];
527 $location_url = "index.$phpEx?pane=right";
528 }
529 }
530 else
531 {
532 $location_url = append_sid("admin_forums.$phpEx?mode=editforum&amp;" . POST_FORUM_URL . "=" . $onlinerow_guest[$i]['session_page']);
533 $location = $forum_data[$onlinerow_guest[$i]['session_page']];
534 }
535  
536 $row_color = ( $guest_users % 2 ) ? $theme['td_color1'] : $theme['td_color2'];
537 $row_class = ( $guest_users % 2 ) ? $theme['td_class1'] : $theme['td_class2'];
538  
539 $guest_ip = decode_ip($onlinerow_guest[$i]['session_ip']);
540  
541 $template->assign_block_vars("guest_user_row", array(
542 "ROW_COLOR" => "#" . $row_color,
543 "ROW_CLASS" => $row_class,
544 "USERNAME" => $lang['Guest'],
545 "STARTED" => create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_start'], $board_config['board_timezone']),
546 "LASTUPDATE" => create_date($board_config['default_dateformat'], $onlinerow_guest[$i]['session_time'], $board_config['board_timezone']),
547 "FORUM_LOCATION" => $location,
548 "IP_ADDRESS" => $guest_ip,
549  
550 "U_WHOIS_IP" => "http://network-tools.com/default.asp?host=$guest_ip",
551 "U_FORUM_LOCATION" => append_sid($location_url))
552 );
553 }
554  
555 }
556 else
557 {
558 $template->assign_vars(array(
559 "L_NO_GUESTS_BROWSING" => $lang['No_users_browsing'])
560 );
561 }
562  
563 // Check for new version
564 $current_version = explode('.', '2' . $board_config['version']);
565 $minor_revision = (int) $current_version[2];
566  
567 $errno = 0;
568 $errstr = $version_info = '';
569  
570 if ($fsock = @fsockopen('www.phpbb.com', 80, $errno, $errstr, 10))
571 {
572 @fputs($fsock, "GET /updatecheck/20x.txt HTTP/1.1\r\n");
573 @fputs($fsock, "HOST: www.phpbb.com\r\n");
574 @fputs($fsock, "Connection: close\r\n\r\n");
575  
576 $get_info = false;
577 while (!@feof($fsock))
578 {
579 if ($get_info)
580 {
581 $version_info .= @fread($fsock, 1024);
582 }
583 else
584 {
585 if (@fgets($fsock, 1024) == "\r\n")
586 {
587 $get_info = true;
588 }
589 }
590 }
591 @fclose($fsock);
592  
593 $version_info = explode("\n", $version_info);
594 $latest_head_revision = (int) $version_info[0];
595 $latest_minor_revision = (int) $version_info[2];
596 $latest_version = (int) $version_info[0] . '.' . (int) $version_info[1] . '.' . (int) $version_info[2];
597  
598 if ($latest_head_revision == 2 && $minor_revision == $latest_minor_revision)
599 {
600 $version_info = '<p style="color:green">' . $lang['Version_up_to_date'] . '</p>';
601 }
602 else
603 {
604 $version_info = '<p style="color:red">' . $lang['Version_not_up_to_date'];
605 $version_info .= '<br />' . sprintf($lang['Latest_version_info'], $latest_version) . ' ' . sprintf($lang['Current_version_info'], '2' . $board_config['version']) . '</p>';
606 }
607 }
608 else
609 {
610 if ($errstr)
611 {
612 $version_info = '<p style="color:red">' . sprintf($lang['Connect_socket_error'], $errstr) . '</p>';
613 }
614 else
615 {
616 $version_info = '<p>' . $lang['Socket_functions_disabled'] . '</p>';
617 }
618 }
619  
620 $version_info .= '<p>' . $lang['Mailing_list_subscribe_reminder'] . '</p>';
621  
622  
623 $template->assign_vars(array(
624 'VERSION_INFO' => $version_info,
625 'L_VERSION_INFORMATION' => $lang['Version_information'])
626 );
627  
628 $template->pparse("body");
629  
630 include('./page_footer_admin.'.$phpEx);
631  
632 }
633 else
634 {
635 //
636 // Generate frameset
637 //
638 $template->set_filenames(array(
639 "body" => "admin/index_frameset.tpl")
640 );
641  
642 $template->assign_vars(array(
643 "S_FRAME_NAV" => append_sid("index.$phpEx?pane=left"),
644 "S_FRAME_MAIN" => append_sid("index.$phpEx?pane=right"))
645 );
646  
647 header ("Expires: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
648 header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
649  
650 $template->pparse("body");
651  
652 $db->sql_close();
653 exit;
654  
655 }
656  
657 ?>