Exemple #1
0
 private function loadIconDefinitions($path, $file = 'views.ini')
 {
     $ret = array();
     if (!@file_exists($path . '/views.ini')) {
         return $ret;
     }
     $ini_data = \Akeeba\Engine\Util\ParseIni::parse_ini_file($path . '/' . $file, true);
     if (!empty($ini_data)) {
         foreach ($ini_data as $view => $def) {
             $task = array_key_exists('task', $def) ? $def['task'] : null;
             $ret[$def['group']][] = $this->_makeIconDefinition($def['icon'], JText::_($def['label']), $view, $task);
         }
     }
     return $ret;
 }
Exemple #2
0
 /**
  * Loads the current configuration off the database table
  *
  * @param   int  $profile_id  The profile where to read the configuration from, defaults to current profile
  *
  * @return  bool  True if everything was read properly
  *
  * @throws  DecryptionException  When the settings cannot be decrypted
  */
 public function load_configuration($profile_id = null)
 {
     // Load the database class
     $db = Factory::getDatabase($this->get_platform_database_options());
     // Get the active profile number, if no profile was specified
     if (is_null($profile_id)) {
         $profile_id = $this->get_active_profile();
     }
     // Initialize the registry
     $registry = Factory::getConfiguration();
     $registry->reset();
     // Is the database connected?
     if (!$db->connected()) {
         return false;
     }
     // Load the INI format local configuration dump off the database
     $sql = $db->getQuery(true)->select($db->qn('configuration'))->from($db->qn($this->tableNameProfiles))->where($db->qn('id') . ' = ' . $db->q($profile_id));
     $db->setQuery($sql);
     $databaseData = $db->loadResult();
     if (empty($databaseData) || is_null($databaseData)) {
         // No configuration was saved yet - store the defaults
         $saved = $this->save_configuration($profile_id);
         // If this is the case we probably don't have the necesary table. Throw an exception.
         if (!$saved) {
             throw new \RuntimeException("Could not save data to backup profile #{$profile_id}", 500);
         }
         return $this->load_configuration($profile_id);
     }
     // Configuration found. Convert to array format.
     if (function_exists('get_magic_quotes_runtime')) {
         if (@get_magic_quotes_runtime()) {
             $databaseData = stripslashes($databaseData);
         }
     }
     // Decrypt the data if required
     $secureSettings = Factory::getSecureSettings();
     $noData = empty($databaseData);
     $databaseData = $secureSettings->decryptSettings($databaseData);
     $dataArray = ParseIni::parse_ini_file($databaseData, true, true);
     $parsedData = array();
     // Did the decryption fail and we were asked to throw an exception?
     if ($this->decryptionException && !$noData) {
         // No decrypted data
         if (empty($databaseData)) {
             throw new DecryptionException();
         }
         // Corrupt data
         if (!strstr($databaseData, '[akeeba]')) {
             throw new DecryptionException();
         }
     }
     unset($databaseData);
     foreach ($dataArray as $section => $row) {
         if ($section == 'volatile') {
             continue;
         }
         if (is_array($row) && !empty($row)) {
             foreach ($row as $key => $value) {
                 $parsedData["{$section}.{$key}"] = $value;
             }
         }
     }
     unset($dataArray);
     // Import the configuration array
     $protected_keys = $registry->getProtectedKeys();
     $registry->resetProtectedKeys();
     $registry->mergeArray($parsedData, false, false);
     // Old profiles have advanced.proc_engine instead of advanced.postproc_engine. Migrate them.
     $procEngine = $registry->get('akeeba.advanced.proc_engine', null);
     if (!empty($procEngine)) {
         $registry->set('akeeba.advanced.postproc_engine', $procEngine);
         $registry->set('akeeba.advanced.proc_engine', null);
     }
     // Apply config overrides
     if (is_array($this->configOverrides) && !empty($this->configOverrides)) {
         $registry->mergeArray($this->configOverrides, false, false);
     }
     $registry->setProtectedKeys($protected_keys);
     $registry->activeProfile = $profile_id;
 }
Exemple #3
0
 /**
  * Parses a graphical interface INI file returning two arrays, one with the general
  * information of that configuration section and one with its configuration variables'
  * definitions.
  *
  * @param string $inifile     Absolute path to engine INI file
  * @param array  $information [out] The GUI information hash array
  * @param array  $parameters  [out] The parameters hash array
  *
  * @return bool True if the file was loaded
  */
 public function parseInterfaceINI($inifile, &$information, &$parameters)
 {
     if (!file_exists($inifile)) {
         return false;
     }
     $information = array('description' => '');
     $parameters = array();
     $inidata = ParseIni::parse_ini_file($inifile, true);
     foreach ($inidata as $section => $data) {
         if (is_array($data)) {
             if ($section == '_group') {
                 // Parse information
                 foreach ($data as $key => $value) {
                     $information[$key] = $value;
                 }
                 continue;
             }
             if (substr($section, 0, 1) != '_') {
                 // Parse parameters
                 $newparam = array('title' => '', 'description' => '', 'type' => 'string', 'default' => '', 'protected' => 0);
                 foreach ($data as $key => $value) {
                     $newparam[$key] = $value;
                 }
                 $parameters[$section] = $newparam;
             }
         }
     }
     return true;
 }
Exemple #4
0
 /**
  * Loads the current configuration off the database table
  *
  * @param    int $profile_id The profile where to read the configuration from, defaults to current profile
  *
  * @return    bool    True if everything was read properly
  */
 public function load_configuration($profile_id = null)
 {
     // Load the database class
     $db = Factory::getDatabase($this->get_platform_database_options());
     // Get the active profile number, if no profile was specified
     if (is_null($profile_id)) {
         $profile_id = $this->get_active_profile();
     }
     // Initialize the registry
     $registry = Factory::getConfiguration();
     $registry->reset();
     // Load the INI format local configuration dump off the database
     if ($db->connected()) {
         $sql = $db->getQuery(true)->select($db->qn('configuration'))->from($db->qn($this->tableNameProfiles))->where($db->qn('id') . ' = ' . $db->q($profile_id));
         $db->setQuery($sql);
         $ini_data_local = $db->loadResult();
         if (empty($ini_data_local) || is_null($ini_data_local)) {
             // No configuration was saved yet - store the defaults
             $this->save_configuration($profile_id);
         } else {
             // Configuration found. Convert to array format.
             if (function_exists('get_magic_quotes_runtime')) {
                 if (@get_magic_quotes_runtime()) {
                     $ini_data_local = stripslashes($ini_data_local);
                 }
             }
             // Decrypt the data if required
             $secureSettings = Factory::getSecureSettings();
             $ini_data_local = $secureSettings->decryptSettings($ini_data_local);
             $ini_data_local = ParseIni::parse_ini_file($ini_data_local, true, true);
             $ini_data = array();
             foreach ($ini_data_local as $section => $row) {
                 if ($section == 'volatile') {
                     continue;
                 }
                 if (is_array($row) && !empty($row)) {
                     foreach ($row as $key => $value) {
                         $ini_data["{$section}.{$key}"] = $value;
                     }
                 }
             }
             unset($ini_data_local);
             // Import the configuration array
             $protected_keys = $registry->getProtectedKeys();
             $registry->resetProtectedKeys();
             $registry->mergeArray($ini_data, false, false);
             // Old profiles have advanced.proc_engine instead of advanced.postproc_engine. Migrate them.
             $procEngine = $registry->get('akeeba.advanced.proc_engine', null);
             if (!empty($procEngine)) {
                 $registry->set('akeeba.advanced.postproc_engine', $procEngine);
                 $registry->set('akeeba.advanced.proc_engine', null);
             }
             $registry->setProtectedKeys($protected_keys);
         }
     }
     // Apply config overrides
     if (is_array($this->configOverrides) && !empty($this->configOverrides)) {
         $protected_keys = $registry->getProtectedKeys();
         $registry->resetProtectedKeys();
         $registry->mergeArray($this->configOverrides, false, false);
         $registry->setProtectedKeys($protected_keys);
     }
     $registry->activeProfile = $profile_id;
 }
Exemple #5
0
 /**
  * Merges an engine INI file to the configuration. Each section defines a full
  * registry path (section.subsection.key). It searches each section for the
  * key named "default" and merges its value to the configuration. The other keys
  * are simply ignored.
  *
  * @param   string $inifile    The absolute path to an INI file
  * @param   bool   $noOverride [optional] If true, values from the INI will not override the configuration
  *
  * @return  boolean  True on success
  */
 public function mergeEngineINI($inifile, $noOverride = false)
 {
     if (!file_exists($inifile)) {
         return false;
     }
     $inidata = ParseIni::parse_ini_file($inifile, true);
     foreach ($inidata as $section => $nodes) {
         if (is_array($nodes)) {
             if (substr($section, 0, 1) != '_') {
                 // Is this a protected node?
                 $protected = false;
                 if (array_key_exists('protected', $nodes)) {
                     $protected = $nodes['protected'];
                 }
                 // If overrides are allowed, unprotect until we can set the value
                 if (!$noOverride) {
                     if (in_array($section, $this->protected_nodes)) {
                         $pnk = array_search($section, $this->protected_nodes);
                         unset($this->protected_nodes[$pnk]);
                     }
                 }
                 if (array_key_exists('remove', $nodes)) {
                     // Remove a node if it has "remove" set
                     $this->remove($section);
                 } elseif (isset($nodes['default'])) {
                     if (!$noOverride) {
                         // Update the default value if No Override is set
                         $this->set($section, $nodes['default']);
                     } elseif (is_null($this->get($section, null))) {
                         // Set the default value if it does not exist
                         $this->set($section, $nodes['default']);
                     }
                 }
                 // Finally, if it's a protected node, enable the protection
                 if ($protected) {
                     $this->protected_nodes[] = $section;
                 } else {
                     $idx = array_search($section, $this->protected_nodes);
                     if ($idx !== false) {
                         unset($this->protected_nodes[$idx]);
                     }
                 }
             }
         }
     }
     return true;
 }
