You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

<?php
define('AUTH_KEY', '2(QMu)jt|2!(9t]V!4SB/y,+T]LcvGZ8-sV@vS6RUgR!_]&S}{6/RZjAmLeW28On');
3 years ago
//header('Content-type: text/plain;charset=utf-8');
header('Content-type: application/json;charset=utf-8');
$vars=array();
foreach(array('REQUEST_METHOD',
'REDIRECT_URL',
'QUERY_STRING',
'REQUEST_URI',
'REQUEST_TIME_FLOAT',
'REQUEST_TIME') as $key)
{
3 years ago
if(isset($_SERVER[$key]))
{
$vars[$key] = $_SERVER[$key];
}
else
{
$vars[$key] = "";
}
}
3 years ago
//echo json_encode($vars);
$query = preg_replace("/^\/api/","",$vars['REDIRECT_URL']);
//echo $query;
switch($query)
{
case "/toto/" :
case "/test/" :
header('HTTP/1.1 200 OK');
echo json_encode( (object) array('status'=>'active') );
break;
case "/key/" :
if($vars['REQUEST_METHOD'] == "POST")
{
3 years ago
if(!empty($_POST['user']) && !empty($_POST['password']))
{
$user = $_POST['user'];
$password = md5($_POST['password'].AUTH_KEY);
$response = array('user'=>$user,'md5'=>$password);
header('HTTP/1.1 200 OK');
echo json_encode( (object) $response );
3 years ago
}
else
{
header('HTTP/1.1 403 Forbidden');
echo json_encode( (object) array('error'=>'PLease provide a valid user and matching password') );
}
3 years ago
}
else
{
header('HTTP/1.1 405 Method Not Allowed');
echo json_encode( (object) array('error'=>'/key/ requires POST method') );
}
break;
default :
// header('HTTP/1.1 404 Not Found');
header('HTTP/1.1 501 Not Implemented');
echo json_encode( (object) array('error'=>'This path has not been implemented') );
break;
}