Esempio n. 1
0
 /**
  * checks permissions of all required filesystem resources.
  *
  * @return array An array of error messages
  */
 public static function checkFilesystem()
 {
     // -------------------------- SCHREIBRECHTE
     $writables = [rex_path::media(), rex_path::assets(), rex_path::cache(), rex_path::data(), rex_path::src()];
     $func = function ($dir) use(&$func) {
         if (!rex_dir::isWritable($dir)) {
             return ['setup_304' => [$dir]];
         }
         $res = [];
         foreach (rex_finder::factory($dir) as $path => $file) {
             if ($file->isDir()) {
                 $res = array_merge_recursive($res, $func($path));
             } elseif (!$file->isWritable()) {
                 $res['setup_305'][] = $path;
             }
         }
         return $res;
     };
     $res = [];
     foreach ($writables as $dir) {
         if (@is_dir($dir)) {
             $res = array_merge_recursive($res, $func($dir));
         } else {
             $res['setup_306'][] = $dir;
         }
     }
     return $res;
 }
Esempio n. 2
0
/**
 * Deletes the cache.
 *
 * @package redaxo\core
 */
function rex_delete_cache()
{
    // close logger, so the logfile can also be deleted
    rex_logger::close();
    $finder = rex_finder::factory(rex_path::cache())->recursive()->childFirst()->ignoreFiles(['.htaccess', '.redaxo'], false)->ignoreSystemStuff(false);
    rex_dir::deleteIterator($finder);
    rex_clang::reset();
    // ----- EXTENSION POINT
    return rex_extension::registerPoint(new rex_extension_point('CACHE_DELETED', rex_i18n::msg('delete_cache_message')));
}
Esempio 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::cache('autoload.cache');
     self::loadCache();
     register_shutdown_function([__CLASS__, 'saveCache']);
     self::$registered = true;
 }
Esempio n. 4
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::cache('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') . '"><span class="rex-truncate rex-truncate-left">' . (isset($data[2]) ? $data[2] : '') . '</span></td>
                        <td class="rex-table-number" data-title="' . rex_i18n::msg('syslog_line') . '">' . (isset($data[3]) ? $data[3] : '') . '</td>
                    </tr>';
    }
}
Esempio n. 5
0
 /**
  * Prepares the logifle for later use.
  */
 public static function open()
 {
     // check if already opened
     if (!self::$file) {
         $file = rex_path::cache('system.log');
         self::$file = new rex_log_file($file, 2000000);
     }
 }
Esempio n. 6
0
 /**
  * Loads the properties of package.yml.
  */
 private function loadProperties()
 {
     static $cache = null;
     if (is_null($cache)) {
         $cache = rex_file::getCache(rex_path::cache('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 {
         $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::cache('packages.cache'), $cache);
             });
         }
     }
     foreach ($properties as $key => $value) {
         if (!isset($this->properties[$key])) {
             $this->properties[$key] = rex_i18n::translateArray($value, false, [$this, 'i18n']);
         }
     }
     $this->propertiesLoaded = true;
 }
Esempio n. 7
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::data('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::cache('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');
}
Esempio n. 8
0
 /**
  * Loads the cache if not already loaded.
  */
 private static function checkCache()
 {
     if (self::$cacheLoaded) {
         return;
     }
     $file = rex_path::cache('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;
 }
Esempio n. 9
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::cache('clang.cache');
     if (rex_file::putCache($file, $clangs) === false) {
         throw new rex_exception('Clang cache file could not be generated');
     }
 }
Esempio n. 10
0
rex_autoload::addDirectory(rex_path::core('lib'));
rex_url::init($REX['HTDOCS_PATH'], $REX['BACKEND_FOLDER']);
// 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-alpha7');
$cacheFile = rex_path::cache('config.yml.cache');
$configFile = rex_path::data('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, ['fileperm', 'dirperm'])) {
        $value = octdec($value);
    }
    rex::setProperty($key, $value);
}
date_default_timezone_set(rex::getProperty('timezone', 'Europe/Berlin'));
if (!rex::isSetup()) {
Esempio n. 11
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::cache('.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
         if ($installAddon->getConfig('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::assets());
         }
         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');
     }
     return new rex_api_result($success, $message);
 }
Esempio n. 12
0
 /**
  * Get the path to the compiled version of a fragment.
  *
  * @param string $path
  *
  * @return string
  */
 public function getCompiledFile($file)
 {
     return rex_path::cache($file);
 }
Esempio n. 13
0
 /**
  * initilizes the rex_config class.
  */
 protected static function init()
 {
     if (self::$initialized) {
         return;
     }
     define('REX_CONFIG_FILE_CACHE', rex_path::cache('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)
     if (!is_writable(dirname(REX_CONFIG_FILE_CACHE))) {
         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;
 }