From 17f1c5c857daaa10b66bd19f230b69c0a21611e9 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sun, 26 Nov 2023 18:08:45 -0500 Subject: [PATCH] bko controller --- www-api/app/Config/Routes.php | 5 ++ www-api/app/Controllers/Bko.php | 101 ++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 www-api/app/Controllers/Bko.php diff --git a/www-api/app/Config/Routes.php b/www-api/app/Config/Routes.php index b1d0bdb7..5887069d 100644 --- a/www-api/app/Config/Routes.php +++ b/www-api/app/Config/Routes.php @@ -221,6 +221,11 @@ $routes->post('/en/wrench/hooks/v1/stripes', 'WrenchHooks::stripes'); // cron jobs ------------ ===== ------------ $routes->post('/en/wrench/api/v1/cron', 'WrenchCrons::apigate'); $routes->get('/en/wrench/api/v1/cron', 'WrenchCrons::apigate'); + +$routes->get('/en/wrench/api/v1/bko', 'Bko::apigate'); + + + /* * -------------------------------------------------------------------- * Additional Routing diff --git a/www-api/app/Controllers/Bko.php b/www-api/app/Controllers/Bko.php new file mode 100644 index 00000000..10de2676 --- /dev/null +++ b/www-api/app/Controllers/Bko.php @@ -0,0 +1,101 @@ +request = $request = \Config\Services::request(); + } + public function index() + { + return []; + } + + public function apigate() + { + + $endpoints = array( + 'generics' => array('POST') + ); + + $call_backend = true; // sometimes we need to overwite the call to the extenstion API + $local_out = []; // use local out to send output when the result is not from the extenstion + $ret = -1; + + + header("Access-Control-Allow-Origin: *"); + header("Access-Control-Expose-Headers: Access-Control-Allow-Origin"); + header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"); + header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS"); + header('Content-type: application/json'); + + if ("OPTIONS" === $_SERVER['REQUEST_METHOD']) { + exit(); + } + + $endpoint = strtolower(str_replace('/svs/bko/', '', strtok($_SERVER['REQUEST_URI'], '?'))); + + $id = 0; // update, get & delete actions require ID + if (substr($endpoint, 0, 19) == 'gettransportrequest' || substr($endpoint, 0, 13) == 'updateprofile') { + $endpoint = strtok($endpoint, '/'); + $id = strtok('/'); + } + + if (!isset($endpoints[$endpoint])) { + header('HTTP/1.1 400 Bad Request'); + header('Status: 400 Bad Request'); + echo "{\"status\":\"Invalid endpoint url WRB\"}"; + exit(); + } + + $methods = $endpoints[$endpoint]; + + if (array_search($_SERVER['REQUEST_METHOD'], $methods) === false) { + header('HTTP/1.1 405 Method Not Allowed'); + header('Status: 405 Method Not Allowed'); + echo "{\"status\":\"Invalid request method\"}"; + exit(); + } + + if ($_SERVER["REQUEST_METHOD"] == "POST") { + $in = flatten(json_decode(file_get_contents('php://input'), true)); + } + if ($_SERVER["REQUEST_METHOD"] == "PUT") { + parse_str(file_get_contents('php://input'), $in); + } + if ($_SERVER["REQUEST_METHOD"] == "GET") { + $in = $_GET; + } + $in["loc"] = $_SERVER["REMOTE_ADDR"]; + switch ($endpoint) { + case 'generics': + break; + } + + $in["pid"] = 100; + + $out = array(); + if ( $call_backend == true){ + $wrenchboard = new \App\Models\BackendModel(); + $ret = $wrenchboard->wrenchboard_api($in, $out); + $out['internal_return'] = $ret; // this is reserved array parameter - to be captured and received before you use the out array() + } + else + { + $out = $local_out; + } + + + header("HTTP/1.1 200 OK"); + header("Status: 200 OK"); +//$out = array_merge($in, $out); // DEBUG + echo json_encode(( new \App\Models\ResultFormatter() )->processOutJson($in, $out)); + exit(); + } +} \ No newline at end of file