/** * Send an e-mail * @param array $recipients An array of the recipients. The key represents the e-mail address, the value is the displayname * @param type $subject The subject of the message * @param type $message The message body * @return void */ public function email($recipients, $subject, $message) { $beehubConfig = \BeeHub::config(); $config = $beehubConfig['email']; $mail = new Mail\Message(); $mail->setBody($message)->addTo($recipients)->setSubject($subject)->setFrom($config['sender_address'], $config['sender_name'])->setEncoding('UTF-8'); $this->emailer->send($mail); }
public function setUp() { $config = \BeeHub::config(); if (!isset($config['mongo']) || empty($config['mongo']['database'])) { $this->markTestSkipped('No mongoDB database specified; all tests depending on mongoDB are skipped'); return; } setUpDatabase(); parent::setUp(); setUp(); }
public function testWheel() { $obj = new \BeeHub_ACL_Provider(); $this->setCurrentUser('/system/users/john'); $this->assertTrue($obj->wheel(), 'BeeHub_ACL_Provider::wheel() should return true, because John is a member of the admin group'); $config = \BeeHub::config(); $adminGroup = new \BeeHub_Group($config['namespace']['admin_group']); $adminGroup->change_memberships(array('jane'), \BeeHub_Group::USER_ACCEPT); $adminGroup->change_memberships(array('jane'), \BeeHub_Group::ADMIN_ACCEPT); $this->setCurrentUser('/system/users/jane'); $this->assertTrue($obj->wheel(), 'BeeHub_ACL_Provider::wheel() should return true, because Jane is also a member of the admin group'); $this->setCurrentUser('/system/users/johny'); $this->assertFalse($obj->wheel(), 'BeeHub_ACL_Provider::wheel() should return true, because Johny is not a member of the admin group'); }
/** * @return mysqli * @throws DAV_Status */ public static function mysqli() { if (!self::$mysqli instanceof mysqli) { $config = BeeHub::config(); self::$mysqli = new mysqli($config['mysql']['host'], $config['mysql']['username'], $config['mysql']['password'], $config['mysql']['database']); if (!self::$mysqli) { self::$mysqli = null; throw new BeeHub_MySQL(mysqli_connect_error(), mysqli_connect_errno()); } self::$mysqli->set_charset('utf8'); #$charset = $mysqli->get_charset(); #DAV::debug($charset); } return self::$mysqli; }
public function testMethod_POST() { if (!setUpStorageBackend()) { $this->markTestSkipped('No storage backend specified; all tests depending on the storage backend are skipped'); return; } $_POST['user_name'] = 'jdoe'; $_POST['displayname'] = 'J Doe'; $_POST['email'] = "*****@*****.**"; $_POST['password'] = '******'; $headers = array(); $obj = $this->getMock('\\BeeHub_Users', array('include_view'), array('/system/users/')); $obj->expects($this->any())->method('include_view')->with($this->equalTo('new_user_confirmation'), $this->equalTo(array('email_address' => $_POST['email']))); $emailer = $this->getMock('\\BeeHub_Emailer', array('email')); $emailer->expects($this->once())->method('email'); \BeeHub::setEmailer($emailer); $this->expectOutputRegex('/html/'); $this->obj->method_POST($headers); $user = new \BeeHub_User('/system/users/jdoe'); $this->assertSame($_POST['displayname'], $user->user_prop(\DAV::PROP_DISPLAYNAME)); $this->assertTrue($user->check_password($_POST['password'])); $userFolder = \DAV::$REGISTRY->resource('/home/' . $_POST['user_name']); $beehubConfig = \BeeHub::config(); $this->assertSame($user->path, $userFolder->user_prop(\DAV::PROP_OWNER)); \BeeHub::setEmailer(new \BeeHub_Emailer()); }
$version = \explode('.', \phpversion()); print 'PHP version should be > 5.4 ...'; if ($version[0] < 5 || $version[0] == 5 && $version[1] < 4) { print 'WRONG (actual value: ' . \phpversion() . "\n"; $notGood = true; } else { print "ok\n"; } print "/system/js/server/principals.js should be writable by the webserver..."; if (\file_put_contents(\dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'public' . \DIRECTORY_SEPARATOR . 'system' . \DIRECTORY_SEPARATOR . 'js' . \DIRECTORY_SEPARATOR . 'server' . \DIRECTORY_SEPARATOR . 'principals.js', 'some contents') === false) { print "WRONG\n"; $notGood = true; } else { print "ok\n"; } $config = \BeeHub::config(); print "The configured data directory should be writable by the webserver..."; if (empty($config['environment']['datadir'])) { $tempfile = false; } else { $tempfile = \tempnam($config['environment']['datadir'], 'deleteMe_'); } if ($tempfile === false) { print "WRONG\n"; $notGood = true; } else { \unlink($tempfile); print "ok\n"; } // If we encountered an error, abort now! if ($notGood) {
public function testUser_prop_owner() { $resource = $this->getMock('\\BeeHub_Resource', array('init_props', 'user_prop_acl_internal', 'user_prop'), array($_SERVER['REQUEST_URI'])); $resource->expects($this->once())->method('user_prop')->with(\DAV::PROP_OWNER)->will($this->returnValue('/system/users/jane')); $this->assertSame('/system/users/jane', $resource->user_prop_owner()); $ownerlessResource = $this->getMock('\\BeeHub_Resource', array('init_props', 'user_prop_acl_internal'), array($_SERVER['REQUEST_URI'])); $config = \BeeHub::config(); $this->assertNull($ownerlessResource->user_prop_owner(), 'All resources have owners. If none is specified, then it defaults to null'); }
public function testLocalPath() { $config = \BeeHub::config(); $this->assertSame($config['environment']['datadir'] . 'some/path', \BeeHub::localPath('/some/path'), 'BeeHub::localPath() should prepend the path of the data dir to the path provided'); }
/** * Return the noSQL database * @todo Move database name to the configuration file * @return MongoDB The noSQL database */ public static function getNoSQL() { $config = BeeHub::config(); if (!isset($config['mongo']) || !isset($config['mongo']['database'])) { throw new DAV_Status(DAV::HTTP_INTERNAL_SERVER_ERROR); } if (!self::$mongo instanceof MongoDB) { if (!empty($config['mongo']['host'])) { $server = 'mongodb://' . $config['mongo']['host']; if (!empty($config['mongo']['port'])) { $server .= ':' . $config['mongo']['port']; } $mongoDB = new MongoClient($server); } else { $mongoDB = new MongoClient(); } self::$mongo = $mongoDB->selectDB($config['mongo']['database']); if (!empty($config['mongo']['user']) && !empty($config['mongo']['password'])) { self::$mongo->authenticate($config['mongo']['user'], $config['mongo']['password']); } } return self::$mongo; }
/** * Initialize the storage backend * * @return boolean False if there is no storage backend specified, true otherwise */ function setUpStorageBackend() { $config = \BeeHub::config(); if (empty($config['environment']['datadir']) || !\is_dir($config['environment']['datadir']) || !@\touch($config['environment']['datadir'] . 'tempfile')) { return false; } // Remove everything in the datadir delTreeContents($config['environment']['datadir']); // Set extended attributes and create a controlled environment $basePath = $config['environment']['datadir']; \umask(07); \mkdir($basePath . 'home'); \mkdir($basePath . 'home' . \DIRECTORY_SEPARATOR . 'john'); \mkdir($basePath . 'home' . \DIRECTORY_SEPARATOR . 'johny'); \mkdir($basePath . 'home' . \DIRECTORY_SEPARATOR . 'jane'); \mkdir($basePath . 'foo'); \file_put_contents($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'file.txt', 'Some contents of this file'); \touch($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'file.txt', 1388576096); \file_put_contents($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'file2.txt', 'Lorem ipsum'); \mkdir($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'directory'); \mkdir($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'directory2'); \mkdir($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'client_tests'); \file_put_contents($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'client_tests' . \DIRECTORY_SEPARATOR . 'file.txt', 'Some contents of this file'); \touch($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'client_tests' . \DIRECTORY_SEPARATOR . 'file.txt', 1388576096); \file_put_contents($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'client_tests' . \DIRECTORY_SEPARATOR . 'file2.txt', 'Lorem ipsum'); \mkdir($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'client_tests' . \DIRECTORY_SEPARATOR . 'directory'); \mkdir($basePath . 'foo' . \DIRECTORY_SEPARATOR . 'client_tests' . \DIRECTORY_SEPARATOR . 'directory2'); \mkdir($basePath . 'bar'); \mkdir($basePath . 'system'); \mkdir($basePath . 'system' . \DIRECTORY_SEPARATOR . 'groups'); \mkdir($basePath . 'system' . \DIRECTORY_SEPARATOR . 'sponsors'); \mkdir($basePath . 'system' . \DIRECTORY_SEPARATOR . 'users'); // Environment for system tests \mkdir($basePath . 'denyAll'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowRead'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWrite'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWriteAcl'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadWrite'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadWriteAcl'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWriteWriteAcl'); \mkdir($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadDir'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadDir' . \DIRECTORY_SEPARATOR . 'resource'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadDir' . \DIRECTORY_SEPARATOR . 'allowWrite'); \mkdir($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWriteDir'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWriteDir' . \DIRECTORY_SEPARATOR . 'resource'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWriteDir' . \DIRECTORY_SEPARATOR . 'allowRead'); \mkdir($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadWriteDir'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadWriteDir' . \DIRECTORY_SEPARATOR . 'resource'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadWriteDir' . \DIRECTORY_SEPARATOR . 'denyRead'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowReadWriteDir' . \DIRECTORY_SEPARATOR . 'denyWrite'); \mkdir($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWriteAclDir'); \touch($basePath . 'denyAll' . \DIRECTORY_SEPARATOR . 'allowWriteAclDir' . \DIRECTORY_SEPARATOR . 'resource'); \mkdir($basePath . 'allowAll'); \touch($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyRead'); \touch($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyWrite'); \touch($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyWriteAcl'); \mkdir($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyReadDir'); \touch($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyReadDir' . \DIRECTORY_SEPARATOR . 'resource'); \mkdir($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyWriteDir'); \touch($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyWriteDir' . \DIRECTORY_SEPARATOR . 'resource'); \touch($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyWriteDir' . \DIRECTORY_SEPARATOR . 'allowWrite'); \mkdir($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyWriteAclDir'); \touch($basePath . 'allowAll' . \DIRECTORY_SEPARATOR . 'denyWriteAclDir' . \DIRECTORY_SEPARATOR . 'resource'); // Return true to indicate everything went well return true; }
#!/usr/bin/env php <?php require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'beehub_bootstrap.php'; mb_internal_encoding('UTF-8'); $CONFIG = BeeHub::config(); //Create a mongoDB $db = BeeHub::getNoSQL(); $collection = $db->files; $collection->remove(); $collection->ensureIndex(array('props.http://beehub%2Enl/ sponsor' => 1)); $collection->ensureIndex(array('props.DAV: owner' => 1)); $collection->ensureIndex(array('path' => 1), array('unique' => 1)); $collection->ensureIndex(array('depth' => 1, 'path' => 1)); $locksCollection = $db->locks; $locksCollection->ensureIndex(array('path' => 1), array('unique' => 1)); /** * Traverse over the files and subdirectories * * @global MongoCollection $collection The MongoDB collection * @global Array $CONFIG The configuration parameters * @param DirectoryIterator $iterator The DirectoryIterator to iterate over * @return void */ function traverse($iterator) { global $collection, $CONFIG; foreach ($iterator as $fileinfo) { $file = $fileinfo->getPathname(); if ($fileinfo->isDot()) { continue; } elseif ($fileinfo->isDir()) {
* * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at <http://www.apache.org/licenses/LICENSE-2.0> * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @package BeeHub */ // Bootstrap the application require_once '../src/beehub_bootstrap.php'; $config = BeeHub::config(); if (@$config['install']['run_install'] === 'true') { require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'webserver_install.php'; exit; } // If a GET request on the root doesn't have this server as a referer, redirect to the homepage: if (!isset($_GET['nosystem']) && DAV::getPath() === '/' && $_SERVER['REQUEST_METHOD'] === 'GET' && (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['SERVER_NAME'] !== parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST))) { DAV::redirect(DAV::HTTP_SEE_OTHER, BeeHub::SYSTEM_PATH); return; } // After bootstrapping, start authentication if (APPLICATION_ENV === BeeHub::ENVIRONMENT_TEST || !empty($_SERVER['HTTPS'])) { BeeHub_Auth::inst()->handle_authentication(BeeHub_Auth::is_authentication_required()); } // And finally handle the request $request = DAV_Request::inst();
public function testMethod_POST() { if (!setUpStorageBackend()) { $this->markTestSkipped('No storage backend specified; all tests depending on the storage backend are skipped'); return; } $this->setCurrentUser('/system/users/john'); $_POST['displayname'] = 'Some test group of John'; $_POST['description'] = "This is the description of John's test group"; $_POST['group_name'] = 'johngroup'; $headers = array(); $this->expectOutputRegex('/https 303 See Other/'); $this->obj->method_POST($headers); $group = new \BeeHub_Group('/system/groups/johngroup'); $this->assertSame($_POST['displayname'], $group->user_prop(\DAV::PROP_DISPLAYNAME)); $this->assertSame($_POST['description'], $group->user_prop(\BeeHub::PROP_DESCRIPTION)); $groupFolder = \DAV::$REGISTRY->resource('/' . $_POST['group_name']); $beehubConfig = \BeeHub::config(); $expectedAcl = array(new \DAVACL_Element_ace($group->path, false, array(\DAVACL::PRIV_READ, \DAVACL::PRIV_WRITE), false, false)); $this->assertNull($groupFolder->user_prop(\DAV::PROP_OWNER)); $this->assertEquals($expectedAcl, $groupFolder->user_prop_acl_internal()); $this->assertSame('/system/sponsors/sponsor_a', $groupFolder->user_prop(\BeeHub::PROP_SPONSOR)); }