/**
  * Get JSON containing all translation for a given jelix property file.
  * @param string $property Name of the property file. Ex: map if searched file is map.UTF-8.properties
  * @param string $lang Language. Ex: fr_FR (optional)
  * @return binary object The image for this project.
  */
 function getDictionary()
 {
     $rep = $this->getResponse('json');
     // Get the property file
     $property = $this->param('property');
     $lang = $this->param('lang');
     if (!$lang) {
         $lang = jLocale::getCurrentLang() . '_' . jLocale::getCurrentCountry();
     }
     $data = array();
     $path = jApp::appPath() . 'modules/view/locales/' . $lang . '/' . $property . '.UTF-8.properties';
     if (file_exists($path)) {
         $lines = file($path);
         foreach ($lines as $lineNumber => $lineContent) {
             if (!empty($lineContent) and $lineContent != '\\n') {
                 $exp = explode('=', trim($lineContent));
                 if (!empty($exp[0])) {
                     $data[$exp[0]] = jLocale::get('view~dictionnary.' . $exp[0], null, $lang);
                 }
             }
         }
     }
     $rep->data = $data;
     return $rep;
 }
 protected function _createPath()
 {
     if (!isset(jApp::config()->_modulesPathList[$this->module])) {
         throw new jExceptionSelector('jelix~errors.selector.module.unknown', $this->toString(true));
     }
     // we see if the forms have been redefined in var/
     $overloadedPath = jApp::varPath('overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix);
     if (is_readable($overloadedPath)) {
         $this->_path = $overloadedPath;
         $this->_where = 'var/';
         return;
     }
     // we see if the forms have been redefined in app/
     $overloadedPath = jApp::appPath('app/overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix);
     if (is_readable($overloadedPath)) {
         $this->_path = $overloadedPath;
         $this->_where = 'app/';
         return;
     }
     $this->_path = jApp::config()->_modulesPathList[$this->module] . $this->_dirname . $this->resource . $this->_suffix;
     if (!is_readable($this->_path)) {
         throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), $this->type));
     }
     $this->_where = 'modules/';
 }
 function atStart($config)
 {
     if ($config->sessions['storage'] == 'files') {
         $config->sessions['files_path'] = str_replace(array('lib:', 'app:'), array(LIB_PATH, jApp::appPath()), $config->sessions['files_path']);
     }
     $config->sessions['_class_to_load'] = array();
     if ($config->sessions['loadClasses'] != '') {
         trigger_error("Configuration: loadClasses is deprecated, use instead autoload configuration in module.xml files", E_USER_NOTICE);
         $list = preg_split('/ *, */', $config->sessions['loadClasses']);
         foreach ($list as $sel) {
             if (preg_match("/^([a-zA-Z0-9_\\.]+)~([a-zA-Z0-9_\\.\\/]+)\$/", $sel, $m)) {
                 if (!isset($config->_modulesPathList[$m[1]])) {
                     throw new Exception('Error in the configuration file -- in loadClasses parameter, ' . $m[1] . ' is not a valid or activated module');
                 }
                 if (($p = strrpos($m[2], '/')) !== false) {
                     $className = substr($m[2], $p + 1);
                     $subpath = substr($m[2], 0, $p + 1);
                 } else {
                     $className = $m[2];
                     $subpath = '';
                 }
                 $path = $config->_modulesPathList[$m[1]] . 'classes/' . $subpath . $className . '.class.php';
                 if (!file_exists($path) || strpos($subpath, '..') !== false) {
                     throw new Exception('Error in the configuration file -- in loadClasses parameter, bad class selector: ' . $sel);
                 }
                 $config->sessions['_class_to_load'][] = $path;
             } else {
                 throw new Exception('Error in the configuration file --  in loadClasses parameter, bad class selector: ' . $sel);
             }
         }
     }
 }
 protected function _createPath()
 {
     if (!isset(jApp::config()->_modulesPathList[$this->module])) {
         throw new jExceptionSelector('jelix~errors.selector.module.unknown', $this->toString());
     }
     // check if the dao was redefined (overloaded) in var/
     $overloadedPath = jApp::varPath('overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix);
     if (is_readable($overloadedPath)) {
         $this->_path = $overloadedPath;
         $this->_where = 'var/';
         return;
     }
     // check if the dao was redefined (overloaded) in app/
     $overloadedPath = jApp::appPath('app/overloads/' . $this->module . '/' . $this->_dirname . $this->resource . $this->_suffix);
     if (is_readable($overloadedPath)) {
         $this->_path = $overloadedPath;
         $this->_where = 'app/';
         return;
     }
     // else check if the module exists in the current module
     $this->_path = jApp::config()->_modulesPathList[$this->module] . $this->_dirname . $this->resource . $this->_suffix;
     if (!is_readable($this->_path)) {
         throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "dao"));
     }
     $this->_where = 'modules/';
 }
 function install()
 {
     $cmdFile = jApp::appPath('cmd.php');
     if (!file_exists($cmdFile)) {
         $content = "<" . "?php\n/**\n* @package  jelix\n* @author   Laurent Jouanneau\n* @contributor\n* @copyright 2011 Laurent Jouanneau\n* @link     http://jelix.org\n* @licence  http://www.gnu.org/licenses/gpl.html GNU General Public Licence, see LICENCE file\n*/\nrequire (dirname(__FILE__).'/application.init.php');\nrequire(LIB_PATH.'jelix-scripts/includes/cmd.inc.php');\n";
         file_put_contents($cmdFile, $content);
     }
 }
 function __construct($profile)
 {
     $this->profile = $profile;
     $prof = $profile;
     $user = '';
     $password = '';
     $dsn = '';
     if (isset($profile['dsn'])) {
         $this->dbms = substr($profile['dsn'], 0, strpos($profile['dsn'], ':'));
         $dsn = $profile['dsn'];
         unset($prof['dsn']);
         if ($this->dbms == 'sqlite') {
             $dsn = str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $dsn);
         }
     } else {
         $this->dbms = $profile['driver'];
         $db = $profile['database'];
         $dsn = $this->dbms . ':host=' . $profile['host'] . ';dbname=' . $db;
         if ($this->dbms != 'sqlite') {
             $dsn = $this->dbms . ':host=' . $profile['host'] . ';dbname=' . $db;
         } else {
             if (preg_match('/^(app|lib|var)\\:/', $db, $m)) {
                 $dsn = 'sqlite:' . str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $db);
             } else {
                 $dsn = 'sqlite:' . jApp::varPath('db/sqlite/' . $db);
             }
         }
     }
     if (isset($prof['usepdo'])) {
         unset($prof['usepdo']);
     }
     if (isset($prof['user'])) {
         $user = $prof['user'];
         unset($prof['user']);
     }
     if (isset($prof['password'])) {
         $password = $profile['password'];
         unset($prof['password']);
     }
     unset($prof['driver']);
     parent::__construct($dsn, $user, $password, $prof);
     $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('jDbPDOResultSet'));
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     if ($this->dbms == 'mysql') {
         $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
     }
     if ($this->dbms == 'oci') {
         $this->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
     }
     if (isset($prof['force_encoding']) && $prof['force_encoding'] == true) {
         $charset = jApp::config()->charset;
         if ($this->dbms == 'mysql' && isset($this->_mysqlCharsets[$charset])) {
             $this->exec("SET NAMES '" . $this->_mysqlCharsets[$charset] . "'");
         } elseif ($this->dbms == 'pgsql' && isset($this->_pgsqlCharsets[$charset])) {
             $this->exec("SET client_encoding to '" . $this->_pgsqlCharsets[$charset] . "'");
         }
     }
 }
