squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

redirect.php
Go to the documentation of this file.
1 <?php
2 
15 define('PAGE_NAME', 'redirect');
16 
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');
39 
41 
42 sqsession_unregister ('user_is_logged_in');
43 sqsession_register ($base_uri, 'base_uri');
44 
45 /* get globals we me need */
46 sqGetGlobalVar('login_username', $login_username);
47 sqGetGlobalVar('secretkey', $secretkey);
48 sqGetGlobalVar('js_autodetect_results', $js_autodetect_results);
49 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
51 }
52 
53 if (!sqgetGlobalVar('mailtodata', $mailtodata)) {
54  $mailtodata = '';
55 }
56 
57 
58 /* end of get globals */
59 
61 /* Refresh the language cookie. */
62 sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+2592000, $base_uri);
63 
64 if (!isset($login_username)) {
65  include_once(SM_PATH . 'functions/display_messages.php' );
66  logout_error( _("You must be logged in to access this page.") );
67  exit;
68 }
69 
70 if (!sqsession_is_registered('user_is_logged_in')) {
71  do_hook ('login_before');
72 
85  if (function_exists('session_regenerate_id')) {
86  session_regenerate_id();
87 
88  // re-send session cookie so we get the right parameters on it
89  // (such as HTTPOnly, if necessary - PHP doesn't do this itself
90  sqsetcookie(session_name(),session_id(),false,$base_uri);
91  }
92 
93  $onetimepad = OneTimePadCreate(strlen($secretkey));
94  $key = OneTimePadEncrypt($secretkey, $onetimepad);
95  sqsession_register($onetimepad, 'onetimepad');
96 
97  /* remove redundant spaces */
98  $login_username = trim($login_username);
99 
100  /* Verify that username and password are correct. */
102  $login_username = strtolower($login_username);
103  }
104 
105  $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
106 
108  sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
109  $delimiter = sqimap_get_delimiter ($imapConnection);
110 
112  sqsession_register($delimiter, 'delimiter');
113 
114  $username = $login_username;
115  sqsession_register ($username, 'username');
116  sqsetcookie('key', $key, 0, $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. */
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 */
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_accept, SQ_SERVER) &&
140  !isset($attachment_common_types_parsed[$http_accept]) ) {
141  attachment_common_parse($http_accept);
142 }
143 
144 /* Complete autodetection of Javascript. */
146  ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
149 /* See if it's set to "Always on" */
155  }
156  } else {
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_location, SQ_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 session_write_close();
193 header("Location: $redirect_url");
194 
195 /* --------------------- end main ----------------------- */
196 
197 function attachment_common_parse($str) {
199 
200  $attachment_common_types_parsed[$str] = true;
201 
202  /*
203  * Replace ", " with "," and explode on that as Mozilla 1.x seems to
204  * use "," to seperate whilst IE, and earlier versions of Mozilla use
205  * ", " to seperate
206  */
207 
208  $str = str_replace( ', ' , ',' , $str );
209  $types = explode(',', $str);
210 
211  foreach ($types as $val) {
212  // Ignore the ";q=1.0" stuff
213  if (strpos($val, ';') !== false)
214  $val = substr($val, 0, strpos($val, ';'));
215 
216  if (! isset($attachment_common_types[$val])) {
217  $attachment_common_types[$val] = true;
218  }
219  }
220  sqsession_register($attachment_common_types, 'attachment_common_types');
221 }
222 
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$imapConnection
$imapConnection
Definition: message_details_bottom.php:74
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
$squirrelmail_default_language
$squirrelmail_default_language
Definition: config_default.php:1012
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$js_autodetect_results
$js_autodetect_results
Definition: redirect.php:147
OneTimePadEncrypt
OneTimePadEncrypt($string, $epad)
Definition: strings.php:430
OneTimePadCreate
OneTimePadCreate($length=100)
Definition: strings.php:565
setPref
setPref($data_dir, $username, $string, $set_to)
Definition: db_prefs.php:352
SMPREF_JS_ON
const SMPREF_JS_ON
Definition: constants.php:53
$just_logged_in
$just_logged_in
Definition: redirect.php:126
$username
global $username
Definition: validate.php:55
do_hook
do_hook($name)
Definition: plugin.php:42
$sqimap_capabilities
if(sqgetGlobalVar('passed_id', $temp)) if(sqgetGlobalVar('sort', $temp)) if(sqgetGlobalVar('startMessage', $temp)) global $sqimap_capabilities
Definition: read_body.php:767
logout_error
logout_error( $errString, $errTitle='')
Definition: display_messages.php:44
set_up_language
set_up_language($sm_language, $do_search=false, $default=false)
Definition: i18n.php:330
sqsession_is_registered
sqsession_is_registered($name)
Definition: global.php:318
$js_pref
$js_pref
Definition: redirect.php:150
$redirect_url
$redirect_url
Definition: redirect.php:164
SMPREF_JS_OFF
const SMPREF_JS_OFF
Definition: constants.php:52
sqimap_logout
sqimap_logout($imap_stream)
Definition: imap_general.php:639
SM_PATH
const SM_PATH
Definition: redirect.php:21
$attachment_common_types_parsed
$attachment_common_types_parsed
Definition: redirect.php:134
$user_is_logged_in
if(!isset($login_username)) if(!sqsession_is_registered('user_is_logged_in')) $user_is_logged_in
Definition: redirect.php:125
sqsetcookie
sqsetcookie($sName, $sValue='deleted', $iExpire=0, $sPath="", $sDomain="", $bSecure=false, $bHttpOnly=true, $bReplace=false)
Definition: global.php:509
SQ_SERVER
const SQ_SERVER
Definition: global.php:20
SMPREF_JS_AUTODETECT
const SMPREF_JS_AUTODETECT
Definition: constants.php:54
exit
exit
Definition: help.php:128
$location
$location
Definition: redirect.php:38
sqsession_register
sqsession_register($var, $name)
Definition: global.php:289
_
_($str)
Definition: gettext.php:160
$base_uri
if(!(bool) ini_get('session.use_cookies')||ini_get('session.use_cookies')=='off') $base_uri
Definition: global.php:173
$force_username_lowercase
$force_username_lowercase
Definition: config_default.php:550
$imapPort
$imapPort
Definition: config_default.php:210
attachment_common_parse
attachment_common_parse($str)
Definition: redirect.php:197
$javascript_setting
if(sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&!isset($attachment_common_types_parsed[$http_accept])) $javascript_setting
Definition: redirect.php:145
sqsession_is_active
sqsession_is_active()
Definition: global.php:452
$squirrelmail_language
global $squirrelmail_language
Definition: i18n.php:774
sqsession_unregister
sqsession_unregister($name)
Definition: global.php:301
get_location
get_location()
Definition: strings.php:340
$compose_new_win
$compose_new_win
Definition: load_prefs.php:251
sqimap_get_delimiter
sqimap_get_delimiter($imap_stream=false)
Definition: imap_general.php:681
sqimap_capability
sqimap_capability($imap_stream, $capability='')
Definition: imap_general.php:651
$attachment_common_types
$attachment_common_types
Definition: redirect.php:133