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
 
   8 * 2014-15 by Jan "Someone" Vales <someone@somenet.org>
 
  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);
 
  15 if (strcmp($_SERVER['REQUEST_METHOD'],"GET") === 0 || strcmp($_SERVER['REQUEST_METHOD'],"POST") === 0 ) {
 
  18   http_response_code(405); //Method not implemented
 
  19   exit("<p><b>what?</b> try GET or POST</p>");
 
  22 function handleRequest() {
 
  23   if (isset($_REQUEST['service'])) {
 
  24      getTargets($_REQUEST['service']);
 
  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>";
 
  32 function getTargets($service) {
 
  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) {