From e2054c13c8e45b21dd71f7d6e2861e476a37e645 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Tue, 3 Mar 2015 16:04:45 -0500 Subject: [PATCH] Added provisioning code for change requests --- airtime_mvc/application/Bootstrap.php | 5 ++++ .../application/common/ProvisioningHelper.php | 29 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 7c9cf8c20..2db23c8f7 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -36,10 +36,15 @@ require_once (APPLICATION_PATH."/logging/Logging.php"); Logging::setLogPath('/var/log/airtime/zendphp.log'); // We need to manually route because we can't load Zend without the database being initialized first. +// We should probably look for a better way to do this rather tan overloading this if statement if (array_key_exists("REQUEST_URI", $_SERVER) && (stripos($_SERVER["REQUEST_URI"], "/provisioning/create") !== false)) { $provisioningHelper = new ProvisioningHelper($CC_CONFIG["apiKey"][0]); $provisioningHelper->createAction(); die(); +} else if (array_key_exists("REQUEST_URI", $_SERVER) && (stripos($_SERVER["REQUEST_URI"], "/provisioning/change") !== false)) { + $provisioningHelper = new ProvisioningHelper($CC_CONFIG["apiKey"][0]); + $provisioningHelper->changeAction(); + die(); } Config::setAirtimeVersion(); diff --git a/airtime_mvc/application/common/ProvisioningHelper.php b/airtime_mvc/application/common/ProvisioningHelper.php index a436e6974..61127463a 100644 --- a/airtime_mvc/application/common/ProvisioningHelper.php +++ b/airtime_mvc/application/common/ProvisioningHelper.php @@ -65,8 +65,33 @@ class ProvisioningHelper $this->initializePrefs(); } catch (Exception $e) { http_response_code(400); - Logging::error($e->getMessage() - ); + Logging::error($e->getMessage()); + echo $e->getMessage() . PHP_EOL; + return; + } + + http_response_code(201); + } + + /** + * Endpoint to change Airtime preferences remotely. + * Mainly for use with the dashboard right now. + */ + public function changeAction() { + $apikey = $_SERVER['PHP_AUTH_USER']; + if (!isset($apikey) || $apikey != $this->apikey) { + Logging::info("Invalid API Key: $apikey"); + http_response_code(403); + echo "ERROR: Incorrect API key"; + return; + } + + try { + $this->parsePostParams(); + $this->initializePrefs(); + } catch (Exception $e) { + http_response_code(400); + Logging::error($e->getMessage()); echo $e->getMessage() . PHP_EOL; return; }