예제 #1
0
파일: lock.php 프로젝트: sara-nl/ToPoS
    }
}
$result = Topos::query(<<<EOS
SELECT `tokenId`,
       `tokenName`,
       `tokenLockTimeout` - UNIX_TIMESTAMP(),
       `tokenLockDescription`
FROM `Tokens`
WHERE `tokenLockUUID` = {$escLockUUID}
  AND `tokenLockTimeout` > UNIX_TIMESTAMP();
EOS
);
if (!($row = $result->fetch_row())) {
    REST::fatal(REST::HTTP_NOT_FOUND);
}
$tokenURL = Topos::urlbase() . 'pools/' . REST::urlencode($TOPOS_POOL) . '/tokens/' . $row[0];
$xhtmltype = REST::best_xhtml_type();
$bct = REST::best_content_type(array($xhtmltype => 1, 'text/plain' => 1), $xhtmltype);
if ($bct === 'text/plain') {
    REST::header(array('Content-Type' => 'text/plain; charset=US-ASCII', 'Cache-Control' => 'no-cache'));
    if ($_SERVER['REQUEST_METHOD'] === 'HEAD') {
        exit;
    }
    echo <<<EOS
TokenId: {$row[0]}
TokenName: {$row[1]}
TokenURL: {$tokenURL}
Timeout: {$row[2]}
Description: {$row[3]}
EOS;
    exit;
예제 #2
0
파일: nextToken.php 프로젝트: sara-nl/ToPoS
        $row = $result->fetch_row();
        if ($row[0] === null) {
            REST::fatal(REST::HTTP_NOT_FOUND, 'No token available');
        }
        Topos::real_query(<<<EOS
UPDATE `Pools`
SET `minLeases` = {$row[0]}
WHERE `poolId` = {$poolId};
EOS
);
    }
    // while
    while ($row = $result->fetch_row()) {
        Topos::real_query(<<<EOS
UPDATE `Tokens` SET `tokenLeases` = {$row[1]} + 1 {$timeout}
WHERE `tokenId` = {$row[0]} AND `tokenLeases` = {$row[1]};
EOS
);
        if (Topos::mysqli()->affected_rows) {
            break 2;
        }
    }
    // while
}
// while
$url = Topos::urlbase() . 'pools/' . REST::urlencode($TOPOS_POOL) . '/tokens/' . $row[0];
if ($lockUUID) {
    header("X-Topos-OpaqueLockToken: opaquelocktoken:{$lockUUID}");
    header('X-Topos-LockURL: ' . Topos::urlbase() . 'pools/' . REST::urlencode($TOPOS_POOL) . '/locks/' . $lockUUID);
}
REST::redirect(REST::HTTP_SEE_OTHER, $url);
예제 #3
0
파일: token.php 프로젝트: sara-nl/ToPoS
$result = Topos::query(<<<EOS
SELECT `tokenLength`, `tokenType`, `tokenCreated`, `tokenName`,
       IF(`tokenLockTimeout` > UNIX_TIMESTAMP(), `tokenLockUUID`, NULL) AS 'tokenLockUUID', `tokenLeases`
FROM `Tokens`
WHERE `tokenId` = {$TOPOS_TOKEN}
  AND `poolId`  = {$poolId};
EOS
);
if (!($row = $result->fetch_array())) {
    REST::fatal(REST::HTTP_NOT_FOUND);
}
$result = Topos::query(<<<EOS
SELECT `tokenValue` FROM `TokenValues`
WHERE `tokenId` = {$TOPOS_TOKEN}
EOS
);
$tokenValue = $result->fetch_row();
$tokenValue = $tokenValue[0];
$headers = array('Content-Type' => $row['tokenType'], 'Content-Length' => $row['tokenLength'], 'Last-Modified' => REST::http_date($row['tokenCreated']), 'X-Number-Of-Leases' => $row['tokenLeases']);
if (!empty($row['tokenName'])) {
    $headers['Content-Disposition'] = 'inline; filename="' . $row['tokenName'] . '"';
}
if (array_key_exists('tokenLockUUID', $row)) {
    $headers['X-Topos-OpaqueLockToken'] = "opaquelocktoken:{$row['tokenLockUUID']}";
    $headers['X-Topos-LockURL'] = Topos::urlbase() . 'pools/' . REST::urlencode($TOPOS_POOL) . '/locks/' . $row['tokenLockUUID'];
}
REST::header($headers);
if ($_SERVER['REQUEST_METHOD'] === 'HEAD') {
    exit;
}
echo $tokenValue;
<?php

/*·************************************************************************
 * Copyright ©2009 SARA Computing and Networking Services
 *                 Amsterdam, the Netherlands
 *
 * 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.
 * 
 * $Id$
 **************************************************************************/
require_once 'include/global.php';
$file = fopen('/dev/urandom', 'r');
$random = bin2hex(fread($file, 12));
fclose($file);
$url = Topos::urlbase() . "pools/{$random}/";
REST::redirect(REST::HTTP_SEE_OTHER, $url);