PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/admin.php

http://github.com/usebb/UseBB
PHP | 180 lines | 87 code | 31 blank | 62 comment | 9 complexity | 347b2d70245cbe4381519a914a8432df MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. Copyright (C) 2003-2012 UseBB Team
  4. http://www.usebb.net
  5. $Id$
  6. This file is part of UseBB.
  7. UseBB is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. UseBB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with UseBB; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /**
  20. * Admin control panel
  21. *
  22. * Gives access to the ACP features, including authorizing the admin first.
  23. *
  24. * @author UseBB Team
  25. * @link http://www.usebb.net
  26. * @license GPL-2
  27. * @version $Revision$
  28. * @copyright Copyright (C) 2003-2012 UseBB Team
  29. * @package UseBB
  30. * @subpackage ACP
  31. */
  32. define('INCLUDED', true);
  33. define('ROOT_PATH', './');
  34. //
  35. // Include usebb engine
  36. //
  37. require(ROOT_PATH.'sources/common.php');
  38. //
  39. // Update and get the session information
  40. //
  41. $session->update('admin');
  42. //
  43. // Include the page header
  44. //
  45. require(ROOT_PATH.'sources/page_head.php');
  46. if ( $functions->get_user_level() == LEVEL_ADMIN ) {
  47. //
  48. // Get Admin variables
  49. //
  50. $lang = $functions->fetch_language('', 'admin');
  51. $_GET['act'] = ( !empty($_GET['act']) ) ? str_replace(array('/', '\\'), '', $_GET['act']) : 'index';
  52. $_SESSION['admin_last_activity'] = ( isset($_SESSION['admin_last_activity']) ) ? (int) $_SESSION['admin_last_activity'] : 0;
  53. $_SESSION['admin_disable_logout'] = ( isset($_SESSION['admin_disable_logout']) ) ? (bool) $_SESSION['admin_disable_logout'] : false;
  54. $acp_auto_logout = (int) $functions->get_config('acp_auto_logout');
  55. if ( $_GET['act'] == 'logout' && $functions->verify_url(false) ) {
  56. //
  57. // Log out from ACP
  58. //
  59. $_SESSION['admin_pwd'] = '';
  60. $functions->redirect('index.php');
  61. } elseif ( !empty($_POST['passwd']) && md5(stripslashes($_POST['passwd'])) === $session->sess_info['user_info']['passwd'] ) {
  62. //
  63. // Password submitted and correct
  64. //
  65. $_SESSION['admin_pwd'] = md5(stripslashes($_POST['passwd']));
  66. $_SESSION['admin_last_activity'] = time();
  67. $_SESSION['admin_disable_logout'] = false;
  68. $functions->redirect('admin.php', $_GET);
  69. } elseif ( !empty($_SESSION['admin_pwd']) && $_SESSION['admin_pwd'] === $session->sess_info['user_info']['passwd'] && ( $_SESSION['admin_disable_logout'] || $_SESSION['admin_last_activity'] > time() - $acp_auto_logout * 60 ) ) {
  70. //
  71. // Password in session and recent activity
  72. //
  73. $_SESSION['admin_last_activity'] = time();
  74. $_SESSION['admin_disable_logout'] = false;
  75. require(ROOT_PATH.'sources/functions_admin.php');
  76. $admin_functions = new admin_functions;
  77. //
  78. // Include page/module
  79. //
  80. if ( preg_match('#^mod_([A-Za-z0-9\-_\.]+)$#', $_GET['act'], $module_name) && array_key_exists($module_name[1], $admin_functions->acp_modules) ) {
  81. //
  82. // ACP module
  83. //
  84. $admin_functions->run_module($module_name[1]);
  85. } elseif ( file_exists(ROOT_PATH.'sources/admin_'.$_GET['act'].'.php') ) {
  86. //
  87. // Regular page
  88. //
  89. $content = '';
  90. require(ROOT_PATH.'sources/admin_'.$_GET['act'].'.php');
  91. } else {
  92. //
  93. // Non existent
  94. //
  95. $functions->redirect('admin.php');
  96. }
  97. } else {
  98. //
  99. // Request password
  100. //
  101. if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  102. if ( empty($_POST['passwd']) ) {
  103. $template->parse('msgbox', 'global', array(
  104. 'box_title' => $lang['Error'],
  105. 'content' => sprintf($lang['MissingFields'], $lang['Password'])
  106. ));
  107. } else {
  108. $template->parse('msgbox', 'global', array(
  109. 'box_title' => $lang['Error'],
  110. 'content' => $lang['WrongPassword']
  111. ));
  112. }
  113. }
  114. $template->add_breadcrumb($lang['AdminLogin']);
  115. $template->parse('login_form', 'admin', array(
  116. 'form_begin' => '<form action="'.$functions->make_url('admin.php', $_GET).'" method="post">',
  117. 'form_end' => '</form>',
  118. 'username' => $session->sess_info['user_info']['name'],
  119. 'password_input' => '<input type="password" name="passwd" id="passwd" size="25" maxlength="255" />',
  120. 'submit_button' => '<input type="submit" value="'.$lang['LogIn'].'" />',
  121. ));
  122. $template->set_js_onload("set_focus('passwd')");
  123. }
  124. } else {
  125. $functions->redir_to_login();
  126. }
  127. //
  128. // Include the page footer
  129. //
  130. require(ROOT_PATH.'sources/page_foot.php');
  131. ?>