]> source.dussan.org Git - nextcloud-server.git/commitdiff
API: Remove old code. Move remaining methods to OC_OCS_Result.
authorTom Needham <needham.thomas@gmail.com>
Wed, 12 Dec 2012 18:06:07 +0000 (18:06 +0000)
committerTom Needham <needham.thomas@gmail.com>
Wed, 12 Dec 2012 18:06:07 +0000 (18:06 +0000)
lib/ocs.php
lib/ocs/cloud.php
lib/ocs/config.php
lib/ocs/privatedata.php
ocs/routes.php

index 1cec3ecc7c083cd2af5293195cdec6dcfc435db6..001965d45e3356e486f0c14f61176783d630506f 100644 (file)
@@ -103,44 +103,6 @@ class OC_OCS {
                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);
-       }
-
 
        /**
        * generates the xml or json response for the API call from an multidimenional data array.
@@ -261,130 +223,6 @@ class OC_OCS {
                }
        }
 
-       /**
-       * return the config data of this server
-       * @param string $format
-       * @return string xml/json
-       */
-       public static function apiConfig($parameters) {
-               $format = $parameters['format'];
-               $user=OC_OCS::checkpassword(false);
-               $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'], 0, -11).'';
-
-               $xml['version']='1.7';
-               $xml['website']='ownCloud';
-               $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
-       * @param string $format
-       * @param string $login
-       * @param string $passwd
-       * @return string xml/json
-       */
-       private static function personCheck($format,$login,$passwd) {
-               if($login<>'') {
-                       if(OC_User::login($login, $passwd)) {
-                               $xml['person']['personid']=$login;
-                               echo(OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'person', 'check', 2));
-                       }else{
-                               echo(OC_OCS::generatexml($format, 'failed', 102, 'login not valid'));
-                       }
-               }else{
-                       echo(OC_OCS::generatexml($format, 'failed', 101, 'please specify all mandatory fields'));
-               }
-       }
-
-       // ACTIVITY API #############################################
-
-       /**
-       * get my activities
-       * @param string $format
-       * @param string $page
-       * @param string $pagesize
-       * @return string xml/json
-       */
-       private static function activityGet($format, $page, $pagesize) {
-               $user=OC_OCS::checkpassword();
-
-                       //TODO
-
-               $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'activity', 'full', 2, $totalcount,$pagesize);
-               echo($txt);
-       }
-
-       /**
-       * 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
-       * @param string $key
-       * @return string xml/json
-       */
-       private static function privateDataGet($format, $app="", $key="") {
-               $user=OC_OCS::checkpassword();
-               $result=OC_OCS::getData($user, $app, $key);
-               $xml=array();
-               foreach($result as $i=>$log) {
-                       $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
-               echo($txt);
-       }
-
-       /**
-       * set private data referenced by $key to $value and generate the xml for ocs
-       * @param string $format
-       * @param string $app
-       * @param string $key
-       * @param string $value
-       * @return string xml/json
-       */
-       private static function privateDataSet($format, $app, $key, $value) {
-               $user=OC_OCS::checkpassword();
-               if(OC_OCS::setData($user, $app, $key, $value)) {
-                       echo(OC_OCS::generatexml($format, 'ok', 100, ''));
-               }
-       }
-
-       /**
-       * delete private data referenced by $key and generate the xml for ocs
-       * @param string $format
-       * @param string $app
-       * @param string $key
-       * @return string xml/json
-       */
-       private static function privateDataDelete($format, $app, $key) {
-               if($key=="" or $app=="") {
-                       return; //key and app are NOT optional here
-               }
-               $user=OC_OCS::checkpassword();
-               if(OC_OCS::deleteData($user, $app, $key)) {
-                       echo(OC_OCS::generatexml($format, 'ok', 100, ''));
-               }
-       }
-
        /**
        * get private data
        * @param string $user
@@ -416,93 +254,6 @@ class OC_OCS {
                return $result;
        }
 
-       /**
-       * set private data referenced by $key to $value
-       * @param string $user
-       * @param string $app
-       * @param string $key
-       * @param string $value
-       * @return bool
-       */
-       public static function setData($user, $app, $key, $value) {
-               return OC_Preferences::setValue($user, $app, $key, $value);
-       }
-
-       /**
-       * delete private data referenced by $key
-       * @param string $user
-       * @param string $app
-       * @param string $key
-       * @return string xml/json
-       */
-       public static function deleteData($user, $app, $key) {
-               return OC_Preferences::deleteKey($user, $app, $key);
-       }
-
-
-        // CLOUD API #############################################
-
-        /**
-        * get a list of installed web apps
-        * @param string $format
-        * @return string xml/json
-        */
-        private static function systemWebApps($format) {
-                $login=OC_OCS::checkpassword();
-               $apps=OC_App::getEnabledApps();
-               $values=array();
-               foreach($apps as $app) {
-                       $info=OC_App::getAppInfo($app);
-                       if(isset($info['standalone'])) {
-                               $newvalue=array('name'=>$info['name'],'url'=>OC_Helper::linkToAbsolute($app,''),'icon'=>'');
-                               $values[]=$newvalue;
-                       }
-
-               }
-               $txt=OC_OCS::generatexml($format, 'ok', 100, '', $values, 'cloud', '', 2, 0, 0);
-               echo($txt);
-
-        }
-
-
-        /**
-        * get the quota of a user
-        * @param string $format
-        * @param string $user
-        * @return string xml/json
-        */
-        private static function quotaGet($format,$user) {
-                $login=OC_OCS::checkpassword();
-               if(OC_Group::inGroup($login, 'admin') or ($login==$user)) {
-
-                       if(OC_User::userExists($user)) {
-                               // 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', '', 1, 0, 0);
-                               echo($txt);
-                       }else{
-                               echo self::generateXml('', 'fail', 300, 'User does not exist');
-                       }
-               }else{
-                       echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
-               }
-        }
-
         /**
         * set the quota of a user
         * @param string $format
@@ -527,45 +278,4 @@ class OC_OCS {
                 }
         }
 
-        /**
-        * get the public key of a user
-        * @param string $format
-        * @param string $user
-        * @return string xml/json
-        */
-        private static function publicKeyGet($format,$user) {
-                $login=OC_OCS::checkpassword();
-
-               if(OC_User::userExists($user)) {
-                       // calculate the disc space
-                       $txt='this is the public key of '.$user;
-                       echo($txt);
-               }else{
-                       echo self::generateXml('', 'fail', 300, 'User does not exist');
-               }
-       }
-
-        /**
-        * get the private key of a user
-        * @param string $format
-        * @param string $user
-        * @return string xml/json
-        */
-        private static function privateKeyGet($format,$user) {
-                $login=OC_OCS::checkpassword();
-                if(OC_Group::inGroup($login, 'admin') or ($login==$user)) {
-
-                        if(OC_User::userExists($user)) {
-                                // calculate the disc space
-                                $txt='this is the private key of '.$user;
-                                echo($txt);
-                        }else{
-                                echo self::generateXml('', 'fail', 300, 'User does not exist');
-                        }
-                }else{
-                        echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
-                }
-        }
-
-
 }
