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 <kraude@wiwi.uni-rostock.de>
  7.  *
  8.  * @copyright 1999-2012 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: redirect.php 14248 2012-01-02 00:18:17Z pdontthink $
  11.  * @package squirrelmail
  12.  */
  13.  
  14. /** This is the redirect page */
  15. define('PAGE_NAME''redirect');
  16.  
  17. /**
  18.  * Path for SquirrelMail required files.
  19.  * @ignore
  20.  */
  21. define('SM_PATH','../');
  22.  
  23. /* SquirrelMail required files. */
  24. require_once(SM_PATH 'functions/global.php');
  25. require_once(SM_PATH 'functions/i18n.php');
  26. require_once(SM_PATH 'functions/strings.php');
  27. require_once(SM_PATH 'functions/prefs.php');
  28. require_once(SM_PATH 'functions/imap.php');
  29. require_once(SM_PATH 'functions/plugin.php');
  30. require_once(SM_PATH 'functions/constants.php');
  31. require_once(SM_PATH 'functions/page_header.php');
  32.  
  33. // Disable Browser Caching
  34. //
  35. header('Cache-Control: no-cache, no-store, must-revalidate');
  36. header('Pragma: no-cache');
  37. header('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
  38. $location get_location();
  39.  
  40.  
  41. sqsession_unregister ('user_is_logged_in');
  42. sqsession_register ($base_uri'base_uri');
  43.  
  44. /* get globals we me need */
  45. sqGetGlobalVar('login_username'$login_username);
  46. sqGetGlobalVar('secretkey'$secretkey);
  47. sqGetGlobalVar('js_autodetect_results'$js_autodetect_results);
  48. if(!sqGetGlobalVar('squirrelmail_language'$squirrelmail_language|| $squirrelmail_language == ''{
  49.     $squirrelmail_language $squirrelmail_default_language;
  50. }
  51.  
  52. if (!sqgetGlobalVar('mailtodata'$mailtodata)) {
  53.     $mailtodata '';
  54. }
  55.  
  56.  
  57. /* end of get globals */
  58.  
  59. set_up_language($squirrelmail_languagetrue);
  60. /* Refresh the language cookie. */
  61. sqsetcookie('squirrelmail_language'$squirrelmail_languagetime()+2592000$base_uri);
  62.  
  63. if (!isset($login_username)) {
  64.     include_once(SM_PATH .  'functions/display_messages.php' );
  65.     logout_error_("You must be logged in to access this page.") );
  66.     exit;
  67. }
  68.  
  69. if (!sqsession_is_registered('user_is_logged_in')) {
  70.     do_hook ('login_before');
  71.  
  72.     /**
  73.      * Regenerate session id to make sure that authenticated session uses
  74.      * different ID than one used before user authenticated.  This is a
  75.      * countermeasure against session fixation attacks.
  76.      * NB: session_regenerate_id() was added in PHP 4.3.2 (and new session
  77.      *     cookie is only sent out in this call as of PHP 4.3.3), but PHP 4
  78.      *     is not vulnerable to session fixation problems in SquirrelMail
  79.      *     because it prioritizes $base_uri subdirectory cookies differently
  80.      *     than PHP 5, which is otherwise vulnerable.  If we really want to,
  81.      *     we could define our own session_regenerate_id() when one does not
  82.      *     exist, but there seems to be no reason to do so.
  83.      */
  84.     if (function_exists('session_regenerate_id')) {
  85.         session_regenerate_id();
  86.  
  87.         // re-send session cookie so we get the right parameters on it
  88.         // (such as HTTPOnly, if necessary - PHP doesn't do this itself
  89.         sqsetcookie(session_name(),session_id(),false,$base_uri);
  90.     }
  91.  
  92.     $onetimepad OneTimePadCreate(strlen($secretkey));
  93.     $key OneTimePadEncrypt($secretkey$onetimepad);
  94.     sqsession_register($onetimepad'onetimepad');
  95.  
  96.     /* remove redundant spaces */
  97.     $login_username trim($login_username);
  98.  
  99.     /* Verify that username and password are correct. */
  100.     if ($force_username_lowercase{
  101.         $login_username strtolower($login_username);
  102.     }
  103.  
  104.     $imapConnection sqimap_login($login_username$key$imapServerAddress$imapPort0);
  105.  
  106.     $sqimap_capabilities sqimap_capability($imapConnection);
  107.     sqsession_register($sqimap_capabilities'sqimap_capabilities');
  108.     $delimiter sqimap_get_delimiter ($imapConnection);
  109.  
  110.     sqimap_logout($imapConnection);
  111.     sqsession_register($delimiter'delimiter');
  112.  
  113.     $username $login_username;
  114.     sqsession_register ($username'username');
  115.     sqsetcookie('key'$key0$base_uri);
  116.  
  117.     $is_login_verified_hook TRUE;
  118.     do_hook ('login_verified');
  119.     $is_login_verified_hook FALSE;
  120.  
  121. }
  122.  
  123. /* Set the login variables. */
  124. $user_is_logged_in true;
  125. $just_logged_in true;
  126.  
  127. /* And register with them with the session. */
  128. sqsession_register ($user_is_logged_in'user_is_logged_in');
  129. sqsession_register ($just_logged_in'just_logged_in');
  130.  
  131. /* parse the accepted content-types of the client */
  132. $attachment_common_types array();
  133. $attachment_common_types_parsed array();
  134. sqsession_register($attachment_common_types'attachment_common_types');
  135. sqsession_register($attachment_common_types_parsed'attachment_common_types_parsed');
  136.  
  137.  
  138. if sqgetGlobalVar('HTTP_ACCEPT'$http_acceptSQ_SERVER&&
  139.     !isset($attachment_common_types_parsed[$http_accept]) ) {
  140.     attachment_common_parse($http_accept);
  141. }
  142.  
  143. /* Complete autodetection of Javascript. */
  144. $javascript_setting getPref
  145.     ($data_dir$username'javascript_setting'SMPREF_JS_AUTODETECT);
  146. $js_autodetect_results (isset($js_autodetect_results?
  147.     $js_autodetect_results SMPREF_JS_OFF);
  148. /* See if it's set to "Always on" */
  149. $js_pref SMPREF_JS_ON;
  150. if ($javascript_setting != SMPREF_JS_ON){
  151.     if ($javascript_setting == SMPREF_JS_AUTODETECT{
  152.         if ($js_autodetect_results == SMPREF_JS_OFF{
  153.             $js_pref SMPREF_JS_OFF;
  154.         }
  155.     else {
  156.         $js_pref SMPREF_JS_OFF;
  157.     }
  158. }
  159. /* Update the prefs */
  160. setPref($data_dir$username'javascript_on'$js_pref);
  161.  
  162. /* Compute the URL to forward the user to. */
  163. $redirect_url 'webmail.php';
  164.  
  165. if sqgetGlobalVar('session_expired_location'$session_expired_locationSQ_SESSION) ) {
  166.     sqsession_unregister('session_expired_location');
  167.     if $session_expired_location == 'compose' {
  168.         $compose_new_win getPref($data_dir$username'compose_new_win'0);
  169.         if ($compose_new_win{
  170.             // do not prefix $location here because $session_expired_location is set to the PAGE_NAME
  171.             // of the last page
  172.             $redirect_url $session_expired_location '.php';
  173.         else {
  174.             $redirect_url 'webmail.php?right_frame=' urlencode($session_expired_location '.php');
  175.         }
  176.     else if ($session_expired_location != 'webmail'
  177.             && $session_expired_location != 'left_main'{
  178.         $redirect_url 'webmail.php?right_frame=' urlencode($session_expired_location '.php');
  179.     }
  180.     unset($session_expired_location);
  181. }
  182.  
  183. if($mailtodata != ''{
  184.     $redirect_url  $location '/webmail.php?right_frame=compose.php&mailtodata=';
  185.     $redirect_url .= urlencode($mailtodata);
  186. }
  187.  
  188.  
  189.  
  190. /* Write session data and send them off to the appropriate page. */
  191. header("Location: $redirect_url");
  192.  
  193. /* --------------------- end main ----------------------- */
  194.  
  195. function attachment_common_parse($str{
  196.     global $attachment_common_types$attachment_common_types_parsed;
  197.  
  198.     $attachment_common_types_parsed[$strtrue;
  199.  
  200.     /*
  201.      * Replace ", " with "," and explode on that as Mozilla 1.x seems to
  202.      * use "," to seperate whilst IE, and earlier versions of Mozilla use
  203.      * ", " to seperate
  204.      */
  205.  
  206.     $str str_replace', ' ',' $str );
  207.     $types explode(','$str);
  208.  
  209.     foreach ($types as $val{
  210.         // Ignore the ";q=1.0" stuff
  211.         if (strpos($val';'!== false)
  212.             $val substr($val0strpos($val';'));
  213.  
  214.         if (isset($attachment_common_types[$val])) {
  215.             $attachment_common_types[$valtrue;
  216.         }
  217.     }
  218.     sqsession_register($attachment_common_types'attachment_common_types');
  219. }

Documentation generated on Mon, 20 May 2013 04:22:56 +0200 by phpDocumentor 1.4.3