|
|
@ -1,6 +1,5 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************************
|
|
|
|
/************************************************************************************************
|
|
|
|
* API Documentation
|
|
|
|
* API Documentation
|
|
|
|
************************************************************************************************
|
|
|
|
************************************************************************************************
|
|
|
@ -103,58 +102,60 @@ sendMessage
|
|
|
|
|
|
|
|
|
|
|
|
************************************************************************************************/
|
|
|
|
************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* General API Controller
|
|
|
|
* General API Controller
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function api_controller() {
|
|
|
|
function api_controller() {
|
|
|
|
global $user, $DataJson, $_REQUEST;
|
|
|
|
global $user, $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
header("Content-Type: application/json; charset=utf-8");
|
|
|
|
header("Content-Type: application/json; charset=utf-8");
|
|
|
|
|
|
|
|
|
|
|
|
// decode JSON request
|
|
|
|
// decode JSON request
|
|
|
|
$input = file_get_contents("php://input");
|
|
|
|
$input = file_get_contents("php://input");
|
|
|
|
$input = json_decode($input, true);
|
|
|
|
$input = json_decode($input, true);
|
|
|
|
$_REQUEST = $input;
|
|
|
|
$_REQUEST = $input;
|
|
|
|
|
|
|
|
|
|
|
|
// get command
|
|
|
|
// get command
|
|
|
|
$cmd='';
|
|
|
|
$cmd = '';
|
|
|
|
if (isset($_REQUEST['cmd']) )
|
|
|
|
if (isset($_REQUEST['cmd']))
|
|
|
|
$cmd = strtolower( $_REQUEST['cmd']);
|
|
|
|
$cmd = strtolower($_REQUEST['cmd']);
|
|
|
|
|
|
|
|
|
|
|
|
// decode commands, without key
|
|
|
|
// decode commands, without key
|
|
|
|
switch( $cmd) {
|
|
|
|
switch ($cmd) {
|
|
|
|
case 'getversion':
|
|
|
|
case 'getversion':
|
|
|
|
getVersion();
|
|
|
|
getVersion();
|
|
|
|
die( json_encode($DataJson));
|
|
|
|
die(json_encode($DataJson));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'getapikey':
|
|
|
|
case 'getapikey':
|
|
|
|
getApiKey();
|
|
|
|
getApiKey();
|
|
|
|
die( json_encode($DataJson));
|
|
|
|
die(json_encode($DataJson));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get API KEY
|
|
|
|
// get API KEY
|
|
|
|
if (isset($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key']))
|
|
|
|
if (isset($_REQUEST['key']) && preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key']))
|
|
|
|
$key = $_REQUEST['key'];
|
|
|
|
$key = $_REQUEST['key'];
|
|
|
|
else
|
|
|
|
else
|
|
|
|
die( json_encode( array (
|
|
|
|
die(json_encode(array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Missing parameter "key".' )));
|
|
|
|
'error' => 'Missing parameter "key".'
|
|
|
|
|
|
|
|
)));
|
|
|
|
// check API key
|
|
|
|
|
|
|
|
|
|
|
|
// check API key
|
|
|
|
$user = User_by_api_key($key);
|
|
|
|
$user = User_by_api_key($key);
|
|
|
|
if ($user === false)
|
|
|
|
if ($user === false)
|
|
|
|
die( json_encode( array (
|
|
|
|
die(json_encode(array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Unable to find user' )));
|
|
|
|
'error' => 'Unable to find user'
|
|
|
|
|
|
|
|
)));
|
|
|
|
if ($user == null)
|
|
|
|
if ($user == null)
|
|
|
|
die( json_encode( array (
|
|
|
|
die(json_encode(array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Key invalid.' )));
|
|
|
|
'error' => 'Key invalid.'
|
|
|
|
|
|
|
|
)));
|
|
|
|
// decode command
|
|
|
|
|
|
|
|
switch( $cmd) {
|
|
|
|
// decode command
|
|
|
|
|
|
|
|
switch ($cmd) {
|
|
|
|
case 'getroom':
|
|
|
|
case 'getroom':
|
|
|
|
getRoom();
|
|
|
|
getRoom();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -162,34 +163,39 @@ function api_controller() {
|
|
|
|
getAngelType();
|
|
|
|
getAngelType();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'getuser':
|
|
|
|
case 'getuser':
|
|
|
|
getUser();
|
|
|
|
// TODO Dataleak! Only coordinators are allowed to see so much user informations.
|
|
|
|
|
|
|
|
//getUser();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'getshift':
|
|
|
|
case 'getshift':
|
|
|
|
getShift();
|
|
|
|
getShift();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'getmessage':
|
|
|
|
case 'getmessage':
|
|
|
|
getMessage();
|
|
|
|
// TODO Dataleak!
|
|
|
|
|
|
|
|
//getMessage();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'sendmessage':
|
|
|
|
case 'sendmessage':
|
|
|
|
sendMessage();
|
|
|
|
sendMessage();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Unknown Command "'. $cmd. '"' );
|
|
|
|
'error' => 'Unknown Command "' . $cmd . '"'
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// check
|
|
|
|
// check
|
|
|
|
if( $DataJson === false) {
|
|
|
|
if ($DataJson === false) {
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'DataJson === false' );
|
|
|
|
'error' => 'DataJson === false'
|
|
|
|
} elseif( $DataJson == null) {
|
|
|
|
);
|
|
|
|
$DataJson = array (
|
|
|
|
} elseif ($DataJson == null) {
|
|
|
|
'status' => 'failed',
|
|
|
|
$DataJson = array(
|
|
|
|
'error' => 'DataJson == null' );
|
|
|
|
'status' => 'failed',
|
|
|
|
|
|
|
|
'error' => 'DataJson == null'
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
echo json_encode($DataJson);
|
|
|
|
echo json_encode($DataJson);
|
|
|
|
die();
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -197,143 +203,151 @@ function api_controller() {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get Version of API
|
|
|
|
* Get Version of API
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getVersion(){
|
|
|
|
function getVersion() {
|
|
|
|
global $DataJson;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
$DataJson = array(
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'success',
|
|
|
|
'status' => 'success',
|
|
|
|
'Version' => 1);
|
|
|
|
'Version' => 1
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get API Key
|
|
|
|
* Get API Key
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getApiKey(){
|
|
|
|
function getApiKey() {
|
|
|
|
global $DataJson, $_REQUEST;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($_REQUEST['user']) ) {
|
|
|
|
if (! isset($_REQUEST['user'])) {
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Missing parameter "user".' );
|
|
|
|
'error' => 'Missing parameter "user".'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
elseif (!isset($_REQUEST['pw']) ) {
|
|
|
|
} elseif (! isset($_REQUEST['pw'])) {
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Missing parameter "pw".' );
|
|
|
|
'error' => 'Missing parameter "pw".'
|
|
|
|
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$Erg = sql_select( "SELECT `UID`, `Passwort`, `api_key` FROM `User` WHERE `Nick`='" . sql_escape($_REQUEST['user']) . "'");
|
|
|
|
$Erg = sql_select("SELECT `UID`, `Passwort`, `api_key` FROM `User` WHERE `Nick`='" . sql_escape($_REQUEST['user']) . "'");
|
|
|
|
|
|
|
|
|
|
|
|
if (count($Erg) == 1) {
|
|
|
|
if (count($Erg) == 1) {
|
|
|
|
$Erg = $Erg[0];
|
|
|
|
$Erg = $Erg[0];
|
|
|
|
if (verify_password( $_REQUEST['pw'], $Erg["Passwort"], $Erg["UID"])) {
|
|
|
|
if (verify_password($_REQUEST['pw'], $Erg["Passwort"], $Erg["UID"])) {
|
|
|
|
$key = $Erg["api_key"];
|
|
|
|
$key = $Erg["api_key"];
|
|
|
|
$DataJson = array(
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'success',
|
|
|
|
'status' => 'success',
|
|
|
|
'Key' => $key);
|
|
|
|
'Key' => $key
|
|
|
|
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'PW wrong' );
|
|
|
|
'error' => 'PW wrong'
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'User not found.' );
|
|
|
|
'error' => 'User not found.'
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get Room
|
|
|
|
* Get Room
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getRoom(){
|
|
|
|
function getRoom() {
|
|
|
|
global $DataJson, $_REQUEST;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['id']) ) {
|
|
|
|
if (isset($_REQUEST['id'])) {
|
|
|
|
$DataJson = mRoom( $_REQUEST['id']);
|
|
|
|
$DataJson = Room($_REQUEST['id']);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = mRoomList();
|
|
|
|
$DataJson = Room_ids();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get AngelType
|
|
|
|
* Get AngelType
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getAngelType(){
|
|
|
|
function getAngelType() {
|
|
|
|
global $DataJson, $_REQUEST;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['id']) ) {
|
|
|
|
if (isset($_REQUEST['id'])) {
|
|
|
|
$DataJson = mAngelType( $_REQUEST['id']);
|
|
|
|
$DataJson = AngelType($_REQUEST['id']);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = mAngelTypeList();
|
|
|
|
$DataJson = AngelType_ids();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get User
|
|
|
|
* Get User
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getUser(){
|
|
|
|
function getUser() {
|
|
|
|
global $DataJson, $_REQUEST;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['id']) ) {
|
|
|
|
if (isset($_REQUEST['id'])) {
|
|
|
|
$DataJson = mUser_Limit( $_REQUEST['id']);
|
|
|
|
$DataJson = mUser_Limit($_REQUEST['id']);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = mUserList();
|
|
|
|
$DataJson = User_ids();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get Shift
|
|
|
|
* Get Shift
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getShift(){
|
|
|
|
function getShift() {
|
|
|
|
global $DataJson, $_REQUEST;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['id']) ) {
|
|
|
|
if (isset($_REQUEST['id'])) {
|
|
|
|
$DataJson = mShift( $_REQUEST['id']);
|
|
|
|
$DataJson = Shift($_REQUEST['id']);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = mShiftList();
|
|
|
|
$DataJson = Shifts_filtered();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @TODO: Why are ALL messages of ALL users returned? Data leak. It is not checked if this is my message!
|
|
|
|
* Get Message
|
|
|
|
* Get Message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function getMessage(){
|
|
|
|
function getMessage() {
|
|
|
|
global $DataJson, $_REQUEST;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['id']) ) {
|
|
|
|
if (isset($_REQUEST['id'])) {
|
|
|
|
$DataJson = mMessage( $_REQUEST['id']);
|
|
|
|
$DataJson = Message($_REQUEST['id']);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = mMessageList();
|
|
|
|
$DataJson = Message_ids();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Send Message
|
|
|
|
* Send Message
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function sendMessage(){
|
|
|
|
function sendMessage() {
|
|
|
|
global $DataJson, $_REQUEST;
|
|
|
|
global $DataJson;
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($_REQUEST['uid']) ) {
|
|
|
|
if (! isset($_REQUEST['uid'])) {
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Missing parameter "uid".' );
|
|
|
|
'error' => 'Missing parameter "uid".'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
elseif (!isset($_REQUEST['text']) ) {
|
|
|
|
} elseif (! isset($_REQUEST['text'])) {
|
|
|
|
$DataJson = array (
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Missing parameter "text".' );
|
|
|
|
'error' => 'Missing parameter "text".'
|
|
|
|
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if( mMessage_Send( $_REQUEST['uid'], $_REQUEST['text']) === true) {
|
|
|
|
if (Message_send($_REQUEST['uid'], $_REQUEST['text']) === true) {
|
|
|
|
$DataJson = array( 'status' => 'success');
|
|
|
|
$DataJson = array(
|
|
|
|
|
|
|
|
'status' => 'success'
|
|
|
|
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$DataJson = array(
|
|
|
|
$DataJson = array(
|
|
|
|
'status' => 'failed',
|
|
|
|
'status' => 'failed',
|
|
|
|
'error' => 'Transmitting was terminated with an Error.');
|
|
|
|
'error' => 'Transmitting was terminated with an Error.'
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|