コード例 #1
0
ファイル: BeeHub_Principal.php プロジェクト: niekbosch/BeeHub
 /**
  * This method renews file .../js/principals.js
  * @TODO make sure that .../js/principals.js is overwritable by a `rename`; consider not writing it to a location inside the document root for security reasons
  */
 public static function update_principals_json()
 {
     $json = array();
     foreach (array('users', 'groups', 'sponsors') as $thing) {
         $collection = BeeHub::getNoSQL()->selectCollection($thing);
         $resultSet = $collection->find(array(), array('name' => true, 'displayname' => true));
         $things = array();
         foreach ($resultSet as $row) {
             $things[$row['name']] = $row['displayname'];
         }
         $json[$thing] = $things;
     }
     $local_js_path = dirname(dirname(__FILE__)) . '/public' . BeeHub::JAVASCRIPT_PATH;
     $filename = tempnam($local_js_path, 'tmp_principals');
     file_put_contents($filename, 'nl.sara.beehub.principals = ' . json_encode($json) . ';');
     rename($filename, $local_js_path . DIRECTORY_SEPARATOR . 'principals.js');
     chmod($local_js_path . 'principals.js', 0664);
 }
コード例 #2
0
ファイル: BeeHub_User.php プロジェクト: niekbosch/BeeHub
 public function check_password_reset_code($reset_code)
 {
     $collection = BeeHub::getNoSQL()->users;
     $document = $collection->findOne(array('name' => $this->name));
     if ($document['password_reset_code'] === $reset_code && $document['password_reset_expiration'] > time()) {
         unset($document['password_reset_code'], $document['password_reset_expiration']);
         $saveResult = $collection->save($document);
         if (!$saveResult['ok']) {
             throw new DAV_Status(DAV::HTTP_INTERNAL_SERVER_ERROR);
         }
         return true;
     } else {
         return false;
     }
 }
コード例 #3
0
ファイル: BeeHub_Registry.php プロジェクト: niekbosch/BeeHub
 /**
  * @param string $path
  */
 public function resource($path)
 {
     if (is_array($path)) {
         $document = $path;
         $path = '/' . $document['path'];
     } else {
         $document = null;
     }
     $path = DAV::unslashify($path);
     $systemPath = DAV::unslashify(BeeHub::SYSTEM_PATH);
     $usersPath = DAV::unslashify(BeeHub::USERS_PATH);
     $groupsPath = DAV::unslashify(BeeHub::GROUPS_PATH);
     $sponsorsPath = DAV::unslashify(BeeHub::SPONSORS_PATH);
     if (isset($this->resourceCache[$path])) {
         return $this->resourceCache[$path];
     }
     $localPath = BeeHub::localPath($path);
     $retval = null;
     if ($path === '/') {
         $retval = new BeeHub_Directory($path);
     } elseif ($path === $systemPath) {
         $retval = new BeeHub_System_Collection($path);
     } elseif (substr($path, 0, strlen($usersPath)) === $usersPath) {
         if ($path === $usersPath) {
             $retval = new BeeHub_Users($path);
         } else {
             try {
                 $retval = new BeeHub_User($path);
             } catch (Exception $e) {
             }
         }
     } elseif (substr($path, 0, strlen($groupsPath)) === $groupsPath) {
         if ($path === $groupsPath) {
             $retval = new BeeHub_Groups($path);
         } else {
             try {
                 $retval = new BeeHub_Group($path);
             } catch (Exception $e) {
             }
         }
     } elseif (substr($path, 0, strlen($sponsorsPath)) === $sponsorsPath) {
         if ($path === $sponsorsPath) {
             $retval = new BeeHub_Sponsors($path);
         } else {
             try {
                 $retval = new BeeHub_Sponsor($path);
             } catch (Exception $e) {
             }
         }
     } else {
         $unslashifiedPath = $path;
         if (substr($unslashifiedPath, 0, 1) === '/') {
             $unslashifiedPath = substr($unslashifiedPath, 1);
         }
         $collection = BeeHub::getNoSQL()->files;
         if (!is_array($document)) {
             $document = $collection->findOne(array('path' => $unslashifiedPath));
         }
         if (!is_null($document)) {
             if (isset($document['collection']) && $document['collection']) {
                 $retval = new BeeHub_Directory($document);
             } else {
                 $retval = new BeeHub_File($document);
             }
         } else {
             return null;
         }
     }
     return $this->resourceCache[$path] = $retval;
 }
