function install()
 {
     if ($this->getParameter('masteradmin')) {
         $this->config->setValue('loginResponse', 'htmlauth', 'jcommunity');
     }
     if ($this->firstExec('acl2') && class_exists('jAcl2DbManager')) {
         jAcl2DbManager::addSubjectGroup('jcommunity.admin', 'jcommunity~prefs.admin.jcommunity');
         jAcl2DbManager::addSubject('jcommunity.prefs.change', 'jcommunity~prefs.admin.prefs.change', 'jprefs.prefs.management');
         jAcl2DbManager::addRight('admins', 'jcommunity.prefs.change');
         // for admin group
     }
     if ($this->firstExec('preferences')) {
         $prefIni = new jIniFileModifier(__DIR__ . '/prefs.ini');
         $prefFile = jApp::configPath('preferences.ini.php');
         if (file_exists($prefFile)) {
             $mainPref = new jIniFileModifier($prefFile);
             //import this way to not erase changed value.
             $prefIni->import($mainPref);
         }
         $prefIni->saveAs($prefFile);
     }
 }
 function install()
 {
     $profilesfile = jApp::configPath('profiles.ini.php');
     if (!file_exists($profilesfile)) {
         file_put_contents($profilesfile, ";<?php die(''); ?>\n;for security reasons, don't remove or modify the first line");
     }
     $profiles = new jIniFileModifier($profilesfile);
     $profilesdistfile = jApp::configPath('profiles.ini.php.dist');
     $distcreated = false;
     if (!file_exists($profilesdistfile)) {
         file_put_contents($profilesdistfile, ";<?php die(''); ?>\n;for security reasons, don't remove or modify the first line");
         $distcreated = true;
     }
     $profilesdist = new jIniFileModifier($profilesdistfile);
     $dbprofile = $this->config->getValue('dbProfils');
     if (!$dbprofile) {
         $dbprofile = 'dbprofils.ini.php';
     }
     $dbprofilefile = jApp::configPath($dbprofile);
     if (file_exists($dbprofilefile)) {
         $dbProfiles = new jIniFileModifier($dbprofilefile);
         $profiles->import($dbProfiles, 'jdb', ':');
         unlink($dbprofilefile);
     }
     $dbprofilefile = jApp::configPath('dbprofils.ini.php.dist');
     if (file_exists($dbprofilefile)) {
         $dbProfiles = new jIniFileModifier($dbprofilefile);
         $profilesdist->import($dbProfiles, 'jdb', ':');
         unlink($dbprofilefile);
     }
     $kvprofilefile = jApp::configPath('kvprofiles.ini.php');
     if (file_exists($kvprofilefile)) {
         $dbProfiles = new jIniFileModifier($kvprofilefile);
         $profiles->import($dbProfiles, 'jkvdb', ':');
         unlink($kvprofilefile);
     }
     $kvprofilefile = jApp::configPath('kvprofiles.ini.php.dist');
     if (file_exists($kvprofilefile)) {
         $dbProfiles = new jIniFileModifier($kvprofilefile);
         $profilesdist->import($dbProfiles, 'jkvdb', ':');
         unlink($kvprofilefile);
     }
     $soapprofilefile = jApp::configPath('soapprofiles.ini.php');
     if (file_exists($soapprofilefile)) {
         $soapProfiles = new jIniFileModifier($soapprofilefile);
         $profiles->import($soapProfiles, 'jsoapclient', ':');
         unlink($soapprofilefile);
     }
     $soapprofilefile = jApp::configPath('soapprofiles.ini.php.dist');
     if (file_exists($soapprofilefile)) {
         $soapProfiles = new jIniFileModifier($soapprofilefile);
         $profilesdist->import($soapProfiles, 'jsoapclient', ':');
         unlink($soapprofilefile);
     }
     $cacheprofilefile = jApp::configPath('cache.ini.php');
     if (file_exists($cacheprofilefile)) {
         $cacheProfiles = new jIniFileModifier($cacheprofilefile);
         $profiles->import($cacheProfiles, 'jcache', ':');
         unlink($cacheprofilefile);
     }
     $cacheprofilefile = jApp::configPath('cache.ini.php.dist');
     if (file_exists($cacheprofilefile)) {
         $cacheProfiles = new jIniFileModifier($cacheprofilefile);
         $profilesdist->import($cacheProfiles, 'jcache', ':');
         unlink($cacheprofilefile);
     }
     $profiles->save();
     if ($profilesdist->isModified()) {
         $profilesdist->save();
     } else {
         if ($distcreated) {
             unlink($profilesdistfile);
         }
     }
     $this->config->getMaster()->removeValue('dbProfils');
     $this->config->getOverrider()->removeValue('dbProfils');
     $this->config->getMaster()->removeValue('cacheProfiles');
     $this->config->getOverrider()->removeValue('cacheProfiles');
 }
