auth.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Administrator plugin - Authentication routines
  4. *
  5. * This function tell other modules what users have access
  6. * to the plugin.
  7. *
  8. * @author Philippe Mingo
  9. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  10. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11. * @version $Id$
  12. * @package plugins
  13. * @subpackage administrator
  14. */
  15. /**
  16. * Check if user has access to administrative functions
  17. *
  18. * @return boolean
  19. */
  20. function adm_check_user() {
  21. global $PHP_SELF, $plugins;
  22. /* fail if the plugin is not enabled */
  23. if ( !in_array('administrator', $plugins) ) {
  24. return FALSE;
  25. }
  26. if ( !sqgetGlobalVar('username',$username,SQ_SESSION) ) {
  27. $username = '';
  28. }
  29. /* This needs to be first, for all non_options pages */
  30. if (strpos('options.php', $PHP_SELF)) {
  31. $auth = FALSE;
  32. } else if (file_exists(SM_PATH . 'plugins/administrator/admins')) {
  33. $auths = file(SM_PATH . 'plugins/administrator/admins');
  34. array_walk($auths, 'adm_array_trim');
  35. $auth = in_array($username, $auths);
  36. } else if (file_exists(SM_PATH . 'config/admins')) {
  37. $auths = file(SM_PATH . 'config/admins');
  38. array_walk($auths, 'adm_array_trim');
  39. $auth = in_array($username, $auths);
  40. } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) &&
  41. function_exists('posix_getpwuid')) {
  42. $adm = posix_getpwuid( $adm_id );
  43. $auth = ($username == $adm['name']);
  44. } else {
  45. $auth = FALSE;
  46. }
  47. return ($auth);
  48. }
  49. /**
  50. * Removes whitespace from array values
  51. * @param string $value array value that has to be trimmed
  52. * @param string $key array key
  53. * @since 1.5.1 and 1.4.5
  54. * @access private
  55. */
  56. function adm_array_trim(&$value,$key) {
  57. $value=trim($value);
  58. }