2011-09-02 16:56:40 +04:00
|
|
|
<?php
|
|
|
|
|
2011-10-04 12:07:46 +04:00
|
|
|
class OC_remoteStorage {
|
2011-09-02 16:56:40 +04:00
|
|
|
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");
|
2011-10-05 22:01:58 +04:00
|
|
|
$result=$query->execute(array($ownCloudUser,$userAddress,$dataScope));
|
2011-09-02 16:56:40 +04:00
|
|
|
$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));
|
|
|
|
$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));
|
|
|
|
}
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
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());
|
2011-10-04 12:07:46 +04:00
|
|
|
$scopePathParts = array('remoteStorage', 'webdav', $userHost, $userName, $dataScope);
|
2011-09-02 16:56:40 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|