auth.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 $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 (!defined('PAGE_NAME') || strpos(PAGE_NAME, 'options') === FALSE) {
  31. if (!defined('PAGE_NAME')
  32. || (PAGE_NAME != 'administrator_options' && PAGE_NAME != 'options')) {
  33. $auth = FALSE;
  34. } else if (file_exists(SM_PATH . 'plugins/administrator/admins')) {
  35. $auths = file(SM_PATH . 'plugins/administrator/admins');
  36. array_walk($auths, 'adm_array_trim');
  37. $auth = in_array($username, $auths);
  38. } else if (file_exists(SM_PATH . 'config/admins')) {
  39. $auths = file(SM_PATH . 'config/admins');
  40. array_walk($auths, 'adm_array_trim');
  41. $auth = in_array($username, $auths);
  42. } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) &&
  43. function_exists('posix_getpwuid')) {
  44. $adm = posix_getpwuid( $adm_id );
  45. $auth = ($username == $adm['name']);
  46. } else {
  47. $auth = FALSE;
  48. }
  49. return ($auth);
  50. }
  51. /**
  52. * Removes whitespace from array values
  53. * @param string $value array value that has to be trimmed
  54. * @param string $key array key
  55. * @since 1.5.1 and 1.4.5
  56. * @access private
  57. */
  58. function adm_array_trim(&$value,$key) {
  59. $value=trim($value);
  60. }