Exemplo n.º 1
0
 /**
  * Upload Finished callback
  *
  * This is called as soon as uploads have finished.
  * takes care of moving them to the right folder
  *
  * @param string $tempPath    Path to the temporary directory containing the files at this moment
  * @param string $tempWebPath Points to the same folder as tempPath, but relative to the webroot
  * @param array  $data        Data given to setData() when creating the uploader
  * @param string $uploadId    unique session id for the current upload
  * @param array  $fileInfos   uploaded file informations
  * @param array  $response    uploaded status
  *
  * @return array path and webpath
  */
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response)
 {
     $path = $data['path'];
     $webPath = $data['webPath'];
     $objCategory = Category::getCategory($data['category_id']);
     // check for sufficient permissions
     if ($objCategory->getAddFilesAccessId() && !\Permission::checkAccess($objCategory->getAddFilesAccessId(), 'dynamic', true) && $objCategory->getOwnerId() != \FWUser::getFWUserObject()->objUser->getId()) {
         return;
     }
     //we remember the names of the uploaded files here. they are stored in the session afterwards,
     //so we can later display them highlighted.
     $arrFiles = array();
     $uploadFiles = array();
     //rename files, delete unwanted
     $arrFilesToRename = array();
     //used to remember the files we need to rename
     $h = opendir($tempPath);
     if (!$h) {
         return array($path, $webPath);
     }
     while (false !== ($file = readdir($h))) {
         //skip . and ..
         if ($file == '.' || $file == '..') {
             continue;
         }
         try {
             //delete potentially malicious files
             $objTempFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $file);
             if (!\FWValidator::is_file_ending_harmless($file)) {
                 $objTempFile->delete();
                 continue;
             }
             $cleanFile = \Cx\Lib\FileSystem\FileSystem::replaceCharacters($file);
             if ($cleanFile != $file) {
                 $objTempFile->rename($tempPath . '/' . $cleanFile, false);
                 $file = $cleanFile;
             }
             $info = pathinfo($file);
             //check if file needs to be renamed
             $newName = '';
             $suffix = '';
             if (file_exists($path . '/' . $file)) {
                 $suffix = '_' . time();
                 $newName = $info['filename'] . $suffix . '.' . $info['extension'];
                 $arrFilesToRename[$file] = $newName;
                 array_push($arrFiles, $newName);
             }
             if (!isset($arrFilesToRename[$file])) {
                 array_push($uploadFiles, $file);
             }
             //rename files where needed
             foreach ($arrFilesToRename as $oldName => $newName) {
                 $objTempFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $oldName);
                 $objTempFile->rename($tempPath . '/' . $newName, false);
                 array_push($uploadFiles, $newName);
             }
             //move file from temp path into target folder
             $objImage = new \ImageManager();
             foreach ($uploadFiles as $fileName) {
                 $objFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $fileName);
                 $objFile->move($path . '/' . $fileName, false);
                 \Cx\Core\Core\Controller\Cx::instanciate()->getMediaSourceManager()->getThumbnailGenerator()->createThumbnailFromPath($path . '/' . $fileName);
             }
         } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             \DBG::msg($e->getMessage());
         }
         $objDownloads = new downloads('');
         $objDownloads->addDownloadFromUpload($info['filename'], $info['extension'], $suffix, $objCategory, $objDownloads, $fileInfos['name']);
     }
     return array($path, $webPath);
 }
 /**
  * Clears a cache page
  * @param string $urlPattern Drop all pages that match the pattern, for exact format, make educated guesses
  * @param string $domain Domain name to drop cache page of
  * @param int $port Port to drop cache page of
  */
 protected function clearCachePageForDomainAndPort($urlPattern, $domain, $port)
 {
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $strCachePath = $cx->getWebsiteCachePath() . '/';
     $glob = null;
     if ($urlPattern == '*') {
         $glob = $strCachePath . '*';
     }
     if (!$glob) {
         $searchParts = $cx->getComponent('Cache')->getCacheFileNameSearchPartsFromUrl($urlPattern);
         $glob = $strCachePath . $cx->getComponent('Cache')->getCacheFileNameFromUrl($urlPattern, false) . '*' . implode('', $searchParts) . '*';
     }
     if ($glob !== null) {
         $fileNames = glob($glob);
         foreach ($fileNames as $fileName) {
             if (!preg_match('#/[0-9a-f]{32}((_[plutgc][a-z0-9]+)+)?$#', $fileName)) {
                 continue;
             }
             try {
                 $file = new \Cx\Lib\FileSystem\File($fileName);
                 $file->delete();
             } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
             }
         }
         return;
     }
     $cacheFile = $cx->getComponent('Cache')->getCacheFileNameFromUrl($urlPattern);
     try {
         $file = new \Cx\Lib\FileSystem\File($strCachePath . $cacheFile);
         $file->delete();
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
     }
     // make sure HTTP and HTTPS files are dropped
     if (substr($urlPattern, 0, 5) == 'https') {
         $urlPattern = 'http' . substr($urlPattern, 5);
     } else {
         if (substr($urlPattern, 0, 4) == 'http') {
             $urlPattern = 'https' . substr($urlPattern, 4);
         }
     }
     $cacheFile = md5($urlPattern);
     try {
         $file = new \Cx\Lib\FileSystem\File($strCachePath . $cacheFile);
         $file->delete();
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
     }
 }
