remoteStorage app version 0.5

This commit is contained in:
Michiel de Jong 2012-03-01 20:55:12 +00:00
parent 5dcd9e20d0
commit 5d8d7ef2a1
9 changed files with 121 additions and 30 deletions

View File

@ -0,0 +1,41 @@
<?php
/**
* ownCloud
*
* Original:
* @author Frank Karlitschek
* @copyright 2010 Frank Karlitschek karlitschek@kde.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/>.
*
*/
// Do not load FS ...
$RUNTIME_NOSETUPFS = true;
require_once('../../../lib/base.php');
OC_Util::checkAppEnabled('remoteStorage');
require_once('Sabre/autoload.php');
require_once('../lib_remoteStorage.php');
ini_set('default_charset', 'UTF-8');
#ini_set('error_reporting', '');
@ob_clean();
echo OC_remoteStorage::deleteToken(file_get_contents("php://input"));

View File

@ -3,3 +3,4 @@ OC_App::register( array(
'order' => 10,
'id' => 'remoteStorage',
'name' => 'remoteStorage compatibility' ));
OC_APP::registerPersonal('remoteStorage','settings');

View File

@ -3,7 +3,7 @@
<id>remoteStorage</id>
<name>remoteStorage compatibility</name>
<description>Enables your users to use ownCloud as their remote storage for unhosted applications.</description>
<version>0.4</version>
<version>0.5</version>
<licence>AGPL or MIT</licence>
<author>Michiel de Jong</author>
<require>2</require>

View File

@ -0,0 +1,8 @@
h2 { font-size:2em; font-weight:bold; margin-bottom:1em; white-space:nowrap; }
ul.scopes { list-style:disc; }
ul.scopes li { white-space:nowrap; }
h2 img { width: 50% }
#oauth { margin:4em auto 2em; width:20em; }
#allow-auth { background-color:#5c3; text-shadow:#5e3 0 1px 0; color:#fff;
-webkit-box-shadow:0 1px 1px #fff, 0 1px 1px #5f3 inset; -moz-box-shadow:0 1px 1px #fff, 0 1px 1px #5f3 inset; box-shadow:0 1px 1px #fff, 0 1px 1px #5f3 inset; }
#deny-auth { padding:0; margin:.7em; border:0; background:none; font-size:1.2em; -moz-box-shadow: 0 0 0 #fff, 0 0 0 #fff inset; -webkit-box-shadow: 0 0 0 #fff, 0 0 0 #fff inset; box-shadow: 0 0 0 #fff, 0 0 0 #fff inset; }

View File

@ -8,7 +8,7 @@
* @copyright 2010 Frank Karlitschek karlitschek@kde.org
*
* Adapted:
* @author Michiel de Jong, 2011
* @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
@ -17,11 +17,11 @@
*
* 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
* 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/>.
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
@ -39,24 +39,8 @@ 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($_SERVER["SCRIPT_NAME"]));
$pathParts = explode('/', $path);
// for webdav:
// 0/ 1 / 2 / 3 / 4 / 5 / 6 / 7
// /$ownCloudUser/remoteStorage/webdav/$userHost/$userName/$dataScope/$key
// for oauth:
// 0/ 1 / 2 / 3 / 4
// /$ownCloudUser/remoteStorage/oauth/auth
$pathParts = explode('/', $path);
if(count($pathParts) == 2 && $pathParts[0] == '') {
//TODO: input checking. these explodes may fail to produces the desired arrays:
@ -66,7 +50,8 @@ if(count($pathParts) == 2 && $pathParts[0] == '') {
if($k=='user_address'){
$userAddress=$v;
} else if($k=='redirect_uri'){
$appUrl=$v;
$appUrlParts=explode('/', $v);
$appUrl = $appUrlParts[2];//bit dodgy i guess
} else if($k=='scope'){
$categories=$v;
}
@ -78,7 +63,56 @@ if(count($pathParts) == 2 && $pathParts[0] == '') {
$token=OC_remoteStorage::createCategories($appUrl, $categories);
header('Location: '.$_GET['redirect_uri'].'#access_token='.$token.'&token_type=bearer');
} else {
echo '<form method="POST"><input name="allow" type="submit" value="Allow this web app to store stuff on your owncloud."></form>';
?>
<!DOCTYPE html>
<html>
<head>
<title>ownCloud</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="../../../core/img/favicon.png" /><link rel="apple-touch-icon-precomposed" href="../../../core/img/favicon-touch.png" />
<link rel="stylesheet" href="../../../core/css/styles.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../auth.css" type="text/css" media="screen" />
</head>
<body id="body-login">
<div id="login">
<header>
<div id="header">
<img src="../../../core/img/owncloud-logo-medium-white.png" alt="ownCloud" />
</div>
</header>
<section id="main">
<div id="oauth">
<h2><img src="../remoteStorage-big.png" alt="remoteStorage" /></h2>
<p><strong><?php $appUrlParts = explode('/', $_GET['redirect_uri']); echo htmlentities($appUrlParts[2]); ?></strong>
requests read &amp; write access to your
<?php
$categories = explode(',', htmlentities($_GET['scope']));
if(!count($categories)) {
echo htmlentities($_GET['scope']);
} 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>
</div>
<footer><p class="info"><a href="http://owncloud.org/">ownCloud</a> &ndash; web services under your control</p></footer>
</body>
</html>
<?php
}
} else {
if((isset($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'])) {
@ -88,12 +122,11 @@ if(count($pathParts) == 2 && $pathParts[0] == '') {
}
$url .= $_SERVER['SERVER_NAME'];
$url .= substr($_SERVER['SCRIPT_NAME'], 0, -strlen('apps/remoteStorage/compat.php'));
die('You are '.($currUser?'logged in as '.$currUser.' instead of '.$ownCloudUser:'not logged in').'. Please '
.'<input type="submit" onclick="'
."window.open('$url','Close me!','height=600,width=300');"
.'" value="log in">'
.', close the pop-up, and '
.'<form method="POST"><input name="allow" type="submit" value="Click here"></form>');
if($currUser) {
die('You are logged in as '.$currUser.' instead of '.$ownCloudUser);
} else {
header('Location: /?redirect_url='.urlencode('/apps/remoteStorage/auth.php'.$_SERVER['PATH_INFO'].'?'.$_SERVER['QUERY_STRING']));
}
}
} else {
//die('please use auth.php/username?params. '.var_export($pathParts, true));

View File

@ -20,7 +20,7 @@ class OC_remoteStorage {
$ret = array();
while($row=$result->fetchRow()){
$ret[$row['token']] = array(
'appUrl' => $row['appurl'],
'appUrl' => $row['appUrl'],
'categories' => $row['category'],
);
}
@ -31,6 +31,7 @@ class OC_remoteStorage {
$user=OC_User::getUser();
$query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?");
$result=$query->execute(array($token,$user));
return 'unknown';//how can we see if any rows were affected?
}
private static function addToken($token, $appUrl, $categories){
$user=OC_User::getUser();

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,7 @@
<?php
require_once('lib_remoteStorage.php');
$tmpl = new OC_Template( 'remoteStorage', 'settings');
return $tmpl->fetchPage();
?>