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.
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.
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
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
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.
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.
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 ********************************************************************************/
45 var $allow_undefined = array ('stack_trace_errors', 'export_delimiter', 'use_real_names', 'developerMode', 'default_module_favicon', 'authenticationClass', 'SAML_loginurl', 'SAML_X509Cert');
46 var $errors = array ('main' => '');
48 var $previous_sugar_override_config_array = array();
49 var $useAuthenticationClass = false;
51 function Configurator() {
55 function loadConfig() {
56 $this->logger = LoggerManager::getLogger();
58 $this->config = $sugar_config;
61 function populateFromPost() {
62 $sugarConfig = SugarConfig::getInstance();
63 foreach ($_POST as $key => $value) {
64 if (isset ($this->config[$key]) || in_array($key, $this->allow_undefined)) {
65 if (strcmp("$value", 'true') == 0) {
68 if (strcmp("$value", 'false') == 0) {
71 $this->config[$key] = $value;
73 $v = $sugarConfig->get(str_replace('_', '.', $key));
75 setDeepArrayValue($this->config, $key, $value);
81 function handleOverride($fromParseLoggerSettings=false) {
82 global $sugar_config, $sugar_version;
83 $sc = SugarConfig::getInstance();
84 $overrideArray = $this->readOverride();
85 $this->previous_sugar_override_config_array = $overrideArray;
86 $diffArray = deepArrayDiff($this->config, $sugar_config);
87 $overrideArray = sugarArrayMergeRecursive($overrideArray, $diffArray);
89 // To remember checkbox state
90 if (!$this->useAuthenticationClass && !$fromParseLoggerSettings) {
91 if (isset($overrideArray['authenticationClass']) &&
92 $overrideArray['authenticationClass'] == 'SAMLAuthenticate') {
93 unset($overrideArray['authenticationClass']);
97 $overideString = "<?php\n/***CONFIGURATOR***/\n";
99 sugar_cache_put('sugar_config', $this->config);
100 $GLOBALS['sugar_config'] = $this->config;
102 //print_r($overrideArray);
104 foreach($overrideArray as $key => $val) {
105 if (in_array($key, $this->allow_undefined) || isset ($sugar_config[$key])) {
106 if (strcmp("$val", 'true') == 0) {
108 $this->config[$key] = $val;
110 if (strcmp("$val", 'false') == 0) {
112 $this->config[$key] = false;
115 $overideString .= override_value_to_string_recursive2('sugar_config', $key, $val);
117 $overideString .= '/***CONFIGURATOR***/';
119 $this->saveOverride($overideString);
120 if(isset($this->config['logger']['level']) && $this->logger) $this->logger->setLevel($this->config['logger']['level']);
123 //bug #27947 , if previous $sugar_config['stack_trace_errors'] is true and now we disable it , we should clear all the cache.
124 function clearCache(){
125 global $sugar_config, $sugar_version;
126 $currentConfigArray = $this->readOverride();
127 foreach($currentConfigArray as $key => $val) {
128 if (in_array($key, $this->allow_undefined) || isset ($sugar_config[$key])) {
130 if(!empty($this->previous_sugar_override_config_array['stack_trace_errors']) && $key == 'stack_trace_errors'){
131 require_once('include/TemplateHandler/TemplateHandler.php');
132 TemplateHandler::clearAll();
140 function saveConfig() {
142 $this->populateFromPost();
143 $this->handleOverride();
147 function readOverride() {
148 $sugar_config = array();
149 if (file_exists('config_override.php')) {
150 include('config_override.php');
152 return $sugar_config;
154 function saveOverride($override) {
155 $fp = sugar_fopen('config_override.php', 'w');
156 fwrite($fp, $override);
160 function overrideClearDuplicates($array_name, $key) {
161 if (!empty ($this->override)) {
162 $pattern = '/.*CONFIGURATOR[^\$]*\$'.$array_name.'\[\''.$key.'\'\][\ ]*=[\ ]*[^;]*;\n/';
163 $this->override = preg_replace($pattern, '', $this->override);
165 $this->override = "<?php\n\n?>";
170 function replaceOverride($array_name, $key, $value) {
171 $GLOBALS[$array_name][$key] = $value;
172 $this->overrideClearDuplicates($array_name, $key);
173 $new_entry = '/***CONFIGURATOR***/'.override_value_to_string($array_name, $key, $value);
174 $this->override = str_replace('?>', "$new_entry\n?>", $this->override);
177 function restoreConfig() {
178 $this->readOverride();
179 $this->overrideClearDuplicates('sugar_config', '[a-zA-Z0-9\_]+');
180 $this->saveOverride();
182 header('Location: index.php?action=EditView&module=Configurator');
185 function saveImages() {
186 if (!empty ($_POST['company_logo'])) {
187 $this->saveCompanyLogo($_POST['company_logo']);
191 function checkTempImage($path)
193 if(!verify_uploaded_image($path)) {
194 $GLOBALS['log']->fatal("A user ({$GLOBALS['current_user']->id}) attempted to use an invalid file for the logo - {$path}");
195 sugar_die('Invalid File Type');
200 * Saves the company logo to the custom directory for the default theme, so all themes can use it
202 * @param string $path path to the image to set as the company logo image
204 function saveCompanyLogo($path)
206 $path = $this->checkTempImage($path);
207 mkdir_recursive('custom/'.SugarThemeRegistry::current()->getDefaultImagePath(), true);
208 copy($path,'custom/'. SugarThemeRegistry::current()->getDefaultImagePath(). '/company_logo.png');
209 sugar_cache_clear('company_logo_attributes');
210 SugarThemeRegistry::clearAllCaches();
214 * @return : An array of logger configuration properties including log size, file extensions etc. See SugarLogger for more details.
215 * Parses the old logger settings from the log4php.properties files.
219 function parseLoggerSettings(){
220 if(!function_exists('setDeepArrayValue')){
221 require('include/utils/array_utils.php');
223 if (file_exists('log4php.properties')) {
224 $fileContent = file_get_contents('log4php.properties');
225 $old_props = explode('\n', $fileContent);
226 $new_props = array();
228 foreach($old_props as $value) {
229 if(!empty($value) && !preg_match("/^\/\//", $value)) {
230 $temp = explode("=",$value);
231 $property = isset( $temp[1])? $temp[1] : array();
232 if(preg_match("/log4php.appender.A2.MaxFileSize=/",$value)){
233 setDeepArrayValue($this->config, 'logger_file_maxSize', rtrim( $property));
235 elseif(preg_match("/log4php.appender.A2.File=/", $value)){
236 $ext = preg_split("/\./",$property);
237 if(preg_match( "/^\./", $property)){ //begins with .
238 setDeepArrayValue($this->config, 'logger_file_ext', isset($ext[2]) ? '.' . rtrim( $ext[2]):'.log');
239 setDeepArrayValue($this->config, 'logger_file_name', rtrim( ".".$ext[1]));
241 setDeepArrayValue($this->config, 'logger_file_ext', isset($ext[1]) ? '.' . rtrim( $ext[1]):'.log');
242 setDeepArrayValue($this->config, 'logger_file_name', rtrim( $ext[0] ));
244 }elseif(preg_match("/log4php.appender.A2.layout.DateFormat=/",$value)){
245 setDeepArrayValue($this->config, 'logger_file_dateFormat', trim(rtrim( $property), '""'));
247 }elseif(preg_match("/log4php.rootLogger=/",$value)){
248 $property = explode(",",$property);
249 setDeepArrayValue($this->config, 'logger_level', rtrim( $property[0]));
253 setDeepArrayValue($this->config, 'logger_file_maxLogs', 10);
254 setDeepArrayValue($this->config, 'logger_file_suffix', "%m_%Y");
255 $this->handleOverride();
256 unlink('log4php.properties');
257 $GLOBALS['sugar_config'] = $this->config; //load the rest of the sugar_config settings.
258 require_once('include/SugarLogger/SugarLogger.php');
259 //$logger = new SugarLogger(); //this will create the log file.
263 if (!isset($this->config['logger']) || empty($this->config['logger'])) {
264 $this->config['logger'] = array (
267 'name' => 'sugarcrm',
268 'dateFormat' => '%c',
271 'suffix' => '%m_%Y'),
274 $this->handleOverride(true);