Exemple #7
0
 function testContext()
 {
     $appPath = jApp::appPath();
     $varPath = jApp::varPath();
     $logPath = jApp::logPath();
     $configPath = jApp::configPath();
     $wwwPath = jApp::wwwPath();
     $scriptsPath = jApp::scriptsPath();
     $tempPath = jApp::tempPath();
     // first save
     jApp::saveContext();
     // verify that we still have the current path
     $this->assertEquals($appPath, jApp::appPath());
     $this->assertEquals($varPath, jApp::varPath());
     $this->assertEquals($logPath, jApp::logPath());
     $this->assertEquals($configPath, jApp::configPath());
     $this->assertEquals($wwwPath, jApp::wwwPath());
     $this->assertEquals($scriptsPath, jApp::scriptsPath());
     $this->assertEquals($tempPath, jApp::tempPath());
     // change the path
     jApp::initPaths('/myapp/');
     $this->assertEquals('/myapp/', jApp::appPath());
     $this->assertEquals('/myapp/var/', jApp::varPath());
     $this->assertEquals('/myapp/var/log/', jApp::logPath());
     $this->assertEquals('/myapp/var/config/', jApp::configPath());
     $this->assertEquals('/myapp/www/', jApp::wwwPath());
     $this->assertEquals('/myapp/scripts/', jApp::scriptsPath());
     $this->assertEquals($tempPath, jApp::tempPath());
     // second save
     jApp::saveContext();
     jApp::initPaths('/myapp2/');
     $this->assertEquals('/myapp2/', jApp::appPath());
     $this->assertEquals('/myapp2/var/', jApp::varPath());
     $this->assertEquals('/myapp2/var/log/', jApp::logPath());
     $this->assertEquals('/myapp2/var/config/', jApp::configPath());
     $this->assertEquals('/myapp2/www/', jApp::wwwPath());
     $this->assertEquals('/myapp2/scripts/', jApp::scriptsPath());
     $this->assertEquals($tempPath, jApp::tempPath());
     // pop the second save, we should be with the first saved values
     jApp::restoreContext();
     $this->assertEquals('/myapp/', jApp::appPath());
     $this->assertEquals('/myapp/var/', jApp::varPath());
     $this->assertEquals('/myapp/var/log/', jApp::logPath());
     $this->assertEquals('/myapp/var/config/', jApp::configPath());
     $this->assertEquals('/myapp/www/', jApp::wwwPath());
     $this->assertEquals('/myapp/scripts/', jApp::scriptsPath());
     $this->assertEquals($tempPath, jApp::tempPath());
     // pop the first save, we should be with initial paths
     jApp::restoreContext();
     $this->assertEquals($appPath, jApp::appPath());
     $this->assertEquals($varPath, jApp::varPath());
     $this->assertEquals($logPath, jApp::logPath());
     $this->assertEquals($configPath, jApp::configPath());
     $this->assertEquals($wwwPath, jApp::wwwPath());
     $this->assertEquals($scriptsPath, jApp::scriptsPath());
     $this->assertEquals($tempPath, jApp::tempPath());
 }
 protected function _connect()
 {
     $db = $this->profile['database'];
     if (preg_match('/^(app|lib|var)\\:/', $db)) {
         $path = str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $db);
     } else {
         $path = jApp::varPath('db/sqlite3/' . $db);
     }
     return new SQLite3($path);
 }
 public function getInfo()
 {
     $file = jApp::appPath('project.xml');
     if (!file_exists($file)) {
         return null;
     }
     $project = new projectinfo();
     $project = $this->parse($file, $project);
     return $project;
 }