Exemplo n.º 3
0
 /**
  * Start caching functions. If this page is already cached, load it, otherwise create new file
  */
 public function startContrexxCaching()
 {
     if (!$this->boolIsEnabled) {
         return null;
     }
     $files = glob($this->strCachePath . $this->strCacheFilename . "*");
     foreach ($files as $file) {
         if (filemtime($file) > time() - $this->intCachingTime) {
             //file was cached before, load it
             readfile($file);
             exit;
         } else {
             $File = new \Cx\Lib\FileSystem\File($file);
             $File->delete();
         }
     }
     //if there is no cached file, start recording
     ob_start();
 }
Exemplo n.º 4
0
 /**
  * Deletes the file from the path specified
  *
  * Returns true if the file doesn't exist in the first place.
  * @param   string    $file_path      The path of the file
  * @return  boolean                   True on success, false otherwise
  */
 public static function delete_file($file_path)
 {
     try {
         $objFile = new \Cx\Lib\FileSystem\File($file_path);
         $objFile->delete();
         return true;
     } catch (FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * Deletes all entries for the current section
  *
  * This is for testing purposes only.  Use with care!
  * The $section determines the module affected.
  * @return    boolean               True on success, false otherwise
  */
 function deleteModule()
 {
     if (empty($this->section)) {
         return false;
     }
     try {
         $objFile = new \Cx\Lib\FileSystem\File($this->filename);
         $objFile->delete();
         return true;
     } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
         \DBG::msg($e->getMessage());
     }
 }
Exemplo n.º 6
0
function executeContrexxUpdate()
{
    global $_CORELANG, $_CONFIG, $objDatabase, $objUpdate, $_DBCONFIG;
    /**
     * These are the modules which MUST have new template in order for Cloudrexx
     * to work correctly. CSS definitions for these modules will get updated too.
     */
    $viewUpdateTable = array('newsletter' => array('version' => '3.1.0.0', 'dependencies' => array('forms')), 'calendar' => array('version' => '3.1.0.0', 'dependencies' => array()), 'shop' => array('version' => '3.0.0.0', 'dependencies' => array('forms')), 'voting' => array('version' => '2.1.0.0', 'dependencies' => array()), 'access' => array('version' => '2.0.0.0', 'dependencies' => array('forms', 'captcha', 'uploader')), 'podcast' => array('version' => '2.0.0.0', 'dependencies' => array()), 'login' => array('version' => '3.0.2.0', 'dependencies' => array('forms', 'captcha')), 'media1' => array('version' => '3.0.0.0', 'dependencies' => array()), 'media2' => array('version' => '3.0.0.0', 'dependencies' => array()), 'media3' => array('version' => '3.0.0.0', 'dependencies' => array()), 'media4' => array('version' => '3.0.0.0', 'dependencies' => array()));
    $_SESSION['contrexx_update']['copyFilesFinished'] = !empty($_SESSION['contrexx_update']['copyFilesFinished']) ? $_SESSION['contrexx_update']['copyFilesFinished'] : false;
    // Copy cx files to the root directory
    if (!$_SESSION['contrexx_update']['copyFilesFinished']) {
        if (!loadMd5SumOfOriginalCxFiles()) {
            return false;
        }
        $copyFilesStatus = copyCxFilesToRoot(dirname(__FILE__) . '/cx_files', ASCMS_PATH . ASCMS_PATH_OFFSET);
        if ($copyFilesStatus !== true) {
            if ($copyFilesStatus === 'timeout') {
                setUpdateMsg(1, 'timeout');
            }
            return false;
        }
        if (extension_loaded('apc') && ini_get('apc.enabled')) {
            apc_clear_cache();
        }
        $_SESSION['contrexx_update']['copyFilesFinished'] = true;
        // log modified files
        DBG::msg('MODIFIED FILES:');
        if (isset($_SESSION['contrexx_update']['modified_files'])) {
            DBG::dump($_SESSION['contrexx_update']['modified_files']);
        }
        // we need to stop the script here to force a reinitialization of the update system
        // this is required so that the new constants from config/set_constants.php are loaded
        //setUpdateMsg($_CORELANG['TXT_UPDATE_PROCESS_HALTED'], 'title');
        //setUpdateMsg($_CORELANG['TXT_UPDATE_PROCESS_HALTED_TIME_MSG'].'<br />', 'msg');
        //setUpdateMsg('Installation der neuen Dateien abgeschlossen.<br /><br />', 'msg');
        //setUpdateMsg('<input type="submit" value="'.$_CORELANG['TXT_CONTINUE_UPDATE'].'" name="updateNext" /><input type="hidden" name="processUpdate" id="processUpdate" />', 'button');
        setUpdateMsg(1, 'timeout');
        return false;
    }
    unset($_SESSION['contrexx_update']['copiedCxFilesIndex']);
    /**
     * This needs to be initialized before loading config/doctrine.php
     * Because we overwrite the Gedmo model (so we need to load our model
     * before doctrine loads the Gedmo one)
     */
    require_once ASCMS_CORE_PATH . '/ClassLoader/ClassLoader.class.php';
    $cl = new \Cx\Core\ClassLoader\ClassLoader(ASCMS_DOCUMENT_ROOT, true);
    Env::set('ClassLoader', $cl);
    FWLanguage::init();
    if (!isset($_SESSION['contrexx_update']['update'])) {
        $_SESSION['contrexx_update']['update'] = array();
    }
    if (!isset($_SESSION['contrexx_update']['update']['done'])) {
        $_SESSION['contrexx_update']['update']['done'] = array();
    }
    /////////////////////
    // UTF-8 MIGRATION //
    /////////////////////
    if (!(include_once dirname(__FILE__) . '/components/core/core.php')) {
        setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_UPDATE_COMPONENT'], dirname(__FILE__) . '/components/core/core.php'));
        return false;
    }
    if (!(include_once dirname(__FILE__) . '/components/core/utf8.php')) {
        setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_UPDATE_COMPONENT'], dirname(__FILE__) . '/components/core/utf8.php'));
        return false;
    }
    if (!in_array('utf8', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $result = _utf8Update();
        if ($result === 'timeout') {
            setUpdateMsg(1, 'timeout');
            return false;
        } elseif (!$result) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UTF_CONVERSION']), 'title');
            }
            return false;
        }
        if ($result === 'charset_changed') {
            // write new charset/collation definition to config file
            if (!_writeNewConfigurationFile()) {
                return false;
            }
        }
        $_SESSION['contrexx_update']['update']['done'][] = 'utf8';
        // _utf8Update() might have changed the charset/collation and migrated some tables,
        // therefore, we will force a reinitialization of the update system
        // to ensure that all db-connections are using the proper charset/collation
        \DBG::msg('Changed collation to: ' . $_DBCONFIG['collation']);
        \DBG::msg('Force reinitialization of update...');
        setUpdateMsg(1, 'timeout');
        return false;
    }
    /////////////////////
    /////////////////////////////
    // Session Table MIGRATION //
    /////////////////////////////
    $isSessionVariableTableExists = \Cx\Lib\UpdateUtil::table_exist(DBPREFIX . 'session_variable');
    if ($isSessionVariableTableExists) {
        createOrAlterSessionVariableTable();
    }
    if (!$isSessionVariableTableExists && $objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.2.0')) {
        if (!migrateSessionTable()) {
            setUpdateMsg('Error in updating session table', 'error');
            return false;
        }
        setUpdateMsg(1, 'timeout');
        return false;
    }
    // Load Doctrine (this must be done after the UTF-8 Migration, because we'll need $_DBCONFIG['charset'] to be set)
    $incDoctrineStatus = (require_once UPDATE_PATH . '/config/doctrine.php');
    Env::set('incDoctrineStatus', $incDoctrineStatus);
    $userData = array('id' => $_SESSION['contrexx_update']['user_id'], 'name' => $_SESSION['contrexx_update']['username']);
    $loggableListener = \Env::get('loggableListener');
    $loggableListener->setUsername(json_encode($userData));
    /////////////////////
    if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.0.0')) {
        //////////////////////////////
        // BEGIN: CONTENT MIGRATION //
        //////////////////////////////
        DBG::msg('Installed version: ' . $_CONFIG['coreCmsVersion']);
        Env::get('ClassLoader')->loadFile(dirname(__FILE__) . '/ContentMigration.class.php');
        $contentMigration = new \Cx\Update\Cx_3_0_4\ContentMigration();
        // Migrate statistics - this must be done before migrating to the new content architecture
        if (empty($_SESSION['contrexx_update']['content_stats'])) {
            DBG::msg('Migrate stats');
            if ($contentMigration->migrateStatistics()) {
                $_SESSION['contrexx_update']['content_stats'] = true;
                if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                    return false;
                }
            } else {
                return false;
            }
        }
        // Check if there are content of inactive languages.
        // If true then ask if the update system can remove them.
        if (empty($_SESSION['contrexx_update']['inactive_content_languages_checked'])) {
            DBG::msg('Check inactive content languages');
            $arrMigrateLangIds = $contentMigration->getActiveContentLanguageIds();
            if (!isset($_POST['skipMigrateLangIds'])) {
                $result = $contentMigration->getInactiveContentLanguageCheckboxes();
                if (!empty($result)) {
                    setUpdateMsg('Inhaltsseiten von inaktiven Sprache(n) gefunden', 'title');
                    setUpdateMsg('
                        Folgende Sprache(n) sind inaktiv, aber enthalten Inhaltsseiten:<br />
                        ' . $result . '<br />
                        Wählen Sie die inaktiven Sprachen, dessen Inhaltseiten Sie migrieren möchten.<br />
                        Klicken Sie anschliessend auf <b>Update fortsetzen...</b>.<br /><br />
                        <div class="message-alert">
                        <b>Achtung:</b><br />
                        Die Inhaltsseiten der inaktive Sprache(n), welche Sie nicht ausgewählt haben, werden gelöscht.
                        </div>
                    ', 'msg');
                    setUpdateMsg('<input type="submit" value="' . $_CORELANG['TXT_CONTINUE_UPDATE'] . '" name="updateNext" /><input type="hidden" name="processUpdate" id="processUpdate" /><input type="hidden" name="skipMigrateLangIds" id="skipMigrateLangIds" />', 'button');
                    return false;
                }
            } else {
                if (!empty($_POST['migrateLangIds'])) {
                    if (is_array($_POST['migrateLangIds'])) {
                        $_POST['migrateLangIds'] = array_filter($_POST['migrateLangIds'], 'intval');
                        if (!empty($_POST['migrateLangIds'])) {
                            $arrMigrateLangIds = array_merge($arrMigrateLangIds, $_POST['migrateLangIds']);
                        }
                    } else {
                        if (intval($_POST['migrateLangIds'])) {
                            $arrMigrateLangIds[] = intval($_POST['migrateLangIds']);
                        }
                    }
                }
            }
            $_SESSION['contrexx_update']['migrate_lang_ids'] = $arrMigrateLangIds;
            $_SESSION['contrexx_update']['inactive_content_languages_checked'] = true;
        }
        if (empty($_SESSION['contrexx_update']['migrate_lang_ids'])) {
            $_SESSION['contrexx_update']['migrate_lang_ids'] = $contentMigration->getActiveContentLanguageIds();
        }
        $contentMigration->arrMigrateLangIds = ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['migrate_lang_ids']);
        $contentMigration->migrateLangIds = implode(',', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['migrate_lang_ids']));
        // Migrate content
        if (empty($_SESSION['contrexx_update']['content_migrated'])) {
            DBG::msg('Migrate content');
            $status = $contentMigration->migrate();
            if ($status === true) {
                $_SESSION['contrexx_update']['content_migrated'] = true;
                // log migrated nodes
                DBG::msg('NODES: catId -> nodeId');
                DBG::dump(ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['nodes']));
                unset($_SESSION['contrexx_update']['nodes']);
                // log migrated pages
                DBG::msg('PAGES: catId -> pageId');
                DBG::dump(ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['pages']));
                unset($_SESSION['contrexx_update']['pages']);
                if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                    return false;
                }
            } else {
                if ($status === 'timeout') {
                    setUpdateMsg(1, 'timeout');
                    return false;
                } else {
                    return false;
                }
            }
        }
        // Page grouping
        if (empty($_SESSION['contrexx_update']['pages_grouped'])) {
            DBG::msg('Group pages');
            $pageGrouping = $contentMigration->pageGrouping();
            if ($pageGrouping === true) {
                $_SESSION['contrexx_update']['pages_grouped'] = true;
                if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                    return false;
                }
            } else {
                if ($pageGrouping === 'timeout') {
                    setUpdateMsg(1, 'timeout');
                    return false;
                } else {
                    if ($pageGrouping === false) {
                        return false;
                    } else {
                        if (!empty($pageGrouping)) {
                            $arrDialogData = array('similarPages' => $contentMigration->similarPages);
                            setUpdateMsg('Inhaltsseiten gruppieren', 'title');
                            setUpdateMsg($pageGrouping, 'msg');
                            setUpdateMsg('<input type="submit" value="' . $_CORELANG['TXT_UPDATE_NEXT'] . '" name="updateNext" /><input type="hidden" name="processUpdate" id="processUpdate" />', 'button');
                            setUpdateMsg($arrDialogData, 'dialog');
                            return false;
                        }
                    }
                }
            }
        }
        // Migrate aliases
        if (empty($_SESSION['contrexx_update']['aliases_migrated'])) {
            DBG::msg('Migrate aliases');
            if ($contentMigration->migrateAliases()) {
                $_SESSION['contrexx_update']['aliases_migrated'] = true;
                if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                    return false;
                }
            } else {
                return false;
            }
        }
        // Migrate blocks
        if (empty($_SESSION['contrexx_update']['blocks_migrated'])) {
            DBG::msg('Migrate blocks');
            if ($contentMigration->migrateBlocks()) {
                $_SESSION['contrexx_update']['blocks_migrated'] = true;
                if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                    return false;
                }
            } else {
                return false;
            }
        }
        // Drop old tables
        if (empty($_SESSION['contrexx_update']['old_tables_dropped'])) {
            DBG::msg('Drop old tables');
            if ($contentMigration->dropOldTables()) {
                $_SESSION['contrexx_update']['old_tables_dropped'] = true;
                if (!checkMemoryLimit() || !checkTimeoutLimit()) {
                    return false;
                }
            }
        }
        ////////////////////////////
        // END: CONTENT MIGRATION //
        ////////////////////////////
    } else {
        ///////////////////////////////////////////
        // BEGIN: UPDATE FOR CONTREXX 3 OR NEWER //
        ///////////////////////////////////////////
        $result = _updateModuleRepository();
        if ($result === false) {
            DBG::msg('unable to update module repository');
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_MODULE_REPOSITORY']), 'title');
            }
            return false;
        } else {
            try {
                \Cx\Lib\UpdateUtil::sql('UPDATE `' . DBPREFIX . 'log_entry`
                    SET `object_class` = \'Cx\\\\Core\\\\ContentManager\\\\Model\\\\Entity\\\\Page\'
                    WHERE object_class = \'Cx\\\\Model\\\\ContentManager\\\\Page\'');
            } catch (\Cx\Lib\UpdateException $e) {
                return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
            }
            // before an update of module page can be done, the db changes have to be done
            \Cx\Lib\UpdateUtil::table(DBPREFIX . 'content_page', array('id' => array('type' => 'INT(11)', 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'node_id' => array('type' => 'INT(11)', 'notnull' => false, 'after' => 'id'), 'nodeIdShadowed' => array('type' => 'INT(11)', 'notnull' => false, 'after' => 'node_id'), 'lang' => array('type' => 'INT(11)', 'after' => 'nodeIdShadowed'), 'type' => array('type' => 'VARCHAR(16)', 'after' => 'lang'), 'caching' => array('type' => 'TINYINT(1)', 'after' => 'type'), 'updatedAt' => array('type' => 'timestamp', 'after' => 'caching', 'notnull' => false), 'updatedBy' => array('type' => 'CHAR(40)', 'after' => 'updatedAt'), 'title' => array('type' => 'VARCHAR(255)', 'after' => 'updatedBy'), 'linkTarget' => array('type' => 'VARCHAR(16)', 'notnull' => false, 'after' => 'title'), 'contentTitle' => array('type' => 'VARCHAR(255)', 'after' => 'linkTarget'), 'slug' => array('type' => 'VARCHAR(255)', 'after' => 'contentTitle'), 'content' => array('type' => 'longtext', 'after' => 'slug'), 'sourceMode' => array('type' => 'TINYINT(1)', 'notnull' => true, 'default' => '0', 'after' => 'content'), 'customContent' => array('type' => 'VARCHAR(64)', 'notnull' => false, 'after' => 'sourceMode'), 'useCustomContentForAllChannels' => array('type' => 'INT(2)', 'after' => 'customContent', 'notnull' => false), 'cssName' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'useCustomContentForAllChannels'), 'cssNavName' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'cssName'), 'skin' => array('type' => 'INT(11)', 'notnull' => false, 'after' => 'cssNavName'), 'useSkinForAllChannels' => array('type' => 'INT(2)', 'after' => 'skin', 'notnull' => false), 'metatitle' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'useSkinForAllChannels'), 'metadesc' => array('type' => 'text', 'after' => 'metatitle'), 'metakeys' => array('type' => 'text', 'after' => 'metadesc'), 'metarobots' => array('type' => 'VARCHAR(7)', 'notnull' => false, 'after' => 'metakeys'), 'start' => array('type' => 'timestamp', 'after' => 'metarobots', 'notnull' => false), 'end' => array('type' => 'timestamp', 'after' => 'start', 'notnull' => false), 'editingStatus' => array('type' => 'VARCHAR(16)', 'after' => 'end'), 'protection' => array('type' => 'INT(11)', 'after' => 'editingStatus'), 'frontendAccessId' => array('type' => 'INT(11)', 'after' => 'protection'), 'backendAccessId' => array('type' => 'INT(11)', 'after' => 'frontendAccessId'), 'display' => array('type' => 'TINYINT(1)', 'after' => 'backendAccessId'), 'active' => array('type' => 'TINYINT(1)', 'after' => 'display'), 'target' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'active'), 'module' => array('type' => 'VARCHAR(255)', 'notnull' => false, 'after' => 'target'), 'cmd' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => '', 'after' => 'module')), array('node_id' => array('fields' => array('node_id', 'lang'), 'type' => 'UNIQUE'), 'IDX_D8E86F54460D9FD7' => array('fields' => array('node_id'))), 'InnoDB', '', array('node_id' => array('table' => DBPREFIX . 'content_node', 'column' => 'id', 'onDelete' => 'SET NULL', 'onUpdate' => 'NO ACTION')));
            if (_convertThemes2Component() === false) {
                if (empty($objUpdate->arrStatusMsg['title'])) {
                    DBG::msg('unable to convert themes to component');
                    setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_CONVERT_TEMPLATES']), 'title');
                }
                return false;
            }
            if (_updateModulePages($viewUpdateTable) === false) {
                if (empty($objUpdate->arrStatusMsg['title'])) {
                    DBG::msg('unable to update module templates');
                    setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_MODULE_TEMPLATES']), 'title');
                }
                return false;
            }
            /* else {
                   if (!in_array('moduleStyles', $_SESSION['contrexx_update']['update']['done'])) {
                       if (_updateCssDefinitions($viewUpdateTable, $objUpdate) === false) {
                           if (empty($objUpdate->arrStatusMsg['title'])) {
                               setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_MODULE_TEMPLATES']), 'title');
                           }
                           return false;
                       }
                       $_SESSION['contrexx_update']['update']['done'][] = 'moduleStyles';
                   }
               }*/
        }
        // we are updating from 3.0.0 rc1, rc2, stable or 3.0.0.1
        if (!(include_once dirname(__FILE__) . '/update3.php')) {
            setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_UPDATE_COMPONENT'], dirname(__FILE__) . '/update3.php'));
            return false;
        }
        if (!createHtAccess()) {
            $webServerSoftware = !empty($_SERVER['SERVER_SOFTWARE']) && stristr($_SERVER['SERVER_SOFTWARE'], 'apache') ? 'apache' : (stristr($_SERVER['SERVER_SOFTWARE'], 'iis') ? 'iis' : '');
            $file = $webServerSoftware == 'iis' ? 'web.config' : '.htaccess';
            setUpdateMsg('Die Datei \'' . $file . '\' konnte nicht erstellt/aktualisiert werden.');
            return false;
        }
        // Update configuration.php
        if (!_writeNewConfigurationFile()) {
            return false;
        }
        $arrUpdate = $objUpdate->getLoadedVersionInfo();
        $_CONFIG['coreCmsVersion'] = $arrUpdate['cmsVersion'];
        $lupd = new License();
        try {
            $lupd->update(false);
        } catch (\Cx\Lib\UpdateException $e) {
            setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_LICENSE_DATA']), 'title');
            return false;
        }
        return true;
        /////////////////////////////////////////
        // END: UPDATE FOR CONTREXX 3 OR NEWER //
        /////////////////////////////////////////
    }
    ///////////////////////////////////////////
    // CONTINUE UPDATE FOR NON CX 3 VERSIONS //
    ///////////////////////////////////////////
    $arrDirs = array('core_module', 'module');
    $updateStatus = true;
    if (!(include_once dirname(__FILE__) . '/components/core/backendAreas.php')) {
        setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_UPDATE_COMPONENT'], dirname(__FILE__) . '/components/core/backendAreas.php'));
        return false;
    } elseif (!(include_once dirname(__FILE__) . '/components/core/modules.php')) {
        setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_UPDATE_COMPONENT'], dirname(__FILE__) . '/components/core/modules.php'));
        return false;
    } elseif (!(include_once dirname(__FILE__) . '/components/core/settings.php')) {
        setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_UPDATE_COMPONENT'], dirname(__FILE__) . '/components/core/settings.php'));
        return false;
    }
    if (!in_array('coreUpdate', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $result = _coreUpdate();
        if ($result === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_CORE_SYSTEM']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'coreUpdate';
        }
    }
    $missedModules = array();
    if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.0.0')) {
        $missedModules = getMissedModules();
        $conflictedModules = getConflictedModules($missedModules);
        if (!empty($conflictedModules)) {
            $conflictedModulesList = '';
            foreach ($conflictedModules as $moduleName => $moduleTables) {
                $conflictedModulesList = '<li><strong>' . $moduleName . ':</strong> ' . implode(', ', $moduleTables) . '</li>';
            }
            setUpdateMsg($_CORELANG['TXT_CONFLICTED_MODULES_TITLE'], 'title');
            setUpdateMsg($_CORELANG['TXT_CONFLICTED_MODULES_DESCRIPTION'] . '<ul>' . $conflictedModulesList . '</ul>', 'msg');
            setUpdateMsg('<input type="submit" value="' . $_CORELANG['TXT_UPDATE_TRY_AGAIN'] . '" name="updateNext" /><input type="hidden" name="processUpdate" id="processUpdate" />', 'button');
            return false;
        }
    }
    foreach ($arrDirs as $dir) {
        $dh = opendir(dirname(__FILE__) . '/components/' . $dir);
        if ($dh) {
            while (($file = readdir($dh)) !== false) {
                if (!in_array($file, ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
                    $fileInfo = pathinfo(dirname(__FILE__) . '/components/' . $dir . '/' . $file);
                    if ($fileInfo['extension'] == 'php') {
                        DBG::msg("--------- updating {$file} ------");
                        if (!(include_once dirname(__FILE__) . '/components/' . $dir . '/' . $file)) {
                            setUpdateMsg($_CORELANG['TXT_UPDATE_ERROR'], 'title');
                            setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_UPDATE_COMPONENT'], dirname(__FILE__) . '/components/' . $dir . '/' . $file));
                            return false;
                        }
                        if (!in_array($fileInfo['filename'], $missedModules)) {
                            $function = '_' . $fileInfo['filename'] . 'Update';
                            if (function_exists($function)) {
                                $result = $function();
                                if ($result === false) {
                                    if (empty($objUpdate->arrStatusMsg['title'])) {
                                        setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $file), 'title');
                                    }
                                    return false;
                                } elseif ($result === 'timeout') {
                                    setUpdateMsg(1, 'timeout');
                                    return false;
                                }
                            } else {
                                setUpdateMsg($_CORELANG['TXT_UPDATE_ERROR'], 'title');
                                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UPDATE_COMPONENT_CORRUPT'], '.' . $fileInfo['filename'], $file));
                                return false;
                            }
                        } else {
                            $function = '_' . $fileInfo['filename'] . 'Install';
                            if (function_exists($function)) {
                                $result = $function();
                                if ($result === false) {
                                    if (empty($objUpdate->arrStatusMsg['title'])) {
                                        setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $file), 'title');
                                    }
                                    return false;
                                } elseif ($result === 'timeout') {
                                    setUpdateMsg(1, 'timeout');
                                    return false;
                                } else {
                                    // fetch module info from components/core/module.php
                                    $arrModule = getModuleInfo($fileInfo['filename']);
                                    if ($arrModule) {
                                        try {
                                            \Cx\Lib\UpdateUtil::sql("INSERT INTO " . DBPREFIX . "modules ( `id` , `name` , `description_variable` , `status` , `is_required` , `is_core` , `distributor` ) VALUES ( " . $arrModule['id'] . " , '" . $arrModule['name'] . "', '" . $arrModule['description_variable'] . "', '" . $arrModule['status'] . "', '" . $arrModule['is_required'] . "', '" . $arrModule['is_core'] . "', 'Comvation AG') ON DUPLICATE KEY UPDATE `id` = `id`");
                                        } catch (\Cx\Lib\UpdateException $e) {
                                            return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
                                        }
                                    } else {
                                        DBG::msg('unable to register module ' . $fileInfo['filename']);
                                    }
                                }
                            } else {
                                setUpdateMsg($_CORELANG['TXT_UPDATE_ERROR'], 'title');
                                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UPDATE_COMPONENT_CORRUPT'], '.' . $fileInfo['filename'], $file));
                                return false;
                            }
                        }
                    }
                    $_SESSION['contrexx_update']['update']['done'][] = $file;
                    setUpdateMsg(1, 'timeout');
                    return false;
                }
            }
        } else {
            setUpdateMsg($_CORELANG['TXT_UPDATE_ERROR'], 'title');
            setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_UNABLE_LOAD_DIR_COMPONENTS'], dirname(__FILE__) . '/components/' . $dir));
            return false;
        }
        closedir($dh);
    }
    if (!in_array('coreSettings', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $result = _updateSettings();
        if ($result === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_BASIC_CONFIGURATION']), 'title');
            }
            return false;
        } else {
            // update configuration.php (migrate to new format)
            if (!_writeNewConfigurationFile()) {
                return false;
            }
            $_SESSION['contrexx_update']['update']['done'][] = 'coreSettings';
            // till this point the file config/version.php was still loaded upon a request,
            // therefore we must force a new page request here, to ensure that the file config/version.php
            // will not be loaded anylonger. This is essential here, otherwise the old values of config/version.php
            // would screw up the update process
            setUpdateMsg(1, 'timeout');
            return false;
        }
    }
    if (!in_array('coreModules', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $result = _updateModules();
        if ($result === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_MODULES']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'coreModules';
        }
    }
    if (!in_array('coreBackendAreas', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $result = _updateBackendAreas();
        if ($result === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_SECURITY_SYSTEM']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'coreBackendAreas';
        }
    }
    if (!in_array('coreModuleRepository', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $result = _updateModuleRepository();
        if ($result === false) {
            DBG::msg('unable to update module repository');
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_MODULE_REPOSITORY']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'coreModuleRepository';
        }
    }
    if (!in_array('convertTemplates', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $result = _convertThemes2Component();
        if ($result === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                DBG::msg('unable to convert themes to component');
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_CONVERT_TEMPLATES']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'convertTemplates';
        }
    }
    if (!in_array('moduleTemplates', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        if (_updateModulePages($viewUpdateTable) === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                DBG::msg('unable to update module templates');
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_MODULE_TEMPLATES']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'moduleTemplates';
        }
    }
    if (!in_array('moduleStyles', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        if (_updateCssDefinitions($viewUpdateTable, $objUpdate) === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_MODULE_TEMPLATES']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'moduleStyles';
        }
    }
    if (!in_array('navigations', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        if (_updateNavigations() === false) {
            if (empty($objUpdate->arrStatusMsg['title'])) {
                setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_NAVIGATIONS']), 'title');
            }
            return false;
        } else {
            $_SESSION['contrexx_update']['update']['done'][] = 'navigations';
        }
    }
    if (!createHtAccess()) {
        $webServerSoftware = !empty($_SERVER['SERVER_SOFTWARE']) && stristr($_SERVER['SERVER_SOFTWARE'], 'apache') ? 'apache' : (stristr($_SERVER['SERVER_SOFTWARE'], 'iis') ? 'iis' : '');
        $file = $webServerSoftware == 'iis' ? 'web.config' : '.htaccess';
        setUpdateMsg('Die Datei \'' . $file . '\' konnte nicht erstellt/aktualisiert werden.');
        return false;
    }
    if (file_exists(ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php')) {
        \DBG::msg('/cadmin/index.php still exists...');
        // move cadmin index.php if its customized
        if (!loadMd5SumOfOriginalCxFiles()) {
            return false;
        }
        if (!verifyMd5SumOfFile(ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php', '', false)) {
            \DBG::msg('...and it\'s customized, so let\'s move it to customizing directory');
            // changes, backup modified file
            if (!backupModifiedFile(ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php')) {
                setUpdateMsg('Die Datei \'' . ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php\' konnte nicht kopiert werden.');
                return false;
            }
        } else {
            \DBG::msg('...but it\'s not customized');
        }
        // no non-backupped changes, can delete
        try {
            \DBG::msg('So let\'s remove it...');
            $cadminIndex = new \Cx\Lib\FileSystem\File(ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php');
            $cadminIndex->delete();
        } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
            setUpdateMsg('Die Datei \'' . ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php\' konnte nicht gelöscht werden.');
            return false;
        }
    }
    $arrUpdate = $objUpdate->getLoadedVersionInfo();
    $_CONFIG['coreCmsVersion'] = $arrUpdate['cmsVersion'];
    if (!in_array('coreLicense', ContrexxUpdate::_getSessionArray($_SESSION['contrexx_update']['update']['done']))) {
        $lupd = new License();
        try {
            $result = $lupd->update();
        } catch (\Cx\Lib\UpdateException $e) {
            setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_LICENSE_DATA']), 'title');
            return false;
        }
        // ignore error to allow offline installations
        /*if ($result === false) {
              if (empty($objUpdate->arrStatusMsg['title'])) {
                  setUpdateMsg(sprintf($_CORELANG['TXT_UPDATE_COMPONENT_BUG'], $_CORELANG['TXT_UPDATE_LICENSE_DATA']), 'title');
              }
              return false;
          } else {*/
        $_SESSION['contrexx_update']['update']['done'][] = 'coreLicense';
        //}
    }
    return true;
}
Exemplo n.º 7
0
    }
    if (!verifyMd5SumOfFile(ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php', '', false)) {
        \DBG::msg('...and it\'s customized, so let\'s move it to customizing directory');
        // changes, backup modified file
        if (!backupModifiedFile(ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php')) {
            setUpdateMsg('Die Datei \'' . ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php\' konnte nicht kopiert werden.');
            return false;
        }
    } else {
        \DBG::msg('...but it\'s not customized');
    }
    // no non-backupped changes, can delete
    try {
        \DBG::msg('So let\'s remove it...');
        $cadminIndex = new \Cx\Lib\FileSystem\File(ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php');
        $cadminIndex->delete();
    } catch (\Cx\Lib\FileSystem\FileSystemException $e) {
        setUpdateMsg('Die Datei \'' . ASCMS_DOCUMENT_ROOT . ASCMS_BACKEND_PATH . '/index.php\' konnte nicht gelöscht werden.');
        return false;
    }
}
/***************************************
 *
 * CALENDAR: FIX TABLE
 * only for 3.1.0
 *
 **************************************/
// fixing news container text setting which cannot be activated
if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.1.1')) {
    try {
        $result = \Cx\Lib\UpdateUtil::sql('SELECT `name` FROM `' . DBPREFIX . 'module_news_settings` WHERE `name` = "news_use_teaser_text"');
Exemplo n.º 8
0
 /**
  * Parses ESI directives internally if configured to do so
  * @param string $htmlCode HTML code to replace ESI directives in
  * @return string Parsed HTML code
  */
 public function internalEsiParsing($htmlCode, $cxNotYetInitialized = false)
 {
     if (!is_a($this->getSsiProxy(), '\\Cx\\Core_Modules\\Cache\\Model\\Entity\\ReverseProxyCloudrexx')) {
         return $htmlCode;
     }
     // Replace include tags
     $settings = $this->getSettings();
     // apply ESI dynamic variables
     foreach ($this->dynVars as $groupName => $vars) {
         foreach ($vars as $varName => $url) {
             $esiPlaceholder = '$(' . $groupName . '{\'' . $varName . '\'})';
             if (strpos($htmlCode, $esiPlaceholder) === false) {
                 continue;
             }
             $varValue = $this->getApiResponseForUrl($url);
             $htmlCode = str_replace($esiPlaceholder, $varValue, $htmlCode);
         }
     }
     $replaceEsiFn = function ($matches) use(&$cxNotYetInitialized, $settings) {
         // return cached content if available
         $cacheFile = $this->getCacheFileNameFromUrl($matches[1]);
         if ($settings['internalSsiCache'] == 'on' && file_exists($this->strCachePath . $cacheFile)) {
             if (filemtime($this->strCachePath . $cacheFile) > time() - $this->intCachingTime) {
                 return file_get_contents($this->strCachePath . $cacheFile);
             } else {
                 $file = new \Cx\Lib\FileSystem\File($this->strCachePath . $cacheFile);
                 $file->delete();
             }
         }
         if ($cxNotYetInitialized) {
             \Cx\Core\Core\Controller\Cx::instanciate(\Cx\Core\Core\Controller\Cx::MODE_MINIMAL, true, null, true);
             $cxNotYetInitialized = false;
         }
         // TODO: Somehow FRONTEND_LANG_ID is sometimes undefined here...
         if (!defined('FRONTEND_LANG_ID')) {
             define('FRONTEND_LANG_ID', 1);
         }
         $content = $this->getApiResponseForUrl($matches[1]);
         if ($settings['internalSsiCache'] == 'on') {
             $file = new \Cx\Lib\FileSystem\File($this->strCachePath . $cacheFile);
             $file->write($content);
         }
         return $content;
     };
     do {
         // Random include tags
         $htmlCode = preg_replace_callback('#<!-- ESI_RANDOM_START -->[\\s\\S]*<esi:assign name="content_list">\\s*\\[([^\\]]+)\\]\\s*</esi:assign>[\\s\\S]*<!-- ESI_RANDOM_END -->#', function ($matches) {
             $uris = explode('\',\'', substr($matches[1], 1, -1));
             $randomNumber = rand(0, count($uris) - 1);
             $uri = $uris[$randomNumber];
             // this needs to match the format below!
             return '<esi:include src="' . $uri . '" onerror="continue"/>';
         }, $htmlCode);
         $htmlCode = preg_replace_callback('#<esi:include src="([^"]+)" onerror="continue"/>#', $replaceEsiFn, $htmlCode, -1, $count);
         // repeat replacement to recursively parse ESI-tags
     } while ($count);
     return $htmlCode;
 }