diff --git a/airtime_mvc/application/configs/ACL.php b/airtime_mvc/application/configs/ACL.php index 83cba4b08..842778065 100644 --- a/airtime_mvc/application/configs/ACL.php +++ b/airtime_mvc/application/configs/ACL.php @@ -28,7 +28,8 @@ $ccAcl->add(new Zend_Acl_Resource('library')) ->add(new Zend_Acl_Resource('usersettings')) ->add(new Zend_Acl_Resource('audiopreview')) ->add(new Zend_Acl_Resource('webstream')) - ->add(new Zend_Acl_Resource('locale')); + ->add(new Zend_Acl_Resource('locale')) + ->add(new Zend_Acl_Resource('upgrade')); /** Creating permissions */ $ccAcl->allow('G', 'index') @@ -42,6 +43,7 @@ $ccAcl->allow('G', 'index') ->allow('G', 'audiopreview') ->allow('G', 'webstream') ->allow('G', 'locale') + ->allow('G', 'upgrade') ->allow('H', 'preference', 'is-import-in-progress') ->allow('H', 'usersettings') ->allow('H', 'plupload') diff --git a/airtime_mvc/application/controllers/UpgradeController.php b/airtime_mvc/application/controllers/UpgradeController.php new file mode 100644 index 000000000..bad83f409 --- /dev/null +++ b/airtime_mvc/application/controllers/UpgradeController.php @@ -0,0 +1,86 @@ +view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + if (!$this->verifyAuth()) { + retrun; + } + + if (!$this->verifyAirtimeVersion()) { + return; + } + + //Begin upgrade + $filename = "/etc/airtime/airtime.conf"; + $values = parse_ini_file($filename, true); + + $username = $values['database']['dbuser']; + $password = $values['database']['dbpass']; + $host = $values['database']['host']; + $database = $values['database']['dbname']; + $dir = __DIR__; + + passthru("export PGPASSWORD=$password && psql -h $host -U $username -q -f $dir/upgrade_sql/airtime_$airtime_upgrade_version/upgrade.sql $database 2>&1 | grep -v \"will create implicit index\""); + + $musicDir = CcMusicDirsQuery::create() + ->filterByType('stor') + ->filterByExists(true) + ->findOne(); + $storPath = $musicDir->getDirectory(); + + $freeSpace = disk_free_space($storPath); + $totalSpace = disk_total_space($storPath); + + Application_Model_Preference::setDiskUsage($totalSpace - $freeSpace); + + $this->getResponse() + ->setHttpResponseCode(200) + ->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 diff --git a/airtime_mvc/application/controllers/plugins/Acl_plugin.php b/airtime_mvc/application/controllers/plugins/Acl_plugin.php index 4cf9f97b5..c5dc4b9f4 100644 --- a/airtime_mvc/application/controllers/plugins/Acl_plugin.php +++ b/airtime_mvc/application/controllers/plugins/Acl_plugin.php @@ -117,7 +117,7 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract return; } - if (in_array($controller, array("api", "auth", "locale"))) { + if (in_array($controller, array("api", "auth", "locale", "upgrade"))) { $this->setRoleName("G"); } elseif (!Zend_Auth::getInstance()->hasIdentity()) { diff --git a/airtime_mvc/application/controllers/upgrade_sql/airtime_2.5.3/upgrade.sql b/airtime_mvc/application/controllers/upgrade_sql/airtime_2.5.3/upgrade.sql new file mode 100644 index 000000000..6c7980983 --- /dev/null +++ b/airtime_mvc/application/controllers/upgrade_sql/airtime_2.5.3/upgrade.sql @@ -0,0 +1,6 @@ +DELETE FROM cc_pref WHERE keystr = 'system_version'; +INSERT INTO cc_pref (keystr, valstr) VALUES ('system_version', '2.5.3'); + +ALTER TABLE cc_files DROP COLUMN state; +ALTER TABLE cc_files ADD import_status integer default 1; -- Default is "pending" +UPDATE cc_files SET import_status=0; -- Existing files are already "imported" diff --git a/install_minimal/upgrades/airtime-2.5.3/airtime-upgrade.php b/install_minimal/upgrades/airtime-2.5.3/airtime-upgrade.php index 09ecd7ed2..31792eb7a 100644 --- a/install_minimal/upgrades/airtime-2.5.3/airtime-upgrade.php +++ b/install_minimal/upgrades/airtime-2.5.3/airtime-upgrade.php @@ -1,11 +1,5 @@