2011-09-02 16:56:40 +04:00
|
|
|
<?php
|
|
|
|
|
2011-10-04 12:07:46 +04:00
|
|
|
class OC_remoteStorage {
|
2011-12-07 18:51:47 +04:00
|
|
|
public static function getValidTokens($ownCloudUser, $category) {
|
2012-05-03 15:06:08 +04:00
|
|
|
$query=OCP\DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
|
2012-02-22 22:05:52 +04:00
|
|
|
$result=$query->execute(array($ownCloudUser));
|
2011-09-02 16:56:40 +04:00
|
|
|
$ret = array();
|
|
|
|
while($row=$result->fetchRow()){
|
2012-02-22 22:05:52 +04:00
|
|
|
if(in_array($category, explode(',', $row['category']))) {
|
|
|
|
$ret[$row['token']]=true;
|
|
|
|
}
|
2011-09-02 16:56:40 +04:00
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2012-05-09 17:17:01 +04:00
|
|
|
public static function getTokenFor($appUrl, $categories) {
|
|
|
|
$user=OCP\USER::getUser();
|
|
|
|
$query=OCP\DB::prepare("SELECT token FROM *PREFIX*authtoken WHERE user=? AND appUrl=? AND category=? LIMIT 1");
|
|
|
|
$result=$query->execute(array($user, $appUrl, $categories));
|
|
|
|
if($row=$result->fetchRow()) {
|
2012-07-20 20:56:18 +04:00
|
|
|
return base64_encode('remoteStorage:'.$row['token']);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-09 17:17:01 +04:00
|
|
|
}
|
|
|
|
|
2011-09-02 16:56:40 +04:00
|
|
|
public static function getAllTokens() {
|
2012-05-01 20:50:31 +04:00
|
|
|
$user=OCP\USER::getUser();
|
2012-05-03 15:06:08 +04:00
|
|
|
$query=OCP\DB::prepare("SELECT token,appUrl,category FROM *PREFIX*authtoken WHERE user=? LIMIT 100");
|
2011-09-02 16:56:40 +04:00
|
|
|
$result=$query->execute(array($user));
|
|
|
|
$ret = array();
|
|
|
|
while($row=$result->fetchRow()){
|
|
|
|
$ret[$row['token']] = array(
|
2012-03-02 00:55:12 +04:00
|
|
|
'appUrl' => $row['appUrl'],
|
2012-02-22 22:05:52 +04:00
|
|
|
'categories' => $row['category'],
|
2011-09-02 16:56:40 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function deleteToken($token) {
|
2012-05-01 20:50:31 +04:00
|
|
|
$user=OCP\USER::getUser();
|
2012-05-03 15:06:08 +04:00
|
|
|
$query=OCP\DB::prepare("DELETE FROM *PREFIX*authtoken WHERE token=? AND user=?");
|
2012-07-20 20:56:18 +04:00
|
|
|
$query->execute(array($token,$user));
|
2012-03-02 00:55:12 +04:00
|
|
|
return 'unknown';//how can we see if any rows were affected?
|
2011-09-02 16:56:40 +04:00
|
|
|
}
|
2012-02-22 22:05:52 +04:00
|
|
|
private static function addToken($token, $appUrl, $categories){
|
2012-05-01 20:50:31 +04:00
|
|
|
$user=OCP\USER::getUser();
|
2012-05-03 15:06:08 +04:00
|
|
|
$query=OCP\DB::prepare("INSERT INTO *PREFIX*authtoken (`token`,`appUrl`,`user`,`category`) VALUES(?,?,?,?)");
|
2012-07-20 20:56:18 +04:00
|
|
|
$query->execute(array($token,$appUrl,$user,$categories));
|
2011-09-02 16:56:40 +04:00
|
|
|
}
|
2012-02-22 22:05:52 +04:00
|
|
|
public static function createCategories($appUrl, $categories) {
|
2011-09-02 16:56:40 +04:00
|
|
|
$token=uniqid();
|
2012-05-01 20:50:31 +04:00
|
|
|
OC_Util::setupFS(OCP\USER::getUser());
|
2012-02-22 22:05:52 +04:00
|
|
|
self::addToken($token, $appUrl, $categories);
|
2012-02-26 03:15:31 +04:00
|
|
|
foreach(explode(',', $categories) as $category) {
|
2012-02-22 22:05:52 +04:00
|
|
|
//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);
|
|
|
|
}
|
2011-09-02 16:56:40 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-07 18:51:47 +04:00
|
|
|
return base64_encode('remoteStorage:'.$token);
|
2011-09-02 16:56:40 +04:00
|
|
|
}
|
|
|
|
}
|