Beispiel #1
0
 /**
  * TuiyoParameter::saveParams()
  * 
  * @param mixed $postParams
  * @param mixed $key
  * @param string $type
  * @return
  */
 public function saveParams($postParams, $key, $type = "system")
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.client.helper');
     // Set FTP credentials, if given
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     $file = TUIYO_CONFIG . DS . strtolower($key) . ".ini";
     if (JFile::exists($file)) {
         JFile::write($file);
     }
     if (count($postParams)) {
         $registry = new JRegistry();
         $registry->loadArray($postParams);
         $iniTxt = $registry->toString();
         // Try to make the params file writeable
         if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) {
             JError::raiseNotice('SOME_ERROR_CODE', _('Could not make the template parameter file writable'));
             return false;
         }
         //Write the file
         $return = JFile::write($file, $iniTxt);
         // Try to make the params file unwriteable
         if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) {
             JError::raiseNotice('SOME_ERROR_CODE', _('Could not make the template parameter file unwritable'));
             return false;
         }
         if (!$return) {
             JError::raiseError(TUIYO_SERVER_ERROR, _("Could not save the template parameters"));
             return false;
         }
         return $return;
     }
 }
function com_install()
{
    global $mainframe;
    jimport('joomla.filesystem.folder');
    // Initialize variables
    jimport('joomla.client.helper');
    $FTPOptions = JClientHelper::getCredentials('ftp');
    $language =& JFactory::getLanguage();
    $language->load('com_jce_imgmanager_ext', JPATH_SITE);
    $cache = $mainframe->getCfg('tmp_path');
    // Check for tmp folder
    if (!JFolder::exists($cache)) {
        // Create if does not exist
        if (!JFolder::create($cache)) {
            $mainframe->enqueueMessage(JText::_('NO CACHE DESC'), 'error');
        }
    }
    // Check if folder exists and is writable or the FTP layer is enabled
    if (JFolder::exists($cache) && (is_writable($cache) || $FTPOptions['enabled'] == 1)) {
        $mainframe->enqueueMessage(JText::_('CACHE DESC'));
    } else {
        $mainframe->enqueueMessage(JText::_('NO CACHE DESC'), 'error');
    }
    // Check for GD
    if (!function_exists('gd_info')) {
        $mainframe->enqueueMessage(JText::_('NO GD DESC'), 'error');
    } else {
        $info = gd_info();
        $mainframe->enqueueMessage(JText::_('GD DESC') . ' - ' . $info['GD Version']);
    }
}
Beispiel #3
0
/**
 * Disables the unsupported eAccelerator caching method, replacing it with the
 * "file" caching method.
 *
 * @return  void
 *
 * @since   3.2
 */
