Skip to content
defnull edited this page Aug 29, 2012 · 1 revision

Our SpaceAPI data file is generated and controlled by this small PHP script:

<?php

$dbfile = '/tmp/nok_status.db';
$pass = 'PASSWORD';

if (file_exists($dbfile)) {
  $status = unserialize(file_get_contents($dbfile));
} else {
  $status = array('open'=>False);
}

if($_POST and isset($_POST['key']) and $_POST['key'] == $pass) {
  foreach ($_POST as $key => $value) {
      switch($key) {
          case('key'): break;
          case('open'):
              $status[$key] = ($value === 'yes');
              break;
          default:
              die('ERROR');
      }
  }
  file_put_contents($dbfile, serialize($status));
  die('OK');
}

$data = array();
$data['api'] = '0.12';
$data['space'] = 'Noklab';
$data['logo'] = '...';
$data['icon'] = array("open"=>"...",
                      "closed"=>"...");
$data['url'] = "...";
$data['address'] = '...';
$data['open'] = $status['open'];

echo json_encode($data)."\n";

Changing status fields is done via POST requests:

wget -q -O - --post-data='key=PASSWORD&open=yes' http://example.com/space_status.php
Clone this wiki locally