コード例 #1
0
ファイル: tokens.php プロジェクト: sara-nl/ToPoS
<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>
<form action="./" method="post">
<textarea name="tokens"></textarea><br/>
<input type="submit" value="Create"/>
</form>
<h3>Create tokens from files</h3>
<form action="./" method="post" enctype="multipart/form-data">
<input type="file" name="create[]" /> File 1<br />
<input type="file" name="create[]" /> File 2<br />
<input type="file" name="create[]" /> File <i>n</i><br />
<input type="submit" value="Post file(s)" />
</form>
EOS;
$directory = RESTDir::factory('Tokens')->setForm($form);
header('X-Token-Count: ' . $result->num_rows);
while ($row = $result->fetch_row()) {
    $directory->line($row[0], array('Size' => $row[1] . ' B', 'Content-Type' => $row[2], 'Original Name' => $row[3], 'LockTokenHTML' => $row[5] > 0 ? "<a href=\"../locks/{$row[4]}\">{$row[4]}</a>" : '', 'Timeout' => $row[5] > 0 ? sprintf('%d:%02d:%02d', $row[5] / 3600, $row[5] / 60 % 60, $row[5] % 60) : '', 'Created' => Topos::sortable_date($row[8]), 'Leases' => $row[7], 'LockDescription' => $row[5] > 0 ? $row[6] : ''));
}
$directory->end();
コード例 #2
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;
コード例 #3
0
    $errorstring = Portal_MySQL::escape_string($errorstring);
    Portal_MySQL::real_query(<<<EOS
UPDATE `Token` 
   SET `token_error` = CONCAT(`token_error`, {$errorstring})
 WHERE `token_id`={$escjobid}
   AND `user_id`={$escuserid};
EOS
);
    REST::header(array('status' => REST::HTTP_NO_CONTENT));
    exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'DELETE') {
    if (file_exists($fullfilename = Portal::JOBRESULTS_DIR . $jobid)) {
        unlink($fullfilename);
    }
    Topos::deleteTokenFile($jobid);
    Portal_MySQL::real_query(<<<EOS
DELETE FROM `Token`
 WHERE `token_id`={$escjobid}
   AND `user_id`={$escuserid};
EOS
);
    if (!Portal_MySQL::mysql()->affected_rows) {
        REST::fatal(REST::HTTP_NOT_FOUND);
    }
    REST::header(array('status' => REST::HTTP_NO_CONTENT));
    exit;
}
// The user tries to get information about eir jobs
if (file_exists($fullfilename = Portal::JOBRESULTS_DIR . $jobid)) {
    REST::redirect(REST::HTTP_SEE_OTHER, Portal::portalURL() . "jobresults/{$jobid}");
コード例 #4
0
 * 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'];
コード例 #5
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';
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();
コード例 #6
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;
コード例 #7
0
 /**
  * Returns the base URI.
  * The base URI is 'protocol://server.name:port'
  * @return string
  */
 public static function urlbase()
 {
     if (is_null(self::$URLBASE)) {
         //DAV::debug('$_SERVER: ' . var_export($_SERVER, true));
         self::$URLBASE = REST::urlbase() . '/4/';
     }
     return self::$URLBASE;
 }
コード例 #8
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);
コード例 #9
0
$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();
コード例 #10
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">
コード例 #11
0
        @unlink($fullproxyfile);
        continue;
    } elseif ($returnval) {
        $handle = popen("myproxy-logon -v -l {$proxyusername} -s {$escproxyserver} -S -o {$escfullproxyfile} >/dev/null 2>&1", 'w');
        fwrite($handle, $proxypassword);
        if (pclose($handle)) {
            @unlink($fullproxyfile);
            Portal_MySQL::real_query(<<<EOS
UPDATE `User` SET `proxy_server` = NULL, `proxy_username` = NULL, `proxy_password` = NULL
WHERE `user_dn_md5` = {$escuserdnmd5};
EOS
);
            continue;
        }
    }
    $topos = new Topos();
    $pools = $topos->getPools();
    foreach ($pools as $pool => $ntokens) {
        $poolURL = $topos->realmURL() . "pools/{$pool}";
        if (!preg_match('@^todo_for_vo_([-\\w.]+)/$@', $pool, $matches)) {
            Portal::debug("Strange pool URL {$poolURL}");
            continue;
        }
        $vo = $matches[1];
        putenv("X509_USER_PROXY={$fullproxyfile}");
        $vomsproxy = "{$TEMPNAM}.{$vo}.pem";
        $output = '';
        exec("voms-proxy-init -noregen -out {$vomsproxy} -voms {$vo} 2>&1", $output);
        if (!file_exists($vomsproxy)) {
            $output = implode("\n", $output);
            Portal::debug("VO {$vo} unknown, and/or user {$userdn} isn't in it!\n{$output}");
コード例 #12
0
USER_ID={$user_id}

function runJob() (
{$bashcode}
)

EOS
);
    exec("cd '{$sandbox}'; find -mindepth 1 -maxdepth 1 -print0 | xargs -0 tar zcf {$TEMPNAM}.tgz", $output, $return_var);
    if ($return_var) {
        $output = implode("\n", $output);
        REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR, $output);
    }
    $tokenhandle = fopen("{$TEMPNAM}.tgz", 'r');
    try {
        $token_url = Topos::putTokenFile($tokenhandle, 'application/x-compressed-tar');
    } catch (Exception $e) {
        fclose($tokenhandle);
        throw $e;
    }
    fclose($tokenhandle);
    $token_id = basename($token_url);
    Portal_MySQL::real_query(<<<EOS
INSERT INTO `Token`
       ( `token_id`,  `user_id` )
VALUES ( {$token_id}, {$user_id} );
EOS
);
    $resultURL = REST::urlbase() . Portal::portalURL() . "jobstates/{$token_id}";
    REST::created($resultURL);
}
コード例 #13
0
ファイル: locks.php プロジェクト: sara-nl/ToPoS
 * 
 * $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();
コード例 #14
0
<?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);
コード例 #15
0
}
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
);
        Topos::log('delete', array('realm' => $TOPOS_REALM, 'tokens' => Topos::mysqli()->affected_rows));
    } catch (Topos_MySQL $e) {
        Topos::mysqli()->rollback();
        throw $e;
    }
    if (!Topos::mysqli()->commit()) {
        REST::fatal(REST::HTTP_SERVICE_UNAVAILABLE, 'Transaction failed: ' . htmlentities(Topos::mysqli()->error));
    }
    REST::header(array('Content-Type' => REST::best_xhtml_type() . '; charset=UTF-8'));
    echo REST::html_start('Pool');
    echo '<p>Realm destroyed successfully.</p>';
    echo REST::html_end();
    exit;
}
REST::require_method('HEAD', 'GET');
if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
    REST::fatal(REST::HTTP_NOT_MODIFIED);
}
$directory = ToposDirectory::factory(<<<EOS
<h2>Delete</h2>
<form action="./?http_method=DELETE" method="post">
<input type="submit" value="Delete this realm"/>