Source for file prefs.php

Documentation is available at prefs.php

  1. <?php
  2. /**
  3. * prefs.php
  4. *
  5. * This contains functions for filebased user prefs locations
  6. *
  7. * @copyright 1999-2020 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: prefs.php 14840 2020年01月07日 07:42:38Z pdontthink $
  10. * @package squirrelmail
  11. * @subpackage prefs
  12. */
  13. /** Include global.php */
  14. require_once(SM_PATH . 'functions/global.php');
  15. require_once(SM_PATH . 'functions/plugin.php');
  16. /** include this for error messages */
  17. include_once(SM_PATH . 'functions/display_messages.php');
  18. sqgetGlobalVar ('prefs_cache', $prefs_cache, SQ_SESSION );
  19. sqgetGlobalVar ('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
  20. $rg = ini_get ('register_globals');
  21. if ( !sqsession_is_registered ('prefs_are_cached') ||
  22. !isset($prefs_cache) ||
  23. !is_array ($prefs_cache)
  24. ) {
  25. $prefs_are_cached = false;
  26. $prefs_cache = array();
  27. }
  28. $prefs_backend = do_hook_function ('prefs_backend');
  29. if (isset($prefs_backend) && !empty($prefs_backend) && file_exists (SM_PATH . $prefs_backend)) {
  30. require_once(SM_PATH . $prefs_backend);
  31. } elseif (isset($prefs_dsn) && !empty($prefs_dsn)) {
  32. require_once(SM_PATH . 'functions/db_prefs.php');
  33. } else {
  34. require_once(SM_PATH . 'functions/file_prefs.php');
  35. }
  36. /* Hashing functions */
  37. /**
  38. * Given a username and datafilename, this will return the path to the
  39. * hashed location of that datafile.
  40. *
  41. * @param string username the username of the current user
  42. * @param string dir the squirrelmail datadir
  43. * @param string datafile the name of the file to open
  44. * @param bool hash_seach default true
  45. * @return string the hashed location of datafile
  46. */
  47. function getHashedFile ($username, $dir, $datafile, $hash_search = true) {
  48. global $dir_hash_level ;
  49. /* Remove trailing slash from $dir if found */
  50. if (substr ($dir, -1) == '/') {
  51. $dir = substr ($dir, 0, strlen ($dir) - 1);
  52. }
  53. /* Compute the hash for this user and extract the hash directories. */
  54. $hash_dirs = computeHashDirs ($username);
  55. /* First, get and make sure the full hash directory exists. */
  56. $real_hash_dir = getHashedDir ($username, $dir, $hash_dirs);
  57. /* Set the value of our real data file, after we've removed unwanted characters. */
  58. $datafile = str_replace ('/', '_', $datafile);
  59. $result = "$real_hash_dir/$datafile";
  60. /* Check for this file in the real hash directory. */
  61. if ($hash_search && !@file_exists ($result)) {
  62. /* First check the base directory, the most common location. */
  63. if (@file_exists ("$dir/$datafile")) {
  64. rename ("$dir/$datafile", $result);
  65. /* Then check the full range of possible hash directories. */
  66. } else {
  67. $check_hash_dir = $dir;
  68. for ($h = 0; $h < 4; ++$h) {
  69. $check_hash_dir .= '/' . $hash_dirs[$h];
  70. if (@is_readable ("$check_hash_dir/$datafile")) {
  71. rename ("$check_hash_dir/$datafile", $result);
  72. break;
  73. }
  74. }
  75. }
  76. }
  77. /* Return the full hashed datafile path. */
  78. return ($result);
  79. }
  80. /**
  81. * Helper function for getHashedFile(), given a username returns
  82. * the hashed dir for that username.
  83. *
  84. * NOTE that the hashed dir will be created if it doesn't
  85. * already exist.
  86. *
  87. * @param string username the username of the current user
  88. * @param string dir the squirrelmail datadir
  89. * @param string hash_dirs default ''
  90. * @return the path to the hash dir for username
  91. */
  92. function getHashedDir ($username, $dir, $hash_dirs = '') {
  93. global $dir_hash_level ;
  94. /* Remove trailing slash from $dir if found */
  95. if (substr ($dir, -1) == '/') {
  96. $dir = substr ($dir, 0, strlen ($dir) - 1);
  97. }
  98. /* If necessary, populate the hash dir variable. */
  99. if ($hash_dirs == '') {
  100. $hash_dirs = computeHashDirs ($username);
  101. }
  102. /* Make sure the full hash directory exists. */
  103. $real_hash_dir = $dir;
  104. for ($h = 0; $h < $dir_hash_level; ++$h) {
  105. $real_hash_dir .= '/' . $hash_dirs[$h];
  106. if (!@is_dir ($real_hash_dir)) {
  107. if (!@mkdir ($real_hash_dir, 0770)) {
  108. echo sprintf (_ ("Error creating directory %s."), $real_hash_dir) . '<br />' .
  109. _ ("Could not create hashed directory structure!") . "<br />\n" .
  110. _ ("Please contact your system administrator and report this error.") . "<br />\n";
  111. exit;
  112. }
  113. }
  114. }
  115. /* And return that directory. */
  116. return ($real_hash_dir);
  117. }
  118. /**
  119. * Helper function for getHashDir which does the actual hash calculation.
  120. *
  121. * Uses a crc32 algorithm by default, but if you put
  122. * the following in config/config_local.php, you can
  123. * force md5 instead:
  124. * $hash_dirs_use_md5 = TRUE;
  125. *
  126. * You may also specify that if usernames are in full
  127. * email address format, the domain part (beginning
  128. * with "@") be stripped before calculating the crc
  129. * or md5. Do that by putting the following in
  130. * config/config_local.php:
  131. * $hash_dirs_strip_domain = TRUE;
  132. *
  133. * @param string username the username to calculate the hash dir for
  134. *
  135. * @return array a list of hash dirs for this username
  136. *
  137. * @since 1.2.0
  138. *
  139. */
  140. function computeHashDirs ($username) {
  141. global $hash_dirs_use_md5, $hash_dirs_strip_domain;
  142. static $hash_dirs = array();
  143. // strip domain from username
  144. if ($hash_dirs_strip_domain)
  145. $user = substr($username, 0, strpos($username, '@'));
  146. else
  147. $user = $username;
  148. // have we already calculated it?
  149. if (!empty($hash_dirs[$user]))
  150. return $hash_dirs[$user];
  151. if ($hash_dirs_use_md5) {
  152. $hash = md5 ($user);
  153. } else {
  154. /* Compute the hash for this user and extract the hash directories. */
  155. /* Note that the crc32() function result will be different on 32 and */
  156. /* 64 bit systems, thus the hack below. */
  157. $crc = crc32 ($user);
  158. if ($crc & 0x80000000) {
  159. $crc ^= 0xffffffff;
  160. $crc += 1;
  161. }
  162. $hash = base_convert ($crc, 10, 16);
  163. }
  164. $my_hash_dirs = array();
  165. for ($h = 0; $h < 4; ++ $h) {
  166. $my_hash_dirs[] = substr ($hash, $h, 1);
  167. }
  168. // Return our array of hash directories
  169. $hash_dirs[$user] = $my_hash_dirs;
  170. return ($my_hash_dirs);
  171. }

Documentation generated on 2020年1月13日 04:25:10 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /