Ejemplo n.º 1
0
 public static function copyDirToArchive($dir, $archive, $basename = null, $excludeDirs = null)
 {
     $dir = rtrim($dir, '/\\');
     $basename = $basename ?: basename($dir);
     rex_dir::create(dirname($archive));
     $files = array();
     $iterator = rex_finder::factory($dir)->recursive()->filesOnly();
     if ($excludeDirs) {
         $iterator->ignoreDirs($excludeDirs, false);
     }
     foreach ($iterator as $path => $file) {
         $subpath = str_replace($dir, $basename, $path);
         $subpath = str_replace('\\', '/', $subpath);
         $files[$subpath] = $path;
     }
     if (class_exists('ZipArchive')) {
         $zip = new ZipArchive();
         $zip->open($archive, ZipArchive::CREATE);
         foreach ($files as $path => $realpath) {
             $zip->addFile($realpath, $path);
         }
         $zip->close();
     } else {
         $phar = new PharData($archive, 0, null, Phar::ZIP);
         $phar->buildFromIterator(new ArrayIterator($files));
         $phar->compressFiles(Phar::GZ);
         foreach ($files as $path => $realpath) {
             if (filesize($realpath) == 0) {
                 $phar[$path]->decompress();
             }
         }
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 private function createArchives()
 {
     $path = rex_path::base('releases/' . $this->version . '/');
     if (file_exists($path)) {
         rex_dir::deleteFiles($path);
     }
     rex_dir::create($path);
     $complete = new ZipArchive();
     $update = new ZipArchive();
     $complete->open($path . 'redaxo_' . $this->version . '.zip', ZipArchive::CREATE);
     $update->open($path . 'redaxo_update_' . $this->version . '.zip', ZipArchive::CREATE);
     $files = ['assets/.redaxo', 'media/.redaxo', 'redaxo/cache/.htaccess', 'redaxo/cache/.redaxo', 'redaxo/data/.htaccess', 'redaxo/data/.redaxo', 'redaxo/src/.htaccess', 'redaxo/index.php', 'index.php', 'LICENSE.md', 'README.md'];
     foreach ($files as $file) {
         $complete->addFile(rex_path::base($file), $file);
     }
     $this->addDir($complete, rex_path::core(), 'redaxo/src/core');
     $this->addDir($update, rex_path::core(), 'core');
     foreach (self::$addons as $addon) {
         $this->addDir($complete, rex_path::addon($addon), 'redaxo/src/addons/' . $addon);
         $this->addDir($update, rex_path::addon($addon), 'addons/' . $addon);
     }
     $this->addDir($complete, rex_path::core('assets'), 'assets');
     $addon = rex_addon::get('be_style');
     $this->addDir($complete, $addon->getPath('assets'), 'assets/addons/be_style');
     $this->addDir($complete, $addon->getPlugin('redaxo')->getPath('assets'), 'assets/addons/be_style/plugins/redaxo');
     $files = (require $addon->getPath('vendor_files.php'));
     foreach ($files as $source => $destination) {
         $complete->addFile($addon->getPath($source), 'assets/addons/be_style/' . $destination);
     }
     $complete->close();
     $update->close();
 }
Ejemplo n.º 4
0
 protected function extractArchiveTo($dir)
 {
     if (!rex_install_archive::extract($this->archive, $dir, $this->addonkey)) {
         rex_dir::delete($dir);
         return rex_i18n::msg('install_warning_addon_zip_not_extracted');
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Constructor.
  *
  * @param string   $path        File path
  * @param int|null $maxFileSize Maximum file size
  */
 public function __construct($path, $maxFileSize = null)
 {
     $this->path = $path;
     rex_dir::create(dirname($path));
     if ($maxFileSize && file_exists($path) && filesize($path) > $maxFileSize) {
         rename($path, $path . '.2');
     }
     $this->file = fopen($path, 'a+b');
 }
Ejemplo n.º 6
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')));
}
Ejemplo n.º 7
0
 public function testCopyToDir()
 {
     $orig = $this->getPath('file.txt');
     $copyDir = $this->getPath('copy');
     $copyFile = $this->getPath('copy/file.txt');
     $content = 'test';
     rex_file::put($orig, $content);
     rex_dir::create($copyDir);
     $this->assertTrue(rex_file::copy($orig, $copyDir), 'copy() returns true on success');
     $this->assertEquals($content, rex_file::get($copyFile), 'content of new file is the same as of original file');
 }
Ejemplo n.º 8
0
 function readFolder($dir)
 {
     if (!is_dir($dir)) {
         rex_dir::copy(rex_path::addon('import_export', 'backup'), rex_path::addonData('import_export', 'backups'));
     }
     $hdl = opendir($dir);
     $folder = array();
     while (false !== ($file = readdir($hdl))) {
         $folder[] = $file;
     }
     return $folder;
 }
Ejemplo n.º 9
0
<?php

if (rex_string::versionCompare(rex::getVersion(), '5.0.0-beta1', '<=')) {
    rex_extension::register('RESPONSE_SHUTDOWN', function () {
        rex_file::delete(rex_path::assets('jquery.min.js'));
        rex_file::delete(rex_path::assets('jquery.min.map'));
        rex_file::delete(rex_path::assets('jquery-pjax.min.js'));
        rex_file::delete(rex_path::assets('jquery-ui.custom.min.js'));
        rex_file::delete(rex_path::assets('jquery-ui.custom.txt'));
        rex_file::delete(rex_path::assets('redaxo-logo.svg'));
        rex_file::delete(rex_path::assets('sha1.js'));
        rex_file::delete(rex_path::assets('standard.js'));
    });
    rex_dir::copy(__DIR__ . '/assets', rex_path::assets('core'));
    rex_dir::create(rex_path::data('core'));
    rename(rex_path::data('config.yml'), rex_path::data('core/config.yml'));
}
Ejemplo n.º 10
0
 /**
  * Importiert das Tar-Archiv $filename in den Ordner /files.
  *
  * @param string $filename Pfad + Dateinamen zum Tar-Archiv
  *
  * @return array Gibt ein Assoc. Array zurück.
  *               'state' => boolean (Status ob fehler aufgetreten sind)
  *               'message' => Evtl. Status/Fehlermeldung
  */
 public static function importFiles($filename)
 {
     $return = [];
     $return['state'] = false;
     if ($filename == '' || substr($filename, -7, 7) != '.tar.gz') {
         $return['message'] = rex_i18n::msg('backup_no_import_file_chosen') . '<br />';
         return $return;
     }
     // Ordner /files komplett leeren
     rex_dir::deleteFiles(rex_path::media());
     $tar = new rex_backup_tar();
     // ----- EXTENSION POINT
     $tar = rex_extension::registerPoint(new rex_extension_point('BACKUP_BEFORE_FILE_IMPORT', $tar));
     // require import skript to do some userside-magic
     self::importScript(str_replace('.tar.gz', '.php', $filename), self::IMPORT_ARCHIVE, self::IMPORT_EVENT_PRE);
     $tar->openTAR($filename);
     if (!$tar->extractTar()) {
         $msg = rex_i18n::msg('backup_problem_when_extracting') . '<br />';
         if (count($tar->getMessages()) > 0) {
             $msg .= rex_i18n::msg('backup_create_dirs_manually') . '<br />';
             foreach ($tar->getMessages() as $_message) {
                 $msg .= rex_path::absolute($_message) . '<br />';
             }
         }
     } else {
         $msg = rex_i18n::msg('backup_file_imported') . '<br />';
     }
     // ----- EXTENSION POINT
     $tar = rex_extension::registerPoint(new rex_extension_point('BACKUP_AFTER_FILE_IMPORT', $tar));
     // require import skript to do some userside-magic
     self::importScript(str_replace('.tar.gz', '.php', $filename), self::IMPORT_ARCHIVE, self::IMPORT_EVENT_POST);
     $return['state'] = true;
     $return['message'] = $msg;
     return $return;
 }
Ejemplo n.º 11
0
             $template_id = $TPL->getLastId();
             $success = rex_i18n::msg('template_added');
         } catch (rex_sql_exception $e) {
             $error = $e->getMessage();
         }
     } else {
         $TPL->setWhere(['id' => $template_id]);
         $TPL->addGlobalUpdateFields();
         try {
             $TPL->update();
             $success = rex_i18n::msg('template_updated');
         } catch (rex_sql_exception $e) {
             $error = $e->getMessage();
         }
     }
     rex_dir::delete(rex_path::addonCache('templates'), false);
     if ($goon != '') {
         $function = 'edit';
         $save = 'nein';
     } else {
         $function = '';
     }
 }
 if (!isset($save) or $save != 'ja') {
     // Ctype Handling
     $ctypes = isset($attributes['ctype']) ? $attributes['ctype'] : [];
     $modules = isset($attributes['modules']) ? $attributes['modules'] : [];
     $categories = isset($attributes['categories']) ? $attributes['categories'] : [];
     if (!is_array($modules)) {
         $modules = [];
     }
Ejemplo n.º 12
0
<?php

/**
 * Cronjob Addon.
 *
 * @author gharlan[at]web[dot]de Gregor Harlan
 *
 * @package redaxo5
 *
 * @var rex_addon $this
 */
rex_dir::delete($this->getDataPath());
Ejemplo n.º 13
0
 public function tearDown()
 {
     rex_dir::delete($this->getPath());
 }
Ejemplo n.º 14
0
                </div>
                <script type="text/javascript">
                     <!--
                    jQuery(function($) {
                        $("#serverbezeichnung").focus();
                    });
                     //-->
                </script>';
}
// ---------------------------------- MODUS 3 | Datenbank anlegen ...
if ($checkmodus == 3 && $send == 1) {
    $err_msg = '';
    $dbanlegen = rex_post('dbanlegen', 'int', '');
    // -------------------------- Benötigte Tabellen prüfen
    $requiredTables = array($REX['TABLE_PREFIX'] . 'action', $REX['TABLE_PREFIX'] . 'article', $REX['TABLE_PREFIX'] . 'article_slice', $REX['TABLE_PREFIX'] . 'clang', $REX['TABLE_PREFIX'] . 'file', $REX['TABLE_PREFIX'] . 'file_category', $REX['TABLE_PREFIX'] . 'module_action', $REX['TABLE_PREFIX'] . 'module', $REX['TABLE_PREFIX'] . 'template', $REX['TABLE_PREFIX'] . 'user');
    rex_dir::copy(rex_path::addon('import_export', 'backup'), rex_path::addonData('import_export', 'backups'));
    if ($dbanlegen == 4) {
        // ----- vorhandenen seite updaten
        $info_msg = '';
        // import uploaded 4.x dump
        if (isset($_FILES['FORM']) && $_FILES['FORM']['size']['importfile'] < 1) {
            // no upload file error
            $err_msg = $I18N->msg('setup_03801') . '<br>';
        } else {
            // drop rex_* tables
            $info_msg .= rex_setup_dropREXtables();
            // set database default charset
            $info_msg .= rex_setup_setDBcharset('utf8 COLLATE utf8_general_ci');
            // create temp sql dump from upload
            $tmp_sql = getImportDir() . '/temp.sql';
            if (@move_uploaded_file($_FILES['FORM']['tmp_name']['importfile'], $tmp_sql)) {
Ejemplo n.º 15
0
<?php

rex_dir::copy(__DIR__ . '/backup', rex_path::addonData('import_export', 'backups'));
$REX['ADDON']['install']['import_export'] = 1;
// ERRMSG IN CASE: $REX[ADDON][installmsg]["import_export"] = "Leider konnte nichts installiert werden da.";
Ejemplo n.º 16
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.º 17
0
 /**
  * Deletes a package.
  *
  * @param bool $ignoreState
  *
  * @return bool TRUE on success, FALSE on error
  */
 protected function _delete($ignoreState = false)
 {
     // if package is installed, uninstall it first
     if ($this->package->isInstalled() && !$this->uninstall() && !$ignoreState) {
         // message is set by uninstall()
         return false;
     }
     if (!rex_dir::delete($this->package->getPath()) && !$ignoreState) {
         $this->message = $this->i18n('not_deleted', $this->package->getName());
         return false;
     }
     rex_dir::delete($this->package->getDataPath());
     if (!$ignoreState) {
         $this->saveConfig();
         $this->message = $this->i18n('deleted', $this->package->getName());
     }
     return true;
 }
Ejemplo n.º 18
0
<?php

/** @var rex_addon $this */
rex_dir::copy($this->getPath('backups'), rex_addon::get('backup')->getDataPath());
Ejemplo n.º 19
0
 public function testDeleteFilesRecursive()
 {
     $dir = $this->getPath('deleteFilesRecursive');
     $file1 = $this->getPath('deleteFilesRecursive/file.txt');
     $file2 = $this->getPath('deleteFilesRecursive/subdir/file.txt');
     rex_file::put($file1, '');
     rex_file::put($file2, '');
     $this->assertTrue(is_file($file1), 'file exists after put()');
     $this->assertTrue(is_file($file2), 'file exists after put()');
     $this->assertTrue(rex_dir::deleteFiles($dir), 'deleteFiles() returns true on success');
     $this->assertFalse(is_file($file1), 'file in main dir does not exist after deleteFiles()');
     $this->assertFalse(is_file($file2), 'file in subdir does not exist after recursive deleteFiles()');
     $this->assertTrue(is_dir($dir . '/subdir'), 'subdir still exists after deleteFiles()');
 }
Ejemplo n.º 20
0
 function enterObject()
 {
     $error = array();
     $rfile = 'file_' . md5($this->getFieldName('file'));
     $err_msgs = $this->getElement('messages');
     // min_err,max_err,type_err,empty_err
     if (!is_array($err_msgs)) {
         $err_msgs = explode(',', $err_msgs);
     }
     $err_msgs['min_error'] = $err_msgs[0];
     $err_msgs['max_error'] = isset($err_msgs[1]) ? rex_i18n::translate($err_msgs[1]) : 'max_error';
     $err_msgs['type_error'] = isset($err_msgs[2]) ? rex_i18n::translate($err_msgs[2]) : 'type_error';
     $err_msgs['empty_error'] = isset($err_msgs[3]) ? rex_i18n::translate($err_msgs[3]) : 'empty_error';
     $err_msgs['delete_file'] = isset($err_msgs[4]) ? rex_i18n::translate($err_msgs[4]) : 'delete ';
     $this->tmp_messages = $err_msgs;
     $value = $this->getValue();
     if ($value == "") {
         $value = $this->getElement('default_file');
     }
     $this->setValue('');
     $value_email = '';
     $value_sql = '';
     if (!is_string($value) && $value["delete"] == 1) {
         $value = '';
     }
     // SIZE CHECK
     $sizes = explode(',', $this->getElement('max_size'));
     $minsize = count($sizes) > 1 ? (int) ($sizes[0] * 1024) : 0;
     $maxsize = count($sizes) > 1 ? (int) ($sizes[1] * 1024) : (int) ($sizes[0] * 1024);
     if ($this->params['send'] && isset($_FILES[$rfile]) && $_FILES[$rfile]['name'] != '' && ($_FILES[$rfile]['size'] > $maxsize || $_FILES[$rfile]['size'] < $minsize)) {
         if ($_FILES[$rfile]['size'] < $minsize) {
             $error[] = $err_msgs['min_error'];
         }
         if ($_FILES[$rfile]['size'] > $maxsize) {
             $error[] = $err_msgs['max_error'];
         }
         unset($_FILES[$rfile]);
     }
     $database_filename_field = $this->getElement('database_filename_field');
     if ($database_filename_field != "") {
         $value = $this->params['value_pool']['sql'][$database_filename_field];
     }
     $prefix = md5(mt_rand() . microtime(true)) . '_';
     if ($this->getElement('file_prefix')) {
         $prefix .= $this->getElement('file_prefix') . '_';
     }
     $upload_folder = $this->getElement('upload_folder');
     if ($upload_folder == "") {
         $upload_folder = rex_path::addonData('yform', 'uploads');
         rex_dir::create($upload_folder);
     }
     if ($value != "") {
         if ($REX["REDAXO"]) {
             $value = explode("_", $value, 2);
             $value = $value[0];
         }
         $search_path = $upload_folder . '/' . $value . '_' . $this->getElement('file_prefix');
         $files = glob(preg_replace('/(\\*|\\?|\\[)/', '[$1]', $search_path) . '*');
         if (count($files) == 1) {
             $value = basename($files[0]);
             if (rex_request("rex_upload_downloadfile") == $value) {
                 $file = $upload_folder . '/' . $value;
                 if (file_exists($file)) {
                     ob_end_clean();
                     $filename = explode("_", basename($file), 2);
                     $filename = $filename[1];
                     header('Content-Description: File Transfer');
                     header('Content-Type: application/octet-stream');
                     header('Content-Disposition: attachment; filename=' . $filename);
                     header('Expires: 0');
                     header('Cache-Control: must-revalidate');
                     header('Pragma: public');
                     header('Content-Length: ' . filesize($file));
                     readfile($file);
                     exit;
                 }
             }
         } else {
             $value = "";
         }
     }
     if ($this->params['send']) {
         if (isset($_FILES[$rfile]) && $_FILES[$rfile]['name'] != '') {
             $FILE['size'] = $_FILES[$rfile]['size'];
             $FILE['name'] = $_FILES[$rfile]['name'];
             $FILE['type'] = $_FILES[$rfile]['type'];
             $FILE['tmp_name'] = $_FILES[$rfile]['tmp_name'];
             $FILE['error'] = $_FILES[$rfile]['error'];
             $FILE['name_normed'] = strtolower(preg_replace('/[^a-zA-Z0-9.\\-\\$\\+]/', '_', $FILE['name']));
             $extensions_array = explode(',', $this->getElement('types'));
             $ext = '.' . pathinfo($FILE['name'], PATHINFO_EXTENSION);
             if (!in_array(strtolower($ext), $extensions_array) && !in_array(strtoupper($ext), $extensions_array)) {
                 $error[] = $err_msgs['type_error'];
                 $value = '';
             } else {
                 $file_normed = $FILE['name_normed'];
                 $file_normed_new = $prefix . $file_normed;
                 if (file_exists($upload_folder . '/' . $file_normed_new)) {
                     for ($cf = 1; $cf < 1000; $cf++) {
                         $file_normed_new = $prefix . $cf . '_' . $file_normed;
                         if (!file_exists($upload_folder . '/' . $file_normed_new)) {
                             break;
                         }
                     }
                 }
                 $value = $file_normed_new;
                 if (!@move_uploaded_file($FILE['tmp_name'], $upload_folder . '/' . $file_normed_new)) {
                     if (!@copy($FILE['tmp_name'], $upload_folder . '/' . $file_normed_new)) {
                         $error[] = 'upload failed: destination folder problem';
                         $value = '';
                     } else {
                         @chmod($upload_folder . '/' . $file_normed_new, $REX['FILEPERM']);
                     }
                 } else {
                     @chmod($upload_folder . '/' . $file_normed_new, $REX['FILEPERM']);
                 }
             }
         }
     }
     if (count($error) == 0) {
         switch ($this->getElement('modus')) {
             case 'database':
                 if ($database_filename_field != "") {
                     $this->params['value_pool']['email'][$database_filename_field] = $value;
                     // $FILE['name_normed'];
                     $this->params['value_pool']['sql'][$database_filename_field] = $value;
                     // $FILE['name_normed'];
                 }
                 $value_email = file_get_contents($upload_folder . '/' . $value);
                 $value_sql = $value_email;
                 break;
             case 'upload':
             default:
                 $value_email = $value;
                 $value_sql = $value_email;
                 break;
         }
     }
     $this->setValue($value);
     $this->params['value_pool']['email'][$this->getName()] = $value_email;
     $this->params['value_pool']['sql'][$this->getName()] = $value_sql;
     ## check for required file
     if ($this->params['send'] && $this->getElement('required') == 1 && $this->getValue() == '') {
         $error[] = $err_msgs['empty_error'];
     }
     ## setting up error Message
     if ($this->params['send'] && count($error) > 0) {
         $this->params['warning'][$this->getId()] = $this->params['error_class'];
         $this->params['warning_messages'][$this->getId()] = implode(', ', $error);
     }
     $this->params['form_output'][$this->getId()] = $this->parse('value.upload.tpl.php');
 }
Ejemplo n.º 21
0
<?php

/** @var rex_addon $this */
rex_dir::copy($this->getPath('backups'), $this->getDataPath());
Ejemplo n.º 22
0
 /**
  * Writes the body to the given resource.
  *
  * @param string|resource $resource File path or file pointer
  *
  * @return bool `true` on success, `false` on failure
  */
 public function writeBodyTo($resource)
 {
     $close = false;
     if (is_string($resource) && rex_dir::create(dirname($resource))) {
         $resource = fopen($resource, 'wb');
         $close = true;
     }
     if (!is_resource($resource)) {
         return false;
     }
     $success = true;
     while ($success && ($buf = $this->getBufferedBody()) !== false) {
         $success = (bool) fwrite($resource, $buf);
     }
     if ($close) {
         fclose($resource);
     }
     return $success;
 }
Ejemplo n.º 23
0
 /**
  * @return bool
  */
 public static function createDataConfigIfNotExists()
 {
     if (!file_exists(rex_path::addonData(self::getName(), 'config.json'))) {
         return rex_dir::copy(rex_path::addon(self::getName(), 'data'), rex_path::addonData(self::getName()));
     }
     return true;
 }
Ejemplo n.º 24
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.º 25
0
 public function extractTar()
 {
     // kills: Warnung verhindern
     if (is_array($this->files)) {
         foreach ($this->files as $item) {
             // jan: wenn probleme mit der ordnergenerierung -> ordner manuell einstellen
             if (!file_exists(dirname($item['name']))) {
                 rex_dir::create(dirname($item['name']));
             }
             if ($h = @fopen($item['name'], 'w+')) {
                 fwrite($h, $item['file'], $item['size']);
                 fclose($h);
             } else {
                 $this->message[] = dirname($item['name']);
                 return false;
             }
         }
     }
     if (count($this->message) > 0) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 26
0
 /**
  * Copies a file
  *
  * @param string $srcfile Path of the source file
  * @param string $dstfile Path of the destination file or directory
  * @return boolean TRUE on success, FALSE on failure
  */
 public static function copy($srcfile, $dstfile)
 {
     global $REX;
     if (is_file($srcfile)) {
         if (is_dir($dstfile)) {
             $dstdir = rtrim($dstfile, DIRECTORY_SEPARATOR);
             $dstfile = $dstdir . DIRECTORY_SEPARATOR . basename($srcfile);
         } else {
             $dstdir = dirname($dstfile);
         }
         if (rex_dir::isWritable($dstdir) && (!file_exists($dstfile) || is_writable($dstfile)) && copy($srcfile, $dstfile)) {
             touch($dstfile, filemtime($srcfile));
             @chmod($dstfile, $REX['FILEPERM']);
             self::invalidateCache($dstfile);
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 27
0
 public function __destruct()
 {
     rex_dir::delete(rex_path::addon('.new.' . $this->addonkey));
 }
Ejemplo n.º 28
0
 /**
  * Copies a file.
  *
  * @param string $srcfile Path of the source file
  * @param string $dstfile Path of the destination file or directory
  *
  * @return bool TRUE on success, FALSE on failure
  */
 public static function copy($srcfile, $dstfile)
 {
     if (is_file($srcfile)) {
         if (is_dir($dstfile)) {
             $dstdir = rtrim($dstfile, DIRECTORY_SEPARATOR);
             $dstfile = $dstdir . DIRECTORY_SEPARATOR . basename($srcfile);
         } else {
             $dstdir = dirname($dstfile);
             rex_dir::create($dstdir);
         }
         if (rex_dir::isWritable($dstdir) && (!file_exists($dstfile) || is_writable($dstfile)) && copy($srcfile, $dstfile)) {
             touch($dstfile, filemtime($srcfile));
             @chmod($dstfile, rex::getFilePerm());
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 29
0
    $configFile = rex_path::data('config.yml');
    $config = rex_file::getConfig($configFile);
    $config['setup'] = true;
    // echo nl2br(htmlspecialchars($cont));
    if (rex_file::putConfig($configFile, $config) !== false) {
        $info = rex_i18n::msg('setup_error1', '<a href="' . rex_url::backendController() . '">', '</a>');
        header('Location:' . rex_url::backendController());
        exit;
    } else {
        $error[] = rex_i18n::msg('setup_error2');
    }
} elseif ($func == 'generate') {
    // generate all articles,cats,templates,caches
    $success = rex_delete_cache();
} elseif ($func == 'updateassets') {
    rex_dir::copy(rex_path::core('assets'), rex_path::assets());
    $success = 'Updated assets';
} elseif ($func == 'updateinfos') {
    $configFile = rex_path::data('config.yml');
    $config = array_merge(rex_file::getConfig(rex_path::core('default.config.yml')), rex_file::getConfig($configFile));
    $settings = rex_post('settings', 'array', []);
    foreach (['server', 'servername', 'error_email', 'lang'] as $key) {
        if (!isset($settings[$key]) || !$settings[$key]) {
            $error[] = rex_i18n::msg($key . '_required');
            continue;
        }
        $config[$key] = $settings[$key];
        try {
            rex::setProperty($key, $settings[$key]);
        } catch (InvalidArgumentException $e) {
            $error[] = rex_i18n::msg($key . '_invalid');
Ejemplo n.º 30
0
            $form_tmp .= "\n" . '<div class="' . $form_field_wrp . ' ' . $warnblock["el_" . $i] . '"><label ' . $warning["el_" . $i] . ' for="FORM[' . $form_ID . '][el_' . $i . ']" >' . $element[1] . $req . '</label>' . "\n";
            $form_tmp .= '<input type="file" name="FORM[' . $form_ID . '][el_' . $i . ']" id="FORM[' . $form_ID . '][el_' . $i . ']" /></div>' . "\n";
            $formoutput[] = $form_tmp;
            $form_enctype = 'enctype="multipart/form-data"';
            break;
    }
}
// pruefe Pfad auf Vorhandensein und Schreibrechte, Wenn Pfad nicht vorhanden, ignoriere die weitere Verarbeitung.
if (isset($form_upload_folder) and $form_upload_folder != '' and rex::isBackend()) {
    // ... dum die dum ... Pfadpruefung erfolgt hier ...beginnt der Uploadpfad nicht mit einem Slash, muss es sich um einen lokalen Ordner handeln der vom Backend aus erweitert werden muss
    if (substr($form_upload_folder, 0, 1) != '/') {
        $form_upload_folder_tmp = '../' . $form_upload_folder;
    } else {
        $form_upload_folder_tmp = $form_upload_folder;
    }
    if (rex_dir::isWritable($form_upload_folder_tmp) !== true) {
        echo rex_view::warning('Der Uploadpfad "' . $form_upload_folder_tmp . '" ist nicht beschreibbar.<br />
                      Pruefe die Schreibrechte oder lasse die Angaben zum Uploadordner leer, wenn kein Uploadfeld genutzt wird.');
    }
}
// =================AUSGABE-KOPF============================
$out = '
   
   <form class="' . $form_tag_class . '" id="' . $form_ID . '" action="' . rex_getUrl(REX_ARTICLE_ID) . '#doformREX_SLICE_ID" accept-charset="UTF-8" method="post" ' . $form_enctype . '>
      <div><input type="hidden" name="FORM[' . $form_ID . '][' . $form_ID . 'send]" value="1" /><input type="hidden" name="ctype" value="ctype" /></div>
      <input type="hidden" name="token" value="' . $token . '" />';
// =================Formular-generieren=====================
foreach ($formoutput as $fields) {
    $out .= $fields;
}
// =================AUSGABE-FUSS============================