In order to improve security in our projects, we made several changes to the application files. One of these changes affected a crucial file that tells applications how to sync.
To ensure that the synchronization continues to work correctly, we made a modification to the onValidate event code of the synchronization application. All future modules will follow this fix in the code, which will provide greater security and efficiency in our projects.
However, for users who are using a previous version of the security module, it will be necessary to perform a small adjustment in their application to ensure correct operation.
Here is the steps to follow:
1- Access the sync application:
In development, inside the security folder, open the application: "app_sync_apps" .
By default, the application has the name app_sync_apps, however it is possible to change the application prefix when creating the security module. If the application with the default name is not found, use only the end of the application name: sync_apps
2- New code for the app_sync_apps application
The app_sync_apps application is created by generating modules of the types: Group, Applications and LDAP - Total Control.
Make sure the type of module being used before replacing the codes.
For modules of the type: Group
Copy the code below:
- $arr_apps = array();
- $_arr_apps = array_diff(scandir($this->Ini->path_aplicacao . "../_lib/_app_data/"), array('.','..', 'index.php', 'index.html'));
- foreach($_arr_apps as $k => $v)
- {
- if(substr($v, -12) != "_mob_ini.php")
- {
- $arr_apps[] = substr($v, 0, -8);
- }
- }
- if({check_deleted} == 'Y')
- {
- foreach($arr_apps as $k => $app)
- {
- require($this->Ini->path_aplicacao . "../_lib/_app_data/". $app . '_ini.php');
- $app = (isset($arr_data['friendly_url']) && !empty($arr_data['friendly_url']))?$arr_data['friendly_url']:$app;
- if( !is_dir($this->Ini->path_aplicacao . "../" . $app) )
- {
- unset($arr_apps[$k]);
- }
- }
- }
- sc_select(rs, "SELECT app_name FROM sec_apps");
- $arr_apps_db = array();
- while(!$rs->EOF)
- {
- $arr_apps_db[] = $rs->fields[0];
- $rs->MoveNext();
- }
- $rs->Close();
- $arr_apps = array_diff($arr_apps, $arr_apps_db);
- //========= Groups =========
- $arr_grp = array();
- sc_select(rs, "SELECT group_id FROM sec_groups");
- while(!$rs->EOF)
- {
- $arr_grp[] = $rs->fields[0];
- $rs->MoveNext();
- }
- $rs->Close();
- foreach($arr_apps as $k => $app)
- {
- require($this->Ini->path_aplicacao . "../_lib/_app_data/". $app . '_ini.php');
- $app_type = isset($arr_data['type'])?$arr_data['type']:'';
-
- $sql = "SELECT count(*) FROM sec_apps WHERE app_name = '". $app ."' ";
- sc_lookup(rs, $sql);
- if({rs[0][0]} == 0)
- {
- $sql = "INSERT INTO sec_apps(app_name, app_type) VALUES ('". $app ."', '".$app_type."')";
- sc_exec_sql( $sql );
- foreach($arr_grp as $grp)
- {
- $sql = "INSERT INTO sec_groups_apps(app_name, group_id) VALUES ('". $app ."', '". $grp ."')";
- sc_exec_sql( $sql );
- }
- }
- }
For modules of the type: Application
Copy the code below:
- $arr_apps = array();
$_arr_apps = array_diff(scandir($this->Ini->path_aplicacao . "../_lib/_app_data/"), array('.','..', 'index.php', 'index.html'));
foreach($_arr_apps as $k => $v)
{
if(substr($v, -12) != "_mob_ini.php")
{
$arr_apps[] = substr($v, 0, -8);
}
}
if({check_deleted} == 'Y')
{
foreach($arr_apps as $k => $app)
{
require($this->Ini->path_aplicacao . "../_lib/_app_data/". $app . '_ini.php');
$app = (isset($arr_data['friendly_url']) && !empty($arr_data['friendly_url']))?$arr_data['friendly_url']:$app;
if( !is_dir($this->Ini->path_aplicacao . "../" . $app) )
{
unset($arr_apps[$k]);
}
}
}
sc_select(rs, "SELECT app_name FROM sec_apps");
$arr_apps_db = array();
while(!$rs->EOF)
{
$arr_apps_db[] = $rs->fields[0];
$rs->MoveNext();
}
$rs->Close();
$arr_apps = array_diff($arr_apps, $arr_apps_db);
//========= Users =====
$arr_usr = array();
sc_select(rs, "SELECT login FROM sec_users");
while(!$rs->EOF)
{
$arr_usr[] = $rs->fields[0];
$rs->MoveNext();
}
$rs->Close();
foreach($arr_apps as $k => $app)
{
require($this->Ini->path_aplicacao . "../_lib/_app_data/". $app . '_ini.php');
$app_type = isset($arr_data['type'])?$arr_data['type']:'';
$sql = "SELECT count(*) FROM sec_apps WHERE app_name = '". $app ."' ";
sc_lookup(rs, $sql);
if({rs[0][0]} == 0)
{
sc_exec_sql("INSERT INTO sec_apps(app_name, app_type) VALUES ('". $app ."', '".$app_type."')");
foreach($arr_usr as $usr)
{
sc_exec_sql("INSERT INTO sec_users_apps(app_name, login) VALUES ('". $app ."', '".$usr."')");
}
}
}
For modules of types: LDAP - Total Control
Copy the code below:$arr_apps = array();
- $_arr_apps = array_diff(scandir($this->Ini->path_aplicacao . "../_lib/_app_data/"), array('.','..', 'index.php', 'index.html'));
- foreach($_arr_apps as $k => $v)
- {
- if(substr($v, -12) != "_mob_ini.php")
- {
- $arr_apps[] = substr($v, 0, -8);
- }
- }
- if({check_deleted} == 'Y')
- {
- foreach($arr_apps as $k => $app)
- {
- require($this->Ini->path_aplicacao . "../_lib/_app_data/". $app . '_ini.php');
- $app = (isset($arr_data['friendly_url']) && !empty($arr_data['friendly_url']))?$arr_data['friendly_url']:$app;
- if( !is_dir($this->Ini->path_aplicacao . "../" . $app) )
- {
- unset($arr_apps[$k]);
- }
- }
- }
-
- sc_select(rs, "SELECT app_name FROM sec_apps");
- $arr_apps_db = array();
- while(!$rs->EOF)
- {
- $arr_apps_db[] = $rs->fields[0];
- $rs->MoveNext();
- }
- $rs->Close();
- $arr_apps = array_diff($arr_apps, $arr_apps_db);
- //========= Users =========
- $arr_usr = array();
- sc_select(rs, "SELECT login FROM sec_users");
- while(!$rs->EOF)
- {
- $arr_usr[] = $rs->fields[0];
- $rs->MoveNext();
- }
- $rs->Close();
- foreach($arr_apps as $k => $app)
- {
- require($this->Ini->path_aplicacao . "../_lib/_app_data/". $app . '_ini.php');
- $app_type = isset($arr_data['type'])?$arr_data['type']:'';
- $sql = "SELECT count(*) FROM sec_apps WHERE app_name = '". $app ."' ";
- sc_lookup(rs, $sql);
- if({rs[0][0]} == 0)
- {
- sc_exec_sql("INSERT INTO sec_apps(app_name, app_type) VALUES ('". $app ."', '".$app_type."')");
- foreach($arr_usr as $usr)
- {
- sc_exec_sql("INSERT INTO sec_users_apps(app_name, login) VALUES ('". $app ."', '".$usr."')");
- }
- }
- }
3- Replace the "onValidate" event:
In the events folder, select the "onValidate" event. Replace the existing code with the one you copied in step 2.
In the provided code, the tables are prefixed with "sec_" pattern which is generated by the security module. In case you changed the prefix during the generation of your module, it is necessary to adjust the code, replacing "sec_" by the used prefix.
4- Generate the source code
After completing these steps and generating the source code, you are ready to synchronize the applications.