Beispiel #1
0
 public function onBeforeMain()
 {
     if ($this->input->get('layout') != 'init') {
         return true;
     }
     /** @var AngieModelMain $model */
     $model = $this->getModel();
     /** @var ASession $session */
     $session = ASession::getInstance();
     // Assign the results of the various checks
     $this->reqSettings = $model->getRequired();
     $this->reqMet = $model->isRequiredMet();
     $this->recommendedSettings = $model->getRecommended();
     $this->extraInfo = $model->getExtraInfo();
     $this->joomlaVersion = $session->get('jversion');
     $this->version = $session->get('version');
     // Am I restoring to a different site?
     $this->restoringToDifferentHost = false;
     if (isset($this->extraInfo['host'])) {
         $uri = AUri::getInstance();
         $this->restoringToDifferentHost = $this->extraInfo['host']['current'] != $uri->getHost();
     }
     // If I am restoring to a different host blank out the database
     // connection information to prevent unpleasant situations, like a user
     // "accidentally" overwriting his original site's database...
     if ($this->restoringToDifferentHost && !$session->get('main.resetdbinfo', false)) {
         $model->resetDatabaseConnectionInformation();
     }
     return true;
 }
Beispiel #2
0
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     // Application service
     if (!isset($this['application'])) {
         $this['application'] = function (AContainer $c) {
             return AApplication::getTmpInstance($c->application_name, array(), 'Angie', $c);
         };
     }
     // Input Access service
     if (!isset($this['input'])) {
         $this['input'] = function (AContainer $c) {
             return new AInput();
         };
     }
     // Application Dispatcher service
     if (!isset($this['dispatcher'])) {
         $this['dispatcher'] = function (AContainer $c) {
             return ADispatcher::getTmpInstance(null, null, array(), $c);
         };
     }
     if (!isset($this['session'])) {
         $this['session'] = function (AContainer $c) {
             return ASession::getInstance();
         };
     }
 }
    public function onBeforeMain()
    {
        ADocument::getInstance()->addScriptDeclaration(<<<ENDSRIPT
var akeebaAjax = null;
\$(document).ready(function(){
    akeebaAjax = new akeebaAjaxConnector('index.php');

    akeebaAjax.callJSON({
        'view'   : 'runscripts',
        'format' : 'raw'
    });
});
ENDSRIPT
);
        $model = $this->getModel();
        $this->showconfig = $model->getState('showconfig', 0);
        if ($this->showconfig) {
            $this->configuration = AModel::getAnInstance('Configuration', 'AngieModel')->getFileContents();
        }
        if (ASession::getInstance()->get('tfa_warning', false)) {
            $this->extra_warning = '<div class="alert alert-block alert-error">';
            $this->extra_warning .= '<h4 class="alert-heading">' . AText::_('FINALISE_TFA_DISABLED_TITLE') . '</h4>';
            $this->extra_warning .= '<p>' . AText::_('FINALISE_TFA_DISABLED_BODY') . '</p>';
            $this->extra_warning .= '</div>';
        }
        return true;
    }
