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 | */ |
24afb0e9 |
16 | if ((isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) || |
17 | (isset($HTTP_SERVER_SERVER['SCRIPT_FILENAME']) && $HTTP_SERVER_SERVER['SCRIPT_FILENAME'] == __FILE__) ) { |
202bcbcc |
18 | header("Location: ../../src/login.php"); |
19 | die(); |
20 | } |
c64dbf73 |
21 | |
2329d86d |
22 | /** Declare plugin configuration vars */ |
23 | global $bug_report_admin_email, $bug_report_allow_users; |
c64dbf73 |
24 | |
2329d86d |
25 | /** Load default config */ |
26 | if (file_exists(SM_PATH . 'plugins/bug_report/config_default.php')) { |
27 | include_once (SM_PATH . 'plugins/bug_report/config_default.php'); |
28 | } else { |
29 | // default config was removed. |
30 | $bug_report_admin_email = ''; |
31 | $bug_report_allow_users = false; |
32 | } |
c64dbf73 |
33 | |
2329d86d |
34 | /** Load site config */ |
35 | if (file_exists(SM_PATH . 'config/bug_report_config.php')) { |
36 | include_once (SM_PATH . 'config/bug_report_config.php'); |
37 | } elseif (file_exists(SM_PATH . 'plugins/bug_report/config.php')) { |
38 | include_once (SM_PATH . 'plugins/bug_report/config.php'); |
c64dbf73 |
39 | } |
40 | |
41 | /** |
2329d86d |
42 | * Checks if user can use bug_report plugin |
43 | * @return boolean |
44 | * @since 1.5.1 |
c64dbf73 |
45 | */ |
2329d86d |
46 | function bug_report_check_user() { |
47 | global $username, $bug_report_allow_users, $bug_report_admin_email; |
c64dbf73 |
48 | |
2329d86d |
49 | if (file_exists(SM_PATH . 'plugins/bug_report/admins')) { |
50 | $auths = file(SM_PATH . 'plugins/bug_report/admins'); |
51 | array_walk($auths, 'bug_report_array_trim'); |
52 | $auth = in_array($username, $auths); |
53 | } else if (file_exists(SM_PATH . 'config/admins')) { |
54 | $auths = file(SM_PATH . 'config/admins'); |
55 | array_walk($auths, 'bug_report_array_trim'); |
56 | $auth = in_array($username, $auths); |
57 | } else if (($adm_id = fileowner(SM_PATH . 'config/config.php')) && |
58 | function_exists('posix_getpwuid')) { |
59 | $adm = posix_getpwuid( $adm_id ); |
60 | $auth = ($username == $adm['name']); |
61 | } else { |
62 | $auth = false; |
63 | } |
c64dbf73 |
64 | |
2329d86d |
65 | if (! empty($bug_report_admin_email) && $bug_report_allow_users) { |
66 | $auth = true; |
67 | } |
c64dbf73 |
68 | |
2329d86d |
69 | return ($auth); |
70 | } |
c64dbf73 |
71 | |
2329d86d |
72 | /** |
73 | * Removes whitespace from array values |
74 | * @param string $value array value that has to be trimmed |
75 | * @param string $key array key |
76 | * @since 1.5.1 |
77 | * @todo code reuse. create generic sm function. |
78 | * @access private |
79 | */ |
80 | function bug_report_array_trim(&$value,$key) { |
81 | $value=trim($value); |
c64dbf73 |
82 | } |