PageRenderTime 23ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/include/utils/security_utils.php

https://github.com/vincentamari/SuperSweetAdmin
PHP | 146 lines | 83 code | 19 blank | 44 comment | 7 complexity | 1fd66ac45eb2d7a812efeff2cab267fc MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, AGPL-3.0, LGPL-2.1
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM 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. * func: query_module_access
  39. * param: $moduleName
  40. *
  41. * returns 1 if user has access to a module, else returns 0
  42. *
  43. */
  44. $modules_exempt_from_availability_check['Activities']='Activities';
  45. $modules_exempt_from_availability_check['History']='History';
  46. $modules_exempt_from_availability_check['Calls']='Calls';
  47. $modules_exempt_from_availability_check['Meetings']='Meetings';
  48. $modules_exempt_from_availability_check['Tasks']='Tasks';
  49. $modules_exempt_from_availability_check['Notes']='Notes';
  50. $modules_exempt_from_availability_check['CampaignLog']='CampaignLog';
  51. $modules_exempt_from_availability_check['CampaignTrackers']='CampaignTrackers';
  52. $modules_exempt_from_availability_check['Prospects']='Prospects';
  53. $modules_exempt_from_availability_check['ProspectLists']='ProspectLists';
  54. $modules_exempt_from_availability_check['EmailMarketing']='EmailMarketing';
  55. $modules_exempt_from_availability_check['EmailMan']='EmailMan';
  56. $modules_exempt_from_availability_check['ProjectTask']='ProjectTask';
  57. $modules_exempt_from_availability_check['Users']='Users';
  58. $modules_exempt_from_availability_check['Teams']='Teams';
  59. $modules_exempt_from_availability_check['SchedulersJobs']='SchedulersJobs';
  60. $modules_exempt_from_availability_check['DocumentRevisions']='DocumentRevisions';
  61. function query_module_access_list(&$user)
  62. {
  63. require_once('modules/MySettings/TabController.php');
  64. $controller = new TabController();
  65. $tabArray = $controller->get_tabs($user);
  66. return $tabArray[0];
  67. }
  68. function query_user_has_roles($user_id)
  69. {
  70. $role = new Role();
  71. return $role->check_user_role_count($user_id);
  72. }
  73. function get_user_allowed_modules($user_id)
  74. {
  75. $role = new Role();
  76. $allowed = $role->query_user_allowed_modules($user_id);
  77. return $allowed;
  78. }
  79. function get_user_disallowed_modules($user_id, &$allowed)
  80. {
  81. $role = new Role();
  82. $disallowed = $role->query_user_disallowed_modules($user_id, $allowed);
  83. return $disallowed;
  84. }
  85. // grabs client ip address and returns its value
  86. function query_client_ip()
  87. {
  88. global $_SERVER;
  89. $clientIP = false;
  90. if(!empty($GLOBALS['sugar_config']['ip_variable']) && !empty($_SERVER[$GLOBALS['sugar_config']['ip_variable']])){
  91. $clientIP = $_SERVER[$GLOBALS['sugar_config']['ip_variable']];
  92. }else if(isset($_SERVER['HTTP_CLIENT_IP']))
  93. {
  94. $clientIP = $_SERVER['HTTP_CLIENT_IP'];
  95. }
  96. 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))
  97. {
  98. // check for internal ips by looking at the first octet
  99. foreach($matches[0] AS $ip)
  100. {
  101. if(!preg_match("#^(10|172\.16|192\.168)\.#", $ip))
  102. {
  103. $clientIP = $ip;
  104. break;
  105. }
  106. }
  107. }
  108. elseif(isset($_SERVER['HTTP_FROM']))
  109. {
  110. $clientIP = $_SERVER['HTTP_FROM'];
  111. }
  112. else
  113. {
  114. $clientIP = $_SERVER['REMOTE_ADDR'];
  115. }
  116. return $clientIP;
  117. }
  118. // sets value to key value
  119. function get_val_array($arr){
  120. $new = array();
  121. if(!empty($arr)){
  122. foreach($arr as $key=>$val){
  123. $new[$key] = $key;
  124. }
  125. }
  126. return $new;
  127. }