]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/utils/security_utils.php
Release 6.2.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-2011 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 $modules_exempt_from_availability_check['CampaignLog']='CampaignLog';
54 $modules_exempt_from_availability_check['CampaignTrackers']='CampaignTrackers';
55 $modules_exempt_from_availability_check['Prospects']='Prospects';
56 $modules_exempt_from_availability_check['ProspectLists']='ProspectLists';
57 $modules_exempt_from_availability_check['EmailMarketing']='EmailMarketing';
58 $modules_exempt_from_availability_check['EmailMan']='EmailMan';
59 $modules_exempt_from_availability_check['ProjectTask']='ProjectTask';
60 $modules_exempt_from_availability_check['Users']='Users';
61 $modules_exempt_from_availability_check['Teams']='Teams';
62 $modules_exempt_from_availability_check['SchedulersJobs']='SchedulersJobs';
63 $modules_exempt_from_availability_check['DocumentRevisions']='DocumentRevisions';
64 function query_module_access_list(&$user)
65 {
66         require_once('modules/MySettings/TabController.php');
67         $controller = new TabController();
68         $tabArray = $controller->get_tabs($user); 
69
70         return $tabArray[0];
71                 
72 }
73
74 function query_user_has_roles($user_id)
75 {
76         
77         
78         $role = new Role();
79         
80         return $role->check_user_role_count($user_id);
81 }
82
83 function get_user_allowed_modules($user_id)
84 {
85         
86
87         $role = new Role();
88         
89         $allowed = $role->query_user_allowed_modules($user_id);
90         return $allowed;
91 }
92
93 function get_user_disallowed_modules($user_id, &$allowed)
94 {
95         
96
97         $role = new Role();
98         $disallowed = $role->query_user_disallowed_modules($user_id, $allowed);
99         return $disallowed;
100 }
101 // grabs client ip address and returns its value
102 function query_client_ip()
103 {
104         global $_SERVER;
105         $clientIP = false;
106         if(!empty($GLOBALS['sugar_config']['ip_variable']) && !empty($_SERVER[$GLOBALS['sugar_config']['ip_variable']])){
107                 $clientIP = $_SERVER[$GLOBALS['sugar_config']['ip_variable']];
108         }else if(isset($_SERVER['HTTP_CLIENT_IP']))
109         {
110                 $clientIP = $_SERVER['HTTP_CLIENT_IP'];
111         }
112         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))
113         {
114                 // check for internal ips by looking at the first octet
115                 foreach($matches[0] AS $ip)
116                 {
117                         if(!preg_match("#^(10|172\.16|192\.168)\.#", $ip))
118                         {
119                                 $clientIP = $ip;
120                                 break;
121                         }
122                 }
123
124         }
125         elseif(isset($_SERVER['HTTP_FROM']))
126         {
127                 $clientIP = $_SERVER['HTTP_FROM'];
128         }
129         else
130         {
131                 $clientIP = $_SERVER['REMOTE_ADDR'];
132         }
133         return $clientIP;
134 }
135
136 // sets value to key value
137 function get_val_array($arr){
138         $new = array();
139         if(!empty($arr)){
140         foreach($arr as $key=>$val){
141                 $new[$key] = $key;
142         }
143         }
144         return $new;
145 }
146