public function adminControl()
    {
        $this->disableCaching();
        if (!BackupController::checkForZipSupport()) {
            $this->addToView('no_zip_support', true);
        } else {
            $instance_dao = DAOFactory::getDAO('InstanceDAO');
            if (isset($_POST['instance_id'])) {
                $instance = $instance_dao->get($_POST['instance_id']);
                if ($instance != null) {
                    $this->zip_file_short_name = str_replace(' ', '_', $instance->network_username) . "_" . str_replace(' ', '_', $instance->network) . '_user_data.zip';
                    $this->zip_file_full_name = THINKUP_WEBAPP_PATH . BackupDAO::CACHE_DIR . '/' . $this->zip_file_short_name;
                    $this->readme_file = THINKUP_WEBAPP_PATH . BackupDAO::CACHE_DIR . '/README.txt';
                    $this->files_to_zip[] = array('path' => $this->readme_file, 'name' => 'README.txt');
                    self::appendToReadme('THINKUP EXPORTED USER DATA
===========================

This zip archive contains all the data related to a specific service user gathered by ThinkUp. This README file ' . 'describes how to import that data into an existing ThinkUp installation.

');
                    self::exportData($instance->network_username, $instance->network);
                    self::generateZipFile();
                } else {
                    $this->addErrorMessage('Invalid service user');
                }
            } else {
                //render dropdown and form to get POST['instance_id']
                $owner_dao = DAOFactory::getDAO('OwnerDAO');
                $owner = $owner_dao->getByEmail($this->getLoggedInUser());
                $this->addToView('instances', $instance_dao->getByOwner($owner));
                $this->addInfoMessage('To export and download a single service user\'s data, ' . 'choose a service user and click on the Export User Data button. Extract the zip file ' . 'and refer to the README.txt contained within for instructions on how to import the data ' . 'into another ThinkUp database.');
            }
        }
        return $this->generateView();
    }
    public function adminControl()
    {
        $this->disableCaching();
        if (!BackupController::checkForZipSupport()) {
            $this->addToView('no_zip_support', true);
        } else {
            $instance_dao = DAOFactory::getDAO('InstanceDAO');
            if (isset($_POST['instance_id'])) {
                $instance = $instance_dao->get($_POST['instance_id']);
                if ($instance != null) {
                    $this->zip_file_short_name = str_replace(' ', '_', $instance->network_username) . "_" . str_replace(' ', '_', $instance->network) . '_user_data.zip';
                    $this->zip_file_full_name = FileDataManager::getDataPath($this->zip_file_short_name);
                    $this->readme_file = FileDataManager::getBackupPath('README.txt');
                    $this->files_to_zip[] = array('path' => $this->readme_file, 'name' => 'README.txt');
                    self::appendToReadme('THINKUP EXPORTED USER DATA
===========================

This zip archive contains all the data related to a specific service user gathered by ThinkUp. This README file ' . 'describes how to import that data into an existing ThinkUp installation.

');
                    if (!self::exportData($instance->network_username, $instance->network)) {
                        return $this->generateView();
                    }
                    self::generateZipFile();
                } else {
                    $this->addErrorMessage('Invalid service user');
                }
            } else {
                //render dropdown and form to get POST['instance_id']
                $owner_dao = DAOFactory::getDAO('OwnerDAO');
                $owner = $owner_dao->getByEmail($this->getLoggedInUser());
                $this->addToView('instances', $instance_dao->getByOwner($owner));
                $this->addInfoMessage('Choose a user to export.');
            }
        }
        return $this->generateView();
    }
Ejemplo n.º 3
0
 *
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2009-2011 Mark Wilkie
 * @author Mark Wilkie <mwilkie[at]gmail[dot]com>
 */
chdir(dirname(__FILE__) . '/../..');
require_once 'init.php';
//Avoid "Error: DateTime::__construct(): It is not safe to rely on the system's timezone settings" error
require_once 'config.inc.php';
date_default_timezone_set($THINKUP_CFG['timezone']);
// don't run via the web...
if (isset($_SERVER['SERVER_NAME'])) {
    die("This script should only be run via the command line.");
}
// we need zip support
if (!BackupController::checkForZipSupport()) {
    print "\nError: ThinkUp backups require Zip support\n\n";
    exit(1);
}
try {
    array_shift($argv);
    if (!empty($argv[0]) && preg_match('/^(\\-h|\\-\\-help)$/i', $argv[0])) {
        usage();
    }
    if (count($argv) != 2 || !preg_match('/^(\\-\\-export|\\-\\-import)$/', $argv[0])) {
        usage();
    } else {
        $filename = $argv[1];
        if (!preg_match('/\\.zip$/', $filename)) {
            error_log("\nError: data file should end in .zip");
            usage();