]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/utils/security_utils.php
Release 6.5.0
[Github/sugarcrm.git] / include / utils / security_utils.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 /* 
40  * func: query_module_access 
41  * param: $moduleName
42  * 
43  * returns 1 if user has access to a module, else returns 0
44  * 
45  */
46
47 $modules_exempt_from_availability_check['Activities']='Activities';
48 $modules_exempt_from_availability_check['History']='History';
49 $modules_exempt_from_availability_check['Calls']='Calls';
50 $modules_exempt_from_availability_check['Meetings']='Meetings';
51 $modules_exempt_from_availability_check['Tasks']='Tasks';
52 $modules_exempt_from_availability_check['Notes']='Notes';
53
54 $modules_exempt_from_availability_check['CampaignLog']='CampaignLog';
55 $modules_exempt_from_availability_check['CampaignTrackers']='CampaignTrackers';
56 $modules_exempt_from_availability_check['Prospects']='Prospects';
57 $modules_exempt_from_availability_check['ProspectLists']='ProspectLists';
58 $modules_exempt_from_availability_check['EmailMarketing']='EmailMarketing';
59 $modules_exempt_from_availability_check['EmailMan']='EmailMan';
60 $modules_exempt_from_availability_check['ProjectTask']='ProjectTask';
61 $modules_exempt_from_availability_check['Users']='Users';
62 $modules_exempt_from_availability_check['Teams']='Teams';
63 $modules_exempt_from_availability_check['SchedulersJobs']='SchedulersJobs';
64 $modules_exempt_from_availability_check['DocumentRevisions']='DocumentRevisions';
65 function query_module_access_list(&$user)
66 {
67         require_once('modules/MySettings/TabController.php');
68         $controller = new TabController();
69         $tabArray = $controller->get_tabs($user); 
70
71         return $tabArray[0];
72                 
73 }
74
75 function query_user_has_roles($user_id)
76 {
77         
78         
79         $role = new Role();
80         
81         return $role->check_user_role_count($user_id);
82 }
83
84 function get_user_allowed_modules($user_id)
85 {
86         
87
88         $role = new Role();
89         
90         $allowed = $role->query_user_allowed_modules($user_id);
91         return $allowed;
92 }
93
94 function get_user_disallowed_modules($user_id, &$allowed)
95 {
96         
97
98         $role = new Role();
99         $disallowed = $role->query_user_disallowed_modules($user_id, $allowed);
100         return $disallowed;
101 }
102 // grabs client ip address and returns its value
103 function query_client_ip()
104 {
105         global $_SERVER;
106         $clientIP = false;
107         if(!empty($GLOBALS['sugar_config']['ip_variable']) && !empty($_SERVER[$GLOBALS['sugar_config']['ip_variable']])){
108                 $clientIP = $_SERVER[$GLOBALS['sugar_config']['ip_variable']];
109         }else if(isset($_SERVER['HTTP_CLIENT_IP']))
110         {
111                 $clientIP = $_SERVER['HTTP_CLIENT_IP'];
112         }
113         elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches))
114         {
115                 // check for internal ips by looking at the first octet
116                 foreach($matches[0] AS $ip)
117                 {
118                         if(!preg_match("#^(10|172\.16|192\.168)\.#", $ip))
119                         {
120                                 $clientIP = $ip;
121                                 break;
122                         }
123                 }
124
125         }
126         elseif(isset($_SERVER['HTTP_FROM']))
127         {
128                 $clientIP = $_SERVER['HTTP_FROM'];
129         }
130         else
131         {
132                 $clientIP = $_SERVER['REMOTE_ADDR'];
133         }
134         return $clientIP;
135 }
136
137 // sets value to key value
138 function get_val_array($arr){
139         $new = array();
140         if(!empty($arr)){
141         foreach($arr as $key=>$val){
142                 $new[$key] = $key;
143         }
144         }
145         return $new;
146 }
147