added app for admins to create a zipfile containing the owncloud data

This commit is contained in:
Thomas Schmidt 2011-09-29 17:11:07 +02:00
parent 516517dc3c
commit 84e209f1e0
4 changed files with 150 additions and 0 deletions

View file

@ -0,0 +1,33 @@
<?php
/**
* ownCloud - user_ldap
*
* @author Dominik Schmidt
* @copyright 2011 Dominik Schmidt dev@dominik-schmidt.de
*
* 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/>.
*
*/
OC_APP::registerAdmin('admin_export','settings');
// add settings page to navigation
$entry = array(
'id' => "admin_export_settings",
'order'=>1,
'href' => OC_Helper::linkTo( "admin_export", "settings.php" ),
'name' => 'Export'
);

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<info>
<id>admin_export</id>
<name>Import/Export</name>
<description>Import/Export your owncloud data</description>
<version>0.1</version>
<licence>AGPL</licence>
<author>Thomas Schmidt</author>
<require>2</require>
</info>

View file

@ -0,0 +1,94 @@
<?php
/**
* ownCloud - admin export
*
* @author Thomas Schmidt
* @copyright 2011 Thomas Schmidt tom@opensuse.org
*
* 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/>.
*
*/
if (isset($_POST['admin_export'])) {
$root = OC::$SERVERROOT . "/";
$zip = new ZipArchive();
$filename = sys_get_temp_dir() . "/owncloud_export_" . date("y-m-d_H-i-s") . ".zip";
error_log("Creating export file at: " . $filename);
if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
exit("Cannot open <$filename>\n");
}
if (isset($_POST['owncloud_system'])) {
// adding owncloud system files
error_log("Adding owncloud system files to export");
zipAddDir($root, $zip, false);
foreach (array(".git", "3rdparty", "apps", "core", "files", "l10n", "lib", "ocs", "search", "settings", "tests") as $dirname) {
zipAddDir($root . $dirname, $zip, true, basename($root) . "/");
}
}
if (isset($_POST['owncloud_config'])) {
// adding owncloud config
// todo: add database export
error_log("Adding owncloud config to export");
zipAddDir($root . "config/", $zip, true, basename($root) . "/");
$zip->addFile($root . '/data/.htaccess', basename($root) . "/data/owncloud.db");
}
if (isset($_POST['user_files'])) {
// adding user files
$zip->addFile($root . '/data/.htaccess', basename($root) . "/data/.htaccess");
$zip->addFile($root . '/data/index.html', basename($root) . "/data/index.html");
foreach (OC_User::getUsers() as $i) {
error_log("Adding owncloud user files of $i to export");
zipAddDir($root . "data/" . $i, $zip, true, basename($root) . "/data/");
}
}
$zip->close();
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=" . basename($filename));
header("Content-Length: " . filesize($filename));
ob_end_clean();
readfile($filename);
unlink($filename);
} else {
// fill template
$tmpl = new OC_Template('admin_export', 'settings');
return $tmpl->fetchPage();
}
function zipAddDir($dir, $zip, $recursive=true, $internalDir='') {
$dirname = basename($dir);
$zip->addEmptyDir($internalDir . $dirname);
$internalDir.=$dirname.='/';
if ($dirhandle = opendir($dir)) {
while (false !== ( $file = readdir($dirhandle))) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($dir . '/' . $file) && $recursive) {
zipAddDir($dir . '/' . $file, $zip, $recursive, $internalDir);
} elseif (is_file($dir . '/' . $file)) {
$zip->addFile($dir . '/' . $file, $internalDir . $file);
}
}
}
closedir($dirhandle);
} else {
error_log("Was not able to open directory: " . $dir);
}
}

View file

@ -0,0 +1,13 @@
<form id="export" action="#" method="post">
<fieldset class="personalblock">
<legend><strong>Export this ownCloud instance</strong></legend>
<p>This will create a compressed file that contains the data of this owncloud instance.
Please choose which components should be included:
</p>
<p><input type="checkbox" id="user_files" name="user_files" value="true"><label for="user_files">User files</label><br/>
<input type="checkbox" id="owncloud_system" name="owncloud_system" value="true"><label for="owncloud_system">ownCloud system files</label><br/>
<input type="checkbox" id="owncloud_config" name="owncloud_config" value="true"><label for="owncloud_config">ownCloud configuration</label>
</p>
<input type="submit" name="admin_export" value="Export" />
</fieldset>
</form>