* do not publish! */ $GLOBALS['db'] = new PDO('pgsql:host=localhost;port=5432;dbname=flagbot;user=flagbot;password=flagbotpw'); $GLOBALS['db']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (strcmp($_SERVER['REQUEST_METHOD'],"GET") === 0 || strcmp($_SERVER['REQUEST_METHOD'],"POST") === 0 ) { handleRequest(); } else { http_response_code(405); //Method not implemented exit("

what? try GET or POST

"); } function handleRequest() { if (isset($_REQUEST['service'])) { getTargets($_REQUEST['service']); } else { echo "

usage:
"; echo "GET /get_targets.php?service=STRING
"; echo "POST
service=STRING

"; } } function getTargets($service) { try { $stmt = $GLOBALS['db']->prepare("SELECT * FROM flag_ids WHERE (received + INTERVAL '300 minute') > now() and service = ? and status = 0 ORDER BY received DESC"); $stmt->execute(array($service)); $targets = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode($targets); }catch(PDOException $ex) { echo "{}"; } }