Example #1
0
	/**
	 * Handle the apply task which saves settings and shows the editor again
	 *
	 */
	public function apply()
	{
		// CSRF prevention
		if(!JRequest::getVar(JUtility::getToken(), false, 'POST')) {
			JError::raiseError('403', JText::_(version_compare(JVERSION, '1.6.0', 'ge') ? 'JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN' : 'Request Forbidden'));
		}
		
		// Get the var array from the request
		$var = JRequest::getVar('var', array(), 'default', 'array');
		// Make it into Akeeba Engine array format
		$data = array();
		foreach($var as $key => $value)
		{
			$data[$key] = $value;
		}
		// Forbid stupidly selecting the site's root as the output or temporary directory
		if( array_key_exists('akeeba.basic.output_directory', $data) )
		{
			$folder = $data['akeeba.basic.output_directory'];
			$folder = AEUtilFilesystem::translateStockDirs( $folder, true, true );

			$check = AEUtilFilesystem::translateStockDirs( '[SITEROOT]', true, true );

			if($check == $folder)
			{
				JError::raiseWarning(503, JText::_('CONFIG_OUTDIR_ROOT'));
				$data['akeeba.basic.output_directory'] = '[DEFAULT_OUTPUT]';
			}
		}
		if( array_key_exists('akeeba.basic.temporary_directory', $data) )
		{
			$folder = $data['akeeba.basic.temporary_directory'];
			$folder = AEUtilFilesystem::translateStockDirs( $folder, true, true );

			$check = AEUtilFilesystem::translateStockDirs( '[SITEROOT]', true, true );

			if($check == $folder)
			{
				JError::raiseWarning(503, JText::_('CONFIG_TMPDIR_ROOT'));
				$data['akeeba.basic.temporary_directory'] = '[SITETMP]';
			}
		}

		// Merge it
		$config =& AEFactory::getConfiguration();
		$config->mergeArray($data, false, false);
		// Save configuration
		AEPlatform::save_configuration();

		$this->setRedirect(JURI::base().'index.php?option='.JRequest::getCmd('option').'&view=config', JText::_('CONFIG_SAVE_OK'));
	}
Example #2
0
	/**
	 * Creates a dummy file of a given size. Remember to give the filesize
	 * query parameter in bytes!
	 */
	public function partsize()
	{
		$timer = AEFactory::getTimer();
		$blocks = JRequest::getInt('blocks', 1);
		
		$model = JModel::getInstance('Confwiz','AkeebaModel');
		$result = $model->createTempFile($blocks);

		if($result) {
			// Save the setting
			if($blocks > 200) $blocks = 16383; // Over 25Mb = 2Gb minus 128Kb limit (safe setting for PHP not running on 64-bit Linux)
			$profile_id = AEPlatform::get_active_profile();
			$config = AEFactory::getConfiguration();
			$config->set('engine.archiver.common.part_size', $blocks * 128 * 1024);
			AEPlatform::save_configuration($profile_id);
		}
		// Enforce the min exec time
		$timer->enforce_min_exec_time(false);
		
		return $result;
	}