Exemple #10
0
 /**
  * initialize the application paths
  *
  * Warning: given paths should be ended by a directory separator.
  * @param string $appPath  application directory
  * @param string $wwwPath  www directory
  * @param string $varPath  var directory
  * @param string $logPath log directory
  * @param string $configPath config directory
  * @param string $scriptPath scripts directory
  */
 public static function initPaths($appPath, $wwwPath = null, $varPath = null, $logPath = null, $configPath = null, $scriptPath = null)
 {
     self::$appPath = $appPath;
     self::$wwwPath = is_null($wwwPath) ? $appPath . 'www/' : $wwwPath;
     self::$varPath = is_null($varPath) ? $appPath . 'var/' : $varPath;
     self::$logPath = is_null($logPath) ? self::$varPath . 'log/' : $logPath;
     self::$configPath = is_null($configPath) ? self::$varPath . 'config/' : $configPath;
     self::$scriptPath = is_null($scriptPath) ? $appPath . 'scripts/' : $scriptPath;
     self::$_isInit = true;
 }
 public function testBundleUnknownFile()
 {
     $this->filePath = jApp::appPath() . 'modules/jelix_tests/locales/';
     $b = new bundleTest('', '');
     try {
         $b->readProperties($this->filePath . 'unknownfile');
         $this->fail('should throw an exception when trying reading unknownfile');
     } catch (Exception $e) {
         $this->assertTrue($e->getMessage() == 'Cannot load the resource ' . $this->filePath . 'unknownfile', 'should throw the right exception when trying reading unknownfile (wrong message: ' . $e->getMessage() . ')');
     }
 }
 /**
  * Display a summary of the information taken from the ~ configuration file.
  *
  * @return Administration backend for the repositories.
  */
 function index()
 {
     $rep = $this->getResponse('html');
     // Get repository data
     $repository = $this->param('repository');
     // Get rights for repositories per subject and groups
     $cnx = jDb::getConnection('jacl2_profile');
     $repositories = array();
     $data = array();
     foreach (lizmap::getRepositoryList() as $repo) {
         //$sql = " SELECT r.id_aclsbj, group_concat(g.name, ' - ') AS group_names";
         $sql = " SELECT r.id_aclsbj, g.name AS group_name";
         $sql .= " FROM jacl2_rights r";
         $sql .= " INNER JOIN jacl2_group g ON r.id_aclgrp = g.id_aclgrp";
         $sql .= " WHERE g.grouptype = 0 AND r.id_aclgrp NOT IN ('" . implode("','", $this->groupBlacklist) . "')";
         $sql .= " AND id_aclres=" . $cnx->quote($repo);
         //$sql.= " GROUP BY r.id_aclsbj;";
         $sql .= " ORDER BY g.name";
         $rights = $cnx->query($sql);
         $group_names = array();
         foreach ($rights as $r) {
             if (!array_key_exists($r->id_aclsbj, $group_names)) {
                 $group_names[$r->id_aclsbj] = array();
             }
             $group_names[$r->id_aclsbj][] = $r->group_name;
         }
         foreach ($group_names as $k => $v) {
             $group_names[$k] = implode(' - ', $v);
         }
         $rights = (object) $group_names;
         $repositories[] = lizmap::getRepository($repo);
         $data[$repo] = $rights;
     }
     // Subjects labels
     $labels = array();
     $daosubject = jDao::get('jacl2db~jacl2subject', 'jacl2_profile');
     foreach ($daosubject->findAllSubject() as $subject) {
         $labels[$subject->id_aclsbj] = $this->getLabel($subject->id_aclsbj, $subject->label_key);
     }
     // Get Lizmap version from project.xml
     $xmlPath = jApp::appPath('project.xml');
     $xmlLoad = simplexml_load_file($xmlPath);
     $version = (string) $xmlLoad->info->version;
     $tpl = new jTpl();
     $tpl->assign('services', lizmap::getServices());
     $tpl->assign('repositories', $repositories);
     $tpl->assign('data', $data);
     $tpl->assign('labels', $labels);
     $tpl->assign('version', $version);
     $rep->body->assign('MAIN', $tpl->fetch('config'));
     $rep->body->assign('selectedMenuItem', 'lizmap_configuration');
     return $rep;
 }
 /**
  * initialize the application paths
  *
  * Warning: given paths should be ended by a directory separator.
  * @param string $appPath  application directory
  * @param string $wwwPath  www directory
  * @param string $varPath  var directory
  * @param string $logPath log directory
  * @param string $configPath config directory
  * @param string $scriptPath scripts directory
  */
 public static function initPaths($appPath, $wwwPath = null, $varPath = null, $logPath = null, $configPath = null, $scriptPath = null)
 {
     self::$appPath = $appPath;
     self::$wwwPath = is_null($wwwPath) ? $appPath . 'www/' : $wwwPath;
     self::$varPath = is_null($varPath) ? $appPath . 'var/' : $varPath;
     self::$logPath = is_null($logPath) ? self::$varPath . 'log/' : $logPath;
     self::$configPath = is_null($configPath) ? self::$varPath . 'config/' : $configPath;
     self::$scriptPath = is_null($scriptPath) ? $appPath . 'scripts/' : $scriptPath;
     self::$_isInit = true;
     self::$_coord = null;
     self::$_config = null;
     self::$configAutoloader = null;
     self::$_mainConfigFile = null;
 }
 protected function _connect()
 {
     $funcconnect = isset($this->profile['persistent']) && $this->profile['persistent'] ? 'sqlite_popen' : 'sqlite_open';
     $db = $this->profile['database'];
     if (preg_match('/^(app|lib|var)\\:/', $db)) {
         $path = str_replace(array('app:', 'lib:', 'var:'), array(jApp::appPath(), LIB_PATH, jApp::varPath()), $db);
     } else {
         $path = jApp::varPath('db/sqlite/' . $db);
     }
     if ($cnx = @$funcconnect($path)) {
         return $cnx;
     } else {
         throw new jException('jelix~db.error.connection', $db);
     }
 }
 /**
  * load the content of the project.xml file, and store the corresponding DOM
  * into the $projectXml property
  */
 protected function loadProjectXml()
 {
     $doc = new DOMDocument();
     if (!$doc->load(jApp::appPath($this->projectXmlFilename))) {
         throw new Exception("cannot load " . $this->projectXmlFilename);
     }
     $root = $doc->documentElement;
     if ($root->namespaceURI != JELIX_NAMESPACE_BASE . 'project/1.0') {
         throw new Exception("bad namespace in " . $this->projectXmlFilename);
     }
     $info = $root->getElementsByTagName("info");
     if ($info->length && $info->item(0)->hasAttribute('name')) {
         $this->appName = $info->item(0)->getAttribute('name');
     }
     $this->projectXml = $doc;
 }
 function unpackUpdate($file)
 {
     $zip = new ZipArchive();
     $zip->open($file);
     //$zip->extractTo(jApp::appPath());
     jLog::dump(jApp::appPath());
     $src = jApp::appPath() . 'var/uploads/' . uniqid();
     $zip->extractTo($src);
     //modules bos
     copy($src . '/project.xml', jApp::appPath() . 'project.xml');
     copy($src . '/responses/myHtmlResponse.class.php', jApp::appPath() . 'responses/myHtmlResponse.class.php');
     copy($src . '/responses/myJsResponse.class.php', jApp::appPath() . 'responses/myJsResponse.class.php');
     copy($src . '/modules/extension/', jApp::appPath() . 'modules/extension/');
     copy($src . '/modules/user/', jApp::appPath() . 'modules/user/');
     copy($src . '/modules/bos/', jApp::appPath() . 'modules/bos/');
     copy($src . '/modules/chat/', jApp::appPath() . 'modules/chat/');
 }
 /**
  * Returns Lizmap Web Client version
  *
  * @return Json containing application information.
  */
 function metadata()
 {
     $rep = $this->getResponse('json');
     $data = array();
     // Get Lizmap version from project.xml
     $xmlPath = jApp::appPath('project.xml');
     $xmlLoad = simplexml_load_file($xmlPath);
     // Version
     $data['info'] = array();
     $data['info']['version'] = (string) $xmlLoad->info->version;
     $data['info']['date'] = (string) $xmlLoad->info->version->attributes()->date;
     // Dependencies
     $data['dependencies'] = array();
     $data['dependencies']['jelix'] = array();
     $data['dependencies']['jelix']['minversion'] = (string) $xmlLoad->dependencies->jelix->attributes()->minversion;
     $data['dependencies']['jelix']['maxversion'] = (string) $xmlLoad->dependencies->jelix->attributes()->maxversion;
     $rep->data = $data;
     return $rep;
 }
 /**
  * get all physical paths of responses file
  */
 protected function _initResponsesPath($config, $list)
 {
     $copylist = $config->{$list};
     // because we modify $list and then it will search for "foo.path" responses...
     foreach ($copylist as $type => $class) {
         if (strpos($class, 'app:') === 0) {
             $config->{$list}[$type] = $class = substr($class, 4);
             $config->{$list}[$type . '.path'] = $path = jApp::appPath('responses/' . $class . '.class.php');
             if (file_exists($path)) {
                 continue;
             }
         } else {
             if (preg_match('@^(?:module:)?([^~]+)~(.+)$@', $class, $m)) {
                 $mod = $m[1];
                 if (isset($config->_modulesPathList[$mod])) {
                     $class = $m[2];
                     $path = $config->_modulesPathList[$mod] . 'responses/' . $class . '.class.php';
                     $config->{$list}[$type] = $class;
                     $config->{$list}[$type . '.path'] = $path;
                     if (file_exists($path)) {
                         continue;
                     }
                 } else {
                     $path = $class;
                 }
             } else {
                 if (file_exists($path = JELIX_LIB_CORE_PATH . 'response/' . $class . '.class.php')) {
                     $config->{$list}[$type . '.path'] = $path;
                     continue;
                 } else {
                     if (file_exists($path = jApp::appPath('responses/' . $class . '.class.php'))) {
                         $config->{$list}[$type . '.path'] = $path;
                         continue;
                     }
                 }
             }
         }
         throw new Exception('Error in main configuration on responses parameters -- the class file of the response type "' . $type . '" is not found (' . $path . ')', 12);
     }
 }
 /**
  * output errors
  */
 public function outputErrors()
 {
     if (file_exists(jApp::appPath('app/responses/error.en_US.php'))) {
         $file = jApp::appPath('app/responses/error.en_US.php');
     } else {
         $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
     }
     // we erase already generated content
     $this->_headTop = array();
     $this->_headBottom = array();
     $this->_bodyBottom = array();
     $this->_bodyTop = array();
     jLog::outputLog($this);
     foreach ($this->plugins as $name => $plugin) {
         $plugin->beforeOutputError();
     }
     $HEADTOP = implode("\n", $this->_headTop);
     $HEADBOTTOM = implode("\n", $this->_headBottom);
     $BODYTOP = implode("\n", $this->_bodyTop);
     $BODYBOTTOM = implode("\n", $this->_bodyBottom);
     $BASEPATH = jApp::urlBasePath();
     header("HTTP/{$this->httpVersion} 500 Internal jelix error");
     header('Content-Type: text/html;charset=' . $this->_charset);
     include $file;
 }