function admin_postinstall_eaccelerator_action()
{
    $prev = new JConfig();
    $prev = JArrayHelper::fromObject($prev);
    $data = array('cacheHandler' => 'file');
    $data = array_merge($prev, $data);
    $config = new Registry('config');
    $config->loadArray($data);
    jimport('joomla.filesystem.path');
    jimport('joomla.filesystem.file');
    // Set the configuration file path.
    $file = JPATH_CONFIGURATION . '/configuration.php';
    // Get the new FTP credentials.
    $ftp = JClientHelper::getCredentials('ftp', true);
    // Attempt to make the file writeable if using FTP.
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) {
        JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'));
    }
    // Attempt to write the configuration file as a PHP class named JConfig.
    $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
    if (!JFile::write($file, $configuration)) {
        JFactory::getApplication()->enqueueMessage(JText::_('COM_CONFIG_ERROR_WRITE_FAILED'), 'error');
        return;
    }
    // Attempt to make the file unwriteable if using FTP.
    if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) {
        JError::raiseNotice('SOME_ERROR_CODE', JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'));
    }
}
Beispiel #4
0
 function save($data)
 {
     // Get the previous configuration.
     if (is_object($data)) {
         $data = JArrayHelper::fromObject($data);
     }
     $prev = JTheFactoryHelper::getConfig();
     $prev = JArrayHelper::fromObject($prev);
     $data = array_merge($prev, $data);
     $configfile = JTheFactoryAdminHelper::getConfigFile();
     $config = new JRegistry('config');
     $config->loadArray($data);
     jimport('joomla.filesystem.path');
     jimport('joomla.filesystem.file');
     jimport('joomla.client.helper');
     // Get the new FTP credentials.
     $ftp = JClientHelper::getCredentials('ftp', true);
     // Attempt to make the file writeable if using FTP.
     if (!$ftp['enabled'] && JPath::isOwner($configfile) && !JPath::setPermissions($configfile, '0644')) {
         JError::raiseNotice(101, JText::_('FACTORY_SETTINGS_FILE_IS_NOT_WRITABLE'));
     }
     // Attempt to write the configuration file as a PHP class named JConfig.
     $configString = $config->toString('PHP', array('class' => ucfirst(APP_PREFIX) . "Config", 'closingtag' => false));
     if (!JFile::write($configfile, $configString)) {
         JError::raiseWarning(101, JText::_('FACTORY_SETTINGS_FILE_WRITE_FAILED'));
         return false;
     }
     // Attempt to make the file unwriteable if using FTP.
     if (!$ftp['enabled'] && JPath::isOwner($configfile) && !JPath::setPermissions($configfile, '0444')) {
         JError::raiseNotice(101, JText::_('FACTORY_SETTINGS_FILE_IS_NOT_WRITABLE'));
     }
     return true;
 }
Beispiel #5
0
function com_install()
{
    $mainframe = JFactory::getApplication();
    jimport('joomla.filesystem.folder');
    // Initialize variables
    jimport('joomla.client.helper');
    $FTPOptions = JClientHelper::getCredentials('ftp');
    $language = JFactory::getLanguage();
    $language->load('com_jce_imgmanager_ext', JPATH_SITE);
    $cache = $mainframe->getCfg('tmp_path');
    // Check for tmp folder
    if (!JFolder::exists($cache)) {
        // Create if does not exist
        if (!JFolder::create($cache)) {
            $mainframe->enqueueMessage(WFText::_('WF_IMGMANAGER_EXT_NO_CACHE_DESC'), 'error');
        }
    }
    // Check if folder exists and is writable or the FTP layer is enabled
    if (JFolder::exists($cache) && (is_writable($cache) || $FTPOptions['enabled'] == 1)) {
        $mainframe->enqueueMessage(WFText::_('WF_IMGMANAGER_EXT_CACHE_DESC'));
    } else {
        $mainframe->enqueueMessage(WFText::_('WF_IMGMANAGER_EXT_NO_CACHE_DESC'), 'error');
    }
    // Check for GD
    if (!function_exists('gd_info')) {
        $mainframe->enqueueMessage(WFText::_('WF_IMGMANAGER_EXT_NO_GD_DESC'), 'error');
    } else {
        $info = gd_info();
        $mainframe->enqueueMessage(WFText::_('WF_IMGMANAGER_EXT_GD_DESC') . ' - ' . $info['GD Version']);
    }
    // remove wideimage folder
    if (JFolder::exists(dirname(__FILE) . '/classes/wideimage')) {
        @JFolder::delete(dirname(__FILE) . '/classes/wideimage');
    }
}
Beispiel #6
0
 /**
  * Creates a new stream object with appropriate prefix
  * @param boolean Prefix the connections for writing
  * @param boolean Use network if available for writing; use false to disable (e.g. FTP, SCP)
  * @param string UA User agent to use
  * @param boolean User agent masking (prefix Mozilla)
  */
 function &getStream($use_prefix = true, $use_network = true, $ua = null, $uamask = false)
 {
     RokUpdater::import('joomla.filesystem.stream');
     RokUpdater::import('pasamio.pversion');
     jimport('joomla.client.helper');
     // Setup the context; Joomla! UA and overwrite
     $context = array();
     $version = new PVersion();
     // set the UA for HTTP and overwrite for FTP
     $context['http']['user_agent'] = $version->getUserAgent($ua, $uamask);
     $context['ftp']['overwrite'] = true;
     if ($use_prefix) {
         $FTPOptions = JClientHelper::getCredentials('ftp');
         $SCPOptions = JClientHelper::getCredentials('scp');
         if ($FTPOptions['enabled'] == 1 && $use_network) {
             $prefix = 'ftp://' . $FTPOptions['user'] . ':' . $FTPOptions['pass'] . '@' . $FTPOptions['host'];
             $prefix .= $FTPOptions['port'] ? ':' . $FTPOptions['port'] : '';
             $prefix .= $FTPOptions['root'];
         } else {
             if ($SCPOptions['enabled'] == 1 && $use_network) {
                 $prefix = 'ssh2.sftp://' . $SCPOptions['user'] . ':' . $SCPOptions['pass'] . '@' . $SCPOptions['host'];
                 $prefix .= $SCPOptions['port'] ? ':' . $SCPOptions['port'] : '';
                 $prefix .= $SCPOptions['root'];
             } else {
                 $prefix = JPATH_ROOT . DS;
             }
         }
         $retval = new JStream($prefix, JPATH_ROOT, $context);
     } else {
         $retval = new JStream('', '', $context);
     }
     return $retval;
 }
