first part of the new new OCS CLOUD module. So far only quota is implemented.

The specification is developed here:
http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-1.7#CLOUD
will be moved to
http://www.freedesktop.org/wiki/Specifications/open-collaboration-services
as soon as everything is done.
This commit is contained in:
Frank Karlitschek 2012-07-23 18:34:21 +02:00
parent bd63fddbf4
commit e7e1f234dd
2 changed files with 436 additions and 383 deletions

View File

@ -4,7 +4,9 @@
* ownCloud * ownCloud
* *
* @author Frank Karlitschek * @author Frank Karlitschek
* @author Michael Gapczynski
* @copyright 2012 Frank Karlitschek frank@owncloud.org * @copyright 2012 Frank Karlitschek frank@owncloud.org
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@ -29,425 +31,438 @@
*/ */
class OC_OCS { class OC_OCS {
/** /**
* reads input date from get/post/cookies and converts the date to a special data-type * reads input date from get/post/cookies and converts the date to a special data-type
* *
* @param variable $key * @param string HTTP method to read the key from
* @param variable-type $type * @param string Parameter to read
* @param priority $getpriority * @param string Variable type to format data
* @param default $default * @param mixed Default value to return if the key is not found
* @return data * @return mixed Data or if the key is not found and no default is set it will exit with a 400 Bad request
*/ */
public static function readData($key,$type='raw',$getpriority=false,$default='') { public static function readData($method, $key, $type = 'raw', $default = null) {
if($getpriority) { if ($method == 'get') {
if(isset($_GET[$key])) { if (isset($_GET[$key])) {
$data=$_GET[$key]; $data = $_GET[$key];
} elseif(isset($_POST[$key])) { } else if (isset($default)) {
$data=$_POST[$key]; return $default;
} else { } else {
if($default=='') { $data = false;
if(($type=='int') or ($type=='float')) $data=0; else $data=''; }
} else { } else if ($method == 'post') {
$data=$default; if (isset($_POST[$key])) {
} $data = $_POST[$key];
} } else if (isset($default)) {
} else { return $default;
if(isset($_POST[$key])) { } else {
$data=$_POST[$key]; $data = false;
} elseif(isset($_GET[$key])) { }
$data=$_GET[$key]; }
} elseif(isset($_COOKIE[$key])) { if ($data === false) {
$data=$_COOKIE[$key]; echo self::generateXml('', 'fail', 400, 'Bad request. Please provide a valid '.$key);
} else { exit();
if($default=='') { } else {
if(($type=='int') or ($type=='float')) $data=0; else $data=''; // NOTE: Is the raw type necessary? It might be a little risky without sanitization
} else { if ($type == 'raw') return $data;
$data=$default; elseif ($type == 'text') return OC_Util::sanitizeHTML($data);
} elseif ($type == 'int') return (int) $data;
} elseif ($type == 'float') return (float) $data;
} elseif ($type == 'array') return OC_Util::sanitizeHTML($data);
else return OC_Util::sanitizeHTML($data);
}
}
if($type=='raw') return($data); /**
elseif($type=='text') return(addslashes(strip_tags($data))); main function to handle the REST request
elseif($type=='int') { $data = (int) $data; return($data); } **/
elseif($type=='float') { $data = (float) $data; return($data); } public static function handle() {
elseif($type=='array') { $data = $data; return($data); } // overwrite the 404 error page returncode
} header("HTTP/1.0 200 OK");
/** if($_SERVER['REQUEST_METHOD'] == 'GET') {
main function to handle the REST request $method='get';
**/ }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') {
public static function handle() { $method='put';
parse_str(file_get_contents("php://input"),$put_vars);
}elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
$method='post';
}else{
echo('internal server error: method not supported');
exit();
}
// overwrite the 404 error page returncode // preprocess url
header("HTTP/1.0 200 OK"); $url = strtolower($_SERVER['REQUEST_URI']);
if(substr($url,(strlen($url)-1))<>'/') $url.='/';
$ex=explode('/',$url);
$paracount=count($ex);
$format = self::readData($method, 'format', 'text', '');
// eventhandler
// CONFIG
// apiconfig - GET - CONFIG
if(($method=='get') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'config')){
OC_OCS::apiconfig($format);
// PERSON
// personcheck - POST - PERSON/CHECK
}elseif(($method=='post') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-3]=='person') and ($ex[$paracount-2] == 'check')){
$login = self::readData($method, 'login', 'text');
$passwd = self::readData($method, 'password', 'text');
OC_OCS::personcheck($format,$login,$passwd);
/*
} else if ($method == 'post' && $ex[$paracount - 4] == 'v1.php' && $ex[$paracount - 3] == 'person' && $ex[$paracount - 2] == 'add') {
if (OC_Group::inGroup(self::checkPassword(), 'admin')) {
$login = self::readData($method, 'login', 'text');
$password = self::readData($method, 'password', 'text');
try {
OC_User::createUser($login, $password);
echo self::generateXml($format, 'ok', 201, '');
} catch (Exception $exception) {
echo self::generateXml($format, 'fail', 400, $exception->getMessage());
}
} else {
echo self::generateXml($format, 'fail', 403, 'Permission denied');
}
*/
// ACTIVITY
// activityget - GET ACTIVITY page,pagesize als urlparameter
}elseif(($method=='get') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')){
$page = self::readData($method, 'page', 'int', 0);
$pagesize = self::readData($method, 'pagesize','int', 10);
if($pagesize<1 or $pagesize>100) $pagesize=10;
OC_OCS::activityget($format,$page,$pagesize);
// activityput - POST ACTIVITY
}elseif(($method=='post') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')){
$message = self::readData($method, 'message', 'text');
OC_OCS::activityput($format,$message);
if($_SERVER['REQUEST_METHOD'] == 'GET') { // PRIVATEDATA
$method='get'; // get - GET DATA
}elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { }elseif(($method=='get') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-2] == 'getattribute')){
$method='put'; OC_OCS::privateDataGet($format);
}elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
$method='post';
}else{
echo('internal server error: method not supported');
exit();
}
// preprocess url }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-3] == 'getattribute')){
$url=$_SERVER['REQUEST_URI']; $app=$ex[$paracount-2];
if(substr($url,(strlen($url)-1))<>'/') $url.='/'; OC_OCS::privateDataGet($format, $app);
$ex=explode('/',$url); }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'getattribute')){
$paracount=count($ex);
$key=$ex[$paracount-2];
$app=$ex[$paracount-3];
OC_OCS::privateDataGet($format, $app,$key);
// eventhandler // set - POST DATA
// CONFIG }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'setattribute')){
// apiconfig - GET - CONFIG $key=$ex[$paracount-2];
if(($method=='get') and (strtolower($ex[$paracount-3])=='v1.php') and (strtolower($ex[$paracount-2])=='config')){ $app=$ex[$paracount-3];
$format=OC_OCS::readdata('format','text'); $value = self::readData($method, 'value', 'text');
OC_OCS::apiconfig($format); OC_OCS::privatedataset($format, $app, $key, $value);
// delete - POST DATA
}elseif(($method=='post') and ($ex[$paracount-6] =='v1.php') and ($ex[$paracount-4] == 'deleteattribute')){
$key=$ex[$paracount-2];
$app=$ex[$paracount-3];
OC_OCS::privatedatadelete($format, $app, $key);
// PERSON // CLOUD
// personcheck - POST - PERSON/CHECK // quotaget - GET QUOTA parameter
}elseif(($method=='post') and (strtolower($ex[$paracount-4])=='v1.php') and (strtolower($ex[$paracount-3])=='person') and (strtolower($ex[$paracount-2])=='check')){ }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-4]=='cloud') and ($ex[$paracount-3] == 'files') and ($ex[$paracount-2] == 'quota')){
$format=OC_OCS::readdata('format','text'); OC_OCS::quotaget($format);
$login=OC_OCS::readdata('login','text');
$passwd=OC_OCS::readdata('password','text');
OC_OCS::personcheck($format,$login,$passwd);
// ACTIVITY
// activityget - GET ACTIVITY page,pagesize als urlparameter
}elseif(($method=='get') and (strtolower($ex[$paracount-3])=='v1.php')and (strtolower($ex[$paracount-2])=='activity')){
$format=OC_OCS::readdata('format','text');
$page=OC_OCS::readdata('page','int');
$pagesize=OC_OCS::readdata('pagesize','int');
if($pagesize<1 or $pagesize>100) $pagesize=10;
OC_OCS::activityget($format,$page,$pagesize);
// activityput - POST ACTIVITY
}elseif(($method=='post') and (strtolower($ex[$paracount-3])=='v1.php')and (strtolower($ex[$paracount-2])=='activity')){
$format=OC_OCS::readdata('format','text');
$message=OC_OCS::readdata('message','text');
OC_OCS::activityput($format,$message);
// PRIVATEDATA
// get - GET DATA
}elseif(($method=='get') and (strtolower($ex[$paracount-4])=='v1.php')and (strtolower($ex[$paracount-2])=='getattribute')){
$format=OC_OCS::readdata('format','text');
OC_OCS::privateDataGet($format);
}elseif(($method=='get') and (strtolower($ex[$paracount-5])=='v1.php')and (strtolower($ex[$paracount-3])=='getattribute')){
$format=OC_OCS::readdata('format','text');
$app=$ex[$paracount-2];
OC_OCS::privateDataGet($format, $app);
}elseif(($method=='get') and (strtolower($ex[$paracount-6])=='v1.php')and (strtolower($ex[$paracount-4])=='getattribute')){
$format=OC_OCS::readdata('format','text');
$key=$ex[$paracount-2];
$app=$ex[$paracount-3];
OC_OCS::privateDataGet($format, $app,$key);
// set - POST DATA
}elseif(($method=='post') and (strtolower($ex[$paracount-6])=='v1.php')and (strtolower($ex[$paracount-4])=='setattribute')){
$format=OC_OCS::readdata('format','text');
$key=$ex[$paracount-2];
$app=$ex[$paracount-3];
$value=OC_OCS::readdata('value','text');
OC_OCS::privatedataset($format, $app, $key, $value);
// delete - POST DATA
}elseif(($method=='post') and (strtolower($ex[$paracount-6])=='v1.php')and (strtolower($ex[$paracount-4])=='deleteattribute')){
$format=OC_OCS::readdata('format','text');
$key=$ex[$paracount-2];
$app=$ex[$paracount-3];
OC_OCS::privatedatadelete($format, $app, $key);
}else{
$format=OC_OCS::readdata('format','text');
$txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
$txt.=OC_OCS::getdebugoutput();
echo(OC_OCS::generatexml($format,'failed',999,$txt));
}
exit();
}
/**
* generated some debug information to make it easier to find faild API calls
* @return debug data string
*/
private static function getDebugOutput() {
$txt='';
$txt.="debug output:\n";
if(isset($_SERVER['REQUEST_METHOD'])) $txt.='http request method: '.$_SERVER['REQUEST_METHOD']."\n";
if(isset($_SERVER['REQUEST_URI'])) $txt.='http request uri: '.$_SERVER['REQUEST_URI']."\n";
if(isset($_GET)) foreach($_GET as $key=>$value) $txt.='get parameter: '.$key.'->'.$value."\n";
if(isset($_POST)) foreach($_POST as $key=>$value) $txt.='post parameter: '.$key.'->'.$value."\n";
return($txt);
}
/**
* checks if the user is authenticated
* checks the IP whitlist, apikeys and login/password combination
* if $forceuser is true and the authentication failed it returns an 401 http response.
* if $forceuser is false and authentification fails it returns an empty username string
* @param bool $forceuser
* @return username string
*/
private static function checkPassword($forceuser=true) {
//valid user account ?
if(isset($_SERVER['PHP_AUTH_USER'])) $authuser=$_SERVER['PHP_AUTH_USER']; else $authuser='';
if(isset($_SERVER['PHP_AUTH_PW'])) $authpw=$_SERVER['PHP_AUTH_PW']; else $authpw='';
if(empty($authuser)) {
if($forceuser){
header('WWW-Authenticate: Basic realm="your valid user account or api key"');
header('HTTP/1.0 401 Unauthorized');
exit;
}else{
$identifieduser='';
}
}else{
if(!OC_User::login($authuser,$authpw)){
if($forceuser){
header('WWW-Authenticate: Basic realm="your valid user account or api key"');
header('HTTP/1.0 401 Unauthorized');
exit;
}else{
$identifieduser='';
}
}else{
$identifieduser=$authuser;
}
}
return($identifieduser);
}
/** // add more calls here
* generates the xml or json response for the API call from an multidimenional data array. // please document all the call in the draft spec
* @param string $format // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-1.7#CLOUD
* @param string $status
* @param string $statuscode
* @param string $message
* @param array $data
* @param string $tag
* @param string $tagattribute
* @param int $dimension
* @param int $itemscount
* @param int $itemsperpage
* @return string xml/json
*/
private static function generateXml($format,$status,$statuscode,$message,$data=array(),$tag='',$tagattribute='',$dimension=-1,$itemscount='',$itemsperpage='') {
if($format=='json') {
$json=array();
$json['status']=$status;
$json['statuscode']=$statuscode;
$json['message']=$message;
$json['totalitems']=$itemscount;
$json['itemsperpage']=$itemsperpage;
$json['data']=$data;
return(json_encode($json));
}else{ }else{
$txt=''; $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
$writer = xmlwriter_open_memory(); $txt.=OC_OCS::getdebugoutput();
xmlwriter_set_indent( $writer, 2 ); echo(OC_OCS::generatexml($format,'failed',999,$txt));
xmlwriter_start_document($writer ); }
xmlwriter_start_element($writer,'ocs'); exit();
xmlwriter_start_element($writer,'meta'); }
xmlwriter_write_element($writer,'status',$status);
xmlwriter_write_element($writer,'statuscode',$statuscode);
xmlwriter_write_element($writer,'message',$message);
if($itemscount<>'') xmlwriter_write_element($writer,'totalitems',$itemscount);
if(!empty($itemsperpage)) xmlwriter_write_element($writer,'itemsperpage',$itemsperpage);
xmlwriter_end_element($writer);
if($dimension=='0') {
// 0 dimensions
xmlwriter_write_element($writer,'data',$data);
}elseif($dimension=='1') { /**
xmlwriter_start_element($writer,'data'); * generated some debug information to make it easier to find faild API calls
foreach($data as $key=>$entry) { * @return debug data string
xmlwriter_write_element($writer,$key,$entry); */
} private static function getDebugOutput() {
xmlwriter_end_element($writer); $txt='';
$txt.="debug output:\n";
if(isset($_SERVER['REQUEST_METHOD'])) $txt.='http request method: '.$_SERVER['REQUEST_METHOD']."\n";
if(isset($_SERVER['REQUEST_URI'])) $txt.='http request uri: '.$_SERVER['REQUEST_URI']."\n";
if(isset($_GET)) foreach($_GET as $key=>$value) $txt.='get parameter: '.$key.'->'.$value."\n";
if(isset($_POST)) foreach($_POST as $key=>$value) $txt.='post parameter: '.$key.'->'.$value."\n";
return($txt);
}
}elseif($dimension=='2') { /**
xmlwriter_start_element($writer,'data'); * checks if the user is authenticated
foreach($data as $entry) { * checks the IP whitlist, apikeys and login/password combination
xmlwriter_start_element($writer,$tag); * if $forceuser is true and the authentication failed it returns an 401 http response.
if(!empty($tagattribute)) { * if $forceuser is false and authentification fails it returns an empty username string
xmlwriter_write_attribute($writer,'details',$tagattribute); * @param bool $forceuser
} * @return username string
foreach($entry as $key=>$value) { */
if(is_array($value)){ private static function checkPassword($forceuser=true) {
foreach($value as $k=>$v) { //valid user account ?
xmlwriter_write_element($writer,$k,$v); if(isset($_SERVER['PHP_AUTH_USER'])) $authuser=$_SERVER['PHP_AUTH_USER']; else $authuser='';
} if(isset($_SERVER['PHP_AUTH_PW'])) $authpw=$_SERVER['PHP_AUTH_PW']; else $authpw='';
} else {
xmlwriter_write_element($writer,$key,$value);
}
}
xmlwriter_end_element($writer);
}
xmlwriter_end_element($writer);
}elseif($dimension=='3') { if(empty($authuser)) {
xmlwriter_start_element($writer,'data'); if($forceuser){
foreach($data as $entrykey=>$entry) { header('WWW-Authenticate: Basic realm="your valid user account or api key"');
xmlwriter_start_element($writer,$tag); header('HTTP/1.0 401 Unauthorized');
if(!empty($tagattribute)) { exit;
xmlwriter_write_attribute($writer,'details',$tagattribute); }else{
} $identifieduser='';
foreach($entry as $key=>$value) { }
if(is_array($value)){ }else{
xmlwriter_start_element($writer,$entrykey); if(!OC_User::login($authuser,$authpw)){
foreach($value as $k=>$v) { if($forceuser){
xmlwriter_write_element($writer,$k,$v); header('WWW-Authenticate: Basic realm="your valid user account or api key"');
} header('HTTP/1.0 401 Unauthorized');
xmlwriter_end_element($writer); exit;
} else { }else{
xmlwriter_write_element($writer,$key,$value); $identifieduser='';
} }
} }else{
xmlwriter_end_element($writer); $identifieduser=$authuser;
} }
xmlwriter_end_element($writer); }
}elseif($dimension=='dynamic') {
xmlwriter_start_element($writer,'data');
OC_OCS::toxml($writer,$data,'comment');
xmlwriter_end_element($writer);
}
xmlwriter_end_element($writer); return($identifieduser);
}
xmlwriter_end_document( $writer );
$txt.=xmlwriter_output_memory( $writer );
unset($writer);
return($txt);
}
}
public static function toXml($writer,$data,$node) { /**
foreach($data as $key => $value) { * generates the xml or json response for the API call from an multidimenional data array.
if (is_numeric($key)) { * @param string $format
$key = $node; * @param string $status
} * @param string $statuscode
if (is_array($value)){ * @param string $message
xmlwriter_start_element($writer,$key); * @param array $data
OC_OCS::toxml($writer,$value,$node); * @param string $tag
xmlwriter_end_element($writer); * @param string $tagattribute
}else{ * @param int $dimension
xmlwriter_write_element($writer,$key,$value); * @param int $itemscount
} * @param int $itemsperpage
* @return string xml/json
*/
private static function generateXml($format,$status,$statuscode,$message,$data=array(),$tag='',$tagattribute='',$dimension=-1,$itemscount='',$itemsperpage='') {
if($format=='json') {
$json=array();
$json['status']=$status;
$json['statuscode']=$statuscode;
$json['message']=$message;
$json['totalitems']=$itemscount;
$json['itemsperpage']=$itemsperpage;
$json['data']=$data;
return(json_encode($json));
}else{
$txt='';
$writer = xmlwriter_open_memory();
xmlwriter_set_indent( $writer, 2 );
xmlwriter_start_document($writer );
xmlwriter_start_element($writer,'ocs');
xmlwriter_start_element($writer,'meta');
xmlwriter_write_element($writer,'status',$status);
xmlwriter_write_element($writer,'statuscode',$statuscode);
xmlwriter_write_element($writer,'message',$message);
if($itemscount<>'') xmlwriter_write_element($writer,'totalitems',$itemscount);
if(!empty($itemsperpage)) xmlwriter_write_element($writer,'itemsperpage',$itemsperpage);
xmlwriter_end_element($writer);
if($dimension=='0') {
// 0 dimensions
xmlwriter_write_element($writer,'data',$data);
} }elseif($dimension=='1') {
} xmlwriter_start_element($writer,'data');
foreach($data as $key=>$entry) {
xmlwriter_write_element($writer,$key,$entry);
}
xmlwriter_end_element($writer);
}elseif($dimension=='2') {
xmlwriter_start_element($writer,'data');
foreach($data as $entry) {
xmlwriter_start_element($writer,$tag);
if(!empty($tagattribute)) {
xmlwriter_write_attribute($writer,'details',$tagattribute);
}
foreach($entry as $key=>$value) {
if(is_array($value)){
foreach($value as $k=>$v) {
xmlwriter_write_element($writer,$k,$v);
}
} else {
xmlwriter_write_element($writer,$key,$value);
}
}
xmlwriter_end_element($writer);
}
xmlwriter_end_element($writer);
}elseif($dimension=='3') {
xmlwriter_start_element($writer,'data');
foreach($data as $entrykey=>$entry) {
xmlwriter_start_element($writer,$tag);
if(!empty($tagattribute)) {
xmlwriter_write_attribute($writer,'details',$tagattribute);
}
foreach($entry as $key=>$value) {
if(is_array($value)){
xmlwriter_start_element($writer,$entrykey);
foreach($value as $k=>$v) {
xmlwriter_write_element($writer,$k,$v);
}
xmlwriter_end_element($writer);
} else {
xmlwriter_write_element($writer,$key,$value);
}
}
xmlwriter_end_element($writer);
}
xmlwriter_end_element($writer);
}elseif($dimension=='dynamic') {
xmlwriter_start_element($writer,'data');
OC_OCS::toxml($writer,$data,'comment');
xmlwriter_end_element($writer);
}
xmlwriter_end_element($writer);
xmlwriter_end_document( $writer );
$txt.=xmlwriter_output_memory( $writer );
unset($writer);
return($txt);
}
}
public static function toXml($writer,$data,$node) {
foreach($data as $key => $value) {
if (is_numeric($key)) {
$key = $node;
}
if (is_array($value)){
xmlwriter_start_element($writer,$key);
OC_OCS::toxml($writer,$value,$node);
xmlwriter_end_element($writer);
}else{
xmlwriter_write_element($writer,$key,$value);
}
}
}
/** /**
* return the config data of this server * return the config data of this server
* @param string $format * @param string $format
* @return string xml/json * @return string xml/json
*/ */
private static function apiConfig($format) { private static function apiConfig($format) {
$xml['version']='1.5'; $user=OC_OCS::checkpassword(false);
$xml['website']='ownCloud'; $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'],0,-11).'';
$xml['host']=OCP\Util::getServerHost();
$xml['contact']=''; $xml['version']='1.7';
$xml['ssl']='false'; $xml['website']='ownCloud';
echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'config','',1)); $xml['host']=OCP\Util::getServerHost();
} $xml['contact']='';
$xml['ssl']='false';
echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'config','',1));
}
/** /**
* check if the provided login/apikey/password is valid * check if the provided login/apikey/password is valid
* @param string $format * @param string $format
* @param string $login * @param string $login
* @param string $passwd * @param string $passwd
* @return string xml/json * @return string xml/json
*/ */
private static function personCheck($format,$login,$passwd) { private static function personCheck($format,$login,$passwd) {
if($login<>''){ if($login<>''){
if(OC_User::login($login,$passwd)){ if(OC_User::login($login,$passwd)){
$xml['person']['personid']=$login; $xml['person']['personid']=$login;
echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'person','check',2)); echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'person','check',2));
}else{ }else{
echo(OC_OCS::generatexml($format,'failed',102,'login not valid')); echo(OC_OCS::generatexml($format,'failed',102,'login not valid'));
} }
}else{ }else{
echo(OC_OCS::generatexml($format,'failed',101,'please specify all mandatory fields')); echo(OC_OCS::generatexml($format,'failed',101,'please specify all mandatory fields'));
} }
} }
// ACTIVITY API ############################################# // ACTIVITY API #############################################
/** /**
* get my activities * get my activities
* @param string $format * @param string $format
* @param string $page * @param string $page
* @param string $pagesize * @param string $pagesize
* @return string xml/json * @return string xml/json
*/ */
private static function activityGet($format,$page,$pagesize) { private static function activityGet($format,$page,$pagesize) {
$user=OC_OCS::checkpassword(); $user=OC_OCS::checkpassword();
//TODO
$txt=OC_OCS::generatexml($format,'ok',100,'',$xml,'activity','full',2,$totalcount,$pagesize); //TODO
echo($txt);
}
/** $txt=OC_OCS::generatexml($format,'ok',100,'',$xml,'activity','full',2,$totalcount,$pagesize);
* submit a activity echo($txt);
* @param string $format }
* @param string $message
* @return string xml/json
*/
private static function activityPut($format,$message) {
// not implemented in ownCloud
OC_OCS::checkpassword();
echo(OC_OCS::generatexml($format,'ok',100,''));
}
// PRIVATEDATA API ############################################# /**
* submit a activity
* @param string $format
* @param string $message
* @return string xml/json
*/
private static function activityPut($format,$message) {
// not implemented in ownCloud
$user=OC_OCS::checkpassword();
echo(OC_OCS::generatexml($format,'ok',100,''));
}
/** // PRIVATEDATA API #############################################
* get private data and create the xml for ocs
* @param string $format /**
* @param string $app * get private data and create the xml for ocs
* @param string $key * @param string $format
* @return string xml/json * @param string $app
*/ * @param string $key
private static function privateDataGet($format,$app="",$key="") { * @return string xml/json
$user=OC_OCS::checkpassword(); */
$result=OC_OCS::getData($user,$app,$key); private static function privateDataGet($format,$app="",$key="") {
$xml=array(); $user=OC_OCS::checkpassword();
foreach($result as $i=>$log) { $result=OC_OCS::getData($user,$app,$key);
$xml[$i]['key']=$log['key']; $xml=array();
$xml[$i]['app']=$log['app']; foreach($result as $i=>$log) {
$xml[$i]['value']=$log['value']; $xml[$i]['key']=$log['key'];
} $xml[$i]['app']=$log['app'];
$xml[$i]['value']=$log['value'];
}
$txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'privatedata', 'full', 2, count($xml), 0);//TODO: replace 'privatedata' with 'attribute' once a new libattice has been released that works with it $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'privatedata', 'full', 2, count($xml), 0);//TODO: replace 'privatedata' with 'attribute' once a new libattice has been released that works with it
echo($txt); echo($txt);
} }
/** /**
* set private data referenced by $key to $value and generate the xml for ocs * set private data referenced by $key to $value and generate the xml for ocs
* @param string $format * @param string $format
* @param string $app * @param string $app
* @param string $key * @param string $key
* @param string $value * @param string $value
* @return string xml/json * @return string xml/json
*/ */
private static function privateDataSet($format, $app, $key, $value) { private static function privateDataSet($format, $app, $key, $value) {
$user=OC_OCS::checkpassword(); $user=OC_OCS::checkpassword();
if(OC_OCS::setData($user,$app,$key,$value)){ if(OC_OCS::setData($user,$app,$key,$value)){
@ -525,4 +540,40 @@ class OC_OCS {
public static function deleteData($user, $app, $key) { public static function deleteData($user, $app, $key) {
return OC_Preferences::deleteKey($user,$app,$key); return OC_Preferences::deleteKey($user,$app,$key);
} }
// CLOUD API #############################################
/**
* get the quota of the current user
* @param string $format
* @return string xml/json
*/
private static function quotaGet($format) {
$user=OC_OCS::checkpassword();
// calculate the disc space
$user_dir = '/'.$user.'/files';
OC_Filesystem::init($user_dir);
$rootInfo=OC_FileCache::get('');
$sharedInfo=OC_FileCache::get('/Shared');
$used=$rootInfo['size']-$sharedInfo['size'];
$free=OC_Filesystem::free_space();
$total=$free+$used;
if($total==0) $total=1; // prevent division by zero
$relative=round(($used/$total)*10000)/100;
$xml=array();
$xml['quota']=$total;
$xml['free']=$free;
$xml['used']=$used;
$xml['relative']=$relative;
$txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', 'full', 1, count($xml), 0);
echo($txt);
}
} }

View File

@ -35,7 +35,9 @@ echo('
<termsofuse></termsofuse> <termsofuse></termsofuse>
<register></register> <register></register>
<services> <services>
<activity ocsversion="1.5" /> <config ocsversion="1.7" />
<activity ocsversion="1.7" />
<cloud ocsversion="1.7" />
</services> </services>
</provider> </provider>
</providers> </providers>