Exemple #20
0
 protected function updateModulePath($ini, $currentModulesPath, $repository, $repositoryPath)
 {
     $listRepos = preg_split('/ *, */', $currentModulesPath);
     $repositoryFound = false;
     foreach ($listRepos as $path) {
         if (trim($path) == '') {
             continue;
         }
         $p = str_replace(array('lib:', 'app:'), array(LIB_PATH, jApp::appPath()), $path);
         if (substr($p, -1) != '/') {
             $p .= '/';
         }
         if ($p == $repositoryPath) {
             $repositoryFound = true;
             break;
         }
     }
     // the repository doesn't exist in the configuration
     // let's add it into the configuration
     if (!$repositoryFound) {
         $ini->setValue('modulesPath', $currentModulesPath . ',' . $repository);
         $ini->save();
         $this->createDir($repositoryPath);
     }
 }
Exemple #21
0
/**
 * check if the application is opened. If not, it displays the yourapp/install/closed.html
 * file with a http error (or lib/jelix/installer/closed.html), and exit.
 * This function should be called in all entry point, before the creation of the coordinator.
 * @see jAppManager
 * @todo migrate the code to jAppManager or jApp
 */
function checkAppOpened()
{
    if (!jApp::isInit()) {
        header("HTTP/1.1 500 Application not available");
        header('Content-type: text/html');
        echo "checkAppOpened: jApp is not initialized!";
        exit(1);
    }
    if (file_exists(jApp::configPath('CLOSED'))) {
        $message = file_get_contents(jApp::configPath('CLOSED'));
        if (jServer::isCLI()) {
            echo "Application closed." . ($message ? "\n{$message}\n" : "\n");
            exit(1);
        }
        if (file_exists(jApp::appPath('install/closed.html'))) {
            $file = jApp::appPath('install/closed.html');
        } else {
            $file = JELIX_LIB_PATH . 'installer/closed.html';
        }
        header("HTTP/1.1 500 Application not available");
        header('Content-type: text/html');
        echo str_replace('%message%', $message, file_get_contents($file));
        exit(1);
    }
}
Exemple #22
0
 public function run()
 {
     $this->loadAppConfig();
     $entrypoint = $this->getParam('entrypoint');
     if (($p = strpos($entrypoint, '.php')) !== false) {
         $entrypoint = substr($entrypoint, 0, $p);
     }
     $ep = $this->getEntryPointInfo($entrypoint);
     if ($ep == null) {
         try {
             $cmd = JelixScript::getCommand('createentrypoint', $this->config);
             $cmd->initOptParam(array(), array('name' => $entrypoint));
             $cmd->run();
             $this->projectXml = null;
             $ep = $this->getEntryPointInfo($entrypoint);
         } catch (Exception $e) {
             throw new Exception("The entrypoint has not been created because of this error: " . $e->getMessage() . ". No other files have been created.\n");
         }
     }
     $installConfig = new jIniFileModifier(jApp::configPath('installer.ini.php'));
     $inifile = new jIniMultiFilesModifier(jApp::configPath('defaultconfig.ini.php'), jApp::configPath($ep['config']));
     $params = array();
     $this->createFile(jApp::appPath('responses/adminHtmlResponse.class.php'), 'responses/adminHtmlResponse.class.php.tpl', $params);
     $this->createFile(jApp::appPath('responses/adminLoginHtmlResponse.class.php'), 'responses/adminLoginHtmlResponse.class.php.tpl', $params);
     $inifile->setValue('html', 'adminHtmlResponse', 'responses');
     $inifile->setValue('htmlauth', 'adminLoginHtmlResponse', 'responses');
     $inifile->setValue('startModule', 'master_admin');
     $inifile->setValue('startAction', 'default:index');
     $modulePath = $inifile->getValue("modulesPath", 0, null, true);
     if (strpos($modulePath, 'lib:jelix-admin-modules') === false) {
         // we set it on defaultconfig.ini.php, so if the url engine is "significant"
         // it could know the admin modules during the parsing of modules
         $inifile->setValue('modulesPath', 'lib:jelix-admin-modules/,' . $modulePath, 0, null, true);
     }
     $installConfig->setValue('jacldb.installed', '0', $entrypoint);
     $inifile->setValue('jacldb.access', '0', 'modules');
     $installConfig->setValue('junittests.installed', '0', $entrypoint);
     $inifile->setValue('junittests.access', '0', 'modules');
     $installConfig->setValue('jWSDL.installed', '0', $entrypoint);
     $inifile->setValue('jWSDL.access', '0', 'modules');
     $urlconf = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints', null, true);
     if ($urlconf === null || $urlconf == '') {
         // in defaultconfig
         $inifile->setValue($entrypoint, 'jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic', 'simple_urlengine_entrypoints', null, true);
         // in the config of the entry point
         $inifile->setValue($entrypoint, 'jacl2db~*@classic, jauth~*@classic, jacl2db_admin~*@classic, jauthdb_admin~*@classic, master_admin~*@classic', 'simple_urlengine_entrypoints');
     } else {
         $urlconf2 = $inifile->getValue($entrypoint, 'simple_urlengine_entrypoints');
         if (strpos($urlconf, 'jacl2db_admin~*@classic') === false) {
             $urlconf .= ',jacl2db_admin~*@classic';
         }
         if (strpos($urlconf, 'jauthdb_admin~*@classic') === false) {
             $urlconf .= ',jauthdb_admin~*@classic';
         }
         if (strpos($urlconf, 'master_admin~*@classic') === false) {
             $urlconf .= ',master_admin~*@classic';
         }
         if (strpos($urlconf2, 'jacl2db_admin~*@classic') === false) {
             $urlconf2 .= ',jacl2db_admin~*@classic';
         }
         if (strpos($urlconf2, 'jauthdb_admin~*@classic') === false) {
             $urlconf2 .= ',jauthdb_admin~*@classic';
         }
         if (strpos($urlconf2, 'master_admin~*@classic') === false) {
             $urlconf2 .= ',master_admin~*@classic';
         }
         if (strpos($urlconf2, 'jacl2db~*@classic') === false) {
             $urlconf2 .= ',jacl2db~*@classic';
         }
         if (strpos($urlconf2, 'jauth~*@classic') === false) {
             $urlconf2 .= ',jauth~*@classic';
         }
         $inifile->setValue($entrypoint, $urlconf, 'simple_urlengine_entrypoints', null, true);
         $inifile->setValue($entrypoint, $urlconf2, 'simple_urlengine_entrypoints');
     }
     if (null == $inifile->getValue($entrypoint, 'basic_significant_urlengine_entrypoints', null, true)) {
         $inifile->setValue($entrypoint, '1', 'basic_significant_urlengine_entrypoints', null, true);
     }
     $inifile->save();
     require_once JELIX_LIB_PATH . 'installer/jInstaller.class.php';
     $verbose = $this->getOption("-v");
     $reporter = new textInstallReporter($verbose ? 'notice' : 'warning');
     $installer = new jInstaller($reporter);
     $installer->installModules(array('master_admin'), $entrypoint . '.php');
     $authini = new jIniFileModifier(jApp::configPath($entrypoint . '/auth.coord.ini.php'));
     $authini->setValue('after_login', 'master_admin~default:index');
     $authini->setValue('timeout', '30');
     $authini->save();
     $profile = $this->getOption('-profile');
     if (!$this->getOption('-noauthdb')) {
         if ($profile != '') {
             $authini->setValue('profile', $profile, 'Db');
         }
         $authini->save();
         $installer->setModuleParameters('jauthdb', array('defaultuser' => true));
         $installer->installModules(array('jauthdb', 'jauthdb_admin'), $entrypoint . '.php');
     } else {
         $installConfig->setValue('jauthdb_admin.installed', '0', $entrypoint);
         $installConfig->save();
         $inifile->setValue('jauthdb_admin.access', '0', 'modules');
         $inifile->save();
     }
     if (!$this->getOption('-noacl2db')) {
         if ($profile != '') {
             $dbini = new jIniFileModifier(jApp::configPath('profiles.ini.php'));
             $dbini->setValue('jacl2_profile', $profile, 'jdb');
             $dbini->save();
         }
         $installer = new jInstaller($reporter);
         $installer->setModuleParameters('jacl2db', array('defaultuser' => true));
         $installer->installModules(array('jacl2db', 'jacl2db_admin'), $entrypoint . '.php');
     } else {
         $installConfig->setValue('jacl2db_admin.installed', '0', $entrypoint);
         $installConfig->save();
         $inifile->setValue('jacl2db_admin.access', '0', 'modules');
         $inifile->save();
     }
 }
 /**
  * get all physical paths of responses file
  */
 private static function _initResponsesPath(&$list)
 {
     $copylist = $list;
     // because we modify $list and then it will search for "foo.path" responses...
     foreach ($copylist as $type => $class) {
         if (file_exists($path = JELIX_LIB_CORE_PATH . 'response/' . $class . '.class.php')) {
             $list[$type . '.path'] = $path;
         } elseif (file_exists($path = jApp::appPath('responses/' . $class . '.class.php'))) {
             $list[$type . '.path'] = $path;
         } else {
             throw new Exception('Configuration Error: the class file of the response type "' . $type . '" is not found (' . $path . ')', 12);
         }
     }
 }
 static function handleError($type, $code, $message, $file, $line, $trace)
 {
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     // for non fatal error appeared during init, let's just store it for loggers later
     if ($type != 'error') {
         self::$initErrorMessages[] = $errorLog;
         return;
     } else {
         if (jServer::isCLI()) {
             // fatal error appeared during init, in a CLI context
             while (ob_get_level() && @ob_end_clean()) {
             }
             // log into file and output message in the console
             echo 'Error during initialization: \\n';
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
                 echo '* ' . $err->getMessage() . ' (' . $err->getFile() . ' ' . $err->getLine() . ")\n";
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             echo '* ' . $message . ' (' . $file . ' ' . $line . ")\n";
         } else {
             // fatal error appeared during init, let's display an HTML page
             // since we don't know the request, we cannot return a response
             // corresponding to the expected protocol
             while (ob_get_level() && @ob_end_clean()) {
             }
             // log into file
             foreach (self::$initErrorMessages as $err) {
                 @error_log($err->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             }
             @error_log($errorLog->getFormatedMessage() . "\n", 3, jApp::logPath('errors.log'));
             $msg = $errorLog->getMessage();
             if (strpos($msg, '--') !== false) {
                 list($msg, $bin) = explode('--', $msg, 2);
                 // remove confidential data
             }
             // if accept text/html
             if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
                 if (file_exists(jApp::appPath('responses/error.en_US.php'))) {
                     $file = jApp::appPath('responses/error.en_US.php');
                 } else {
                     $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
                 }
                 $HEADTOP = '';
                 $HEADBOTTOM = '';
                 $BODYTOP = '';
                 $BODYBOTTOM = htmlspecialchars($msg);
                 $BASEPATH = jApp::urlBasePath();
                 if ($BASEPATH == '') {
                     $BASEPATH = '/';
                 }
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/html');
                 include $file;
             } else {
                 // output text response
                 header("HTTP/1.1 500 Internal jelix error");
                 header('Content-type: text/plain');
                 echo 'Error during initialization. ' . $msg;
             }
         }
     }
     exit(1);
 }
 /**
  * load the content of the project.xml file, and store the corresponding DOM
  * into the $projectXml property
  */
 protected function loadProjectXml()
 {
     if ($this->projectXml) {
         return;
     }
     $doc = new DOMDocument();
     if (!$doc->load(jApp::appPath('project.xml'))) {
         throw new Exception("cannot load project.xml");
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'project/1.0') {
         throw new Exception("bad namespace in project.xml");
     }
     $this->projectXml = $doc;
 }
 /**
  * returns html formated stack trace
  * @param array $trace
  * @return string
  */
 function formatTrace($trace)
 {
     $html = '<table>';
     foreach ($trace as $k => $t) {
         if (isset($t['file'])) {
             $file = $t['file'];
             $path = '';
             $shortcut = '';
             if (strpos($file, LIB_PATH) === 0) {
                 $path = LIB_PATH;
                 $shortcut = 'lib:';
             } elseif (strpos($file, jApp::tempPath()) === 0) {
                 $path = jApp::tempPath();
                 $shortcut = 'temp:';
             } elseif (strpos($file, jApp::appPath()) === 0) {
                 $path = jApp::appPath();
                 $shortcut = 'app:';
             } else {
                 $path = dirname(jApp::appPath());
                 $shortcut = 'app:';
                 while ($path != '.' && $path != '') {
                     $shortcut .= '../';
                     if (strpos($file, $path) === 0) {
                         break;
                     }
                     $path = dirname($path);
                 }
                 if ($path == '.') {
                     $path = '';
                 }
             }
             if ($path != '') {
                 $cut = $path[0] == '/' ? 0 : 1;
                 $file = '<i>' . $shortcut . '</i>' . substr($file, strlen($path) + $cut);
             }
         } else {
             $file = '[php]';
         }
         $html .= '<tr><td>' . $k . '</td><td>' . (isset($t['class']) ? $t['class'] . $t['type'] : '') . $t['function'] . '()</td>';
         $html .= '<td>' . $file . '</td><td>' . (isset($t['line']) ? $t['line'] : '') . '</td></tr>';
     }
     $html .= '</table>';
     return $html;
 }
