certificate manager should always use a \OC\Files\View otherwise we will get problems for different primary storages
This commit is contained in:
parent
67da1f7e5a
commit
5ba19ba7fc
|
@ -42,6 +42,7 @@ class Manager {
|
||||||
* @param \OCP\IDBConnection $connection
|
* @param \OCP\IDBConnection $connection
|
||||||
* @param \OC\Files\Mount\Manager $mountManager
|
* @param \OC\Files\Mount\Manager $mountManager
|
||||||
* @param \OC\Files\Storage\StorageFactory $storageLoader
|
* @param \OC\Files\Storage\StorageFactory $storageLoader
|
||||||
|
* @param \OC\HTTPHelper $httpHelper
|
||||||
* @param string $uid
|
* @param string $uid
|
||||||
*/
|
*/
|
||||||
public function __construct(\OCP\IDBConnection $connection, \OC\Files\Mount\Manager $mountManager,
|
public function __construct(\OCP\IDBConnection $connection, \OC\Files\Mount\Manager $mountManager,
|
||||||
|
@ -53,6 +54,19 @@ class Manager {
|
||||||
$this->uid = $uid;
|
$this->uid = $uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add new server-to-server share
|
||||||
|
*
|
||||||
|
* @param string $remote
|
||||||
|
* @param string $token
|
||||||
|
* @param string $password
|
||||||
|
* @param string $name
|
||||||
|
* @param string $owner
|
||||||
|
* @param boolean $accepted
|
||||||
|
* @param string $user
|
||||||
|
* @param int $remoteId
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) {
|
public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) {
|
||||||
|
|
||||||
$user = $user ? $user : $this->uid;
|
$user = $user ? $user : $this->uid;
|
||||||
|
@ -174,7 +188,12 @@ class Manager {
|
||||||
return ($result['success'] && $status['ocs']['meta']['statuscode'] === 100);
|
return ($result['success'] && $status['ocs']['meta']['statuscode'] === 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setup($params) {
|
/**
|
||||||
|
* setup the server-to-server mounts
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*/
|
||||||
|
public static function setup(array $params) {
|
||||||
$externalManager = new \OCA\Files_Sharing\External\Manager(
|
$externalManager = new \OCA\Files_Sharing\External\Manager(
|
||||||
\OC::$server->getDatabaseConnection(),
|
\OC::$server->getDatabaseConnection(),
|
||||||
\OC\Files\Filesystem::getMountManager(),
|
\OC\Files\Filesystem::getMountManager(),
|
||||||
|
@ -186,6 +205,12 @@ class Manager {
|
||||||
$externalManager->setupMounts();
|
$externalManager->setupMounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove '/user/files' from the path and trailing slashes
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
protected function stripPath($path) {
|
protected function stripPath($path) {
|
||||||
$prefix = '/' . $this->uid . '/files';
|
$prefix = '/' . $this->uid . '/files';
|
||||||
return rtrim(substr($path, strlen($prefix)), '/');
|
return rtrim(substr($path, strlen($prefix)), '/');
|
||||||
|
|
|
@ -21,10 +21,17 @@ class CertificateManager implements ICertificateManager {
|
||||||
protected $uid;
|
protected $uid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $uid
|
* @var \OC\Files\View
|
||||||
*/
|
*/
|
||||||
public function __construct($uid) {
|
protected $view;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $uid
|
||||||
|
* @param \OC\Files\View $view relative zu data/
|
||||||
|
*/
|
||||||
|
public function __construct($uid, \OC\Files\View $view) {
|
||||||
$this->uid = $uid;
|
$this->uid = $uid;
|
||||||
|
$this->view = $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,18 +41,18 @@ class CertificateManager implements ICertificateManager {
|
||||||
*/
|
*/
|
||||||
public function listCertificates() {
|
public function listCertificates() {
|
||||||
$path = $this->getPathToCertificates() . 'uploads/';
|
$path = $this->getPathToCertificates() . 'uploads/';
|
||||||
if (!is_dir($path)) {
|
if (!$this->view->is_dir($path)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$result = array();
|
$result = array();
|
||||||
$handle = opendir($path);
|
$handle = $this->view->opendir($path);
|
||||||
if (!is_resource($handle)) {
|
if (!is_resource($handle)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
while (false !== ($file = readdir($handle))) {
|
while (false !== ($file = readdir($handle))) {
|
||||||
if ($file != '.' && $file != '..') {
|
if ($file != '.' && $file != '..') {
|
||||||
try {
|
try {
|
||||||
$result[] = new Certificate(file_get_contents($path . $file), $file);
|
$result[] = new Certificate($this->view->file_get_contents($path . $file), $file);
|
||||||
} catch(\Exception $e) {}
|
} catch(\Exception $e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,10 +67,10 @@ class CertificateManager implements ICertificateManager {
|
||||||
$path = $this->getPathToCertificates();
|
$path = $this->getPathToCertificates();
|
||||||
$certs = $this->listCertificates();
|
$certs = $this->listCertificates();
|
||||||
|
|
||||||
$fh_certs = fopen($path . '/rootcerts.crt', 'w');
|
$fh_certs = $this->view->fopen($path . '/rootcerts.crt', 'w');
|
||||||
foreach ($certs as $cert) {
|
foreach ($certs as $cert) {
|
||||||
$file = $path . '/uploads/' . $cert->getName();
|
$file = $path . '/uploads/' . $cert->getName();
|
||||||
$data = file_get_contents($file);
|
$data = $this->view->file_get_contents($file);
|
||||||
if (strpos($data, 'BEGIN CERTIFICATE')) {
|
if (strpos($data, 'BEGIN CERTIFICATE')) {
|
||||||
fwrite($fh_certs, $data);
|
fwrite($fh_certs, $data);
|
||||||
fwrite($fh_certs, "\r\n");
|
fwrite($fh_certs, "\r\n");
|
||||||
|
@ -87,17 +94,14 @@ class CertificateManager implements ICertificateManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
$dir = $this->getPathToCertificates() . 'uploads/';
|
$dir = $this->getPathToCertificates() . 'uploads/';
|
||||||
if (!file_exists($dir)) {
|
if (!$this->view->file_exists($dir)) {
|
||||||
//path might not exist (e.g. non-standard OC_User::getHome() value)
|
$this->view->mkdir($dir);
|
||||||
//in this case create full path using 3rd (recursive=true) parameter.
|
|
||||||
//note that we use "normal" php filesystem functions here since the certs need to be local
|
|
||||||
mkdir($dir, 0700, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$file = $dir . $name;
|
$file = $dir . $name;
|
||||||
$certificateObject = new Certificate($certificate, $name);
|
$certificateObject = new Certificate($certificate, $name);
|
||||||
file_put_contents($file, $certificate);
|
$this->view->file_put_contents($file, $certificate);
|
||||||
$this->createCertificateBundle();
|
$this->createCertificateBundle();
|
||||||
return $certificateObject;
|
return $certificateObject;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -117,8 +121,8 @@ class CertificateManager implements ICertificateManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$path = $this->getPathToCertificates() . 'uploads/';
|
$path = $this->getPathToCertificates() . 'uploads/';
|
||||||
if (file_exists($path . $name)) {
|
if ($this->view->file_exists($path . $name)) {
|
||||||
unlink($path . $name);
|
$this->view->unlink($path . $name);
|
||||||
$this->createCertificateBundle();
|
$this->createCertificateBundle();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -251,7 +251,7 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
$config = $c->getConfig();
|
$config = $c->getConfig();
|
||||||
$user = $c->getUserSession()->getUser();
|
$user = $c->getUserSession()->getUser();
|
||||||
$uid = $user ? $user->getUID() : null;
|
$uid = $user ? $user->getUID() : null;
|
||||||
return new HTTPHelper($config, new \OC\Security\CertificateManager($uid));
|
return new HTTPHelper($config, new \OC\Security\CertificateManager($uid, new \OC\Files\View()));
|
||||||
});
|
});
|
||||||
$this->registerService('EventLogger', function (Server $c) {
|
$this->registerService('EventLogger', function (Server $c) {
|
||||||
if (defined('DEBUG') and DEBUG) {
|
if (defined('DEBUG') and DEBUG) {
|
||||||
|
@ -645,7 +645,7 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
}
|
}
|
||||||
$uid = $user->getUID();
|
$uid = $user->getUID();
|
||||||
}
|
}
|
||||||
return new CertificateManager($uid);
|
return new CertificateManager($uid, new \OC\Files\View());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,7 +28,7 @@ class CertificateManagerTest extends \Test\TestCase {
|
||||||
\OC\Files\Filesystem::tearDown();
|
\OC\Files\Filesystem::tearDown();
|
||||||
\OC_Util::setupFS($this->username);
|
\OC_Util::setupFS($this->username);
|
||||||
|
|
||||||
$this->certificateManager = new CertificateManager($this->username);
|
$this->certificateManager = new CertificateManager($this->username, new \OC\Files\View());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown() {
|
protected function tearDown() {
|
||||||
|
|
Loading…
Reference in New Issue