Example #1
0
 function install()
 {
     if (!$this->firstDbExec()) {
         return;
     }
     // ---  install table for session storage if needed
     $sessionStorage = $this->config->getValue("storage", "sessions");
     $sessionDao = $this->config->getValue("dao_selector", "sessions");
     $sessionProfile = $this->config->getValue("dao_db_profile", "sessions");
     if ($sessionStorage == "dao" && $sessionDao == "jelix~jsession") {
         $this->execSQLScript('sql/install_jsession.schema');
     }
     // --- install table for jCache if needed
     $cachefile = jApp::configPath('profiles.ini.php');
     if (file_exists($cachefile)) {
         $ini = new \Jelix\IniFile\IniModifier($cachefile);
         foreach ($ini->getSectionList() as $section) {
             if (substr($section, 0, 7) != 'jcache:') {
                 continue;
             }
             $driver = $ini->getValue('driver', $section);
             $dao = $ini->getValue('dao', $section);
             $this->useDbProfile($ini->getValue('dbprofile', $section));
             if ($driver == 'db' && $dao == 'jelix~jcache' && $this->firstExec('cachedb:' . $this->dbProfile)) {
                 $this->execSQLScript('sql/install_jcache.schema');
             }
         }
     }
 }
Example #2
0
 function install()
 {
     $authconfig = $this->getConfigIni()->getValue('auth', 'coordplugins');
     if ($authconfig && $this->entryPoint->type != 'cmdline' && $this->firstExec($authconfig)) {
         $conf = new \Jelix\IniFile\IniModifier(jApp::configPath($authconfig));
         $driver = $conf->getValue('driver');
         $daoName = $conf->getValue('dao', 'Db');
         $formName = $conf->getValue('form', 'Db');
         if ($driver == 'Db' && $daoName == 'jauthdb~jelixuser' && $formName == '') {
             $conf->setValue('form', 'jauthdb_admin~jelixuser', 'Db');
             $conf->save();
         }
     }
 }
Example #3
0
 protected function _upgradeconf($module)
 {
     $conf = null;
     // get from entrypoint config
     $jacl2File = $this->getConfigIni()->getOverrider()->getValue($module, 'coordplugins');
     if ($jacl2File == '') {
         // get from localConfig.ini.php
         $jacl2File = $this->getLocalConfigIni()->getOverrider()->getValue($module, 'coordplugins');
         if ($jacl2File == '') {
             // get from mainConfig.ini.php
             $jacl2File = $this->getMainConfigIni()->getOverrider()->getValue($module, 'coordplugins');
             $conf = $this->getMainConfigIni()->getOverrider();
         } else {
             $conf = $this->getLocalConfigIni()->getOverrider();
         }
     } else {
         $conf = $this->getConfigIni()->getOverrider();
     }
     if ($jacl2File == '' || $jacl2File == '1') {
         return;
     }
     $jacl2File = jApp::configPath($jacl2File);
     if (!file_exists($jacl2File)) {
         $jacl2File = '';
         $message = $module . "~errors.action.right.needed";
         if ($this->entryPoint->type != 'classic') {
             $onerror = 1;
         } else {
             $onerror = 2;
         }
         $on_error_action = "jelix~error:badright";
     } else {
         $ini = new \Jelix\IniFile\IniModifier($jacl2File);
         $message = $ini->getValue('error_message');
         // = ');
         if ($message == "jelix~errors.acl.action.right.needed") {
             $message = $module . "~errors.action.right.needed";
         }
         $onerror = $ini->getValue('on_error');
         $on_error_action = $ini->getValue('on_error_action');
     }
     $conf->setValue($module, '1', 'coordplugins');
     $conf->setValue('on_error', $onerror, 'coordplugin_' . $module);
     $conf->setValue('error_message', $message, 'coordplugin_' . $module);
     $conf->setValue('on_error_action', $on_error_action, 'coordplugin_' . $module);
     $conf->save();
 }
