Merge pull request #6146 from nextcloud/downstream-28073
Downstream - removal of outdated API
This commit is contained in:
commit
f0eb882c2e
23 changed files with 1 additions and 6155 deletions
550
apps/files_external/3rdparty/Dropbox/API.php
vendored
550
apps/files_external/3rdparty/Dropbox/API.php
vendored
|
@ -1,550 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox API class
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
class Dropbox_API {
|
||||
|
||||
/**
|
||||
* Sandbox root-path
|
||||
*/
|
||||
const ROOT_SANDBOX = 'sandbox';
|
||||
|
||||
/**
|
||||
* Dropbox root-path
|
||||
*/
|
||||
const ROOT_DROPBOX = 'dropbox';
|
||||
|
||||
/**
|
||||
* API URl
|
||||
*/
|
||||
protected $api_url = 'https://api.dropbox.com/1/';
|
||||
|
||||
/**
|
||||
* Content API URl
|
||||
*/
|
||||
protected $api_content_url = 'https://api-content.dropbox.com/1/';
|
||||
|
||||
/**
|
||||
* OAuth object
|
||||
*
|
||||
* @var Dropbox_OAuth
|
||||
*/
|
||||
protected $oauth;
|
||||
|
||||
/**
|
||||
* Default root-path, this will most likely be 'sandbox' or 'dropbox'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $root;
|
||||
protected $useSSL;
|
||||
|
||||
/**
|
||||
* PHP is Safe Mode
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isSafeMode;
|
||||
|
||||
/**
|
||||
* Chunked file size limit
|
||||
*
|
||||
* @var unknown
|
||||
*/
|
||||
public $chunkSize = 20971520; //20MB
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Dropbox_OAuth Dropbox_Auth object
|
||||
* @param string $root default root path (sandbox or dropbox)
|
||||
*/
|
||||
public function __construct(Dropbox_OAuth $oauth, $root = self::ROOT_DROPBOX, $useSSL = true) {
|
||||
|
||||
$this->oauth = $oauth;
|
||||
$this->root = $root;
|
||||
$this->useSSL = $useSSL;
|
||||
$this->isSafeMode = (version_compare(PHP_VERSION, '5.4', '<') && get_cfg_var('safe_mode'));
|
||||
if (!$this->useSSL)
|
||||
{
|
||||
throw new Dropbox_Exception('Dropbox REST API now requires that all requests use SSL');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the current dropbox account
|
||||
*
|
||||
* @return stdclass
|
||||
*/
|
||||
public function getAccountInfo() {
|
||||
|
||||
$data = $this->oauth->fetch($this->api_url . 'account/info');
|
||||
return json_decode($data['body'],true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file's contents
|
||||
*
|
||||
* @param string $path path
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return string
|
||||
*/
|
||||
public function getFile($path = '', $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
$result = $this->oauth->fetch($this->api_content_url . 'files/' . $root . '/' . ltrim($path,'/'));
|
||||
return $result['body'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a new file
|
||||
*
|
||||
* @param string $path Target path (including filename)
|
||||
* @param string $file Either a path to a file or a stream resource
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return bool
|
||||
*/
|
||||
public function putFile($path, $file, $root = null) {
|
||||
|
||||
if (is_resource($file)) {
|
||||
$stat = fstat($file);
|
||||
$size = $stat['size'];
|
||||
} else if (is_string($file) && is_readable($file)) {
|
||||
$size = filesize($file);
|
||||
} else {
|
||||
throw new Dropbox_Exception('File must be a file-resource or a file path string');
|
||||
}
|
||||
|
||||
if ($this->oauth->isPutSupport()) {
|
||||
if ($size) {
|
||||
if ($size > $this->chunkSize) {
|
||||
$res = array('uploadID' => null, 'offset' => 0);
|
||||
$i[$res['offset']] = 0;
|
||||
while($i[$res['offset']] < 5) {
|
||||
$res = $this->chunkedUpload($path, $file, $root, true, $res['offset'], $res['uploadID']);
|
||||
if (isset($res['uploadID'])) {
|
||||
if (!isset($i[$res['offset']])) {
|
||||
$i[$res['offset']] = 0;
|
||||
} else {
|
||||
$i[$res['offset']]++;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return $this->putStream($path, $file, $root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($size > 157286400) {
|
||||
// Dropbox API /files has a maximum file size limit of 150 MB.
|
||||
// https://www.dropbox.com/developers/core/docs#files-POST
|
||||
throw new Dropbox_Exception("Uploading file to Dropbox failed");
|
||||
}
|
||||
|
||||
$directory = dirname($path);
|
||||
$filename = basename($path);
|
||||
|
||||
if($directory==='.') $directory = '';
|
||||
$directory = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($directory));
|
||||
$filename = str_replace('~', '%7E', rawurlencode($filename));
|
||||
if (is_null($root)) $root = $this->root;
|
||||
|
||||
if (is_string($file)) {
|
||||
|
||||
$file = fopen($file,'rb');
|
||||
|
||||
} elseif (!is_resource($file)) {
|
||||
throw new Dropbox_Exception('File must be a file-resource or a file path string');
|
||||
}
|
||||
|
||||
if (!$this->isSafeMode) {
|
||||
set_time_limit(600);
|
||||
}
|
||||
$result=$this->multipartFetch($this->api_content_url . 'files/' .
|
||||
$root . '/' . trim($directory,'/'), $file, $filename);
|
||||
|
||||
if(!isset($result["httpStatus"]) || $result["httpStatus"] != 200)
|
||||
throw new Dropbox_Exception("Uploading file to Dropbox failed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads large files to Dropbox in mulitple chunks
|
||||
*
|
||||
* @param string $file Absolute path to the file to be uploaded
|
||||
* @param string|bool $filename The destination filename of the uploaded file
|
||||
* @param string $path Path to upload the file to, relative to root
|
||||
* @param boolean $overwrite Should the file be overwritten? (Default: true)
|
||||
* @return stdClass
|
||||
*/
|
||||
public function chunkedUpload($path, $handle, $root = null, $overwrite = true, $offset = 0, $uploadID = null)
|
||||
{
|
||||
if (is_string($handle) && is_readable($handle)) {
|
||||
$handle = fopen($handle, 'rb');
|
||||
}
|
||||
|
||||
if (is_resource($handle)) {
|
||||
// Seek to the correct position on the file pointer
|
||||
fseek($handle, $offset);
|
||||
|
||||
// Read from the file handle until EOF, uploading each chunk
|
||||
while ($data = fread($handle, $this->chunkSize)) {
|
||||
if (!$this->isSafeMode) {
|
||||
set_time_limit(600);
|
||||
}
|
||||
|
||||
// Open a temporary file handle and write a chunk of data to it
|
||||
$chunkHandle = fopen('php://temp', 'rwb');
|
||||
fwrite($chunkHandle, $data);
|
||||
|
||||
// Set the file, request parameters and send the request
|
||||
$this->oauth->setInFile($chunkHandle);
|
||||
$params = array('upload_id' => $uploadID, 'offset' => $offset);
|
||||
|
||||
try {
|
||||
// Attempt to upload the current chunk
|
||||
$res = $this->oauth->fetch($this->api_content_url . 'chunked_upload', $params, 'PUT');
|
||||
$response = json_decode($res['body'], true);
|
||||
} catch (Exception $e) {
|
||||
$res = $this->oauth->getLastResponse();
|
||||
if ($response['httpStatus'] == 400) {
|
||||
// Incorrect offset supplied, return expected offset and upload ID
|
||||
$response = json_decode($res['body'], true);
|
||||
$uploadID = $response['upload_id'];
|
||||
$offset = $response['offset'];
|
||||
return array('uploadID' => $uploadID, 'offset' => $offset);
|
||||
} else {
|
||||
// Re-throw the caught Exception
|
||||
throw $e;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// On subsequent chunks, use the upload ID returned by the previous request
|
||||
if (isset($response['upload_id'])) {
|
||||
$uploadID = $response['upload_id'];
|
||||
}
|
||||
|
||||
// Set the data offset
|
||||
if (isset($response['offset'])) {
|
||||
$offset = $response['offset'];
|
||||
}
|
||||
|
||||
// Close the file handle for this chunk
|
||||
fclose($chunkHandle);
|
||||
}
|
||||
|
||||
// Complete the chunked upload
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
if (is_null($root)) {
|
||||
$root = $this->root;
|
||||
}
|
||||
$params = array('overwrite' => (int) $overwrite, 'upload_id' => $uploadID);
|
||||
return $this->oauth->fetch($this->api_content_url . 'commit_chunked_upload/' .
|
||||
$root . '/' . ltrim($path,'/'), $params, 'POST');
|
||||
} else {
|
||||
throw new Dropbox_Exception('Could not open ' . $handle . ' for reading');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads file data from a stream
|
||||
*
|
||||
* Note: This function is experimental and requires further testing
|
||||
* @param resource $stream A readable stream created using fopen()
|
||||
* @param string $filename The destination filename, including path
|
||||
* @param boolean $overwrite Should the file be overwritten? (Default: true)
|
||||
* @return array
|
||||
*/
|
||||
public function putStream($path, $file, $root = null, $overwrite = true)
|
||||
{
|
||||
if ($this->isSafeMode) {
|
||||
set_time_limit(600);
|
||||
}
|
||||
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
if (is_null($root)) {
|
||||
$root = $this->root;
|
||||
}
|
||||
|
||||
$params = array('overwrite' => (int) $overwrite);
|
||||
$this->oauth->setInfile($file);
|
||||
$result=$this->oauth->fetch($this->api_content_url . 'files_put/' .
|
||||
$root . '/' . ltrim($path,'/'), $params, 'PUT');
|
||||
|
||||
if (!isset($result["httpStatus"]) || $result["httpStatus"] != 200) {
|
||||
throw new Dropbox_Exception("Uploading file to Dropbox failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a file or directory from one location to another
|
||||
*
|
||||
* This method returns the file information of the newly created file.
|
||||
*
|
||||
* @param string $from source path
|
||||
* @param string $to destination path
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return stdclass
|
||||
*/
|
||||
public function copy($from, $to, $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$response = $this->oauth->fetch($this->api_url . 'fileops/copy', array('from_path' => $from, 'to_path' => $to, 'root' => $root), 'POST');
|
||||
|
||||
return json_decode($response['body'],true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new folder
|
||||
*
|
||||
* This method returns the information from the newly created directory
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return stdclass
|
||||
*/
|
||||
public function createFolder($path, $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
|
||||
// Making sure the path starts with a /
|
||||
$path = '/' . ltrim($path,'/');
|
||||
|
||||
$response = $this->oauth->fetch($this->api_url . 'fileops/create_folder', array('path' => $path, 'root' => $root),'POST');
|
||||
return json_decode($response['body'],true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a file or folder.
|
||||
*
|
||||
* This method will return the metadata information from the deleted file or folder, if successful.
|
||||
*
|
||||
* @param string $path Path to new folder
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return array
|
||||
*/
|
||||
public function delete($path, $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$response = $this->oauth->fetch($this->api_url . 'fileops/delete', array('path' => $path, 'root' => $root), 'POST');
|
||||
return json_decode($response['body']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a file or directory to a new location
|
||||
*
|
||||
* This method returns the information from the newly created directory
|
||||
*
|
||||
* @param mixed $from Source path
|
||||
* @param mixed $to destination path
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return stdclass
|
||||
*/
|
||||
public function move($from, $to, $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$response = $this->oauth->fetch($this->api_url . 'fileops/move', array('from_path' => rawurldecode($from), 'to_path' => rawurldecode($to), 'root' => $root), 'POST');
|
||||
|
||||
return json_decode($response['body'],true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns file and directory information
|
||||
*
|
||||
* @param string $path Path to receive information from
|
||||
* @param bool $list When set to true, this method returns information from all files in a directory. When set to false it will only return infromation from the specified directory.
|
||||
* @param string $hash If a hash is supplied, this method simply returns true if nothing has changed since the last request. Good for caching.
|
||||
* @param int $fileLimit Maximum number of file-information to receive
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return array|true
|
||||
*/
|
||||
public function getMetaData($path, $list = true, $hash = null, $fileLimit = null, $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
|
||||
$args = array(
|
||||
'list' => $list,
|
||||
);
|
||||
|
||||
if (!is_null($hash)) $args['hash'] = $hash;
|
||||
if (!is_null($fileLimit)) $args['file_limit'] = $fileLimit;
|
||||
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
$response = $this->oauth->fetch($this->api_url . 'metadata/' . $root . '/' . ltrim($path,'/'), $args);
|
||||
|
||||
/* 304 is not modified */
|
||||
if ($response['httpStatus']==304) {
|
||||
return true;
|
||||
} else {
|
||||
return json_decode($response['body'],true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A way of letting you keep up with changes to files and folders in a user's Dropbox. You can periodically call /delta to get a list of "delta entries", which are instructions on how to update your local state to match the server's state.
|
||||
*
|
||||
* This method returns the information from the newly created directory
|
||||
*
|
||||
* @param string $cursor A string that is used to keep track of your current state. On the next call pass in this value to return delta entries that have been recorded since the cursor was returned.
|
||||
* @return stdclass
|
||||
*/
|
||||
public function delta($cursor) {
|
||||
|
||||
$arg['cursor'] = $cursor;
|
||||
|
||||
$response = $this->oauth->fetch($this->api_url . 'delta', $arg, 'POST');
|
||||
return json_decode($response['body'],true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a thumbnail (as a string) for a file path.
|
||||
*
|
||||
* @param string $path Path to file
|
||||
* @param string $size small, medium or large
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @return string
|
||||
*/
|
||||
public function getThumbnail($path, $size = 'small', $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
$response = $this->oauth->fetch($this->api_content_url . 'thumbnails/' . $root . '/' . ltrim($path,'/'),array('size' => $size));
|
||||
|
||||
return $response['body'];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to generate multipart POST requests for file upload
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $arguments
|
||||
* @return bool
|
||||
*/
|
||||
protected function multipartFetch($uri, $file, $filename) {
|
||||
|
||||
/* random string */
|
||||
$boundary = 'R50hrfBj5JYyfR3vF3wR96GPCC9Fd2q2pVMERvEaOE3D8LZTgLLbRpNwXek3';
|
||||
|
||||
$headers = array(
|
||||
'Content-Type' => 'multipart/form-data; boundary=' . $boundary,
|
||||
);
|
||||
|
||||
$body="--" . $boundary . "\r\n";
|
||||
$body.="Content-Disposition: form-data; name=file; filename=".rawurldecode($filename)."\r\n";
|
||||
$body.="Content-type: application/octet-stream\r\n";
|
||||
$body.="\r\n";
|
||||
$body.=stream_get_contents($file);
|
||||
$body.="\r\n";
|
||||
$body.="--" . $boundary . "--";
|
||||
|
||||
// Dropbox requires the filename to also be part of the regular arguments, so it becomes
|
||||
// part of the signature.
|
||||
$uri.='?file=' . $filename;
|
||||
|
||||
return $this->oauth->fetch($uri, $body, 'POST', $headers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* Returns metadata for all files and folders that match the search query.
|
||||
*
|
||||
* @added by: diszo.sasil
|
||||
*
|
||||
* @param string $query
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
public function search($query = '', $root = null, $path = ''){
|
||||
if (is_null($root)) $root = $this->root;
|
||||
if(!empty($path)){
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
}
|
||||
$response = $this->oauth->fetch($this->api_url . 'search/' . $root . '/' . ltrim($path,'/'),array('query' => $query));
|
||||
return json_decode($response['body'],true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a shareable link to files or folders.
|
||||
*
|
||||
* Note: Links created by the /shares API call expire after thirty days.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $root Use this to override the default root path (sandbox/dropbox)
|
||||
* @param string $short_url When true (default), the URL returned will be shortened using the Dropbox URL shortener
|
||||
* @return array
|
||||
*/
|
||||
public function share($path, $root = null, $short_url = true) {
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
$short_url = ((is_string($short_url) && strtolower($short_url) === 'false') || !$short_url)? 'false' : 'true';
|
||||
$response = $this->oauth->fetch($this->api_url. 'shares/'. $root . '/' . ltrim($path, '/'), array('short_url' => $short_url), 'POST');
|
||||
return json_decode($response['body'],true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a link directly to a file.
|
||||
* Similar to /shares. The difference is that this bypasses the Dropbox webserver, used to provide a preview of the file, so that you can effectively stream the contents of your media.
|
||||
*
|
||||
* Note: The /media link expires after four hours, allotting enough time to stream files, but not enough to leave a connection open indefinitely.
|
||||
*
|
||||
* @param type $path
|
||||
* @param type $root
|
||||
* @return type
|
||||
*/
|
||||
public function media($path, $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
$response = $this->oauth->fetch($this->api_url. 'media/'. $root . '/' . ltrim($path, '/'), array(), 'POST');
|
||||
return json_decode($response['body'],true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a copy_ref to a file. This reference string can be used to copy that file to another user's Dropbox by passing it in as the from_copy_ref parameter on /fileops/copy.
|
||||
*
|
||||
* @param type $path
|
||||
* @param type $root
|
||||
* @return type
|
||||
*/
|
||||
public function copy_ref($path, $root = null) {
|
||||
|
||||
if (is_null($root)) $root = $this->root;
|
||||
$path = str_replace(array('%2F','~'), array('/','%7E'), rawurlencode($path));
|
||||
$response = $this->oauth->fetch($this->api_url. 'copy_ref/'. $root . '/' . ltrim($path, '/'));
|
||||
return json_decode($response['body'],true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox base exception
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base exception class
|
||||
*/
|
||||
class Dropbox_Exception extends Exception { }
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox Forbidden exception
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This exception is thrown when we receive the 403 forbidden response
|
||||
*/
|
||||
class Dropbox_Exception_Forbidden extends Dropbox_Exception {
|
||||
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox Not Found exception
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This exception is thrown when a non-existant uri is accessed.
|
||||
*
|
||||
* Basically, this exception is used when we get back a 404.
|
||||
*/
|
||||
class Dropbox_Exception_NotFound extends Dropbox_Exception {
|
||||
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox Over Quota exception
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This exception is thrown when the operation required more space than the available quota.
|
||||
*
|
||||
* Basically, this exception is used when we get back a 507.
|
||||
*/
|
||||
class Dropbox_Exception_OverQuota extends Dropbox_Exception {
|
||||
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox RequestToken exception
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This exception is thrown when an error occured during the request_token process.
|
||||
*/
|
||||
class Dropbox_Exception_RequestToken extends Dropbox_Exception {
|
||||
|
||||
|
||||
}
|
216
apps/files_external/3rdparty/Dropbox/OAuth.php
vendored
216
apps/files_external/3rdparty/Dropbox/OAuth.php
vendored
|
@ -1,216 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox OAuth
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This class is an abstract OAuth class.
|
||||
*
|
||||
* It must be extended by classes who wish to provide OAuth functionality
|
||||
* using different libraries.
|
||||
*/
|
||||
abstract class Dropbox_OAuth {
|
||||
|
||||
/**
|
||||
* After a user has authorized access, dropbox can redirect the user back
|
||||
* to this url.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $authorizeCallbackUrl = null;
|
||||
|
||||
/**
|
||||
* Uri used to fetch request tokens
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const URI_REQUEST_TOKEN = 'https://api.dropbox.com/1/oauth/request_token';
|
||||
|
||||
/**
|
||||
* Uri used to redirect the user to for authorization.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const URI_AUTHORIZE = 'https://www.dropbox.com/1/oauth/authorize';
|
||||
|
||||
/**
|
||||
* Uri used to
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const URI_ACCESS_TOKEN = 'https://api.dropbox.com/1/oauth/access_token';
|
||||
|
||||
/**
|
||||
* An OAuth request token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $oauth_token = null;
|
||||
|
||||
/**
|
||||
* OAuth token secret
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $oauth_token_secret = null;
|
||||
|
||||
/**
|
||||
* Get OAuth request last responce
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $lastResponse = array();
|
||||
|
||||
/**
|
||||
* Input file stream pointer or file path for PUT method
|
||||
*
|
||||
* @var resource|string
|
||||
*/
|
||||
protected $inFile = null;
|
||||
|
||||
/**
|
||||
* Input file size for PUT method
|
||||
*
|
||||
* @var resource | string
|
||||
*/
|
||||
protected $inFileSize = null;
|
||||
|
||||
/**
|
||||
* Is support PUT method on OAuth consumer
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $putSupported = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
*/
|
||||
abstract public function __construct($consumerKey, $consumerSecret);
|
||||
|
||||
/**
|
||||
* Sets the request token and secret.
|
||||
*
|
||||
* The tokens can also be passed as an array into the first argument.
|
||||
* The array must have the elements token and token_secret.
|
||||
*
|
||||
* @param string|array $token
|
||||
* @param string $token_secret
|
||||
* @return void
|
||||
*/
|
||||
public function setToken($token, $token_secret = null) {
|
||||
|
||||
if (is_array($token)) {
|
||||
$this->oauth_token = $token['token'];
|
||||
$this->oauth_token_secret = $token['token_secret'];
|
||||
} else {
|
||||
$this->oauth_token = $token;
|
||||
$this->oauth_token_secret = $token_secret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the oauth request tokens as an associative array.
|
||||
*
|
||||
* The array will contain the elements 'token' and 'token_secret'.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getToken() {
|
||||
|
||||
return array(
|
||||
'token' => $this->oauth_token,
|
||||
'token_secret' => $this->oauth_token_secret,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authorization url
|
||||
*
|
||||
* @param string $callBack Specify a callback url to automatically redirect the user back
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorizeUrl($callBack = null) {
|
||||
|
||||
// Building the redirect uri
|
||||
$token = $this->getToken();
|
||||
$uri = self::URI_AUTHORIZE . '?oauth_token=' . $token['token'];
|
||||
if ($callBack) $uri.='&oauth_callback=' . $callBack;
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set input file for PUT method
|
||||
*
|
||||
* @param resource|string $file
|
||||
* @throws Dropbox_Exception
|
||||
*/
|
||||
public function setInfile($file) {
|
||||
if (is_resource($file)) {
|
||||
$stat = fstat($file);
|
||||
$this->inFileSize = $stat['size'];
|
||||
} else if (is_string($file) && is_readable($file)) {
|
||||
$this->inFileSize = filesize($file);
|
||||
$file = fopen($file, 'rb');
|
||||
}
|
||||
if (!is_resource($file)) {
|
||||
throw new Dropbox_Exception('File must be a file-resource or a string');
|
||||
}
|
||||
$this->inFile = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return is PUT method supported
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isPutSupport() {
|
||||
return $this->putSupported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last request response
|
||||
*
|
||||
* @return array:
|
||||
*/
|
||||
public function getLastResponse() {
|
||||
return $this->lastResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a secured oauth url and returns the response body.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param mixed $arguments
|
||||
* @param string $method
|
||||
* @param array $httpHeaders
|
||||
* @return string
|
||||
*/
|
||||
public abstract function fetch($uri, $arguments = array(), $method = 'GET', $httpHeaders = array());
|
||||
|
||||
/**
|
||||
* Requests the OAuth request token.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getRequestToken();
|
||||
|
||||
/**
|
||||
* Requests the OAuth access tokens.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getAccessToken();
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* HTTP OAuth Consumer
|
||||
*
|
||||
* Adapted from halldirector's code in
|
||||
* http://code.google.com/p/dropbox-php/issues/detail?id=36#c5
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2011 Joe Constant / halldirector. All rights reserved.
|
||||
* @author Joe Constant / halldirector
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
require_once 'HTTP/OAuth.php';
|
||||
require_once 'HTTP/OAuth/Consumer.php';
|
||||
|
||||
/*
|
||||
* This class is to help work around aomw ssl issues.
|
||||
*/
|
||||
class Dropbox_OAuth_Consumer_Dropbox extends HTTP_OAuth_Consumer
|
||||
{
|
||||
public function getOAuthConsumerRequest()
|
||||
{
|
||||
if (!$this->consumerRequest instanceof HTTP_OAuth_Consumer_Request) {
|
||||
$this->consumerRequest = new HTTP_OAuth_Consumer_Request;
|
||||
}
|
||||
|
||||
// TODO: Change this and add in code to validate the SSL cert.
|
||||
// see https://github.com/bagder/curl/blob/master/lib/mk-ca-bundle.pl
|
||||
$this->consumerRequest->setConfig(array(
|
||||
'ssl_verify_peer' => false,
|
||||
'ssl_verify_host' => false
|
||||
));
|
||||
|
||||
return $this->consumerRequest;
|
||||
}
|
||||
}
|
310
apps/files_external/3rdparty/Dropbox/OAuth/Curl.php
vendored
310
apps/files_external/3rdparty/Dropbox/OAuth/Curl.php
vendored
|
@ -1,310 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox OAuth
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2011 Daniel Huesken
|
||||
* @author Daniel Huesken (http://www.danielhuesken.de/)
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used to sign all requests to dropbox.
|
||||
*
|
||||
* This specific class uses WordPress WP_Http to authenticate.
|
||||
*/
|
||||
class Dropbox_OAuth_Curl extends Dropbox_OAuth {
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string ConsumerKey
|
||||
*/
|
||||
protected $consumerKey = null;
|
||||
/**
|
||||
*
|
||||
* @var string ConsumerSecret
|
||||
*/
|
||||
protected $consumerSecret = null;
|
||||
/**
|
||||
*
|
||||
* @var string ProzessCallBack
|
||||
*/
|
||||
public $ProgressFunction = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
*/
|
||||
public function __construct($consumerKey, $consumerSecret) {
|
||||
if (!function_exists('curl_exec'))
|
||||
throw new Dropbox_Exception('The PHP curl functions not available!');
|
||||
|
||||
$this->consumerKey = $consumerKey;
|
||||
$this->consumerSecret = $consumerSecret;
|
||||
$this->putSupported = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a secured oauth url and returns the response body.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param mixed $arguments
|
||||
* @param string $method
|
||||
* @param array $httpHeaders
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($uri, $arguments = array(), $method = 'GET', $httpHeaders = array()) {
|
||||
|
||||
$uri=str_replace('http://', 'https://', $uri); // all https, upload makes problems if not
|
||||
if (is_string($arguments) and strtoupper($method) == 'POST') {
|
||||
preg_match("/\?file=(.*)$/i", $uri, $matches);
|
||||
if (isset($matches[1])) {
|
||||
$uri = str_replace($matches[0], "", $uri);
|
||||
$filename = rawurldecode(str_replace('%7E', '~', $matches[1]));
|
||||
$httpHeaders=array_merge($httpHeaders,$this->getOAuthHeader($uri, array("file" => $filename), $method));
|
||||
}
|
||||
} else {
|
||||
$httpHeaders=array_merge($httpHeaders,$this->getOAuthHeader($uri, $arguments, $method));
|
||||
}
|
||||
$ch = curl_init();
|
||||
if (strtoupper($method) == 'POST') {
|
||||
curl_setopt($ch, CURLOPT_URL, $uri);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
if (is_array($arguments)) {
|
||||
$arguments=http_build_query($arguments);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $arguments);
|
||||
$httpHeaders['Content-Length']=strlen($arguments);
|
||||
} else if (strtoupper($method) == 'PUT' && $this->inFile) {
|
||||
curl_setopt($ch, CURLOPT_URL, $uri.'?'.http_build_query($arguments));
|
||||
curl_setopt($ch, CURLOPT_PUT, true);
|
||||
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_INFILE, $this->inFile);
|
||||
curl_setopt($ch, CURLOPT_INFILESIZE, $this->inFileSize);
|
||||
fseek($this->inFile, 0);
|
||||
$this->inFileSize = $this->inFile = null;
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_URL, $uri.'?'.http_build_query($arguments));
|
||||
curl_setopt($ch, CURLOPT_POST, false);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
|
||||
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ca-bundle.pem');
|
||||
//Build header
|
||||
$headers = array();
|
||||
foreach ($httpHeaders as $name => $value) {
|
||||
$headers[] = "{$name}: $value";
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
if (!ini_get('safe_mode') && !ini_get('open_basedir'))
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
|
||||
if (function_exists($this->ProgressFunction) and defined('CURLOPT_PROGRESSFUNCTION')) {
|
||||
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
|
||||
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, $this->ProgressFunction);
|
||||
curl_setopt($ch, CURLOPT_BUFFERSIZE, 512);
|
||||
}
|
||||
$response=curl_exec($ch);
|
||||
$errorno=curl_errno($ch);
|
||||
$error=curl_error($ch);
|
||||
$status=curl_getinfo($ch,CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
$this->lastResponse = array(
|
||||
'httpStatus' => $status,
|
||||
'body' => $response
|
||||
);
|
||||
|
||||
if (!empty($errorno))
|
||||
throw new Dropbox_Exception_NotFound('Curl error: ('.$errorno.') '.$error."\n");
|
||||
|
||||
if ($status>=300) {
|
||||
$body = array();
|
||||
$body = json_decode($response, true);
|
||||
if (!is_array($body)) {
|
||||
$body = array();
|
||||
}
|
||||
$jsonErr = isset($body['error'])? $body['error'] : '';
|
||||
switch ($status) {
|
||||
// Not modified
|
||||
case 304 :
|
||||
return array(
|
||||
'httpStatus' => 304,
|
||||
'body' => null,
|
||||
);
|
||||
break;
|
||||
case 400 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Bad input parameter. Error message should indicate which one and why.');
|
||||
case 401 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Bad or expired token. This can happen if the user or Dropbox revoked or expired an access token. To fix, you should re-authenticate the user.');
|
||||
case 403 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. This could mean a bad OAuth request, or a file or folder already existing at the target location.');
|
||||
case 404 :
|
||||
throw new Dropbox_Exception_NotFound('Resource at uri: ' . $uri . ' could not be found');
|
||||
case 405 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Request method not expected (generally should be GET or POST).');
|
||||
case 500 :
|
||||
throw new Dropbox_Exception_Forbidden('Server error. ' . $jsonErr);
|
||||
case 503 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Your app is making too many requests and is being rate limited. 503s can trigger on a per-app or per-user basis.');
|
||||
case 507 :
|
||||
throw new Dropbox_Exception_OverQuota('This dropbox is full');
|
||||
default:
|
||||
throw new Dropbox_Exception_RequestToken('Error: ('.$status.') ' . $jsonErr);
|
||||
|
||||
}
|
||||
if (!empty($body["error"]))
|
||||
throw new Dropbox_Exception_RequestToken('Error: ('.$status.') ' . $jsonErr);
|
||||
}
|
||||
|
||||
return array(
|
||||
'body' => $response,
|
||||
'httpStatus' => $status
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns named array with oauth parameters for further use
|
||||
* @return array Array with oauth_ parameters
|
||||
*/
|
||||
private function getOAuthBaseParams() {
|
||||
$params['oauth_version'] = '1.0';
|
||||
$params['oauth_signature_method'] = 'HMAC-SHA1';
|
||||
|
||||
$params['oauth_consumer_key'] = $this->consumerKey;
|
||||
$tokens = $this->getToken();
|
||||
if (isset($tokens['token']) && $tokens['token']) {
|
||||
$params['oauth_token'] = $tokens['token'];
|
||||
}
|
||||
$params['oauth_timestamp'] = time();
|
||||
$params['oauth_nonce'] = md5(microtime() . mt_rand());
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates valid Authorization header for OAuth, based on URI and Params
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $params
|
||||
* @param string $method GET or POST, standard is GET
|
||||
* @param array $oAuthParams optional, pass your own oauth_params here
|
||||
* @return array Array for request's headers section like
|
||||
* array('Authorization' => 'OAuth ...');
|
||||
*/
|
||||
public function getOAuthHeader($uri, $params, $method = 'GET', $oAuthParams = null) {
|
||||
$oAuthParams = $oAuthParams ? $oAuthParams : $this->getOAuthBaseParams();
|
||||
|
||||
// create baseString to encode for the sent parameters
|
||||
$baseString = $method . '&';
|
||||
$baseString .= $this->oauth_urlencode($uri) . "&";
|
||||
|
||||
// OAuth header does not include GET-Parameters
|
||||
$signatureParams = array_merge($params, $oAuthParams);
|
||||
|
||||
// sorting the parameters
|
||||
ksort($signatureParams);
|
||||
|
||||
$encodedParams = array();
|
||||
foreach ($signatureParams as $key => $value) {
|
||||
if (!is_null($value)) $encodedParams[] = rawurlencode($key) . '=' . rawurlencode($value);
|
||||
}
|
||||
|
||||
$baseString .= $this->oauth_urlencode(implode('&', $encodedParams));
|
||||
|
||||
// encode the signature
|
||||
$tokens = $this->getToken();
|
||||
$hash = $this->hash_hmac_sha1($this->consumerSecret.'&'.$tokens['token_secret'], $baseString);
|
||||
$signature = base64_encode($hash);
|
||||
|
||||
// add signature to oAuthParams
|
||||
$oAuthParams['oauth_signature'] = $signature;
|
||||
|
||||
$oAuthEncoded = array();
|
||||
foreach ($oAuthParams as $key => $value) {
|
||||
$oAuthEncoded[] = $key . '="' . $this->oauth_urlencode($value) . '"';
|
||||
}
|
||||
|
||||
return array('Authorization' => 'OAuth ' . implode(', ', $oAuthEncoded));
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth request token.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getRequestToken() {
|
||||
$result = $this->fetch(self::URI_REQUEST_TOKEN, array(), 'POST');
|
||||
if ($result['httpStatus'] == "200") {
|
||||
$tokens = array();
|
||||
parse_str($result['body'], $tokens);
|
||||
$this->setToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
|
||||
return $this->getToken();
|
||||
} else {
|
||||
throw new Dropbox_Exception_RequestToken('We were unable to fetch request tokens. This likely means that your consumer key and/or secret are incorrect.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth access tokens.
|
||||
*
|
||||
* This method requires the 'unauthorized' request tokens
|
||||
* and, if successful will set the authorized request tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAccessToken() {
|
||||
$result = $this->fetch(self::URI_ACCESS_TOKEN, array(), 'POST');
|
||||
if ($result['httpStatus'] == "200") {
|
||||
$tokens = array();
|
||||
parse_str($result['body'], $tokens);
|
||||
$this->setToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
|
||||
return $this->getToken();
|
||||
} else {
|
||||
throw new Dropbox_Exception_RequestToken('We were unable to fetch request tokens. This likely means that your consumer key and/or secret are incorrect.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to properly urlencode parameters.
|
||||
* See http://php.net/manual/en/function.oauth-urlencode.php
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
private function oauth_urlencode($string) {
|
||||
return str_replace('%E7', '~', rawurlencode($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash function for hmac_sha1; uses native function if available.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
private function hash_hmac_sha1($key, $data) {
|
||||
if (function_exists('hash_hmac') && in_array('sha1', hash_algos())) {
|
||||
return hash_hmac('sha1', $data, $key, true);
|
||||
} else {
|
||||
$blocksize = 64;
|
||||
$hashfunc = 'sha1';
|
||||
if (strlen($key) > $blocksize) {
|
||||
$key = pack('H*', $hashfunc($key));
|
||||
}
|
||||
|
||||
$key = str_pad($key, $blocksize, chr(0x00));
|
||||
$ipad = str_repeat(chr(0x36), $blocksize);
|
||||
$opad = str_repeat(chr(0x5c), $blocksize);
|
||||
$hash = pack('H*', $hashfunc(( $key ^ $opad ) . pack('H*', $hashfunc(($key ^ $ipad) . $data))));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
187
apps/files_external/3rdparty/Dropbox/OAuth/PEAR.php
vendored
187
apps/files_external/3rdparty/Dropbox/OAuth/PEAR.php
vendored
|
@ -1,187 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox OAuth
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
if (!class_exists('HTTP_OAuth_Consumer')) {
|
||||
|
||||
// We're going to try to load in manually
|
||||
include 'HTTP/OAuth/Consumer.php';
|
||||
|
||||
}
|
||||
if (!class_exists('HTTP_OAuth_Consumer'))
|
||||
throw new Dropbox_Exception('The HTTP_OAuth_Consumer class could not be found! Did you install the pear HTTP_OAUTH class?');
|
||||
|
||||
/**
|
||||
* This class is used to sign all requests to dropbox
|
||||
*
|
||||
* This classes use the PEAR HTTP_OAuth package. Make sure this is installed.
|
||||
*/
|
||||
class Dropbox_OAuth_PEAR extends Dropbox_OAuth {
|
||||
|
||||
/**
|
||||
* OAuth object
|
||||
*
|
||||
* @var OAuth
|
||||
*/
|
||||
protected $oAuth;
|
||||
|
||||
/**
|
||||
* OAuth consumer key
|
||||
*
|
||||
* We need to keep this around for later.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $consumerKey;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
*/
|
||||
public function __construct($consumerKey, $consumerSecret)
|
||||
{
|
||||
$this->OAuth = new Dropbox_OAuth_Consumer_Dropbox($consumerKey, $consumerSecret);
|
||||
$this->consumerKey = $consumerKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request token and secret.
|
||||
*
|
||||
* The tokens can also be passed as an array into the first argument.
|
||||
* The array must have the elements token and token_secret.
|
||||
*
|
||||
* @param string|array $token
|
||||
* @param string $token_secret
|
||||
* @return void
|
||||
*/
|
||||
public function setToken($token, $token_secret = null) {
|
||||
|
||||
parent::setToken($token,$token_secret);
|
||||
$this->OAuth->setToken($this->oauth_token);
|
||||
$this->OAuth->setTokenSecret($this->oauth_token_secret);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a secured oauth url and returns the response body.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param mixed $arguments
|
||||
* @param string $method
|
||||
* @param array $httpHeaders
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($uri, $arguments = array(), $method = 'GET', $httpHeaders = array())
|
||||
{
|
||||
$httpRequest = new HTTP_Request2(null,
|
||||
HTTP_Request2::METHOD_GET,
|
||||
array(
|
||||
'ssl_verify_peer' => false,
|
||||
'ssl_verify_host' => false
|
||||
)
|
||||
);
|
||||
|
||||
$consumerRequest = new HTTP_OAuth_Consumer_Request();
|
||||
$consumerRequest->accept($httpRequest);
|
||||
$consumerRequest->setUrl($uri);
|
||||
$consumerRequest->setMethod($method);
|
||||
$consumerRequest->setSecrets($this->OAuth->getSecrets());
|
||||
|
||||
$parameters = array(
|
||||
'oauth_consumer_key' => $this->consumerKey,
|
||||
'oauth_signature_method' => 'HMAC-SHA1',
|
||||
'oauth_token' => $this->oauth_token,
|
||||
);
|
||||
|
||||
|
||||
if (is_array($arguments)) {
|
||||
$parameters = array_merge($parameters,$arguments);
|
||||
} elseif (is_string($arguments)) {
|
||||
$consumerRequest->setBody($arguments);
|
||||
}
|
||||
$consumerRequest->setParameters($parameters);
|
||||
|
||||
|
||||
if (count($httpHeaders)) {
|
||||
foreach($httpHeaders as $k=>$v) {
|
||||
$consumerRequest->setHeader($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
$response = $consumerRequest->send();
|
||||
|
||||
switch($response->getStatus()) {
|
||||
|
||||
// Not modified
|
||||
case 304 :
|
||||
return array(
|
||||
'httpStatus' => 304,
|
||||
'body' => null,
|
||||
);
|
||||
break;
|
||||
case 400 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Bad input parameter. Error message should indicate which one and why.');
|
||||
case 401 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Bad or expired token. This can happen if the user or Dropbox revoked or expired an access token. To fix, you should re-authenticate the user.');
|
||||
case 403 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. This could mean a bad OAuth request, or a file or folder already existing at the target location.');
|
||||
case 404 :
|
||||
throw new Dropbox_Exception_NotFound('Resource at uri: ' . $uri . ' could not be found');
|
||||
case 405 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Request method not expected (generally should be GET or POST).');
|
||||
case 500 :
|
||||
throw new Dropbox_Exception_Forbidden('Server error. ' . $e->getMessage());
|
||||
case 503 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Your app is making too many requests and is being rate limited. 503s can trigger on a per-app or per-user basis.');
|
||||
case 507 :
|
||||
throw new Dropbox_Exception_OverQuota('This dropbox is full');
|
||||
|
||||
}
|
||||
|
||||
return array(
|
||||
'httpStatus' => $response->getStatus(),
|
||||
'body' => $response->getBody()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth request token.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getRequestToken() {
|
||||
|
||||
$this->OAuth->getRequestToken(self::URI_REQUEST_TOKEN);
|
||||
$this->setToken($this->OAuth->getToken(), $this->OAuth->getTokenSecret());
|
||||
return $this->getToken();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth access tokens.
|
||||
*
|
||||
* This method requires the 'unauthorized' request tokens
|
||||
* and, if successful will set the authorized request tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAccessToken() {
|
||||
|
||||
$this->OAuth->getAccessToken(self::URI_ACCESS_TOKEN);
|
||||
$this->setToken($this->OAuth->getToken(), $this->OAuth->getTokenSecret());
|
||||
return $this->getToken();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
157
apps/files_external/3rdparty/Dropbox/OAuth/PHP.php
vendored
157
apps/files_external/3rdparty/Dropbox/OAuth/PHP.php
vendored
|
@ -1,157 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox OAuth
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* This class is used to sign all requests to dropbox.
|
||||
*
|
||||
* This specific class uses the PHP OAuth extension
|
||||
*/
|
||||
class Dropbox_OAuth_PHP extends Dropbox_OAuth {
|
||||
|
||||
/**
|
||||
* OAuth object
|
||||
*
|
||||
* @var OAuth
|
||||
*/
|
||||
protected $oAuth;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
*/
|
||||
public function __construct($consumerKey, $consumerSecret) {
|
||||
|
||||
if (!class_exists('OAuth'))
|
||||
throw new Dropbox_Exception('The OAuth class could not be found! Did you install and enable the oauth extension?');
|
||||
|
||||
$this->OAuth = new OAuth($consumerKey, $consumerSecret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
|
||||
$this->OAuth->enableDebug();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request token and secret.
|
||||
*
|
||||
* The tokens can also be passed as an array into the first argument.
|
||||
* The array must have the elements token and token_secret.
|
||||
*
|
||||
* @param string|array $token
|
||||
* @param string $token_secret
|
||||
* @return void
|
||||
*/
|
||||
public function setToken($token, $token_secret = null) {
|
||||
|
||||
parent::setToken($token,$token_secret);
|
||||
$this->OAuth->setToken($this->oauth_token, $this->oauth_token_secret);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches a secured oauth url and returns the response body.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param mixed $arguments
|
||||
* @param string $method
|
||||
* @param array $httpHeaders
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($uri, $arguments = array(), $method = 'GET', $httpHeaders = array()) {
|
||||
|
||||
try {
|
||||
$this->OAuth->fetch($uri, $arguments, $method, $httpHeaders);
|
||||
$result = $this->OAuth->getLastResponse();
|
||||
$lastResponseInfo = $this->OAuth->getLastResponseInfo();
|
||||
return array(
|
||||
'httpStatus' => $lastResponseInfo['http_code'],
|
||||
'body' => $result,
|
||||
);
|
||||
} catch (OAuthException $e) {
|
||||
|
||||
$lastResponseInfo = $this->OAuth->getLastResponseInfo();
|
||||
switch($lastResponseInfo['http_code']) {
|
||||
|
||||
// Not modified
|
||||
case 304 :
|
||||
return array(
|
||||
'httpStatus' => 304,
|
||||
'body' => null,
|
||||
);
|
||||
break;
|
||||
case 400 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Bad input parameter. Error message should indicate which one and why.');
|
||||
case 401 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Bad or expired token. This can happen if the user or Dropbox revoked or expired an access token. To fix, you should re-authenticate the user.');
|
||||
case 403 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. This could mean a bad OAuth request, or a file or folder already existing at the target location.');
|
||||
case 404 :
|
||||
throw new Dropbox_Exception_NotFound('Resource at uri: ' . $uri . ' could not be found');
|
||||
case 405 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Request method not expected (generally should be GET or POST).');
|
||||
case 500 :
|
||||
throw new Dropbox_Exception_Forbidden('Server error. ' . $e->getMessage());
|
||||
case 503 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden. Your app is making too many requests and is being rate limited. 503s can trigger on a per-app or per-user basis.');
|
||||
case 507 :
|
||||
throw new Dropbox_Exception_OverQuota('This dropbox is full');
|
||||
default:
|
||||
// rethrowing
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth request token.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getRequestToken() {
|
||||
|
||||
try {
|
||||
|
||||
$tokens = $this->OAuth->getRequestToken(self::URI_REQUEST_TOKEN);
|
||||
$this->setToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
|
||||
return $this->getToken();
|
||||
|
||||
} catch (OAuthException $e) {
|
||||
|
||||
throw new Dropbox_Exception_RequestToken('We were unable to fetch request tokens. This likely means that your consumer key and/or secret are incorrect.',0,$e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests the OAuth access tokens.
|
||||
*
|
||||
* This method requires the 'unauthorized' request tokens
|
||||
* and, if successful will set the authorized request tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAccessToken() {
|
||||
|
||||
$uri = self::URI_ACCESS_TOKEN;
|
||||
$tokens = $this->OAuth->getAccessToken($uri);
|
||||
$this->setToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
|
||||
return $this->getToken();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox OAuth
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Stefan Motz
|
||||
* @author Stefan Motz (http://www.multimediamotz.de/)
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used to sign all requests to dropbox.
|
||||
*
|
||||
* This specific class uses WordPress WP_Http to authenticate.
|
||||
*/
|
||||
class Dropbox_OAuth_Wordpress extends Dropbox_OAuth {
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string ConsumerKey
|
||||
*/
|
||||
protected $consumerKey = null;
|
||||
/**
|
||||
*
|
||||
* @var string ConsumerSecret
|
||||
*/
|
||||
protected $consumerSecret = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
*/
|
||||
public function __construct($consumerKey, $consumerSecret) {
|
||||
if (!(defined('ABSPATH') && defined('WPINC')))
|
||||
throw new Dropbox_Exception('The Wordpress OAuth class is available within a wordpress context only!');
|
||||
if (!class_exists('WP_Http')) {
|
||||
include_once( ABSPATH . WPINC . '/class-http.php' );
|
||||
}
|
||||
|
||||
$this->consumerKey = $consumerKey;
|
||||
$this->consumerSecret = $consumerSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a secured oauth url and returns the response body.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param mixed $arguments
|
||||
* @param string $method
|
||||
* @param array $httpHeaders
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($uri, $arguments = array(), $method = 'GET', $httpHeaders = array()) {
|
||||
|
||||
$requestParams = array();
|
||||
|
||||
$requestParams['method'] = $method;
|
||||
$oAuthHeader = $this->getOAuthHeader($uri, $arguments, $method);
|
||||
$requestParams['headers'] = array_merge($httpHeaders, $oAuthHeader);
|
||||
|
||||
// arguments will be passed to uri for GET, to body for POST etc.
|
||||
if ($method == 'GET') {
|
||||
$uri .= '?' . http_build_query($arguments);
|
||||
} else {
|
||||
if (count($arguments)) {
|
||||
$requestParams['body'] = $arguments;
|
||||
}
|
||||
}
|
||||
|
||||
$request = new WP_Http;
|
||||
|
||||
//$uri = str_replace('api.dropbox.com', 'localhost:12346', $uri);
|
||||
|
||||
$result = $request->request($uri, $requestParams);
|
||||
|
||||
return array(
|
||||
'httpStatus' => $result['response']['code'],
|
||||
'body' => $result['body'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns named array with oauth parameters for further use
|
||||
* @return array Array with oauth_ parameters
|
||||
*/
|
||||
private function getOAuthBaseParams() {
|
||||
$params['oauth_version'] = '1.0';
|
||||
$params['oauth_signature_method'] = 'HMAC-SHA1';
|
||||
|
||||
$params['oauth_consumer_key'] = $this->consumerKey;
|
||||
$tokens = $this->getToken();
|
||||
if (isset($tokens['token']) && $tokens['token']) {
|
||||
$params['oauth_token'] = $tokens['token'];
|
||||
}
|
||||
$params['oauth_timestamp'] = time();
|
||||
$params['oauth_nonce'] = md5(microtime() . mt_rand());
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates valid Authorization header for OAuth, based on URI and Params
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $params
|
||||
* @param string $method GET or POST, standard is GET
|
||||
* @param array $oAuthParams optional, pass your own oauth_params here
|
||||
* @return array Array for request's headers section like
|
||||
* array('Authorization' => 'OAuth ...');
|
||||
*/
|
||||
private function getOAuthHeader($uri, $params, $method = 'GET', $oAuthParams = null) {
|
||||
$oAuthParams = $oAuthParams ? $oAuthParams : $this->getOAuthBaseParams();
|
||||
|
||||
// create baseString to encode for the sent parameters
|
||||
$baseString = $method . '&';
|
||||
$baseString .= $this->oauth_urlencode($uri) . "&";
|
||||
|
||||
// OAuth header does not include GET-Parameters
|
||||
$signatureParams = array_merge($params, $oAuthParams);
|
||||
|
||||
// sorting the parameters
|
||||
ksort($signatureParams);
|
||||
|
||||
$encodedParams = array();
|
||||
foreach ($signatureParams as $key => $value) {
|
||||
$encodedParams[] = $this->oauth_urlencode($key) . '=' . $this->oauth_urlencode($value);
|
||||
}
|
||||
|
||||
$baseString .= $this->oauth_urlencode(implode('&', $encodedParams));
|
||||
|
||||
// encode the signature
|
||||
$tokens = $this->getToken();
|
||||
$hash = $this->hash_hmac_sha1($this->consumerSecret.'&'.$tokens['token_secret'], $baseString);
|
||||
$signature = base64_encode($hash);
|
||||
|
||||
// add signature to oAuthParams
|
||||
$oAuthParams['oauth_signature'] = $signature;
|
||||
|
||||
$oAuthEncoded = array();
|
||||
foreach ($oAuthParams as $key => $value) {
|
||||
$oAuthEncoded[] = $key . '="' . $this->oauth_urlencode($value) . '"';
|
||||
}
|
||||
|
||||
return array('Authorization' => 'OAuth ' . implode(', ', $oAuthEncoded));
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth request token.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getRequestToken() {
|
||||
$result = $this->fetch(self::URI_REQUEST_TOKEN, array(), 'POST');
|
||||
if ($result['httpStatus'] == "200") {
|
||||
$tokens = array();
|
||||
parse_str($result['body'], $tokens);
|
||||
$this->setToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
|
||||
return $this->getToken();
|
||||
} else {
|
||||
throw new Dropbox_Exception_RequestToken('We were unable to fetch request tokens. This likely means that your consumer key and/or secret are incorrect.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth access tokens.
|
||||
*
|
||||
* This method requires the 'unauthorized' request tokens
|
||||
* and, if successful will set the authorized request tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAccessToken() {
|
||||
$result = $this->fetch(self::URI_ACCESS_TOKEN, array(), 'POST');
|
||||
if ($result['httpStatus'] == "200") {
|
||||
$tokens = array();
|
||||
parse_str($result['body'], $tokens);
|
||||
$this->setToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
|
||||
return $this->getToken();
|
||||
} else {
|
||||
throw new Dropbox_Exception_RequestToken('We were unable to fetch request tokens. This likely means that your consumer key and/or secret are incorrect.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to properly urlencode parameters.
|
||||
* See http://php.net/manual/en/function.oauth-urlencode.php
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
private function oauth_urlencode($string) {
|
||||
return str_replace('%E7', '~', rawurlencode($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash function for hmac_sha1; uses native function if available.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
private function hash_hmac_sha1($key, $data) {
|
||||
if (function_exists('hash_hmac') && in_array('sha1', hash_algos())) {
|
||||
return hash_hmac('sha1', $data, $key, true);
|
||||
} else {
|
||||
$blocksize = 64;
|
||||
$hashfunc = 'sha1';
|
||||
if (strlen($key) > $blocksize) {
|
||||
$key = pack('H*', $hashfunc($key));
|
||||
}
|
||||
|
||||
$key = str_pad($key, $blocksize, chr(0x00));
|
||||
$ipad = str_repeat(chr(0x36), $blocksize);
|
||||
$opad = str_repeat(chr(0x5c), $blocksize);
|
||||
$hash = pack('H*', $hashfunc(( $key ^ $opad ) . pack('H*', $hashfunc(($key ^ $ipad) . $data))));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
244
apps/files_external/3rdparty/Dropbox/OAuth/Zend.php
vendored
244
apps/files_external/3rdparty/Dropbox/OAuth/Zend.php
vendored
|
@ -1,244 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Dropbox OAuth
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Michael Johansen <michael@taskcamp.com>
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used to sign all requests to dropbox
|
||||
*
|
||||
* This classes use the Zend_Oauth package.
|
||||
*/
|
||||
class Dropbox_OAuth_Zend extends Dropbox_OAuth {
|
||||
|
||||
/**
|
||||
* OAuth object
|
||||
*
|
||||
* @var Zend_Oauth_Consumer
|
||||
*/
|
||||
protected $oAuth;
|
||||
/**
|
||||
* OAuth consumer key
|
||||
*
|
||||
* We need to keep this around for later.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $consumerKey;
|
||||
/**
|
||||
*
|
||||
* @var Zend_Oauth_Token
|
||||
*/
|
||||
protected $zend_oauth_token;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $consumerKey
|
||||
* @param string $consumerSecret
|
||||
*/
|
||||
public function __construct($consumerKey, $consumerSecret) {
|
||||
if (!class_exists('Zend_Oauth_Consumer')) {
|
||||
// We're going to try to load in manually
|
||||
include 'Zend/Oauth/Consumer.php';
|
||||
}
|
||||
if (!class_exists('Zend_Oauth_Consumer'))
|
||||
throw new Dropbox_Exception('The Zend_Oauth_Consumer class could not be found!');
|
||||
$this->OAuth = new Zend_Oauth_Consumer(array(
|
||||
"consumerKey" => $consumerKey,
|
||||
"consumerSecret" => $consumerSecret,
|
||||
"requestTokenUrl" => self::URI_REQUEST_TOKEN,
|
||||
"accessTokenUrl" => self::URI_ACCESS_TOKEN,
|
||||
"authorizeUrl" => self::URI_AUTHORIZE,
|
||||
"signatureMethod" => "HMAC-SHA1",
|
||||
));
|
||||
$this->consumerKey = $consumerKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request token and secret.
|
||||
*
|
||||
* The tokens can also be passed as an array into the first argument.
|
||||
* The array must have the elements token and token_secret.
|
||||
*
|
||||
* @param string|array $token
|
||||
* @param string $token_secret
|
||||
* @return void
|
||||
*/
|
||||
public function setToken($token, $token_secret = null) {
|
||||
if (is_a($token, "Zend_Oauth_Token")) {
|
||||
if (is_a($token, "Zend_Oauth_Token_Access")) {
|
||||
$this->OAuth->setToken($token);
|
||||
}
|
||||
$this->zend_oauth_token = $token;
|
||||
return parent::setToken($token->getToken(), $token->getTokenSecret());
|
||||
} elseif (is_string($token) && is_null($token_secret)) {
|
||||
return $this->setToken(unserialize($token));
|
||||
} elseif (isset($token['zend_oauth_token'])) {
|
||||
return $this->setToken(unserialize($token['zend_oauth_token']));
|
||||
} else {
|
||||
parent::setToken($token, $token_secret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a secured oauth url and returns the response body.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param mixed $arguments
|
||||
* @param string $method
|
||||
* @param array $httpHeaders
|
||||
* @return string
|
||||
*/
|
||||
public function fetch($uri, $arguments = array(), $method = 'GET', $httpHeaders = array()) {
|
||||
$token = $this->OAuth->getToken();
|
||||
if (!is_a($token, "Zend_Oauth_Token")) {
|
||||
if (is_a($this->zend_oauth_token, "Zend_Oauth_Token_Access")) {
|
||||
$token = $this->zend_oauth_token;
|
||||
} else {
|
||||
$token = new Zend_Oauth_Token_Access();
|
||||
$token->setToken($this->oauth_token);
|
||||
$token->setTokenSecret($this->oauth_token_secret);
|
||||
}
|
||||
}
|
||||
/* @var $token Zend_Oauth_Token_Access */
|
||||
$oauthOptions = array(
|
||||
'consumerKey' => $this->consumerKey,
|
||||
'signatureMethod' => "HMAC-SHA1",
|
||||
'consumerSecret' => $this->OAuth->getConsumerSecret(),
|
||||
);
|
||||
$config = array("timeout" => 15);
|
||||
|
||||
/* @var $consumerRequest Zend_Oauth_Client */
|
||||
$consumerRequest = $token->getHttpClient($oauthOptions);
|
||||
$consumerRequest->setMethod($method);
|
||||
if (is_array($arguments)) {
|
||||
$consumerRequest->setUri($uri);
|
||||
if ($method == "GET") {
|
||||
foreach ($arguments as $param => $value) {
|
||||
$consumerRequest->setParameterGet($param, $value);
|
||||
}
|
||||
} else {
|
||||
foreach ($arguments as $param => $value) {
|
||||
$consumerRequest->setParameterPost($param, $value);
|
||||
}
|
||||
}
|
||||
} elseif (is_string($arguments)) {
|
||||
preg_match("/\?file=(.*)$/i", $uri, $matches);
|
||||
if (isset($matches[1])) {
|
||||
$uri = str_replace($matches[0], "", $uri);
|
||||
$filename = $matches[1];
|
||||
$uri = Zend_Uri::factory($uri);
|
||||
$uri->addReplaceQueryParameters(array("file" => $filename));
|
||||
$consumerRequest->setParameterGet("file", $filename);
|
||||
}
|
||||
$consumerRequest->setUri($uri);
|
||||
$consumerRequest->setRawData($arguments);
|
||||
} elseif (is_resource($arguments)) {
|
||||
$consumerRequest->setUri($uri);
|
||||
/** Placeholder for Oauth streaming support. */
|
||||
}
|
||||
if (count($httpHeaders)) {
|
||||
foreach ($httpHeaders as $k => $v) {
|
||||
$consumerRequest->setHeaders($k, $v);
|
||||
}
|
||||
}
|
||||
$response = $consumerRequest->request();
|
||||
$body = Zend_Json::decode($response->getBody());
|
||||
switch ($response->getStatus()) {
|
||||
// Not modified
|
||||
case 304 :
|
||||
return array(
|
||||
'httpStatus' => 304,
|
||||
'body' => null,
|
||||
);
|
||||
break;
|
||||
case 403 :
|
||||
throw new Dropbox_Exception_Forbidden('Forbidden.
|
||||
This could mean a bad OAuth request, or a file or folder already existing at the target location.
|
||||
' . $body["error"] . "\n");
|
||||
case 404 :
|
||||
throw new Dropbox_Exception_NotFound('Resource at uri: ' . $uri . ' could not be found. ' .
|
||||
$body["error"] . "\n");
|
||||
case 507 :
|
||||
throw new Dropbox_Exception_OverQuota('This dropbox is full. ' .
|
||||
$body["error"] . "\n");
|
||||
}
|
||||
|
||||
return array(
|
||||
'httpStatus' => $response->getStatus(),
|
||||
'body' => $response->getBody(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth request token.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getRequestToken() {
|
||||
$token = $this->OAuth->getRequestToken();
|
||||
$this->setToken($token);
|
||||
return $this->getToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the OAuth access tokens.
|
||||
*
|
||||
* This method requires the 'unauthorized' request tokens
|
||||
* and, if successful will set the authorized request tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getAccessToken() {
|
||||
if (is_a($this->zend_oauth_token, "Zend_Oauth_Token_Request")) {
|
||||
$requestToken = $this->zend_oauth_token;
|
||||
} else {
|
||||
$requestToken = new Zend_Oauth_Token_Request();
|
||||
$requestToken->setToken($this->oauth_token);
|
||||
$requestToken->setTokenSecret($this->oauth_token_secret);
|
||||
}
|
||||
$token = $this->OAuth->getAccessToken($_GET, $requestToken);
|
||||
$this->setToken($token);
|
||||
return $this->getToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the oauth request tokens as an associative array.
|
||||
*
|
||||
* The array will contain the elements 'token' and 'token_secret' and the serialized
|
||||
* Zend_Oauth_Token object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getToken() {
|
||||
//$token = $this->OAuth->getToken();
|
||||
//return serialize($token);
|
||||
return array(
|
||||
'token' => $this->oauth_token,
|
||||
'token_secret' => $this->oauth_token_secret,
|
||||
'zend_oauth_token' => serialize($this->zend_oauth_token),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authorization url
|
||||
*
|
||||
* Overloading Dropbox_OAuth to use the built in functions in Zend_Oauth
|
||||
*
|
||||
* @param string $callBack Specify a callback url to automatically redirect the user back
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorizeUrl($callBack = null) {
|
||||
if ($callBack)
|
||||
$this->OAuth->setCallbackUrl($callBack);
|
||||
return $this->OAuth->getRedirectUrl();
|
||||
}
|
||||
|
||||
}
|
3509
apps/files_external/3rdparty/Dropbox/OAuth/ca-bundle.pem
vendored
3509
apps/files_external/3rdparty/Dropbox/OAuth/ca-bundle.pem
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file registers a new autoload function using spl_autoload_register.
|
||||
*
|
||||
* @package Dropbox
|
||||
* @copyright Copyright (C) 2010 Rooftop Solutions. All rights reserved.
|
||||
* @author Evert Pot (http://www.rooftopsolutions.nl/)
|
||||
* @license http://code.google.com/p/dropbox-php/wiki/License MIT
|
||||
*/
|
||||
|
||||
/**
|
||||
* Autoloader function
|
||||
*
|
||||
* @param $className string
|
||||
* @return void
|
||||
*/
|
||||
function Dropbox_autoload($className) {
|
||||
|
||||
if(strpos($className,'Dropbox_')===0) {
|
||||
|
||||
include dirname(__FILE__) . '/' . str_replace('_','/',substr($className,8)) . '.php';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
spl_autoload_register('Dropbox_autoload');
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||
* @author Michael Gapczynski <GapczynskiM@gmail.com>
|
||||
* @author Robin Appelman <robin@icewind.nl>
|
||||
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
require_once __DIR__ . '/../3rdparty/Dropbox/autoload.php';
|
||||
|
||||
OCP\JSON::checkAppEnabled('files_external');
|
||||
OCP\JSON::checkLoggedIn();
|
||||
OCP\JSON::callCheck();
|
||||
$l = \OC::$server->getL10N('files_external');
|
||||
|
||||
// FIXME: currently hard-coded to Dropbox OAuth
|
||||
if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
|
||||
$oauth = new Dropbox_OAuth_Curl((string)$_POST['app_key'], (string)$_POST['app_secret']);
|
||||
if (isset($_POST['step'])) {
|
||||
switch ($_POST['step']) {
|
||||
case 1:
|
||||
try {
|
||||
if (isset($_POST['callback'])) {
|
||||
$callback = (string)$_POST['callback'];
|
||||
} else {
|
||||
$callback = null;
|
||||
}
|
||||
$token = $oauth->getRequestToken();
|
||||
OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback),
|
||||
'request_token' => $token['token'],
|
||||
'request_token_secret' => $token['token_secret'])));
|
||||
} catch (Exception $exception) {
|
||||
OCP\JSON::error(array('data' => array('message' =>
|
||||
$l->t('Fetching request tokens failed. Verify that your app key and secret are correct.'))
|
||||
));
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
|
||||
try {
|
||||
$oauth->setToken((string)$_POST['request_token'], (string)$_POST['request_token_secret']);
|
||||
$token = $oauth->getAccessToken();
|
||||
OCP\JSON::success(array('access_token' => $token['token'],
|
||||
'access_token_secret' => $token['token_secret']));
|
||||
} catch (Exception $exception) {
|
||||
OCP\JSON::error(array('data' => array('message' =>
|
||||
$l->t('Fetching access tokens failed. Verify that your app key and secret are correct.'))
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
OCP\JSON::error(array('data' => array('message' => $l->t('Please provide a valid app key and secret.'))));
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
<id>files_external</id>
|
||||
<name>External storage support</name>
|
||||
<description>
|
||||
This application enables administrators to configure connections to external storage providers, such as FTP servers, S3 or SWIFT object stores, Google Drive, Dropbox, other Nextcloud servers, WebDAV servers, and more. Administrators can choose which types of storage to enable and can mount these storage locations for a user, a group, or the entire system. Users will see a new folder appear in their root Nextcloud directory, which they can access and use like any other Nextcloud folder. External storage also allows users to share files stored in these external locations. In these cases, the credentials for the owner of the file are used when the recipient requests the file from external storage, thereby ensuring that the recipient can access the shared file.
|
||||
This application enables administrators to configure connections to external storage providers, such as FTP servers, S3 or SWIFT object stores, Google Drive, other Nextcloud servers, WebDAV servers, and more. Administrators can choose which types of storage to enable and can mount these storage locations for a user, a group, or the entire system. Users will see a new folder appear in their root Nextcloud directory, which they can access and use like any other Nextcloud folder. External storage also allows users to share files stored in these external locations. In these cases, the credentials for the owner of the file are used when the recipient requests the file from external storage, thereby ensuring that the recipient can access the shared file.
|
||||
|
||||
External storage can be configured using the GUI or at the command line. This second option provides the advanced user with more flexibility for configuring bulk external storage mounts and setting mount priorities. More information is available in the external storage GUI documentation and the external storage Configuration File documentation.
|
||||
</description>
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
function generateUrl($tr) {
|
||||
var app_key = $tr.find('[data-parameter="app_key"]').val();
|
||||
if (app_key) {
|
||||
return 'https://www.dropbox.com/developers/apps/info/' + app_key;
|
||||
} else {
|
||||
return 'https://www.dropbox.com/developers/apps';
|
||||
}
|
||||
}
|
||||
|
||||
OCA.External.Settings.mountConfig.whenSelectBackend(function($tr, backend, onCompletion) {
|
||||
if (backend === 'dropbox') {
|
||||
var backendEl = $tr.find('.backend');
|
||||
var el = $(document.createElement('a'))
|
||||
.attr('href', generateUrl($tr))
|
||||
.attr('target', '_blank')
|
||||
.attr('title', t('files_external', 'Dropbox App Configuration'))
|
||||
.addClass('icon-settings svg')
|
||||
;
|
||||
el.on('click', function(event) {
|
||||
var a = $(event.target);
|
||||
a.attr('href', generateUrl($(this).closest('tr')));
|
||||
});
|
||||
el.tooltip({placement: 'top'});
|
||||
backendEl.append(el);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
|
@ -77,7 +77,6 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
|
|||
$container->query('OCA\Files_External\Lib\Backend\OwnCloud'),
|
||||
$container->query('OCA\Files_External\Lib\Backend\SFTP'),
|
||||
$container->query('OCA\Files_External\Lib\Backend\AmazonS3'),
|
||||
$container->query('OCA\Files_External\Lib\Backend\Dropbox'),
|
||||
$container->query('OCA\Files_External\Lib\Backend\Google'),
|
||||
$container->query('OCA\Files_External\Lib\Backend\Swift'),
|
||||
$container->query('OCA\Files_External\Lib\Backend\SFTP_Key'),
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Lib\Backend;
|
||||
|
||||
use \OCP\IL10N;
|
||||
use \OCA\Files_External\Lib\Backend\Backend;
|
||||
use \OCA\Files_External\Lib\DefinitionParameter;
|
||||
use \OCA\Files_External\Lib\Auth\AuthMechanism;
|
||||
use \OCA\Files_External\Service\BackendService;
|
||||
use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
|
||||
|
||||
use \OCA\Files_External\Lib\Auth\OAuth1\OAuth1;
|
||||
|
||||
class Dropbox extends Backend {
|
||||
|
||||
use LegacyDependencyCheckPolyfill;
|
||||
|
||||
public function __construct(IL10N $l, OAuth1 $legacyAuth) {
|
||||
$this
|
||||
->setIdentifier('dropbox')
|
||||
->addIdentifierAlias('\OC\Files\Storage\Dropbox') // legacy compat
|
||||
->setStorageClass('\OCA\Files_External\Lib\Storage\Dropbox')
|
||||
->setText($l->t('Dropbox'))
|
||||
->addParameters([
|
||||
// all parameters handled in OAuth1 mechanism
|
||||
])
|
||||
->addAuthScheme(AuthMechanism::SCHEME_OAUTH1)
|
||||
->addCustomJs('dropbox')
|
||||
->setLegacyAuthMechanism($legacyAuth)
|
||||
;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,356 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Michael Gapczynski <GapczynskiM@gmail.com>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Philipp Kapfer <philipp.kapfer@gmx.at>
|
||||
* @author Robin Appelman <robin@icewind.nl>
|
||||
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
* @author Vincent Petry <pvince81@owncloud.com>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Lib\Storage;
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Icewind\Streams\CallbackWrapper;
|
||||
use Icewind\Streams\IteratorDirectory;
|
||||
use Icewind\Streams\RetryWrapper;
|
||||
use OCP\Files\StorageNotAvailableException;
|
||||
|
||||
require_once __DIR__ . '/../../../3rdparty/Dropbox/autoload.php';
|
||||
|
||||
class Dropbox extends \OC\Files\Storage\Common {
|
||||
|
||||
private $dropbox;
|
||||
private $root;
|
||||
private $id;
|
||||
private $metaData = array();
|
||||
private $oauth;
|
||||
|
||||
public function __construct($params) {
|
||||
if (isset($params['configured']) && $params['configured'] === 'true'
|
||||
&& isset($params['app_key'])
|
||||
&& isset($params['app_secret'])
|
||||
&& isset($params['token'])
|
||||
&& isset($params['token_secret'])
|
||||
) {
|
||||
$this->root = isset($params['root']) ? $params['root'] : '';
|
||||
$this->id = 'dropbox::'.$params['app_key'] . $params['token']. '/' . $this->root;
|
||||
$this->oauth = new \Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
|
||||
$this->oauth->setToken($params['token'], $params['token_secret']);
|
||||
// note: Dropbox_API connection is lazy
|
||||
$this->dropbox = new \Dropbox_API($this->oauth, 'auto');
|
||||
} else {
|
||||
throw new \Exception('Creating Dropbox storage failed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
private function deleteMetaData($path) {
|
||||
$path = ltrim($this->root.$path, '/');
|
||||
if (isset($this->metaData[$path])) {
|
||||
unset($this->metaData[$path]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function setMetaData($path, $metaData) {
|
||||
$this->metaData[ltrim($path, '/')] = $metaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path's metadata
|
||||
* @param string $path path for which to return the metadata
|
||||
* @param bool $list if true, also return the directory's contents
|
||||
* @return mixed directory contents if $list is true, file metadata if $list is
|
||||
* false, null if the file doesn't exist or "false" if the operation failed
|
||||
*/
|
||||
private function getDropBoxMetaData($path, $list = false) {
|
||||
$path = ltrim($this->root.$path, '/');
|
||||
if ( ! $list && isset($this->metaData[$path])) {
|
||||
return $this->metaData[$path];
|
||||
} else {
|
||||
if ($list) {
|
||||
try {
|
||||
$response = $this->dropbox->getMetaData($path);
|
||||
} catch (\Dropbox_Exception_Forbidden $e) {
|
||||
throw new StorageNotAvailableException('Dropbox API rate limit exceeded', StorageNotAvailableException::STATUS_ERROR, $e);
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
$contents = array();
|
||||
if ($response && isset($response['contents'])) {
|
||||
// Cache folder's contents
|
||||
foreach ($response['contents'] as $file) {
|
||||
if (!isset($file['is_deleted']) || !$file['is_deleted']) {
|
||||
$this->setMetaData($path.'/'.basename($file['path']), $file);
|
||||
$contents[] = $file;
|
||||
}
|
||||
}
|
||||
unset($response['contents']);
|
||||
}
|
||||
if (!isset($response['is_deleted']) || !$response['is_deleted']) {
|
||||
$this->setMetaData($path, $response);
|
||||
}
|
||||
// Return contents of folder only
|
||||
return $contents;
|
||||
} else {
|
||||
try {
|
||||
$requestPath = $path;
|
||||
if ($path === '.') {
|
||||
$requestPath = '';
|
||||
}
|
||||
|
||||
$response = $this->dropbox->getMetaData($requestPath, 'false');
|
||||
if (!isset($response['is_deleted']) || !$response['is_deleted']) {
|
||||
$this->setMetaData($path, $response);
|
||||
return $response;
|
||||
}
|
||||
return null;
|
||||
} catch (\Dropbox_Exception_Forbidden $e) {
|
||||
throw new StorageNotAvailableException('Dropbox API rate limit exceeded', StorageNotAvailableException::STATUS_ERROR, $e);
|
||||
} catch (\Exception $exception) {
|
||||
if ($exception instanceof \Dropbox_Exception_NotFound) {
|
||||
// don't log, might be a file_exist check
|
||||
return false;
|
||||
}
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function mkdir($path) {
|
||||
$path = $this->root.$path;
|
||||
try {
|
||||
$this->dropbox->createFolder($path);
|
||||
return true;
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function rmdir($path) {
|
||||
return $this->unlink($path);
|
||||
}
|
||||
|
||||
public function opendir($path) {
|
||||
$contents = $this->getDropBoxMetaData($path, true);
|
||||
if ($contents !== false) {
|
||||
$files = array();
|
||||
foreach ($contents as $file) {
|
||||
$files[] = basename($file['path']);
|
||||
}
|
||||
return IteratorDirectory::wrap($files);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function stat($path) {
|
||||
$metaData = $this->getDropBoxMetaData($path);
|
||||
if ($metaData) {
|
||||
$stat['size'] = $metaData['bytes'];
|
||||
$stat['atime'] = time();
|
||||
$stat['mtime'] = (isset($metaData['modified'])) ? strtotime($metaData['modified']) : time();
|
||||
return $stat;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function filetype($path) {
|
||||
if ($path === '' || $path === '/') {
|
||||
return 'dir';
|
||||
} else {
|
||||
$metaData = $this->getDropBoxMetaData($path);
|
||||
if ($metaData) {
|
||||
if ($metaData['is_dir'] === 'true') {
|
||||
return 'dir';
|
||||
} else {
|
||||
return 'file';
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function file_exists($path) {
|
||||
if ($path === '' || $path === '/') {
|
||||
return true;
|
||||
}
|
||||
if ($this->getDropBoxMetaData($path)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function unlink($path) {
|
||||
try {
|
||||
$this->dropbox->delete($this->root.$path);
|
||||
$this->deleteMetaData($path);
|
||||
return true;
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function rename($path1, $path2) {
|
||||
try {
|
||||
// overwrite if target file exists and is not a directory
|
||||
$destMetaData = $this->getDropBoxMetaData($path2);
|
||||
if (isset($destMetaData) && $destMetaData !== false && !$destMetaData['is_dir']) {
|
||||
$this->unlink($path2);
|
||||
}
|
||||
$this->dropbox->move($this->root.$path1, $this->root.$path2);
|
||||
$this->deleteMetaData($path1);
|
||||
return true;
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function copy($path1, $path2) {
|
||||
$path1 = $this->root.$path1;
|
||||
$path2 = $this->root.$path2;
|
||||
try {
|
||||
$this->dropbox->copy($path1, $path2);
|
||||
return true;
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function fopen($path, $mode) {
|
||||
$path = $this->root.$path;
|
||||
switch ($mode) {
|
||||
case 'r':
|
||||
case 'rb':
|
||||
try {
|
||||
// slashes need to stay
|
||||
$encodedPath = str_replace('%2F', '/', rawurlencode(trim($path, '/')));
|
||||
$downloadUrl = 'https://api-content.dropbox.com/1/files/auto/' . $encodedPath;
|
||||
$headers = $this->oauth->getOAuthHeader($downloadUrl, [], 'GET');
|
||||
|
||||
$client = \OC::$server->getHTTPClientService()->newClient();
|
||||
try {
|
||||
$response = $client->get($downloadUrl, [
|
||||
'headers' => $headers,
|
||||
'stream' => true,
|
||||
]);
|
||||
} catch (RequestException $e) {
|
||||
if (!is_null($e->getResponse())) {
|
||||
if ($e->getResponse()->getStatusCode() === 404) {
|
||||
return false;
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$handle = $response->getBody();
|
||||
return RetryWrapper::wrap($handle);
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
case 'w':
|
||||
case 'wb':
|
||||
case 'a':
|
||||
case 'ab':
|
||||
case 'r+':
|
||||
case 'w+':
|
||||
case 'wb+':
|
||||
case 'a+':
|
||||
case 'x':
|
||||
case 'x+':
|
||||
case 'c':
|
||||
case 'c+':
|
||||
if (strrpos($path, '.') !== false) {
|
||||
$ext = substr($path, strrpos($path, '.'));
|
||||
} else {
|
||||
$ext = '';
|
||||
}
|
||||
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||
if ($this->file_exists($path)) {
|
||||
$source = $this->fopen($path, 'r');
|
||||
file_put_contents($tmpFile, $source);
|
||||
}
|
||||
$handle = fopen($tmpFile, $mode);
|
||||
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
|
||||
$this->writeBack($tmpFile, $path);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function writeBack($tmpFile, $path) {
|
||||
$handle = fopen($tmpFile, 'r');
|
||||
try {
|
||||
$this->dropbox->putFile($path, $handle);
|
||||
unlink($tmpFile);
|
||||
$this->deleteMetaData($path);
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public function free_space($path) {
|
||||
try {
|
||||
$info = $this->dropbox->getAccountInfo();
|
||||
return $info['quota_info']['quota'] - $info['quota_info']['normal'];
|
||||
} catch (\Exception $exception) {
|
||||
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function touch($path, $mtime = null) {
|
||||
if ($this->file_exists($path)) {
|
||||
return false;
|
||||
} else {
|
||||
$this->file_put_contents($path, '');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if curl is installed
|
||||
*/
|
||||
public static function checkDependencies() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Robin Appelman <robin@icewind.nl>
|
||||
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
* @author Vincent Petry <pvince81@owncloud.com>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Tests\Storage;
|
||||
|
||||
use \OCA\Files_External\Lib\Storage\Dropbox;
|
||||
|
||||
/**
|
||||
* Class DropboxTest
|
||||
*
|
||||
* @group DB
|
||||
*
|
||||
* @package OCA\Files_External\Tests\Storage
|
||||
*/
|
||||
class DropboxTest extends \Test\Files\Storage\Storage {
|
||||
private $config;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$id = $this->getUniqueID();
|
||||
$this->config = include('files_external/tests/config.php');
|
||||
if ( ! is_array($this->config) or ! isset($this->config['dropbox']) or ! $this->config['dropbox']['run']) {
|
||||
$this->markTestSkipped('Dropbox backend not configured');
|
||||
}
|
||||
$this->config['dropbox']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
|
||||
$this->instance = new Dropbox($this->config['dropbox']);
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
if ($this->instance) {
|
||||
$this->instance->unlink('/');
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function directoryProvider() {
|
||||
// doesn't support leading/trailing spaces
|
||||
return array(array('folder'));
|
||||
}
|
||||
|
||||
public function testDropboxTouchReturnValue() {
|
||||
$this->assertFalse($this->instance->file_exists('foo'));
|
||||
|
||||
// true because succeeded
|
||||
$this->assertTrue($this->instance->touch('foo'));
|
||||
$this->assertTrue($this->instance->file_exists('foo'));
|
||||
|
||||
// false because not supported
|
||||
$this->assertFalse($this->instance->touch('foo'));
|
||||
}
|
||||
}
|
|
@ -98,15 +98,6 @@ return array(
|
|||
//'test'=>'true',
|
||||
//'timeout'=>20
|
||||
),
|
||||
'dropbox' => array (
|
||||
'run'=>false,
|
||||
'root'=>'owncloud',
|
||||
'configured' => 'true',
|
||||
'app_key' => '',
|
||||
'app_secret' => '',
|
||||
'token' => '',
|
||||
'token_secret' => ''
|
||||
),
|
||||
'sftp' => array (
|
||||
'run'=>false,
|
||||
'host'=>'localhost',
|
||||
|
|
Loading…
Reference in a new issue