Example #3
0
	/**
	 * Apply the transfer settings to the profile. Returns true if the connection
	 * and uploading a test file works properly, an error message otherwise
	 * 
	 * @return bool|string
	 */
	public function applyTransferSettings()
	{
		// Get state variables
		$method		= $this->getState('method');
		$hostname	= $this->getState('hostname');
		$port		= $this->getState('port');
		$username	= $this->getState('username');
		$password	= $this->getState('password');
		$directory	= $this->getState('directory');
		$passive	= $this->getState('passive');
		$livesite	= $this->getState('livesite');
		
		// Fix the hostname, in case the user added a protocol (grr...)
		$protoPos = strpos($hostname,'://');
		if($protoPos !== false) {
			$proto = substr($hostname, 0, $protoPos-1);
			$proto = strtolower($proto);
			switch($proto) {
				case 'ftp':
					$method = 'ftp';
					break;
				case 'ftps':
				case 'ftpes':
					$method = 'ftps';
					break;
				case 'sftp':
					$method = 'sftp';
					break;
			}
			$hostname = substr($hostname, $protoPos+3);
		}
		
		// Assign default configuration variables
		$config = AEFactory::getConfiguration();
		$config->set('akeeba.basic.backup_type','full');
		$config->set('akeeba.advanced.proc_engine','none');
		if( (substr($livesite, 0, 7) != 'http://') && (substr($livesite, 0, 8) != 'https://') ) {
			$livesite = 'http://'.$livesite;
		}
		$livesite = rtrim($livesite,"/\n\r ");
		$config->set('akeeba.stw.livesite', $livesite);

		// Apply the transfer settings
		switch($method) {
			case 'ftp':
			case 'ftps':
				$config->set('akeeba.advanced.archiver_engine',		'directftp');
				$config->set('engine.archiver.directftp.host',		$hostname);
				$config->set('engine.archiver.directftp.port',		$port);
				$config->set('engine.archiver.directftp.user',		$username);
				$config->set('engine.archiver.directftp.pass',		$password);
				$config->set('engine.archiver.directftp.initial_directory',	$directory);
				$config->set('engine.archiver.directftp.ftps',	($method == 'ftps' ? 1 : 0));
				$config->set('engine.archiver.directftp.passive_mode', ($passive ? 1 : 0));
				break;
			
			case 'sftp':
				$config->set('akeeba.advanced.archiver_engine',		'directsftp');
				$config->set('engine.archiver.directsftp.host',		$hostname);
				$config->set('engine.archiver.directsftp.port',		$port);
				$config->set('engine.archiver.directsftp.user',		$username);
				$config->set('engine.archiver.directsftp.pass',		$password);
				$config->set('engine.archiver.directsftp.initial_directory',	$directory);
				break;
		}
		AEPlatform::save_configuration();
		
		// Connection test
		switch($method) {
			case 'ftp':
			case 'ftps':
				$config = array(
					'host'		=> $config->get('engine.archiver.directftp.host'),
					'port'		=> $config->get('engine.archiver.directftp.port'),
					'user'		=> $config->get('engine.archiver.directftp.user'),
					'pass'		=> $config->get('engine.archiver.directftp.pass'),
					'initdir'	=> $config->get('engine.archiver.directftp.initial_directory'),
					'usessl'	=> $config->get('engine.archiver.directftp.ftps'),
					'passive'	=> $config->get('engine.archiver.directftp.passive_mode')
				);
				
				$test = new AEArchiverDirectftp();
				$test->initialize('', $config);
				$errors = $test->getError();
				break;
				
			case 'sftp':
				$config = array(
					'host'		=> $config->get('engine.archiver.directsftp.host'),
					'port'		=> $config->get('engine.archiver.directsftp.port'),
					'user'		=> $config->get('engine.archiver.directsftp.user'),
					'pass'		=> $config->get('engine.archiver.directsftp.pass'),
					'initdir'	=> $config->get('engine.archiver.directsftp.initial_directory')
				);
				
				$test = new AEArchiverDirectsftp();
				$test->initialize('', $config);
				$errors = $test->getError();
				break;
		}
		
		// Check for connection errors
		if(empty($errors) || $test->connect_ok) {
			$result = true;
		} else {
			$result = JText::_('STW_LBL_CONNECTION_ERR_CONNECTION').' '.$errors;
			return $result;
		}
		
		// Test upload file
		$file = JPATH_ROOT.DS.'media'.DS.'com_akeeba'.DS.'icons'.DS.'ok_small.png';
		$result = $test->addFileRenamed($file, 'akeeba_connection_test.png');
		
		if(!$result) {
			$result = JText::_('STW_LBL_CONNECTION_ERR_UPLOAD').' '.$result;
			return $result;
		}
		
		return true;
	}
Example #4
0
	private function _apiUpdateCleanup($config) {
		$session =& JFactory::getSession();
		$session->set('profile', 1, 'akeeba');
		AEPlatform::load_configuration(1);
		$config = AEFactory::getConfiguration();
		$target = $config->get('remoteupdate.target', '');
		$tempdir = $config->get('remoteupdate.tempdir', '');
		
		$session = JFactory::getSession();
		$session->set('target', $target, 'liveupdate');
		$session->set('tempdir', $tempdir, 'liveupdate');
		
		require_once JPATH_ROOT.'/administrator/components/com_akeeba/liveupdate/liveupdate.php';
		require_once JPATH_ROOT.'/administrator/components/com_akeeba/liveupdate/classes/model.php';
		
		$model = new LiveupdateModel();
		$ret = $model->cleanup();
		
		jimport('joomla.filesystem.file');
		JFile::delete($target);

		$config->set('remoteupdate.target', null);
		$config->set('remoteupdate.tempdir', null);
		AEPlatform::save_configuration(1);

		return (object)array(
			'cleanup'	=> 1
		);
	}