2013-04-12 17:51:58 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Files\Storage;
|
|
|
|
|
|
|
|
set_include_path(get_include_path() . PATH_SEPARATOR .
|
|
|
|
\OC_App::getAppPath('files_external') . '/3rdparty/irodsphp/prods/src');
|
|
|
|
|
2013-07-24 18:10:14 +04:00
|
|
|
ob_start();
|
2013-04-26 19:37:41 +04:00
|
|
|
require_once 'ProdsConfig.inc.php';
|
2013-04-12 17:51:58 +04:00
|
|
|
require_once 'ProdsStreamer.class.php';
|
2013-07-24 18:10:14 +04:00
|
|
|
ob_end_clean();
|
2013-04-12 17:51:58 +04:00
|
|
|
|
|
|
|
class iRODS extends \OC\Files\Storage\StreamWrapper{
|
|
|
|
private $password;
|
|
|
|
private $user;
|
|
|
|
private $host;
|
|
|
|
private $port;
|
|
|
|
private $zone;
|
|
|
|
private $root;
|
2013-04-19 00:12:53 +04:00
|
|
|
private $use_logon_credentials;
|
2013-04-26 19:37:41 +04:00
|
|
|
private $auth_mode;
|
2013-04-12 17:51:58 +04:00
|
|
|
|
|
|
|
public function __construct($params) {
|
|
|
|
if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
|
2013-06-07 01:20:39 +04:00
|
|
|
$this->host = $params['host'];
|
|
|
|
$this->port = $params['port'];
|
|
|
|
$this->user = $params['user'];
|
|
|
|
$this->password = $params['password'];
|
|
|
|
$this->use_logon_credentials = $params['use_logon_credentials'];
|
|
|
|
$this->zone = $params['zone'];
|
|
|
|
$this->auth_mode = isset($params['auth_mode']) ? $params['auth_mode'] : '';
|
|
|
|
|
|
|
|
$this->root = isset($params['root']) ? $params['root'] : '/';
|
|
|
|
if ( ! $this->root || $this->root[0] !== '/') {
|
2013-04-12 17:51:58 +04:00
|
|
|
$this->root='/'.$this->root;
|
|
|
|
}
|
2013-04-19 00:12:53 +04:00
|
|
|
|
2013-06-07 01:20:39 +04:00
|
|
|
// take user and password from the session
|
2013-04-19 00:12:53 +04:00
|
|
|
if ($this->use_logon_credentials && isset($_SESSION['irods-credentials']) )
|
|
|
|
{
|
|
|
|
$this->user = $_SESSION['irods-credentials']['uid'];
|
|
|
|
$this->password = $_SESSION['irods-credentials']['password'];
|
|
|
|
}
|
|
|
|
|
2013-04-12 17:51:58 +04:00
|
|
|
//create the root folder if necessary
|
|
|
|
if ( ! $this->is_dir('')) {
|
|
|
|
$this->mkdir('');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new \Exception();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-19 00:12:53 +04:00
|
|
|
public static function login( $params ) {
|
|
|
|
$_SESSION['irods-credentials'] = $params;
|
|
|
|
}
|
|
|
|
|
2013-04-12 17:51:58 +04:00
|
|
|
public function getId(){
|
|
|
|
return 'irods::' . $this->user . '@' . $this->host . '/' . $this->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-16 13:35:48 +04:00
|
|
|
* construct the rods url
|
2013-04-12 17:51:58 +04:00
|
|
|
* @param string $path
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function constructUrl($path) {
|
2013-06-07 01:20:39 +04:00
|
|
|
$path = rtrim($path,'/');
|
|
|
|
if ( $path === '' || $path[0] !== '/') {
|
|
|
|
$path = '/'.$path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adding auth method
|
2013-04-12 17:51:58 +04:00
|
|
|
$userWithZone = $this->user.'.'.$this->zone;
|
2013-06-07 01:20:39 +04:00
|
|
|
if ($this->auth_mode !== '') {
|
|
|
|
$userWithZone .= '.'.$this->auth_mode;
|
2013-04-26 19:37:41 +04:00
|
|
|
}
|
2013-07-16 13:35:48 +04:00
|
|
|
|
|
|
|
// url wrapper schema is named rods
|
2013-04-12 17:51:58 +04:00
|
|
|
return 'rods://'.$userWithZone.':'.$this->password.'@'.$this->host.':'.$this->port.$this->root.$path;
|
|
|
|
}
|
2013-06-07 01:20:39 +04:00
|
|
|
|
|
|
|
public function filetype($path) {
|
|
|
|
return @filetype($this->constructUrl($path));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mkdir($path) {
|
|
|
|
return @mkdir($this->constructUrl($path));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function touch($path, $mtime=null) {
|
|
|
|
|
|
|
|
// we cannot set a time
|
|
|
|
if ($mtime != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = $this->constructUrl($path);
|
|
|
|
|
|
|
|
// if the file doesn't exist we create it
|
|
|
|
if (!file_exists($path)) {
|
|
|
|
file_put_contents($path, '');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mtime updates are not supported
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if a file or folder has been updated since $time
|
|
|
|
* @param string $path
|
|
|
|
* @param int $time
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasUpdated($path,$time) {
|
|
|
|
// this it a work around for folder mtimes -> we loop it's content
|
|
|
|
if ( $this->is_dir($path)) {
|
|
|
|
$actualTime=$this->collectionMTime($path);
|
|
|
|
return $actualTime>$time;
|
|
|
|
}
|
|
|
|
|
|
|
|
$actualTime=$this->filemtime($path);
|
|
|
|
return $actualTime>$time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the best guess for the modification time of an iRODS collection
|
|
|
|
*/
|
|
|
|
private function collectionMTime($path) {
|
|
|
|
$dh = $this->opendir($path);
|
|
|
|
$lastCTime = $this->filemtime($path);
|
2013-08-19 14:04:53 +04:00
|
|
|
while (($file = readdir($dh)) !== false) {
|
2013-06-07 01:20:39 +04:00
|
|
|
if ($file != '.' and $file != '..') {
|
|
|
|
$time = $this->filemtime($file);
|
|
|
|
if ($time > $lastCTime) {
|
|
|
|
$lastCTime = $time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $lastCTime;
|
|
|
|
}
|
|
|
|
|
2013-04-12 17:51:58 +04:00
|
|
|
}
|