public function getFtp() { static $ftp = null; if (!is_object($ftp)) { $vars = $this->getStateVariables(); $this->ftp = AFtp::getInstance($vars->hostname, $vars->port, array('type' => FTP_AUTOASCII), $vars->username, $vars->password); } return $this->ftp; }
public function fix() { // Connect to FTP $vars = $this->getStateVariables(); $ftp = AFtp::getInstance($vars->hostname, $vars->port, array('type' => FTP_AUTOASCII), $vars->username, $vars->password); $root = rtrim($vars->directory, '/'); // Can we find ourself? try { $ftp->chdir($root . '/installation'); $ftp->read('defines.php', $buffer); if (!strlen($buffer)) { throw new Exception('Cannot read defines.php'); } } catch (Exception $exc) { throw new Exception(AText::_('SESSION_ERR_INVALIDDIRECTORY')); } // Let's try to chmod the directory $success = true; try { $trustMeIKnowWhatImDoing = 500 + 10 + 1; // working around overzealous scanners written by bozos $ftp->chmod($root . '/installation/tmp', $trustMeIKnowWhatImDoing); } catch (Exception $exc) { $success = false; } if ($success) { return true; } try { // That didn't work. Let's try creating an empty file in there. $ftp->write($root . '/installation/tmp/storagedata.dat', ''); // ...and let's try giving it some Number Of The Server Beast permissions $trustMeIKnowWhatImDoing = 500 + 10 + 1; // working around overzealous scanners written by bozos $ftp->chmod($root . '/installation/tmp/storagedata.dat', $trustMeIKnowWhatImDoing); } catch (Exception $exc) { throw new Exception(AText::_('SESSION_ERR_CANNOTFIX')); } return true; }
/** * Apply the settings to the configuration.php file and the database */ public function applySettings() { // Apply the Super Administrator changes $this->applySuperAdminChanges(); // Get the state variables and update the global configuration $stateVars = $this->getStateVariables(); // -- General settings $this->configModel->set('sitename', $stateVars->sitename); $this->configModel->set('mailfrom', $stateVars->siteemail); $this->configModel->set('fromname', $stateVars->emailsender); $this->configModel->set('live_site', $stateVars->livesite); $this->configModel->set('cookie_domain', $stateVars->cookiedomain); $this->configModel->set('cookie_path', $stateVars->cookiepath); $this->configModel->set('tmp_path', $stateVars->tmppath); $this->configModel->set('log_path', $stateVars->logspath); $this->configModel->set('force_ssl', $stateVars->force_ssl); if (version_compare($this->container->session->get('jversion'), '3.2', 'ge')) { $this->configModel->set('mailonline', $stateVars->mailonline); } // -- FTP settings $this->configModel->set('ftp_enable', $stateVars->ftpenable ? 1 : 0); $this->configModel->set('ftp_host', $stateVars->ftphost); $this->configModel->set('ftp_port', $stateVars->ftpport); $this->configModel->set('ftp_user', $stateVars->ftpuser); $this->configModel->set('ftp_pass', $stateVars->ftppass); $this->configModel->set('ftp_root', $stateVars->ftpdir); // -- Database settings $connectionVars = $this->getDbConnectionVars(); $this->configModel->set('dbtype', $connectionVars->dbtype); $this->configModel->set('host', $connectionVars->dbhost); $this->configModel->set('user', $connectionVars->dbuser); $this->configModel->set('password', $connectionVars->dbpass); $this->configModel->set('db', $connectionVars->dbname); $this->configModel->set('dbprefix', $connectionVars->prefix); // Let's get the old secret key, since we need it to update encrypted stored data $oldsecret = $this->configModel->get('secret', ''); $newsecret = $this->genRandomPassword(32); // -- Override the secret key $this->configModel->set('secret', $newsecret); $this->updateEncryptedData($oldsecret, $newsecret); $this->configModel->saveToSession(); // Get the configuration.php file and try to save it $configurationPHP = $this->configModel->getFileContents(); $filepath = APATH_SITE . '/configuration.php'; if (!@file_put_contents($filepath, $configurationPHP)) { if ($this->configModel->get('ftp_enable', 0)) { // Try with FTP $ftphost = $this->configModel->get('ftp_host', ''); $ftpport = $this->configModel->get('ftp_port', ''); $ftpuser = $this->configModel->get('ftp_user', ''); $ftppass = $this->configModel->get('ftp_pass', ''); $ftproot = $this->configModel->get('ftp_root', ''); try { $ftp = AFtp::getInstance($ftphost, $ftpport, array('type' => FTP_AUTOASCII), $ftpuser, $ftppass); $ftp->chdir($ftproot); $ftp->write('configuration.php', $configurationPHP); $ftp->chmod('configuration.php', 0644); } catch (Exception $exc) { // Fail gracefully return false; } return true; } return false; } return true; }