3 * insert flowIDs and info to submit into log_db.log_t.
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['flag']) && isset($_REQUEST['service']) && isset($_REQUEST['flag_id']) && isset($_REQUEST['submitter'])) {
24 insertData($_REQUEST['flag'],$_REQUEST['service'], $_REQUEST['flag_id'], $_REQUEST['submitter']);
26 echo "<p><b>usage:</b><br>";
27 echo "GET /submit.php?flag=<i>STRING</i>&service=<i>STRING</i>&flag_id=<i>STRING</i>&submitter=<i>STRING</i><br>";
28 echo "POST<br> flag=<i>STRING</i>&service=<i>STRING</i>&flag_id=<i>STRING</i>&submitter=<i>STRING</i></p>";
32 function insertData($flag, $service, $flagid, $submitter) {
33 echo "<p><b>inserting data...</b></p>";
34 echo "flag=".htmlentities($flag)."<br>";
35 echo "service=".htmlentities($service)."</p>";
36 echo "flagid=".htmlentities($flagid)."</p>";
37 echo "submitter=".htmlentities($submitter)."</p>";
40 $GLOBALS['db']->beginTransaction();
41 $stmt_fid = $GLOBALS['db']->prepare("UPDATE flag_ids set status = 1 where service = ? and flag_id = ?");
42 $stmt_fid->execute(array($service, $flagid));
43 $GLOBALS['db']->commit();
44 $GLOBALS['db']->beginTransaction();
45 $stmt = $GLOBALS['db']->prepare("INSERT INTO flags (flag, service, flag_id, submitter) VALUES(?, ?, ?, ?)");
46 $stmt->execute(array($flag, $service, $flagid, $submitter));
47 $GLOBALS['db']->commit();
49 }catch(PDOException $ex) {
50 echo "<p><b>INSERT FAIL</b></p><p>".$ex->getMessage()."</p>";
51 $GLOBALS['db']->rollBack();
54 if ($success == 1) echo "<p><b>OK</b></p>";