Beispiel #7
0
 /**
  * Loads the configuration from the Joomla! global configuration itself. The component's options are loaded into
  * the options key. For example, an option called foobar is accessible as $config->get('options.foobar');
  *
  * @param string  $filePath Ignored
  * @param Phpfunc $phpfunc  Ignored
  *
  * @return  void
  */
 public function loadConfiguration($filePath = null, Phpfunc $phpfunc = null)
 {
     // Get the Joomla! configuration object
     $jConfig = \JFactory::getConfig();
     // Create the basic configuration data
     $data = array('timezone' => $jConfig->get('offset', 'UTC'), 'fs' => array('driver' => 'file'), 'dateformat' => \JText::_('DATE_FORMAT_LC2'), 'base_url' => \JUri::base() . '/index.php?option=com_' . strtolower($this->container->application_name), 'live_site' => \JUri::base() . '/index.php?option=com_' . strtolower($this->container->application_name), 'cms_url' => \JUri::base(), 'options' => array());
     // Get the Joomla! FTP layer options
     if (!class_exists('JClientHelper')) {
         \JLoader::import('joomla.client.helper');
     }
     $ftpOptions = \JClientHelper::getCredentials('ftp');
     // If the FTP layer is enabled, enable the Hybrid filesystem engine
     if ($ftpOptions['enabled'] == 1) {
         $data['fs'] = array('driver' => 'hybrid', 'host' => $ftpOptions['host'], 'port' => empty($ftpOptions['port']) ? '21' : $ftpOptions['port'], 'directory' => rtrim($ftpOptions['root'], '/\\'), 'ssl' => false, 'passive' => true, 'username' => $ftpOptions['user'], 'password' => $ftpOptions['pass']);
     }
     // Populate the options key with the component configuration
     $db = $this->container->db;
     $sql = $db->getQuery(true)->select($db->qn('params'))->from($db->qn('#__extensions'))->where($db->qn('element') . " = " . $db->q('com_' . strtolower($this->container->application_name)));
     try {
         $configJson = $db->setQuery($sql)->loadResult();
     } catch (\Exception $e) {
         $configJson = null;
     }
     if (!empty($configJson)) {
         $data['options'] = json_decode($configJson, true);
     }
     // Finally, load the data to the registry class
     $this->data = new \stdClass();
     $this->loadArray($data);
 }
