Example #1
0
function merge_config($arr1, $arr2)
{
    foreach ($arr2 as $key => $val) {
        if (is_array($val)) {
            $arr1[$key] = merge_config($arr1[$key], $val);
        } else {
            $arr1[$key] = $val;
        }
    }
    return $arr1;
}
Example #2
0
/**
 * Load config/filez.ini in "option ('fz_config')".
 * @return boolean  Whether if filez.ini was found or not
 */
function fz_config_load($config_dir)
{
    $result = true;
    $config = parse_ini_file($config_dir . 'filez.ini', true);
    if (empty($config)) {
        $config = array();
        $result = false;
        trigger_error('Missing or malformed config file.', E_USER_WARNING);
    }
    $default = parse_ini_file($config_dir . 'filez.default.ini', true);
    if (empty($default)) {
        trigger_error('Missing file "filez.default.ini".', E_USER_ERROR);
    }
    option('fz_config', merge_config($config, $default));
    return $result;
}
Example #3
0
    /**
     *
     */
    public function configureAction()
    {
        $config = fz_config_get();
        //
        $locales_choices = array();
        foreach (glob(option('root_dir') . '/i18n/*', GLOB_ONLYDIR) as $lc) {
            $locales_choices[basename($lc)] = basename($lc);
        }
        $errors = array();
        $notifs = array();
        // If request is post, check for errors
        if (request_is_post()) {
            // prevent unchecked input from being transformed to true when merging config
            $_POST['config']['looknfeel']['show_credit'] = array_key_exists('show_credit', $_POST['config']['looknfeel']) ? 1 : 0;
            $config = merge_config($_POST['config'], $config);
            // checking rights
            $this->checkRights($errors, $config);
            // Checking database connection
            $this->checkDatabaseConf($errors, $config);
            // If Upload monitoring lib is selected check if it's installed
            if ($config['app']['progress_monitor'] != '') {
                $progressMonitor = $config['app']['progress_monitor'];
                $progressMonitor = new $progressMonitor();
                if (!$progressMonitor->isInstalled()) {
                    $errors[] = array('title' => 'Your system is not configured for ' . get_class($progressMonitor), 'msg' => 'Read <a href="http://github.com/UAPV/FileZ/blob/master/doc/INSTALL.markdown" target="_blank">the INSTALL file</a> for help');
                }
            }
            // Is CAS authentication, check requirements
            if ($config['app']['auth_handler_class'] == 'Fz_Controller_Security_Cas' && !function_exists('curl_init')) {
                $errors[] = array('title' => 'PHP extension "cURL" is required for CAS authentication but is not installed', 'msg' => 'Use php5-curl on debian to install it');
            }
            // Checking User factory connection
            if ($config['app']['user_factory_class'] == 'Fz_User_Factory_Ldap') {
                $this->checkUserFactoryLdapConf($errors, $config);
            }
            // do not check user factory if database.
            //elseif ($config['app']['user_factory_class'] == 'Fz_User_Factory_Database')
            //    $this->checkUserFactoryDatabaseConf ($errors, $config);
            // Checking email
            $this->checkEmailConf($errors, $config);
            // If no errors or if the user ignored them, save the config and create
            // the database
            if (empty($errors) || array_key_exists('ignore_errors', $_POST)) {
                //$errors = array (); // Reset errors.
                // Try to save the file or display it
                $configFile = option('root_dir') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'filez.ini';
                if (!fz_config_save($config, $configFile)) {
                    $errors[] = array('title' => 'Can\'t save filez.ini.', 'msg' => 'Put the following code in the file "' . $configFile . '" :<textarea cols="60" rows="50">' . fz_serialize_ini_array($config, true) . '</textarea>');
                } else {
                    $notifs[] = 'Created file "' . $configFile . '"';
                }
                try {
                    $this->initDatabase();
                    $notifs[] = 'Database configured.<br/><br/>
A default admin account has been created. Login ("<tt>admin</tt>" / "<tt>filez</tt>") and choose a new password.';
                } catch (Exception $e) {
                    $errors[] = array('title' => 'Can\'t initialize the database (' . $e->getMessage() . ')', 'msg' => 'Check your database configuration in config/filez.ini and re-run the SQL script "' . $initDbScript . '".');
                }
                set('errors', $errors);
                set('notifs', $notifs);
                return html('install/finished.php');
            }
            if (!empty($errors)) {
                set('errors', $errors);
            }
        }
        set('config', $config);
        set('locales_choices', $locales_choices);
        return html('install/index.php');
    }