diff --git a/api/describe.php b/api/describe.php new file mode 100644 index 0000000000000000000000000000000000000000..b65095cc3a00277501e14ffc51a89bda5fb5c7bf --- /dev/null +++ b/api/describe.php @@ -0,0 +1,24 @@ +<?php +namespace SmartData; + +require_once('../bin/smartdata/SmartAPI.php'); +use function SmartData\SmartAPI\describe; +use SmartData\Exception\CustomException; +use SmartData\Logger; + +http_response_code(HttpStatusCode::BAD_REQUEST); + +try { + $content = file_get_contents('php://input'); + $response = describe($content); +}catch(CustomException $e){ + http_response_code($e->getHTTPCodeError()); + Logger::exception($e); + return false; +}catch(\Exception $e){ + http_response_code(HttpStatusCode::BAD_REQUEST); + Logger::exception($e); + return false; +} +http_response_code(HttpStatusCode::NO_CONTENT); +echo $response; diff --git a/api/finish.php b/api/finish.php new file mode 100644 index 0000000000000000000000000000000000000000..895d5f4a23d16f8b5da30805d4e378e35925fffc --- /dev/null +++ b/api/finish.php @@ -0,0 +1,23 @@ +<?php +namespace SmartData; + +require_once('../bin/smartdata/SmartAPI.php'); +use function SmartData\SmartAPI\finish; +use SmartData\Exception\CustomException; +use SmartData\Logger; + +http_response_code(HttpStatusCode::BAD_REQUEST); + +try { + $content = file_get_contents('php://input'); + $response = finish($content); +}catch(CustomException $e){ + http_response_code($e->getHTTPCodeError()); + header('X-Message: '. $e->getMessage(), false); + return false; +}catch(\Exception $e){ + http_response_code(HttpStatusCode::BAD_REQUEST); + return false; +} +http_response_code(HttpStatusCode::NO_CONTENT); +echo $response; diff --git a/api/list.php b/api/list.php new file mode 100644 index 0000000000000000000000000000000000000000..f6d3aea4d24535221d6f15d17f3f3834369771cc --- /dev/null +++ b/api/list.php @@ -0,0 +1,25 @@ +<?php +namespace SmartData; + +require_once('../bin/smartdata/SmartAPI.php'); +use function SmartData\SmartAPI\list_devices; +use SmartData\Exception\CustomException; +use SmartData\Logger; + +http_response_code(HttpStatusCode::BAD_REQUEST); + +try { + $content = file_get_contents('php://input'); + $response = list_devices($content); + +}catch(CustomException $e){ + http_response_code($e->getHTTPCodeError()); + Logger::exception($e); + return false; +}catch(\Exception $e){ + http_response_code(HttpStatusCode::BAD_REQUEST); + Logger::exception($e); + return false; +} +http_response_code(HttpStatusCode::OK); +echo $response; diff --git a/api/login.html b/api/login.html new file mode 100644 index 0000000000000000000000000000000000000000..6ce006cc69dfd937f9a806ccb41ce8fdad48699a --- /dev/null +++ b/api/login.html @@ -0,0 +1,22 @@ +<html> +<head> +<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> +<script> + function doLogin() { + console.log("iniciando..."); + let xhr = new XMLHttpRequest(); + xhr.open("POST", "https://iot.lisha.ufsc.br/grafana/login"); + xhr.setRequestHeader("Accept", "application/json"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onload = () => { document.getElementById("grafana_frame").src = "https://iot.lisha.ufsc.br:3000/"; } + let data = '{ "user": "aqtech@lisha.ufsc.br", "password": "jP#55Mh@" } '; + xhr.send(data); + console.log('Enviou...'); + } +</script> +</head> +<body onload="doLogin();"> +<iframe src="" style="min-width:800px; min-height:900px;" id="grafana_frame" name="grafana_frame"></iframe> +</iframe> +</body> +</html> diff --git a/api/nop.php b/api/nop.php new file mode 100644 index 0000000000000000000000000000000000000000..6f97c53a09161f2ec7e3d49e8429af40b4180698 --- /dev/null +++ b/api/nop.php @@ -0,0 +1,28 @@ +<?php +namespace SmartData; + +require_once('../bin/smartdata/SmartAPI.php'); +require_once('../bin/smartdata/Logger.php'); +require_once('../bin/smartdata/SmartData.php'); +require_once('../bin/smartdata/MultiSmartData.php'); + + +use SmartData\Exception\{AuthenticationException,BadRequestException,InternalException}; + +http_response_code(HttpStatusCode::BAD_REQUEST); + +try { +}catch(Exception\CustomException $e){ + http_response_code($e->getHTTPCodeError()); + error_log( $e ); + header('X-Message: '.$e->getMessage(), false); + return false; +}catch(\Exception $e){ + http_response_code(HttpStatusCode::BAD_REQUEST); + error_log( $e ); + header('X-Message: '.$e->getMessage(), false); + return false; +} + +http_response_code(HttpStatusCode::NO_CONTENT); + diff --git a/bin/smartdata/SmartAPI.php b/bin/smartdata/SmartAPI.php index 9e37fa22b978b7b1bdd71058e7afba675060d32a..d882470aacb0ce5b058fbf561391d161589c95f8 100644 --- a/bin/smartdata/SmartAPI.php +++ b/bin/smartdata/SmartAPI.php @@ -40,8 +40,7 @@ namespace SmartData\SmartAPI } if($return != NULL){ - $return = json_encode($return); - $return = preg_replace('/:"([0-9]*)"/',':$1',$return); + $return = json_encode( $return, JSON_NUMERIC_CHECK ); } else { throw new RequestFailedException("Error processing request: null return"); } @@ -94,8 +93,7 @@ namespace SmartData\SmartAPI } $pos = $pos + 1; } - $return = json_encode($return); - $return = preg_replace('/:"([0-9]*)"/',':$1',$return); + $return = json_encode( $return, JSON_NUMERIC_CHECK ); } else { throw new RequestFailedException("Error processing request: null return"); }