Example #4
0
 function install()
 {
     //if ($this->entryPoint->type == 'cmdline')
     //    return;
     $authconfig = $this->config->getValue('auth', 'coordplugins');
     if ($authconfig && $this->firstExec($authconfig)) {
         // a config file for the auth plugin exists, so we can install
         // the module, else we ignore it
         $conf = new \Jelix\IniFile\IniModifier(jApp::configPath($authconfig));
         $driver = $conf->getValue('driver');
         if ($driver == '') {
             $driver = 'Db';
             $conf->setValue('driver', 'Db');
             $conf->setValue('dao', 'jauthdb~jelixuser', 'Db');
             $conf->save();
         } else {
             if ($driver != 'Db') {
                 return;
             }
         }
         $this->useDbProfile($conf->getValue('profile', 'Db'));
         // FIXME: should use the given dao to create the table
         $daoName = $conf->getValue('dao', 'Db');
         if ($daoName == 'jauthdb~jelixuser' && $this->firstDbExec()) {
             $this->execSQLScript('install_jauth.schema');
             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 = $this->dbConnection();
                 $cn->exec("INSERT INTO " . $cn->prefixTable('jlx_user') . " (usr_login, usr_password, usr_email ) VALUES\n                                ('admin', " . $cn->quote($passwordHash) . " , '*****@*****.**')");
             }
         }
     }
 }
Example #5
0
 /**
  * declare a new db profile. if the content of the section is not given,
  * it will declare an alias to the default profile
  * @param string $name  the name of the new section/alias
  * @param null|string|array  $sectionContent the content of the new section, or null
  *     to create an alias.
  * @param boolean $force true:erase the existing profile
  * @return boolean true if the ini file has been changed
  */
 protected function declareDbProfile($name, $sectionContent = null, $force = true)
 {
     $profiles = new \Jelix\IniFile\IniModifier(App::configPath('profiles.ini.php'));
     if ($sectionContent == null) {
         if (!$profiles->isSection('jdb:' . $name)) {
             // no section
             if ($profiles->getValue($name, 'jdb') && !$force) {
                 // already a name
                 return false;
             }
         } else {
             if ($force) {
                 // existing section, and no content provided : we erase the section
                 // and add an alias
                 $profiles->removeValue('', 'jdb:' . $name);
             } else {
                 return false;
             }
         }
         $default = $profiles->getValue('default', 'jdb');
         if ($default) {
             $profiles->setValue($name, $default, 'jdb');
         } else {
             // default is a section
             $profiles->setValue($name, 'default', 'jdb');
         }
     } else {
         if ($profiles->getValue($name, 'jdb') !== null) {
             if (!$force) {
                 return false;
             }
             $profiles->removeValue($name, 'jdb');
         }
         if (is_array($sectionContent)) {
             foreach ($sectionContent as $k => $v) {
                 $profiles->setValue($k, $v, 'jdb:' . $name);
             }
         } else {
             $profile = $profiles->getValue($sectionContent, 'jdb');
             if ($profile !== null) {
                 $profiles->setValue($name, $profile, 'jdb');
             } else {
                 $profiles->setValue($name, $sectionContent, 'jdb');
             }
         }
     }
     $profiles->save();
     \Jelix\Core\Profiles::clear();
     return true;
 }
