]> git.somenet.org - ctf/pub/submit_bot.git/blob - submit.php
adapted to esse-CTF
[ctf/pub/submit_bot.git] / submit.php
1 <?php
2 /**
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
7 *
8 * 2014 by Jan "Someone" Vales <someone@somenet.org>
9 * do not publish!
10 */
11
12 $GLOBALS['db'] = new PDO('pgsql:host=localhost;port=5432;dbname=postgres;user=postgres;password=dba');                                                                                                              
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['flag']) && isset($_REQUEST['service']) && strlen($_REQUEST['flag']) == 32 ) {
24      insertData($_REQUEST['flag'],$_REQUEST['service']);
25   } else {
26      echo "<p><b>usage:</b><br>";
27      echo "GET /submit.php?flag=<i>STRING</i>&service=<i>STRING</i> <br>";
28      echo "POST<br> flag=<i>STRING</i>&service=<i>STRING</i></p>";
29   }
30 }
31
32 function insertData($flag, $service) {
33   echo "<p><b>inserting data...</b></p>";
34   echo "flag=".htmlentities($flag)."<br>";
35   echo "service=".htmlentities($service)."</p>";
36   $success = 0;
37   try {
38     $GLOBALS['db']->beginTransaction();
39     $stmt = $GLOBALS['db']->prepare("INSERT INTO flags (flag, service) VALUES(?, ?)");
40     $stmt->execute(array($flag, $service));
41     $GLOBALS['db']->commit();
42     $success = 1;
43   }catch(PDOException $ex) {
44     echo "<p><b>INSERT FAIL</b></p><p>".$ex->getMessage()."</p>";
45     $GLOBALS['db']->rollBack();
46   }
47
48   if ($success == 1) echo "<p><b>OK</b></p>";
49 }
50