Zachary Kotlarek 12 лет назад
Родитель
Сommit
96d11c8021
1 измененных файлов с 63 добавлено и 1 удалено
  1. 63 1
      backup/opendrive.php

+ 63 - 1
backup/opendrive.php

@@ -30,10 +30,12 @@ function dbOpen() {
 function curlPost($url, $data) {
 function curlPost($url, $data) {
 	global $API_BASE;
 	global $API_BASE;
 	global $CA_PATH;
 	global $CA_PATH;
+	global $DEBUG;
 
 
 	# Setup cURL
 	# Setup cURL
 	$ch = curl_init($API_BASE . $url);
 	$ch = curl_init($API_BASE . $url);
 	curl_setopt_array($ch, array(
 	curl_setopt_array($ch, array(
+		CURLOPT_VERBOSE => $DEBUG,
 		CURLOPT_CAINFO => $CA_PATH,
 		CURLOPT_CAINFO => $CA_PATH,
 		CURLOPT_POST => true,
 		CURLOPT_POST => true,
 		CURLOPT_RETURNTRANSFER => true,
 		CURLOPT_RETURNTRANSFER => true,
@@ -56,6 +58,33 @@ function curlPost($url, $data) {
 	return($responseData);
 	return($responseData);
 }
 }
 
 
+# GET from OpenDrive
+function curlGet($url) {
+	global $API_BASE;
+	global $CA_PATH;
+	global $DEBUG;
+
+	# Setup cURL
+	$ch = curl_init($API_BASE . $url);
+	curl_setopt_array($ch, array(
+		CURLOPT_VERBOSE => $DEBUG,
+		CURLOPT_CAINFO => $CA_PATH,
+		CURLOPT_RETURNTRANSFER => true
+	));
+
+	# Send the request
+	$response = curl_exec($ch);
+
+	# Check for errors
+	if ($response === FALSE){
+	    die(curl_error($ch));
+	}
+
+	# Return
+	$responseData = json_decode($response, TRUE);
+	return($responseData);
+}
+
 # Login to OD and return the SessionID
 # Login to OD and return the SessionID
 function login() {
 function login() {
 	global $API_VERSION;
 	global $API_VERSION;
@@ -89,7 +118,7 @@ function logout($session) {
 	return false;
 	return false;
 }
 }
 
 
-# Return the ID of a folder path
+# Return the ID of a folder
 function folderID($session, $path) {
 function folderID($session, $path) {
 	$data = array(
 	$data = array(
 		'session_id'	=> $session,
 		'session_id'	=> $session,
@@ -135,6 +164,7 @@ function mkFolder($session, $path) {
 	return false;
 	return false;
 }
 }
 
 
+# Trash a folder
 function rmFolder($session, $path) {
 function rmFolder($session, $path) {
 	$id = folderID($session, $path);
 	$id = folderID($session, $path);
 	if (!$id) {
 	if (!$id) {
@@ -154,4 +184,36 @@ function rmFolder($session, $path) {
 	return false;
 	return false;
 }
 }
 
 
+# Return the ID of a file
+function fileID($session, $path) {
+	$data = array(
+		'session_id'	=> $session,
+		'path'		=> $path
+	);
+	$response = curlPost('/file/idbypath.json', $data);
+
+	# Check the result
+	if ($response['FileId']) {
+		return($response['FileId']);
+	}
+	return false;
+}
+
+# Return all file metadata
+function fileInfo($session, $path) {
+	$id = fileID($session, $path);
+	if (!$id) {
+		return false;
+	}
+
+	# GET
+	$response = curlGet('/file/info.json/' . $session . '/' . $id);
+
+	# Check the result
+	if ($response['FileId']) {
+		return($response);
+	}
+	return false;
+}
+
 ?>
 ?>