Beispiel #1
0
 public function testUserOtherExport()
 {
     $user = $this->generateUser();
     $user2 = $this->generateUser();
     \OC_User::setUserId($user2);
     $export = \OC_Migrate::export($user);
     // Check it succeeded and exists
     $this->assertTrue(json_decode($export)->success);
     // Validate the export
     $this->validateUserExport($user2, $user, json_decode($export)->data);
 }
OCP\App::checkAppEnabled('admin_migrate');
// Export?
if (isset($_POST['admin_export'])) {
    // Create the export zip
    $response = json_decode(OC_Migrate::export(null, $_POST['export_type']));
    if (!$response->success) {
        // Error
        die('error');
    } else {
        $path = $response->data;
        // Download it
        header("Content-Type: application/zip");
        header("Content-Disposition: attachment; filename=" . basename($path));
        header("Content-Length: " . filesize($path));
        @ob_end_clean();
        readfile($path);
        unlink($path);
    }
    // Import?
} else {
    if (isset($_POST['admin_import'])) {
        $from = $_FILES['owncloud_import']['tmp_name'];
        if (!OC_Migrate::import($from, 'instance')) {
            die('failed');
        }
    } else {
        // fill template
        $tmpl = new OCP\Template('admin_migrate', 'settings');
        return $tmpl->fetchPage();
    }
}
Beispiel #3
0
 /**
  * tries to create the zip
  * @return bool
  */
 private static function createZip()
 {
     self::$zip = new ZipArchive();
     // Check if properties are set
     if (!self::$zippath) {
         OC_Log::write('migration', 'createZip() called but $zip and/or $zippath have not been set', OC_Log::ERROR);
         return false;
     }
     if (self::$zip->open(self::$zippath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
         OC_Log::write('migration', 'Failed to create the zip with error: ' . self::$zip->getStatusString(), OC_Log::ERROR);
         return false;
     } else {
         return true;
     }
 }
Beispiel #4
0
 *
 */
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
OCP\App::checkAppEnabled('user_migrate');
// Which operation
if ($_GET['operation'] == 'create') {
    $uid = !empty($_POST['uid']) ? $_POST['uid'] : OCP\USER::getUser();
    if ($uid != OCP\USER::getUser()) {
        // Needs to be admin to export someone elses account
        OCP\JSON::error();
        die;
    }
    // Create the export zip
    $response = json_decode(OC_Migrate::export($uid));
    if (!$response->success) {
        // Error
        OCP\JSON::error();
        die;
    } else {
        // Save path in session
        $_SESSION['ocuserexportpath'] = $response->data;
    }
    OCP\JSON::success();
    die;
} else {
    if ($_GET['operation'] == 'download') {
        // Download the export
        $path = isset($_SESSION['ocuserexportpath']) ? $_SESSION['ocuserexportpath'] : false;
        if (!$path) {
 OCP\JSON::callCheck();
 $root = OC::$SERVERROOT . "/";
 $importname = "owncloud_import_" . date("y-m-d_H-i-s");
 // Save data dir for later
 $datadir = OCP\Config::getSystemValue('datadirectory');
 // Copy the uploaded file
 $from = $_FILES['owncloud_import']['tmp_name'];
 $to = get_temp_dir() . '/' . $importname . '.zip';
 if (!move_uploaded_file($from, $to)) {
     $error = array('error' => 'Failed to move the uploaded file', 'hint' => 'Try checking the permissions of the ' . get_temp_dir() . ' dir.');
     OCP\Util::writeLog('user_migrate', "Failed to copy the uploaded file", OCP\Util::ERROR);
     $tmpl = new OCP\Template('user_migrate', 'settings');
     $tmpl->assign('error', $error);
     return $tmpl->fetchPage();
 }
 $response = json_decode(OC_Migrate::import($to, 'user'));
 if (!$response->success) {
     $error = array('error' => 'There was an error while importing the user!', 'hint' => 'Please check the logs for a more detailed explaination');
     $tmpl = new OCP\Template('user_migrate', 'settings');
     $tmpl->assign('error', $error);
     return $tmpl->fetchPage();
 } else {
     // Check import status
     if (!is_null($response->data)) {
         foreach ($response->data as $app => $status) {
             if ($status != 'true') {
                 // It failed for some reason
                 if ($status == 'notsupported') {
                     $notsupported[] = $app;
                 } else {
                     if (!$status) {
 public function __construct($appid)
 {
     // Set the id
     $this->id = $appid;
     OC_Migrate::registerProvider($this);
 }