Beispiel #4
0
 public function onBeforeMain()
 {
     if ($this->input->get('layout') != 'init') {
         return true;
     }
     // Assign the results of the various checks
     $this->reqSettings = $this->getModel()->getRequired();
     $this->reqMet = $this->getModel()->isRequiredMet();
     $this->recommendedSettings = $this->getModel()->getRecommended();
     $this->extraInfo = $this->getModel()->getExtraInfo();
     $this->joomlaVersion = ASession::getInstance()->get('jversion');
     // Am I restoring to a different site?
     $this->restoringToDifferentHost = false;
     if (isset($this->extraInfo['host'])) {
         $uri = AUri::getInstance();
         $this->restoringToDifferentHost = $this->extraInfo['host']['current'] != $uri->getHost();
     }
     // Am I restoring to a different PHP version?
     $this->restoringToDifferentPHP = false;
     if (isset($this->extraInfo['php_version'])) {
         $parts = explode('.', $this->extraInfo['php_version']['current']);
         $sourceVersion = $parts[0] . '.' . $parts[1];
         $parts = explode('.', PHP_VERSION);
         $targetVersion = $parts[0] . '.' . $parts[1];
         $this->restoringToDifferentPHP = $sourceVersion != $targetVersion;
     }
     // If I am restoring to a different host blank out the database
     // connection information to prevent unpleasant situations, like a user
     // "accidentally" overwriting his original site's database...
     if ($this->restoringToDifferentHost && !ASession::getInstance()->get('main.resetdbinfo', false)) {
         $this->getModel()->resetDatabaseConnectionInformation();
     }
     return true;
 }
 public function getDirs($associative = false, $force = false)
 {
     if (empty($this->offsiteini)) {
         if (!$force) {
             $this->offsiteini = ASession::getInstance()->get('directories.offsiteini', null);
         }
         if (empty($this->offsiteini)) {
             $temp = array();
             $filename = APATH_INSTALLATION . '/eff.ini';
             if (file_exists($filename)) {
                 $handle = fopen($filename, 'r');
                 if ($handle !== false) {
                     while (($line = fgets($handle)) !== false) {
                         $parts = explode('=', $line);
                         if (count($parts) < 2) {
                             continue;
                         }
                         $parts = str_replace(array("\n", "\r"), '', $parts);
                         $key = str_replace('external_files/', '', trim($parts[1], '"'));
                         if ($associative) {
                             $temp[$key] = array('target' => trim($parts[0], '"'), 'virtual' => trim($parts[1], '"'));
                         } else {
                             $temp[] = $key;
                         }
                     }
                 }
             }
             $this->offsiteini = $temp;
             ASession::getInstance()->set('directories.offsiteini', $this->offsiteini);
         }
     }
     return $this->offsiteini;
 }
Beispiel #6
0
 public function main()
 {
     $session = ASession::getInstance();
     if ($session->isStorageWorking()) {
         $this->setRedirect('index.php?view=main');
         return;
     }
     parent::main();
 }
Beispiel #7
0
 /**
  * Returns the steps array
  *
  * @return array
  */
 public function getSteps()
 {
     if (empty($this->steps)) {
         // First try fetching the steps from the session
         $this->steps = ASession::getInstance()->get('steps.allsteps', null);
         if (empty($this->steps)) {
             // No steps are saved in the session. Initialise the steps.
             $this->initialiseSteps();
             ASession::getInstance()->set('steps.allsteps', $this->steps);
         }
     }
     return $this->steps;
 }
Beispiel #8
0
 public function unlock()
 {
     $parts = explode(':', AKEEBA_PASSHASH);
     $password = $this->input->get('password', '', 'raw');
     $passHash = md5($password . $parts[1]);
     ASession::getInstance()->set('angie.passhash', $passHash);
     ASession::getInstance()->saveData();
     if ($passHash == $parts[0]) {
         $this->setRedirect('index.php?view=main');
     } else {
         $msg = AText::_('PASSWORD_ERR_INVALIDPASSWORD');
         $this->setRedirect('index.php?view=password', $msg, 'error');
     }
 }
 /**
  * Public constructor
  *
  * @param   array  $config  Configuration parameters
  */
 public function __construct($config = array())
 {
     // Set the application name
     $this->name = $this->getName();
     // Load up the input
     $this->input = new AInput();
     // Create a session
     $this->session = ASession::getInstance();
     // Set up the template
     if (array_key_exists('template', $config)) {
         $this->setTemplate($config['template']);
     }
     // If no template is specified, fall back to the default
     if (empty($this->template)) {
         $this->setTemplate();
     }
 }
 /**
  * Check if the installer is password protected. If it is and the user has
  * not yet entered a password forward him to the password entry page.
  * 
  * @return  boolean
  */
 private function passwordProtection()
 {
     $filePath = APATH_INSTALLATION . '/password.php';
     if (file_exists($filePath)) {
         include_once $filePath;
     }
     $view = $this->input->get('view', $this->defaultView);
     if (defined('AKEEBA_PASSHASH')) {
         $savedHash = ASession::getInstance()->get('angie.passhash', null);
         $parts = explode(':', AKEEBA_PASSHASH);
         $correctHash = $parts[0];
         $allowedViews = array('password', 'session', 'ftpbrowser');
         if (defined('AKEEBA_PASSHASH') && !in_array($view, $allowedViews) && $savedHash != $correctHash) {
             AApplication::getInstance()->redirect('index.php?view=password');
             return true;
         }
     } elseif (!defined('AKEEBA_PASSHASH') && $this->input->get('view', $this->defaultView) == 'password') {
         return false;
     }
     return true;
 }
Beispiel #11
0
?>
					</label>
					<div class="controls">
						<input type="text" id="cookiepath" name="cookiepath" value="<?php 
echo $this->stateVars->cookiepath;
?>
" />
						<span class="help-tooltip icon-question-sign" data-toggle="tooltip" data-html="true" data-placement="top"
							  title="<?php 
echo AText::_('SETUP_LBL_COOKIEPATH_HELP');
?>
"></span>
					</div>
				</div>
            <?php 
if (version_compare(ASession::getInstance()->get('jversion'), '3.2', 'ge')) {
    ?>
                <div class="control-group">
                    <label class="control-label" for="mailonline">
                        <?php 
    echo AText::_('SETUP_LBL_MAILONLINE');
    ?>
                    </label>
                    <div class="controls">
                        <label class="radio inline">
                            <input type="radio" <?php 
    echo !$this->stateVars->mailonline ? 'checked="checked"' : '';
    ?>
 name="mailonline" value="0" />
                            <?php 
    echo AText::_('GENERIC_LBL_NO');
Beispiel #12
0
 /**
  * Resets the database connection information of all databases
  */
 public function resetDatabaseConnectionInformation()
 {
     $model = AModel::getAnInstance('Database', 'AngieModel');
     $databasesIni = $model->getDatabasesIni();
     $temp = array();
     foreach ($databasesIni as $key => $data) {
         $data['dbhost'] = '';
         $data['dbuser'] = '';
         $data['dbpass'] = '';
         $data['dbname'] = '';
         $model->setDatabaseInfo($key, $data);
     }
     $model->saveDatabasesIni();
     ASession::getInstance()->set('main.resetdbinfo', true);
 }
Beispiel #13
0
 /**
  * Resets the configuration variables
  */
 public function reset()
 {
     $this->configvars = array();
     ASession::getInstance()->remove('configuration.variables');
 }
Beispiel #14
0
 private function updateTFA($oldsecret, $newsecret)
 {
     ASession::getInstance()->set('tfa_warning', false);
     // There is no TFA in Joomla < 3.2
     $jversion = ASession::getInstance()->get('jversion');
     if (version_compare($jversion, '3.2', 'lt')) {
         return;
     }
     $db = $this->getDatabase();
     $query = $db->getQuery(true)->select('COUNT(extension_id)')->from($db->qn('#__extensions'))->where($db->qn('type') . ' = ' . $db->q('plugin'))->where($db->qn('folder') . ' = ' . $db->q('twofactorauth'))->where($db->qn('enabled') . ' = ' . $db->q('1'));
     $count = $db->setQuery($query)->loadResult();
     // No enabled plugin, there is no point in continuing
     if (!$count) {
         return;
     }
     $query = $db->getQuery(true)->select('*')->from($db->qn('#__users'))->where($db->qn('otpKey') . ' != ' . $db->q(''))->where($db->qn('otep') . ' != ' . $db->q(''));
     $users = $db->setQuery($query)->loadObjectList();
     // There are no users with TFA configured, let's stop here
     if (!$users) {
         return;
     }
     // Otherwise I'll get a blank page
     if (!defined('FOF_INCLUDED')) {
         define('FOF_INCLUDED', 1);
     }
     include_once APATH_LIBRARIES . '/fof/encrypt/aes.php';
     // Does this host support AES?
     if (!FOFEncryptAes::isSupported()) {
         // If not, set a flag, so we will display a big, fat warning in the finalize screen
         ASession::getInstance()->set('tfa_warning', true);
         // Let's disable them
         $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q('0'))->where($db->qn('type') . ' = ' . $db->q('plugin'))->where($db->qn('folder') . ' = ' . $db->q('twofactorauth'));
         $db->setQuery($query)->execute();
         return;
     }
     $oldaes = new FOFEncryptAes($oldsecret, 256);
     $newaes = new FOFEncryptAes($newsecret, 256);
     foreach ($users as $user) {
         $update = (object) array('id' => $user->id, 'otpKey' => '', 'otep' => '');
         list($method, $otpKey) = explode(':', $user->otpKey);
         $update->otpKey = $oldaes->decryptString($otpKey);
         $update->otpKey = $method . ':' . $newaes->encryptString($update->otpKey);
         $update->otep = $oldaes->decryptString($user->otep);
         $update->otep = $newaes->encryptString($update->otep);
         $db->updateObject('#__users', $update, 'id');
     }
 }
