/** * Method to set client login credentials * * @param string $client Client name, currently only 'ftp' is supported * @param string $user Username * @param string $pass Password * * @return boolean True if the given login credentials have been set and are valid * * @since 11.1 */ public static function setCredentials($client, $user, $pass) { $return = false; $client = strtolower($client); // Test if the given credentials are valid switch ($client) { case 'ftp': $config = JFactory::getConfig(); $options = array('enabled' => $config->get('ftp_enable'), 'host' => $config->get('ftp_host'), 'port' => $config->get('ftp_port')); if ($options['enabled']) { jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($options['host'], $options['port']); // Test the conection and try to log in if ($ftp->isConnected()) { if ($ftp->login($user, $pass)) { $return = true; } $ftp->quit(); } } break; default: break; } if ($return) { // Save valid credentials to the session $session = JFactory::getSession(); $session->set($client . '.user', $user, 'JClientHelper'); $session->set($client . '.pass', $pass, 'JClientHelper'); // Force re-creation of the data saved within JClientHelper::getCredentials() JClientHelper::getCredentials($client, true); } return $return; }
function dgChmod($dir, $mode = 0755) { static $ftpOptions; if (!isset($ftpOptions)) { jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); } if ($ftpOptions['enabled'] == 1) { jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], null, $ftpOptions['user'], $ftpOptions['pass']); $dir = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $dir), '/'); return $ftp->chmod($dir, $mode); } else { return true; } }
public static function getSourceFtp() { $params = JComponentHelper::getParams('com_vmmigrate'); $ftp_active = $params->get('ftp_enable', 0); $ftp_host = $params->get('ftp_host', ''); $ftp_port = $params->get('ftp_port', ''); $ftp_user = $params->get('ftp_user', ''); $ftp_pass = $params->get('ftp_pass', ''); $ftp_root = $params->get('ftp_root', ''); $ftp_root = rtrim($ftp_root, "/"); $ftp_root = '/' . ltrim($ftp_root, "/"); jimport('joomla.client.ftp'); $source_ftp = JFTP::getInstance($ftp_host, $ftp_port, array(), $ftp_user, $ftp_pass); //$source_ftp->chdir($ftp_root); return $source_ftp; }
/** * @return JFTP handle */ function &getFtpHandle() { static $ftp = null; if (is_null($ftp)) { // Initialize variables jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); } else { $ftp = false; } } return $ftp; }
/** * @package AdminTools * * @copyright Copyright (c)2010-2011 Nicholas K. Dionysopoulos * @license GNU General Public License version 3, or later * * @param string $file * @param string $buffer * * @return boolean */ static function _write($file, $buffer) { // Initialize variables jimport('joomla.client.helper'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.path'); $FTPOptions = JClientHelper::getCredentials('ftp'); // If the destination directory doesn't exist we need to create it if (!file_exists(dirname($file))) { JFolder::create(dirname($file)); } if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); if (version_compare(JVERSION, '3.0', 'ge')) { $ftp = JClientFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], NULL, $FTPOptions['user'], $FTPOptions['pass']); } else { $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], NULL, $FTPOptions['user'], $FTPOptions['pass']); } // Translate path for the FTP account and use FTP write buffer to // file $file = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $file), '/'); $ret = $ftp->write($file, $buffer); } else { if (!is_writable($file)) { chmod($file, 0755); } if (!is_writable($file)) { chmod($file, 0777); } $ret = @file_put_contents($file, $buffer); chmod($file, 0644); } if (!$ret) { jimport('joomla.filesystem.file'); JFile::write($file, $buffer); } return $ret; }
function _createConfiguration($options) { // Create a new registry to build the configuration options. $registry = new JRegistry(); /* Site Settings */ $registry->set('offline', 0); $registry->set('offline_message', 'This page is temporarily unavailable'); $registry->set('display_offline_message', 1); $registry->set('offline_image', ''); $registry->set('sitename', 'PlayJoomServer'); $registry->set('editor', 'tinymce'); $registry->set('captcha', '0'); $registry->set('list_limit', 20); $registry->set('access', 1); /* Debug Settings */ $registry->set('debug', 0); $registry->set('debug_lang', 0); /* Database Settings */ $registry->set('dbtype', $options->db_type); $registry->set('host', $options->db_host); $registry->set('user', $options->db_user); $registry->set('password', $options->db_pass); $registry->set('db', $options->db_name); $registry->set('dbprefix', $options->db_prefix); /* Server Settings */ $registry->set('live_site', ''); $registry->set('secret', JUserHelper::genRandomPassword(16)); $registry->set('gzip', 0); $registry->set('error_reporting', 'none'); $registry->set('helpurl', 'http://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}'); $registry->set('ftp_host', $options->ftp_host); $registry->set('ftp_port', $options->ftp_port); $registry->set('ftp_user', $options->ftp_save ? $options->ftp_user : ''); $registry->set('ftp_pass', $options->ftp_save ? $options->ftp_pass : ''); $registry->set('ftp_root', $options->ftp_save ? $options->ftp_root : ''); $registry->set('ftp_enable', $options->ftp_enable); /* Locale Settings */ $registry->set('offset', 'UTC'); $registry->set('offset_user', 'UTC'); /* Mail Settings */ $registry->set('mailer', 'mail'); $registry->set('mailfrom', $options->admin_email); $registry->set('fromname', 'PlayJoomServer'); $registry->set('sendmail', '/usr/sbin/sendmail'); $registry->set('smtpauth', 0); $registry->set('smtpuser', ''); $registry->set('smtppass', ''); $registry->set('smtphost', 'localhost'); $registry->set('smtpsecure', 'none'); $registry->set('smtpport', '25'); /* Cache Settings */ $registry->set('caching', 0); $registry->set('cache_handler', 'file'); $registry->set('cachetime', 15); /* Meta Settings */ $registry->set('MetaDesc', ''); $registry->set('MetaKeys', ''); $registry->set('MetaTitle', 1); $registry->set('MetaAuthor', 1); $registry->set('MetaVersion', 0); $registry->set('robots', ''); /* SEO Settings */ $registry->set('sef', 0); $registry->set('sef_rewrite', 0); $registry->set('sef_suffix', 0); $registry->set('unicodeslugs', 0); /* Feed Settings */ $registry->set('feed_limit', 10); $registry->set('log_path', JPATH_ROOT . '/logs'); $registry->set('tmp_path', JPATH_ROOT . '/tmp'); /* Session Setting */ $registry->set('lifetime', 15); $registry->set('session_handler', 'database'); // Generate the configuration class string buffer. $buffer = $registry->toString('PHP', array('class' => 'JConfig', 'closingtag' => false)); // Build the configuration file path. $path = JPATH_CONFIGURATION . '/configuration.php'; // Determine if the configuration file path is writable. if (file_exists($path)) { $canWrite = is_writable($path); } else { $canWrite = is_writable(JPATH_CONFIGURATION . '/'); } /* * If the file exists but isn't writable OR if the file doesn't exist and the parent directory * is not writable we need to use FTP */ $useFTP = false; if (file_exists($path) && !is_writable($path) || !file_exists($path) && !is_writable(dirname($path) . '/')) { $useFTP = true; } // Check for safe mode if (ini_get('safe_mode')) { $useFTP = true; } // Enable/Disable override if (!isset($options->ftpEnable) || $options->ftpEnable != 1) { $useFTP = false; } if ($useFTP == true) { // Connect the FTP client jimport('joomla.client.ftp'); jimport('joomla.filesystem.path'); $ftp = JFTP::getInstance($options->ftp_host, $options->ftp_port); $ftp->login($options->ftp_user, $options->ftp_pass); // Translate path for the FTP account $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/'); // Use FTP write buffer to file if (!$ftp->write($file, $buffer)) { // Set the config string to the session. $session = JFactory::getSession(); $session->set('setup.config', $buffer); } $ftp->quit(); } else { if ($canWrite) { file_put_contents($path, $buffer); $session = JFactory::getSession(); $session->set('setup.config', null); } else { // Set the config string to the session. $session = JFactory::getSession(); $session->set('setup.config', $buffer); } } return true; }
/** * Finalize export output * * @copyright * @author RolandD * @todo * @see * @access private * @param * @return void * @since 3.0 */ private function _outputEnd() { $jinput = JFactory::getApplication()->input; $csvilog = $jinput->get('csvilog', null, null); $template = $jinput->get('template', null, null); $exportfilename = $jinput->get('export.filename', null, 'string'); jimport('joomla.filesystem.file'); switch ($template->get('exportto', 'general')) { case 'todownload': break; case 'tofile': $csvilog->AddStats('information', JText::sprintf('COM_CSVI_EXPORTFILE_CREATED', $exportfilename)); fclose($jinput->get('handle', null, null)); break; case 'toftp': // Close the file handle fclose($jinput->get('handle', null, null)); // Start the FTP jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($template->get('ftphost', 'general', '', 'string'), $template->get('ftpport', 'general'), null, $template->get('ftpusername', 'general', '', 'string'), $template->get('ftppass', 'general', '', 'string')); $ftp->chdir($template->get('ftproot', 'general', '/', 'string')); $ftp->store($exportfilename); $ftp->quit(); // Remove the temporary file JFile::delete($exportfilename); $csvilog->AddStats('information', JText::sprintf('COM_CSVI_EXPORTFILE_CREATED', $exportfilename)); break; case 'toemail': fclose($jinput->get('handle', null, null)); $this->_getMailer(); // Add the email address $addresses = explode(',', $template->get('export_email_addresses', 'email')); foreach ($addresses as $address) { if (!empty($address)) { $this->mailer->AddAddress($address); } } $addresses_cc = explode(',', $template->get('export_email_addresses_cc', 'email')); if (!empty($addresses_cc)) { foreach ($addresses_cc as $address) { if (!empty($address)) { $this->mailer->AddCC($address); } } } $addresses_bcc = explode(',', $template->get('export_email_addresses_bcc', 'email')); if (!empty($addresses_bcc)) { foreach ($addresses_bcc as $address) { if (!empty($address)) { $this->mailer->AddBCC($address); } } } // Mail submitter $htmlmsg = '<html><body>' . $this->_getRelToAbs($template->get('export_email_body', 'email')) . '</body></html>'; $this->mailer->setBody($htmlmsg); $this->mailer->setSubject($template->get('export_email_subject', 'email')); // Add the attachemnt $this->mailer->AddAttachment($exportfilename); // Send the mail $sendmail = $this->mailer->Send(); if (is_a($sendmail, 'JException')) { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_NO_MAIL_SEND', $sendmail->getMessage())); } else { $csvilog->AddStats('information', JText::_('COM_CSVI_MAIL_SEND')); } // Clear the mail details $this->mailer->ClearAddresses(); // Remove the temporary file JFile::delete($exportfilename); $csvilog->AddStats('information', JText::sprintf('COM_CSVI_EXPORTFILE_CREATED', $exportfilename)); break; } }
/** * Changes the permissions of a directory (or file) * either by the FTP-Layer if enabled * or by JPath::setPermissions (chmod()) * * not sure but probable: J! 1.6 will use * FTP-Layer automatically in setPermissions * so Joom_Chmod will become unnecessary * * @param string $dir directory * @param int or octal number $mode permissions which will be applied to $dir * @return boolean true on success, false otherwise */ function Joom_Chmod($dir, $mode = 0644) { static $ftpOptions; if (!isset($ftpOptions)) { // Initialize variables jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); } if ($ftpOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], null, $ftpOptions['user'], $ftpOptions['pass']); // Translate path to FTP path $dir = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $dir), '/'); return $ftp->chmod($dir, $mode); } else { return true; } }
function upload($src, $dest) { // Initialize variables jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); $ret = false; if (is_uploaded_file($src)) { if ($FTPOptions['enabled'] == 1 && self::exists($dest) && !CKunenaPath::isOwner($dest)) { @chmod($dest, 0777); } $ret = parent::upload($src, $dest); if ($FTPOptions['enabled'] == 1) { if ($ret === true) { jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); @unlink($src); $ret = true; } else { @chmod($src, 0644); } } } else { JError::raiseWarning(21, JText::_('WARNFS_ERR02')); } }
/** * Change the permissions of a file, optionally using FTP * * @param string $path Absolute path to file * @param int $mode Permissions, e.g. 0755 * * @return boolean True on success * * @since 2.5.4 */ private static function chmod($path, $mode) { if (is_string($mode)) { $mode = octdec($mode); if ($mode < 0600 || $mode > 0777) { $mode = 0755; } } // Initialize variables jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); // Check to make sure the path valid and clean $path = JPath::clean($path); if ($ftpOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], null, $ftpOptions['user'], $ftpOptions['pass']); } if (@chmod($path, $mode)) { $ret = true; } elseif ($ftpOptions['enabled'] == 1) { // Translate path and delete jimport('joomla.client.ftp'); $path = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $path), '/'); // FTP connector throws an error $ret = $ftp->chmod($path, $mode); } else { return false; } }
/** * Moves a folder. * * @param string $src The path to the source folder. * @param string $dest The path to the destination folder. * @param string $path An optional base path to prefix to the file names. * @param boolean $use_streams Optionally use streams. * * @return mixed Error message on false or boolean true on success. * * @since 11.1 */ public static function move($src, $dest, $path = '', $use_streams = false) { // Initialise variables. $FTPOptions = JClientHelper::getCredentials('ftp'); if ($path) { $src = JPath::clean($path . '/' . $src); $dest = JPath::clean($path . '/' . $dest); } if (!self::exists($src)) { return JText::_('JLIB_FILESYSTEM_ERROR_FIND_SOURCE_FOLDER'); } if (self::exists($dest)) { return JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_EXISTS'); } if ($use_streams) { $stream = JFactory::getStream(); if (!$stream->move($src, $dest)) { return JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_RENAME', $stream->getError()); } $ret = true; } else { if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); //Translate path for the FTP account $src = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $src), '/'); $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/'); // Use FTP rename to simulate move if (!$ftp->rename($src, $dest)) { return JText::_('Rename failed'); } $ret = true; } else { if (!@rename($src, $dest)) { return JText::_('Rename failed'); } $ret = true; } } return $ret; }
/** * Moves a folder. * * @param string The path to the source folder. * @param string The path to the destination folder. * @param string An optional base path to prefix to the file names. * @return mixed Error message on false or boolean true on success. * @since 1.5 */ function move($src, $dest, $path = '', $use_streams = false) { // Initialise variables. jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); if ($path) { $src = JPath::clean($path . DS . $src); $dest = JPath::clean($path . DS . $dest); } if (!JFolder::exists($src)) { return JText::_('Cannot find source folder'); } if (JFolder::exists($dest)) { return JText::_('Folder already exists'); } if ($use_streams) { $stream =& JFactory::getStream(); if (!$stream->move($src, $dest)) { return JText::_('Rename failed') . ': ' . $stream->getError(); //return JError::raiseError(-1, JText::_('Rename failed').': '. $stream->getError())); } $ret = true; } else { if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); //Translate path for the FTP account $src = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $src), '/'); $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/'); // Use FTP rename to simulate move if (!$ftp->rename($src, $dest)) { return JText::_('Rename failed'); } $ret = true; } else { if (!@rename($src, $dest)) { return JText::_('Rename failed'); } $ret = true; } } return $ret; }
static function resize($imgSrc, $imgDest, $dWidth, $dHeight, $crop = true, $quality = 100) { $info = getimagesize($imgSrc, $imageinfo); $sWidth = $info[0]; $sHeight = $info[1]; if ($sHeight / $sWidth > $dHeight / $dWidth) { $width = $sWidth; $height = round($dHeight * $sWidth / $dWidth); $sx = 0; $sy = round(($sHeight - $height) / 3); } else { $height = $sHeight; $width = round($sHeight * $dWidth / $dHeight); $sx = round(($sWidth - $width) / 2); $sy = 0; } if (!$crop) { $sx = 0; $sy = 0; $width = $sWidth; $height = $sHeight; } //echo "$sx:$sy:$width:$height";die(); $ext = str_replace('image/', '', $info['mime']); $imageCreateFunc = self::getImageCreateFunction($ext); $imageSaveFunc = self::getImageSaveFunction(JFile::getExt($imgDest)); $sImage = $imageCreateFunc($imgSrc); $dImage = imagecreatetruecolor($dWidth, $dHeight); // Make transparent if ($ext == 'png') { imagealphablending($dImage, false); imagesavealpha($dImage, true); $transparent = imagecolorallocatealpha($dImage, 255, 255, 255, 127); imagefilledrectangle($dImage, 0, 0, $dWidth, $dHeight, $transparent); } imagecopyresampled($dImage, $sImage, 0, 0, $sx, $sy, $dWidth, $dHeight, $width, $height); // Initialise variables. $FTPOptions = JClientHelper::getCredentials('ftp'); if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']); ob_start(); if ($ext == 'png') { $imageSaveFunc($dImage, null, 9); } else { if ($ext == 'gif') { $imageSaveFunc($dImage, null); } else { $imageSaveFunc($dImage, null, $quality); } } $buffer = ob_get_contents(); ob_end_clean(); // Translate path for the FTP account and use FTP write buffer to file $imgDest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $imgDest), '/'); $ret = $ftp->write($imgDest, $buffer); //$ftp->chmode($imgDest,0755); } else { if ($ext == 'png') { $imageSaveFunc($dImage, $imgDest, 9); } else { if ($ext == 'gif') { $imageSaveFunc($dImage, $imgDest); } else { $imageSaveFunc($dImage, $imgDest, $quality); } } } }
/** * Save the configuration information * * @return boolean True if successful * @access public * @since 1.5 */ function saveConfig() { global $mainframe; $vars =& $this->getVars(); $lang =& JFactory::getLanguage(); // Import authentication library jimport('joomla.user.helper'); // Set some needed variables $vars['siteUrl'] = JURI::root(); $vars['secret'] = JUserHelper::genRandomPassword(16); $vars['offline'] = JText::_('STDOFFLINEMSG'); $vars['errormsg'] = JText::_('STDERRORMSG'); $vars['metadesc'] = JText::_('STDMETADESC'); $vars['metakeys'] = JText::_('STDMETAKEYS'); $vars['tmp_path'] = JPATH_ROOT . DS . 'tmp'; $vars['log_path'] = JPATH_ROOT . DS . 'logs'; // set default language $forced = $mainframe->getLocalise(); if (empty($forced['lang'])) { $vars['deflang'] = 'en-GB'; $vars['bclang'] = 'english'; } else { $vars['deflang'] = $forced['lang']; $vars['bclang'] = $lang->getBackwardLang(); } if (empty($forced['helpurl'])) { $vars['helpurl'] = 'http://help.joomla.org'; } else { $vars['helpurl'] = $forced['helpurl']; } // If FTP has not been enabled, set the value to 0 if (!isset($vars['ftpEnable'])) { $vars['ftpEnable'] = 0; } /* * Trim the last slash from the FTP root, as the FTP root usually replaces JPATH_ROOT. * If the path had a trailing slash, this would lead to double slashes, like "/joomla//configuration.php" */ if (isset($vars['ftpRoot'])) { $vars['ftpRoot'] = rtrim($vars['ftpRoot'], '/'); } switch ($vars['DBtype']) { case 'mssql': $vars['ZERO_DATE'] = '1/01/1990'; break; default: $vars['ZERO_DATE'] = '0000-00-00 00:00:00'; break; } JInstallationHelper::createAdminUser($vars); /** * Write the configuration file */ jimport('joomla.template.template'); $tmpl = new JTemplate(); $tmpl->applyInputFilter('ShortModifiers'); // load the wrapper and common templates $tmpl->setRoot(JPATH_BASE . DS . 'template' . DS . 'tmpl'); $tmpl->readTemplatesFromFile('configuration.html'); $tmpl->addVars('configuration', $vars, 'var_'); if (empty($vars['ftpSavePass'])) { $tmpl->addVar('configuration', 'var_ftpuser', ''); $tmpl->addVar('configuration', 'var_ftppassword', ''); } $buffer = $tmpl->getParsedTemplate('configuration'); $path = JPATH_CONFIGURATION . DS . 'configuration.php'; if (file_exists($path)) { $canWrite = is_writable($path); } else { $canWrite = is_writable(JPATH_CONFIGURATION . DS); } /* * If the file exists but isn't writable OR if the file doesn't exist and the parent directory * is not writable we need to use FTP */ $ftpFlag = false; if (file_exists($path) && !is_writable($path) || !file_exists($path) && !is_writable(dirname($path) . '/')) { $ftpFlag = true; } // Check for safe mode if (ini_get('safe_mode')) { $ftpFlag = true; } // Enable/Disable override if (!isset($vars['ftpEnable']) || $vars['ftpEnable'] != 1) { $ftpFlag = false; } if ($ftpFlag == true) { // Connect the FTP client jimport('joomla.client.ftp'); jimport('joomla.filesystem.path'); $ftp =& JFTP::getInstance($vars['ftpHost'], $vars['ftpPort']); $ftp->login($vars['ftpUser'], $vars['ftpPassword']); // Translate path for the FTP account $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $vars['ftpRoot'], $path), '/'); // Use FTP write buffer to file if (!$ftp->write($file, $buffer)) { $this->setData('buffer', $buffer); return false; } $ftp->quit(); } else { if ($canWrite) { file_put_contents($path, $buffer); } else { $this->setData('buffer', $buffer); return true; } } return true; }
if (is_callable("jimport")) { global $CB_AdminFileFunctions; /** @noinspection PhpUnusedParameterInspection */ $CB_AdminFileFunctions = array('_constructor' => function (&$functions) { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); jimport('joomla.filesystem.path'); }, 'mkdir' => array('JFolder', 'create'), 'rmdir' => array('JFolder', 'delete'), 'is_dir' => null, 'opendir' => null, 'readdir' => null, 'closedir' => null, 'rename' => function ($old_name, $new_name) { if (is_file($old_name)) { return JFile::move($old_name, $new_name); } elseif (is_dir($old_name)) { return JFolder::move($old_name, $new_name); } else { return false; } }, 'file_exists' => null, 'is_writable' => null, 'is_file' => null, 'chmod' => function ($pathname, $mode) { jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); if ($FTPOptions['enabled'] == 1) { jimport('joomla.client.ftp'); // JFTPClient is Joomla 3.x-only, not in 2.5. $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], array(), $FTPOptions['user'], $FTPOptions['pass']); //Translate path to FTP account: $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $pathname), '/'); return $ftp->chmod($dest, $mode); } else { return @chmod($pathname, $mode); } }, 'chmoddir' => null, 'copy' => array('JFile', 'copy'), 'copydir' => array('JFolder', 'copy'), 'unlink' => array('JFile', 'delete'), 'file_put_contents' => array('JFile', 'write'), 'move_uploaded_file' => array('JFile', 'upload')); }
private function deletePath($path) { // Initialize variables JLoader::import('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); // Check to make sure the path valid and clean $n_path = @realpath($path); $path = empty($n_path) ? $path : $n_path; if ($ftpOptions['enabled'] == 1) { // Connect the FTP client if (version_compare(JVERSION, '3.0', 'ge')) { $ftp = JClientFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], array(), $ftpOptions['user'], $ftpOptions['pass']); } else { $ftp = JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], array(), $ftpOptions['user'], $ftpOptions['pass']); } } if (@unlink($path)) { $ret = true; } elseif (@rmdir($path)) { $ret = true; } elseif ($ftpOptions['enabled'] == 1) { if (substr($path, 0, strlen(JPATH_ROOT)) !== JPATH_ROOT) { return false; } // Translate path and delete $path = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $path), '/'); // FTP connector throws an error $ret = $ftp->delete($path); } else { return false; } return $ret; }
/** * Validate the file * * Validate the file is of the supported type * Types supported are csv, txt, xls, ods, xml * * @copyright * @author RolandD * @todo See if this code can be optimized * @see * @access public * @param * @return bool true if all OK | false if not OK * @since 3.0 */ public function validateFile() { $jinput = JFactory::getApplication()->input; $csvilog = $jinput->get('csvilog', null, null); $template = $jinput->get('template', null, null); // Workaround as it is always true //if ($jinput->get('filepos', 0, 'int') >= 0) { // $csv_file = $template->get('local_csv_file', 'general', false); // if (!$csv_file) { // $csv_file = urldecode($jinput->get('csv_file')); // $jinput->set('local_csv_file', $csv_file); // } // $this->folder = dirname($csv_file); // $jinput->set('csv_file', $csv_file); //} $loadfrom = $template->get('source', 'general'); switch (strtolower($loadfrom)) { // Uploaded file case 'fromupload': $upload['name'] = $_FILES['jform']['name']['general']['import_file']; $upload['type'] = $_FILES['jform']['type']['general']['import_file']; $upload['tmp_name'] = $_FILES['jform']['tmp_name']['general']['import_file']; $upload['error'] = $_FILES['jform']['error']['general']['import_file']; // Check if the file upload has an error if (empty($upload)) { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_UPLOADED_FILE_PROVIDED')); return false; } else { if ($upload['error'] == 0) { if (is_uploaded_file($upload['tmp_name'])) { // Get some basic info $folder = $this->_unpackpath . '/' . time(); $upload_parts = pathinfo($upload['name']); // Create the temp folder if (JFolder::create($folder)) { $this->folder = $folder; // Move the uploaded file to its temp location if (JFile::upload($upload['tmp_name'], $folder . '/' . $upload['name'])) { $this->_uploaded = true; // Let's see if the uploaded file is an archive if (in_array($upload_parts['extension'], $this->archives)) { // It is an archive, unpack first if (JArchive::extract($folder . '/' . $upload['name'], $folder)) { // File is unpacked, let's get the filename $foundfiles = scandir($folder); foreach ($foundfiles as $ffkey => $filename) { $ff_parts = pathinfo($filename); if (in_array(strtolower($ff_parts['extension']), $this->suffixes)) { $jinput->set('csv_file', $folder . '/' . $filename); $jinput->set('upload_file_error', false); $this->extension = strtolower($ff_parts["extension"]); end($foundfiles); } else { $found = false; } } if (!$found) { $jinput->set('upload_file_error', true); } } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_UNPACK_UPLOADED_FILE')); return false; } } else { $jinput->set('csv_file', $folder . '/' . $upload['name']); $this->extension = strtolower($upload_parts['extension']); } } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_UNPACK_FOLDER', $folder)); return false; } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_NO_UPLOADED_FILE_PROVIDED', $upload['tmp_name'])); return false; } } else { // There was a problem uploading the file switch ($upload['error']) { case '1': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THE_UPLOADED_FILE_EXCEEDS_THE_MAXIMUM_UPLOADED_FILE_SIZE')); break; case '2': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THE_UPLOADED_FILE_EXCEEDS_THE_MAXIMUM_UPLOADED_FILE_SIZE')); break; case '3': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THE_UPLOADED_FILE_WAS_ONLY_PARTIALLY_UPLOADED')); break; case '4': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILE_WAS_UPLOADED')); break; case '6': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_MISSING_A_TEMPORARY_FOLDER')); break; case '7': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_FAILED_TO_WRITE_FILE_TO_DISK')); break; case '8': $csvilog->AddStats('incorrect', JText::_('COM_CSVI_FILE_UPLOAD_STOPPED_BY_EXTENSION')); break; default: $csvilog->AddStats('incorrect', JText::_('COM_CSVI_THERE_WAS_A_PROBLEM_UPLOADING_THE_FILE')); break; } return false; } } break; // Local file // Local file case 'fromserver': $csv_file = JPath::clean($template->get('local_csv_file', 'general'), '/'); // Set the file name to use $jinput->set('csv_file', $csv_file); if (!JFile::exists($csv_file)) { $csvilog->addDebug('[VALIDATEFILE] ' . JText::sprintf('COM_CSVI_LOCAL_FILE_DOESNT_EXIST', $csv_file)); $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_LOCAL_FILE_DOESNT_EXIST', $csv_file)); return false; } else { $jinput->set('upload_file_error', false); } $fileinfo = pathinfo($csv_file); if (isset($fileinfo["extension"])) { $this->extension = strtolower($fileinfo["extension"]); if ($this->extension == 'txt') { $this->extension = 'csv'; } } break; case 'fromurl': // The temporary folder $folder = $this->_unpackpath . '/' . time(); $urlfile = $template->get('urlfile', 'general', false); $tempfile = basename($urlfile); // Check if the remote file exists if ($urlfile) { if (CsviHelper::fileExistsRemote($urlfile)) { // Copy the remote file to a local location if (JFolder::create($folder)) { if (touch($folder . '/' . $tempfile)) { if (JFile::write($folder . '/' . $tempfile, JFile::read($urlfile))) { $csvilog->addDebug(JText::sprintf('COM_CSVI_RETRIEVE_FROM_URL', $urlfile)); $jinput->set('csv_file', $folder . '/' . $tempfile); $jinput->set('upload_file_error', false); $this->extension = JFile::getExt($tempfile); } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_READ_FROM_URL')); return false; } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FILE', $folder . '/' . $tempfile)); return false; } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FOLDER', $folder)); return false; } } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_READ_FROM_URL')); return false; } } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILENAME_GIVEN')); return false; } break; case 'fromftp': // The temporary folder $folder = $this->_unpackpath . '/' . time(); $ftpfile = $template->get('ftpfile', 'general', false); if ($ftpfile) { // Create the output file if (JFolder::create($folder)) { if (touch($folder . '/' . $ftpfile)) { // Start the FTP jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($template->get('ftphost', 'general'), $template->get('ftpport', 'general'), null, $template->get('ftpusername', 'general'), $template->get('ftppass', 'general')); if ($ftp->get($folder . '/' . $ftpfile, $template->get('ftproot', 'general', '/') . $ftpfile)) { $csvilog->addDebug(JText::sprintf('COM_CSVI_RETRIEVE_FROM_FTP', $template->get('ftproot', 'general', '/') . $ftpfile)); $jinput->set('csv_file', $folder . '/' . $ftpfile); $jinput->set('upload_file_error', false); $this->extension = JFile::getExt($ftpfile); } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_CANNOT_READ_FROM_FTP')); return false; } $ftp->quit(); } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FILE', $folder . '/' . $ftpfile)); return false; } } else { $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_CANNOT_CREATE_TEMP_FOLDER', $folder)); return false; } } else { $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILENAME_GIVEN')); return false; } break; // No file given // No file given default: $csvilog->AddStats('incorrect', JText::_('COM_CSVI_NO_FILE_PROVIDED')); return false; break; } // Make sure txt files are not ignored if ($this->extension == 'txt') { $this->extension = 'csv'; } // Set the filename $csv_file = $jinput->get('csv_file', '', 'string'); if (JFile::exists($csv_file)) { $this->filename = JPath::clean($csv_file, '/'); // Store the users filename for display purposes $csvilog->setFilename(basename($this->filename)); } else { $csvilog->addDebug(JText::sprintf('COM_CSVI_LOCAL_FILE_DOESNT_EXIST', $jinput->get('csv_file'))); return false; } if (in_array($this->extension, $this->suffixes)) { $this->valid_extension = true; } else { // Test the mime type if (!in_array($this->extension, $this->mimetypes)) { $csvilog->AddStats('information', JText::sprintf('COM_CSVI_EXTENSION_NOT_ACCEPTED', $this->extension)); return false; } } // Debug message to know what filetype the user is uploading $csvilog->addDebug(JText::sprintf('COM_CSVI_IMPORT_FILETYPE', $this->extension)); // All is fine return true; }
/** * @return void * @since 1.6 */ public function removeFolder() { jimport('joomla.filesystem.folder'); // Check for a valid token. If invalid, send a 403 with the error message. JRequest::checkToken('request') or $this->sendResponse(new JException(JText::_('JINVALID_TOKEN'), 403)); // Get the posted config options. $vars = JRequest::getVar('jform', array()); $path = JPATH_INSTALLATION; //check whether the folder still exists if (!file_exists($path)) { $this->sendResponse(new JException(JText::sprintf('INSTL_COMPLETE_ERROR_FOLDER_ALREADY_REMOVED'), 500)); } // check whether we need to use FTP $useFTP = false; if ((file_exists($path) && !is_writable($path))) { $useFTP = true; } // Check for safe mode if (ini_get('safe_mode')) { $useFTP = true; } // Enable/Disable override if (!isset($options->ftpEnable) || ($options->ftpEnable != 1)) { $useFTP = false; } if ($useFTP == true) { // Connect the FTP client jimport('joomla.client.ftp'); jimport('joomla.filesystem.path'); $ftp = JFTP::getInstance($options->ftp_host, $options->ftp_port); $ftp->login($options->ftp_user, $options->ftp_pass); // Translate path for the FTP account $file = JPath::clean(str_replace(JPATH_CONFIGURATION, $options->ftp_root, $path), '/'); $return = $ftp->delete($file); // Delete the extra XML file while we're at it if ($return) { $file = JPath::clean($options->ftp_root.'/joomla.xml'); if (file_exists($file)) { $return = $ftp->delete($file); } } $ftp->quit(); } else { // Try to delete the folder. // We use output buffering so that any error message echoed JFolder::delete // doesn't land in our JSON output. ob_start(); $return = JFolder::delete($path) && (!file_exists(JPATH_ROOT.'/joomla.xml') || JFile::delete(JPATH_ROOT.'/joomla.xml')); ob_end_clean(); } // If an error was encountered return an error. if (!$return) { $this->sendResponse(new JException(JText::_('INSTL_COMPLETE_ERROR_FOLDER_DELETE'), 500)); } // Create a response body. $r = new JObject(); $r->text = JText::_('INSTL_COMPLETE_FOLDER_REMOVED'); // Send the response. $this->sendResponse($r); }
function copy($src, $dest, $path = null) { jimport('joomla.client.helper'); // Basispfad if ($path) { $src = JPath::clean($path . DS . $src); $dest = JPath::clean($path . DS . $dest); } // Quellpfad testen if (!is_readable($src)) { JError::raiseWarning(21, 'JFile::copy: ' . JText::_('DB_CANNOTFIND') . ": '{$src}'"); return false; } if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); // ggf. Ordner erstellen if (!file_exists(dirname($dest))) { jimport('joomla.filesystem.folder'); JFolder::create(dirname($dest)); } //Translate the destination path for the FTP account $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/'); if (!$ftp->store($src, $dest)) { // ggf. FTP Fehler zeigen return false; } $ret = true; } else { if (!@copy($src, $dest)) { JError::raiseWarning(21, JText::_('DB_COPY')); return false; } $ret = true; } return $ret; }
/** * Changes the permissions of a directory (or file) * either by the FTP-Layer if enabled * or by JPath::setPermissions (chmod()). * * Not sure but probable: J! 1.6 will use * FTP-Layer automatically in setPermissions * so JoomFile::chmod will become unnecessary. * * @param string $path Directory or file for which the permissions will be changed * @param string $mode Permissions which will be applied to $path * @param boolean $is_dir True if the given path is a directory, false if it is a file * @return boolean True on success, false otherwise * @since 1.5.0 */ public static function chmod($path, $mode, $is_dir = false) { static $ftpOptions; if (!isset($ftpOptions)) { // Initialize variables jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); } if ($ftpOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], array(), $ftpOptions['user'], $ftpOptions['pass']); // Translate path to FTP path $path = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $path), '/'); return $ftp->chmod($path, $mode); } else { if ($is_dir) { return JPath::setPermissions(JPath::clean($path), null, $mode); } return JPath::setPermissions(JPath::clean($path), $mode, null); } }
/** * Moves a folder. * * @param string The path to the source folder. * @param string The path to the destination folder. * @param string An optional base path to prefix to the file names. * @return mixed Error message on false or boolean true on success. * @since 1.5 */ function move($src, $dest, $path = '') { // Initialize variables jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); if ($path) { $src = JPath::clean($path . DS . $src); $dest = JPath::clean($path . DS . $dest); } if (!JFolder::exists($src) && !is_writable($src)) { return JText::_('Cannot find source folder'); } if (JFolder::exists($dest)) { return JText::_('Folder already exists'); } if ($ftpOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], null, $ftpOptions['user'], $ftpOptions['pass']); //Translate path for the FTP account $src = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $src), '/'); $dest = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $dest), '/'); // Use FTP rename to simulate move if (!$ftp->rename($src, $dest)) { return JText::_('Rename failed'); } $ret = true; } else { if (!@rename($src, $dest)) { return JText::_('Rename failed'); } $ret = true; } return $ret; }
/** * Moves an uploaded file to a destination folder * * @param string $src The name of the php (temporary) uploaded file * @param string $dest The path (including filename) to move the uploaded file to * @return boolean True on success * @since 1.5 */ function upload($src, $dest) { // Initialize variables jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); $ret = false; // Ensure that the path is valid and clean $dest = JPath::clean($dest); // Create the destination directory if it does not exist $baseDir = dirname($dest); if (!file_exists($baseDir)) { jimport('joomla.filesystem.folder'); JFolder::create($baseDir); } if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); //Translate path for the FTP account $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/'); // Copy the file to the destination directory if ($ftp->store($src, $dest)) { $ftp->chmod($dest, 0777); $ret = true; } else { JError::raiseWarning(21, JText::_('WARNFS_ERR02')); } } else { if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors if (JPath::setPermissions($dest)) { $ret = true; } else { JError::raiseWarning(21, JText::_('WARNFS_ERR01')); } } else { JError::raiseWarning(21, JText::_('WARNFS_ERR02')); } } return $ret; }
/** * Create a folder */ function folder_create($path = '', $mode = 0755) { // Initialize variables jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); // Check to make sure the path valid and clean $path = JPath::clean($path); // Check if dir already exists if (JFolder::exists($path)) { return true; } // Check for safe mode if ($ftpOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], null, $ftpOptions['user'], $ftpOptions['pass']); // Translate path to FTP path $path = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $path), '/'); $ret = $ftp->mkdir($path); $ftp->chmod($path, $mode); } else { // We need to get and explode the open_basedir paths $obd = ini_get('open_basedir'); // If open_basedir is set we need to get the open_basedir that the path is in if ($obd != null) { if (JPATH_ISWIN) { $obdSeparator = ";"; } else { $obdSeparator = ":"; } // Create the array of open_basedir paths $obdArray = explode($obdSeparator, $obd); $inBaseDir = false; // Iterate through open_basedir paths looking for a match foreach ($obdArray as $test) { $test = JPath::clean($test); if (strpos($path, $test) === 0) { $inBaseDir = true; break; } } if ($inBaseDir == false) { // Return false for JFolder::create because the path to be created is not in open_basedir JError::raiseWarning('SOME_ERROR_CODE', 'JFolder::create: ' . JText::_('NNI_PATH_NOT_IN_OPEN_BASEDIR_PATHS')); return false; } } // First set umask $origmask = @umask(0); // Create the path if (!($ret = @mkdir($path, $mode))) { @umask($origmask); return false; } // Reset umask @umask($origmask); } return $ret; }
private function set_permissions($filename, $permissions) { jimport("joomla.client.helper"); $ftp_config = JClientHelper::getCredentials('ftp'); if ($ftp_config['enabled']) { jimport("joomla.client.ftp"); jimport("joomla.filesystem.path"); $jpath_root = JPATH_ROOT; $filename = JPath::clean(str_replace(JPATH_ROOT, $ftp_config['root'], $filename), '/'); $ftp = new JFTP($ftp_config); $result = intval($ftp->chmod($filename, $permissions)); } else { $result = intval(@chmod($filename, $permissions)); } $this->InstallLog->Write("setting permissions for [{$filename}]... [{$result}]"); return $result; }
function _chmod($path, $mode) { global $mainframe; $ret = false; // Initialize variables $ftpFlag = true; $ftpRoot = $mainframe->getCfg('ftp_root'); // Do NOT use ftp if it is not enabled if ($mainframe->getCfg('ftp_enable') != 1) { $ftpFlag = false; } if ($ftpFlag == true) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp =& JFTP::getInstance($mainframe->getCfg('ftp_host'), $mainframe->getCfg('ftp_port')); $ftp->login($mainframe->getCfg('ftp_user'), $mainframe->getCfg('ftp_pass')); //Translate the destination path for the FTP account $path = JPath::clean(str_replace(JPATH_SITE, $ftpRoot, $path), '/'); // do the ftp chmod if (!$ftp->chmod($path, $mode)) { // FTP connector throws an error return false; } $ftp->quit(); $ret = true; } else { $ret = @chmod($path, $mode); } return $ret; }
function _CBchmodJJ( $pathname, $mode ) { jimport( 'joomla.client.helper' ); $FTPOptions = JClientHelper::getCredentials( 'ftp' ); if ( $FTPOptions['enabled'] == 1 ) { jimport( 'joomla.client.ftp' ); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); //Translate path to FTP account: $dest = JPath::clean(str_replace( JPATH_ROOT, $FTPOptions['root'], $pathname), '/' ); return $ftp->chmod( $dest, $mode ); } else { return @chmod( $pathname, $mode ); } }
/** * Changes the permissions of a file or directory using direct file access or * Joomla!'s FTP layer, whichever works * @param $path string Absolute path to the file/dir to chmod * @param $mode The permissions mode to apply * @return bool True on success */ private function chmod($path, $mode) { if (is_string($mode)) { $mode = octdec($mode); } // Initialize variables JLoader::import('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); // Check to make sure the path valid and clean $path = JPath::clean($path); if ($ftpOptions['enabled'] == 1) { // Connect the FTP client JLoader::import('joomla.client.ftp'); if (version_compare(JVERSION, '3.0', 'ge')) { $ftp = JClientFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], array(), $ftpOptions['user'], $ftpOptions['pass']); } else { $ftp = JFTP::getInstance($ftpOptions['host'], $ftpOptions['port'], array(), $ftpOptions['user'], $ftpOptions['pass']); } } if (@chmod($path, $mode)) { $ret = true; } elseif ($ftpOptions['enabled'] == 1) { // Translate path and delete JLoader::import('joomla.client.ftp'); $path = JPath::clean(str_replace(JPATH_ROOT, $ftpOptions['root'], $path), '/'); // FTP connector throws an error $ret = $ftp->chmod($path, $mode); } else { return false; } }
/** * @since 2.5.4 */ public function createRestorationFile($basename = null) { // Get a password jimport('joomla.user.helper'); $password = JUserHelper::genRandomPassword(32); JFactory::getApplication()->setUserState('com_joomlaupdate.password', $password); // Do we have to use FTP? $method = JRequest::getCmd('method', 'direct'); // Get the absolute path to site's root $siteroot = JPATH_SITE; // If the package name is not specified, get it from the update info if (empty($basename)) { $updateInfo = $this->getUpdateInformation(); $packageURL = $updateInfo['object']->downloadurl->_data; $basename = basename($packageURL); } // Get the package name $tempdir = JFactory::getConfig()->getValue('config.tmp_path'); $file = $tempdir . '/' . $basename; $filesize = @filesize($file); JFactory::getApplication()->setUserState('com_joomlaupdate.password', $password); JFactory::getApplication()->setUserState('com_joomlaupdate.filesize', $filesize); $data = "<?php\ndefined('_AKEEBA_RESTORATION') or die('Restricted access');\n"; $data .= '$restoration_setup = array(' . "\n"; $data .= <<<ENDDATA \t'kickstart.security.password' => '{$password}', \t'kickstart.tuning.max_exec_time' => '5', \t'kickstart.tuning.run_time_bias' => '75', \t'kickstart.tuning.min_exec_time' => '0', \t'kickstart.procengine' => '{$method}', \t'kickstart.setup.sourcefile' => '{$file}', \t'kickstart.setup.destdir' => '{$siteroot}', \t'kickstart.setup.restoreperms' => '0', \t'kickstart.setup.filetype' => 'zip', \t'kickstart.setup.dryrun' => '0' ENDDATA; if ($method == 'ftp') { // Fetch the FTP parameters from the request. Note: The password should be // allowed as raw mode, otherwise something like !@<sdf34>43H% would be // sanitised to !@43H% which is just plain wrong. $ftp_host = JRequest::getVar('ftp_host', ''); $ftp_port = JRequest::getVar('ftp_port', '21'); $ftp_user = JRequest::getVar('ftp_user', ''); $ftp_pass = JRequest::getVar('ftp_pass', '', 'default', 'none', 2); $ftp_root = JRequest::getVar('ftp_root', ''); // Is the tempdir really writable? $writable = @is_writeable($tempdir); if ($writable) { // Let's be REALLY sure $fp = @fopen($tempdir . '/test.txt', 'w'); if ($fp === false) { $writable = false; } else { fclose($fp); unlink($tempdir . '/test.txt'); } } // If the tempdir is not writable, create a new writable subdirectory if (!$writable) { jimport('joomla.client.ftp'); jimport('joomla.client.helper'); jimport('joomla.filesystem.folder'); $FTPOptions = JClientHelper::getCredentials('ftp'); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $tempdir . '/admintools'), '/'); if (!@mkdir($tempdir . '/admintools')) { $ftp->mkdir($dest); } if (!@chmod($tempdir . '/admintools', 511)) { $ftp->chmod($dest, 511); } $tempdir .= '/admintools'; } // Just in case the temp-directory was off-root, try using the default tmp directory $writable = @is_writeable($tempdir); if (!$writable) { $tempdir = JPATH_ROOT . '/tmp'; // Does the JPATH_ROOT/tmp directory exist? if (!is_dir($tempdir)) { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); JFolder::create($tempdir, 511); JFile::write($tempdir . '/.htaccess', "order deny, allow\ndeny from all\nallow from none\n"); } // If it exists and it is unwritable, try creating a writable admintools subdirectory if (!is_writable($tempdir)) { jimport('joomla.client.ftp'); jimport('joomla.client.helper'); jimport('joomla.filesystem.folder'); $FTPOptions = JClientHelper::getCredentials('ftp'); $ftp =& JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $tempdir . '/admintools'), '/'); if (!@mkdir($tempdir . '/admintools')) { $ftp->mkdir($dest); } if (!@chmod($tempdir . '/admintools', 511)) { $ftp->chmod($dest, 511); } $tempdir .= '/admintools'; } } // If we still have no writable directory, we'll try /tmp and the system's temp-directory $writable = @is_writeable($tempdir); if (!$writable) { if (@is_dir('/tmp') && @is_writable('/tmp')) { $tempdir = '/tmp'; } else { // Try to find the system temp path $tmpfile = @tempnam("dummy", ""); $systemp = @dirname($tmpfile); @unlink($tmpfile); if (!empty($systemp)) { if (@is_dir($systemp) && @is_writable($systemp)) { $tempdir = $systemp; } } } } $data .= <<<ENDDATA \t, \t'kickstart.ftp.ssl' => '0', \t'kickstart.ftp.passive' => '1', \t'kickstart.ftp.host' => '{$ftp_host}', \t'kickstart.ftp.port' => '{$ftp_port}', \t'kickstart.ftp.user' => '{$ftp_user}', \t'kickstart.ftp.pass' => '{$ftp_pass}', \t'kickstart.ftp.dir' => '{$ftp_root}', \t'kickstart.ftp.tempdir' => '{$tempdir}' ENDDATA; } $data .= ');'; // Remove the old file, if it's there... jimport('joomla.filesystem.file'); $configpath = JPATH_COMPONENT_ADMINISTRATOR . '/restoration.php'; if (JFile::exists($configpath)) { JFile::delete($configpath); } // Write new file. First try with JFile. $result = JFile::write($configpath, $data); // In case JFile used FTP but direct access could help if (!$result) { if (function_exists('file_put_contents')) { $result = @file_put_contents($configpath, $data); if ($result !== false) { $result = true; } } else { $fp = @fopen($configpath, 'wt'); if ($fp !== false) { $result = @fwrite($fp, $data); if ($result !== false) { $result = true; } @fclose($fp); } } } return $result; }
/** * Moves an uploaded file to a destination folder * * @param string $src The name of the php (temporary) uploaded file * @param string $dest The path (including filename) to move the uploaded file to * * @return boolean True on success * @since 1.5 */ public static function upload($src, $dest, $use_streams = false) { // Ensure that the path is valid and clean $dest = JPath::clean($dest); // Create the destination directory if it does not exist $baseDir = dirname($dest); if (!file_exists($baseDir)) { jimport('joomla.filesystem.folder'); JFolder::create($baseDir); } if ($use_streams) { $stream = JFactory::getStream(); if (!$stream->upload($src, $dest)) { JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError())); return false; } return true; } else { // Initialise variables. jimport('joomla.client.helper'); $FTPOptions = JClientHelper::getCredentials('ftp'); $ret = false; if ($FTPOptions['enabled'] == 1) { // Connect the FTP client jimport('joomla.client.ftp'); $ftp = JFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); //Translate path for the FTP account $dest = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dest), '/'); // Copy the file to the destination directory if (is_uploaded_file($src) && $ftp->store($src, $dest)) { unlink($src); $ret = true; } else { JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02')); } } else { if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors if (JPath::setPermissions($dest)) { $ret = true; } else { JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR01')); } } else { JError::raiseWarning(21, JText::_('JLIB_FILESYSTEM_ERROR_WARNFS_ERR02')); } } return $ret; } }
function uddeIMmkdir($folder, $forcenoftp=false) { $options = array(); $ret = false; if (class_exists('JFactory')) { // Joomla 1.5? $config = JFactory::getConfig(); $options = array( 'enabled' => $config->getValue('config.ftp_enable'), 'host' => $config->getValue('config.ftp_host'), 'port' => $config->getValue('config.ftp_port'), 'user' => $config->getValue('config.ftp_user'), 'pass' => $config->getValue('config.ftp_pass'), 'root' => $config->getValue('config.ftp_root'), ); } if ($forcenoftp) $options['enabled'] = false; if ($options['enabled']) { jimport('joomla.client.ftp'); $configdatei = $options['root'].$folder; $ftp = JFTP::getInstance($options['host'], $options['port'], null, $options['user'], $options['pass']); //if ($ftp->isConnected()) { // if ($ftp->login($options['user'], $options['pass'])) { $ret = $ftp->mkdir($configdatei); // } // $ftp->quit(); //} } else { $configdatei = uddeIMgetPath('absolute_path').$folder; $ret = @mkdir($configdatei); } return $ret; }