function activateDebugging() { $File = new \Cx\Lib\FileSystem\File(ASCMS_DOCUMENT_ROOT . '/update/dbg.log'); if ($File->getAccessMode() == \Cx\Lib\FileSystem\File::FTP_ACCESS) { throw new \Exception('Cannot write log via FTP (file needs to be loaded into memory which leads to memory overflow)'); } // temporariy disable FTP support to prevent the FileSystem // from creating the dbg.log file through FTP $ftpConfig = \Env::get('ftpConfig'); if ($ftpConfig['is_activated']) { \DBG::msg('Update: Intentionally deactivate FTP support as we do not support to write the update log (dbg.log) through FTP due to potential memory overflows.'); $hackedFtpConfig = $ftpConfig; $hackedFtpConfig['is_activated'] = false; \Env::set('ftpConfig', $hackedFtpConfig); } $File->touch(); // reset FTP if ($ftpConfig['is_activated']) { \Env::set('ftpConfig', $ftpConfig); } if ($File->makeWritable()) { \DBG::activate(DBG_LOG_FILE | DBG_PHP | DBG_DB); return true; } return false; }
public static function makeWritable($path) { try { $objFile = new \Cx\Lib\FileSystem\File($path); $objFile->makeWritable(); return true; } catch (FileSystemException $e) { \DBG::msg($e->getMessage()); } return false; }
function _writeNewConfigurationFile() { global $_CORELANG, $_ARRAYLANG, $_DBCONFIG, $_PATHCONFIG, $_FTPCONFIG, $_CONFIGURATION, $_CONFIG; $ftpStatus = $_FTPCONFIG['is_activated'] ? 'true' : 'false'; $charset = 'UTF-8'; $dbCharset = 'utf8'; $_FTPCONFIG['port'] = intval($_FTPCONFIG['port']); $configurationTpl = <<<CONFIG_TPL <?php global \$_DBCONFIG, \$_PATHCONFIG, \$_FTPCONFIG, \$_CONFIG; /** * @exclude * * Cloudrexx CMS Web Installer * Please use the Cloudrexx CMS installer to configure this file * or edit this file and configure the parameters for your site and * database manually. */ /** * ------------------------------------------------------------------------- * Set installation status * ------------------------------------------------------------------------- */ define('CONTREXX_INSTALLED', true); /** * ------------------------------------------------------------------------- * Database configuration section * ------------------------------------------------------------------------- */ \$_DBCONFIG['host'] = '{$_DBCONFIG['host']}'; // This is normally set to localhost \$_DBCONFIG['database'] = '{$_DBCONFIG['database']}'; // Database name \$_DBCONFIG['tablePrefix'] = '{$_DBCONFIG['tablePrefix']}'; // Database table prefix \$_DBCONFIG['user'] = '******'user']}'; // Database username \$_DBCONFIG['password'] = '******'password']}'; // Database password \$_DBCONFIG['dbType'] = '{$_DBCONFIG['dbType']}'; // Database type (e.g. mysql,postgres ..) \$_DBCONFIG['charset'] = '{$dbCharset}'; // Charset (default, latin1, utf8, ..) \$_DBCONFIG['timezone'] = '{$_CONFIG['timezone']}'; // Controller's timezone for model \$_DBCONFIG['collation'] = '{$_DBCONFIG['collation']}'; /** * ------------------------------------------------------------------------- * Site path specific configuration * ------------------------------------------------------------------------- */ \$_PATHCONFIG['ascms_root'] = ''; \$_PATHCONFIG['ascms_root_offset'] = ''; // example: '/cms'; \$_PATHCONFIG['ascms_installation_root'] = \$_PATHCONFIG['ascms_root']; \$_PATHCONFIG['ascms_installation_offset'] = \$_PATHCONFIG['ascms_root_offset']; // example: '/cms'; /** * ------------------------------------------------------------------------- * Ftp specific configuration * ------------------------------------------------------------------------- */ \$_FTPCONFIG['is_activated'] = {$ftpStatus}; // Ftp support true or false \$_FTPCONFIG['host'] = '{$_FTPCONFIG['host']}';// This is normally set to localhost \$_FTPCONFIG['port'] = {$_FTPCONFIG['port']}; // Ftp remote port \$_FTPCONFIG['username'] = '******'username']}'; // Ftp login username \$_FTPCONFIG['password'] = '******'password']}'; // Ftp login password \$_FTPCONFIG['path'] = '{$_FTPCONFIG['path']}'; // Ftp path to cms (must not include ascms_root_offset) /** * ------------------------------------------------------------------------- * Base setup (altering might break the system!) * ------------------------------------------------------------------------- */ // Set character encoding \$_CONFIG['coreCharacterEncoding'] = 'UTF-8'; // example 'UTF-8' CONFIG_TPL; // write settings try { $objFile = new \Cx\Lib\FileSystem\File(ASCMS_DOCUMENT_ROOT . '/config/configuration.php'); $objFile->makeWritable(); $objFile->write($configurationTpl); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); setUpdateMsg(sprintf($_ARRAYLANG['TXT_UNABLE_WRITE_SETTINGS_FILE'], ASCMS_DOCUMENT_ROOT . '/config/configuration.php')); setUpdateMsg(sprintf($_ARRAYLANG['TXT_SET_WRITE_PERMISSON_TO_FILE'], ASCMS_DOCUMENT_ROOT . '/config/configuration.php', $_CORELANG['TXT_UPDATE_TRY_AGAIN']), 'msg'); return false; } return true; }
/** * Create an Image * @param string $strPathOld: The old path of the image * @param string $strPathNew: The new path for the created image * @param string $strFileOld: The name of the old file * @param string $strFileNew: The name of the new file * @param integer $intNewWidth: Width of the new image * @param integer $intNewHeight: Height of the new image * @param integer $intQuality: Quality of the new image */ function createImages_JPG_GIF_PNG($strPathOld, $strPathNew, $strFileOld, $strFileNew, $intNewWidth, $intNewHeight, $intQuality) { global $_ARRAYLANG; //TODO: sometimes, strings are passed... this is a workaround $intNewWidth = intval($intNewWidth); $intNewHeight = intval($intNewHeight); //copy image $intSize = getimagesize($strPathOld . $strFileOld); //ermittelt die Gr��e des Bildes $intWidth = $intSize[0]; //die Breite des Bildes $intHeight = $intSize[1]; //die H�he des Bildes $strType = $intSize[2]; //type des Bildes if (file_exists($strPathNew . $strFileNew)) { \Cx\Lib\FileSystem\FileSystem::makeWritable($strPathNew . $strFileNew); } else { try { $objFile = new \Cx\Lib\FileSystem\File($strPathNew . $strFileNew); $objFile->touch(); $objFile->makeWritable(); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } } // TODO: Unfortunately, the functions imagegif(), imagejpeg() and imagepng() can't use the Cloudrexx FileSystem wrapper, // therefore we need to set the global write access image files. // This issue might be solved by using the output-buffer and write the image manually afterwards. // // IMPORTANT: In case something went wrong (see bug #1441) and the path $strPathNew.$strFileNew refers to a directory // we must abort the operation here, otherwise we would remove the execution flag on a directory, which would // cause to remove any browsing access to the directory. if (is_dir($strPathNew . $strFileNew)) { return false; } \Cx\Lib\FileSystem\FileSystem::chmod($strPathNew . $strFileNew, 0666); //\Cx\Lib\FileSystem\FileSystem::CHMOD_FILE); //fix cases of zeroes if ($intNewWidth == 0) { if ($intNewHeight == 0) { $intNewHeight = $this->arrSettings['standard_height_abs']; } if ($intNewHeight == 0) { //set a standard value if the settings default to 0 $intNewHeight = 100; } $intNewWidth = round($intWidth * $intNewHeight / $intHeight, 0); } else { if ($intNewHeight == 0) { $intNewHeight = round($intHeight * $intNewWidth / $intWidth, 0); } } $objSystem = new \FWSystem(); if ($objSystem === false) { return false; } if (is_array($intSize)) { $memoryLimit = $objSystem->getBytesOfLiteralSizeFormat(@ini_get('memory_limit')); // a $memoryLimit of zero means that there is no limit. so let's try it and hope that the host system has enough memory if (!empty($memoryLimit)) { $potentialRequiredMemory = $intSize[0] * $intSize[1] * ($intSize['bits'] / 8) * $intSize['channels'] * 1.8 * 2; if (function_exists('memory_get_usage')) { $potentialRequiredMemory += memory_get_usage(); } else { // add a default of 10 MBytes $potentialRequiredMemory += 10 * pow(1024, 2); } if ($potentialRequiredMemory > $memoryLimit) { // try to set a higher memory_limit @ini_set('memory_limit', $potentialRequiredMemory); $curr_limit = $objSystem->getBytesOfLiteralSizeFormat(@ini_get('memory_limit')); if ($curr_limit < $potentialRequiredMemory) { return false; } } } } else { return false; } switch ($strType) { case 1: //GIF if ($this->boolGifEnabled) { $handleImage1 = ImageCreateFromGif($strPathOld . $strFileOld); $handleImage2 = @ImageCreateTrueColor($intNewWidth, $intNewHeight); ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight); ImageGif($handleImage2, $strPathNew . $strFileNew); ImageDestroy($handleImage1); ImageDestroy($handleImage2); } else { $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_GIF_SUPPORT']; } break; case 2: //JPG if ($this->boolJpgEnabled) { $handleImage1 = ImageCreateFromJpeg($strPathOld . $strFileOld); $handleImage2 = ImageCreateTrueColor($intNewWidth, $intNewHeight); ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight); ImageJpeg($handleImage2, $strPathNew . $strFileNew, $intQuality); ImageDestroy($handleImage1); ImageDestroy($handleImage2); } else { $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_JPG_SUPPORT']; } break; case 3: //PNG if ($this->boolPngEnabled) { $handleImage1 = ImageCreateFromPNG($strPathOld . $strFileOld); $handleImage2 = @ImageCreateTrueColor($intNewWidth, $intNewHeight); ImageAlphaBlending($handleImage2, false); ImageSaveAlpha($handleImage2, true); ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight); ImagePNG($handleImage2, $strPathNew . $strFileNew); ImageDestroy($handleImage1); ImageDestroy($handleImage2); } else { $this->strErrMessage = $_ARRAYLANG['TXT_GALLERY_NO_PNG_SUPPORT']; } break; } return true; }