Exemple #27
0
 /**
  * retrieve all modules specifications
  */
 private function getModulesPath($modulesPath, $defaultAccess)
 {
     $list = preg_split('/ *, */', $modulesPath);
     array_unshift($list, JELIX_LIB_PATH . 'core-modules/');
     $modulesPathList = array();
     foreach ($list as $k => $path) {
         if (trim($path) == '') {
             continue;
         }
         $p = str_replace(array('lib:', 'app:'), array(LIB_PATH, jApp::appPath()), $path);
         if (!file_exists($p)) {
             throw new Exception('The path, ' . $path . ' given in the jelix config, doesn\'t exists !', E_USER_ERROR);
         }
         if (substr($p, -1) != '/') {
             $p .= '/';
         }
         $this->moduleRepositories[$p] = array();
         if ($handle = opendir($p)) {
             while (false !== ($f = readdir($handle))) {
                 if ($f[0] != '.' && is_dir($p . $f)) {
                     $m = new migrateModuleInfo();
                     $m->path = $p . $f . '/';
                     $m->name = $f;
                     $m->access = $f == 'jelix' ? 2 : $defaultAccess;
                     $m->repository = $p;
                     $modulesPathList[$f] = $m;
                     $this->moduleRepositories[$p][$f] = $m;
                 }
             }
             closedir($handle);
         }
     }
     return $modulesPathList;
 }
