summaryrefslogtreecommitdiffstats
path: root/apps/admin_export
diff options
context:
space:
mode:
authorThomas Schmidt <tschmidt@suse.de>2011-09-29 17:11:07 +0200
committerThomas Schmidt <tschmidt@suse.de>2011-09-29 17:11:07 +0200
commit84e209f1e09cdbb39847e49f25807cf94623bd1a (patch)
tree63de65525d612d0f2707f1967e9a37a8295388d7 /apps/admin_export
parent516517dc3c113f79614cdd2759bcf83d6a54de74 (diff)
downloadnextcloud-server-84e209f1e09cdbb39847e49f25807cf94623bd1a.tar.gz
nextcloud-server-84e209f1e09cdbb39847e49f25807cf94623bd1a.zip
added app for admins to create a zipfile containing the owncloud data
Diffstat (limited to 'apps/admin_export')
-rw-r--r--apps/admin_export/appinfo/app.php33
-rw-r--r--apps/admin_export/appinfo/info.xml10
-rw-r--r--apps/admin_export/settings.php94
-rw-r--r--apps/admin_export/templates/settings.php13
4 files changed, 150 insertions, 0 deletions
diff --git a/apps/admin_export/appinfo/app.php b/apps/admin_export/appinfo/app.php
new file mode 100644
index 00000000000..beebb4864e9
--- /dev/null
+++ b/apps/admin_export/appinfo/app.php
@@ -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'
+);
diff --git a/apps/admin_export/appinfo/info.xml b/apps/admin_export/appinfo/info.xml
new file mode 100644
index 00000000000..c4a2a9b398c
--- /dev/null
+++ b/apps/admin_export/appinfo/info.xml
@@ -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>
diff --git a/apps/admin_export/settings.php b/apps/admin_export/settings.php
new file mode 100644
index 00000000000..2d1bc66a296
--- /dev/null
+++ b/apps/admin_export/settings.php
@@ -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);
+ }
+} \ No newline at end of file
diff --git a/apps/admin_export/templates/settings.php b/apps/admin_export/templates/settings.php
new file mode 100644
index 00000000000..a65b17ce26f
--- /dev/null
+++ b/apps/admin_export/templates/settings.php
@@ -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>