Beispiel #8
0
 function translatePath($file)
 {
     if (empty($file)) {
         return null;
     }
     jimport('joomla.client.ftp');
     // Initialize variables
     jimport('joomla.client.helper');
     $FTPOptions = JClientHelper::getCredentials('ftp');
     if (JD_Ftp::getFtpHandle()) {
         // Translate path for the FTP account and use FTP write buffer to file
         return JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $file), '/');
     }
     return $file;
 }
 function saveProfile()
 {
     global $mainframe;
     // Initialize some variables
     $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
     $json = JRequest::getVar('json', '', 'post', 'string', JREQUEST_ALLOWRAW);
     $post = json_decode($json);
     $profile = JRequest::getCmd('profile');
     $result = array();
     if (!$profile) {
         $result['error'] = JText::_('No Profile name contains space or special chracters.');
         echo json_encode($result);
         exit;
     }
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     $errors = array();
     $file = dirname(dirname(__FILE__)) . DS . 'profiles' . DS . $profile . '.ini';
     $params = new JParameter('');
     if (isset($post)) {
         foreach ($post as $k => $v) {
             $params->set($k, $v);
         }
     }
     $data = $params->toString();
     if (JFile::exists($file)) {
         @chmod($file, 0777);
     }
     $return = @JFile::write($file, $data);
     // Try to make the params file unwriteable
     if (!$ftp['enabled'] && @JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) {
         $errors[] = sprintf(JText::_('Profile file unwritable'), $file);
     }
     if (!$return) {
         $errors[] = JText::_('Operation Failed') . ': ' . JText::sprintf('Failed to open file for writing.', $file);
     }
     if ($errors) {
         $result['error'] = implode('<br/>', $errors);
     } else {
         $result['successful'] = sprintf(JText::_('SAVE PROFILE SUCCESSFULLY'), $profile);
         $result['profile'] = $profile;
         $result['type'] = 'new';
     }
     echo json_encode($result);
     exit;
 }
Beispiel #10
0
 function fetchElement($name, $value, &$node, $control_name)
 {
     global $mctrl;
     $mctrl =& MissionControl::getInstance();
     if ($mctrl->_getCurrentAdminTemplate() == "rt_missioncontrol_j15") {
         $ftp = JClientHelper::getCredentials('ftp');
         if ($ftp['enabled']) {
             $html = '<div class="mc-update-check"><b>* FTP mode currently not supported in Auto-Update</b><br />Please check the MissionControl forum for information on the latest version.</div>';
         } else {
             $html = MCUpdater::display(false);
         }
     } else {
         $html = '<b>* Feature only available within MissionControl</b>';
     }
     return $html;
 }
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 function setDatabaseType()
 {
     $path = JPATH_CONFIGURATION . '/configuration.php';
     $result = false;
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     $ftp = JClientHelper::getCredentials('ftp');
     jimport('joomla.filesystem.path');
     if ($ftp['enabled'] || JPath::isOwner($path) && JPath::setPermissions($path, '0644')) {
         $search = JFile::read($path);
         $replaced = str_replace('$dbtype = \'mysql\';', '$dbtype = \'mysqli\';', $search);
         $result = JFile::write($path, $replaced);
         if (!$ftp['enabled'] && JPath::isOwner($path)) {
             JPath::setPermissions($path, '0444');
         }
     }
     return $result;
 }
Beispiel #13
0
 function delete(&$id)
 {
     $element = $this->get(reset($id));
     if (!$element) {
         return false;
     }
     jimport('joomla.filesystem.file');
     if (!JFile::exists($element->override)) {
         return true;
     }
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     if (!$ftp['enabled'] && !JPath::setPermissions($element->override, '0755')) {
         JError::raiseNotice('SOME_ERROR_CODE', JText::sprintf('FILE_NOT_WRITABLE', $element->override));
     }
     $result = JFile::delete($element->override);
     return $result;
 }
