From 819862c37bf456be2f16816c0d35c9e3455dc0c3 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 10 Apr 2014 10:55:47 -0400 Subject: [PATCH] CC-5781: Upgrade script for new storage quota implementation cleaned up upgrade controller --- .../controllers/UpgradeController.php | 69 ++++++++++++------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/airtime_mvc/application/controllers/UpgradeController.php b/airtime_mvc/application/controllers/UpgradeController.php index a01eb5eca..bad83f409 100644 --- a/airtime_mvc/application/controllers/UpgradeController.php +++ b/airtime_mvc/application/controllers/UpgradeController.php @@ -9,35 +9,15 @@ class UpgradeController extends Zend_Controller_Action $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); - //TODO: check api key - //The API key is passed in via HTTP "basic authentication": - //http://en.wikipedia.org/wiki/Basic_access_authentication + if (!$this->verifyAuth()) { + retrun; + } - $CC_CONFIG = Config::getConfig(); - - //Decode the API key that was passed to us in the HTTP request. - $authHeader = $this->getRequest()->getHeader("Authorization"); - - $encodedRequestApiKey = substr($authHeader, strlen("Basic ")); - $encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":"); - - if ($encodedRequestApiKey !== $encodedStoredApiKey) - { - $this->getResponse() - ->setHttpResponseCode(401) - ->appendBody("Bad Authorization."); - return; - } - - //check current airtime version - $airtime_version = Application_Model_Preference::GetAirtimeVersion(); - if ($airtime_version != '2.5.2') { - $this->getResponse() - ->setHttpResponseCode(400) - ->appendBody("Upgrade to Airtime 2.5.3 FAILED. You must be using Airtime 2.5.2 to upgrade."); + if (!$this->verifyAirtimeVersion()) { return; } + //Begin upgrade $filename = "/etc/airtime/airtime.conf"; $values = parse_ini_file($filename, true); @@ -65,5 +45,42 @@ class UpgradeController extends Zend_Controller_Action ->appendBody("Upgrade to Airtime 2.5.3 OK"); } - + private function verifyAuth() + { + //The API key is passed in via HTTP "basic authentication": + //http://en.wikipedia.org/wiki/Basic_access_authentication + + $CC_CONFIG = Config::getConfig(); + + //Decode the API key that was passed to us in the HTTP request. + $authHeader = $this->getRequest()->getHeader("Authorization"); + + $encodedRequestApiKey = substr($authHeader, strlen("Basic ")); + $encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":"); + + if ($encodedRequestApiKey !== $encodedStoredApiKey) + { + $this->getResponse() + ->setHttpResponseCode(401) + ->appendBody("Error: Incorrect API key."); + return false; + } + return true; + } + + private function verifyAirtimeVersion() + { + $pref = CcPrefQuery::create() + ->filterByKeystr('system_version') + ->findOne(); + $airtime_version = $pref->getValStr(); + + if ($airtime_version != '2.5.2') { + $this->getResponse() + ->setHttpResponseCode(400) + ->appendBody("Upgrade to Airtime 2.5.3 FAILED. You must be using Airtime 2.5.2 to upgrade."); + return false; + } + return true; + } } \ No newline at end of file