Exemplo n.º 1
0
Arquivo: native.php Projeto: 01J/topm
 protected function _prepare()
 {
     AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Processing parameters");
     // Get the DB connection parameters
     if (is_array($this->_parametersArray)) {
         $driver = array_key_exists('driver', $this->_parametersArray) ? $this->_parametersArray['driver'] : 'mysql';
         $host = array_key_exists('host', $this->_parametersArray) ? $this->_parametersArray['host'] : '';
         $port = array_key_exists('port', $this->_parametersArray) ? $this->_parametersArray['port'] : '';
         $username = array_key_exists('username', $this->_parametersArray) ? $this->_parametersArray['username'] : '';
         $username = array_key_exists('user', $this->_parametersArray) ? $this->_parametersArray['user'] : $username;
         $password = array_key_exists('password', $this->_parametersArray) ? $this->_parametersArray['password'] : '';
         $database = array_key_exists('database', $this->_parametersArray) ? $this->_parametersArray['database'] : '';
         $prefix = array_key_exists('prefix', $this->_parametersArray) ? $this->_parametersArray['prefix'] : '';
     }
     $options = array('driver' => $driver, 'host' => $host . ($port != '' ? ':' . $port : ''), 'user' => $username, 'password' => $password, 'database' => $database, 'prefix' => is_null($prefix) ? '' : $prefix);
     $db = AEFactory::getDatabase($options);
     $driverType = $db->getDriverType();
     $className = 'AEDumpNative' . ucfirst($driverType);
     // Check if we have a native dump driver
     if (!class_exists($className, true)) {
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Native database dump engine {$className} not found; trying Reverse Engineering instead");
         // Native driver nor found, I will try falling back to reverse engineering
         $className = 'AEDumpReverse' . ucfirst($driverType);
     }
     if (!class_exists($className, true)) {
         $this->setState('error', 'Akeeba Engine does not have a native dump engine for ' . $driverType . ' databases');
     } else {
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Instanciating new native database dump engine {$className}");
         $this->_engine = new $className();
         $this->_engine->setup($this->_parametersArray);
         $this->_engine->callStage('_prepare');
         $this->setState($this->_engine->getState(), $this->_engine->getError());
     }
 }
Exemplo n.º 2
0
 private static function loadConfig()
 {
     if (defined('JVERSION')) {
         $j16 = version_compare(JVERSION, '1.6.0', 'ge');
     } else {
         $j16 = false;
     }
     $db =& AEFactory::getDatabase();
     if (!$j16) {
         $sql = "SELECT " . $db->nameQuote('params') . " FROM " . $db->nameQuote('#__components') . " WHERE (" . $db->nameQuote('link') . " = " . $db->Quote('option=com_akeeba') . ") AND (" . $db->nameQuote('parent') . " = " . $db->Quote('0') . ")";
         $db->setQuery($sql);
         $config_ini = $db->loadResult();
     } else {
         $config_ini = null;
     }
     if ($db->getErrorNum() || is_null($config_ini)) {
         // Maybe it's Joomla! 1.6?
         $sql = "SELECT " . $db->nameQuote('params') . " FROM " . $db->nameQuote('#__extensions') . " WHERE (" . $db->nameQuote('type') . ' = ' . $db->Quote('component') . ') AND (' . $db->nameQuote('element') . " = " . $db->Quote('com_akeeba') . ")";
         $db->setQuery($sql);
         $config_ini = $db->loadResult();
         // OK, Joomla! 1.6 stores values JSON-encoded so, what do I do? Right!
         $config_ini = json_decode($config_ini, true);
         return $config_ini;
     }
     return AEUtilINI::parse_ini_file($config_ini, false, true);
 }
 public function &getExtraSQL($root)
 {
     $empty = '';
     if ($root != '[SITEDB]') {
         return $empty;
     }
     $sql = '';
     $db = AEFactory::getDatabase();
     $this->getFilters(null);
     // Forcibly reload the filter data
     // Loop all components and add SQL statements
     if (!empty($this->filter_data)) {
         foreach ($this->filter_data as $type => $items) {
             if (!empty($items)) {
                 // Make sure that DB only backups get the correct prefix
                 $configuration = AEFactory::getConfiguration();
                 $abstract = AEUtilScripting::getScriptingParameter('db.abstractnames', 1);
                 if ($abstract) {
                     $prefix = '#__';
                 } else {
                     $prefix = $db->getPrefix();
                 }
                 foreach ($items as $item) {
                     $client = $type == 'frontend' ? 0 : 1;
                     $sql .= 'DELETE FROM ' . $db->quoteName($prefix . 'modules_menu') . ' WHERE ' . $db->quoteName('moduleid') . ' IN (' . 'SELECT ' . $db->quoteName('id') . ' FROM ' . $db->quoteName($prefix . 'modules') . ' WHERE ' . '(' . $db->quoteName('module') . ' = ' . $db->Quote($item) . ')' . ' AND (' . $db->quoteName('client_id') . ' = ' . $db->Quote($client) . ')' . ");\n";
                     $sql .= 'DELETE FROM ' . $db->quoteName($prefix . 'modules') . ' WHERE ' . '(' . $db->quoteName('module') . ' = ' . $db->Quote($item) . ')' . ' AND (' . $db->quoteName('client_id') . ' = ' . $db->Quote($client) . ')' . ";\n";
                     $sql .= 'DELETE FROM ' . $db->quoteName($prefix . 'extensions') . ' WHERE ' . $db->quoteName('element') . ' = ' . $db->Quote($item) . " AND " . $db->quoteName('type') . ' = ' . $db->Quote('module') . ";\n";
                 }
             }
         }
     }
     return $sql;
 }
Exemplo n.º 4
0
 public function &getExtraSQL($root)
 {
     $empty = '';
     if ($root != '[SITEDB]') {
         return $empty;
     }
     $sql = '';
     $db = AEFactory::getDatabase();
     $this->getFilters(null);
     // Forcibly reload the filter data
     // Loop all components and add SQL statements
     if (!empty($this->filter_data)) {
         foreach ($this->filter_data as $type => $items) {
             if (!empty($items)) {
                 // Make sure that DB only backups get the correct prefix
                 $configuration = AEFactory::getConfiguration();
                 $abstract = AEUtilScripting::getScriptingParameter('db.abstractnames', 1);
                 if ($abstract) {
                     $prefix = '#__';
                 } else {
                     $prefix = $db->getPrefix();
                 }
                 foreach ($items as $item) {
                     if (!$this->joomla16) {
                         $sql .= 'DELETE FROM ' . $db->quoteName($prefix . 'components') . ' WHERE ' . $db->quoteName('option') . ' = ' . $db->Quote($item) . ";\n";
                     } else {
                         $sql .= 'DELETE FROM ' . $db->quoteName($prefix . 'extensions') . ' WHERE ' . $db->quoteName('element') . ' = ' . $db->Quote($item) . " AND " . $db->quoteName('type') . ' = ' . $db->Quote('component') . ";\n";
                     }
                     $sql .= 'DELETE FROM ' . $db->quoteName($prefix . 'menu') . ' WHERE ' . $db->quoteName('type') . ' = ' . $db->Quote('component') . ' AND ' . $db->quoteName('link') . ' LIKE ' . $db->Quote('%option=' . $item . '%') . ";\n";
                 }
             }
         }
     }
     return $sql;
 }
Exemplo n.º 5
0
 /**
  * Returns a list of the database tables, views, procedures, functions and triggers,
  * along with their filter status in array format, for use in the GUI
  * @return array
  */
 public function make_listing($root)
 {
     // Get database inclusion filters
     $filters =& AEFactory::getFilters();
     $database_list = $filters->getInclusions('db');
     // Load the database object for the selected database
     $config = $database_list[$root];
     $config['user'] = $config['username'];
     $db =& AEFactory::getDatabase($config);
     // Load the table data
     $table_data = $db->getTables();
     // Process filters
     $tables = array();
     if (!empty($table_data)) {
         foreach ($table_data as $table_name => $table_type) {
             $status = array();
             // Add table type
             $status['type'] = $table_type;
             // Check dbobject/all filter (exclude)
             $result = $filters->isFilteredExtended($table_name, $root, 'dbobject', 'all', $byFilter);
             $status['tables'] = !$result ? 0 : ($byFilter == 'tables' ? 1 : 2);
             // Check dbobject/content filter (skip table data)
             $result = $filters->isFilteredExtended($table_name, $root, 'dbobject', 'content', $byFilter);
             $status['tabledata'] = !$result ? 0 : ($byFilter == 'tabledata' ? 1 : 2);
             if ($table_type != 'table') {
                 $status['tabledata'] = 2;
             }
             // We can't filter contents of views, merge tables, black holes, procedures, functions and triggers :)
             $tables[$table_name] = $status;
         }
     }
     return array('tables' => $tables, 'root' => $root);
 }
 public function check()
 {
     $db = AEFactory::getDatabase();
     // Can I execute SHOW statements?
     try {
         $result = $db->setQuery('SHOW TABLES')->query();
     } catch (Exception $e) {
         AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW TABLES statement");
         $this->setResult(-1);
         throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR'));
     }
     if (!$result) {
         AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW TABLES statement");
         $this->setResult(-1);
         throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR'));
     }
     try {
         $result = $db->setQuery('SHOW CREATE TABLE ' . $db->nameQuote('#__ak_profiles'))->query();
     } catch (Exception $e) {
         AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW CREATE TABLE statement");
         $this->setResult(-1);
         throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR'));
     }
     if (!$result) {
         AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW CREATE TABLE statement");
         $this->setResult(-1);
         throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR'));
     }
     return true;
 }
Exemplo n.º 7
0
 private static function loadConfig()
 {
     $db = AEFactory::getDatabase();
     $sql = $db->getQuery(true)->select($db->qn('params'))->from($db->qn('#__extensions'))->where($db->qn('element') . " = " . $db->q('com_akeeba'));
     $db->setQuery($sql);
     $config_ini = $db->loadResult();
     // OK, Joomla! 1.6 stores values JSON-encoded so, what do I do? Right!
     $config_ini = json_decode($config_ini, true);
     if (is_null($config_ini) || empty($config_ini)) {
         $config_ini = array();
     }
     return $config_ini;
 }
Exemplo n.º 8
0
 /**
  * Returns a list of emails to the Super Administrators
  * @return unknown_type
  */
 public function get_administrator_emails()
 {
     $db =& AEFactory::getDatabase($this->get_platform_database_options());
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $query = 'SELECT u.name, u.email FROM #__users AS u INNER JOIN #__user_usergroup_map AS m ON(m.user_id = u.id) ' . ' WHERE m.group_id = 8 ';
     } else {
         $query = 'SELECT name, email FROM #__users' . ' WHERE usertype = \'Super Administrator\' ';
     }
     $db->setQuery($query);
     $superAdmins =& $db->loadAssocList();
     $mails = array();
     if (!empty($superAdmins)) {
         foreach ($superAdmins as $admin) {
             $mails[] = $admin['email'];
         }
     }
     return $mails;
 }
Exemplo n.º 9
0
 /**
  * Keeps a maximum number of "obsolete" records
  */
 private function apply_obsolete_quotas()
 {
     $this->setStep('Applying quota limit on obsolete backup records');
     $this->setSubstep('');
     $registry = AEFactory::getConfiguration();
     $limit = $registry->get('akeeba.quota.obsolete_quota', 0);
     $limit = (int) $limit;
     if ($limit <= 0) {
         return;
     }
     $statsTable = AEPlatform::getInstance()->tableNameStats;
     $db = AEFactory::getDatabase(AEPlatform::getInstance()->get_platform_database_options());
     $query = $db->getQuery(true)->select(array($db->qn('id'), $db->qn('backupid'), $db->qn('absolute_path')))->from($db->qn($statsTable))->where($db->qn('status') . ' = ' . $db->q('complete'))->where($db->qn('filesexist') . '=' . $db->q('0'))->order($db->qn('id') . ' DESC');
     $db->setQuery($query, $limit, 100000);
     $records = $db->loadAssocList();
     if (empty($records)) {
         return;
     }
     $array = array();
     // Delete backup-specific log files if they exist and add the IDs of the records to delete in the $array
     foreach ($records as $stat) {
         $array[] = $stat['id'];
         // We can't delete logs if there is no backup ID in the record
         if (!isset($stat['backupid']) || empty($stat['backupid'])) {
             continue;
         }
         $logFileName = 'akeeba.' . $stat['tag'] . '.' . $stat['backupid'] . '.log';
         $logPath = dirname($stat['absolute_path']) . '/' . $logFileName;
         @unlink($logPath);
     }
     $ids = array();
     foreach ($array as $id) {
         $ids[] = $db->q($id);
     }
     $ids = implode(',', $ids);
     $query = $db->getQuery(true)->delete($db->qn($statsTable))->where($db->qn('id') . " IN ({$ids})");
     $db->setQuery($query);
     $db->query();
 }
Exemplo n.º 10
0
 public static function &get($tag = null)
 {
     $storage_filename = self::get_storage_filename($tag);
     $ret = false;
     switch (self::getStorageEngine()) {
         case 'file':
             $rawdata = @file_get_contents($storage_filename);
             if ($rawdata === false) {
                 return $ret;
             }
             if (strpos($rawdata, "\n") === false) {
                 return $ret;
             }
             list($header, $data) = explode("\n", $rawdata);
             unset($rawdata);
             unset($header);
             break;
         case 'db':
             $db = AEFactory::getDatabase();
             $sql = 'SELECT `data` FROM `#__ak_storage` WHERE `tag` = ' . $db->Quote($storage_filename);
             $db->setQuery($sql);
             $data = $db->loadResult();
             break;
     }
     $ret = self::decode($data);
     unset($data);
     return $ret;
 }
 /**
  * Return an instance of AEAbstractDriver
  *
  * @return AEAbstractDriver
  */
 protected function &getDB()
 {
     $host = $this->host . ($this->port != '' ? ':' . $this->port : '');
     $user = $this->username;
     $password = $this->password;
     $driver = $this->driver;
     $database = $this->database;
     $prefix = is_null($this->prefix) ? '' : $this->prefix;
     $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
     $db = AEFactory::getDatabase($options);
     if ($error = $db->getError()) {
         $this->setError(__CLASS__ . ' :: Database Error: ' . $error);
         $false = false;
         return $false;
     }
     if ($db->getErrorNum() > 0) {
         $error = $db->getErrorMsg();
         $this->setError(__CLASS__ . ' :: Database Error: ' . $error);
         $false = false;
         return $false;
     }
     return $db;
 }
Exemplo n.º 12
0
    public function execute()
    {
        // Load the language files
        $paths = array(JPATH_ADMINISTRATOR, JPATH_ROOT);
        $jlang = JFactory::getLanguage();
        $jlang->load('com_akeeba', $paths[0], 'en-GB', true);
        $jlang->load('com_akeeba', $paths[1], 'en-GB', true);
        $jlang->load('com_akeeba' . '.override', $paths[0], 'en-GB', true);
        $jlang->load('com_akeeba' . '.override', $paths[1], 'en-GB', true);
        // Get the backup profile and description
        $profile = $this->input->get('profile', 1, 'int');
        $description = $this->input->get('description', 'Command-line backup', 'string');
        $overrides = $this->getOption('override', array(), false);
        if (!empty($overrides)) {
            $override_message = "\nConfiguration variables overriden in the command line:\n";
            $override_message .= implode(', ', array_keys($overrides));
            $override_message .= "\n";
        } else {
            $override_message = "";
        }
        $debugmessage = '';
        if ($this->input->get('debug', -1, 'int') != -1) {
            if (!defined('AKEEBADEBUG')) {
                define('AKEEBADEBUG', 1);
            }
            $debugmessage = "*** DEBUG MODE ENABLED ***\n";
        }
        $version = AKEEBA_VERSION;
        $date = AKEEBA_DATE;
        $start_backup = time();
        $memusage = $this->memUsage();
        $phpversion = PHP_VERSION;
        $phpenvironment = PHP_SAPI;
        $phpos = PHP_OS;
        if ($this->input->get('quiet', -1, 'int') == -1) {
            $year = gmdate('Y');
            echo <<<ENDBLOCK
Akeeba Backup CLI {$version} ({$date})
Copyright (C) 2010-{$year} Nicholas K. Dionysopoulos
-------------------------------------------------------------------------------
Akeeba Backup is Free Software, distributed under the terms of the GNU General
Public License version 3 or, at your option, any later version.
This program comes with ABSOLUTELY NO WARRANTY as per sections 15 & 16 of the
license. See http://www.gnu.org/licenses/gpl-3.0.html for details.
-------------------------------------------------------------------------------
You are using PHP {$phpversion} ({$phpenvironment})
{$debugmessage}
Starting a new backup with the following parameters:
Profile ID  {$profile}
Description "{$description}"
{$override_message}
Current memory usage: {$memusage}


ENDBLOCK;
        }
        // Attempt to use an infinite time limit, in case you are using the PHP CGI binary instead
        // of the PHP CLI binary. This will not work with Safe Mode, though.
        $safe_mode = true;
        if (function_exists('ini_get')) {
            $safe_mode = ini_get('safe_mode');
        }
        if (!$safe_mode && function_exists('set_time_limit')) {
            if ($this->input->get('quiet', -1, 'int') == -1) {
                echo "Unsetting time limit restrictions.\n";
            }
            @set_time_limit(0);
        } elseif (!$safe_mode) {
            if ($this->input->get('quiet', -1, 'int') == -1) {
                echo "Could not unset time limit restrictions; you may get a timeout error\n";
            }
        } else {
            if ($this->input->get('quiet', -1, 'int') == -1) {
                echo "You are using PHP's Safe Mode; you may get a timeout error\n";
            }
        }
        if ($this->input->get('quiet', -1, 'int') == -1) {
            echo "\n";
        }
        // Log some paths
        if ($this->input->get('quiet', -1, 'int') == -1) {
            echo "Site paths determined by this script:\n";
            echo "JPATH_BASE : " . JPATH_BASE . "\n";
            echo "JPATH_ADMINISTRATOR : " . JPATH_ADMINISTRATOR . "\n\n";
        }
        // Load the engine
        $factoryPath = JPATH_ADMINISTRATOR . '/components/com_akeeba/akeeba/factory.php';
        define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_akeeba');
        define('AKEEBAROOT', JPATH_ADMINISTRATOR . '/components/com_akeeba/akeeba');
        if (!file_exists($factoryPath)) {
            echo "ERROR!\n";
            echo "Could not load the backup engine; file does not exist. Technical information:\n";
            echo "Path to " . basename(__FILE__) . ": " . __DIR__ . "\n";
            echo "Path to factory file: {$factoryPath}\n";
            die("\n");
        } else {
            try {
                require_once $factoryPath;
            } catch (Exception $e) {
                echo "ERROR!\n";
                echo "Backup engine returned an error. Technical information:\n";
                echo "Error message:\n\n";
                echo $e->getMessage() . "\n\n";
                echo "Path to " . basename(__FILE__) . ":" . __DIR__ . "\n";
                echo "Path to factory file: {$factoryPath}\n";
                die("\n");
            }
        }
        // Forced CLI mode settings
        define('AKEEBA_PROFILE', $profile);
        define('AKEEBA_BACKUP_ORIGIN', 'cli');
        // Force loading CLI-mode translation class
        $dummy = new AEUtilTranslate();
        // Load the profile
        AEPlatform::getInstance()->load_configuration($profile);
        // Reset Kettenrad and its storage
        AECoreKettenrad::reset(array('maxrun' => 0));
        AEUtilTempvars::reset(AKEEBA_BACKUP_ORIGIN);
        // Setup
        $kettenrad = AEFactory::getKettenrad();
        $options = array('description' => $description, 'comment' => '');
        if (!empty($overrides)) {
            AEPlatform::getInstance()->configOverrides = $overrides;
        }
        $kettenrad->setup($options);
        // Dummy array so that the loop iterates once
        $array = array('HasRun' => 0, 'Error' => '');
        $warnings_flag = false;
        while ($array['HasRun'] != 1 && empty($array['Error'])) {
            // Recycle the database conenction to minimise problems with database timeouts
            $db = AEFactory::getDatabase();
            $db->close();
            $db->open();
            AEUtilLogger::openLog(AKEEBA_BACKUP_ORIGIN);
            AEUtilLogger::WriteLog(true, '');
            // Apply overrides in the command line
            if (!empty($overrides)) {
                $config = AEFactory::getConfiguration();
                foreach ($overrides as $key => $value) {
                    $config->set($key, $value);
                }
            }
            // Apply engine optimization overrides
            $config = AEFactory::getConfiguration();
            $config->set('akeeba.tuning.min_exec_time', 0);
            $config->set('akeeba.tuning.nobreak.beforelargefile', 1);
            $config->set('akeeba.tuning.nobreak.afterlargefile', 1);
            $config->set('akeeba.tuning.nobreak.proactive', 1);
            $config->set('akeeba.tuning.nobreak.finalization', 1);
            $config->set('akeeba.tuning.settimelimit', 0);
            $config->set('akeeba.tuning.nobreak.domains', 0);
            $kettenrad->tick();
            AEFactory::getTimer()->resetTime();
            $array = $kettenrad->getStatusArray();
            AEUtilLogger::closeLog();
            $time = date('Y-m-d H:i:s \\G\\M\\TO (T)');
            $memusage = $this->memUsage();
            $warnings = "no warnings issued (good)";
            $stepWarnings = false;
            if (!empty($array['Warnings'])) {
                $warnings_flag = true;
                $warnings = "POTENTIAL PROBLEMS DETECTED; " . count($array['Warnings']) . " warnings issued (see below).\n";
                foreach ($array['Warnings'] as $line) {
                    $warnings .= "\t{$line}\n";
                }
                $stepWarnings = true;
                $kettenrad->resetWarnings();
            }
            if ($this->input->get('quiet', -1, 'int') == -1 || $stepWarnings) {
                echo <<<ENDSTEPINFO
Last Tick   : {$time}
Domain      : {$array['Domain']}
Step        : {$array['Step']}
Substep     : {$array['Substep']}
Memory used : {$memusage}
Warnings    : {$warnings}


ENDSTEPINFO;
            }
        }
        // Clean up
        AEUtilTempvars::reset(AKEEBA_BACKUP_ORIGIN);
        if (!empty($array['Error'])) {
            echo "An error has occurred:\n{$array['Error']}\n\n";
            $exitCode = 2;
        } else {
            if ($this->input->get('quiet', -1, 'int') == -1) {
                echo "Backup job finished successfully after approximately " . $this->timeago($start_backup, time(), '', false) . "\n";
            }
            $exitCode = 0;
        }
        if ($warnings_flag && $this->input->get('quiet', -1, 'int') == -1) {
            $exitCode = 1;
            echo "\n" . str_repeat('=', 79) . "\n";
            echo "!!!!!  W A R N I N G  !!!!!\n\n";
            echo "Akeeba Backup issued warnings during the backup process. You have to review them\n";
            echo "and make sure that your backup has completed successfully. Always test a backup with\n";
            echo "warnings to make sure that it is working properly, by restoring it to a local server.\n";
            echo "DO NOT IGNORE THIS MESSAGE! AN UNTESTED BACKUP IS AS GOOD AS NO BACKUP AT ALL.\n";
            echo "\n" . str_repeat('=', 79) . "\n";
        } elseif ($warnings_flag) {
            $exitCode = 1;
        }
        if ($this->input->get('quiet', -1, 'int') == -1) {
            echo "Peak memory usage: " . $this->peakMemUsage() . "\n\n";
        }
        $this->close($exitCode);
    }
Exemplo n.º 13
0
 public static function &get($tag = null)
 {
     $storage_filename = self::get_storage_filename($tag);
     $ret = false;
     switch (self::getStorageEngine()) {
         case 'file':
             $rawdata = @file_get_contents($storage_filename);
             if ($rawdata === false) {
                 return $ret;
             }
             if (strpos($rawdata, "\n") === false) {
                 return $ret;
             }
             list($header, $data) = explode("\n", $rawdata);
             unset($rawdata);
             unset($header);
             break;
         case 'db':
             $db = AEFactory::getDatabase();
             $sql = $db->getQuery(true)->select($db->qn('data'))->from($db->qn('#__ak_storage'))->where($db->qn('tag') . ' = ' . $db->q($storage_filename));
             $db->setQuery($sql);
             $data = $db->loadResult();
             break;
     }
     $ret = self::decode($data);
     unset($data);
     return $ret;
 }
Exemplo n.º 14
0
 /**
  * Saves the nested filter data array $filter_data to the database
  * @param	array	$filter_data	The filter data to save
  * @return	bool	True on success
  */
 public function save_filters(&$filter_data)
 {
     $profile_id = $this->get_active_profile();
     $db = AEFactory::getDatabase($this->get_platform_database_options());
     $sql = $db->getQuery(true)->update($db->qn($this->tableNameProfiles))->set($db->qn('filters') . '=' . $db->q(serialize($filter_data)))->where($db->qn('id') . ' = ' . $db->q($profile_id));
     $db->setQuery($sql);
     $db->query();
     $errors = $db->getError();
     return empty($errors);
 }
Exemplo n.º 15
0
 /**
  * Keeps a maximum number of "obsolete" records
  */
 private function apply_obsolete_quotas()
 {
     $this->setStep('Applying quota limit on obsolete backup records');
     $this->setSubstep('');
     $registry =& AEFactory::getConfiguration();
     $limit = $registry->get('akeeba.quota.obsolete_quota', 0);
     $limit = (int) $limit;
     if ($limit <= 0) {
         return;
     }
     $db =& AEFactory::getDatabase(AEPlatform::getInstance()->get_platform_database_options());
     $query = 'SELECT `id` FROM #__ak_stats WHERE `status` = \'complete\' AND `filesexist` = 0 ORDER BY `id` DESC LIMIT ' . $limit . ',100000';
     $db->setQuery($query);
     $array = $db->loadResultArray();
     if (empty($array)) {
         return;
     }
     $ids = implode(',', $array);
     $query = "DELETE FROM #__ak_stats WHERE " . $db->nameQuote('id') . " IN ({$ids})";
     $db->setQuery($query);
     $db->query();
 }
Exemplo n.º 16
0
 /**
  * Keeps a maximum number of "obsolete" records
  */
 private function apply_obsolete_quotas()
 {
     $this->setStep('Applying quota limit on obsolete backup records');
     $this->setSubstep('');
     $registry = AEFactory::getConfiguration();
     $limit = $registry->get('akeeba.quota.obsolete_quota', 0);
     $limit = (int) $limit;
     if ($limit <= 0) {
         return;
     }
     $statsTable = AEPlatform::getInstance()->tableNameStats;
     $db = AEFactory::getDatabase(AEPlatform::getInstance()->get_platform_database_options());
     $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn($statsTable))->where($db->qn('status') . ' = ' . $db->q('complete'))->where($db->qn('filesexist') . '=' . $db->q('0'))->order($db->qn('id') . ' DESC');
     $db->setQuery($query, $limit, 100000);
     $array = $db->loadColumn();
     if (empty($array)) {
         return;
     }
     $ids = array();
     foreach ($array as $id) {
         $ids[] = $db->q($id);
     }
     $ids = implode(',', $ids);
     $query = $db->getQuery(true)->delete($db->qn($statsTable))->where($db->qn('id') . " IN ({$ids})");
     $db->setQuery($query);
     $db->query();
 }
 /**
  * Tests the connectivity to a database
  * @param array $data
  * @return array Status array: 'status' is true on success, 'message' contains any error message while connecting to the database
  */
 public function test($data)
 {
     $db = AEFactory::getDatabase($data);
     $error = $db->getErrorMsg();
     return array('status' => $db->getErrorNum() <= 0, 'message' => $error);
 }
 /**
  * Returns the selected profile's name. If no ID is specified, the current
  * profile's name is returned.
  * @return string
  */
 public function get_profile_name($id = null)
 {
     if (empty($id)) {
         $id = $this->get_active_profile();
     }
     $id = (int) $id;
     $sql = 'SELECT `description` FROM `#__ak_profiles` WHERE `id` = ' . $id;
     $db = AEFactory::getDatabase($this->get_platform_database_options());
     $db->setQuery($sql);
     return $db->loadResult();
 }
Exemplo n.º 19
0
 /**
  * Saves the nested filter data array $filter_data to the database
  * @param	array	$filter_data	The filter data to save
  * @return	bool	True on success
  */
 public function save_filters(&$filter_data)
 {
     $profile_id = $this->get_active_profile();
     $db =& AEFactory::getDatabase($this->get_platform_database_options());
     // Load the INI format local configuration dump off the database
     $sql = "UPDATE " . $db->nameQuote('#__ak_profiles') . ' SET ' . $db->nameQuote('filters') . '=' . $db->Quote(serialize($filter_data)) . ' WHERE ' . $db->nameQuote('id') . ' = ' . $db->Quote($profile_id);
     $db->setQuery($sql);
     $db->query();
     $errors = $db->getError();
     return empty($errors);
 }
    private function createDatabasesINI()
    {
        // caching databases.ini contents
        AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . "AkeebaCUBEDomainDBBackup :: Creating databases.ini data");
        // Create a new string
        $databasesINI = '';
        $blankOutPass = AEFactory::getConfiguration()->get('engine.dump.common.blankoutpass', 0);
        // Loop through databases list
        foreach ($this->dumpedDatabases as $definition) {
            $section = basename($definition['dumpFile']);
            $dboInstance = AEFactory::getDatabase($definition);
            $type = $dboInstance->name;
            $tech = $dboInstance->getDriverType();
            if ($blankOutPass) {
                $this->databases_ini .= <<<ENDDEF
[{$section}]
dbtype = "{$type}"
dbtech = "{$tech}"
dbname = "{$definition['database']}"
sqlfile = "{$definition['dumpFile']}"
dbhost = "{$definition['host']}"
dbuser = ""
dbpass = ""
prefix = "{$definition['prefix']}"
parts = "{$definition['parts']}"

ENDDEF;
            } else {
                $this->databases_ini .= <<<ENDDEF
[{$section}]
dbtype = "{$type}"
dbtech = "{$tech}"
dbname = "{$definition['database']}"
sqlfile = "{$definition['dumpFile']}"
dbhost = "{$definition['host']}"
dbuser = "******"
dbpass = "******"
prefix = "{$definition['prefix']}"
parts = "{$definition['parts']}"

ENDDEF;
            }
        }
    }
Exemplo n.º 21
0
 /**
  * Saves the nested filter data array $filter_data to the database
  *
  * @param    array $filter_data The filter data to save
  *
  * @return    bool    True on success
  */
 public function save_filters(&$filter_data)
 {
     $profile_id = $this->get_active_profile();
     $db = AEFactory::getDatabase($this->get_platform_database_options());
     $sql = $db->getQuery(true)->update($db->qn($this->tableNameProfiles))->set($db->qn('filters') . '=' . $db->q(serialize($filter_data)))->where($db->qn('id') . ' = ' . $db->q($profile_id));
     $db->setQuery($sql);
     try {
         $db->query();
     } catch (Exception $exc) {
         return false;
     }
     return true;
 }
Exemplo n.º 22
0
 /**
  * Implements the _run() abstract method
  */
 protected function _run()
 {
     if ($this->getState() == 'postrun') {
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Already finished");
         $this->setStep('');
         $this->setSubstep('');
         return;
     } else {
         $this->setState('running');
     }
     // Load the version defines
     AEPlatform::getInstance()->load_version_defines();
     $registry = AEFactory::getConfiguration();
     // Write log file's header
     AEUtilLogger::WriteLog(_AE_LOG_INFO, "--------------------------------------------------------------------------------");
     AEUtilLogger::WriteLog(_AE_LOG_INFO, "Akeeba Backup " . AKEEBA_VERSION . ' (' . AKEEBA_DATE . ')');
     AEUtilLogger::WriteLog(_AE_LOG_INFO, "Got backup?");
     AEUtilLogger::WriteLog(_AE_LOG_INFO, "--------------------------------------------------------------------------------");
     // PHP configuration variables are tried to be logged only for debug and info log levels
     if ($registry->get('akeeba.basic.log_level') >= _AE_LOG_INFO) {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "--- System Information ---");
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "PHP Version        :" . PHP_VERSION);
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "PHP OS             :" . PHP_OS);
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "PHP SAPI           :" . PHP_SAPI);
         if (function_exists('php_uname')) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "OS Version         :" . php_uname('s'));
         }
         $db = AEFactory::getDatabase();
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "DB Version         :" . $db->getVersion());
         if (isset($_SERVER['SERVER_SOFTWARE'])) {
             $server = $_SERVER['SERVER_SOFTWARE'];
         } else {
             if ($sf = getenv('SERVER_SOFTWARE')) {
                 $server = $sf;
             } else {
                 $server = 'n/a';
             }
         }
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Web Server         :" . $server);
         $platform = 'Unknown platform';
         $version = '(unknown version)';
         $platformData = AEPlatform::getInstance()->getPlatformVersion();
         AEUtilLogger::WriteLog(_AE_LOG_INFO, $platformData['name'] . " version    :" . $platformData['version']);
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "User agent         :" . phpversion() <= "4.2.1" ? getenv("HTTP_USER_AGENT") : $_SERVER['HTTP_USER_AGENT']);
         }
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Safe mode          :" . ini_get("safe_mode"));
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Display errors     :" . ini_get("display_errors"));
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Error reporting    :" . self::error2string());
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Error display      :" . self::errordisplay());
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Disabled functions :" . ini_get("disable_functions"));
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "open_basedir restr.:" . ini_get('open_basedir'));
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Max. exec. time    :" . ini_get("max_execution_time"));
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Memory limit       :" . ini_get("memory_limit"));
         if (function_exists("memory_get_usage")) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Current mem. usage :" . memory_get_usage());
         }
         if (function_exists("gzcompress")) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "GZIP Compression   : available (good)");
         } else {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "GZIP Compression   : n/a (no compression)");
         }
         AEPlatform::getInstance()->log_platform_special_directories();
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Output directory   :" . $registry->get('akeeba.basic.output_directory'));
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "--------------------------------------------------------------------------------");
     }
     // Quirks reporting
     $quirks = AEUtilQuirks::get_quirks(true);
     if (!empty($quirks)) {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Akeeba Backup has detected the following potential problems:");
         foreach ($quirks as $q) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, '- ' . $q['code'] . ' ' . $q['description'] . ' (' . $q['severity'] . ')');
         }
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "You probably do not have to worry about them, but you should be aware of them.");
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "--------------------------------------------------------------------------------");
     }
     if (!version_compare(PHP_VERSION, '5.3.0', 'ge')) {
         AEUtilLogger::WriteLog(_AE_LOG_WARNING, "You are using an outdated version of PHP. Akeeba Engine may not work properly. Please upgrade to PHP 5.3 or later.");
     }
     // Report profile ID
     $profile_id = AEPlatform::getInstance()->get_active_profile();
     AEUtilLogger::WriteLog(_AE_LOG_INFO, "Loaded profile #{$profile_id}");
     // Get archive name
     AEUtilFilesystem::get_archive_name($relativeArchiveName, $absoluteArchiveName);
     // ==== Stats initialisation ===
     $origin = AEPlatform::getInstance()->get_backup_origin();
     // Get backup origin
     $profile_id = AEPlatform::getInstance()->get_active_profile();
     // Get active profile
     $registry = AEFactory::getConfiguration();
     $backupType = $registry->get('akeeba.basic.backup_type');
     AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Backup type is now set to '" . $backupType . "'");
     // Substitute "variables" in the archive name
     $description = AEUtilFilesystem::replace_archive_name_variables($this->description);
     $comment = AEUtilFilesystem::replace_archive_name_variables($this->comment);
     if ($registry->get('volatile.writer.store_on_server', true)) {
         // Archive files are stored on our server
         $stat_relativeArchiveName = $relativeArchiveName;
         $stat_absoluteArchiveName = $absoluteArchiveName;
     } else {
         // Archive files are not stored on our server (FTP backup, cloud backup, sent by email, etc)
         $stat_relativeArchiveName = '';
         $stat_absoluteArchiveName = '';
     }
     $kettenrad = AEFactory::getKettenrad();
     $temp = array('description' => $description, 'comment' => $comment, 'backupstart' => AEPlatform::getInstance()->get_timestamp_database(), 'status' => 'run', 'origin' => $origin, 'type' => $backupType, 'profile_id' => $profile_id, 'archivename' => $stat_relativeArchiveName, 'absolute_path' => $stat_absoluteArchiveName, 'multipart' => 0, 'filesexist' => 1, 'tag' => $kettenrad->getTag());
     // Save the entry
     $statistics = AEFactory::getStatistics();
     $statistics->setStatistics($temp);
     if ($statistics->getError()) {
         $this->setError($statistics->getError());
         return;
     }
     $statistics->release_multipart_lock();
     // Initialize the archive.
     if (AEUtilScripting::getScriptingParameter('core.createarchive', true)) {
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Expanded archive file name: " . $absoluteArchiveName);
         AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Initializing archiver engine");
         $archiver = AEFactory::getArchiverEngine();
         $archiver->initialize($absoluteArchiveName);
         $archiver->setComment($comment);
         // Add the comment to the archive itself.
         $archiver->propagateToObject($this);
         if ($this->getError()) {
             return;
         }
     }
     $this->setState('postrun');
 }
Exemplo n.º 23
0
	/**
	 * Returns a list of emails to the Super Administrators
	 * @return unknown_type
	 */
	public static function get_administrator_emails()
	{
		$db =& AEFactory::getDatabase( self::get_platform_database_options() );
		$query = 'SELECT name, email FROM #__users'.
				' WHERE usertype = \'Super Administrator\' ';
		$db->setQuery($query);
		$superAdmins =& $db->loadObjectList();

		$mails = array();
		if(!empty($superAdmins))
		{
			foreach($superAdmins as $admin)
			{
				$mails[] = $admin->email;
			}
		}

		return $mails;
	}