Exemple #6
0
 /**
  * Loads the current configuration off the database table
  *
  * @param    int $profile_id The profile where to read the configuration from, defaults to current profile
  *
  * @return    bool    True if everything was read properly
  */
 public function load_configuration($profile_id = null)
 {
     // Load the database class
     $db = Factory::getDatabase($this->get_platform_database_options());
     // Initialize the registry
     $registry = Factory::getConfiguration();
     $registry->reset();
     // 1) Load the INI format local configuration dump:
     $filename = realpath(dirname(__FILE__) . '/Config/config.ini');
     $ini_data_local = file_get_contents($filename);
     // Configuration found. Convert to array format.
     $ini_data_local = \Akeeba\Engine\Util\ParseIni::parse_ini_file_php($ini_data_local, true, true);
     $ini_data = array();
     foreach ($ini_data_local as $section => $row) {
         if (!empty($row)) {
             foreach ($row as $key => $value) {
                 $ini_data["{$section}.{$key}"] = $value;
             }
         }
     }
     unset($ini_data_local);
     // Import the configuration array
     $protected_keys = $registry->getProtectedKeys();
     $registry->resetProtectedKeys();
     $registry->mergeArray($ini_data, false, false);
     $registry->setProtectedKeys($protected_keys);
     // 2) Load the INI format local configuration dump off the database:
     $db = \Akeeba\Engine\Factory::getDatabase($this->get_platform_database_options());
     $sql = $db->getQuery(true)->select($db->qn('configuration'))->from($db->qn($this->tableNameProfiles))->where($db->qn('id') . ' = ' . $db->q(1));
     $db->setQuery($sql);
     $ini_data_local = $db->loadResult();
     if (empty($ini_data_local) || is_null($ini_data_local)) {
         // No configuration was saved yet - store the defaults
         $this->save_configuration($profile_id);
     } else {
         // Configuration found. Convert to array format.
         if (function_exists('get_magic_quotes_runtime')) {
             if (@get_magic_quotes_runtime()) {
                 $ini_data_local = stripslashes($ini_data_local);
             }
         }
         // Decrypt the data if required
         $ini_data_local = \Akeeba\Engine\Factory::getSecureSettings()->decryptSettings($ini_data_local);
         $ini_data_local = \Akeeba\Engine\Util\ParseIni::parse_ini_file_php($ini_data_local, true, true);
         $ini_data = array();
         foreach ($ini_data_local as $section => $row) {
             if (is_array($row) && !empty($row)) {
                 foreach ($row as $key => $value) {
                     $ini_data["{$section}.{$key}"] = $value;
                 }
             }
         }
         unset($ini_data_local);
         $allowedOverrides = array('akeeba.basic.clientsidewait', 'akeeba.basic.file_extensions', 'akeeba.basic.exclude_folders', 'akeeba.basic.exclude_files', 'akeeba.tuning.min_exec_time', 'akeeba.tuning.max_exec_time', 'akeeba.tuning.run_time_bias');
         foreach ($allowedOverrides as $key) {
             if (isset($ini_data[$key])) {
                 $registry->setKeyProtection($key, false);
                 $registry->set($key, $ini_data[$key]);
                 $registry->setKeyProtection($key, true);
             }
         }
     }
     $registry->activeProfile = 1;
     // Apply config overrides
     if (is_array($this->configOverrides) && !empty($this->configOverrides)) {
         $protected_keys = $registry->getProtectedKeys();
         $registry->resetProtectedKeys();
         $registry->mergeArray($this->configOverrides, false, false);
         $registry->setProtectedKeys($protected_keys);
     }
     $registry->activeProfile = $profile_id;
 }
Exemple #7
0
 /**
  * Create credentials from the credentials ini file in the HOME directory.
  *
  * @param string|null $profile  Pass a specific profile to use. If no
  *                              profile is specified we will attempt to use
  *                              the value specified in the AWS_PROFILE
  *                              environment variable. If AWS_PROFILE is not
  *                              set, the "default" profile is used.
  * @param string|null $filename Pass a string to specify the location of the
  *                              credentials files. If null is passed, the
  *                              SDK will attempt to find the configuration
  *                              file at in your HOME directory at
  *                              ~/.aws/credentials.
  * @return CredentialsInterface
  * @throws \RuntimeException if the file cannot be found, if the file is
  *                           invalid, or if the profile is invalid.
  */
 public static function fromIni($profile = null, $filename = null)
 {
     if (!$filename) {
         $filename = self::getHomeDir() . '/.aws/credentials';
     }
     if (!$profile) {
         $profile = self::getEnvVar(self::ENV_PROFILE) ?: 'default';
     }
     if (!file_exists($filename) || !($data = ParseIni::parse_ini_file($filename, true))) {
         throw new \RuntimeException("Invalid AWS credentials file: {$filename}.");
     }
     if (empty($data[$profile])) {
         throw new \RuntimeException("Invalid AWS credentials profile {$profile} in {$filename}.");
     }
     return new self($data[$profile]['aws_access_key_id'], $data[$profile]['aws_secret_access_key'], isset($data[$profile]['aws_security_token']) ? $data[$profile]['aws_security_token'] : null);
 }