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