Ejemplo n.º 1
0
 /**
  * Prepares a new stream.
  *
  * @param string $path    Virtual path which should describe the content (e.g. "template/1"), only relevant for error messages
  * @param string $content Content which will be included
  *
  * @throws InvalidArgumentException
  *
  * @return string Full path with protocol (e.g. "rex:///template/1")
  */
 public static function factory($path, $content)
 {
     if (!is_string($path) || empty($path)) {
         throw new InvalidArgumentException('Expecting $path to be a string and not empty!');
     }
     if (!is_string($content)) {
         throw new InvalidArgumentException('Expecting $content to be a string!');
     }
     if (null === self::$useRealFiles) {
         self::$useRealFiles = extension_loaded('suhosin') && !preg_match('/(?:^|,)rex(?::|,|$)/', ini_get('suhosin.executor.include.whitelist'));
     }
     if (self::$useRealFiles) {
         $hash = substr(sha1($content), 0, 7);
         $path = rex_path::coreCache('stream/' . $path . '/' . $hash);
         if (!file_exists($path)) {
             rex_file::put($path, $content);
         }
         return $path;
     }
     if (!self::$registered) {
         stream_wrapper_register('rex', __CLASS__);
         self::$registered = true;
     }
     // 3 slashes needed to sidestep some server url include protections
     // example: https://www.strato.de/faq/article/622/Warum-erhalte-ich-über-PHP-die-Fehlermeldung-%22Warning:-main()-…:-include(….).html
     $path = 'rex:///' . $path;
     self::$nextContent[$path] = $content;
     return $path;
 }
Ejemplo n.º 2
0
 /**
  * Prepares a new stream.
  *
  * @param string $path    Virtual path which should describe the content (e.g. "template/1"), only relevant for error messages
  * @param string $content Content which will be included
  *
  * @throws InvalidArgumentException
  *
  * @return string Full path with protocol (e.g. "rex://template/1")
  */
 public static function factory($path, $content)
 {
     if (!is_string($path) || empty($path)) {
         throw new InvalidArgumentException('Expecting $path to be a string and not empty!');
     }
     if (!is_string($content)) {
         throw new InvalidArgumentException('Expecting $content to be a string!');
     }
     if (null === self::$useRealFiles) {
         self::$useRealFiles = extension_loaded('suhosin') && !preg_match('/(?:^|,)rex(?::|,|$)/', ini_get('suhosin.executor.include.whitelist'));
     }
     if (self::$useRealFiles) {
         $hash = substr(sha1($content), 0, 7);
         $path = rex_path::coreCache('stream/' . $path . '/' . $hash);
         if (!file_exists($path)) {
             rex_file::put($path, $content);
         }
         return $path;
     }
     if (!self::$registered) {
         stream_wrapper_register('rex', __CLASS__);
         self::$registered = true;
     }
     $path = 'rex://' . $path;
     self::$nextContent[$path] = $content;
     return $path;
 }
Ejemplo n.º 3
0
 /**
  * Register rex_autoload in spl autoloader.
  */
 public static function register()
 {
     if (self::$registered) {
         return;
     }
     ini_set('unserialize_callback_func', 'spl_autoload_call');
     if (!self::$composerLoader) {
         self::$composerLoader = (require rex_path::core('vendor/autoload.php'));
         // Unregister Composer Autoloader because we call self::$composerLoader->loadClass() manually
         self::$composerLoader->unregister();
     }
     if (false === spl_autoload_register([__CLASS__, 'autoload'])) {
         throw new Exception(sprintf('Unable to register %s::autoload as an autoloading method.', __CLASS__));
     }
     self::$cacheFile = rex_path::coreCache('autoload.cache');
     self::loadCache();
     register_shutdown_function([__CLASS__, 'saveCache']);
     self::$registered = true;
 }
Ejemplo n.º 4
0
 /**
  * Prepares the logifle for later use.
  */
 public static function open()
 {
     // check if already opened
     if (!self::$file) {
         $file = rex_path::coreCache('system.log');
         self::$file = new rex_log_file($file, 2000000);
     }
 }