Beispiel #15
0
 /**
  * Saves the (modified) databases information to the session
  */
 public function saveDatabasesIni()
 {
     ASession::getInstance()->set('databases.dbini', $this->dbini);
 }
Beispiel #16
0
 private function applySuperAdminChanges()
 {
     // Get the Super User ID. If it's empty, skip.
     $id = $this->getState('superuserid', 0);
     if (!$id) {
         return false;
     }
     // Get the Super User email and password
     $email = $this->getState('superuseremail', '');
     $password1 = $this->getState('superuserpassword', '');
     $password2 = $this->getState('superuserpasswordrepeat', '');
     // If the email is empty but the passwords are not, fail
     if (empty($email)) {
         if (empty($password1) && empty($password2)) {
             return false;
         } else {
             throw new Exception(AText::_('SETUP_ERR_EMAILEMPTY'));
         }
     }
     // If the passwords are empty, skip
     if (empty($password1) && empty($password2)) {
         return false;
     }
     // Make sure the passwords match
     if ($password1 != $password2) {
         throw new Exception(AText::_('SETUP_ERR_PASSWORDSDONTMATCH'));
     }
     // Let's load the password compatibility file
     require_once APATH_ROOT . '/installation/framework/utils/password.php';
     // Connect to the database
     $connectionVars = $this->getDbConnectionVars();
     $name = $connectionVars->dbtype;
     $options = array('database' => $connectionVars->dbname, 'select' => 1, 'host' => $connectionVars->dbhost, 'user' => $connectionVars->dbuser, 'password' => $connectionVars->dbpass, 'prefix' => $connectionVars->prefix);
     $db = ADatabaseFactory::getInstance()->getDriver($name, $options);
     // Create a new salt and encrypted password (legacy method for Joomla! 1.5.0 through 3.2.0)
     $salt = $this->genRandomPassword(32);
     $crypt = md5($password1 . $salt);
     $cryptpass = $crypt . ':' . $salt;
     // Get the Joomla! version. If none was detected we assume it's 1.5.0 (so we can use the legacy method)
     $jVersion = ASession::getInstance()->get('jversion', '1.5.0');
     // If we're restoring Joomla! 3.2.2 or later which fully supports bCrypt then we need to get a bCrypt-hashed
     // password.
     if (version_compare($jVersion, '3.2.2', 'ge')) {
         // Create a new bCrypt-bashed password. At the time of this writing (July 2015) Joomla! is using a cost of 10
         $cryptpass = password_hash($password1, PASSWORD_BCRYPT, array('cost' => 10));
     }
     // Update the database record
     $query = $db->getQuery(true)->update($db->qn('#__users'))->set($db->qn('password') . ' = ' . $db->q($cryptpass))->set($db->qn('email') . ' = ' . $db->q($email))->where($db->qn('id') . ' = ' . $db->q($id));
     $db->setQuery($query);
     $db->execute();
     return true;
 }
