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