コード例 #4
0
function setUpDatabase()
{
    $db = \BeeHub::getNoSQL();
    $collections = $db->listCollections();
    foreach ($collections as $collection) {
        $collection->drop();
    }
    // All the resources are stored
    $filesCollection = $db->createCollection('files');
    $filesCollection->ensureIndex(array('props.http://beehub%2Enl/ sponsor' => 1));
    $filesCollection->ensureIndex(array('props.DAV: owner' => 1));
    $filesCollection->ensureIndex(array('path' => 1), array('unique' => 1));
    $filesCollection->ensureIndex(array('depth' => 1, 'path' => 1));
    $files = array();
    $files[] = array('path' => 'home', 'depth' => 1);
    // Create 1 sponsor
    $collection = $db->createCollection('sponsors');
    $collection->ensureIndex(array('name' => 1), array('unique' => 1));
    $sponsors = array();
    $sponsorNames = array();
    $sponsors[] = array('name' => 'sponsor1', 'displayname' => 'sponsor1', 'admins' => array('user1'));
    $sponsorNames[] = 'sponsor1';
    $collection->batchInsert($sponsors);
    // Create 200 groepen
    $collection = $db->createCollection('groups');
    $collection->ensureIndex(array('name' => 1), array('unique' => 1));
    $groups = array();
    $groupNames = array();
    for ($counter = 1; $counter <= 500; $counter++) {
        $groups[] = array('name' => 'group' . $counter, 'displayname' => 'group' . $counter, 'admins' => array('user1'));
        $groupNames[] = 'group' . $counter;
        // Create the resources for this group; all for user1 who is in all groups
        $files[] = array('path' => 'group' . $counter, 'depth' => 1, 'props' => array('http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 1000; $resourceCounter++) {
            $files[] = array('path' => 'group' . $counter . '/5mb_' . $resourceCounter, 'depth' => 2, 'props' => array('DAV: owner' => 'user1', 'DAV: getcontentlength' => 5242880, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        for ($resourceCounter = 1; $resourceCounter <= 500; $resourceCounter++) {
            $files[] = array('path' => 'group' . $counter . '/100gb_' . $resourceCounter, 'depth' => 2, 'props' => array('DAV: owner' => 'user1', 'DAV: getcontentlength' => 107374182400.0, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
    }
    $collection->batchInsert($groups);
    unset($groups);
    // 20 gebruikers
    $collection = $db->createCollection('users');
    $collection->ensureIndex(array('name' => 1), array('unique' => 1));
    $users = array();
    for ($counter = 1; $counter <= 20; $counter++) {
        $users[] = array('name' => 'user' . $counter, 'displayname' => 'user' . $counter, 'email' => 'user' . $counter . '@mailservice.com', 'password' => '$6$rounds=5000$126b519331f5189c$liGp7IWjOlsZ7wwYbobzsMC9y7bE9JYERiS4ts503HKNqIQUrvNM8IyxoGDSBo30XwrdyTzI6rNZRL5lSEPTr0', 'default_sponsor' => 'sponsor1', 'sponsors' => $sponsorNames);
        // And create user files
        //   /home/userXX/    200 bestanden van 500 Mb
        $files[] = array('path' => 'home/user' . $counter, 'depth' => 2, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 500; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/500mb_' . $resourceCounter, 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 524288000, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
    }
    $users[0]['groups'] = $groupNames;
    $users[0]['sponsors'] = $sponsorNames;
    $tb = 1073741824 * 1024;
    for ($counter = 21; $counter <= 40; $counter++) {
        $users[] = array('name' => 'user' . $counter, 'displayname' => 'user' . $counter, 'email' => 'user' . $counter . '@mailservice.com', 'password' => '$6$rounds=5000$126b519331f5189c$liGp7IWjOlsZ7wwYbobzsMC9y7bE9JYERiS4ts503HKNqIQUrvNM8IyxoGDSBo30XwrdyTzI6rNZRL5lSEPTr0', 'default_sponsor' => 'sponsor1', 'sponsors' => $sponsorNames);
        // And create user files
        //   /home/userXX/             10,000 bestanden van 1 Mb
        //   /home/userXX/dir1         1,000 bestanden van 1Gb
        //   /home/userXX/dir2/dir1    10 bestanden van 1 Tb
        $files[] = array('path' => 'home/user' . $counter, 'depth' => 2, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        $files[] = array('path' => 'home/user' . $counter . '/dir1', 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        $files[] = array('path' => 'home/user' . $counter . '/dir2', 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        $files[] = array('path' => 'home/user' . $counter . '/dir2/dir1', 'depth' => 4, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 10000; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/1mb_' . $resourceCounter, 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 1048576, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        for ($resourceCounter = 1; $resourceCounter <= 1000; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/dir1/1gb_' . $resourceCounter, 'depth' => 4, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 1073741824, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        for ($resourceCounter = 1; $resourceCounter <= 10; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/dir2/dir1/1tb_' . $resourceCounter, 'depth' => 5, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => $tb, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
    }
    for ($counter = 41; $counter <= 60; $counter++) {
        $users[] = array('name' => 'user' . $counter, 'displayname' => 'user' . $counter, 'email' => 'user' . $counter . '@mailservice.com', 'password' => '$6$rounds=5000$126b519331f5189c$liGp7IWjOlsZ7wwYbobzsMC9y7bE9JYERiS4ts503HKNqIQUrvNM8IyxoGDSBo30XwrdyTzI6rNZRL5lSEPTr0', 'default_sponsor' => 'sponsor1', 'sponsors' => $sponsorNames);
        // And create user files
        //   /home/userXX/        10 bestanden van 1 Tb
        //   /home/userXX/dir1    20 bestanden van 500 Gb
        $files[] = array('path' => 'home/user' . $counter, 'depth' => 2, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        $files[] = array('path' => 'home/user' . $counter . '/dir1', 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 10; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/1tb_' . $resourceCounter, 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => $tb, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        for ($resourceCounter = 1; $resourceCounter <= 20; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/dir1/500gb_' . $resourceCounter, 'depth' => 4, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 536870912000.0, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
    }
    for ($counter = 61; $counter <= 80; $counter++) {
        $users[] = array('name' => 'user' . $counter, 'displayname' => 'user' . $counter, 'email' => 'user' . $counter . '@mailservice.com', 'password' => '$6$rounds=5000$126b519331f5189c$liGp7IWjOlsZ7wwYbobzsMC9y7bE9JYERiS4ts503HKNqIQUrvNM8IyxoGDSBo30XwrdyTzI6rNZRL5lSEPTr0', 'default_sponsor' => 'sponsor1', 'sponsors' => $sponsorNames);
        // And create user files
        //   /home/userXX/        10 bestanden van 1 Tb, 10,000 bestanden van 1Kb
        //   /home/userXX/dir1    200 bestanden van 500 Gb, 1,000 bestanden van 1 Mb
        $files[] = array('path' => 'home/user' . $counter, 'depth' => 2, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        $files[] = array('path' => 'home/user' . $counter . '/dir1', 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 10; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/1tb_' . $resourceCounter, 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => $tb, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        for ($resourceCounter = 1; $resourceCounter <= 10000; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/1kb_' . $resourceCounter, 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 1024, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        for ($resourceCounter = 1; $resourceCounter <= 200; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/dir1/500gb_' . $resourceCounter, 'depth' => 4, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 536870912000.0, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        for ($resourceCounter = 1; $resourceCounter <= 1000; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/dir1/1mb_' . $resourceCounter, 'depth' => 4, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 1048576, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
    }
    for ($counter = 81; $counter <= 100; $counter++) {
        $users[] = array('name' => 'user' . $counter, 'displayname' => 'user' . $counter, 'email' => 'user' . $counter . '@mailservice.com', 'password' => '$6$rounds=5000$126b519331f5189c$liGp7IWjOlsZ7wwYbobzsMC9y7bE9JYERiS4ts503HKNqIQUrvNM8IyxoGDSBo30XwrdyTzI6rNZRL5lSEPTr0', 'default_sponsor' => 'sponsor1', 'sponsors' => $sponsorNames);
        // And create user files
        //   /home/userXX/                       10 bestanden van 10 Mb
        //   /home/userXX/dir1                   10 bestanden van 10 Mb
        //   /home/userXX/dir2                   100 bestanden van 1 Gb
        //   /home/userXX/dir2/dir1              150 bestanden van 20 Mb
        //   /home/userXX/dir2/dir1/../dir50/    150 bestanden van 20 Mb in tussenliggende dirs
        //   /home/userXX/dir3/dir1/../dir20/    150 bestanden van 20 Mb in tussenliggende dirs
        $files[] = array('path' => 'home/user' . $counter, 'depth' => 2, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 10; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/10mb_' . $resourceCounter, 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 10485760, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        $files[] = array('path' => 'home/user' . $counter . '/dir1', 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 10; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/dir1/10mb_' . $resourceCounter, 'depth' => 4, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 10485760, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        $files[] = array('path' => 'home/user' . $counter . '/dir2', 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        for ($resourceCounter = 1; $resourceCounter <= 100; $resourceCounter++) {
            $files[] = array('path' => 'home/user' . $counter . '/dir2/1gb_' . $resourceCounter, 'depth' => 4, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 1073741824, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
        }
        $filesCollection->batchInsert($files);
        $files = array();
        $path = 'home/user' . $counter . '/dir2';
        for ($dirCounter = 1; $dirCounter <= 50; $dirCounter++) {
            $path .= '/dir' . $dirCounter;
            $files[] = array('path' => $path, 'depth' => 3 + $dirCounter, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
            for ($resourceCounter = 1; $resourceCounter <= 150; $resourceCounter++) {
                $files[] = array('path' => $path . '/20mb_' . $resourceCounter, 'depth' => 3 + $dirCounter + 1, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 20971520, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
            }
            $filesCollection->batchInsert($files);
            $files = array();
        }
        $files[] = array('path' => 'home/user' . $counter . '/dir3', 'depth' => 3, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
        $path = 'home/user' . $counter . '/dir3';
        for ($dirCounter = 1; $dirCounter <= 20; $dirCounter++) {
            $path .= '/dir' . $dirCounter;
            $files[] = array('path' => $path, 'depth' => 3 + $dirCounter, 'props' => array('DAV: owner' => 'user' . $counter, 'http://beehub%2Enl/ sponsor' => 'sponsor1'), 'collection' => true);
            for ($resourceCounter = 1; $resourceCounter <= 150; $resourceCounter++) {
                $files[] = array('path' => $path . '/20mb_' . $resourceCounter, 'depth' => 3 + $dirCounter + 1, 'props' => array('DAV: owner' => 'user' . $counter, 'DAV: getcontentlength' => 20971520, 'http://beehub%2Enl/ sponsor' => 'sponsor1'));
            }
            $filesCollection->batchInsert($files);
            $files = array();
        }
    }
    $collection->batchInsert($users);
    unset($users);
    unset($files);
    \BeeHub_Principal::update_principals_json();
}
コード例 #5
0
if ($tempfile === false) {
    print "WRONG\n";
    $notGood = true;
} else {
    \unlink($tempfile);
    print "ok\n";
}
// If we encountered an error, abort now!
if ($notGood) {
    \header('HTTP/1.1 500 Internal Server Error');
    \ob_end_flush();
    print "Your PHP configuration is not correct.\n";
    exit;
}
try {
    $db = \BeeHub::getNoSQL();
} catch (DAV_Status $exception) {
    \header('HTTP/1.1 500 Internal Server Error');
    \ob_end_flush();
    print "\nFailed to connect to MongoDB\n";
    exit;
}
$collections = $db->listCollections();
if (\count($collections) > 0) {
    \header('HTTP/1.1 500 Internal Server Error');
    \ob_end_flush();
    print "MongoDB database already contains collections. Cannot initialise the database.\n";
    exit;
}
$datadir = new \DirectoryIterator($config['environment']['datadir']);
$hasChildren = false;
コード例 #6
0
 /**
  * Gets all members who have a certain property set
  * @param   string  $prop  The property which should be set on the member
  * @return  array          An array with all paths to members who have the property set
  */
 public function get_members_with_prop($prop)
 {
     $collection = BeeHub::getNoSQL()->files;
     $unslashifiedPath = DAV::unslashify($this->path);
     while (substr($unslashifiedPath, 0, 1) === '/') {
         $unslashifiedPath = substr($unslashifiedPath, 1);
     }
     if ($unslashifiedPath === '') {
         $queryArray = array('depth' => array('$gt' => 0), 'props.' . $prop => array('$exists' => true));
     } else {
         $queryArray = array('depth' => array('$gt' => substr_count($unslashifiedPath, '/') + 1), 'path' => array('$regex' => '^' . preg_quote(DAV::slashify($unslashifiedPath)) . '.*'), 'props.' . $prop => array('$exists' => true));
     }
     $results = $collection->find($queryArray, array('path' => 1, 'props.' . $prop => 1));
     $returnVal = array();
     foreach ($results as $result) {
         $returnVal[$result['path']] = $result['props'][$prop];
     }
     return $returnVal;
 }
コード例 #7
0
ファイル: BeeHub_Sponsor.php プロジェクト: niekbosch/BeeHub
 /**
  * Stores properties set earlier by set().
  * @return void
  * @throws DAV_Status in particular 507 (Insufficient Storage)
  */
 public function storeProperties()
 {
     if (!$this->touched) {
         return;
     }
     $collection = BeeHub::getNoSQL()->sponsors;
     $update_document = array('displayname' => @$this->stored_props[DAV::PROP_DISPLAYNAME], 'description' => @$this->stored_props[BeeHub::PROP_DESCRIPTION]);
     $collection->update(array('name' => $this->name), array('$set' => $update_document));
     // Update the json file containing all displaynames of all privileges
     self::update_principals_json();
     $this->touched = false;
 }
コード例 #8
0
function setUpDatabase()
{
    $db = \BeeHub::getNoSQL();
    $collections = $db->listCollections();
    foreach ($collections as $collection) {
        $collection->drop();
    }
    $newCollections = \json_decode(\file_get_contents(\dirname(__FILE__) . \DIRECTORY_SEPARATOR . 'dbtests_data' . \DIRECTORY_SEPARATOR . 'basicDataset.json'), true);
    foreach ($newCollections as $collectionName => $documents) {
        $collection = $db->createCollection($collectionName);
        $collection->batchInsert($documents);
    }
    $filesCollection = $db->selectCollection('files');
    $filesCollection->ensureIndex(array('props.http://beehub%2Enl/ sponsor' => 1));
    $filesCollection->ensureIndex(array('props.DAV: owner' => 1));
    $filesCollection->ensureIndex(array('path' => 1), array('unique' => 1));
    $filesCollection->ensureIndex(array('depth' => 1, 'path' => 1));
    $locksCollection = $db->selectCollection('locks');
    $locksCollection->ensureIndex(array('path' => 1), array('unique' => 1));
    $groupsCollection = $db->selectCollection('groups');
    $groupsCollection->ensureIndex(array('name' => 1), array('unique' => 1));
    $sponsorsCollection = $db->selectCollection('sponsors');
    $sponsorsCollection->ensureIndex(array('name' => 1), array('unique' => 1));
    $usersCollection = $db->selectCollection('users');
    $usersCollection->ensureIndex(array('name' => 1), array('unique' => 1));
    \BeeHub_Principal::update_principals_json();
}
コード例 #9
0
ファイル: BeeHub.php プロジェクト: niekbosch/BeeHub
 /**
  * Returns a new, unique, unused ETag
  * @return  String      The new ETag
  * @throws  DAV_Status  When a database error occurs
  */
 public static function ETag()
 {
     $result = BeeHub::getNoSQL()->command(array('findAndModify' => "beehub_system", 'query' => array('name' => 'etag'), 'update' => array('$inc' => array('counter' => 1)), 'new' => true));
     if ($result['ok'] != 1) {
         throw new DAV_Status(DAV::HTTP_INTERNAL_SERVER_ERROR);
     }
     $etag = $result['value']['counter'];
     return '"' . trim(base64_encode(pack('H*', dechex($etag))), '=') . '"';
 }
コード例 #10
0
ファイル: BeeHub_Groups.php プロジェクト: niekbosch/BeeHub
 protected function init_members()
 {
     $collection = BeeHub::getNoSQL()->groups;
     $this->members = $collection->find(array(), array('name'))->sort(array('displayname' => 1));
 }
コード例 #11
0
ファイル: BeeHub_Directory.php プロジェクト: niekbosch/BeeHub
 /**
  * @return DirectoryIterator
  */
 private function dir()
 {
     if (is_null($this->dir)) {
         $collection = BeeHub::getNoSQL()->files;
         $unslashifiedPath = DAV::unslashify($this->path);
         while (substr($unslashifiedPath, 0, 1) === '/') {
             $unslashifiedPath = substr($unslashifiedPath, 1);
         }
         if (!empty($unslashifiedPath)) {
             $query = array('depth' => substr_count($unslashifiedPath, '/') + 2, 'path' => array('$regex' => '^' . preg_quote($unslashifiedPath) . '/[^/]*$'));
         } else {
             $query = array('depth' => 1);
         }
         $allChildren = $collection->find($query);
         $this->dir = array();
         foreach ($allChildren as $document) {
             $child = basename($document['path']);
             if (isset($document['collection']) && $document['collection']) {
                 $child .= '/';
             }
             if (!DAV::$REGISTRY->resource($document)->isVisible()) {
                 DAV::$REGISTRY->forget($this->path . $child);
             } else {
                 $this->dir[] = $child;
             }
         }
     }
     return $this->dir;
 }
コード例 #12
0
ファイル: BeeHub_Auth.php プロジェクト: niekbosch/BeeHub
 /**
  * Authenticates the user through one of the authentication mechanisms.
  * @param  boolean $requireAuth  If set to false and authentication fails,
  *   the user will continue as an unauthenticated user. If set to true
  *   (default), status 401 UNAUTHORIZED will be returned upon authentication
  *   failure.
  * @param  boolean  $allowDoubleLogin  TODO documentation
  */
 public function handle_authentication($requireAuth = true, $allowDoubleLogin = false)
 {
     // We start with assuming nobody is logged in
     $this->set_user(null);
     $this->SURFconext = false;
     if (isset($_GET['logout'])) {
         if ($this->simpleSAML_authentication->isAuthenticated()) {
             $this->simpleSAML_authentication->logout();
         }
         if (!empty($_SERVER['HTTPS'])) {
             DAV::redirect(DAV::HTTP_SEE_OTHER, BeeHub::urlbase(false) . '/system/');
             return;
         }
     }
     if (isset($_SERVER['PHP_AUTH_PW'])) {
         if (!$allowDoubleLogin) {
             if ($this->simpleSAML_authentication->isAuthenticated()) {
                 // You can't be logged in through SURFconext and HTTP Basic at the same time!
                 $this->simpleSAML_authentication->logout();
             }
             if ('conext' === @$_GET['login']) {
                 throw new DAV_Status(DAV::HTTP_BAD_REQUEST, "You are already logged in using your username/password. Therefore you are not allowed to login using SURFconext. Unfortunately the only way to logout with your username and password is to close all browser windows. Hit the 'back' button in your browser and login using username/password.");
             }
         }
         // The user already sent username and password: check them!
         try {
             $user = BeeHub::user($_SERVER['PHP_AUTH_USER']);
             $password_verified = $user->check_password($_SERVER['PHP_AUTH_PW']);
         } catch (DAV_Status $status) {
             if ($status->getCode() === DAV::HTTP_FORBIDDEN) {
                 $password_verified = false;
             }
         }
         if (!$password_verified) {
             // If authentication fails, respond accordingly
             if ('passwd' === @$_GET['login'] || $requireAuth) {
                 // User could not be authenticated with supplied credentials, but we
                 // require authentication, so we ask again!
                 $this->unauthorized();
             }
         } else {
             // Authentication succeeded: store credentials!
             $this->set_user($_SERVER['PHP_AUTH_USER']);
         }
         // end of: if (user sent username/passwd)
     } elseif ('passwd' !== @$_GET['login'] && $this->simpleSAML_authentication->isAuthenticated()) {
         $surfId = $this->simpleSAML_authentication->getAuthData("saml:sp:NameID");
         $surfId = $surfId['Value'];
         $collection = BeeHub::getNoSQL()->users;
         $result = $collection->findOne(array('surfconext_id' => $surfId), array('name' => true));
         if (!is_null($result)) {
             // We found a user, this is the one that's logged in!
             $this->SURFconext = true;
             $this->set_user($result['name']);
         } elseif (rawurldecode($_SERVER['REQUEST_URI']) !== BeeHub::USERS_PATH) {
             throw new DAV_Status(DAV::HTTP_TEMPORARY_REDIRECT, BeeHub::urlbase(true) . BeeHub::USERS_PATH);
         }
     } elseif ('conext' === @$_GET['login']) {
         // We don't know this SURFconext ID, this is a new user
         $this->simpleSAML_authentication->login();
     } elseif ('passwd' === @$_GET['login'] || $requireAuth) {
         // If the user didn't send any credentials, but we require authentication, ask for it!
         $this->unauthorized();
     }
     // If the current user is logged in, but has no verified e-mail address.
     // He/she is not authorized to do anything, but will get a message that we
     // want a verified e-mail address. Although he has to be able to verify
     // his e-mail address of course (so GET and POST on /system/users/<name>
     // is allowed)
     $user = $this->current_user();
     if (!is_null($user)) {
         // Update the http://beehub.nl/ last-activity property
         $user->user_set(BeeHub::PROP_LAST_ACTIVITY, date('Y-m-d\\TH:i:sP'));
         $user->storeProperties();
         $email = $user->prop(BeeHub::PROP_EMAIL);
         if (empty($email) && DAV::unslashify(DAV::getPath()) != DAV::unslashify($user->path)) {
             $message = file_get_contents(dirname(dirname(__FILE__)) . '/views/error_no_verified_email.html');
             $message = str_replace('%USER_PATH%', BeeHub::urlbase(true) . DAV::encodeURIFullPath($user->path), $message);
             BeeHub::htmlError($message, DAV::HTTP_FORBIDDEN);
         }
     }
 }
コード例 #13
0
ファイル: saml_connect.php プロジェクト: niekbosch/BeeHub
    $simpleSaml->login();
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    require_once 'views' . DIRECTORY_SEPARATOR . 'saml_connect.php';
    exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    throw new DAV_Status(DAV::HTTP_METHOD_NOT_ALLOWED);
}
// Get some authentication info
$user = $auth->current_user();
$surfId = $simpleSaml->getAuthData("saml:sp:NameID");
$surfId = $surfId['Value'];
// You need to supply the users current password (as stored in the local database)
if (!$user->check_password($_POST['password'])) {
    throw DAV::forbidden();
}
// Unlink potential other local account linked to this SURFconext ID
$collection = BeeHub::getNoSQL()->users;
$collection->update(array('surfconext_id' => $surfId), array('$unset' => array('surfconext_id' => '', 'surfconext_description' => '')));
// And connect it to the current user
$user->user_set(BeeHub::PROP_SURFCONEXT, $surfId);
$attributes = $simpleSaml->getAttributes();
$surfconext_description = @$attributes['urn:mace:terena.org:attribute-def:schacHomeOrganization'][0];
if (empty($surfconext_description)) {
    $surfconext_description = 'Unknown account';
}
$user->user_set(BeeHub::PROP_SURFCONEXT_DESCRIPTION, $surfconext_description);
$user->storeProperties();
// Redirect to the user's profile page
DAV::redirect(DAV::HTTP_SEE_OTHER, $user->path);
コード例 #14
0
ファイル: xattr_to_nosql.php プロジェクト: niekbosch/BeeHub
#!/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()) {