Esempio n. 3
0
 function install()
 {
     $authconfig = $this->config->getValue('auth', 'coordplugins');
     $authconfigMaster = $this->config->getValue('auth', 'coordplugins', null, true);
     $forWS = in_array($this->entryPoint->type, array('json', 'jsonrpc', 'soap', 'xmlrpc'));
     $createdConfFile = false;
     if (!$authconfig || $forWS && $authconfig == $authconfigMaster) {
         //if ($this->entryPoint->type == 'cmdline') {
         //    return;
         //}
         if ($forWS) {
             $pluginIni = 'authsw.coord.ini.php';
         } else {
             $pluginIni = 'auth.coord.ini.php';
         }
         $authconfig = dirname($this->entryPoint->configFile) . '/' . $pluginIni;
         if ($this->firstExec($authconfig)) {
             // no configuration, let's install the plugin for the entry point
             $this->config->setValue('auth', $authconfig, 'coordplugins');
             $this->copyFile('var/config/' . $pluginIni, 'epconfig:' . $pluginIni);
             $createdConfFile = true;
         }
     }
     $conf = new jIniFileModifier(jApp::configPath($authconfig));
     $usedStandardDao = $conf->getValue('dao', 'Db') == 'jauthdb~jelixuser';
     $this->useDbProfile($conf->getValue('profile', 'Db'));
     if ($createdConfFile) {
         mt_srand();
         $conf->setValue('persistant_crypt_key', sha1("jelix" . time() . mt_rand()));
         $conf->save();
     }
     if ($this->firstExec($authconfig) && $this->getParameter('rewriteconfig')) {
         $conf->setValue('driver', 'Db');
         $conf->setValue('dao', 'jcommunity~user', 'Db');
         $conf->setValue('form', 'jcommunity~account_admin', 'Db');
         $conf->setValue('error_message', 'jcommunity~login.error.notlogged');
         $conf->setValue('on_error_action', 'jcommunity~login:out');
         $conf->setValue('bad_ip_action', 'jcommunity~login:out');
         $conf->setValue('after_logout', 'jcommunity~login:index');
         $conf->setValue('enable_after_login_override', 'on');
         $conf->setValue('enable_after_logout_override', 'on');
         $conf->setValue('after_login', 'jcommunity~account:show');
         $conf->save();
     }
     if ($this->getParameter('masteradmin')) {
         $conf->setValue('after_login', 'master_admin~default:index');
         $conf->save();
         $this->config->setValue('loginResponse', 'htmlauth', 'jcommunity');
     }
     if ($this->firstDbExec() && !$this->getParameter('notjcommunitytable')) {
         $conf->setValue('dao', 'jcommunity~user', 'Db');
         $conf->setValue('form', 'jcommunity~account_admin', 'Db');
         $conf->save();
         $this->execSQLScript('sql/install');
         $cn = $this->dbConnection();
         if ($usedStandardDao && $this->getParameter('migratejauthdbusers')) {
             $cn->exec("INSERT INTO " . $cn->prefixTable('community_users') . "\n                            (login, password, email, nickname, status, create_date)\n                         SELECT usr_login, usr_password, usr_email, usr_login, 1, '" . date('Y-m-d H:i:s') . "'\n                         FROM " . $cn->prefixTable('jlx_user'));
         } else {
             if ($this->getParameter('defaultuser')) {
                 require_once JELIX_LIB_PATH . 'auth/jAuth.class.php';
                 require_once JELIX_LIB_PATH . 'plugins/auth/db/db.auth.php';
                 $confIni = parse_ini_file(jApp::configPath($authconfig), true);
                 $authConfig = jAuth::loadConfig($confIni);
                 $driver = new dbAuthDriver($authConfig['Db']);
                 $passwordHash = $driver->cryptPassword('admin');
                 $cn->exec("INSERT INTO " . $cn->prefixTable('community_users') . " (login, password, email, nickname, status, create_date) VALUES\n                            ('admin', " . $cn->quote($passwordHash) . ", '*****@*****.**', 'admin', 1, '" . date('Y-m-d H:i:s') . "')");
             }
         }
     }
     if ($this->firstExec('acl2') && class_exists('jAcl2DbManager')) {
         jAcl2DbManager::addSubjectGroup('jcommunity.admin', 'jcommunity~prefs.admin.jcommunity');
         jAcl2DbManager::addSubject('jcommunity.prefs.change', 'jcommunity~prefs.admin.prefs.change', 'jprefs.prefs.management');
         jAcl2DbManager::addRight('admins', 'jcommunity.prefs.change');
         // for admin group
     }
     if ($this->firstExec('preferences')) {
         $prefIni = new jIniFileModifier(__DIR__ . '/prefs.ini');
         $prefFile = jApp::configPath('preferences.ini.php');
         if (file_exists($prefFile)) {
             $mainPref = new jIniFileModifier($prefFile);
             //import this way to not erase changed value.
             $prefIni->import($mainPref);
         }
         $prefIni->saveAs($prefFile);
     }
 }