Example #6
0
 protected function _execute(InputInterface $input, OutputInterface $output)
 {
     $module = $input->getArgument('module');
     $initialVersion = $input->getOption('ver');
     if (!$initialVersion) {
         $initialVersion = '0.1pre';
     }
     // note: since module name are used for name of generated name,
     // only this characters are allowed
     if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) {
         throw new \Exception("'" . $module . "' is not a valid name for a module");
     }
     // check if the module already exist or not
     $path = '';
     try {
         $path = $this->getModulePath($module);
     } catch (\Exception $e) {
     }
     if ($path != '') {
         throw new \Exception("module '" . $module . "' already exists");
     }
     // verify the given repository
     $repository = $input->getArgument('repository');
     if (substr($repository, -1) != '/') {
         $repository .= '/';
     }
     $repositoryPath = \jFile::parseJelixPath($repository);
     if (!$input->getOption('noregistration')) {
         $this->registerModulesDir($repository, $repositoryPath);
     }
     $path = $repositoryPath . $module . '/';
     $this->createDir($path);
     App::setConfig(null);
     $noSubDir = $input->getOption('nosubdir');
     $addInstallZone = $input->getOption('addinstallzone');
     $isdefault = $input->getOption('defaultmodule');
     if ($input->getOption('admin')) {
         $noSubDir = false;
         $addInstallZone = false;
     }
     $param = array();
     $param['module'] = $module;
     $param['version'] = $initialVersion;
     $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param);
     // create all sub directories of a module
     if (!$noSubDir) {
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'zones/');
         $this->createDir($path . 'controllers/');
         $this->createDir($path . 'templates/');
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'daos/');
         $this->createDir($path . 'forms/');
         $this->createDir($path . 'locales/');
         $this->createDir($path . 'locales/en_US/');
         $this->createDir($path . 'locales/fr_FR/');
         $this->createDir($path . 'install/');
         if ($this->verbose()) {
             $output->writeln("Sub directories have been created in the new module {$module}.");
         }
         $this->createFile($path . 'install/install.php', 'module/install.tpl', $param);
         $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array());
     }
     $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile());
     $urlsFile = App::appConfigPath($iniDefault->getValue('significantFile', 'urlengine'));
     $xmlMap = new \Jelix\Routing\UrlMapping\XmlMapModifier($urlsFile, true);
     // activate the module in the application
     if ($isdefault) {
         if ($this->allEntryPoint) {
             $xmlEp = $xmlMap->getDefaultEntryPoint($type);
         } else {
             $xmlEp = $xmlMap->getEntryPoint($this->entryPointId);
         }
         if ($xmlEp) {
             $xmlEp->addUrlAction('/', $module, 'default:index', null, null, array('default' => true));
             $xmlEp->addUrlModule('', $module);
             if ($this->verbose()) {
                 $output->writeln("The new module {$module} becomes the default module");
             }
         } else {
             if ($this->verbose()) {
                 $output->writeln("No default entry point found: the new module cannot be the default module");
             }
         }
     }
     $xmlMap->save();
     $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules');
     $iniDefault->save();
     $list = $this->getEntryPointsList();
     $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php'));
     // install the module for all needed entry points
     foreach ($list as $entryPoint) {
         $configFile = App::appConfigPath($entryPoint['config']);
         $epconfig = new \Jelix\IniFile\IniModifier($configFile);
         if ($this->allEntryPoint) {
             $access = 2;
         } else {
             $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0;
         }
         $epconfig->setValue($module . '.access', $access, 'modules');
         $epconfig->save();
         if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) {
             $install->setValue($module . '.installed', 1, $entryPoint['id']);
             $install->setValue($module . '.version', $initialVersion, $entryPoint['id']);
         }
         if ($this->verbose()) {
             $output->writeln("The module is initialized for the entry point " . $entryPoint['file']);
         }
     }
     $install->save();
     App::declareModule($path);
     // create a default controller
     if (!$input->getOption('nocontroller')) {
         $arguments = array('module' => $module, 'controller' => 'default', 'method' => 'index');
         if ($input->getOption('entry-point')) {
             $arguments['--entry-point'] = $input->getOption('entry-point');
         }
         if ($input->getOption('cmdline')) {
             $arguments['--cmdline'] = true;
         }
         if ($addInstallZone) {
             $arguments['--addinstallzone'] = true;
         }
         if ($output->isVerbose()) {
             $arguments['-v'] = true;
         }
         $this->executeSubCommand('module:create-ctrl', $arguments, $output);
     }
     if ($input->getOption('admin')) {
         $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener");
         $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param);
         file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module);
         file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module);
     }
 }
