]> git.somenet.org - ctf/pub/submit_bot.git/blob - get_targets.php
GITOLITE.txt
[ctf/pub/submit_bot.git] / get_targets.php
1 <?php
2 /**
3 * get targets for a given service.
4 * log_db.log_t gets periodically checked by
5 * script whichs tries to submit flowids to gameserver.
6 * Information about this status can be found in board.php
7 *
8 * 2014-15 by Jan "Someone" Vales <someone@somenet.org>
9 * do not publish!
10 */
11
12 $GLOBALS['db'] = new PDO('pgsql:host=localhost;port=5432;dbname=flagbot;user=flagbot;password=flagbotpw');
13 $GLOBALS['db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
14
15 if (strcmp($_SERVER['REQUEST_METHOD'],"GET") === 0 || strcmp($_SERVER['REQUEST_METHOD'],"POST") === 0 ) {
16   handleRequest();
17 } else {
18   http_response_code(405); //Method not implemented
19   exit("<p><b>what?</b> try GET or POST</p>");
20 }
21
22 function handleRequest() {
23   if (isset($_REQUEST['service'])) {
24      getTargets($_REQUEST['service']);
25   } else {
26      echo "<p><b>usage:</b><br>";
27      echo "GET /get_targets.php?service=<i>STRING</i> <br>";
28      echo "POST<br> service=<i>STRING</i></p>";
29   }
30 }
31
32 function getTargets($service) {
33   try {
34     $stmt = $GLOBALS['db']->prepare("SELECT * FROM flag_ids WHERE (received + INTERVAL '15 minute') > now() and service = ? and status = 0 ORDER BY received DESC");
35     $stmt->execute(array($service));
36     $targets = $stmt->fetchAll(PDO::FETCH_ASSOC);
37         echo json_encode($targets);
38   }catch(PDOException $ex) {
39     echo "{}";
40   }
41 }
42