From 556a4bd76828f1a98a4e4ed44ad355aa6c802f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20M=C3=A4del?= Date: Mon, 17 Dec 2018 22:16:06 +0100 Subject: [PATCH] Added authentication for api/radio --- application/controllers/Api.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/application/controllers/Api.php b/application/controllers/Api.php index 2acfedbb..6b85efca 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -351,6 +351,8 @@ class API extends CI_Controller { function radio() { header('Content-type: application/json'); + $this->load->model('api_model'); + //$json = '{"radio":"FT-950","frequency":14075,"mode":"SSB","timestamp":"2012/04/07 16:47"}'; $this->load->model('cat'); @@ -360,6 +362,11 @@ class API extends CI_Controller { // Decode JSON and store $obj = json_decode(file_get_contents("php://input"), true); + if(!isset($obj['key']) || $this->api_model->authorize($obj['key']) == 0) { + echo json_encode(['status' => 'failed', 'reason' => "missing api key"]); + die(); + } + // Store Result to Database $this->cat->update($obj);