external.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. OCP\JSON::callCheck();
  9. OCP\JSON::checkLoggedIn();
  10. OCP\JSON::checkAppEnabled('files_sharing');
  11. $l = \OC::$server->getL10N('files_sharing');
  12. // check if server admin allows to mount public links from other servers
  13. if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) {
  14. \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server'))));
  15. exit();
  16. }
  17. $token = $_POST['token'];
  18. $remote = $_POST['remote'];
  19. $owner = $_POST['owner'];
  20. $name = $_POST['name'];
  21. $password = $_POST['password'];
  22. // Check for invalid name
  23. if(!\OCP\Util::isValidFileName($name)) {
  24. \OCP\JSON::error(array('data' => array('message' => $l->t('The mountpoint name contains invalid characters.'))));
  25. exit();
  26. }
  27. $externalManager = new \OCA\Files_Sharing\External\Manager(
  28. \OC::$server->getDatabaseConnection(),
  29. \OC\Files\Filesystem::getMountManager(),
  30. \OC\Files\Filesystem::getLoader(),
  31. \OC::$server->getUserSession()
  32. );
  33. $name = OCP\Files::buildNotExistingFileName('/', $name);
  34. // check for ssl cert
  35. if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) {
  36. \OCP\JSON::error(array('data' => array('message' => $l->t("Invalid or untrusted SSL certificate"))));
  37. exit;
  38. } else {
  39. $mount = $externalManager->addShare($remote, $token, $password, $name, $owner);
  40. /**
  41. * @var \OCA\Files_Sharing\External\Storage $storage
  42. */
  43. $storage = $mount->getStorage();
  44. $result = $storage->file_exists('');
  45. if ($result) {
  46. $storage->getScanner()->scanAll();
  47. \OCP\JSON::success();
  48. } else {
  49. $externalManager->removeShare($mount->getMountPoint());
  50. \OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't add remote share"))));
  51. }
  52. }