diff options
author | Frank Karlitschek <frank@owncloud.org> | 2012-08-26 17:30:07 +0200 |
---|---|---|
committer | Frank Karlitschek <frank@owncloud.org> | 2012-08-26 17:30:07 +0200 |
commit | 72e9a2ce57ee88503db83614cec5ccda71f0b58e (patch) | |
tree | 8bc301ca22d9ca08ea54426bcb61f62bd1c1cb75 /apps/remoteStorage | |
parent | 32bad688bdb4fea55eba9d4255fc55f1c60a0aca (diff) | |
download | nextcloud-server-72e9a2ce57ee88503db83614cec5ccda71f0b58e.tar.gz nextcloud-server-72e9a2ce57ee88503db83614cec5ccda71f0b58e.zip |
moved to apps repository
Diffstat (limited to 'apps/remoteStorage')
-rw-r--r-- | apps/remoteStorage/BearerAuth.php | 61 | ||||
-rw-r--r-- | apps/remoteStorage/ajax/revokeToken.php | 35 | ||||
-rw-r--r-- | apps/remoteStorage/appinfo/app.php | 2 | ||||
-rw-r--r-- | apps/remoteStorage/appinfo/database.xml | 52 | ||||
-rw-r--r-- | apps/remoteStorage/appinfo/info.xml | 13 | ||||
-rw-r--r-- | apps/remoteStorage/appinfo/version | 1 | ||||
-rw-r--r-- | apps/remoteStorage/appinfo/webfinger.php | 8 | ||||
-rw-r--r-- | apps/remoteStorage/auth.php | 79 | ||||
-rw-r--r-- | apps/remoteStorage/img/remoteStorage.png | bin | 1024 -> 0 bytes | |||
-rw-r--r-- | apps/remoteStorage/lib_remoteStorage.php | 68 | ||||
-rw-r--r-- | apps/remoteStorage/oauth_ro_auth.php | 70 | ||||
-rw-r--r-- | apps/remoteStorage/settings.php | 6 | ||||
-rw-r--r-- | apps/remoteStorage/templates/auth.php | 28 | ||||
-rw-r--r-- | apps/remoteStorage/templates/settings.php | 22 | ||||
-rw-r--r-- | apps/remoteStorage/webdav.php | 87 |
15 files changed, 0 insertions, 532 deletions
diff --git a/apps/remoteStorage/BearerAuth.php b/apps/remoteStorage/BearerAuth.php deleted file mode 100644 index ebcf189dfb9..00000000000 --- a/apps/remoteStorage/BearerAuth.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -/** - * HTTP Bearer Authentication handler - * - * Use this class for easy http authentication setup - * - * @package Sabre - * @subpackage HTTP - * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. - * @author Evert Pot (http://www.rooftopsolutions.nl/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License - */ -class Sabre_HTTP_BearerAuth extends Sabre_HTTP_AbstractAuth { - - /** - * Returns the supplied username and password. - * - * The returned array has two values: - * * 0 - username - * * 1 - password - * - * If nothing was supplied, 'false' will be returned - * - * @return mixed - */ - public function getUserPass() { - - // Apache and mod_php - if (($user = $this->httpRequest->getRawServerValue('PHP_AUTH_USER')) && ($pass = $this->httpRequest->getRawServerValue('PHP_AUTH_PW'))) { - - return array($user,$pass); - - } - - // Most other webservers - $auth = $this->httpRequest->getHeader('Authorization'); - - if (!$auth) return false; - - if (strpos(strtolower($auth),'bearer')!==0) return false; - - return explode(':', base64_decode(substr($auth, 7))); - - } - - /** - * Returns an HTTP 401 header, forcing login - * - * This should be called when username and password are incorrect, or not supplied at all - * - * @return void - */ - public function requireLogin() { - - $this->httpResponse->setHeader('WWW-Authenticate','Basic realm="' . $this->realm . '"'); - $this->httpResponse->sendStatus(401); - - } - -} diff --git a/apps/remoteStorage/ajax/revokeToken.php b/apps/remoteStorage/ajax/revokeToken.php deleted file mode 100644 index e6a68189945..00000000000 --- a/apps/remoteStorage/ajax/revokeToken.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -/** -* ownCloud -* -* Original: -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* Adapted: -* @author Michiel de Jong, 2012 -* -* 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/>. -* -*/ - -OCP\App::checkAppEnabled('remoteStorage'); -require_once('remoteStorage/lib_remoteStorage.php'); - -ini_set('default_charset', 'UTF-8'); -#ini_set('error_reporting', ''); -@ob_clean(); - -echo OC_remoteStorage::deleteToken(file_get_contents("php://input")); diff --git a/apps/remoteStorage/appinfo/app.php b/apps/remoteStorage/appinfo/app.php deleted file mode 100644 index c278fd73056..00000000000 --- a/apps/remoteStorage/appinfo/app.php +++ /dev/null @@ -1,2 +0,0 @@ -<?php -OCP\App::registerPersonal('remoteStorage','settings'); diff --git a/apps/remoteStorage/appinfo/database.xml b/apps/remoteStorage/appinfo/database.xml deleted file mode 100644 index d48f9f747b1..00000000000 --- a/apps/remoteStorage/appinfo/database.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> -<database> - <name>*dbname*</name> - <create>true</create> - <overwrite>false</overwrite> - <charset>utf8</charset> - <table> - <name>*dbprefix*authtoken</name> - <declaration> - <field> - <name>token</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>40</length> - </field> - <field> - <name>appUrl</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>128</length> - </field> - <field> - <name>user</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>64</length> - </field> - <field> - <name>category</name> - <type>text</type> - <default></default> - <notnull>true</notnull> - <length>64</length> - </field> - <index> - <name>a_app_remotestorage_user</name> - <unique>true</unique> - <field> - <name>user</name> - <sorting>ascending</sorting> - </field> - <field> - <name>token</name> - <sorting>ascending</sorting> - </field> - </index> - </declaration> - </table> -</database> diff --git a/apps/remoteStorage/appinfo/info.xml b/apps/remoteStorage/appinfo/info.xml deleted file mode 100644 index 1388ad9c316..00000000000 --- a/apps/remoteStorage/appinfo/info.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0"?> -<info> - <id>remoteStorage</id> - <name>remoteStorage compatibility</name> - <description>Enables you to use ownCloud as their remote storage for unhosted applications. This app requires the Webfinger app to be installed and enabled correctly. More info on <a href="http://unhosted.org">the website of the unhosted movement</a>.</description> - <licence>AGPL or MIT</licence> - <author>Michiel de Jong</author> - <require>4</require> - <shipped>true</shipped> - <remote> - <remoteStorage>webdav.php</remoteStorage> - </remote> -</info> diff --git a/apps/remoteStorage/appinfo/version b/apps/remoteStorage/appinfo/version deleted file mode 100644 index 0e2c93950bb..00000000000 --- a/apps/remoteStorage/appinfo/version +++ /dev/null @@ -1 +0,0 @@ -0.7
\ No newline at end of file diff --git a/apps/remoteStorage/appinfo/webfinger.php b/apps/remoteStorage/appinfo/webfinger.php deleted file mode 100644 index e8b237628c4..00000000000 --- a/apps/remoteStorage/appinfo/webfinger.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php if(OC_User::userExists(WF_USER)): ?> - { - "rel":"remoteStorage", - "template":"<?php echo WF_BASEURL; ?>/remote.php/remoteStorage/<?php echo WF_USER; ?>/remoteStorage/{category}/", - "api":"WebDAV", - "auth":"<?php echo WF_BASEURL; ?>/?app=remoteStorage&getfile=auth.php&userid=<?php echo WF_USER; ?>" - } -<?php endif ?> diff --git a/apps/remoteStorage/auth.php b/apps/remoteStorage/auth.php deleted file mode 100644 index 91ca43ea076..00000000000 --- a/apps/remoteStorage/auth.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -/** -* ownCloud -* -* Original: -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* Adapted: -* @author Michiel de Jong, 2012 -* -* 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/>. -* -*/ - -header("X-Frame-Options: Sameorigin"); - -OCP\App::checkAppEnabled('remoteStorage'); -require_once('Sabre/autoload.php'); -require_once('lib_remoteStorage.php'); -require_once('oauth_ro_auth.php'); - -ini_set('default_charset', 'UTF-8'); -#ini_set('error_reporting', ''); -@ob_clean(); - -foreach($_GET as $k => $v) { - if($k=='userid'){ - $userId=$v; - } else if($k=='redirect_uri'){ - $appUrlParts=explode('/', $v); - $appUrl = htmlentities($appUrlParts[2]);//TODO: check if this is equal to client_id - } else if($k=='scope'){ - $categories=htmlentities($v); - } -} -$currUser = OCP\USER::getUser(); -if($userId && $appUrl && $categories) { - if($currUser == $userId) { - if(isset($_POST['allow'])) { - //TODO: check if this can be faked by editing the cookie in firebug! - $token=OC_remoteStorage::createCategories($appUrl, $categories); - header('Location: '.$_GET['redirect_uri'].'#access_token='.$token.'&token_type=bearer'); - } else if($existingToken = OC_remoteStorage::getTokenFor($appUrl, $categories)) { - header('Location: '.$_GET['redirect_uri'].'#access_token='.$existingToken.'&token_type=bearer'); - } else { - //params ok, logged in ok, but need to click Allow still: - $appUrlParts = explode('/', $_GET['redirect_uri']); - $host = $appUrlParts[2]; - $categories = explode(',', $_GET['scope']); - OCP\Util::addStyle('', 'auth'); - OCP\Template::printGuestPage('remoteStorage', 'auth', array( - 'host' => $host, - 'categories' => $categories, - )); - }//end 'need to click Allow still' - } else {//login not ok - if($currUser) { - die('You are logged in as '.$currUser.' instead of '.htmlentities($userId)); - } else { - // this will display the login page for us - OCP\Util::checkLoggedIn(); - } - } -} else {//params not ok - die('please use e.g. '.OCP\Util::linkTo('remoteStorage', 'auth.php').'?userid=admin&redirect_uri=http://host/path&scope=...'); -} diff --git a/apps/remoteStorage/img/remoteStorage.png b/apps/remoteStorage/img/remoteStorage.png Binary files differdeleted file mode 100644 index 10c2be243c2..00000000000 --- a/apps/remoteStorage/img/remoteStorage.png +++ /dev/null diff --git a/apps/remoteStorage/lib_remoteStorage.php b/apps/remoteStorage/lib_remoteStorage.php deleted file mode 100644 index b9e23680037..00000000000 --- a/apps/remoteStorage/lib_remoteStorage.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -class OC_remoteStorage { - public static function getValidTokens($ownCloudUser, $category) { - $stmt=OCP\DB::prepare("SELECT `token`,`appUrl`,`category` FROM `*PREFIX*authtoken` WHERE `user`=?",100); - $result=$stmt->execute(array($ownCloudUser)); - $ret = array(); - while($row=$result->fetchRow()){ - if(in_array($category, explode(',', $row['category']))) { - $ret[$row['token']]=true; - } - } - return $ret; - } - - public static function getTokenFor($appUrl, $categories) { - $user=OCP\USER::getUser(); - $stmt=OCP\DB::prepare("SELECT `token` FROM `*PREFIX*authtoken` WHERE `user`=? AND `appUrl`=? AND `category`=?",1); - $result=$stmt->execute(array($user, $appUrl, $categories)); - if($row=$result->fetchRow()) { - return base64_encode('remoteStorage:'.$row['token']); - } else { - return false; - } - } - - public static function getAllTokens() { - $user=OCP\USER::getUser(); - $stmt=OCP\DB::prepare("SELECT `token`,`appUrl`,`category` FROM `*PREFIX*authtoken` WHERE `user`=?",100); - $result=$stmt->execute(array($user)); - $ret = array(); - while($row=$result->fetchRow()){ - $ret[$row['token']] = array( - 'appUrl' => $row['appUrl'], - 'categories' => $row['category'], - ); - } - return $ret; - } - - public static function deleteToken($token) { - $user=OCP\USER::getUser(); - $stmt=OCP\DB::prepare("DELETE FROM `*PREFIX*authtoken` WHERE `token`=? AND `user`=?"); - $stmt->execute(array($token,$user)); - return 'unknown';//how can we see if any rows were affected? - } - private static function addToken($token, $appUrl, $categories){ - $user=OCP\USER::getUser(); - $stmt=OCP\DB::prepare("INSERT INTO `*PREFIX*authtoken` (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)"); - $stmt->execute(array($token,$appUrl,$user,$categories)); - } - public static function createCategories($appUrl, $categories) { - $token=uniqid(); - OC_Util::setupFS(OCP\USER::getUser()); - self::addToken($token, $appUrl, $categories); - foreach(explode(',', $categories) as $category) { - //TODO: input checking on $category - $scopePathParts = array('remoteStorage', $category); - for($i=0;$i<=count($scopePathParts);$i++){ - $thisPath = '/'.implode('/', array_slice($scopePathParts, 0, $i)); - if(!OC_Filesystem::file_exists($thisPath)) { - OC_Filesystem::mkdir($thisPath); - } - } - } - return base64_encode('remoteStorage:'.$token); - } -} diff --git a/apps/remoteStorage/oauth_ro_auth.php b/apps/remoteStorage/oauth_ro_auth.php deleted file mode 100644 index bed3093c3b3..00000000000 --- a/apps/remoteStorage/oauth_ro_auth.php +++ /dev/null @@ -1,70 +0,0 @@ -<?php -/** - * Copyright (c) 2011, 2012 Michiel de Jong <michiel@unhosted.org> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - - -class OC_Connector_Sabre_Auth_ro_oauth extends Sabre_DAV_Auth_Backend_AbstractBasic { - private $validTokens; - private $category; - public function __construct($validTokensArg, $categoryArg) { - $this->validTokens = $validTokensArg; - $this->category = $categoryArg; - } - - /** - * Validates a username and password - * - * This method should return true or false depending on if login - * succeeded. - * - * @return bool - */ - protected function validateUserPass($username, $password){ - //always give read-only: - if(($_SERVER['REQUEST_METHOD'] == 'OPTIONS') - || (isset($this->validTokens[$password])) - || (($_SERVER['REQUEST_METHOD'] == 'GET') && ($this->category == 'public')) - ) { - OC_Util::setUpFS(); - return true; - } else { - //var_export($_SERVER); - //var_export($this->validTokens); - //die('not getting in with "'.$username.'"/"'.$password.'"!'); - return false; - } - } - - //overwriting this to make it not automatically fail if no auth header is found: - public function authenticate(Sabre_DAV_Server $server,$realm) { - $auth = new Sabre_HTTP_BearerAuth(); - $auth->setHTTPRequest($server->httpRequest); - $auth->setHTTPResponse($server->httpResponse); - $auth->setRealm($realm); - $userpass = $auth->getUserPass(); - if (!$userpass) { - if(($_SERVER['REQUEST_METHOD'] == 'OPTIONS') - ||(($_SERVER['REQUEST_METHOD'] == 'GET') && ($this->category == 'public')) - ) { - $userpass = array('', ''); - } else { - $auth->requireLogin(); - throw new Sabre_DAV_Exception_NotAuthenticated('No basic authentication headers were found'); - } - } - - // Authenticates the user - if (!$this->validateUserPass($userpass[0],$userpass[1])) { - $auth->requireLogin(); - throw new Sabre_DAV_Exception_NotAuthenticated('Username or password does not match'); - } - $this->currentUser = $userpass[0]; - return true; - } - -} - diff --git a/apps/remoteStorage/settings.php b/apps/remoteStorage/settings.php deleted file mode 100644 index 3be8b0984d8..00000000000 --- a/apps/remoteStorage/settings.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -require_once('lib_remoteStorage.php'); -$tmpl = new OCP\Template( 'remoteStorage', 'settings'); - -return $tmpl->fetchPage(); diff --git a/apps/remoteStorage/templates/auth.php b/apps/remoteStorage/templates/auth.php deleted file mode 100644 index 6a7054eabb0..00000000000 --- a/apps/remoteStorage/templates/auth.php +++ /dev/null @@ -1,28 +0,0 @@ - <section id="main"> - <div id="oauth"> - <h2><img src="<?php echo image_path('', 'remoteStorage-big.png'); ?>" alt="remoteStorage" /></h2> - <p><strong><?php echo $_['host'] ?></strong> - requests read & write access to your - <?php - $categories = $_['categories']; - if(!count($categories)) { - echo $categories[0]; - } else { - echo '<em>'.$categories[0].'</em>'; - if(count($categories)==2) { - echo ' and <em>'.$categories[1].'</em>'; - } else if(count($categories)>2) { - for($i=1; $i<count($categories)-1; $i++) { - echo ', <em>'.$categories[$i].'</em>'; - } - echo ', and <em>'.$categories[$i].'</em>'; - } - } - ?>. - </p> - <form accept-charset="UTF-8" method="post"> - <input id="allow-auth" name="allow" type="submit" value="Allow" /> - <input id="deny-auth" name="deny" type="submit" value="Deny" /> - </form> - </div> - </section> diff --git a/apps/remoteStorage/templates/settings.php b/apps/remoteStorage/templates/settings.php deleted file mode 100644 index 1d2a188f527..00000000000 --- a/apps/remoteStorage/templates/settings.php +++ /dev/null @@ -1,22 +0,0 @@ - <fieldset class="personalblock"> - <img src="<?php echo image_path('remoteStorage', 'remoteStorage.png') ?>" style="width:16px"> - <strong><?php echo $l->t('remoteStorage') ?></strong> user address: <?php echo OCP\USER::getUser().'@'.$_SERVER['SERVER_NAME'] ?> (<a href="http://unhosted.org/">more info</a>) - <p><em>Apps that currently have access to your ownCloud:</em></p> - <script> - function revokeToken(token) { - var xhr = new XMLHttpRequest(); - xhr.open('POST', '/apps/remoteStorage/ajax/revokeToken.php', true); - xhr.send(token); - } - </script> - <ul> - <?php foreach(OC_remoteStorage::getAllTokens() as $token => $details) { ?> - <li onmouseover="$('#revoke_<?php echo $token ?>').show();" onmouseout="$('#revoke_<?php echo $token ?>').hide();"> - <strong><?php echo $details['appUrl'] ?></strong>: <?php echo $details['categories'] ?> - <a href="#" title="Revoke" class="action" style="display:none" id="revoke_<?php echo $token ?>" onclick="revokeToken('<?php echo $token ?>');$(this).hide();"> - <img src="<?php echo OCP\Util::imagePath('core', 'actions/delete.svg') ?>"> - </a> - </li> - <?php } ?> - </ul> - </fieldset> diff --git a/apps/remoteStorage/webdav.php b/apps/remoteStorage/webdav.php deleted file mode 100644 index 8d8ec6a45a1..00000000000 --- a/apps/remoteStorage/webdav.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -/** -* ownCloud -* -* Original: -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* Adapted: -* @author Michiel de Jong, 2011 -* -* 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::loadApps(array('filesystem','authentication')); - -OCP\App::checkAppEnabled('remoteStorage'); -require_once('lib_remoteStorage.php'); -require_once('BearerAuth.php'); -require_once('oauth_ro_auth.php'); - -ini_set('default_charset', 'UTF-8'); -#ini_set('error_reporting', ''); -@ob_clean(); - -//allow use as remote storage for other websites -if(isset($_SERVER['HTTP_ORIGIN'])) { - header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); - header('Access-Control-Max-Age: 3600'); - header('Access-Control-Allow-Methods: OPTIONS, GET, PUT, DELETE, PROPFIND'); - header('Access-Control-Allow-Headers: Authorization, Content-Type'); -} else { - header('Access-Control-Allow-Origin: *'); -} - -$path = substr($_SERVER["REQUEST_URI"], strlen($baseuri)); - -$pathParts = explode('/', $path); -// for webdav: -// 0 / 1 / 2... -// $ownCloudUser/remoteStorage/$category/ - -if(count($pathParts) >= 2) { - list($ownCloudUser, $dummy2, $category) = $pathParts; - - OC_Util::setupFS($ownCloudUser); - - // Create ownCloud Dir - $publicDir = new OC_Connector_Sabre_Directory(''); - $server = new Sabre_DAV_Server($publicDir); - - // Path to our script - $server->setBaseUri($baseuri.$ownCloudUser); - - // Auth backend - $authBackend = new OC_Connector_Sabre_Auth_ro_oauth( - OC_remoteStorage::getValidTokens($ownCloudUser, $category), - $category - ); - - $authPlugin = new Sabre_DAV_Auth_Plugin($authBackend,'ownCloud');//should use $validTokens here - $server->addPlugin($authPlugin); - - // Also make sure there is a 'data' directory, writable by the server. This directory is used to store information about locks - $lockBackend = new OC_Connector_Sabre_Locks(); - $lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend); - $server->addPlugin($lockPlugin); - - // And off we go! - $server->exec(); -} else { - //die('not the right address format '.var_export($pathParts, true)); - die('not the right address format'); -} |