There is often a need to update the configuration of a live SugarCRM installation, especially in cloud. Some uses cases are testing, flipping an emergency switch, etc.
But - unless you have access to the file system, there is no easy way to do it other than re-installation, or uploading a package file manually.
We developed an Admin Configuration Panel which can be used to update them at runtime. But this should be used with care, so we added a password (that could be added to the DB or
config_override.php) for any updates, but searches can be simple.
We've also added filtering so that it doesn't display any password or keys in the UI, and it's enabled only for Admins, of course!
Use it at your own risk!
Our source code and package can be downloaded from our Github Repo:
The way the package works is by adding a new Admin panel first - this is done by creating a new file in the Extension directory:
Once we add a language file, the admin panel will look like this:
Then we have to build the User interface to search/update configurations. The Admin UI will expect a file named
ConfigManager.php , which we'll create under
custom/modules/Administration. Since Sugar Admin is mostly using Legacy 6 UI, we create a template file as well for rendering.
Reading the config
As you might know already, the sugar config is available as part of
global $sugar_config variable.
The user interface will submit a backend form, which reads from sugar config and pretty prints it into a
pre tag, simple.
The main think to notice is that this supports nested arrays, so you can use a syntax like:
To mask passwords, we search the key by keywords, that is specified in
// TODO - Update the keywords you don't want to show in the UI const CONFIG_KEYS_TO_MASK=['pass', 'key'];
Updating the config
We have to be careful here, but this mainly works by updating the
require_once 'modules/Configurator/Configurator.php'; $configuratorObj = new Configurator(); $configuratorObj->loadConfig(); $configuratorObj->config[$key] = $value; $configuratorObj->saveConfig(); echo "Configuration Updated Successfully!";
The UI to update config should be protected, of course. So we added a simple password that could be set during installation, or could be set using
$sugar_config or even use Admin config db - but for simplicity, the package just uses a default password that is present in the
// This password is used to validate if the request is valid. Change it! // This is just a basic check. Don't want to hardcode move it to sugar_config const CONFIG_MANAGER_PASSWORD='****';
Alternatives to Update
We're also ensuring that passwords or keys cannot be updated, since it's potentially risky. An alternative is to allow only certain fields to be updated. We could tweak it for you, let us know!
const CONFIG_KEYS_TO_DENY_UPDATE=['pass', 'key', 'dbconfig'];
SugarCRM uses manifest.php to define how to install files, for simplicity, we created all files under the
files directory. The manifest then specifies where to install the files:
$installdefs = array( 'id' => 'config_manager', 'copy' => array( array( 'from' => '<basepath>/files/ConfigManager.php', 'to' => 'custom/modules/Administration/ConfigManager.php' ), array( 'from' => '<basepath>/files/ConfigManager.tpl', 'to' => 'custom/modules/Administration/ConfigManager.tpl' ), ), 'administration' => array( array( 'from' => '<basepath>/files/ConfigManagerAdminLink.php', 'to' => 'custom/Extension/modules/Administration/Ext/Administration/ConfigManagerAdminLink.php' ), ), 'language' => array( array( 'from' => '<basepath>/files/en_us.ConfigManager.php', 'to' => 'custom/Extensions/modules/Administration/Ext/Language/en_us.ConfigManager.php', 'to_module' => 'Administration', 'language' => 'en_us' ) ) );
Here is the final directory structure:
├── sugarcrm-config-manager │ ├── files │ │ ├── ConfigManagerAdminLink.php │ │ ├── ConfigManager.php │ │ ├── ConfigManager.tpl │ │ └── en_us.ConfigManager.php │ ├── manifest.php │ ├── README.md
To package, ensure that the manifest.php is in the root folder - i.e you have to create the zip from inside the
~/code/sugar/packages/sugarcrm-config-manager zip -r ../sugarcrm-config-manager.zip . adding: README.md (deflated 50%) adding: manifest.php (deflated 66%) adding: files/ (stored 0%) adding: files/ConfigManager.tpl (deflated 74%) adding: files/ConfigManager.php (deflated 66%) adding: files/ConfigManagerAdminLink.php (deflated 50%) adding: files/en_us.ConfigManager.php (deflated 54%)
You can then just zip the folder and upload the package to module loader, or download the packaged release and source code from our Github repo below.