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`, `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; }
* 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 <p>Missing required parameter <tt>total</tt>.</p> <form action="progress" method="get"> <input type="text" name="total"/> Total number of tokens<br/> <input type="submit" value="Show progress bar"/> </form> EOS ); } $total = (int) $_GET['total'];
REST::require_method('HEAD', 'GET'); $query = <<<EOS SELECT `tokenId`, `tokenLength`, `tokenType`, `tokenName`, `tokenLockUUID`, `tokenLockTimeout` - UNIX_TIMESTAMP(), `tokenLockDescription`, `tokenLeases`, `tokenCreated` FROM `Tokens` WHERE `poolId` = {$poolId} ORDER BY 1; EOS; $result = Topos::query($query); $form = <<<EOS <h2>Forms</h2> <h3>Populate this pool with numbers</h3> <form action="./" method="post"> <input type="text" name="ntokens"/> #tokens<br/> <input type="text" name="offset"/> offset<br/> <input type="submit" value="Populate"/> </form> <h3>Move tokens into this pool</h3> <form action="./" method="post"> <input type="text" name="pool"/> Source pool name<br/> <input type="text" name="tokens"/> Token IDs (separated by anything)<br/> <input type="submit" value="Move"/> </form> <h3>Create tokens from a parameter list</h3>
* 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'; REST::require_method('HEAD', 'GET'); if (!preg_match('/^(?:145\\.100\\.(?:6|7|15)\\.|82\\.93\\.61\\.215)/', $_SERVER['REMOTE_ADDR'])) { REST::fatal(REST::HTTP_FORBIDDEN, <<<EOS <p>Sorry, for security reasons you're not allowed to get a directory listing for this URL.</p> <p>However, you <em>do</em> have access to any subdirectory, such as <a href="example/">this</a>.</p> EOS ); } $result = Topos::query(<<<EOS SELECT `poolName`, COUNT(*) FROM `Pools` NATURAL JOIN `Tokens` GROUP BY `poolId` ORDER BY 1; EOS ); $directory = RESTDir::factory(); while ($row = $result->fetch_row()) { $directory->line(urlencode($row[0]) . '/', array('Size' => $row[1] . ' tokens')); } $directory->end();
} $poolId = Topos::poolId($TOPOS_POOL); $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;
$minLeases = ($row = $result->fetch_row()) ? $row[0] : 0; $result = Topos::query(<<<EOS SELECT `tokenId`, `tokenLeases` FROM `Tokens` WHERE `poolId` = {$poolId} AND `Tokens`.`tokenLeases` = {$minLeases} AND `Tokens`.`tokenLockTimeout` <= UNIX_TIMESTAMP() {$nameClause} LIMIT 100; EOS ); if ($result->num_rows) { break; } $result = Topos::query(<<<EOS SELECT MIN(`tokenLeases`) FROM `Tokens` WHERE `poolId` = {$poolId} AND `tokenLockTimeout` <= UNIX_TIMESTAMP(); EOS ); $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()) {
public static function poolId3($poolName) { $escPoolName = self::escape_string($poolName); $loopflag = 1; while ($loopflag) { try { $result = Topos::query("SELECT getPoolId({$escPoolName});"); $row = $result->fetch_row(); $loopflag = 0; } catch (Topos_Retry $e) { $loopflag++; } } // while return $row[0]; }
EOS ); REST::header(array('Content-Type' => REST::best_xhtml_type() . '; charset=UTF-8')); echo REST::html_start('Pool'); echo '<p>Pool destroyed successfully.</p>'; echo REST::html_end(); exit; } REST::require_method('HEAD', 'GET'); // Fetch number of tokens $query = <<<EOS SELECT COUNT(`tokenId`), SUM(UNIX_TIMESTAMP() < `tokenLockTimeout`) FROM `Pools` NATURAL JOIN `Tokens` WHERE `poolName` = {$escPool}; EOS; list($ntokens, $nlocks) = Topos::query($query)->fetch_row(); $form = <<<EOS <h2>Forms</h2> <h3>Delete</h3> <form action="./?http_method=DELETE" method="post"> <input type="submit" value="Delete this pool"/> </form> <h3>Getting the next token</h3> <form action="nextToken" method="get"> <input type="text" name="token"/> Token value RegExp<br/> <input type="text" name="timeout"/> Timeout in seconds (leave empty for shared tokens)<br/> <input type="text" name="description"/> Lock description (leave empty for shared tokens)<br/> <input type="submit" value="Get next token"/> </form> <h3>Progress bar</h3> <form action="progress" method="get">
$escPool = Topos::escape_string($TOPOS_POOL); // TODO: the DELETE handler was written by Evert, using a subquery. I'm used // to doing this with a single JOIN query... if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { Topos::real_query(<<<EOS UPDATE `Tokens` SET `tokenLockTimeout` = 0, `tokenLockUUID` = null WHERE `poolId` = (SELECT `poolId` FROM `Pools` WHERE `Pools`.`poolName` = {$escPool}); EOS ); REST::header(array('Content-Type' => REST::best_xhtml_type() . '; charset=UTF-8')); echo REST::html_start('Locks'); echo '<p>Locks destroyed successfully.</p>'; echo REST::html_end(); exit; } REST::require_method('HEAD', 'GET'); $result = Topos::query(<<<EOS SELECT `tokenId`, `tokenName`, `tokenLockUUID`, `tokenLockTimeout` - UNIX_TIMESTAMP(), `tokenLockDescription` FROM `Pools` NATURAL JOIN `Tokens` WHERE `poolName` = {$escPool} AND `tokenLockTimeout` > UNIX_TIMESTAMP() ORDER BY 1; EOS ); $directory = RESTDir::factory(); while ($row = $result->fetch_row()) { $directory->line($row[2], array('Token name' => $row[1], 'Timeout' => $row[3] > 0 ? sprintf('%d:%02d:%02d', $row[3] / 3600, $row[3] / 60 % 60, $row[3] % 60) : '', 'LockDescription' => $row[3] > 0 ? $row[4] : '')); } $directory->end();
* * $Id$ **************************************************************************/ require_once 'include/global.php'; $poolId = Topos::poolId($TOPOS_POOL); // TODO: the DELETE handler was written by Evert, using a subquery. I'm used // to doing this with a single JOIN query... if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { Topos::real_query(<<<EOS UPDATE `Tokens` SET `tokenLockTimeout` = 0, `tokenLockUUID` = null WHERE `poolId` = {$poolId}; EOS ); REST::fatal(REST::HTTP_OK, 'Locks destroyed successfully'); } REST::require_method('HEAD', 'GET'); $result = Topos::query(<<<EOS SELECT `tokenId`, `tokenName`, `tokenLockUUID`, `tokenLockTimeout` - UNIX_TIMESTAMP(), `tokenLockDescription` FROM `Tokens` WHERE `poolId` = {$poolId} AND `tokenLockTimeout` > UNIX_TIMESTAMP() ORDER BY 1; EOS ); $directory = RESTDir::factory(); while ($row = $result->fetch_row()) { $directory->line($row[2], array('Token name' => $row[1], 'Timeout' => $row[3] > 0 ? sprintf('%d:%02d:%02d', $row[3] / 3600, $row[3] / 60 % 60, $row[3] % 60) : '', 'LockDescription' => $row[3] > 0 ? $row[4] : '')); } $directory->end();