public function testFTP() { $config = array( 'host' => $this->getState('host'), 'port' => $this->getState('port'), 'user' => $this->getState('user'), 'pass' => $this->getState('pass'), 'initdir' => $this->getState('initdir'), 'usessl' => $this->getState('usessl'), 'passive' => $this->getState('passive'), ); // Perform the FTP connection test $test = new AEArchiverDirectftp(); $test->initialize('', $config); $errors = $test->getError(); if(empty($errors) || $test->connect_ok) { $result = true; } else { $result = $errors; } return $result; }
public function testFTP() { $config = array('host' => $this->getState('host'), 'port' => $this->getState('port'), 'user' => $this->getState('user'), 'pass' => $this->getState('pass'), 'initdir' => $this->getState('initdir'), 'usessl' => $this->getState('usessl'), 'passive' => $this->getState('passive')); // Check for bad settings if (substr($config['host'], 0, 6) == 'ftp://') { return JText::_('CONFIG_FTPTEST_BADPREFIX'); } // Perform the FTP connection test $test = new AEArchiverDirectftp(); $test->initialize('', $config); $errors = $test->getError(); if (empty($errors) || $test->connect_ok) { $result = true; } else { $result = $errors; } return $result; }
function doAjax() { $ajax = $this->getState('ajax'); switch ($ajax) { // FTP Connection test for DirectFTP case 'testftp': // Grab request parameters $config = array('host' => $this->input->get('host', '', 'none', 2), 'port' => $this->input->get('port', 21, 'int'), 'user' => $this->input->get('user', '', 'none', 2), 'pass' => $this->input->get('pass', '', 'none', 2), 'initdir' => $this->input->get('initdir', '', 'none', 2), 'usessl' => $this->input->get('usessl', 'cmd') == 'true', 'passive' => $this->input->get('passive', 'cmd') == 'true'); // Perform the FTP connection test $test = new AEArchiverDirectftp(); $test->initialize('', $config); $errors = $test->getError(); if (empty($errors)) { $result = true; } else { $result = $errors; } break; // Unrecognized AJAX task // Unrecognized AJAX task default: $result = false; break; } return $result; }
/** * 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; }
function doAjax() { $ajax = $this->getState('ajax'); switch ($ajax) { // FTP Connection test for DirectFTP case 'testftp': // Grab request parameters $config = array('host' => $this->input->get('host', '', 'none', 2), 'port' => $this->input->get('port', 21, 'int'), 'user' => $this->input->get('user', '', 'none', 2), 'pass' => $this->input->get('pass', '', 'none', 2), 'initdir' => $this->input->get('initdir', '', 'none', 2), 'usessl' => $this->input->get('usessl', 'cmd') == 'true', 'passive' => $this->input->get('passive', 'cmd') == 'true'); // Perform the FTP connection test $test = new AEArchiverDirectftp(); $test->initialize('', $config); $errors = $test->getError(); if (empty($errors)) { $result = true; } else { $result = $errors; } break; case 'restoreFilesPing': case 'restoreFilesStart': case 'restoreFilesStep': case 'restoreFilesFinalize': global $restoration_setup; $restoration_setup = $this->getRestorationParameters(); define('KICKSTART', 1); include_once JPATH_COMPONENT_ADMINISTRATOR . '/restore.php'; akeebaTinyHackForRestorationObserver(); masterSetup(); $retArray = array('status' => true, 'message' => null); switch ($ajax) { case 'restoreFilesPing': // ping task - realy does nothing! $timer = AKFactory::getTimer(); $timer->enforce_min_exec_time(); break; case 'restoreFilesStart': AKFactory::nuke(); // Reset the factory // Reset the factory case 'restoreFilesStep': $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { $tmp_path = $config->get('tmp_path', ''); } else { $tmp_path = $config->getValue('tmp_path', ''); } $override = array('rename_dirs' => array('sql' => rtrim($tmp_path, '/\\') . '/sql')); $engine = AKFactory::getUnarchiver($override); // Get the engine $observer = new RestorationObserver(); // Create a new observer $engine->attach($observer); // Attach the observer $engine->tick(); $ret = $engine->getStatusArray(); if ($ret['Error'] != '') { $retArray['status'] = false; $retArray['done'] = true; $retArray['message'] = $ret['Error']; } elseif (!$ret['HasRun']) { $retArray['files'] = $observer->filesProcessed; $retArray['bytesIn'] = $observer->compressedTotal; $retArray['bytesOut'] = $observer->uncompressedTotal; $retArray['status'] = true; $retArray['done'] = true; } else { $retArray['files'] = $observer->filesProcessed; $retArray['bytesIn'] = $observer->compressedTotal; $retArray['bytesOut'] = $observer->uncompressedTotal; $retArray['status'] = true; $retArray['done'] = false; $retArray['factory'] = AKFactory::serialize(); } break; case 'restoreFilesFinalize': $root = AKFactory::get('kickstart.setup.destdir'); // Remove the sql dump directory $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { $tmp_path = $config->get('tmp_path', ''); } else { $tmp_path = $config->getValue('tmp_path', ''); } $sqldir = rtrim($tmp_path, '/\\') . '/sql'; recursive_remove_directory($sqldir); break; } return $retArray; break; case 'dbRestoreStart': $this->dbRestorationInit(); case 'dbRestore': $result = $this->dbRestore(); break; // Unrecognized AJAX task // Unrecognized AJAX task default: $result = false; break; } return $result; }