<?php
/** board script
* Displayes the submitted flowIDs of the
* last X time with meta information
* If the submission to gameserver was successfull (submitsuccess)
* and we got points for it (scoresuccess) it should be green bg
*
* 2014-16 by Jan "Someone" Vales <someone@somenet.org>
* 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);

$query = "SELECT count(*) as count , submitter, service, status FROM flags WHERE (received + INTERVAL '30 minute') > now()  group by submitter, service, status order by count DESC";

if (isset($_REQUEST['all'])) $query = "SELECT count(*) as count , submitter, service, status FROM flags group by submitter, service, status order by count DESC";

?>
<!DOCTYPE html>
  <html>
  <head>
    <link rel="stylesheet" type="text/css" href="styles.css"></link>
    <meta http-equiv="refresh" content="10;">
  </head>
  <body>
    <h1>Submission Board - Services/Exploits and their Flags</h1>
<p><a href="./index.php">Flags</a>
<a href="./index_serviceflags.php">Service + Exploit flags</a> <a href="./index_serviceflags.php?all">Alltime Service + Exploit flags</a>
<a href="./index_flag_ids.php">Flag_IDs</a></p>
    <p><?php if (!isset($_REQUEST['all'])) echo 'Shows all submissions of the last 30 min'; ?>

    <b>Current Time: <?php echo ' '.date('Y-m-d H:i:s');?></b><br>
    NUM ROWS: <?php echo sizeof($GLOBALS['db']->query($query)->fetchAll()); ?></p>
    <table style="width: 100%">
      <thead>
        <tr>
            <th>count</th>
            <th>service</th>
            <th>submitter</th>
            <th>status</th>
          </tr>
        </thead>
        <tbody>
          <?php
          $stmt = $GLOBALS['db']->query($query);
          while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
          ?>
            <tr class="score-<?php echo $row['status']; ?>">
              <td><?php echo $row['count']; ?>&nbsp;</td>
              <td><?php echo $row['service']; ?>&nbsp;</td>
              <td><?php echo $row['submitter']; ?>&nbsp;</td>
              <td><?php echo $row['status']; ?></td>
            </tr>
            <?php
          }
          ?>
        </tbody>
      </table>
    <p>Status: 0=submission pending; 1=submitted:OK; 2=submitted:Fail</p>
    </body>
    </html>