forked from sara-nl/ToPoS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.php
More file actions
119 lines (109 loc) · 3.67 KB
/
lock.php
File metadata and controls
119 lines (109 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?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$
**************************************************************************/
//TODO
require_once('include/global.php');
$escLockUUID = Topos::escape_string($TOPOS_TOKEN);
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
Topos::real_query(<<<EOS
UPDATE `Tokens`
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`,
`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;
}
REST::header(array(
'Content-Type' => $xhtmltype . '; charset=UTF-8',
'Cache-Control' => 'no-cache',
));
if ($_SERVER['REQUEST_METHOD'] === 'HEAD') exit;
echo REST::html_start('Lock info');
?><h2>Lock info</h2>
<table class="lockinfo"><tbody>
<tr><th>TokenId:</th><td id="tokenId"><?php echo htmlentities($row[0]); ?></td></tr>
<tr><th>TokenName:</th><td id="tokenName"><?php echo htmlentities($row[1]); ?></td></tr>
<tr><th>TokenURL:</th><td id="tokenURL"><a href="<?php
echo htmlspecialchars($tokenURL, ENT_QUOTES, 'UTF-8');
?>"><?php echo htmlspecialchars($tokenURL, ENT_QUOTES, 'UTF-8'); ?></a></td></tr>
<tr><th>Timeout:</th><td id="timeout"><?php echo htmlentities($row[2], ENT_QUOTES, 'UTF-8'); ?></td></tr>
<tr><th>Description:</th><td id="description"><?php echo htmlentities($row[3], ENT_QUOTES, 'UTF-8'); ?></td></tr>
</tbody></table><?php
echo REST::html_end();