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)  

file_prefs.php
Go to the documentation of this file.
1 <?php
2 
21 
22  sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
23  if ( isset($prefs_are_cached) && $prefs_are_cached) {
24  sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
25  return;
26  }
27 
28  sqsession_unregister('prefs_cache');
29  sqsession_unregister('prefs_are_cached');
30 
31  /* Calculate the filename for the user's preference file */
32  $filename = getHashedFile($username, $data_dir, "$username.pref");
33 
34  /* A call to checkForPrefs here should take eliminate the need for */
35  /* this to be called throughout the rest of the SquirrelMail code. */
37 
38  /* Make sure that the preference file now DOES exist. */
39  if (!file_exists($filename)) {
40  logout_error( sprintf( _("Preference file, %s, does not exist. Log out, and log back in to create a default preference file."), $filename) );
41  exit;
42  }
43 
44  /* Open the file, or else display an error to the user. */
45  if(!$file = @fopen($filename, 'r'))
46  {
47  logout_error( sprintf( _("Preference file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename) );
48  exit;
49  }
50 
51  /* Read in the preferences. */
52  $highlight_num = 0;
53  while (! feof($file)) {
54  $pref = '';
55  /* keep reading a pref until we reach an eol (\n (or \r for macs)) */
56  while($read = fgets($file, 1024))
57  {
58  $pref .= $read;
59  if(strpos($read,"\n") || strpos($read,"\r"))
60  break;
61  }
62  $pref = trim($pref);
63  $equalsAt = strpos($pref, '=');
64  if ($equalsAt > 0) {
65  $key = substr($pref, 0, $equalsAt);
66  $value = substr($pref, $equalsAt + 1);
67  /* this is to 'rescue' old-style highlighting rules. */
68  if (substr($key, 0, 9) == 'highlight') {
69  $key = 'highlight' . $highlight_num;
70  $highlight_num ++;
71  }
72 
73  if ($value != '') {
74  $prefs_cache[$key] = $value;
75  }
76  }
77  }
78  fclose($file);
79 
80  $prefs_are_cached = TRUE;
81 
82  sqsession_register($prefs_cache, 'prefs_cache');
83  sqsession_register($prefs_are_cached, 'prefs_are_cached');
84 }
85 
89 function getPref($data_dir, $username, $string, $default = '') {
90  global $prefs_cache;
91 
92  $result = do_hook_function('get_pref_override',array($username, $string));
93 //FIXME: testing below for !$result means that a plugin cannot fetch its own pref value of 0, '0', '', FALSE, or anything else that evaluates to boolean FALSE.
94  if (!$result) {
96  if (isset($prefs_cache[$string])) {
97  $result = $prefs_cache[$string];
98  } else {
99 //FIXME: is there justification for having these TWO hooks so close together? who uses these?
100  $result = do_hook_function('get_pref', array($username, $string));
101 //FIXME: testing below for !$result means that a plugin cannot fetch its own pref value of 0, '0', '', FALSE, or anything else that evaluates to boolean FALSE.
102  if (!$result) {
103  $result = $default;
104  }
105  }
106  }
107  return ($result);
108 }
109 
114  global $prefs_cache;
115 
116  $filename = getHashedFile($username, $data_dir, "$username.pref");
117 
118  /* Open the file for writing, or else display an error to the user. */
119  if(!$file = @fopen($filename.'.tmp', 'w'))
120  {
121  logout_error( sprintf( _("Preference file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename.'.tmp') );
122  exit;
123  }
124  foreach ($prefs_cache as $Key => $Value) {
125  if (isset($Value)) {
126  if ( sq_fwrite($file, $Key . '=' . $Value . "\n") === FALSE ) {
127  logout_error( sprintf( _("Preference file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp') );
128  exit;
129  }
130  }
131  }
132  fclose($file);
133  if (! @copy($filename . '.tmp',$filename) ) {
134  logout_error( sprintf( _("Preference file, %s, could not be copied from temporary file, %s. Contact your system administrator to resolve this issue."), $filename, $filename . '.tmp') );
135  exit;
136  }
137  @unlink($filename . '.tmp');
138  @chmod($filename, 0600);
139  sqsession_register($prefs_cache , 'prefs_cache');
140 }
141 
145 function removePref($data_dir, $username, $string) {
146  global $prefs_cache;
147 
149 
150  if (isset($prefs_cache[$string])) {
151  unset($prefs_cache[$string]);
152  }
153 
155 }
156 
160 function setPref($data_dir, $username, $string, $value) {
161  global $prefs_cache;
162 
164  if (isset($prefs_cache[$string]) && ($prefs_cache[$string] == $value)) {
165  return;
166  }
167 
168  if ($value === '') {
169  removePref($data_dir, $username, $string);
170  return;
171  }
172 
173  $prefs_cache[$string] = $value;
175 }
176 
181  /* First, make sure we have the filename. */
182  if ($filename == '') {
183  $filename = getHashedFile($username, $data_dir, "$username.pref");
184  }
185 
186  /* Then, check if the file exists. */
187  if (!@file_exists($filename) ) {
188  /* First, check the $data_dir for the default preference file. */
189  if(substr($data_dir,-1) != '/') {
190  $data_dir .= '/';
191  }
192  $default_pref = $data_dir . 'default_pref';
193 
194  /* If it is not there, check the internal data directory. */
195  if (!@file_exists($default_pref)) {
196  $default_pref = SM_PATH . 'data/default_pref';
197  }
198 
199  /* Otherwise, report an error. */
200  $errTitle = sprintf( _("Error opening %s"), $default_pref );
201  if (!is_readable($default_pref)) {
202  $errString = $errTitle . "<br />\n" .
203  _("Default preference file not found or not readable!") . "<br />\n" .
204  _("Please contact your system administrator and report this error.") . "<br />\n";
205  logout_error( $errString, $errTitle );
206  exit;
207  } else if (!@copy($default_pref, $filename)) {
208  $uid = 'httpd';
209  if (function_exists('posix_getuid')){
210  $user_data = posix_getpwuid(posix_getuid());
211  $uid = $user_data['name'];
212  }
213  $errString = $errTitle . '<br />' .
214  _("Could not create initial preference file!") . "<br />\n" .
215  sprintf( _("%s should be writable by user %s"), $data_dir, $uid ) .
216  "<br />\n" . _("Please contact your system administrator and report this error.") . "<br />\n";
217  logout_error( $errString, $errTitle );
218  exit;
219  }
220  }
221 }
222 
226 function setSig($data_dir, $username, $number, $value) {
227  // Limit signature size to 64KB (database BLOB limit)
228  if (strlen($value)>65536) {
229  error_option_save(_("Signature is too big."));
230  return;
231  }
232  $filename = getHashedFile($username, $data_dir, "$username.si$number");
233  /* Open the file for writing, or else display an error to the user. */
234  if(!$file = @fopen("$filename.tmp", 'w')) {
235  logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename . '.tmp') );
236  exit;
237  }
238  if ( sq_fwrite($file, $value) === FALSE ) {
239  logout_error( sprintf( _("Signature file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp'));
240  exit;
241  }
242  fclose($file);
243  if (! @copy($filename . '.tmp',$filename) ) {
244  logout_error( sprintf( _("Signature file, %s, could not be copied from temporary file, %s. Contact your system administrator to resolve this issue."), $filename, $filename . '.tmp') );
245  exit;
246  }
247  @unlink($filename . '.tmp');
248  @chmod($filename, 0600);
249 
250 }
251 
255 function getSig($data_dir, $username, $number) {
256  $filename = getHashedFile($username, $data_dir, "$username.si$number");
257  $sig = '';
258  if (file_exists($filename)) {
259  /* Open the file, or else display an error to the user. */
260  if(!$file = @fopen($filename, 'r'))
261  {
262  logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename) );
263  exit;
264  }
265  while (!feof($file)) {
266  $sig .= fgets($file, 1024);
267  }
268  fclose($file);
269  }
270  return $sig;
271 }
272 
checkForPrefs
checkForPrefs($data_dir, $username, $filename='')
Definition: file_prefs.php:180
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
removePref
removePref($data_dir, $username, $string)
Definition: file_prefs.php:145
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
setPref
setPref($data_dir, $username, $string, $value)
Definition: file_prefs.php:160
sprintf
powered by Systran sprintf(_("Number of supported language pairs: %s"), '36').' '
Definition: options.php:107
sq_fwrite
sq_fwrite($fp, $string)
Definition: strings.php:763
$username
global $username
Definition: validate.php:55
logout_error
logout_error( $errString, $errTitle='')
Definition: display_messages.php:44
$prefs_cache
if(!include_once('DB.php')) global $prefs_cache
Definition: db_prefs.php:39
do_hook_function
do_hook_function($name, $parm=NULL)
Definition: plugin.php:69
cachePrefValues
cachePrefValues($data_dir, $username)
Definition: file_prefs.php:19
error_option_save
error_option_save($message)
Definition: display_messages.php:165
setSig
setSig($data_dir, $username, $number, $value)
Definition: file_prefs.php:226
getPref
getPref($data_dir, $username, $string, $default='')
Definition: file_prefs.php:89
$filename
if(isset($override_type0)) if(isset($override_type1)) $filename
Definition: download.php:97
exit
exit
Definition: help.php:128
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
sqsession_register
sqsession_register($var, $name)
Definition: global.php:289
_
_($str)
Definition: gettext.php:160
$read
$read
Definition: message_details_bottom.php:75
getSig
getSig($data_dir, $username, $number)
Definition: file_prefs.php:255
getHashedFile
getHashedFile($username, $dir, $datafile, $hash_search=true)
Definition: prefs.php:56
sqsession_unregister
sqsession_unregister($name)
Definition: global.php:301
savePrefValues
savePrefValues($data_dir, $username)
Definition: file_prefs.php:113
$prefs_are_cached
if(!include_once('DB.php')) global $prefs_are_cached
Definition: db_prefs.php:39