diff options
author | Jan-Christoph Borchardt <jan@unhosted.org> | 2011-10-04 10:07:46 +0200 |
---|---|---|
committer | Jan-Christoph Borchardt <jan@unhosted.org> | 2011-10-04 10:07:46 +0200 |
commit | 79da90bb08a7bb0dd1c4d29136dd18b27501888e (patch) | |
tree | 0933df4f7234b66783b2c944b42a61966d588a89 /apps/remoteStorage/lib_remoteStorage.php | |
parent | 77e12a15b1cffcaf3c152bf394fd15eb61d24ace (diff) | |
download | nextcloud-server-79da90bb08a7bb0dd1c4d29136dd18b27501888e.tar.gz nextcloud-server-79da90bb08a7bb0dd1c4d29136dd18b27501888e.zip |
renamed unhosted to remoteStorage (needs to be updated with coming protocol version)
Diffstat (limited to 'apps/remoteStorage/lib_remoteStorage.php')
-rw-r--r-- | apps/remoteStorage/lib_remoteStorage.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/apps/remoteStorage/lib_remoteStorage.php b/apps/remoteStorage/lib_remoteStorage.php new file mode 100644 index 00000000000..259efb0da69 --- /dev/null +++ b/apps/remoteStorage/lib_remoteStorage.php @@ -0,0 +1,78 @@ +<?php + +class OC_remoteStorage { + public static function getValidTokens($ownCloudUser, $userAddress, $dataScope) { + $query=OC_DB::prepare("SELECT token,appUrl FROM *PREFIX*authtoken WHERE user=? AND userAddress=? AND dataScope=? LIMIT 100"); + $result=$query->execute(array($user,$userAddress,$dataScope)); + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"<br />'; + $entry .= 'Offending command was: '.$result->getDebugInfo().'<br />'; + if(defined("DEBUG") && DEBUG) {error_log( $entry );} + die( $entry ); + } + $ret = array(); + while($row=$result->fetchRow()){ + $ret[$row['token']]=$userAddress; + } + return $ret; + } + + public static function getAllTokens() { + $user=OC_User::getUser(); + $query=OC_DB::prepare("SELECT token,appUrl,userAddress,dataScope FROM *PREFIX*authtoken WHERE user=? LIMIT 100"); + $result=$query->execute(array($user)); + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"<br />'; + $entry .= 'Offending command was: '.$result->getDebugInfo().'<br />'; + if(defined("DEBUG") && DEBUG) {error_log( $entry );} + die( $entry ); + } + $ret = array(); + while($row=$result->fetchRow()){ + $ret[$row['token']] = array( + 'appUrl' => $row['appurl'], + 'userAddress' => $row['useraddress'], + 'dataScope' => $row['datascope'], + ); + } + return $ret; + } + + public static function deleteToken($token) { + $user=OC_User::getUser(); + $query=OC_DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?"); + $result=$query->execute(array($token,$user)); + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"<br />'; + $entry .= 'Offending command was: '.$result->getDebugInfo().'<br />'; + if(defined("DEBUG") && DEBUG) {error_log( $entry );} + die( $entry ); + } + } + private static function addToken($token, $appUrl, $userAddress, $dataScope){ + $user=OC_User::getUser(); + $query=OC_DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`userAddress`,`dataScope`) VALUES(?,?,?,?,?)"); + $result=$query->execute(array($token,$appUrl,$user,$userAddress,$dataScope)); + if( PEAR::isError($result)) { + $entry = 'DB Error: "'.$result->getMessage().'"<br />'; + $entry .= 'Offending command was: '.$result->getDebugInfo().'<br />'; + if(defined("DEBUG") && DEBUG) {error_log( $entry );} + die( $entry ); + } + } + public static function createDataScope($appUrl, $userAddress, $dataScope){ + $token=uniqid(); + self::addToken($token, $appUrl, $userAddress, $dataScope); + //TODO: input checking on $userAddress and $dataScope + list($userName, $userHost) = explode('@', $userAddress); + OC_Util::setupFS(OC_User::getUser()); + $scopePathParts = array('remoteStorage', 'webdav', $userHost, $userName, $dataScope); + 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 $token; + } +} |