Beispiel #14
0
 /**
  * Saves the css
  *
  */
 function savecss()
 {
     global $mainframe;
     JRequest::checkToken() or die('Invalid Token');
     // Initialize some variables
     $option = JRequest::getVar('option');
     $filename = JRequest::getVar('filename', '', 'post', 'cmd');
     $filecontent = JRequest::getVar('filecontent', '', '', '', JREQUEST_ALLOWRAW);
     if (!$filecontent) {
         $mainframe->redirect('index.php?option=' . $option, JText::_('OPERATION FAILED') . ': ' . JText::_('CONTENT EMPTY'));
     }
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     $file = JPATH_SITE . DS . 'components' . DS . 'com_eventlist' . DS . 'assets' . DS . 'css' . DS . $filename;
     // Try to make the css file writeable
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) {
         JError::raiseNotice('SOME_ERROR_CODE', 'COULD NOT MAKE CSS FILE WRITABLE');
     }
     jimport('joomla.filesystem.file');
     $return = JFile::write($file, $filecontent);
     // Try to make the css file unwriteable
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) {
         JError::raiseNotice('SOME_ERROR_CODE', 'COULD NOT MAKE CSS FILE UNWRITABLE');
     }
     if ($return) {
         $task = JRequest::getVar('task');
         switch ($task) {
             case 'applycss':
                 $mainframe->redirect('index.php?option=' . $option . '&view=editcss', JText::_('CSS FILE SUCCESSFULLY ALTERED'));
                 break;
             case 'savecss':
             default:
                 $mainframe->redirect('index.php?option=' . $option, JText::_('CSS FILE SUCCESSFULLY ALTERED'));
                 break;
         }
     } else {
         $mainframe->redirect('index.php?option=' . $option, JText::_('OPERATION FAILED') . ': ' . JText::sprintf('FAILED TO OPEN FILE FOR WRITING', $file));
     }
 }
Beispiel #15
0
 /**
  * Save Profile to module folder
  */
 public function saveProfile()
 {
     //This function only run in backend
     $app = JFactory::getApplication();
     if (!$app->isAdmin()) {
         return false;
     }
     //Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     //Do NOT filter, HTML can be saved in profile
     $data_json = JRequest::getVar('data_json', '', 'post', 'string', JREQUEST_ALLOWRAW);
     //Create profile folder if does not exist
     $moduleprofilefolder = JPATH_SITE . DS . 'modules' . DS . $this->modulename . DS . 'profiles';
     if (!is_dir($moduleprofilefolder)) {
         mkdir($moduleprofilefolder);
         //Create blank index.html file
         $fp = fopen($moduleprofilefolder . DS . 'index.html', 'w');
         fwrite($fp, '<!DOCTYPE html><title></title>');
         fclose($fp);
     }
     $file = self::getIniFileModule();
     if (JFile::exists($file)) {
         chmod($file, 0777);
     }
     $data = array();
     if (JFile::write($file, $data_json)) {
         $data['success'] = 1;
         $data['reports'] = JText::_('SAVE_PROFILE_SUCCESSFULLY');
     } else {
         $data['success'] = 0;
         $data['reports'] = JText::_('FILE_UNWRITEABLE');
     }
     // Try to make the params file unwriteable
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) {
         $data['success'] = 0;
         $data['reports'] = JText::_('FILE_UNWRITEABLE');
     }
     return $data;
 }
Beispiel #16
0
 /**
  * @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;
 }
Beispiel #17
0
 function save()
 {
     $app =& JFactory::getApplication();
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     $file = JPATH_RSGALLERY2_SITE . '/templates/' . $this->template . '/html/' . $this->filename;
     // Try to make the css file writeable
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0755')) {
         JError::raiseNotice('SOME_ERROR_CODE', 'Could not make the html file writable');
     }
     jimport('joomla.filesystem.file');
     $return = JFile::write($file, $this->content);
     // Try to make the css file unwriteable
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) {
         JError::raiseNotice('SOME_ERROR_CODE', 'Could not make the html file unwritable');
     }
     if ($return) {
         $app->enqueueMessage('File saved');
     }
     return $return;
 }
Beispiel #18
0
 /**
  * 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;
     }
 }
Beispiel #19
0
 /**
  * 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;
     }
 }
 /**
  * Determine whether FTP mode is enabled
  * @return boolean
  */
 function isFtp()
 {
     // Initialize variables
     jimport('joomla.client.helper');
     $FTPOptions = JClientHelper::getCredentials('ftp');
     return $FTPOptions['enabled'] == 1;
 }