Example #7
0
 protected function loadProfiles()
 {
     $file = jApp::configPath('profiles.ini.php');
     if (file_exists($file)) {
     } elseif (file_exists(jApp::configPath('profiles.ini.php.dist'))) {
         copy(jApp::configPath('profiles.ini.php.dist'), $file);
     } else {
         file_put_contents($file, ";<?php die(''); ?>\n;for security reasons, don't remove or modify the first line\n\n[jdb:default]\ndriver=mysqli\ndatabase=\nhost=localhost\nuser=\npassword=\npersistent = on\nforce_encoding = on\ntable_prefix=\n");
     }
     $ini = new \Jelix\IniFile\IniModifier($file);
     $data = array('dbtype' => array(), 'driver' => array(), 'database' => array(), 'host' => array(), 'port' => array(), 'user' => array(), 'password' => array(), 'passwordconfirm' => array(), 'persistent' => array(), 'table_prefix' => array(), 'force_encoding' => array(), 'search_path' => array(), 'errors' => array());
     $profiles = $ini->getSectionList();
     $dbprofileslist = array();
     foreach ($profiles as $profile) {
         if (strpos($profile, 'jdb:') !== 0) {
             continue;
         }
         $dbprofileslist[] = $profile;
         $options = $ini->getValues($profile);
         $dbparam = new jDbParameters($options);
         $options = $dbparam->getParameters();
         $data['dbtype'][$profile] = $options['dbtype'];
         $driver = $options['driver'];
         if ($options['usepdo']) {
             $dsn = $ini->getValue('dsn', $profile);
             $data['driver'][$profile] = $driver . ':pdo';
             if (preg_match("/host=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['host'][$profile] = $m[1];
             } else {
                 $host = $ini->getValue('host', $profile);
                 $data['host'][$profile] = $host === null ? '' : $host;
             }
             if (preg_match("/dbname=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['database'][$profile] = $m[1];
             } else {
                 $host = $ini->getValue('database', $profile);
                 $data['database'][$profile] = $host === null ? '' : $host;
             }
             if (preg_match("/port=([^;]*)(;|\$)/", $dsn, $m)) {
                 $data['port'][$profile] = $m[1];
             } else {
                 $port = $ini->getValue('port', $profile);
                 $data['port'][$profile] = $port === null ? '' : $port;
             }
         } else {
             $data['driver'][$profile] = $driver . ($options['usepdo'] ? ':pdo' : '');
             $data['database'][$profile] = $ini->getValue('database', $profile);
             $data['host'][$profile] = $ini->getValue('host', $profile);
             $data['port'][$profile] = $ini->getValue('port', $profile);
         }
         $data['user'][$profile] = $ini->getValue('user', $profile);
         $data['password'][$profile] = $ini->getValue('password', $profile);
         $data['passwordconfirm'][$profile] = $data['password'][$profile];
         $data['persistent'][$profile] = $options['persistent'];
         $data['force_encoding'][$profile] = $options['force_encoding'];
         $data['table_prefix'][$profile] = $ini->getValue('table_prefix', $profile);
         $data['search_path'][$profile] = $ini->getValue('search_path', $profile);
         $data['errors'][$profile] = array();
     }
     $_SESSION['dbprofiles']['profiles'] = $dbprofileslist;
     $_SESSION['dbprofiles']['data'] = $data;
 }
Example #8
0
 protected function loadconf()
 {
     $ini = new \Jelix\IniFile\IniModifier(jApp::mainConfigFile());
     $emailConfig = array('webmasterEmail' => $ini->getValue('webmasterEmail', 'mailer'), 'webmasterName' => $ini->getValue('webmasterName', 'mailer'), 'mailerType' => $ini->getValue('mailerType', 'mailer'), 'hostname' => $ini->getValue('hostname', 'mailer'), 'sendmailPath' => $ini->getValue('sendmailPath', 'mailer'), 'smtpHost' => $ini->getValue('smtpHost', 'mailer'), 'smtpPort' => $ini->getValue('smtpPort', 'mailer'), 'smtpSecure' => $ini->getValue('smtpSecure', 'mailer'), 'smtpHelo' => $ini->getValue('smtpHelo', 'mailer'), 'smtpAuth' => $ini->getValue('smtpAuth', 'mailer'), 'smtpUsername' => $ini->getValue('smtpUsername', 'mailer'), 'smtpPassword' => $ini->getValue('smtpPassword', 'mailer'), 'smtpTimeout' => $ini->getValue('smtpTimeout', 'mailer'), 'errors' => array());
     if (!in_array($emailConfig['mailerType'], array('mail', 'sendmail', 'smtp'))) {
         $emailConfig['mailerType'] = 'mail';
     }
     return $emailConfig;
 }
Example #9
0
 public function run()
 {
     $this->loadAppConfig();
     $module = $this->getParam('module');
     $initialVersion = $this->getOption('-ver');
     if ($initialVersion === false) {
         $initialVersion = '0.1pre';
     }
     // note: since module name are used for name of generated name,
     // only this characters are allowed
     if ($module == null || preg_match('/([^a-zA-Z_0-9])/', $module)) {
         throw new Exception("'" . $module . "' is not a valid name for a module");
     }
     // check if the module already exist or not
     $path = '';
     try {
         $path = $this->getModulePath($module);
     } catch (Exception $e) {
     }
     if ($path != '') {
         throw new Exception("module '" . $module . "' already exists");
     }
     // verify the given repository
     $repository = $this->getParam('repository', 'app:modules/');
     if (substr($repository, -1) != '/') {
         $repository .= '/';
     }
     $repositoryPath = jFile::parseJelixPath($repository);
     if (!$this->getOption('-noregistration')) {
         $this->registerModulesDir($repository, $repositoryPath);
     }
     $path = $repositoryPath . $module . '/';
     $this->createDir($path);
     App::setConfig(null);
     if ($this->getOption('-admin')) {
         $this->removeOption('-nosubdir');
         $this->removeOption('-addinstallzone');
     }
     $param = array();
     $param['module'] = $module;
     $param['version'] = $initialVersion;
     $this->createFile($path . 'jelix-module.json', 'module/jelix-module.json.tpl', $param);
     // create all sub directories of a module
     if (!$this->getOption('-nosubdir')) {
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'zones/');
         $this->createDir($path . 'controllers/');
         $this->createDir($path . 'templates/');
         $this->createDir($path . 'classes/');
         $this->createDir($path . 'daos/');
         $this->createDir($path . 'forms/');
         $this->createDir($path . 'locales/');
         $this->createDir($path . 'locales/en_US/');
         $this->createDir($path . 'locales/fr_FR/');
         $this->createDir($path . 'install/');
         if ($this->verbose()) {
             echo "Sub directories have been created in the new module {$module}.\n";
         }
         $this->createFile($path . 'install/install.php', 'module/install.tpl', $param);
         $this->createFile($path . 'urls.xml', 'module/urls.xml.tpl', array());
     }
     $isdefault = $this->getOption('-defaultmodule');
     $iniDefault = new \Jelix\IniFile\IniModifier(App::mainConfigFile());
     // activate the module in the application
     if ($isdefault) {
         $iniDefault->setValue('startModule', $module);
         $iniDefault->setValue('startAction', 'default:index');
         if ($this->verbose()) {
             echo "The new module {$module} becomes the default module\n";
         }
     }
     $iniDefault->setValue($module . '.access', $this->allEntryPoint ? 2 : 1, 'modules');
     $iniDefault->save();
     $list = $this->getEntryPointsList();
     $install = new \Jelix\IniFile\IniModifier(App::configPath('installer.ini.php'));
     // install the module for all needed entry points
     foreach ($list as $entryPoint) {
         $configFile = App::configPath($entryPoint['config']);
         $epconfig = new \Jelix\IniFile\IniModifier($configFile);
         if ($this->allEntryPoint) {
             $access = 2;
         } else {
             $access = $entryPoint['file'] == $this->entryPointName ? 2 : 0;
         }
         $epconfig->setValue($module . '.access', $access, 'modules');
         $epconfig->save();
         if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) {
             $install->setValue($module . '.installed', 1, $entryPoint['id']);
             $install->setValue($module . '.version', $initialVersion, $entryPoint['id']);
         }
         if ($isdefault) {
             // we set the module as default module for one or all entry points.
             // we set the startModule option for all entry points except
             // if an entry point is indicated on the command line
             if ($this->allEntryPoint || $entryPoint['file'] == $this->entryPointName) {
                 if ($epconfig->getValue('startModule') != '') {
                     $epconfig->setValue('startModule', $module);
                     $epconfig->setValue('startAction', 'default:index');
                     $epconfig->save();
                 }
             }
         }
         if ($this->verbose()) {
             echo "The module is initialized for the entry point " . $entryPoint['file'] . ".\n";
         }
     }
     $install->save();
     // create a default controller
     if (!$this->getOption('-nocontroller')) {
         $agcommand = JelixScript::getCommand('createctrl', $this->config);
         $options = $this->getCommonActiveOption();
         if ($this->getOption('-cmdline')) {
             $options['-cmdline'] = true;
         }
         if ($this->getOption('-addinstallzone')) {
             $options['-addinstallzone'] = true;
         }
         $agcommand->initOptParam($options, array('module' => $module, 'name' => 'default', 'method' => 'index'));
         $agcommand->run();
     }
     if ($this->getOption('-admin')) {
         $this->createFile($path . 'classes/admin' . $module . '.listener.php', 'module/admin.listener.php.tpl', $param, "Listener");
         $this->createFile($path . 'events.xml', 'module/events.xml.tpl', $param);
         file_put_contents($path . 'locales/en_US/interface.UTF-8.properties', 'menu.item=' . $module);
         file_put_contents($path . 'locales/fr_FR/interface.UTF-8.properties', 'menu.item=' . $module);
     }
 }