c64dbf73 |
1 | <?php |
2 | /** |
3 | * functions for bug_report plugin |
4 | * |
4b5049de |
5 | * @copyright © 2004-2007 The SquirrelMail Project Team |
c64dbf73 |
6 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
7 | * @version $Id$ |
8 | * @package plugins |
9 | * @subpackage bug_report |
10 | */ |
11 | |
202bcbcc |
12 | |
13 | /** |
14 | * do not allow to call this file directly |
15 | */ |
f627180c |
16 | if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) { |
202bcbcc |
17 | header("Location: ../../src/login.php"); |
18 | die(); |
19 | } |
c64dbf73 |
20 | |
2329d86d |
21 | /** Declare plugin configuration vars */ |
22 | global $bug_report_admin_email, $bug_report_allow_users; |
c64dbf73 |
23 | |
2329d86d |
24 | /** Load default config */ |
25 | if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) { |
26 | include_once (SM_PATH . 'plugins/bug_report/config_default.php'); |
27 | } else { |
28 | // default config was removed. |
29 | $bug_report_admin_email = ''; |
30 | $bug_report_allow_users = false; |
31 | } |
c64dbf73 |
32 | |
2329d86d |
33 | /** Load site config */ |
34 | if (file_exists(SM_PATH . 'config/bug_report_config.php')) { |
35 | include_once (SM_PATH . 'config/bug_report_config.php'); |
36 | } elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) { |
37 | include_once (SM_PATH . 'plugins/bug_report/config.php'); |
c64dbf73 |
38 | } |
39 | |
40 | /** |
2329d86d |
41 | * Checks if user can use bug_report plugin |
42 | * @return boolean |
43 | * @since 1.5.1 |
c64dbf73 |
44 | */ |
2329d86d |
45 | function bug_report_check_user() { |
46 | global $username, $bug_report_allow_users, $bug_report_admin_email; |
c64dbf73 |
47 | |
2329d86d |
48 | if (file_exists(SM_PATH . 'plugins/bug_report/admins')) { |
49 | $auths = file(SM_PATH . 'plugins/bug_report/admins'); |
50 | array_walk($auths, 'bug_report_array_trim'); |
51 | $auth = in_array($username, $auths); |
52 | } else if (file_exists(SM_PATH . 'config/admins')) { |
53 | $auths = file(SM_PATH . 'config/admins'); |
54 | array_walk($auths, 'bug_report_array_trim'); |
55 | $auth = in_array($username, $auths); |
56 | } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) && |
57 | function_exists('posix_getpwuid')) { |
58 | $adm = posix_getpwuid( $adm_id ); |
59 | $auth = ($username == $adm['name']); |
60 | } else { |
61 | $auth = false; |
62 | } |
c64dbf73 |
63 | |
2329d86d |
64 | if (! empty($bug_report_admin_email) && $bug_report_allow_users) { |
65 | $auth = true; |
66 | } |
c64dbf73 |
67 | |
2329d86d |
68 | return ($auth); |
69 | } |
c64dbf73 |
70 | |
2329d86d |
71 | /** |
72 | * Removes whitespace from array values |
73 | * @param string $value array value that has to be trimmed |
74 | * @param string $key array key |
75 | * @since 1.5.1 |
76 | * @todo code reuse. create generic sm function. |
77 | * @access private |
78 | */ |
79 | function bug_report_array_trim(&$value,$key) { |
80 | $value=trim($value); |
c64dbf73 |
81 | } |