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.
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', 'dashlet_auto_refresh_min', 'show_download_tab', 'enable_action_menu');
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 ($key == "logger_file_ext") {
65 $trim_value = preg_replace('/.*\.([^\.]+)$/', '\1', $value);
66 if(in_array($trim_value, $this->config['upload_badext'])) {
67 $GLOBALS['log']->security("Invalid log file extension: trying to use invalid file extension '$value'.");
71 if (isset ($this->config[$key]) || in_array($key, $this->allow_undefined)) {
72 if (strcmp("$value", 'true') == 0) {
75 if (strcmp("$value", 'false') == 0) {
78 $this->config[$key] = $value;
80 $v = $sugarConfig->get(str_replace('_', '.', $key));
82 setDeepArrayValue($this->config, $key, $value);
89 function handleOverride($fromParseLoggerSettings=false) {
90 global $sugar_config, $sugar_version;
91 $sc = SugarConfig::getInstance();
92 $overrideArray = $this->readOverride();
93 $this->previous_sugar_override_config_array = $overrideArray;
94 $diffArray = deepArrayDiff($this->config, $sugar_config);
95 $overrideArray = sugarArrayMergeRecursive($overrideArray, $diffArray);
97 // To remember checkbox state
98 if (!$this->useAuthenticationClass && !$fromParseLoggerSettings) {
99 if (isset($overrideArray['authenticationClass']) &&
100 $overrideArray['authenticationClass'] == 'SAMLAuthenticate') {
101 unset($overrideArray['authenticationClass']);
105 $overideString = "<?php\n/***CONFIGURATOR***/\n";
107 sugar_cache_put('sugar_config', $this->config);
108 $GLOBALS['sugar_config'] = $this->config;
110 //print_r($overrideArray);
111 //Bug#53013: Clean the tpl cache if action menu style has been changed.
112 if( isset($overrideArray['enable_action_menu']) &&
113 ( !isset($this->previous_sugar_override_config_array['enable_action_menu']) ||
114 $overrideArray['enable_action_menu'] != $this->previous_sugar_override_config_array['enable_action_menu'] )
116 require_once('modules/Administration/QuickRepairAndRebuild.php');
117 $repair = new RepairAndClear;
118 $repair->module_list = array();
119 $repair->clearTpls();
122 foreach($overrideArray as $key => $val) {
123 if (in_array($key, $this->allow_undefined) || isset ($sugar_config[$key])) {
124 if (is_string($val) && strcmp($val, 'true') == 0) {
126 $this->config[$key] = $val;
128 if (is_string($val) && strcmp($val, 'false') == 0) {
130 $this->config[$key] = false;
133 $overideString .= override_value_to_string_recursive2('sugar_config', $key, $val);
135 $overideString .= '/***CONFIGURATOR***/';
137 $this->saveOverride($overideString);
138 if(isset($this->config['logger']['level']) && $this->logger) $this->logger->setLevel($this->config['logger']['level']);
141 //bug #27947 , if previous $sugar_config['stack_trace_errors'] is true and now we disable it , we should clear all the cache.
142 function clearCache(){
143 global $sugar_config, $sugar_version;
144 $currentConfigArray = $this->readOverride();
145 foreach($currentConfigArray as $key => $val) {
146 if (in_array($key, $this->allow_undefined) || isset ($sugar_config[$key])) {
148 if(!empty($this->previous_sugar_override_config_array['stack_trace_errors']) && $key == 'stack_trace_errors'){
149 require_once('include/TemplateHandler/TemplateHandler.php');
150 TemplateHandler::clearAll();
158 function saveConfig() {
160 $this->populateFromPost();
161 $this->handleOverride();
165 function readOverride() {
166 $sugar_config = array();
167 if (file_exists('config_override.php')) {
168 if ( !is_readable('config_override.php') ) {
169 $GLOBALS['log']->fatal("Unable to read the config_override.php file. Check the file permissions");
172 include('config_override.php');
175 return $sugar_config;
177 function saveOverride($override) {
178 require_once('install/install_utils.php');
179 if ( !file_exists('config_override.php') ) {
180 touch('config_override.php');
182 if ( !(make_writable('config_override.php')) || !(is_writable('config_override.php')) ) {
183 $GLOBALS['log']->fatal("Unable to write to the config_override.php file. Check the file permissions");
186 $fp = sugar_fopen('config_override.php', 'w');
187 fwrite($fp, $override);
191 function overrideClearDuplicates($array_name, $key) {
192 if (!empty ($this->override)) {
193 $pattern = '/.*CONFIGURATOR[^\$]*\$'.$array_name.'\[\''.$key.'\'\][\ ]*=[\ ]*[^;]*;\n/';
194 $this->override = preg_replace($pattern, '', $this->override);
196 $this->override = "<?php\n\n?>";
201 function replaceOverride($array_name, $key, $value) {
202 $GLOBALS[$array_name][$key] = $value;
203 $this->overrideClearDuplicates($array_name, $key);
204 $new_entry = '/***CONFIGURATOR***/'.override_value_to_string($array_name, $key, $value);
205 $this->override = str_replace('?>', "$new_entry\n?>", $this->override);
208 function restoreConfig() {
209 $this->readOverride();
210 $this->overrideClearDuplicates('sugar_config', '[a-zA-Z0-9\_]+');
211 $this->saveOverride();
213 header('Location: index.php?action=EditView&module=Configurator');
216 function saveImages() {
217 if (!empty ($_POST['company_logo'])) {
218 $this->saveCompanyLogo("upload://".$_POST['company_logo']);
222 function checkTempImage($path)
224 if(!verify_uploaded_image($path)) {
225 $GLOBALS['log']->fatal("A user ({$GLOBALS['current_user']->id}) attempted to use an invalid file for the logo - {$path}");
226 sugar_die('Invalid File Type');
231 * Saves the company logo to the custom directory for the default theme, so all themes can use it
233 * @param string $path path to the image to set as the company logo image
235 function saveCompanyLogo($path)
237 $path = $this->checkTempImage($path);
238 mkdir_recursive('custom/'.SugarThemeRegistry::current()->getDefaultImagePath(), true);
239 copy($path,'custom/'. SugarThemeRegistry::current()->getDefaultImagePath(). '/company_logo.png');
240 sugar_cache_clear('company_logo_attributes');
241 SugarThemeRegistry::clearAllCaches();
245 * @return : An array of logger configuration properties including log size, file extensions etc. See SugarLogger for more details.
246 * Parses the old logger settings from the log4php.properties files.
250 function parseLoggerSettings(){
251 if(!function_exists('setDeepArrayValue')){
252 require('include/utils/array_utils.php');
254 if (file_exists('log4php.properties')) {
255 $fileContent = file_get_contents('log4php.properties');
256 $old_props = explode('\n', $fileContent);
257 $new_props = array();
259 foreach($old_props as $value) {
260 if(!empty($value) && !preg_match("/^\/\//", $value)) {
261 $temp = explode("=",$value);
262 $property = isset( $temp[1])? $temp[1] : array();
263 if(preg_match("/log4php.appender.A2.MaxFileSize=/",$value)){
264 setDeepArrayValue($this->config, 'logger_file_maxSize', rtrim( $property));
266 elseif(preg_match("/log4php.appender.A2.File=/", $value)){
267 $ext = preg_split("/\./",$property);
268 if(preg_match( "/^\./", $property)){ //begins with .
269 setDeepArrayValue($this->config, 'logger_file_ext', isset($ext[2]) ? '.' . rtrim( $ext[2]):'.log');
270 setDeepArrayValue($this->config, 'logger_file_name', rtrim( ".".$ext[1]));
272 setDeepArrayValue($this->config, 'logger_file_ext', isset($ext[1]) ? '.' . rtrim( $ext[1]):'.log');
273 setDeepArrayValue($this->config, 'logger_file_name', rtrim( $ext[0] ));
275 }elseif(preg_match("/log4php.appender.A2.layout.DateFormat=/",$value)){
276 setDeepArrayValue($this->config, 'logger_file_dateFormat', trim(rtrim( $property), '""'));
278 }elseif(preg_match("/log4php.rootLogger=/",$value)){
279 $property = explode(",",$property);
280 setDeepArrayValue($this->config, 'logger_level', rtrim( $property[0]));
284 setDeepArrayValue($this->config, 'logger_file_maxLogs', 10);
285 setDeepArrayValue($this->config, 'logger_file_suffix', "%m_%Y");
286 $this->handleOverride();
287 unlink('log4php.properties');
288 $GLOBALS['sugar_config'] = $this->config; //load the rest of the sugar_config settings.
289 require_once('include/SugarLogger/SugarLogger.php');
290 //$logger = new SugarLogger(); //this will create the log file.
294 if (!isset($this->config['logger']) || empty($this->config['logger'])) {
295 $this->config['logger'] = array (
298 'name' => 'sugarcrm',
299 'dateFormat' => '%c',
302 'suffix' => ''), // bug51583, change default suffix to blank for backwards comptability
305 $this->handleOverride(true);