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