Ejemplo n.º 5
0
 /**
  * Schreibt Spracheigenschaften in die Datei include/clang.php.
  *
  * @throws rex_exception
  */
 public static function generateCache()
 {
     $lg = rex_sql::factory();
     $lg->setQuery('select * from ' . rex::getTablePrefix() . 'clang order by priority');
     $clangs = [];
     foreach ($lg as $lang) {
         $id = $lang->getValue('id');
         foreach ($lg->getFieldnames() as $field) {
             $clangs[$id][$field] = $lang->getValue($field);
         }
     }
     $file = rex_path::coreCache('clang.cache');
     if (rex_file::putCache($file, $clangs) === false) {
         throw new rex_exception('Clang cache file could not be generated');
     }
 }
Ejemplo n.º 6
0
 public function execute()
 {
     if (!rex::getUser()->isAdmin()) {
         throw new rex_api_exception('You do not have the permission!');
     }
     $installAddon = rex_addon::get('install');
     $versions = self::getVersions();
     $versionId = rex_request('version_id', 'int');
     if (!isset($versions[$versionId])) {
         return null;
     }
     $version = $versions[$versionId];
     if (!rex_string::versionCompare($version['version'], rex::getVersion(), '>')) {
         throw new rex_api_exception(sprintf('Existing version of Core (%s) is newer than %s', rex::getVersion(), $version['version']));
     }
     try {
         $archivefile = rex_install_webservice::getArchive($version['path']);
     } catch (rex_functional_exception $e) {
         throw new rex_api_exception($e->getMessage());
     }
     $message = '';
     $temppath = rex_path::coreCache('.new.core/');
     try {
         if ($version['checksum'] != md5_file($archivefile)) {
             throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_checksum'));
         }
         if (!rex_install_archive::extract($archivefile, $temppath)) {
             throw new rex_functional_exception($installAddon->i18n('warning_core_zip_not_extracted'));
         }
         if (!is_dir($temppath . 'core')) {
             throw new rex_functional_exception($installAddon->i18n('warning_zip_wrong_format'));
         }
         $coreAddons = [];
         /** @var rex_addon[] $updateAddons */
         $updateAddons = [];
         if (is_dir($temppath . 'addons')) {
             foreach (rex_finder::factory($temppath . 'addons')->dirsOnly() as $dir) {
                 $addonkey = $dir->getBasename();
                 $addonPath = $dir->getRealPath() . '/';
                 if (!file_exists($addonPath . rex_package::FILE_PACKAGE)) {
                     continue;
                 }
                 $config = rex_file::getConfig($addonPath . rex_package::FILE_PACKAGE);
                 if (!isset($config['version']) || rex_addon::exists($addonkey) && rex_string::versionCompare($config['version'], rex_addon::get($addonkey)->getVersion(), '<')) {
                     continue;
                 }
                 $coreAddons[$addonkey] = $addonkey;
                 if (rex_addon::exists($addonkey)) {
                     $updateAddons[$addonkey] = rex_addon::get($addonkey);
                     $updateAddonsConfig[$addonkey] = $config;
                 }
             }
         }
         //$config = rex_file::getConfig($temppath . 'core/default.config.yml');
         //foreach ($config['system_addons'] as $addonkey) {
         //    if (is_dir($temppath . 'addons/' . $addonkey) && rex_addon::exists($addonkey)) {
         //        $updateAddons[$addonkey] = rex_addon::get($addonkey);
         //    }
         //}
         $this->checkRequirements($temppath, $version['version'], $updateAddonsConfig);
         if (file_exists($temppath . 'core/update.php')) {
             include $temppath . 'core/update.php';
         }
         foreach ($updateAddons as $addonkey => $addon) {
             if ($addon->isInstalled() && file_exists($file = $temppath . 'addons/' . $addonkey . '/' . rex_package::FILE_UPDATE)) {
                 try {
                     $addon->includeFile($file);
                     if ($msg = $addon->getProperty('updatemsg', '')) {
                         throw new rex_functional_exception($msg);
                     }
                     if (!$addon->getProperty('update', true)) {
                         throw new rex_functional_exception(rex_i18n::msg('package_no_reason'));
                     }
                 } catch (rex_functional_exception $e) {
                     throw new rex_functional_exception($addonkey . ': ' . $e->getMessage(), $e);
                 } catch (rex_sql_exception $e) {
                     throw new rex_functional_exception($addonkey . ': SQL error: ' . $e->getMessage(), $e);
                 }
             }
         }
         // create backup
         $installConfig = rex_file::getCache($installAddon->getDataPath('config.json'));
         if (isset($installConfig['backups']) && $installConfig['backups']) {
             rex_dir::create($installAddon->getDataPath());
             $archive = $installAddon->getDataPath(strtolower(preg_replace('/[^a-z0-9-_.]/i', '_', rex::getVersion())) . '.zip');
             rex_install_archive::copyDirToArchive(rex_path::core(), $archive);
             foreach ($updateAddons as $addonkey => $addon) {
                 rex_install_archive::copyDirToArchive($addon->getPath(), $archive, 'addons/' . $addonkey);
             }
         }
         // copy plugins to new addon dirs
         foreach ($updateAddons as $addonkey => $addon) {
             foreach ($addon->getRegisteredPlugins() as $plugin) {
                 $pluginPath = $temppath . 'addons/' . $addonkey . '/plugins/' . $plugin->getName();
                 if (!is_dir($pluginPath)) {
                     rex_dir::copy($plugin->getPath(), $pluginPath);
                 } elseif ($plugin->isInstalled() && is_dir($pluginPath . '/assets')) {
                     rex_dir::copy($pluginPath . '/assets', $plugin->getAssetsPath());
                 }
             }
         }
         // move temp dirs to permanent destination
         rex_dir::delete(rex_path::core());
         rename($temppath . 'core', rex_path::core());
         if (is_dir(rex_path::core('assets'))) {
             rex_dir::copy(rex_path::core('assets'), rex_path::coreAssets());
         }
         foreach ($coreAddons as $addonkey) {
             if (isset($updateAddons[$addonkey])) {
                 rex_dir::delete(rex_path::addon($addonkey));
             }
             rename($temppath . 'addons/' . $addonkey, rex_path::addon($addonkey));
             if (is_dir(rex_path::addon($addonkey, 'assets'))) {
                 rex_dir::copy(rex_path::addon($addonkey, 'assets'), rex_path::addonAssets($addonkey));
             }
         }
     } catch (rex_functional_exception $e) {
         $message = $e->getMessage();
     } catch (rex_sql_exception $e) {
         $message = 'SQL error: ' . $e->getMessage();
     }
     rex_file::delete($archivefile);
     rex_dir::delete($temppath);
     if ($message) {
         $message = $installAddon->i18n('warning_core_not_updated') . '<br />' . $message;
         $success = false;
     } else {
         $message = $installAddon->i18n('info_core_updated');
         $success = true;
         rex_delete_cache();
         rex_install_webservice::deleteCache('core');
     }
     $result = new rex_api_result($success, $message);
     if ($success) {
         $result->setRequiresReboot(true);
     }
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * initilizes the rex_config class.
  */
 protected static function init()
 {
     if (self::$initialized) {
         return;
     }
     define('REX_CONFIG_FILE_CACHE', rex_path::coreCache('config.cache'));
     // take care, so we are able to write a cache file on shutdown
     // (check here, since exceptions in shutdown functions are not visible to the user)
     $dir = dirname(REX_CONFIG_FILE_CACHE);
     rex_dir::create($dir);
     if (!is_writable($dir)) {
         throw new rex_exception('rex-config: cache dir "' . dirname(REX_CONFIG_FILE_CACHE) . '" is not writable!');
     }
     // save cache on shutdown
     register_shutdown_function([__CLASS__, 'save']);
     self::load();
     self::$initialized = true;
 }
Ejemplo n.º 8
0
 /**
  * Loads the properties of package.yml.
  */
 public function loadProperties()
 {
     static $cache = null;
     if (is_null($cache)) {
         $cache = rex_file::getCache(rex_path::coreCache('packages.cache'));
     }
     $id = $this->getPackageId();
     $file = $this->getPath(self::FILE_PACKAGE);
     if (!file_exists($file)) {
         $this->propertiesLoaded = true;
         return;
     }
     if (isset($cache[$id]) && (!rex::isBackend() || !($user = rex::getUser()) || !$user->isAdmin() || $cache[$id]['timestamp'] >= filemtime($file))) {
         $properties = $cache[$id]['data'];
     } else {
         try {
             $properties = rex_file::getConfig($file);
             $cache[$id]['timestamp'] = filemtime($file);
             $cache[$id]['data'] = $properties;
             static $registeredShutdown = false;
             if (!$registeredShutdown) {
                 $registeredShutdown = true;
                 register_shutdown_function(function () use(&$cache) {
                     foreach ($cache as $package => $_) {
                         if (!rex_package::exists($package)) {
                             unset($cache[$package]);
                         }
                     }
                     rex_file::putCache(rex_path::coreCache('packages.cache'), $cache);
                 });
             }
         } catch (rex_yaml_parse_exception $exception) {
             if ($this->isInstalled()) {
                 throw $exception;
             }
             $properties = [];
         }
     }
     $this->properties = array_intersect_key($this->properties, ['install' => null, 'status' => null]);
     if ($properties) {
         foreach ($properties as $key => $value) {
             if (isset($this->properties[$key])) {
                 continue;
             }
             if ('supportpage' !== $key) {
                 $value = rex_i18n::translateArray($value, false, [$this, 'i18n']);
             } elseif (!preg_match('@^https?://@i', $value)) {
                 $value = 'http://' . $value;
             }
             $this->properties[$key] = $value;
         }
     }
     $this->propertiesLoaded = true;
 }
Ejemplo n.º 9
0
rex_autoload::addDirectory(rex_path::core('lib'));
rex_url::init(new rex_path_default_provider($REX['HTDOCS_PATH'], $REX['BACKEND_FOLDER'], false));
// start timer at the very beginning
rex::setProperty('timer', new rex_timer($_SERVER['REQUEST_TIME_FLOAT']));
// add backend flag to rex
rex::setProperty('redaxo', $REX['REDAXO']);
// add core lang directory to rex_i18n
rex_i18n::addDirectory(rex_path::core('lang'));
// add core base-fragmentpath to fragmentloader
rex_fragment::addDirectory(rex_path::core('fragments/'));
// ----------------- FUNCTIONS
require_once rex_path::core('functions/function_rex_globals.php');
require_once rex_path::core('functions/function_rex_other.php');
// ----------------- VERSION
rex::setProperty('version', '5.0.0');
$cacheFile = rex_path::coreCache('config.yml.cache');
$configFile = rex_path::coreData('config.yml');
if (file_exists($cacheFile) && file_exists($configFile) && filemtime($cacheFile) >= filemtime($configFile)) {
    $config = rex_file::getCache($cacheFile);
} else {
    $config = array_merge(rex_file::getConfig(rex_path::core('default.config.yml')), rex_file::getConfig($configFile));
    rex_file::putCache($cacheFile, $config);
}
foreach ($config as $key => $value) {
    if (in_array($key, array('fileperm', 'dirperm'))) {
        $value = octdec($value);
    }
    rex::setProperty($key, $value);
}
date_default_timezone_set(rex::getProperty('timezone', 'Europe/Berlin'));
if (!rex::isSetup()) {
Ejemplo n.º 10
0
    echo $headline;
    $fragment = new rex_fragment();
    $fragment->setVar('title', rex_i18n::msg('setup_606'), false);
    $fragment->setVar('body', $content, false);
    $fragment->setVar('buttons', $buttons, false);
    $content = $fragment->parse('core/page/section.php');
    echo '<form class="rex-js-createadminform" action="' . rex_url::backendController() . '" method="post" autocomplete="off">' . $content . '</form>';
}
// ---------------------------------- step 7 . thank you . setup false
if ($step == 7) {
    $configFile = rex_path::coreData('config.yml');
    $config = array_merge(rex_file::getConfig(rex_path::core('default.config.yml')), rex_file::getConfig($configFile));
    $config['setup'] = false;
    if (rex_file::putConfig($configFile, $config)) {
        $errmsg = '';
        rex_file::delete(rex_path::coreCache('config.yml.cache'));
    } else {
        $errmsg = rex_i18n::msg('setup_701');
    }
    $headline = rex_view::title(rex_i18n::msg('setup_700'));
    $content = '<h3>' . rex_i18n::msg('setup_703') . '</h3>';
    $content .= rex_i18n::rawMsg('setup_704', '<a href="' . rex_url::backendController() . '">', '</a>');
    $content .= '<p>' . rex_i18n::msg('setup_705') . '</p>';
    $buttons = '<a class="btn btn-setup" href="' . rex_url::backendController() . '">' . rex_i18n::msg('setup_706') . '</a>';
    echo $headline;
    $fragment = new rex_fragment();
    $fragment->setVar('heading', rex_i18n::msg('setup_702'), false);
    $fragment->setVar('body', $content, false);
    $fragment->setVar('buttons', $buttons, false);
    echo $fragment->parse('core/page/section.php');
}
Ejemplo n.º 11
0
 /**
  * Loads the cache if not already loaded.
  */
 private static function checkCache()
 {
     if (self::$cacheLoaded) {
         return;
     }
     $file = rex_path::coreCache('clang.cache');
     if (!file_exists($file)) {
         rex_clang_service::generateCache();
     }
     foreach (rex_file::getCache($file) as $id => $clang) {
         self::$clangs[$id] = new self($id, $clang['code'], $clang['name'], $clang['priority']);
     }
     self::$cacheLoaded = true;
 }
Ejemplo n.º 12
0
if ($error != '') {
    $message .= rex_view::error($error);
}
$content .= '
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>' . rex_i18n::msg('syslog_timestamp') . '</th>
                        <th>' . rex_i18n::msg('syslog_type') . '</th>
                        <th>' . rex_i18n::msg('syslog_message') . '</th>
                        <th>' . rex_i18n::msg('syslog_file') . '</th>
                        <th class="rex-table-number">' . rex_i18n::msg('syslog_line') . '</th>
                    </tr>
                </thead>
                <tbody>';
if ($file = new rex_log_file(rex_path::coreCache('system.log'))) {
    foreach (new LimitIterator($file, 0, 30) as $entry) {
        /* @var rex_log_entry $entry */
        $data = $entry->getData();
        $class = strtolower($data[0]);
        $class = $class == 'notice' || $class == 'warning' ? $class : 'error';
        $content .= '
                    <tr class="rex-state-' . $class . '">
                        <td data-title="' . rex_i18n::msg('syslog_timestamp') . '">' . $entry->getTimestamp('%d.%m.%Y %H:%M:%S') . '</td>
                        <td data-title="' . rex_i18n::msg('syslog_type') . '">' . $data[0] . '</td>
                        <td data-title="' . rex_i18n::msg('syslog_message') . '">' . $data[1] . '</td>
                        <td data-title="' . rex_i18n::msg('syslog_file') . '"><div class="rex-word-break">' . (isset($data[2]) ? $data[2] : '') . '</div></td>
                        <td class="rex-table-number" data-title="' . rex_i18n::msg('syslog_line') . '">' . (isset($data[3]) ? $data[3] : '') . '</td>
                    </tr>';
    }
}
Ejemplo n.º 13
0
 /**
  * Loads the cache if not already loaded.
  */
 private static function checkCache()
 {
     if (self::$cacheLoaded) {
         return;
     }
     $file = rex_path::coreCache('clang.cache');
     if (!file_exists($file)) {
         rex_clang_service::generateCache();
     }
     foreach (rex_file::getCache($file) as $id => $data) {
         $clang = new self();
         foreach ($data as $key => $value) {
             $clang->{$key} = $value;
         }
         self::$clangs[$id] = $clang;
     }
     self::$cacheLoaded = true;
 }