Beispiel #17
0
 /**
  * Gets the value of a user state variable.
  *
  * @access	public
  * @param	string	The key of the user state variable.
  * @param	string	The name of the variable passed in a request.
  * @param	string	The default value for the variable if not found. Optional.
  * @param	string	Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.
  * @param	bool	Should I save the variable in the user state? Default: true. Optional.
  * @return	The request user state.
  */
 protected function getUserStateFromRequest($key, $request, $default = null, $type = 'none', $setUserState = true)
 {
     $session = ASession::getInstance();
     $hash = $this->getHash();
     $old_state = $session->get($hash . $key, null);
     $cur_state = !is_null($old_state) ? $old_state : $default;
     $new_state = $this->input->get($request, null, $type);
     // Save the new value only if it was set in this request
     if ($setUserState) {
         if ($new_state !== null) {
             $session->set($hash . $key, $new_state);
         } else {
             $new_state = $cur_state;
         }
     } elseif (is_null($new_state)) {
         $new_state = $cur_state;
     }
     return $new_state;
 }
Beispiel #18
0
 /**
  * Runs a restoration step and returns an array to be used in the response.
  *
  * @return  array
  *
  * @throws Exception
  */
 public function stepRestoration()
 {
     $parts = $this->getParam('parts', 1);
     $this->openFile();
     $this->linenumber = $this->start;
     $this->totalsizeread = 0;
     $this->queries = 0;
     while ($this->timer->getTimeLeft() > 0) {
         // Get the next query line
         try {
             $query = $this->readNextLine();
         } catch (Exception $exc) {
             if ($exc->getCode() == 200) {
                 break;
             } elseif ($exc->getCode() == 201) {
                 continue;
             }
         }
         // Process the query line, running drop/rename queries as necessary
         $this->processQueryLine($query);
         // Update variables
         $this->totalsizeread += strlen($query);
         $this->totalqueries++;
         $this->queries++;
         $query = "";
         $this->linenumber++;
     }
     // Get the current file position
     $current_foffset = ftell($this->file);
     if ($current_foffset === false) {
         if (is_resource($this->file)) {
             @fclose($this->file);
         }
         throw new Exception(AText::_('ANGI_RESTORE_ERROR_CANTREADPOINTER'));
     } else {
         if (is_null($this->foffset)) {
             $this->foffset = 0;
         }
         $bytes_in_step = $current_foffset - $this->foffset;
         $this->runSize = (is_null($this->runSize) ? 0 : $this->runSize) + $bytes_in_step;
         $this->foffset = $current_foffset;
     }
     // Return statistics
     $bytes_togo = $this->totalSize - $this->runSize;
     // Check for global EOF
     if ($this->curpart >= $parts - 1 && feof($this->file)) {
         $bytes_togo = 0;
     }
     // Save variables in storage
     $this->setToStorage('start', $this->start);
     $this->setToStorage('foffset', $this->foffset);
     $this->setToStorage('totalqueries', $this->totalqueries);
     $this->setToStorage('runsize', $this->runSize);
     if ($bytes_togo == 0) {
         // Clear stored variables if we're finished
         $lines_togo = '0';
         $lines_tota = $this->linenumber - 1;
         $queries_togo = '0';
         $queries_tota = $this->totalqueries;
         $this->removeInformationFromStorage();
     }
     ASession::getInstance()->saveData();
     // Calculate estimated time
     $bytesPerSecond = $bytes_in_step / $this->timer->getRunningTime();
     if ($bytesPerSecond <= 0.01) {
         $remainingSeconds = 120;
     } else {
         $remainingSeconds = round($bytes_togo / $bytesPerSecond, 0);
     }
     // Return meaningful data
     return array('percent' => round(100 * ($this->runSize / $this->totalSize), 1), 'restored' => $this->sizeformat($this->runSize), 'total' => $this->sizeformat($this->totalSize), 'queries_restored' => $this->totalqueries, 'current_line' => $this->linenumber, 'current_part' => $this->curpart, 'total_parts' => $parts, 'eta' => $this->etaformat($remainingSeconds), 'error' => '', 'done' => $bytes_togo == 0 ? '1' : '0');
 }
Beispiel #19
0
 public function startover()
 {
     ASession::getInstance()->reset();
     ASession::getInstance()->saveData();
     $this->setRedirect('index.php?view=main');
 }