RFID Squeezebox Controller

by anonymous on March 3rd, 2009

No notes

Syntax: PHP
Show lines - Hide lines - Show in textbox - Download
<?
# read in all our unique keys
$keys = array();
$files = scandir('.');
foreach($files as $file){
  if (preg_match('/(.*)\.key$/', $file, $groups)){
    $contents = file_get_contents($file);
    $key = $groups[1];
    $keys[$key] = $contents;
  }
}
 
# see if this is a request to stop
if (isset($_GET['stop'])){
   file_get_contents("http://192.168.0.105:9000/status.html?p0=stop&player=00%3A04%3A20%3A06%3A4
4%3A87");
}
 
# see if we have a key parameter passed in
if (isset($_GET['key'])){
  $key = $_GET['key'];
 
  # output this as our last key
  file_put_contents("last", $key);
 
  # add the key file if it isn't already present
  if (!isset($keys[$key]) && strlen($key) > 0){
    // add the file
    touch($key . ".key");
    $keys[$key] = "";
  }
 
  # set the url if one is passed in
  if (isset($_GET['url'])){
    $url = $_GET['url'];
    file_put_contents($key . ".key", $url);
    $keys[$key] = $url;
  }
  # no url?  then this is a request to go hit that url
  else if (strlen($key) > 0){
    $url = $keys[$key];
 
    # this gets the url by hand
    $content = file_get_contents($url);
 
    print("<b>fetched url for key: $key</b>");
  }
}
 
# read our last key
$last = file_get_contents("last");
?>
 
<table>
 
<?
foreach($keys as $key => $value){
?>
<tr>
  <form action="index.php">
  <input type="hidden" name="key" value="<?= $key ?>" />
  <td
<? if (strcmp($last, $key) == 0){
     print("bgcolor='green'");
   }
?>
><code><?= $key ?></code></td>
  <td><input name="url" type="text" size="80" value="<?= $value ?>" /></td>
  <td><input type="submit" value="update"/></td>
  </form>
</tr>
<?
}
?>

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS