From 9072106048265ce144227605c8919104acf6d746 Mon Sep 17 00:00:00 2001
From: Tom Needham <tom@owncloud.com>
Date: Mon, 30 Jul 2012 12:42:18 +0000
Subject: [PATCH] Move OCS methods to lib/ocs/.php

---
 lib/api.php             |  2 +-
 lib/ocs/activity.php    | 11 +++++
 lib/ocs/cloud.php       | 97 +++++++++++++++++++++++++++++++++++++++++
 lib/ocs/config.php      | 16 +++++++
 lib/ocs/person.php      | 22 ++++++++++
 lib/ocs/privatedata.php | 37 ++++++++++++++++
 6 files changed, 184 insertions(+), 1 deletion(-)
 create mode 100644 lib/ocs/activity.php
 create mode 100644 lib/ocs/cloud.php
 create mode 100644 lib/ocs/config.php
 create mode 100644 lib/ocs/person.php
 create mode 100644 lib/ocs/privatedata.php

diff --git a/lib/api.php b/lib/api.php
index b1176a0707..2203d86ac9 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -62,7 +62,7 @@ class OC_API {
 			}
 		}
 		// include core routes
-		require_once(OC::$SERVERROOT.'core/routes.php');
+		require_once(OC::$SERVERROOT.'ocs/routes.php');
 		
 		$name = $parameters['_name'];
 		$response = array();
diff --git a/lib/ocs/activity.php b/lib/ocs/activity.php
new file mode 100644
index 0000000000..3b090376e7
--- /dev/null
+++ b/lib/ocs/activity.php
@@ -0,0 +1,11 @@
+<?php
+
+class OC_OCS_Activity {
+
+	public static function activityGet($parameters){
+		// TODO
+	}
+	
+}
+
+?>
\ No newline at end of file
diff --git a/lib/ocs/cloud.php b/lib/ocs/cloud.php
new file mode 100644
index 0000000000..d0cd72e98c
--- /dev/null
+++ b/lib/ocs/cloud.php
@@ -0,0 +1,97 @@
+<?php
+
+class OC_OCS_Cloud {
+
+	public static function systemwebapps($parameters){
+		$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;
+			}
+		}
+		return $values;
+	}
+	
+	public static function getQuota($parameters){
+		$login=OC_OCS::checkpassword();
+		if(OC_Group::inGroup($login, 'admin') or ($login==$parameters['user'])) {
+
+			if(OC_User::userExists($parameters['user'])){
+				// calculate the disc space
+				$user_dir = '/'.$parameters['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;
+
+				return $xml;
+			}else{
+				return 300;
+			}
+		}else{
+			return 300;
+		}
+	}
+	
+	public static function setQuota($parameters){
+		$login=OC_OCS::checkpassword();
+		if(OC_Group::inGroup($login, '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;
+		}
+	}
+	
+	public static function getPublickey($parameters){
+		$login=OC_OCS::checkpassword();
+
+		if(OC_User::userExists($parameters['user'])){
+			// calculate the disc space
+			// TODO
+			return array();
+		}else{
+			return 300;
+		}
+	}
+	
+	public static function getPrivatekey($parameters){
+		$login=OC_OCS::checkpassword();
+        if(OC_Group::inGroup($login, 'admin') or ($login==$parameters['user'])) {
+
+                if(OC_User::userExists($user)){
+                        // calculate the disc space
+                        $txt='this is the private key of '.$parameters['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.');
+        }
+	}
+	
+	
+}
+
+?>
\ No newline at end of file
diff --git a/lib/ocs/config.php b/lib/ocs/config.php
new file mode 100644
index 0000000000..b736abe3b9
--- /dev/null
+++ b/lib/ocs/config.php
@@ -0,0 +1,16 @@
+<?php
+
+class OC_OCS_Config {
+	
+	public static function apiConfig($parameters){
+		$xml['version'] = '1.7';
+		$xml['website'] = 'ownCloud';
+		$xml['host'] = OCP\Util::getServerHost();
+		$xml['contact'] = '';
+		$xml['ssl'] = 'false';
+		return $xml;
+	}
+	
+}
+
+?>
\ No newline at end of file
diff --git a/lib/ocs/person.php b/lib/ocs/person.php
new file mode 100644
index 0000000000..f4e4be5ee0
--- /dev/null
+++ b/lib/ocs/person.php
@@ -0,0 +1,22 @@
+<?php
+
+class OC_OCS_Person {
+
+	public static function check($parameters){
+	
+		if($parameters['login']<>''){
+			if(OC_User::login($parameters['login'],$parameters['password'])){
+				$xml['person']['personid'] = $parameters['login'];
+				return $xml;
+			}else{
+				return 102;
+			}
+		}else{
+			return 101;
+		}
+		
+	}
+	
+}
+
+?>
\ No newline at end of file
diff --git a/lib/ocs/privatedata.php b/lib/ocs/privatedata.php
new file mode 100644
index 0000000000..cb62d60a8d
--- /dev/null
+++ b/lib/ocs/privatedata.php
@@ -0,0 +1,37 @@
+<?php
+
+class OC_OCS_Privatedata {
+
+	public static function privatedataGet($parameters){
+		$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'];
+		}
+		return $xml;
+		//TODO: replace 'privatedata' with 'attribute' once a new libattice has been released that works with it
+	}
+	
+	public static function privatedataSet($parameters){
+		$user = OC_OCS::checkpassword();
+		if(OC_OCS::setData($user,$app,$key,$value)){
+			return 100;
+		}
+	}
+	
+	public static function privatedataDelete($parameteres){
+		$user = OC_OCS::checkpassword();
+		if($key=="" or $app==""){
+			return; //key and app are NOT optional here
+		}
+		if(OC_OCS::deleteData($user,$app,$key)){
+			return 100;
+		}
+	}
+	
+}
+
+?>
\ No newline at end of file
-- 
GitLab