コード例 #1
0
ファイル: BeeHub_Registry.php プロジェクト: niekbosch/BeeHub
 /**
  * Singleton factory.
  * @return BeeHub_Registry
  */
 public static function inst()
 {
     if (is_null(self::$inst)) {
         self::$inst = new BeeHub_Registry();
     }
     return self::$inst;
 }
コード例 #2
0
ファイル: beehub_bootstrap.php プロジェクト: niekbosch/BeeHub
defined('ENT_HTML5') || define('ENT_HTML5', 0);
// Set the include path, so BeeHub* classes are automatically loaded
set_include_path(realpath(dirname(dirname(__FILE__))) . PATH_SEPARATOR . dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
DAV::bootstrap();
set_exception_handler(array('BeeHub', 'exception_handler'));
// We need SimpleSamlPHP
require_once BeeHub::$CONFIG['environment']['simplesamlphp'] . 'lib' . DIRECTORY_SEPARATOR . '_autoload.php';
if (isset($_SERVER['HTTP_ORIGIN']) && !empty($_SERVER['HTTP_ORIGIN']) && parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST) != $_SERVER['SERVER_NAME']) {
    die('Cross Origin Resourc Sharing prohibited!');
}
DAV::$PROTECTED_PROPERTIES[DAV::PROP_GROUP_MEMBER_SET] = true;
DAV::$ACL_PROPERTIES[BeeHub::PROP_SPONSOR] = 'sponsor';
DAV::addSupported_Properties(BeeHub::PROP_SPONSOR, 'sponsor');
BeeHub::handle_method_spoofing();
DAV::$REGISTRY = BeeHub_Registry::inst();
DAV::$LOCKPROVIDER = BeeHub_Lock_Provider::inst();
DAV::$ACLPROVIDER = BeeHub_ACL_Provider::inst();
DAV::$UNAUTHORIZED = array(BeeHub::getAuth(), 'unauthorized');
// In case of POST requests, we can already check the POST authentication code
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!BeeHub::getAuth()->checkPostAuthCode()) {
        throw new DAV_Status(DAV::HTTP_FORBIDDEN, 'POST authentication code (POST_auth_code) was incorrect. The correct code can be obtained with a GET request to /system/?POST_auth_code');
    }
}
// Prepare test environments if needed
if (APPLICATION_ENV === BeeHub::ENVIRONMENT_TEST && isset($_GET['test'])) {
    if (substr($_SERVER['REQUEST_URI'], 0, 19) !== '/foo/client_tests/?') {
        header('Location: /foo/client_tests/?' . $_SERVER['QUERY_STRING']);
        die;
    }
コード例 #3
0
ファイル: beehub_directory.php プロジェクト: niekbosch/BeeHub
function printTree($path, $treeState, $selectedPath)
{
    $registry = BeeHub_Registry::inst();
    $resource = $registry->resource($path);
    $members = array();
    foreach ($resource as $member) {
        // Skip the /system/ directory, as there is no need to see this
        if ($path === '/' && $member === 'system/' || substr($member, -1) !== '/') {
            continue;
        }
        $members[] = $member;
    }
    usort($members, 'strnatcasecmp');
    $last = count($members) - 1;
    for ($counter = 0; $counter <= $last; $counter++) {
        $member = $members[$counter];
        $memberResource = $registry->resource($path . $member);
        // Previous versions actually checked whether the resource has children
        // or not. But with the new set-up that means a query for each resource
        // and this is simply to expensive. Setting this to true for all cases
        // means the end-user will find out there are no child resources on the
        // first attempt to unfold the directory in the tree
        $hasChildren = true;
        $expanded = isset($treeState[$memberResource->path]) && $hasChildren ? $treeState[$memberResource->path] : false;
        ?>
<li <?php 
        echo $counter === $last ? 'class="dynatree-lastsib"' : '';
        ?>
          ><span class="dynatree-node dynatree-folder
                       <?php 
        echo $hasChildren ? 'dynatree-has-children' : '';
        ?>
                       <?php 
        echo $expanded ? 'dynatree-expanded' : ($hasChildren ? 'dynatree-lazy' : '');
        ?>
                       dynatree-exp-<?php 
        echo $expanded ? 'e' : 'cd';
        echo $counter === $last ? 'l dynatree-lastsib' : '';
        ?>
                       dynatree-ico-<?php 
        echo $expanded ? 'e' : 'c';
        ?>
f
                       <?php 
        echo $memberResource->path === $selectedPath ? 'dynatree-focused' : '';
        ?>
                "
            ><span class="dynatree-<?php 
        echo $hasChildren ? 'expander' : 'connector';
        ?>
"></span
            ><span class="dynatree-icon"></span
            ><a class="dynatree-title" href="<?php 
        echo DAV::xmlescape(DAV::encodeURIFullPath($memberResource->path));
        ?>
"><?php 
        echo DAV::xmlescape($memberResource->user_prop_displayname());
        ?>
</a
          ></span
          <?php 
        if ($expanded && $hasChildren) {
            ?>
            ><ul><?php 
            echo printTree($memberResource->path, $treeState, $selectedPath);
            ?>
</ul
          <?php 
        }
        ?>
        ></li>
        <?php 
        $registry->forget($path . $member);
    }
}
コード例 #4
0
ファイル: beehub_user.php プロジェクト: niekbosch/BeeHub
    <div class="control-group">
      <label class="control-label" >Default sponsor</label>
      <div class="controls">
      <?php 
/*        <?php if ( DAV::determine_client() & DAV::CLIENT_IE ) : ?>
          <input type="hidden" id="sponsor" name="sponsor" value="<?= DAV::xmlescape( $this->user_prop( BeeHub::PROP_SPONSOR ) ) ?>" />
          <?= DAV::xmlescape( BeeHub::sponsor( $this->user_prop(BeeHub::PROP_SPONSOR) )->user_prop( DAV::PROP_DISPLAYNAME ) ) ?> (Sponsor can't be changed in Internet Explorer)
        <?php else: ?>
*/
?>
          <select id="sponsor" name="sponsor" <?php 
echo DAV::determine_client() & DAV::CLIENT_IE ? 'disabled="disabled"' : '';
?>
 >
            <?php 
$registry = BeeHub_Registry::inst();
foreach ($this->user_prop_sponsor_membership() as $sponsor_path) {
    ?>
              <option value="<?php 
    echo DAV::xmlescape($sponsor_path);
    ?>
" <?php 
    echo $this->user_prop(BeeHub::PROP_SPONSOR) === $sponsor_path ? 'selected="selected"' : '';
    ?>
>
                <?php 
    echo DAV::xmlescape(BeeHub::sponsor($sponsor_path)->user_prop(DAV::PROP_DISPLAYNAME));
    ?>
              </option>
              <?php 
    $registry->forget($sponsor_path);
コード例 #5
0
 public function testShallowWriteLock()
 {
     declare (ticks=1) {
         @\unlink('locksAreSet.deleteMe');
         @\unlink('allowWriteLocks.deleteMe');
         @\unlink('writeLockHangsLongEnough.deleteMe');
         @\unlink('writeLockSet.deleteMe');
         $registry = \BeeHub_Registry::inst();
         $pid = pcntl_fork();
         if ($pid === -1) {
             $this->markTestSkipped("Unable to fork process");
             return;
         }
         \BeeHub_DB::forceReconnect();
         if ($pid !== 0) {
             // This is the parent process. I could put this code after the if statement,
             // But now everything in the code is in the same (chronological) order as
             // how it is supposed to run.
             // Set a shallow read and write lock should just happen
             $timeBeforeLocks = time();
             $registry->shallowLock(array('/foo/file.txt'), array('/foo/file2.txt'));
             $this->assertGreaterThanOrEqual(-1, $timeBeforeLocks - time());
             // Let's assert that it takes less than a second to set the locks, else something is seriously wrong
             \touch('locksAreSet.deleteMe');
         } elseif ($pid === 0) {
             // we are the child
             $this->alternate_pid = true;
             $counter = 0;
             while (!\file_exists('locksAreSet.deleteMe')) {
                 \sleep(1);
                 if ($counter++ > 10) {
                     $this->assertTrue(false, 'Waited for 10 seconds for the initial locks to be set. This is really much much much too long');
                 }
             }
             // From another thread: Setting a shallow write lock on a resource with another write lock should hang until the other write lock is released
             $registry->shallowLock(array('/foo/file.txt'));
             if (\file_exists('allowWriteLocks.deleteMe')) {
                 \touch('writeLockHangsLongEnough.deleteMe');
             }
             \touch('writeLockSet.deleteMe');
             \BeeHub_DB::mysqli()->close();
             exit;
         }
         // Only the parent process will get to this
         // Then let's wait a second
         \sleep(2);
         \touch('allowWriteLocks.deleteMe');
         $registry->shallowUnlock();
         $counter = 0;
         while (!\file_exists('writeLockSet.deleteMe')) {
             \sleep(1);
             if ($counter++ > 10) {
                 $this->assertTrue(false, 'Waited for 10 seconds for the write lock to be set. This is really much much much too long');
             }
         }
         $this->assertTrue(\file_exists('writeLockHangsLongEnough.deleteMe'), 'A shallow write lock can not be set on resources with another shallow write lock');
         @\unlink('locksAreSet.deleteMe');
         @\unlink('allowWriteLocks.deleteMe');
         @\unlink('writeLockHangsLongEnough.deleteMe');
         @\unlink('writeLockSet.deleteMe');
     }
 }