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