Exemple #28
0
 /**
  * Handle an error event. Called by error handler and exception handler.
  * @param string  $type    error type : 'error', 'warning', 'notice'
  * @param integer $code    error code
  * @param string  $message error message
  * @param string  $file    the file name where the error appear
  * @param integer $line    the line number where the error appear
  * @param array   $trace   the stack trace
  * @since 1.1
  */
 public function handleError($type, $code, $message, $file, $line, $trace)
 {
     global $gJConfig;
     $errorLog = new jLogErrorMessage($type, $code, $message, $file, $line, $trace);
     if ($this->request) {
         // we have config, so we can process "normally"
         $errorLog->setFormat($gJConfig->error_handling['messageLogFormat']);
         jLog::log($errorLog, $type);
         // if non fatal error, it is finished
         if ($type != 'error') {
             return;
         }
         $this->errorMessage = $errorLog;
         while (ob_get_level()) {
             ob_end_clean();
         }
         $resp = $this->request->getErrorResponse($this->response);
         $resp->outputErrors();
         jSession::end();
     } elseif ($type != 'error') {
         $this->initErrorMessages[] = $errorLog;
         return;
     } else {
         // fatal error appeared during init, let's display an HTML page
         // since we don't know the request, we cannot return a response
         // corresponding to the expected protocol
         while (ob_get_level()) {
             ob_end_clean();
         }
         // log into file
         @error_log($errorLog->getFormatedMessage(), 3, jApp::logPath('errors.log'));
         // if accept text/html
         if (isset($_SERVER['HTTP_ACCEPT']) && strstr($_SERVER['HTTP_ACCEPT'], 'text/html')) {
             if (file_exists(jApp::appPath('responses/error.en_US.php'))) {
                 $file = jApp::appPath('responses/error.en_US.php');
             } else {
                 $file = JELIX_LIB_CORE_PATH . 'response/error.en_US.php';
             }
             $HEADBOTTOM = '';
             $BODYTOP = '';
             $BODYBOTTOM = '';
             $basePath = '';
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/html');
             include $file;
         } else {
             // output text response
             header("HTTP/1.1 500 Internal jelix error");
             header('Content-type: text/plain');
             echo 'Error during initialization.';
         }
     }
     exit(1);
 }
 public static function computeUrlFilePath($config = null)
 {
     $basePath = jApp::config()->urlengine['basePath'];
     if (!$config) {
         $config =& jApp::config()->imagemodifier;
     }
     if ($config['src_url'] && $config['src_path']) {
         $srcUri = $config['src_url'];
         if ($srcUri[0] != '/' && strpos($srcUri, 'http:') !== 0) {
             $srcUri = $basePath . $srcUri;
         }
         $srcPath = str_replace(array('www:', 'app:'), array(jApp::wwwPath(), jApp::appPath()), $config['src_path']);
     } else {
         $srcUri = jApp::coord()->request->getServerURI() . $basePath;
         $srcPath = jApp::wwwPath();
     }
     if ($config['cache_path'] && $config['cache_url']) {
         $cacheUri = $config['cache_url'];
         if ($cacheUri[0] != '/' && strpos($cacheUri, 'http:') !== 0) {
             $cacheUri = $basePath . $cacheUri;
         }
         $cachePath = str_replace(array('www:', 'app:'), array(jApp::wwwPath(), jApp::appPath()), $config['cache_path']);
     } else {
         $cachePath = jApp::wwwPath('cache/images/');
         $cacheUri = jApp::coord()->request->getServerURI() . $basePath . 'cache/images/';
     }
     return array($srcPath, $srcUri, $cachePath, $cacheUri);
 }
 /**
  * fill some properties from informations stored into the project.xml file.
  * @return string the application name
  */
 function loadFromProject()
 {
     $doc = new DOMDocument();
     if (!$doc->load(jApp::appPath('project.xml'))) {
         throw new Exception("cannot load project.xml");
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'project/1.0') {
         throw new Exception("bad namespace in project.xml");
     }
     $info = $doc->getElementsByTagName('info');
     $info = $info->item(0);
     $id = $info->getAttribute('id');
     list($name, $suffix) = explode('@', $id);
     if ($suffix == '') {
         $suffix = $name;
     }
     $this->infoIDSuffix = $suffix;
     if ($info->getAttribute('name')) {
         $name = $info->getAttribute('name');
     }
     $licence = $info->getElementsByTagName('licence');
     if ($licence->length) {
         $licence = $licence->item(0);
         $this->infoLicence = $licence->textContent;
         $this->infoLicenceUrl = $licence->getAttribute('URL');
     }
     $copyright = $info->getElementsByTagName('copyright');
     if ($copyright->length) {
         $copyright = $copyright->item(0);
         $this->infoCopyright = $copyright->textContent;
     }
     $website = $info->getElementsByTagName('homepageURL');
     if ($website->length) {
         $website = $website->item(0);
         $this->infoWebsite = $website->textContent;
     }
     return $name;
 }