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 14840 2020-01-07 07:42:38Z 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.     global $imap_stream_options// in case not defined in config
  105.     $imapConnection sqimap_login($login_username$key$imapServerAddress$imapPort0$imap_stream_options);
  106.  
  107.     $sqimap_capabilities sqimap_capability($imapConnection);
  108.     sqsession_register($sqimap_capabilities'sqimap_capabilities');
  109.     $delimiter sqimap_get_delimiter ($imapConnection);
  110.  
  111.     sqimap_logout($imapConnection);
  112.     sqsession_register($delimiter'delimiter');
  113.  
  114.     $username $login_username;
  115.     sqsession_register ($username'username');
  116.     sqsetcookie('key'$key0$base_uri);
  117.  
  118.     $is_login_verified_hook TRUE;
  119.     do_hook ('login_verified');
  120.     $is_login_verified_hook FALSE;
  121.  
  122. }
  123.  
  124. /* Set the login variables. */
  125. $user_is_logged_in true;
  126. $just_logged_in true;
  127.  
  128. /* And register with them with the session. */
  129. sqsession_register ($user_is_logged_in'user_is_logged_in');
  130. sqsession_register ($just_logged_in'just_logged_in');
  131.  
  132. /* parse the accepted content-types of the client */
  133. $attachment_common_types array();
  134. $attachment_common_types_parsed array();
  135. sqsession_register($attachment_common_types'attachment_common_types');
  136. sqsession_register($attachment_common_types_parsed'attachment_common_types_parsed');
  137.  
  138.  
  139. if sqgetGlobalVar('HTTP_ACCEPT'$http_acceptSQ_SERVER&&
  140.     !isset($attachment_common_types_parsed[$http_accept]) ) {
  141.     attachment_common_parse($http_accept);
  142. }
  143.  
  144. /* Complete autodetection of Javascript. */
  145. $javascript_setting getPref
  146.     ($data_dir$username'javascript_setting'SMPREF_JS_AUTODETECT);
  147. $js_autodetect_results (isset($js_autodetect_results?
  148.     $js_autodetect_results SMPREF_JS_OFF);
  149. /* See if it's set to "Always on" */
  150. $js_pref SMPREF_JS_ON;
  151. if ($javascript_setting != SMPREF_JS_ON){
  152.     if ($javascript_setting == SMPREF_JS_AUTODETECT{
  153.         if ($js_autodetect_results == SMPREF_JS_OFF{
  154.             $js_pref SMPREF_JS_OFF;
  155.         }
  156.     else {
  157.         $js_pref SMPREF_JS_OFF;
  158.     }
  159. }
  160. /* Update the prefs */
  161. setPref($data_dir$username'javascript_on'$js_pref);
  162.  
  163. /* Compute the URL to forward the user to. */
  164. $redirect_url 'webmail.php';
  165.  
  166. if sqgetGlobalVar('session_expired_location'$session_expired_locationSQ_SESSION) ) {
  167.     sqsession_unregister('session_expired_location');
  168.     if $session_expired_location == 'compose' {
  169.         $compose_new_win getPref($data_dir$username'compose_new_win'0);
  170.         if ($compose_new_win{
  171.             // do not prefix $location here because $session_expired_location is set to the PAGE_NAME
  172.             // of the last page
  173.             $redirect_url $session_expired_location '.php';
  174.         else {
  175.             $redirect_url 'webmail.php?right_frame=' urlencode($session_expired_location '.php');
  176.         }
  177.     else if ($session_expired_location != 'webmail'
  178.             && $session_expired_location != 'left_main'{
  179.         $redirect_url 'webmail.php?right_frame=' urlencode($session_expired_location '.php');
  180.     }
  181.     unset($session_expired_location);
  182. }
  183.  
  184. if($mailtodata != ''{
  185.     $redirect_url  $location '/webmail.php?right_frame=compose.php&mailtodata=';
  186.     $redirect_url .= urlencode($mailtodata);
  187. }
  188.  
  189.  
  190.  
  191. /* Write session data and send them off to the appropriate page. */
  192. header("Location: $redirect_url");
  193.  
  194. /* --------------------- end main ----------------------- */
  195.  
  196. function attachment_common_parse($str{
  197.     global $attachment_common_types$attachment_common_types_parsed;
  198.  
  199.     $attachment_common_types_parsed[$strtrue;
  200.  
  201.     /*
  202.      * Replace ", " with "," and explode on that as Mozilla 1.x seems to
  203.      * use "," to seperate whilst IE, and earlier versions of Mozilla use
  204.      * ", " to seperate
  205.      */
  206.  
  207.     $str str_replace', ' ',' $str );
  208.     $types explode(','$str);
  209.  
  210.     foreach ($types as $val{
  211.         // Ignore the ";q=1.0" stuff
  212.         if (strpos($val';'!== false)
  213.             $val substr($val0strpos($val';'));
  214.  
  215.         if (isset($attachment_common_types[$val])) {
  216.             $attachment_common_types[$valtrue;
  217.         }
  218.     }
  219.     sqsession_register($attachment_common_types'attachment_common_types');
  220. }

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