Esempio n. 1
0
 /**
 	main function to handle the REST request
 	**/
 public static function handle()
 {
     // overwrite the 404 error page returncode
     header("HTTP/1.0 200 OK");
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         $method = 'get';
     } elseif ($_SERVER['REQUEST_METHOD'] == 'PUT') {
         $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;
     }
     // preprocess url
     $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);
         // 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);
         // PRIVATEDATA
         // get - GET DATA
     } elseif ($method == 'get' and $ex[$paracount - 4] == 'v1.php' and $ex[$paracount - 2] == 'getattribute') {
         OC_OCS::privateDataGet($format);
     } elseif ($method == 'get' and $ex[$paracount - 5] == 'v1.php' and $ex[$paracount - 3] == 'getattribute') {
         $app = $ex[$paracount - 2];
         OC_OCS::privateDataGet($format, $app);
     } elseif ($method == 'get' and $ex[$paracount - 6] == 'v1.php' and $ex[$paracount - 4] == 'getattribute') {
         $key = $ex[$paracount - 2];
         $app = $ex[$paracount - 3];
         OC_OCS::privateDataGet($format, $app, $key);
         // set - POST DATA
     } elseif ($method == 'post' and $ex[$paracount - 6] == 'v1.php' and $ex[$paracount - 4] == 'setattribute') {
         $key = $ex[$paracount - 2];
         $app = $ex[$paracount - 3];
         $value = self::readData($method, 'value', 'text');
         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);
         // CLOUD
         // systemWebApps
     } elseif ($method == 'get' and $ex[$paracount - 5] == 'v1.php' and $ex[$paracount - 4] == 'cloud' and $ex[$paracount - 3] == 'system' and $ex[$paracount - 2] == 'webapps') {
         OC_OCS::systemwebapps($format);
         // quotaget
     } elseif ($method == 'get' and $ex[$paracount - 6] == 'v1.php' and $ex[$paracount - 5] == 'cloud' and $ex[$paracount - 4] == 'user' and $ex[$paracount - 2] == 'quota') {
         $user = $ex[$paracount - 3];
         OC_OCS::quotaget($format, $user);
         // quotaset
     } elseif ($method == 'post' and $ex[$paracount - 6] == 'v1.php' and $ex[$paracount - 5] == 'cloud' and $ex[$paracount - 4] == 'user' and $ex[$paracount - 2] == 'quota') {
         $user = $ex[$paracount - 3];
         $quota = self::readData('post', 'quota', 'int');
         OC_OCS::quotaset($format, $user, $quota);
         // keygetpublic
     } elseif ($method == 'get' and $ex[$paracount - 6] == 'v1.php' and $ex[$paracount - 5] == 'cloud' and $ex[$paracount - 4] == 'user' and $ex[$paracount - 2] == 'publickey') {
         $user = $ex[$paracount - 3];
         OC_OCS::publicKeyGet($format, $user);
         // keygetprivate
     } elseif ($method == 'get' and $ex[$paracount - 6] == 'v1.php' and $ex[$paracount - 5] == 'cloud' and $ex[$paracount - 4] == 'user' and $ex[$paracount - 2] == 'privatekey') {
         $user = $ex[$paracount - 3];
         OC_OCS::privateKeyGet($format, $user);
         // add more calls here
         // please document all the call in the draft spec
         // http://www.freedesktop.org/wiki/Specifications/open-collaboration-services-1.7#CLOUD
         // TODO:
         // users
         // groups
         // bookmarks
         // sharing
         // versioning
         // news (rss)
     } else {
         $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;
 }