index 720cc0ade39678e7087bbd97fd2f612383ec1647..b5cfbc295e87eff71a195787fa45db42ad08b715 100644 (file)
@@ -17,7 +17,6 @@ class OC_OCS_Cloud {
        }
        
        public static function getUserQuota($parameters){
-               OC_Util::checkLoggedIn();
                $user = OC_User::getUser();
                if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) {
 
@@ -41,44 +40,25 @@ class OC_OCS_Cloud {
 
                                return new OC_OCS_Result($xml);
                        }else{
-                               return 300;
+                               return new OC_OCS_Result(null, 300);
                        }
                }else{
-                       return 300;
-               }
-       }
-       
-       public static function setUserQuota($parameters){
-               OC_Util::checkLoggedIn();
-               $user = OC_User::getUser();
-               if(OC_Group::inGroup($user, 'admin')) {
-               
-                       // todo
-                       // not yet implemented
-                       // add logic here
-                       error_log('OCS call: user:'.$parameters['user'].' quota:'.$parameters['quota']);
-                       
-                       $xml=array();
-                       return $xml;
-               }else{
-                       return 300;
+                       return new OC_OCS_Result(null, 300);
                }
        }
        
        public static function getUserPublickey($parameters){
-               OC_Util::checkLoggedIn();
 
                if(OC_User::userExists($parameters['user'])){
                        // calculate the disc space
                        // TODO
-                       return array();
+                       return new OC_OCS_Result(array());
                }else{
-                       return 300;
+                       return new OC_OCS_Result(null, 300);
                }
        }
        
        public static function getUserPrivatekey($parameters){
-               OC_Util::checkLoggedIn();
                $user = OC_User::getUser();
                if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) {
 
@@ -87,10 +67,10 @@ class OC_OCS_Cloud {
                                $txt='this is the private key of '.$parameters['user'];
                                echo($txt);
                        }else{
-                               echo self::generateXml('', 'fail', 300, 'User does not exist');
+                               return new OC_OCS_Result(null, 300, 'User does not exist');
                        }
                }else{
-                       echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
+                       return new OC_OCS_Result('null', 300, 'You don´t have permission to access this ressource.');
                }
        }
 }
index eb9e470381a9e4481f61b15cb101a4fc5d6eba6c..52affcd65ee6e67008a4977d64f73c484910cfb7 100644 (file)
@@ -10,4 +10,5 @@ class OC_OCS_Config {
                $xml['ssl'] = 'false';
                return new OC_OCS_Result($xml);
        }
+       
 }
index 02ca31f2d29f29bd0b359c2e650f3991309d59ed..09d636bd7331af501ad5fe05aa9ccea10f190b99 100644 (file)
@@ -8,7 +8,7 @@ class OC_OCS_Privatedata {
                $app = addslashes(strip_tags($parameters['app']));
                $key = addslashes(strip_tags($parameters['key']));
                $result = OC_OCS::getData($user,$app,$key);
-               $xml array();
+               $xml = array();
                foreach($result as $i=>$log) {
                        $xml[$i]['key']=$log['key'];
                        $xml[$i]['app']=$log['app'];
@@ -24,7 +24,7 @@ class OC_OCS_Privatedata {
                $app = addslashes(strip_tags($parameters['app']));
                $key = addslashes(strip_tags($parameters['key']));
                $value = OC_OCS::readData('post', 'value', 'text');
-               if(OC_OCS::setData($user,$app,$key,$value)){
+               if(OC_Preferences::setValue($user,$app,$key,$value)){
                        return new OC_OCS_Result(null, 100);
                }
        }
@@ -37,7 +37,7 @@ class OC_OCS_Privatedata {
                if($key=="" or $app==""){
                        return new OC_OCS_Result(null, 101); //key and app are NOT optional here
                }
-               if(OC_OCS::deleteData($user,$app,$key)){
+               if(OC_Preferences::deleteKey($user,$app,$key)){
                        return new OC_OCS_Result(null, 100);
                }
        }
index 6b01abe31f2e4141c56e8273863ce88a06d2f899..033d9b79df28aad028736eca29ce7109abece9ed 100644 (file)
@@ -10,7 +10,13 @@ OC_API::register('get', '/config', array('OC_OCS_Config', 'apiConfig'), 'ocs', O
 // Person
 OC_API::register('post', '/person/check', array('OC_OCS_Person', 'check'), 'ocs', OC_API::GUEST_AUTH);
 // Activity
-OC_API::register('get', '/activity', array('OC_OCS_Activity', 'activityGet'), 'ocs', OC_API::USER_AUTH);
+OC_API::register('get', '/activity', array('OC_OCS_Activity', 'activityGet'), 'ocs', OC_API::USER_AUTH); 
+
+
+//activity put, keygetpublic, keygetprivate
+
+
+
 // Privatedata
 OC_API::register('get', '/privatedata/getattribute', array('OC_OCS_Privatedata', 'get'), 'ocs', OC_API::USER_AUTH, array('app' => '', 'key' => ''));
 OC_API::register('get', '/privatedata/getattribute/{app}', array('OC_OCS_Privatedata', 'get'), 'ocs', OC_API::USER_AUTH, array('key' => ''));