diff --git a/apps/user_migrate/ajax/export.php b/apps/user_migrate/ajax/export.php new file mode 100644 index 0000000000000000000000000000000000000000..ef947c610f2db6143fa530f3aace8691f6cebadd --- /dev/null +++ b/apps/user_migrate/ajax/export.php @@ -0,0 +1,63 @@ +<?php + +/** + * ownCloud - user_migrate + * + * @author Tom Needham + * @copyright 2012 Tom Needham tom@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ +// Init owncloud +require_once('../../../lib/base.php'); + +// Check if we are a user +OC_JSON::checkLoggedIn(); +OC_Util::checkAppEnabled('user_migrate'); + OC_JSON::error(); + die(); +// Which operation +if( $_GET['operation']=='create' ){ +$uid = !empty( $_POST['uid'] ) ? $_POST['uid'] : OC_User::getUser(); +if( $uid != OC_User::getUser() ){ + // Needs to be admin to export someone elses account + OC_JSON::error(); + die(); +} +// Create the export zip +if( !$path = OC_Migrate::export( $uid ) ){ + // Error + OC_JSON::error(); + die(); +} else { + // Save path in session + $_SESSION['ocuserexportpath'] = $path; +} +OC_JSON::success(); +die(); +} else if( $_GET['operation']=='download' ){ + // Download the export + $path = isset( $_SESSION['ocuserexportpath'] ) ? $_SESSION['ocuserexportpath'] : false; + if( !$path ){ + die(); + } + header("Content-Type: application/zip"); + header("Content-Disposition: attachment; filename=" . basename($path)); + header("Content-Length: " . filesize($path)); + @ob_end_clean(); + readfile($path); + unlink( $path ); + $_SESSION['ocuserexportpath'] = ''; +} diff --git a/apps/user_migrate/appinfo/app.php b/apps/user_migrate/appinfo/app.php index 18ea8f52b2acda4e36c5fb484d4a856ece09534c..a59b6dd705c3640ea82e36193a230d4e931b54a4 100644 --- a/apps/user_migrate/appinfo/app.php +++ b/apps/user_migrate/appinfo/app.php @@ -23,6 +23,7 @@ OC_APP::registerPersonal( 'user_migrate', 'settings' ); OC_APP::registerAdmin( 'user_migrate', 'admin' ); +OC_Util::addScript( 'user_migrate', 'export'); // add settings page to navigation $entry = array( diff --git a/apps/user_migrate/js/export.js b/apps/user_migrate/js/export.js new file mode 100644 index 0000000000000000000000000000000000000000..0e1e396f65dfb50e842980c12476de6f21b19782 --- /dev/null +++ b/apps/user_migrate/js/export.js @@ -0,0 +1,27 @@ +$(document).ready(function(){ + // Do the export + $('#exportbtn').click(function(){ + // Show loader + $('.loading').show(); + $.getJSON( + OC.filePath('user_migrate','ajax','export.php'), + {operation:'create'}, + function(result){ + if(result.status == 'success'){ + // Download the file + window.location = OC.filePath('user_migrate','ajax','export.php?operation=download') ; + $('.loading').hide(); + $('#exportbtn').val(t('user_migrate', 'Export')); + } else { + // Cancel loading + $('#exportbtn').html('Failed'); + // Show Dialog + OC.dialogs.alert(t('user_migrate', 'Something went wrong while the export file was being generated'), t('user_migrate', 'An error has occurred'), function(){ + $('#exportbtn').html(t('user_migrate', 'Export')+'<img style="display: none;" class="loading" src="'+OC.filePath('core','img','loading.git')+'" />'); + }); + } + } + // End ajax + ); + }); +}); \ No newline at end of file diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php index 38eee990b46fd05d68d6baf9e2cd833b53b756d6..62f347b3557933540f17eea853a8f723991ad685 100644 --- a/apps/user_migrate/settings.php +++ b/apps/user_migrate/settings.php @@ -24,22 +24,6 @@ */ OC_Util::checkAppEnabled('user_migrate'); -if (isset($_POST['user_export'])) { - // Create the export zip - if( !$path = OC_Migrate::export() ){ - // Error - die('error'); - } else { - // 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 ); - } -} else { - // fill template - $tmpl = new OC_Template('user_migrate', 'settings'); - return $tmpl->fetchPage(); -} \ No newline at end of file +// fill template +$tmpl = new OC_Template('user_migrate', 'settings'); +return $tmpl->fetchPage(); \ No newline at end of file diff --git a/apps/user_migrate/templates/settings.php b/apps/user_migrate/templates/settings.php index 389de563a6fc5258bb4155614d386fbcb9c04a64..5f4857de5fa4a518605514a2045d0554a4027f1c 100644 --- a/apps/user_migrate/templates/settings.php +++ b/apps/user_migrate/templates/settings.php @@ -1,8 +1,6 @@ -<form id="export" action="#" method="post"> - <fieldset class="personalblock"> - <legend><strong><?php echo $l->t('Export your user account');?></strong></legend> - <p><?php echo $l->t('This will create a compressed file that contains your ownCloud account.');?> - </p> - <input type="submit" name="user_export" value="Export" /> - </fieldset> -</form> \ No newline at end of file +<fieldset class="personalblock"> + <legend><strong><?php echo $l->t('Export your user account');?></strong></legend> + <p><?php echo $l->t('This will create a compressed file that contains your ownCloud account.');?> + </p> + <button id="exportbtn">Export<img style="display: none;" class="loading" src="<?php echo OC_Helper::linkTo('core', 'img/loading.gif'); ?>" /></button> +</fieldset> diff --git a/lib/migrate.php b/lib/migrate.php index fe5ac45600557620fba6064b97145a91f5687cbd..db3852fb8323d24a4e7cdf7d4e587cfe53ec9e76 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -73,12 +73,12 @@ class OC_Migrate{ /** * @breif exports a user, or owncloud instance + * @param optional $uid string user id of user to export if export type is user, defaults to current * @param ootional $type string type of export, defualts to user * @param otional $path string path to zip output folder - * @param optional $uid string user id of user to export if export type is user, defaults to current * @return false on error, path to zip on success */ - public static function export( $type='user', $path=null, $uid=null ){ + public static function export( $uid=null, $type='user', $path=null ){ $datadir = OC_Config::getValue( 'datadirectory' ); // Validate export type $types = array( 'user', 'instance', 'system', 'userfiles' );