Beispiel #21
0
 /**
  * Method to write the configuration to a file.
  *
  * @param   Registry  $config  A Registry object containing all global config data.
  *
  * @return	boolean  True on success, false on failure.
  *
  * @since	2.5.4
  * @throws  RuntimeException
  */
 private function writeConfigFile(Registry $config)
 {
     jimport('joomla.filesystem.path');
     jimport('joomla.filesystem.file');
     // Set the configuration file path.
     $file = JPATH_CONFIGURATION . '/configuration.php';
     // Get the new FTP credentials.
     $ftp = JClientHelper::getCredentials('ftp', true);
     $app = JFactory::getApplication();
     // Attempt to make the file writeable if using FTP.
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0644')) {
         $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTWRITABLE'), 'notice');
     }
     // Attempt to write the configuration file as a PHP class named JConfig.
     $configuration = $config->toString('PHP', array('class' => 'JConfig', 'closingtag' => false));
     if (!JFile::write($file, $configuration)) {
         throw new RuntimeException(JText::_('COM_CONFIG_ERROR_WRITE_FAILED'));
     }
     // Attempt to make the file unwriteable if using FTP.
     if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0444')) {
         $app->enqueueMessage(JText::_('COM_CONFIG_ERROR_CONFIGURATION_PHP_NOTUNWRITABLE'), 'notice');
     }
     return true;
 }
Beispiel #22
0
 /**
  * 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;
 }
Beispiel #23
0
/**
 * 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;
}
 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'));
     }
 }
Beispiel #25
0
 /**
  * Method to store the source file contents.
  *
  * @param	array	The souce data to save.
  *
  * @return	boolean	True on success, false otherwise and internal error set.
  * @since	1.6
  */
 public function save($data)
 {
     // Get the template.
     $template = $this->getTemplate();
     if (empty($template)) {
         return false;
     }
     $fileName = $this->getState('filename');
     $client = JApplicationHelper::getClientInfo($template->client_id);
     $filePath = \Hubzero\Filesystem\Util::normalizePath($client->path . '/templates/' . $template->element . '/' . $fileName);
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     // Try to make the template file writeable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !Filesystem::setPermissions($filePath, '0644')) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'));
         return false;
     }
     // Trigger the onExtensionBeforeSave event.
     $result = Event::trigger('extension.onExtensionBeforeSave', array('com_templates.source', &$data, false));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // [!] HUBZERO - Force line endings to be consistent with the server environment
     $data['source'] = preg_replace('~\\R~u', PHP_EOL, $data['source']);
     $return = Filesystem::write($filePath, $data['source']);
     // Try to make the template file unwriteable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !Filesystem::setPermissions($filePath, '0444')) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE'));
         return false;
     } elseif (!$return) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName));
         return false;
     }
     // Trigger the onExtensionAfterSave event.
     Event::trigger('extension.onExtensionAfterSave', array('com_templates.source', &$table, false));
     return true;
 }
Beispiel #26
0
 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);
             }
         }
     }
 }
Beispiel #27
0
 /**
  * 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;
 }
Beispiel #28
0
/**
 * logInfo
 * to help debugging Payment notification for example
 */
