ocs.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @author Michael Gapczynski
  7. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  8. * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  12. * License as published by the Free Software Foundation; either
  13. * version 3 of the License, or any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * Class to handle open collaboration services API requests
  26. *
  27. */
  28. class OC_OCS {
  29. /**
  30. * reads input date from get/post/cookies and converts the date to a special data-type
  31. *
  32. * @param string HTTP method to read the key from
  33. * @param string Parameter to read
  34. * @param string Variable type to format data
  35. * @param mixed Default value to return if the key is not found
  36. * @return mixed Data or if the key is not found and no default is set it will exit with a 400 Bad request
  37. */
  38. public static function readData($method, $key, $type = 'raw', $default = null) {
  39. if ($method == 'get') {
  40. if (isset($_GET[$key])) {
  41. $data = $_GET[$key];
  42. } else if (isset($default)) {
  43. return $default;
  44. } else {
  45. $data = false;
  46. }
  47. } else if ($method == 'post') {
  48. if (isset($_POST[$key])) {
  49. $data = $_POST[$key];
  50. } else if (isset($default)) {
  51. return $default;
  52. } else {
  53. $data = false;
  54. }
  55. }
  56. if ($data === false) {
  57. echo self::generateXml('', 'fail', 400, 'Bad request. Please provide a valid '.$key);
  58. exit();
  59. } else {
  60. // NOTE: Is the raw type necessary? It might be a little risky without sanitization
  61. if ($type == 'raw') return $data;
  62. elseif ($type == 'text') return OC_Util::sanitizeHTML($data);
  63. elseif ($type == 'int') return (int) $data;
  64. elseif ($type == 'float') return (float) $data;
  65. elseif ($type == 'array') return OC_Util::sanitizeHTML($data);
  66. else return OC_Util::sanitizeHTML($data);
  67. }
  68. }
  69. /**
  70. main function to handle the REST request
  71. **/
  72. public static function handle() {
  73. // overwrite the 404 error page returncode
  74. header("HTTP/1.0 200 OK");
  75. if($_SERVER['REQUEST_METHOD'] == 'GET') {
  76. $method='get';
  77. }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') {
  78. $method='put';
  79. parse_str(file_get_contents("php://input"), $put_vars);
  80. }elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
  81. $method='post';
  82. }else{
  83. echo('internal server error: method not supported');
  84. exit();
  85. }
  86. // preprocess url
  87. $url = strtolower($_SERVER['REQUEST_URI']);
  88. if(substr($url, (strlen($url)-1))<>'/') $url.='/';
  89. $ex=explode('/', $url);
  90. $paracount=count($ex);
  91. $format = self::readData($method, 'format', 'text', '');
  92. // eventhandler
  93. // CONFIG
  94. // apiconfig - GET - CONFIG
  95. if(($method=='get') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'config')) {
  96. OC_OCS::apiconfig($format);
  97. // PERSON
  98. // personcheck - POST - PERSON/CHECK
  99. } elseif(($method=='post') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-3]=='person') and ($ex[$paracount-2] == 'check')) {
  100. $login = self::readData($method, 'login', 'text');
  101. $passwd = self::readData($method, 'password', 'text');
  102. OC_OCS::personcheck($format, $login, $passwd);
  103. // ACTIVITY
  104. // activityget - GET ACTIVITY page,pagesize als urlparameter
  105. }elseif(($method=='get') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')) {
  106. $page = self::readData($method, 'page', 'int', 0);
  107. $pagesize = self::readData($method, 'pagesize', 'int', 10);
  108. if($pagesize<1 or $pagesize>100) $pagesize=10;
  109. OC_OCS::activityget($format, $page, $pagesize);
  110. // activityput - POST ACTIVITY
  111. }elseif(($method=='post') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')) {
  112. $message = self::readData($method, 'message', 'text');
  113. OC_OCS::activityput($format, $message);
  114. // PRIVATEDATA
  115. // get - GET DATA
  116. }elseif(($method=='get') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-2] == 'getattribute')) {
  117. OC_OCS::privateDataGet($format);
  118. }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-3] == 'getattribute')) {
  119. $app=$ex[$paracount-2];
  120. OC_OCS::privateDataGet($format, $app);
  121. }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'getattribute')) {
  122. $key=$ex[$paracount-2];
  123. $app=$ex[$paracount-3];
  124. OC_OCS::privateDataGet($format, $app, $key);
  125. // set - POST DATA
  126. }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'setattribute')) {
  127. $key=$ex[$paracount-2];
  128. $app=$ex[$paracount-3];
  129. $value = self::readData($method, 'value', 'text');
  130. OC_OCS::privatedataset($format, $app, $key, $value);
  131. // delete - POST DATA
  132. }elseif(($method=='post') and ($ex[$paracount-6] =='v1.php') and ($ex[$paracount-4] == 'deleteattribute')) {
  133. $key=$ex[$paracount-2];
  134. $app=$ex[$paracount-3];
  135. OC_OCS::privatedatadelete($format, $app, $key);
  136. // CLOUD
  137. // systemWebApps
  138. }elseif(($method=='get') and ($ex[$paracount-5] == 'v1.php') and ($ex[$paracount-4]=='cloud') and ($ex[$paracount-3] == 'system') and ($ex[$paracount-2] == 'webapps')) {
  139. OC_OCS::systemwebapps($format);
  140. // quotaget
  141. }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')) {
  142. $user=$ex[$paracount-3];
  143. OC_OCS::quotaget($format, $user);
  144. // quotaset
  145. }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')) {
  146. $user=$ex[$paracount-3];
  147. $quota = self::readData('post', 'quota', 'int');
  148. OC_OCS::quotaset($format, $user, $quota);
  149. // keygetpublic
  150. }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'publickey')) {
  151. $user=$ex[$paracount-3];
  152. OC_OCS::publicKeyGet($format, $user);
  153. // keygetprivate
  154. }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')) {
  155. $user=$ex[$paracount-3];
  156. OC_OCS::privateKeyGet($format, $user);
  157. // add more calls here
  158. // please document all the call in the draft spec
  159. // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-1.7#CLOUD
  160. // TODO:
  161. // users
  162. // groups
  163. // bookmarks
  164. // sharing
  165. // versioning
  166. // news (rss)
  167. }else{
  168. $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n";
  169. $txt.=OC_OCS::getdebugoutput();
  170. echo(OC_OCS::generatexml($format, 'failed', 999, $txt));
  171. }
  172. exit();
  173. }
  174. /**
  175. * generated some debug information to make it easier to find faild API calls
  176. * @return debug data string
  177. */
  178. private static function getDebugOutput() {
  179. $txt='';
  180. $txt.="debug output:\n";
  181. if(isset($_SERVER['REQUEST_METHOD'])) $txt.='http request method: '.$_SERVER['REQUEST_METHOD']."\n";
  182. if(isset($_SERVER['REQUEST_URI'])) $txt.='http request uri: '.$_SERVER['REQUEST_URI']."\n";
  183. if(isset($_GET)) foreach($_GET as $key=>$value) $txt.='get parameter: '.$key.'->'.$value."\n";
  184. if(isset($_POST)) foreach($_POST as $key=>$value) $txt.='post parameter: '.$key.'->'.$value."\n";
  185. return($txt);
  186. }
  187. /**
  188. * checks if the user is authenticated
  189. * checks the IP whitlist, apikeys and login/password combination
  190. * if $forceuser is true and the authentication failed it returns an 401 http response.
  191. * if $forceuser is false and authentification fails it returns an empty username string
  192. * @param bool $forceuser
  193. * @return username string
  194. */
  195. private static function checkPassword($forceuser=true) {
  196. //valid user account ?
  197. if(isset($_SERVER['PHP_AUTH_USER'])) $authuser=$_SERVER['PHP_AUTH_USER']; else $authuser='';
  198. if(isset($_SERVER['PHP_AUTH_PW'])) $authpw=$_SERVER['PHP_AUTH_PW']; else $authpw='';
  199. if(empty($authuser)) {
  200. if($forceuser) {
  201. header('WWW-Authenticate: Basic realm="your valid user account or api key"');
  202. header('HTTP/1.0 401 Unauthorized');
  203. exit;
  204. }else{
  205. $identifieduser='';
  206. }
  207. }else{
  208. if(!OC_User::login($authuser, $authpw)) {
  209. if($forceuser) {
  210. header('WWW-Authenticate: Basic realm="your valid user account or api key"');
  211. header('HTTP/1.0 401 Unauthorized');
  212. exit;
  213. }else{
  214. $identifieduser='';
  215. }
  216. }else{
  217. $identifieduser=$authuser;
  218. }
  219. }
  220. return($identifieduser);
  221. }
  222. /**
  223. * generates the xml or json response for the API call from an multidimenional data array.
  224. * @param string $format
  225. * @param string $status
  226. * @param string $statuscode
  227. * @param string $message
  228. * @param array $data
  229. * @param string $tag
  230. * @param string $tagattribute
  231. * @param int $dimension
  232. * @param int $itemscount
  233. * @param int $itemsperpage
  234. * @return string xml/json
  235. */
  236. private static function generateXml($format,$status,$statuscode,$message,$data=array(),$tag='',$tagattribute='',$dimension=-1,$itemscount='',$itemsperpage='') {
  237. if($format=='json') {
  238. $json=array();
  239. $json['status']=$status;
  240. $json['statuscode']=$statuscode;
  241. $json['message']=$message;
  242. $json['totalitems']=$itemscount;
  243. $json['itemsperpage']=$itemsperpage;
  244. $json['data']=$data;
  245. return(json_encode($json));
  246. }else{
  247. $txt='';
  248. $writer = xmlwriter_open_memory();
  249. xmlwriter_set_indent( $writer, 2 );
  250. xmlwriter_start_document($writer );
  251. xmlwriter_start_element($writer, 'ocs');
  252. xmlwriter_start_element($writer, 'meta');
  253. xmlwriter_write_element($writer, 'status', $status);
  254. xmlwriter_write_element($writer, 'statuscode', $statuscode);
  255. xmlwriter_write_element($writer, 'message', $message);
  256. if($itemscount<>'') xmlwriter_write_element($writer,'totalitems',$itemscount);
  257. if(!empty($itemsperpage)) xmlwriter_write_element($writer, 'itemsperpage', $itemsperpage);
  258. xmlwriter_end_element($writer);
  259. if($dimension=='0') {
  260. // 0 dimensions
  261. xmlwriter_write_element($writer, 'data', $data);
  262. }elseif($dimension=='1') {
  263. xmlwriter_start_element($writer, 'data');
  264. foreach($data as $key=>$entry) {
  265. xmlwriter_write_element($writer, $key, $entry);
  266. }
  267. xmlwriter_end_element($writer);
  268. }elseif($dimension=='2') {
  269. xmlwriter_start_element($writer,'data');
  270. foreach($data as $entry) {
  271. xmlwriter_start_element($writer, $tag);
  272. if(!empty($tagattribute)) {
  273. xmlwriter_write_attribute($writer, 'details', $tagattribute);
  274. }
  275. foreach($entry as $key=>$value) {
  276. if(is_array($value)) {
  277. foreach($value as $k=>$v) {
  278. xmlwriter_write_element($writer, $k, $v);
  279. }
  280. } else {
  281. xmlwriter_write_element($writer, $key, $value);
  282. }
  283. }
  284. xmlwriter_end_element($writer);
  285. }
  286. xmlwriter_end_element($writer);
  287. }elseif($dimension=='3') {
  288. xmlwriter_start_element($writer, 'data');
  289. foreach($data as $entrykey=>$entry) {
  290. xmlwriter_start_element($writer, $tag);
  291. if(!empty($tagattribute)) {
  292. xmlwriter_write_attribute($writer, 'details', $tagattribute);
  293. }
  294. foreach($entry as $key=>$value) {
  295. if(is_array($value)) {
  296. xmlwriter_start_element($writer, $entrykey);
  297. foreach($value as $k=>$v) {
  298. xmlwriter_write_element($writer, $k, $v);
  299. }
  300. xmlwriter_end_element($writer);
  301. } else {
  302. xmlwriter_write_element($writer, $key, $value);
  303. }
  304. }
  305. xmlwriter_end_element($writer);
  306. }
  307. xmlwriter_end_element($writer);
  308. }elseif($dimension=='dynamic') {
  309. xmlwriter_start_element($writer, 'data');
  310. OC_OCS::toxml($writer, $data, 'comment');
  311. xmlwriter_end_element($writer);
  312. }
  313. xmlwriter_end_element($writer);
  314. xmlwriter_end_document( $writer );
  315. $txt.=xmlwriter_output_memory( $writer );
  316. unset($writer);
  317. return($txt);
  318. }
  319. }
  320. public static function toXml($writer,$data,$node) {
  321. foreach($data as $key => $value) {
  322. if (is_numeric($key)) {
  323. $key = $node;
  324. }
  325. if (is_array($value)) {
  326. xmlwriter_start_element($writer, $key);
  327. OC_OCS::toxml($writer,$value, $node);
  328. xmlwriter_end_element($writer);
  329. }else{
  330. xmlwriter_write_element($writer, $key, $value);
  331. }
  332. }
  333. }
  334. /**
  335. * return the config data of this server
  336. * @param string $format
  337. * @return string xml/json
  338. */
  339. private static function apiConfig($format) {
  340. $user=OC_OCS::checkpassword(false);
  341. $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'], 0, -11).'';
  342. $xml['version']='1.7';
  343. $xml['website']='ownCloud';
  344. $xml['host']=OCP\Util::getServerHost();
  345. $xml['contact']='';
  346. $xml['ssl']='false';
  347. echo(OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'config', '', 1));
  348. }
  349. /**
  350. * check if the provided login/apikey/password is valid
  351. * @param string $format
  352. * @param string $login
  353. * @param string $passwd
  354. * @return string xml/json
  355. */
  356. private static function personCheck($format,$login,$passwd) {
  357. if($login<>'') {
  358. if(OC_User::login($login, $passwd)) {
  359. $xml['person']['personid']=$login;
  360. echo(OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'person', 'check', 2));
  361. }else{
  362. echo(OC_OCS::generatexml($format, 'failed', 102, 'login not valid'));
  363. }
  364. }else{
  365. echo(OC_OCS::generatexml($format, 'failed', 101, 'please specify all mandatory fields'));
  366. }
  367. }
  368. // ACTIVITY API #############################################
  369. /**
  370. * get my activities
  371. * @param string $format
  372. * @param string $page
  373. * @param string $pagesize
  374. * @return string xml/json
  375. */
  376. private static function activityGet($format, $page, $pagesize) {
  377. $user=OC_OCS::checkpassword();
  378. //TODO
  379. $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'activity', 'full', 2, $totalcount,$pagesize);
  380. echo($txt);
  381. }
  382. /**
  383. * submit a activity
  384. * @param string $format
  385. * @param string $message
  386. * @return string xml/json
  387. */
  388. private static function activityPut($format,$message) {
  389. // not implemented in ownCloud
  390. $user=OC_OCS::checkpassword();
  391. echo(OC_OCS::generatexml($format, 'ok', 100, ''));
  392. }
  393. // PRIVATEDATA API #############################################
  394. /**
  395. * get private data and create the xml for ocs
  396. * @param string $format
  397. * @param string $app
  398. * @param string $key
  399. * @return string xml/json
  400. */
  401. private static function privateDataGet($format, $app="", $key="") {
  402. $user=OC_OCS::checkpassword();
  403. $result=OC_OCS::getData($user, $app, $key);
  404. $xml=array();
  405. foreach($result as $i=>$log) {
  406. $xml[$i]['key']=$log['key'];
  407. $xml[$i]['app']=$log['app'];
  408. $xml[$i]['value']=$log['value'];
  409. }
  410. $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
  411. echo($txt);
  412. }
  413. /**
  414. * set private data referenced by $key to $value and generate the xml for ocs
  415. * @param string $format
  416. * @param string $app
  417. * @param string $key
  418. * @param string $value
  419. * @return string xml/json
  420. */
  421. private static function privateDataSet($format, $app, $key, $value) {
  422. $user=OC_OCS::checkpassword();
  423. if(OC_OCS::setData($user, $app, $key, $value)) {
  424. echo(OC_OCS::generatexml($format, 'ok', 100, ''));
  425. }
  426. }
  427. /**
  428. * delete private data referenced by $key and generate the xml for ocs
  429. * @param string $format
  430. * @param string $app
  431. * @param string $key
  432. * @return string xml/json
  433. */
  434. private static function privateDataDelete($format, $app, $key) {
  435. if($key=="" or $app=="") {
  436. return; //key and app are NOT optional here
  437. }
  438. $user=OC_OCS::checkpassword();
  439. if(OC_OCS::deleteData($user, $app, $key)) {
  440. echo(OC_OCS::generatexml($format, 'ok', 100, ''));
  441. }
  442. }
  443. /**
  444. * get private data
  445. * @param string $user
  446. * @param string $app
  447. * @param string $key
  448. * @param bool $like use LIKE instead of = when comparing keys
  449. * @return array
  450. */
  451. public static function getData($user, $app="", $key="") {
  452. if($app) {
  453. $apps=array($app);
  454. }else{
  455. $apps=OC_Preferences::getApps($user);
  456. }
  457. if($key) {
  458. $keys=array($key);
  459. }else{
  460. foreach($apps as $app) {
  461. $keys=OC_Preferences::getKeys($user, $app);
  462. }
  463. }
  464. $result=array();
  465. foreach($apps as $app) {
  466. foreach($keys as $key) {
  467. $value=OC_Preferences::getValue($user, $app, $key);
  468. $result[]=array('app'=>$app, 'key'=>$key, 'value'=>$value);
  469. }
  470. }
  471. return $result;
  472. }
  473. /**
  474. * set private data referenced by $key to $value
  475. * @param string $user
  476. * @param string $app
  477. * @param string $key
  478. * @param string $value
  479. * @return bool
  480. */
  481. public static function setData($user, $app, $key, $value) {
  482. return OC_Preferences::setValue($user, $app, $key, $value);
  483. }
  484. /**
  485. * delete private data referenced by $key
  486. * @param string $user
  487. * @param string $app
  488. * @param string $key
  489. * @return string xml/json
  490. */
  491. public static function deleteData($user, $app, $key) {
  492. return OC_Preferences::deleteKey($user, $app, $key);
  493. }
  494. // CLOUD API #############################################
  495. /**
  496. * get a list of installed web apps
  497. * @param string $format
  498. * @return string xml/json
  499. */
  500. private static function systemWebApps($format) {
  501. $login=OC_OCS::checkpassword();
  502. $apps=OC_App::getEnabledApps();
  503. $values=array();
  504. foreach($apps as $app) {
  505. $info=OC_App::getAppInfo($app);
  506. if(isset($info['standalone'])) {
  507. $newvalue=array('name'=>$info['name'],'url'=>OC_Helper::linkToAbsolute($app,''),'icon'=>'');
  508. $values[]=$newvalue;
  509. }
  510. }
  511. $txt=OC_OCS::generatexml($format, 'ok', 100, '', $values, 'cloud', '', 2, 0, 0);
  512. echo($txt);
  513. }
  514. /**
  515. * get the quota of a user
  516. * @param string $format
  517. * @param string $user
  518. * @return string xml/json
  519. */
  520. private static function quotaGet($format,$user) {
  521. $login=OC_OCS::checkpassword();
  522. if(OC_Group::inGroup($login, 'admin') or ($login==$user)) {
  523. if(OC_User::userExists($user)) {
  524. // calculate the disc space
  525. $user_dir = '/'.$user.'/files';
  526. OC_Filesystem::init($user_dir);
  527. $rootInfo=OC_FileCache::get('');
  528. $sharedInfo=OC_FileCache::get('/Shared');
  529. $used=$rootInfo['size']-$sharedInfo['size'];
  530. $free=OC_Filesystem::free_space();
  531. $total=$free+$used;
  532. if($total==0) $total=1; // prevent division by zero
  533. $relative=round(($used/$total)*10000)/100;
  534. $xml=array();
  535. $xml['quota']=$total;
  536. $xml['free']=$free;
  537. $xml['used']=$used;
  538. $xml['relative']=$relative;
  539. $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0);
  540. echo($txt);
  541. }else{
  542. echo self::generateXml('', 'fail', 300, 'User does not exist');
  543. }
  544. }else{
  545. echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
  546. }
  547. }
  548. /**
  549. * set the quota of a user
  550. * @param string $format
  551. * @param string $user
  552. * @param string $quota
  553. * @return string xml/json
  554. */
  555. private static function quotaSet($format,$user,$quota) {
  556. $login=OC_OCS::checkpassword();
  557. if(OC_Group::inGroup($login, 'admin')) {
  558. // todo
  559. // not yet implemented
  560. // add logic here
  561. error_log('OCS call: user:'.$user.' quota:'.$quota);
  562. $xml=array();
  563. $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0);
  564. echo($txt);
  565. }else{
  566. echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
  567. }
  568. }
  569. /**
  570. * get the public key of a user
  571. * @param string $format
  572. * @param string $user
  573. * @return string xml/json
  574. */
  575. private static function publicKeyGet($format,$user) {
  576. $login=OC_OCS::checkpassword();
  577. if(OC_User::userExists($user)) {
  578. // calculate the disc space
  579. $txt='this is the public key of '.$user;
  580. echo($txt);
  581. }else{
  582. echo self::generateXml('', 'fail', 300, 'User does not exist');
  583. }
  584. }
  585. /**
  586. * get the private key of a user
  587. * @param string $format
  588. * @param string $user
  589. * @return string xml/json
  590. */
  591. private static function privateKeyGet($format,$user) {
  592. $login=OC_OCS::checkpassword();
  593. if(OC_Group::inGroup($login, 'admin') or ($login==$user)) {
  594. if(OC_User::userExists($user)) {
  595. // calculate the disc space
  596. $txt='this is the private key of '.$user;
  597. echo($txt);
  598. }else{
  599. echo self::generateXml('', 'fail', 300, 'User does not exist');
  600. }
  601. }else{
  602. echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
  603. }
  604. }
  605. }