Source for file redirect.php

Documentation is available at redirect.php

  1. <?php
  2.  
  3. /**
  4.  * Prevents users from reposting their form data after a successful logout.
  5.  *
  6.  * Derived from webmail.php by Ralf Kraudelt <[email protected]>
  7.  *
  8.  * @copyright 1999-2020 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: redirect.php 14845 2020-01-07 08:09:34Z pdontthink $
  11.  * @package squirrelmail
  12.  */
  13.  
  14. /** This is the redirect page */
  15. define('PAGE_NAME''redirect');
  16.  
  17. /**
  18.  * Include the SquirrelMail initialization file.
  19.  */
  20. require('../include/init.php');
  21.  
  22. /* SquirrelMail required files. */
  23. require_once(SM_PATH 'functions/imap_general.php');
  24. require_once(SM_PATH 'functions/strings.php');
  25.  
  26. // Disable browser caching
  27. //
  28. header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
  29. header('Pragma: no-cache');
  30. header('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
  31. $location get_location();
  32.  
  33. // session_set_cookie_params (0, $base_uri);
  34.  
  35. sqsession_unregister ('user_is_logged_in');
  36. sqsession_register ($base_uri'base_uri');
  37.  
  38. /* get globals we me need */
  39. sqGetGlobalVar('login_username'$login_username);
  40. sqGetGlobalVar('secretkey'$secretkey);
  41. if(!sqGetGlobalVar('squirrelmail_language'$squirrelmail_language|| $squirrelmail_language == ''{
  42.     $squirrelmail_language $squirrelmail_default_language;
  43. }
  44. if (!sqgetGlobalVar('mailtodata'$mailtodata)) {
  45.     $mailtodata '';
  46. }
  47.  
  48. /* end of get globals */
  49.  
  50. set_up_language($squirrelmail_languagetrue);
  51. /* Refresh the language cookie. */
  52. sqsetcookie('squirrelmail_language'$squirrelmail_languagetime()+2592000,
  53.           $base_uri);
  54.  
  55. if (!isset($login_username)) {
  56.     logout_error_("You must be logged in to access this page.") );
  57.     exit;
  58. }
  59.  
  60. do_hook('login_before'$null);
  61.  
  62. $onetimepad OneTimePadCreate(strlen($secretkey));
  63. $key OneTimePadEncrypt($secretkey$onetimepad);
  64.  
  65. /* remove redundant spaces */
  66. $login_username trim($login_username);
  67.  
  68. /* Case-normalise username if so desired */
  69. if ($force_username_lowercase{
  70.     $login_username strtolower($login_username);
  71. }
  72.  
  73. /* Verify that username and password are correct. */
  74. global $imap_stream_options// in case not defined in config
  75. $imapConnection sqimap_login($login_username$key$imapServerAddress$imapPort0$imap_stream_options);
  76. /* From now on we are logged it. If the login failed then sqimap_login handles it */
  77.  
  78. /**
  79.  * Regenerate session id to make sure that authenticated session uses
  80.  * different ID than one used before user authenticated.  This is a
  81.  * countermeasure against session fixation attacks.
  82.  * NB: session_regenerate_id() was added in PHP 4.3.2 (and new session
  83.  *     cookie is only sent out in this call as of PHP 4.3.3), but PHP 4
  84.  *     is not vulnerable to session fixation problems in SquirrelMail
  85.  *     because it prioritizes $base_uri subdirectory cookies differently
  86.  *     than PHP 5, which is otherwise vulnerable.  If we really want to,
  87.  *     we could define our own session_regenerate_id() when one does not
  88.  *     exist, but there seems to be no reason to do so.
  89.  */
  90. if (function_exists('session_regenerate_id')) {
  91. }
  92.  
  93. /**
  94. * The cookie part. session_start and session_regenerate_session normally set
  95. * their own cookie. SquirrelMail sets another cookie which overwites the
  96. * php cookies. The sqsetcookie function sets the cookie by using the header
  97. * function which gives us full control how the cookie is set. We do that
  98. * to add the HttpOnly cookie attribute which blocks javascript access on
  99. * IE6 SP1.
  100. */
  101. sqsetcookie(session_name(),session_id(),false,$base_uri);
  102. sqsetcookie('key'$keyfalse$base_uri);
  103.  
  104. sqsession_register($onetimepad'onetimepad');
  105.  
  106. $sqimap_capabilities sqimap_capability($imapConnection);
  107.  
  108. /* Server side sorting control */
  109. if (isset($sqimap_capabilities['SORT']&& $sqimap_capabilities['SORT'== true &&
  110.     isset($disable_server_sort&& $disable_server_sort{
  111.     unset($sqimap_capabilities['SORT']);
  112. }
  113.  
  114. /* Thread sort control */
  115. if (isset($sqimap_capabilities['THREAD']&& $sqimap_capabilities['THREAD'== true &&
  116.     isset($disable_thread_sort&& $disable_thread_sort{
  117.     unset($sqimap_capabilities['THREAD']);
  118. }
  119.  
  120. sqsession_register($sqimap_capabilities'sqimap_capabilities');
  121. $delimiter sqimap_get_delimiter ($imapConnection);
  122.  
  123. if (isset($sqimap_capabilities['NAMESPACE']&& $sqimap_capabilities['NAMESPACE'== true{
  124.     $namespace sqimap_get_namespace($imapConnection);
  125.     sqsession_register($namespace'sqimap_namespace');
  126. }
  127.  
  128. sqimap_logout($imapConnection);
  129. sqsession_register($delimiter'delimiter');
  130.  
  131. $username $login_username;
  132. sqsession_register ($username'username');
  133. do_hook('login_verified'$null);
  134.  
  135. /* Set the login variables. */
  136. $user_is_logged_in true;
  137. $just_logged_in true;
  138.  
  139. /* And register with them with the session. */
  140. sqsession_register ($user_is_logged_in'user_is_logged_in');
  141. sqsession_register ($just_logged_in'just_logged_in');
  142.  
  143. /* parse the accepted content-types of the client */
  144. $attachment_common_types array();
  145. $attachment_common_types_parsed array();
  146. sqsession_register($attachment_common_types'attachment_common_types');
  147. sqsession_register($attachment_common_types_parsed'attachment_common_types_parsed');
  148.  
  149. if sqgetGlobalVar('HTTP_ACCEPT'$http_acceptSQ_SERVER&&
  150.     !isset($attachment_common_types_parsed[$http_accept]) ) {
  151.     attachment_common_parse($http_accept);
  152. }
  153.  
  154. // having just logged in, need to synch the template file cache
  155. // so the right template set is displayed (per user prefs)
  156. require(SM_PATH 'include/load_prefs.php');
  157. global $sTemplateID;
  158.  
  159. /* Complete autodetection of Javascript. */
  160.  
  161. /* Compute the URL to forward the user to. */
  162. $redirect_url $location '/webmail.php';
  163.  
  164. if sqgetGlobalVar('session_expired_location'$session_expired_locationSQ_SESSION) ) {
  165.     sqsession_unregister('session_expired_location');
  166.     if $session_expired_location == 'compose' {
  167.         $compose_new_win getPref($data_dir$username'compose_new_win'0);
  168.         if ($compose_new_win{
  169.             // do not prefix $location here because $session_expired_location is set to the PAGE_NAME
  170.             // of the last page
  171.             $redirect_url $location '/' $session_expired_location '.php';
  172.         else {
  173.             $redirect_url $location '/webmail.php?right_frame=' urlencode($session_expired_location '.php');
  174.         }
  175.     else if ($session_expired_location != 'webmail' 
  176.             && $session_expired_location != 'left_main'{
  177.         $redirect_url $location '/webmail.php?right_frame=' urlencode($session_expired_location '.php');
  178.     }
  179.     unset($session_expired_location);
  180. }
  181.  
  182. if($mailtodata != ''{
  183.     $redirect_url  $location '/webmail.php?right_frame=compose.php&mailtodata=';
  184.     $redirect_url .= urlencode($mailtodata);
  185. }
  186.  
  187. /* Write session data and send them off to the appropriate page. */
  188. header("Location: $redirect_url");
  189. exit;
  190.  
  191. /* --------------------- end main ----------------------- */
  192.  
  193. function attachment_common_parse($str{
  194.     global $attachment_common_types$attachment_common_types_parsed;
  195.  
  196.     /*
  197.      * Replace ", " with "," and explode on that as Mozilla 1.x seems to
  198.      * use "," to seperate whilst IE, and earlier versions of Mozilla use
  199.      * ", " to seperate
  200.      */
  201.  
  202.     $str str_replace', ' ',' $str );
  203.     $types explode(','$str);
  204.  
  205.     foreach ($types as $val{
  206.         // Ignore the ";q=1.0" stuff
  207.         if (strpos($val';'!== false{
  208.             $val substr($val0strpos($val';'));
  209.         }
  210.         if (isset($attachment_common_types[$val])) {
  211.             $attachment_common_types[$valtrue;
  212.         }
  213.     }
  214.     sqsession_register($attachment_common_types'attachment_common_types');
  215.  
  216.     /* mark as parsed */
  217.     $attachment_common_types_parsed[$strtrue;
  218. }

Documentation generated on Mon, 13 Jan 2020 04:23:25 +0100 by phpDocumentor 1.4.3