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 |
c4faef33 |
10 | * @copyright 1999-2020 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 |
22 | function adm_check_user() { |
a6f162eb |
23 | global $plugins; |
91e0dccc |
24 | |
4c80d233 |
25 | /* fail if the plugin is not enabled */ |
26 | if ( !in_array('administrator', $plugins) ) { |
27 | return FALSE; |
28 | } |
29 | |
4cd8ae7d |
30 | if ( !sqgetGlobalVar('username',$username,SQ_SESSION) ) { |
31 | $username = ''; |
32 | } |
33 | |
a28a56da |
34 | /* This needs to be first, for all non_options pages */ |
14f55202 |
35 | //if (!defined('PAGE_NAME') || strpos(PAGE_NAME, 'options') === FALSE) { |
36 | if (!defined('PAGE_NAME') |
37 | || (PAGE_NAME != 'administrator_options' && PAGE_NAME != 'options')) { |
71bf4974 |
38 | $auth = FALSE; |
52a6105d |
39 | } else if (file_exists(SM_PATH . 'plugins/administrator/admins')) { |
40 | $auths = file(SM_PATH . 'plugins/administrator/admins'); |
0a577181 |
41 | array_walk($auths, 'adm_array_trim'); |
daa192a8 |
42 | $auth = in_array($username, $auths); |
52a6105d |
43 | } else if (file_exists(SM_PATH . 'config/admins')) { |
44 | $auths = file(SM_PATH . 'config/admins'); |
0a577181 |
45 | array_walk($auths, 'adm_array_trim'); |
daa192a8 |
46 | $auth = in_array($username, $auths); |
ec4584f9 |
47 | } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) && |
a9ccc40c |
48 | function_exists('posix_getpwuid')) { |
7004cc32 |
49 | $adm = posix_getpwuid( $adm_id ); |
52a6105d |
50 | $auth = ($username == $adm['name']); |
51 | } else { |
a82293f6 |
52 | $auth = FALSE; |
53 | } |
7004cc32 |
54 | |
52a6105d |
55 | return ($auth); |
7004cc32 |
56 | } |
57 | |
0a577181 |
58 | /** |
59 | * Removes whitespace from array values |
60 | * @param string $value array value that has to be trimmed |
61 | * @param string $key array key |
63ed9ceb |
62 | * @since 1.5.1 and 1.4.5 |
63 | * @access private |
0a577181 |
64 | */ |
65 | function adm_array_trim(&$value,$key) { |
66 | $value=trim($value); |
67 | } |