function logInfo($text, $type = 'message')
{
    if (!class_exists('JFile')) {
        require JPATH_VM_LIBRARIES . DS . 'joomla' . DS . 'filesystem' . DS . 'file.php';
    }
    $config = JFactory::getConfig();
    $log_path = $config->get('log_path', JPATH_ROOT . "/log");
    $file = $log_path . "/" . VmConfig::$logFileName . VmConfig::LOGFILEEXT;
    if (!is_dir($log_path)) {
        jimport('joomla.filesystem.folder');
        if (!JFolder::create($log_path)) {
            if (VmConfig::$echoAdmin) {
                $msg = 'Could not create path ' . $log_path . ' to store log information. Check your folder ' . $log_path . ' permissions.';
                $app = JFactory::getApplication();
                $app->enqueueMessage($msg, 'error');
            }
            return;
        }
    }
    if (!is_writable($log_path)) {
        if (VmConfig::$echoAdmin) {
            $msg = 'Path ' . $log_path . ' to store log information is not writable. Check your folder ' . $log_path . ' permissions.';
            $app = JFactory::getApplication();
            $app->enqueueMessage($msg, 'error');
        }
        return;
    }
    $head = false;
    if (!JFile::exists($file)) {
        // blank line to prevent information disclose: https://bugs.php.net/bug.php?id=60677
        // from Joomla log file
        $head = "#\n";
        $head .= '#<?php die("Forbidden."); ?>' . "\n";
    }
    // Initialise variables.
    if (!class_exists('JClientHelper')) {
        require JPATH_VM_LIBRARIES . DS . 'joomla' . DS . 'client' . DS . 'helper.php';
    }
    $FTPOptions = JClientHelper::getCredentials('ftp');
    if ($FTPOptions['enabled'] == 0) {
        static $fp;
        $fp = fopen($file, 'a');
        if ($fp) {
            if ($head) {
                fwrite($fp, $head);
            }
            fwrite($fp, "\n" . JFactory::getDate()->format('%Y-%m-%d %H:%M:%S'));
            fwrite($fp, " " . strtoupper($type) . ' ' . $text);
            fclose($fp);
        } else {
            if (VmConfig::$echoAdmin) {
                $msg = 'Could not write in file  ' . $file . ' to store log information. Check your file ' . $file . ' permissions.';
                $app = JFactory::getApplication();
                $app->enqueueMessage($msg, 'error');
            }
        }
    } else {
        //For logging we do not support FTP. For loggin without file permissions using FTP, we need to load the file,..
        //append the text and replace the file. This cannot be fast per FTP and therefore we disable it.
    }
    return;
}
Beispiel #29
0
 /**
  * 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;
     }
 }
Beispiel #30
0
 /**
  * Method to store the source file contents.
  *
  * @param	array	The souce data to save.
  *
  * @return	boolean	True on success, false otherwise and internal error set.
  * @since	1.6
  */
 public function save($data)
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.client.helper');
     // Get the template.
     $template = $this->getTemplate();
     if (empty($template)) {
         return false;
     }
     $dispatcher = JDispatcher::getInstance();
     $fileName = $this->getState('filename');
     $client = JApplicationHelper::getClientInfo($template->client_id);
     $filePath = JPath::clean($client->path . '/templates/' . $template->element . '/' . $fileName);
     // Include the extension plugins for the save events.
     JPluginHelper::importPlugin('extension');
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     // Try to make the template file writeable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0644')) {
         $this->setError(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'));
         return false;
     }
     // Trigger the onExtensionBeforeSave event.
     $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_templates.source', &$data, false));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     $return = JFile::write($filePath, $data['source']);
     // Try to make the template file unwriteable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !JPath::setPermissions($filePath, '0444')) {
         $this->setError(JText::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE'));
         return false;
     } else {
         if (!$return) {
             $this->setError(JText::sprintf('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName));
             return false;
         }
     }
     // Trigger the onExtensionAfterSave event.
     $dispatcher->trigger('onExtensionAfterSave', array('com_templates.source', &$table, false));
     return true;
 }