/include/admin/tokenmissing.php

https://github.com/mysnip/Core · PHP · 106 lines · 70 code · 13 blank · 23 comment · 11 complexity · 40db6f9281eff8164eb90656d947c3fe MD5 · raw file

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // Copyright (C) 2011 Phorum Development Team //
  5. // http://www.phorum.org //
  6. // //
  7. // This program is free software. You can redistribute it and/or modify //
  8. // it under the terms of either the current Phorum License (viewable at //
  9. // phorum.org) or the Phorum License that was distributed with this file //
  10. // //
  11. // This program 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. //
  14. // //
  15. // You should have received a copy of the Phorum License //
  16. // along with this program. //
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // don't allow this page to be loaded directly
  19. if(!defined("PHORUM_ADMIN")) exit();
  20. if(count($_POST)) {
  21. if(!empty($_POST['phorum_admin_token']) &&
  22. $_POST['phorum_admin_token'] == $PHORUM["user"]['settings_data']['admin_token'] &&
  23. time()-PHORUM_ADMIN_TOKEN_TIMEOUT < $PHORUM["user"]['settings_data']['admin_token_time']
  24. ) {
  25. if(!empty($_POST['cancel'])) {
  26. $PHORUM["user"]['settings_data']['admin_token'] = "";
  27. $tmp_user = array(
  28. 'user_id'=>$PHORUM["user"]['user_id'],
  29. 'settings_data'=>$PHORUM["user"]['settings_data']
  30. );
  31. phorum_api_user_save($tmp_user);
  32. phorum_api_redirect($PHORUM['http_path']);
  33. } elseif(!empty($_POST['continue'])) {
  34. if(!empty($_POST['target'])) {
  35. $url = phorum_admin_build_url($_POST['target']);
  36. } else {
  37. $url = phorum_admin_build_url();
  38. }
  39. phorum_api_redirect($url);
  40. }
  41. exit();
  42. }
  43. }
  44. // We have no token or our token expired.
  45. // Generate a fresh token.
  46. $admin_token_time = time();
  47. $admin_token = phorum_api_sign(
  48. $PHORUM['user']['user_id'].
  49. microtime().
  50. $PHORUM['user']['username'].
  51. $PHORUM['user']['sessid_st']
  52. );
  53. phorum_api_user_save_settings(array(
  54. 'admin_token_time' => $admin_token_time,
  55. 'admin_token' => $admin_token
  56. ));
  57. $PHORUM['admin_token'] = $admin_token;
  58. // If there are no POST or GET variables in the request, besides
  59. // "module" and/or "phorum_admin_token", then we can safely load
  60. // the requested admin page, without bugging the admin about the
  61. // token timeout.
  62. $post = $_POST; unset($post['module']); unset($post['phorum_admin_token']);
  63. $get = $_GET; unset($get['module']); unset($get['phorum_admin_token']);
  64. if (empty($post) && empty($get)) {
  65. $module = '';
  66. if (isset($_POST['module'])) {
  67. $module = basename($_POST['module']);
  68. } elseif (isset($_GET['module'])) {
  69. $module = basename($_GET['module']);
  70. }
  71. $url = phorum_admin_build_url('module='.urlencode($module));
  72. phorum_api_redirect($url);
  73. }
  74. $targetargs = $_SERVER['QUERY_STRING'];
  75. $target_html = htmlspecialchars(phorum_admin_build_url($targetargs));
  76. $targs_html = htmlspecialchars($targetargs);
  77. $post_url = phorum_admin_build_url();
  78. ?>
  79. You are accessing the admin after a security timeout.<br /><br />
  80. The requested URL was:
  81. <pre><?php echo $target_html;?></pre><br />
  82. <strong>Please make sure that you really want to access this URL and weren't tricked to go to the admin.</strong><br />
  83. Please click on <strong>continue</strong> to go to this URL or on <strong>cancel</strong> to go to the forum homepage.
  84. <br /><br />
  85. <form action="<?php echo $post_url;?>" method="POST">
  86. <input type="hidden" name="module" value="tokenmissing" />
  87. <input type="hidden" name="phorum_admin_token" value="<?php echo $PHORUM["user"]['settings_data']['admin_token'];?>" />
  88. <input type="hidden" name="target" value="<?php echo $targs_html;?>" />
  89. <input type="submit" name="cancel" value="cancel" />
  90. <input type="submit" name="continue" value="continue" />
  91. </form>