本文整理汇总了PHP中REST::fatal方法的典型用法代码示例。如果您正苦于以下问题:PHP REST::fatal方法的具体用法?PHP REST::fatal怎么用?PHP REST::fatal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类REST
的用法示例。
在下文中一共展示了REST::fatal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doPOST
public function doPOST($sandbox, &$bashcode, &$database)
{
$name = $_POST['name'];
if (empty($name)) {
REST::fatal(REST::HTTP_BAD_REQUEST, 'Missing required parameter "name"');
}
file_put_contents($sandbox . 'name.txt', $name);
$bashcode = <<<EOS
\${APPDIR}greeter \$(< "\${INDIR}name.txt" )
EOS;
}
示例2: foreach
SELECT DISTINCT `handle`
FROM `handles`
WHERE `type` = ? AND `data` {$p_mode} ?
EOS
);
$statement->bind_param('ss', $key, $value);
foreach ($parampairs as $parampair) {
list($key, $value) = $parampair;
if ($p_mode == 'LIKE') {
preg_match_all('/([^~]|~.|~)/s', $value, $matches);
$value = implode(preg_replace(array('/%/', '/_/', '/^\\*/', '/^~(.+)/s'), array('\\%', '\\_', '%', '$1'), $matches[0]));
}
if (!$statement->execute()) {
switch (CP_MySQL::mysql()->errno) {
case 1139:
REST::fatal(REST::HTTP_BAD_REQUEST, CP_MySQL::mysql()->error);
break;
default:
throw new CP_MySQL_Exception(CP_MySQL::mysql()->error, CP_MySQL::mysql()->errno);
}
}
$r_handle = null;
$statement->bind_result($r_handle);
$r_handles = array();
while ($statement->fetch()) {
$r_handles[$r_handle] = 1;
}
if ($handles === null) {
$handles = $r_handles;
} else {
$handles = array_intersect_key($handles, $r_handles);
示例3: md5
require_once 'include/global.php';
$userdnmd5 = md5(Portal::user_dn());
$proxy = Portal::PROXY_DIR . $userdnmd5 . '.pem';
$escproxy = str_replace("'", "\\'", $proxy);
if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
$input = REST::inputhandle();
$output = fopen($proxy, 'w');
while (!feof($input)) {
if (($block = fread($input, 8192)) === false) {
REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR, 'Error while reading PUT data');
}
fwrite($output, $block);
}
fclose($output);
fclose($input);
REST::header(array('status' => REST::HTTP_NO_CONTENT));
exit;
}
REST::require_method('GET', 'HEAD');
if (file_exists($proxy)) {
REST::header(array('Content-Type' => 'text/plain; charset=UTF-8'));
system("openssl x509 -text -in '{$escproxy}'");
exit;
}
REST::fatal(REST::HTTP_NOT_FOUND, <<<EOS
<p>Couldn't find a proxy. You could try to delegate credentials here:</p>
<ul>
<li><a href="myproxy">./myproxy</a></li>
</ul>
EOS
);
示例4: COUNT
* 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);
//Deprecated:
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
Topos::real_query(<<<EOS
DELETE `Pools`, `Tokens`
FROM `Pools` NATURAL LEFT JOIN `Tokens`
WHERE `Pools`.`poolName` = {$escPool};
EOS
);
REST::fatal(REST::HTTP_OK, 'Pool destroyed successfully.');
}
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>Getting the next token</h3>
<form action="nextToken" method="get">
<input type="text" name="name"/> Token name search string<br/>
<input type="text" name="timeout"/> Timeout in seconds (leave empty for shared tokens)<br/>
示例5: UNIX_TIMESTAMP
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;
}
echo <<<EOS
TokenId: {$row[0]}
TokenName: {$row[1]}
TokenURL: {$tokenURL}
Timeout: {$row[2]}
Description: {$row[3]}
示例6: catch
}
// if ( !$stmt2->execute() )
}
// if (isset($t_upload_map[$paramname][$key]))
}
// foreach ( $file['name'] as $key => $filename )
}
// foreach ($_FILES as $paramname => $file)
} 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::fatal(REST::HTTP_ACCEPTED);
}
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;
示例7:
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}");
}
$result = Portal_MySQL::query(<<<EOS
SELECT `token_error`
FROM `Token`
WHERE `token_id`={$escjobid}
AND `user_id`={$escuserid};
EOS
);
if (!($row = $result->fetch_row())) {
// Can't find what the user is looking for
REST::fatal(REST::HTTP_GONE);
}
if (empty($row[0])) {
REST::fatal(REST::HTTP_NOT_FOUND, "<p>Your job hasn't been executed yet. Try again later.</p>");
}
REST::fatal(REST::HTTP_OK, '<p>Your job finished with the following error:</p><pre>' . REST::htmlspecialchars($row[0]) . '</pre>');
示例8: current
/**
* @param bool $required
* @return Portal_User
*/
public static function current()
{
if (self::$current === null) {
switch ($_SERVER['SERVER_PORT']) {
case Portal::PORT_PLAIN:
self::unauthorized();
break;
// strictly unnecessary, but syntactically nicer.
// strictly unnecessary, but syntactically nicer.
case Portal::PORT_SSL:
if (!isset($_SERVER['PHP_AUTH_USER'])) {
self::unauthorized();
}
$user_email = Portal_MySQL::escape_string($_SERVER['PHP_AUTH_USER']);
$user_password = md5($_SERVER['PHP_AUTH_PW']);
$result = Portal_MySQL::query(<<<EOS
SELECT `user_id`, `user_name`, `user_dn` FROM `User`
WHERE `user_email` = {$user_email}
AND `user_password`= '{$user_password}';
EOS
);
if (!($row = $result->fetch_row())) {
self::unauthorized();
}
self::$current = new Portal_User((int) $row[0], $_SERVER['PHP_AUTH_USER'], $row[1], $row[2]);
break;
case Portal::PORT_SSL_CSA:
$user_dn = self::csa_dn();
if (isset($_SERVER['PHP_AUTH_USER']) && (int) $_SERVER['PHP_AUTH_USER'] > 0 && preg_match('@^/O=dutchgrid/O=users/O=sara/CN=(?:Evert Lammerts|Pieter van Beek)@', $_SERVER['SSL_CLIENT_S_DN'])) {
$esc_user_id = (int) $_SERVER['PHP_AUTH_USER'];
$result = Portal_MySQL::query(<<<EOS
SELECT `user_email`, `user_name`, `user_dn` FROM `User`
WHERE `user_id` = {$esc_user_id};
EOS
);
if (!($row = $result->fetch_row())) {
REST::fatal(REST::HTTP_UNAUTHORIZED, "No such user id: {$esc_user_id}");
}
self::$current = new Portal_User($esc_user_id, $row[1], $row[0], $row[2], true);
} else {
$esc_user_dn = Portal_MySQL::escape_string($user_dn);
$result = Portal_MySQL::query(<<<EOS
SELECT `user_id`, `user_email`, `user_name` FROM `User`
WHERE `user_dn` = {$esc_user_dn};
EOS
);
if (!($row = $result->fetch_row())) {
self::unauthorized();
}
self::$current = new Portal_User($row[0], $row[2], $row[1], $user_dn);
}
break;
default:
REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR);
}
}
return self::$current;
}
示例9: address
if (!$mailresult) {
REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR, <<<EOS
Your registration was successful, but the email containing your password could not be sent.
The site administrator has been informed and will contact you as soon as possible.
EOS
);
}
$message = <<<EOS
<p>Registration successful.</p>
<p>An e-mail with password has been sent to
<a href="mailto:{$_GET['email']}">{$_GET['email']}</a>.</p>
EOS;
if ($referrer) {
$message .= <<<EOS
<p>Click here to continue:<br/>
<a href="{$referrer}">{$referrer}</a></p>
EOS;
}
REST::fatal(REST::HTTP_ACCEPTED, $message);
}
REST::header(REST::best_xhtml_type() . '; charset="UTF-8"');
echo REST::html_start('Register') . <<<EOS
<p>Fill in your e-mail address and display name below, and you'll recieve a password.</p>
<form action="register.php" method="get">
<input type="hidden" name="referrer" value="{$referrer}"/>
<input type="text" name="email" value=""/> E-mail address (invisible to other users)<br/>
<input type="text" name="name" value=""/> Display name (visible to other users if you share your databases)<br/>
<input type="submit" value="Request password"/>
</form>
EOS
. REST::html_end();
示例10: runJob
#!/bin/bash
DATABASE={$escdatabase}
APPLICATION='{$applicationURL}'
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
示例11: md5
if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['server'])) {
REST::fatal(REST::HTTP_BAD_REQUEST, 'Missing required parameter.');
}
//$output = array();
$userdnmd5 = md5(Portal::user_dn());
$username = escapeshellarg(trim($_POST['username']));
$password = escapeshellarg(trim($_POST['password']));
$server = escapeshellarg(trim($_POST['server']));
$filename = escapeshellarg(Portal::PROXY_DIR . $userdnmd5 . '.pem');
exec("echo {$password} | myproxy-logon -v -l {$username} -s {$server} -S -o {$filename} 2>&1", $output, $returnval);
$output = implode("\n", $output);
if (preg_match('/^(?:invalid pass phrase|No credentials exist for username .*)$/m', $output)) {
REST::fatal(REST::HTTP_UNAUTHORIZED, 'Invalid username and/or pass phrase');
}
if ($returnval) {
REST::fatal(REST::HTTP_BAD_REQUEST, '<pre>' . htmlentities($output) . '</pre>');
}
$escserver = Portal_MySQL::escape_string($_POST['server']);
$escusername = Portal_MySQL::escape_string($_POST['username']);
$escpassword = Portal_MySQL::escape_string($_POST['password']);
Portal_MySQL::real_query("UPDATE `User` SET `proxy_server` = {$escserver}, `proxy_username` = {$escusername}, `proxy_password` = {$escpassword} WHERE `user_dn_md5` = '{$userdnmd5}'");
$best_xhtml_type = REST::best_xhtml_type();
$type = REST::best_content_type(array($best_xhtml_type => 1.0, 'text/plain' => 1.0), $best_xhtml_type);
$relurl = REST::urlencode(dirname($_SERVER['REDIRECT_URL'])) . '/proxy';
REST::header(array('status' => REST::HTTP_CREATED, 'Location' => REST::urlbase() . $relurl, 'Content-Type' => "{$type}; charset=UTF-8"));
if ($type == 'text/plain') {
echo REST::urlbase() . $relurl;
} else {
echo Portal::html_start('Proxy created') . "<p><a href=\"proxy\">proxy</a></p>" . Portal::html_end();
}
exit;
示例12: doPOST
public function doPOST($sandbox, &$bashcode, &$database)
{
$bashstring = <<<EOS
DBDIR=\${DBFILE}.d/
rm -rf \${DBDIR} || true
mkdir \${DBDIR}
cd \${DBDIR}
tar xf \${DBFILE}
if [ \$( ls -1d *.pal 2>/dev/null | wc -l ) -eq 1 ]; then
DB=\$( basename *.pal .pal )
elif [ \$( ls -1d *.pin 2>/dev/null | wc -l ) -eq 1 ]; then
DB=\$( basename *.pin .pin )
else
echo "No valid database found"
exit 2
fi
cd \${OUTDIR}
\${APPDIR}omssa-2.1.4/omssacl -d \${DBDIR}\${DB}
EOS;
// Check -d parameter
if (empty($_POST[$this->db_url])) {
REST::fatal(REST::HTTP_BAD_REQUEST, "You need to specify a database URL");
}
$database = $_POST[$this->db_url];
// File uploads
$filecounter = 0;
foreach ($this->files as $input => $required) {
if (Portal::isUploaded($input)) {
if (!move_uploaded_file($_FILES[$input]['tmp_name'], $sandbox . $filecounter)) {
REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR, "Couldn't store uploaded file.");
}
$bashstring .= " -{$input} \"\${INDIR}{$filecounter}\"";
$filecounter++;
} else {
if ($required) {
REST::fatal(REST::HTTP_BAD_REQUEST, "Missing required file {$input}");
}
}
}
// Check flags
foreach ($this->flags as $flag) {
if (!empty($_POST[$flag])) {
$bashstring .= " -{$flag}";
}
}
// Check params
foreach ($this->params as $paramname => $defaultvalue) {
if (isset($_POST[$paramname]) && strlen($_POST[$paramname]) && $_POST[$paramname] != $defaultvalue) {
$bashstring .= " -{$paramname} " . escapeshellarg($_POST[$paramname]);
}
}
$bashcode = $bashstring . " || exit 2";
}
示例13: array
* limitations under the License.
*
* $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] : ''));
}
示例14: catch
Portal_MySQL::real_query(<<<EOS
INSERT INTO `Database`
( `name`, `version`, `user_id`, `is_shared`, `checksum`, `type` )
VALUES
( {$dbname}, {$dbversion}, {$user_id}, {$is_shared}, '{$checksum}', {$typeId} );
EOS
);
} catch (Portal_MySQL_Exception $e) {
unlink($tmpfilename);
REST::fatal(REST::HTTP_CONFLICT, "Can't overwrite existing file: name={$dbname}, version={$dbversion}, type={$_POST['type']}");
}
$insert_id = Portal_MySQL::mysql()->insert_id;
if (!rename($tmpfilename, Portal_DB::DATABASE_DIR . $insert_id)) {
unlink($tmpfilename);
Portal_MySQL::real_query("DELETE FROM `Database` WHERE `database_id` = {$insert_id}");
REST::fatal(REST::HTTP_INTERNAL_SERVER_ERROR, "Couldn't store uploaded file.");
}
chmod(Portal_DB::DATABASE_DIR . $insert_id, 0660);
}
$extension = Portal_DB::databaseTypeExtension($typeId);
$htmlurl = "{$insert_id}.{$extension}";
$fullurl = REST::urlbase() . $_SERVER['REDIRECT_URL'] . $htmlurl;
$content_type = REST::best_content_type(array(REST::best_xhtml_type() => 1.0, 'text/plain' => 0.5), 'text/plain');
if ($content_type == 'text/plain') {
REST::header(array('status' => REST::HTTP_CREATED, 'Location' => $fullurl, 'Content-Type' => 'text/plain; charset=US-ASCII'));
echo $fullurl;
exit;
}
REST::header(array('status' => REST::HTTP_CREATED, 'Location' => $fullurl, 'Content-Type' => REST::best_xhtml_type() . '; charset=US-ASCII'));
echo Portal::html_start('New database created') . "<a href=\"{$htmlurl}\" rel=\"child\" rev=\"index\">{$htmlurl}</a>" . Portal::html_end();
exit;
示例15: escapeshellarg
*
* 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: myproxy_renew.php 2378 2009-07-14 14:00:34Z pieterb $
**************************************************************************/
/**
* File documentation.
* @package Portal
*/
require_once 'include/global.php';
if (Portal::user_dn() != @$_SERVER['SSL_SERVER_S_DN']) {
REST::fatal(REST::HTTP_UNAUTHORIZED);
}
REST::require_method('GET');
foreach (glob(Portal::PROXY_DIR . '*.pem') as $fullfilename) {
$escfullfilename = escapeshellarg($fullfilename);
exec("grid-proxy-info -f {$escfullfilename} -exists -valid 1:00", $output, $returnval);
if (!$returnval) {
continue;
}
// The proxy is valid for at least another hour
$user_dn_md5 = Portal_MySQL::escape_string(basename($fullfilename, '.pem'));
$result = Portal_MySQL::query(<<<EOS
SELECT `proxy_server`, `proxy_username`, `proxy_password` FROM `User`
WHERE `user_dn_md5` = {$user_dn_md5};
EOS
);