Commit 63dd98a8 authored by Steve Johnson's avatar Steve Johnson

updated README

parent 8aff13e2
......@@ -2,7 +2,8 @@ My Stuff Everywhere(TM) by Cable Television Laboratories, Inc. is licensed under
Based on a work at github.com/cablelabs/mse
http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
The license text below was current as of 9/30/2014. Up to date
license information can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
Attribution 4.0 International
......
#My Stuff Everywhere™ - mse-php repository
Contains a mockup of back end (web services). There is no database. The portal user interface is very primitive. This code is intended for illustration purposes and API validation only. You should use this as a functional guide and write your back end from scratch.
There are several folders that need to exist with write permissions on the server for this to work:
yourdomain.com/prod/mse/php/log
yourdomain.com/prod/mse/php/auth/cookies
yourdomain.com/prod/mse/php/auth/log
yourdomain.com/prod/mse/php/auth/userapps
yourdomain.com/prod/mse/php/dial/subnets
##Folder descriptions
####auth
Contains the user/guest portals, oauth api abstractions for DropBox and Google (and a faked out API for USPS), application definitions, user login cookies, and user access tokens for authorized services (userapps).
####dial
Contains code to upload/download information about discovered DIAL servers.
####images
Contains image files
<?php
/* discovery.php
*
* Web proxy for local device discovery
*
* Copyright CableLabs 2014. All rights reserved.
*/
require '../utils.php';
function subnet_addr($ipaddr) {
$octets = explode(".", $ipaddr);
$leftByte = intval($octets[0]);
// check for class A, where first octet is 1-127
if (($leftByte & 128) == 0) {return "{$octets[0]}.00.00.00";} //class A
// check for class C, where first octet is 192-223
if (($leftByte & 192) == 192) {return "{$octets[0]}.{$octets[1]}.{$octets[2]}.00";} //class C
// check for class B, where first octet is 128-191
if (($leftByte & 128) == 128) {return "{$octets[0]}.{$octets[1]}.00.00";} //class B
return ipAddr;
}
// Purge aged discovery records
foreach (glob('./subnets/*') as $file)
{
$filelastmodified = filemtime($file);
$delta = time()-$filelastmodified;
// Note: Discovery Proxy (mseproxy) should update every 30 seconds.
if ($delta > 45)
{
unlink($file);
}
}
// Check query params for special actions
if (isset($_GET['list'])) {
// GET from web client application (remote SDOM device)
header('HTTP/1.0 200 OK');
header('Content-type: application/json');
$subnet = subnet_addr(remote_ipaddress());
$subnets_dir = dirname(__FILE__).'/subnets/';
$discovery_file = $subnets_dir.'/'.$subnet;
if (!file_exists($discovery_file)) {
echo '{"bridges" : [], "devices" : [], "subnet" : "'.remote_ipaddress().'"}';
}
else {
$server_list = file_get_contents($discovery_file);
echo $server_list;
}
}
else if (isset($_GET['update'])) {
// POST from discovery proxy
header('HTTP/1.0 200 OK');
$post_data = file_get_contents("php://input");
$server_list = json_decode($post_data, true);
// Add our subnet to the object (informational)
$subnet = subnet_addr(remote_ipaddress());
$server_list['subnet'] = $subnet;
// Add empty arrays if missing.
$empty_array = array();
if (!isset($server_list['devices'])) {
$server_list['devices'] = $empty_array;
}
if (!isset($server_list['bridges'])) {
$server_list['bridges'] = $empty_array;
}
$json = json_encode($server_list);
$subnets_dir = dirname(__FILE__).'/subnets/';
$discovery_file = $subnets_dir.'/'.$subnet;
$fp = fopen($discovery_file, 'w');
fwrite($fp, $json);
fclose($fp);
}
else {
header('HTTP/1.0 400 Bad Request');
echo "HTTP/1.0 400 Bad Request";
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment