aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/ajax')
-rw-r--r--apps/files_sharing/ajax/external.php51
-rw-r--r--apps/files_sharing/ajax/shareinfo.php69
-rw-r--r--apps/files_sharing/ajax/testremote.php29
3 files changed, 149 insertions, 0 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php
new file mode 100644
index 00000000000..52c84b7babb
--- /dev/null
+++ b/apps/files_sharing/ajax/external.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+OCP\JSON::callCheck();
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('files_sharing');
+
+$l = OC_L10N::get('files_sharing');
+
+// check if server admin allows to mount public links from other servers
+// check if files_external is enabled
+// FIXME file_external check no longer needed if we use the webdav implementation from core
+if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false ||
+ \OC_App::isEnabled('files_external') === false) {
+ \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server'))));
+ exit();
+}
+
+$token = $_POST['token'];
+$remote = $_POST['remote'];
+$owner = $_POST['owner'];
+$name = $_POST['name'];
+$password = $_POST['password'];
+
+$externalManager = new \OCA\Files_Sharing\External\Manager(
+ \OC::$server->getDatabaseConnection(),
+ \OC\Files\Filesystem::getMountManager(),
+ \OC\Files\Filesystem::getLoader(),
+ \OC::$server->getUserSession()
+);
+
+$name = OCP\Files::buildNotExistingFileName('/', $name);
+
+$mount = $externalManager->addShare($remote, $token, $password, $name, $owner);
+/**
+ * @var \OCA\Files_Sharing\External\Storage $storage
+ */
+$storage = $mount->getStorage();
+$result = $storage->file_exists('');
+if($result){
+ $storage->getScanner()->scanAll();
+ \OCP\JSON::success();
+} else {
+ $externalManager->removeShare($mount->getMountPoint());
+ \OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't add remote share"))));
+}
diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php
new file mode 100644
index 00000000000..e87b0779e8d
--- /dev/null
+++ b/apps/files_sharing/ajax/shareinfo.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+OCP\JSON::checkAppEnabled('files_sharing');
+
+if (!isset($_GET['t'])) {
+ \OC_Response::setStatus(400); //400 Bad Request
+ exit;
+}
+
+$token = $_GET['t'];
+
+$password = null;
+if (isset($_POST['password'])) {
+ $password = $_POST['password'];
+}
+
+$relativePath = null;
+if (isset($_GET['dir'])) {
+ $relativePath = $_GET['dir'];
+}
+
+$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password);
+
+$linkItem = $data['linkItem'];
+// Load the files
+$path = $data['realPath'];
+
+$isWritable = $linkItem['permissions'] & (\OCP\PERMISSION_UPDATE | \OCP\PERMISSION_CREATE);
+if (!$isWritable) {
+ \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
+ return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
+ });
+}
+
+$rootInfo = \OC\Files\Filesystem::getFileInfo($path);
+$rootView = new \OC\Files\View('');
+
+/**
+ * @param \OCP\Files\FileInfo $dir
+ * @param \OC\Files\View $view
+ * @return array
+ */
+function getChildInfo($dir, $view) {
+ $children = $view->getDirectoryContent($dir->getPath());
+ $result = array();
+ foreach ($children as $child) {
+ $formated = \OCA\Files\Helper::formatFileInfo($child);
+ if ($child->getType() === 'dir') {
+ $formated['children'] = getChildInfo($child, $view);
+ }
+ $formated['mtime'] = $formated['mtime'] / 1000;
+ $result[] = $formated;
+ }
+ return $result;
+}
+
+$result = \OCA\Files\Helper::formatFileInfo($rootInfo);
+$result['mtime'] = $result['mtime'] / 1000;
+if ($rootInfo->getType() === 'dir') {
+ $result['children'] = getChildInfo($rootInfo, $rootView);
+}
+
+OCP\JSON::success(array('data' => $result));
diff --git a/apps/files_sharing/ajax/testremote.php b/apps/files_sharing/ajax/testremote.php
new file mode 100644
index 00000000000..89581794698
--- /dev/null
+++ b/apps/files_sharing/ajax/testremote.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+OCP\JSON::checkAppEnabled('files_sharing');
+
+$remote = $_GET['remote'];
+
+function testUrl($url) {
+ try {
+ $result = file_get_contents($url);
+ $data = json_decode($result);
+ return is_object($data) and !empty($data->version);
+ } catch (Exception $e) {
+ return false;
+ }
+}
+
+if (testUrl('https://' . $remote . '/status.php')) {
+ echo 'https';
+} elseif (testUrl('http://' . $remote . '/status.php')) {
+ echo 'http';
+} else {
+ echo 'false';
+}