0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2025-06-11 02:53:28 +02:00

Reorganised files

Moved files meant for release to www folder
Removed old files
This commit is contained in:
peteruithoven
2014-04-24 12:09:08 +02:00
parent 101100f7e5
commit 7512b680b6
13 changed files with 339 additions and 1 deletions

20
www/api/connect.php Normal file
View File

@ -0,0 +1,20 @@
<?php
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
require 'credentials.php';
$database = "doodle3d_com_connect";
$dsn = "mysql:host=doodle1.sql.greenhost.nl;dbname=$database";
$table = "signins";
try {
$db = new PDO($dsn, $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
$response = array( "status" => "error",
"msg" => $e->getMessage()." (".$e->getCode().")");
exit(json_encode($response)."\r\n");
}
?>

24
www/api/create_table.php Normal file
View File

@ -0,0 +1,24 @@
<?php
require 'connect.php';
try {
// exported structure using phpMyAdmin
$createsql = $db->prepare("CREATE TABLE IF NOT EXISTS $table (" .
"`id` varchar(31) NOT NULL," .
"`remoteip` varchar(15) NOT NULL," .
"`localip` varchar(15) NOT NULL," .
"`wifiboxid` varchar(140) NOT NULL," .
"`hidden` tinyint(1) NOT NULL DEFAULT '0'," .
"`date` datetime NOT NULL," .
"PRIMARY KEY (`id`)" .
") ENGINE=InnoDB DEFAULT CHARSET=latin1;");
if($createsql->execute() == TRUE)
echo "$table created";
} catch (PDOException $e) {
$response = array( "status" => "error",
"msg" => $e->getMessage()." (".$e->getCode().")");
exit(json_encode($response)."\r\n");
}
?>

21
www/api/list.example Normal file
View File

@ -0,0 +1,21 @@
{
"status":"success",
"data":[
{
"id":"62.216.8.197\/10.0.0.18",
"remoteip":"62.216.8.197",
"localip":"10.0.0.18",
"wifiboxid":"Albert",
"hidden":"0",
"date":"2013-10-03 17:24:33",
},
{
"id":"62.216.8.197\/10.0.0.29",
"remoteip":"62.216.8.197",
"localip":"10.0.0.29",
"wifiboxid":"Wilbert",
"hidden":"0",
"date":"2013-10-03 17:52:19"
}
],
}

21
www/api/list.php Normal file
View File

@ -0,0 +1,21 @@
<?php
require 'connect.php';
$hourago = time() - 60*60;
$remoteip = getenv('REMOTE_ADDR');
try {
$statement = $db->prepare("SELECT * FROM $table where date >= FROM_UNIXTIME(:hourago) AND remoteip = :remoteip");
$statement->execute(array( ':hourago' => $hourago,
':remoteip' => $remoteip));
$boxes = $statement->fetchAll(PDO::FETCH_CLASS);
} catch (PDOException $e) {
$response = array( "status" => "error",
"msg" => $e->getMessage()." (".$e->getCode().")");
exit(json_encode($response)."\r\n");
}
$response = array( "status" => "success",
"data" => $boxes);
exit(json_encode($response)."\r\n");
?>

68
www/api/signin.php Normal file
View File

@ -0,0 +1,68 @@
<?php
/*if ($_SERVER['REQUEST_METHOD'] != "POST") {
$response = array( "status" => "error",
"msg" => "'signin' can only be accessed with the POST method");
exit(json_encode($response)."\r\n");
}*/
require 'connect.php';
if(!isset($_GET['localip'])) {
$response = array( "status" => "error",
"msg" => "missing localip");
exit(json_encode($response)."\r\n");
}
$localip = $_GET['localip'];
if(!isset($_GET['wifiboxid'])) {
$response = array( "status" => "error",
"msg" => "missing wifiboxid");
exit(json_encode($response)."\r\n");
}
$wifiboxid = $_GET['wifiboxid'];
$remoteip = getenv('REMOTE_ADDR');
$timestamp = time();
$id = $remoteip.'/'.$localip; //TODO: column length: 31
try {
$statement = $db->prepare( "REPLACE INTO $table " .
"SET id = :id, " .
" remoteip = :remoteip, " .
" localip = :localip, " .
" wifiboxid = :wifiboxid, " .
" date = FROM_UNIXTIME(:timestamp)");
$statement->execute(array( ":id" => $id,
":remoteip" => $remoteip,
":localip" => $localip,
":wifiboxid" => $wifiboxid,
":timestamp" => $timestamp));
} catch (PDOException $e) {
$response = array( "status" => "error",
"msg" => $e->getMessage()." (".$e->getCode().")");
exit(json_encode($response)."\r\n");
}
// Remove old signins
$hourago = time() - 60*60;
try {
$statement = $db->prepare("DELETE FROM $table WHERE date < FROM_UNIXTIME(:hourago)");
$statement->execute(array( ':hourago' => $hourago));
} catch (PDOException $e) {
$response = array( "status" => "error",
"msg" => $e->getMessage()." (".$e->getCode().")");
exit(json_encode($response)."\r\n");
}
$responseData = array( "remoteip" => $remoteip,
"localip" => $localip,
"wifiboxid" => $wifiboxid,
"timestamp" => $timestamp);
$response = array( "status" => "success",
"data" => $responseData);
exit(json_encode($response)."\r\n");
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

BIN
www/img/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
www/img/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

BIN
www/img/logo_full.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
www/img/logo_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB