コード例 #1
0
ファイル: lock.php プロジェクト: sara-nl/ToPoS
SET `tokenLockTimeout` = 0, `tokenLockUUID` = null
WHERE `tokenLockUUID` = {$escLockUUID};
EOS
);
    if (Topos::mysqli()->affected_rows) {
        REST::fatal(REST::HTTP_OK, 'Lock destroyed successfully');
    }
    REST::fatal(REST::HTTP_NOT_FOUND);
}
REST::require_method('HEAD', 'GET');
if (isset($_GET['timeout'])) {
    $timeout = (int) $_GET['timeout'];
    if ($timeout < 1) {
        REST::fatal(REST::HTTP_BAD_REQUEST, 'Bad value for parameter "timeout"');
    }
    $description = isset($_GET['description']) ? ', `tokenLockDescription` = ' . Topos::escape_string((string) $_GET['description']) : '';
    Topos::real_query(<<<EOS
UPDATE `Tokens`
SET `tokenLockTimeout` = UNIX_TIMESTAMP() + {$timeout},
    `tokenLockCounter` = `tokenLockCounter` + 1
    {$description}
WHERE `tokenLockUUID` = {$escLockUUID}
  AND `tokenLockTimeout` > UNIX_TIMESTAMP();
EOS
);
    if (!Topos::mysqli()->affected_rows) {
        REST::fatal(REST::HTTP_NOT_FOUND);
    }
}
$result = Topos::query(<<<EOS
SELECT `tokenId`,
コード例 #2
0
ファイル: tokens.php プロジェクト: sara-nl/ToPoS
            REST::fatal(REST::HTTP_BAD_REQUEST, 'Bad values for "ntokens" or "offset"');
        }
        Topos::real_query("CALL `createTokens`({$escPool}, {$ntokens}, {$offset});");
        REST::fatal(REST::HTTP_ACCEPTED);
    } elseif (isset($_POST['tokens'])) {
        $input = tmpfile();
        fwrite($input, $_POST['tokens']);
        fseek($input, 0);
        $_SERVER['CONTENT_TYPE'] = 'text/plain; charset="UTF-8"';
    } else {
        REST::fatal(REST::HTTP_BAD_REQUEST);
    }
}
// Handle a upload of a single text file, of which each line will be a token.
if ($_SERVER['REQUEST_METHOD'] === 'POST' && strpos(@$_SERVER['CONTENT_TYPE'], 'text/') === 0) {
    $esccontenttype = Topos::escape_string($_SERVER['CONTENT_TYPE']);
    if (!$input) {
        $input = REST::inputhandle();
    }
    $stmt1 = Topos::mysqli()->prepare(<<<EOS
INSERT INTO `TokenValues` (
  `tokenValue`
) VALUES (?);
EOS
);
    $stmt2 = Topos::mysqli()->prepare(<<<EOS
INSERT INTO `Tokens` (
  `tokenId`, `poolId`, `tokenType`, `tokenLength`, `tokenCreated`
) VALUES (?, {$poolId}, {$esccontenttype}, ?, UNIX_TIMESTAMP());
EOS
);
コード例 #3
0
 *                 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';
$escPool = Topos::escape_string($TOPOS_POOL);
REST::require_method('HEAD', 'GET');
$width = 300;
if (!empty($_GET['width'])) {
    $width = (int) $_GET['width'];
}
$result = Topos::query(<<<EOS
SELECT COUNT(*)
FROM `Tokens` NATURAL JOIN `Pools`
WHERE `poolName` = {$escPool};
EOS
);
$tokens = $result->fetch_row();
$tokens = (int) $tokens[0];
if (empty($_GET['total'])) {
    REST::fatal(REST::HTTP_BAD_REQUEST, <<<EOS
コード例 #4
0
ファイル: nextToken.php プロジェクト: sara-nl/ToPoS
        } catch (Exception $e) {
            Topos::real_query("DELETE FROM `Tokens` WHERE `tokenId` = {$tokenId};");
            REST::fatal($e->getCode(), $e->getMessage());
        }
    }
    $tokenURL = Topos::urlbase() . 'pools/' . REST::urlencode($TOPOS_POOL) . '/tokens/' . $tokenId;
    REST::created($tokenURL);
}
REST::require_method('HEAD', 'GET');
$nameClause = is_string(@$_GET['name']) && strlen($_GET['name']) ? "AND MATCH(`tokenName`) AGAINST (" . Topos::escape_string($_GET['name']) . " IN BOOLEAN MODE)" : '';
if ((int) @$_GET['timeout'] > 0) {
    $timeout = (int) $_GET['timeout'];
    if ($timeout < 1) {
        REST::fatal(REST::HTTP_BAD_REQUEST, 'Illegal value for parameter "timeout"');
    }
    $escDescription = isset($_GET['description']) ? Topos::escape_string((string) $_GET['description']) : "''";
    $lockUUID = Topos::uuid();
    $timeout = <<<EOS
, `tokenLockTimeout` = UNIX_TIMESTAMP() + {$timeout}
, `tokenLockUUID` = '{$lockUUID}'
, `tokenLockDescription` = {$escDescription}
EOS;
} else {
    $timeout = '';
    $lockUUID = null;
}
while (true) {
    while (true) {
        $result = Topos::query("SELECT `minLeases` FROM `Pools` WHERE `poolId` = {$poolId};");
        $minLeases = ($row = $result->fetch_row()) ? $row[0] : 0;
        $result = Topos::query(<<<EOS
コード例 #5
0
        // while
        while ($row = $result->fetch_row()) {
            $tokenId = $row[0];
            $tokenLeases = $row[1];
            $lockUUID = '';
            if (empty($_GET['timeout']) || (int) $_GET['timeout'] < 1) {
                Topos::real_query(<<<EOS
UPDATE `Tokens` SET `tokenLeases` = {$tokenLeases} + 1
WHERE `tokenId` = {$tokenId} AND `tokenLeases` = {$tokenLeases};
EOS
);
            } else {
                $lockUUID = Topos::uuid();
                $timeout = (int) $_GET['timeout'];
                $description = isset($_GET['description']) ? $_GET['description'] : '';
                $description = Topos::escape_string($description);
                Topos::real_query(<<<EOS
UPDATE `Tokens`
SET `tokenLeases` = {$tokenLeases} + 1,
    `tokenLockTimeout` = UNIX_TIMESTAMP() + {$timeout},
    `tokenLockUUID` = '{$lockUUID}',
    `tokenLockDescription` = {$description}
WHERE `tokenId` = {$tokenId} AND `tokenLeases` = {$tokenLeases};
EOS
);
            }
            if (Topos::mysqli()->affected_rows) {
                break 2;
            }
        }
        // while
コード例 #6
0
 * limitations under the License.
 * 
 * $Id$
 **************************************************************************/
require_once 'include/global.php';
$escRealm = Topos::escape_string($TOPOS_REALM);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (empty($_POST['pool']) || empty($_POST['tokens'])) {
        REST::fatal(REST::HTTP_BAD_REQUEST, 'Missing one or more required parameters');
    }
    $pool = $_POST['pool'];
    $tokens = (int) $_POST['tokens'];
    if (!preg_match('/^[\\w\\-.]+$/', $pool) || !$tokens || $tokens > 1000000) {
        REST::fatal(REST::HTTP_BAD_REQUEST, 'Illegal parameter value(s)');
    }
    $escPoolName = Topos::escape_string($pool);
    Topos::real_query("CALL `createTokens`({$escRealm}, {$escPoolName}, {$tokens});");
    Topos::log('populate', array('realmName' => $TOPOS_REALM, 'poolName' => $TOPOS_POOL, 'tokens' => $tokens));
    REST::header(array('Content-Type' => REST::best_xhtml_type() . '; charset=UTF-8'));
    echo REST::html_start('Realm');
    echo '<p>Pool populated successfully.</p>' . '<p><a href="./" rel="index">Back</a></p>';
    echo REST::html_end();
    exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
    Topos::real_query('START TRANSACTION;');
    try {
        Topos::real_query(<<<EOS
DELETE `Tokens`.* FROM `Tokens` NATURAL JOIN `Pools`
WHERE `Pools`.`realmName` = {$escRealm};
EOS