Merge branch 'saas' of github.com:sourcefabric/Airtime into saas
This commit is contained in:
commit
ddd75cb8e3
|
@ -37,7 +37,7 @@ require_once (APPLICATION_PATH."/logging/Logging.php");
|
||||||
Logging::setLogPath('/var/log/airtime/zendphp.log');
|
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 need to manually route because we can't load Zend without the database being initialized first.
|
||||||
if (array_key_exists("REQUEST_URI", $_SERVER) && (strpos($_SERVER["REQUEST_URI"], "/provisioning/create") !== false)) {
|
if (array_key_exists("REQUEST_URI", $_SERVER) && (stripos($_SERVER["REQUEST_URI"], "/provisioning/create") !== false)) {
|
||||||
$provisioningHelper = new ProvisioningHelper($CC_CONFIG["apiKey"][0]);
|
$provisioningHelper = new ProvisioningHelper($CC_CONFIG["apiKey"][0]);
|
||||||
$provisioningHelper->createAction();
|
$provisioningHelper->createAction();
|
||||||
die();
|
die();
|
||||||
|
|
|
@ -10,6 +10,7 @@ class ProvisioningHelper
|
||||||
// Parameter values
|
// Parameter values
|
||||||
private $dbuser, $dbpass, $dbname, $dbhost, $dbowner, $apikey;
|
private $dbuser, $dbpass, $dbname, $dbhost, $dbowner, $apikey;
|
||||||
private $instanceId;
|
private $instanceId;
|
||||||
|
private $station_name, $description;
|
||||||
|
|
||||||
public function __construct($apikey)
|
public function __construct($apikey)
|
||||||
{
|
{
|
||||||
|
@ -34,34 +35,37 @@ class ProvisioningHelper
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$this->parsePostParams();
|
$this->parsePostParams();
|
||||||
|
|
||||||
//For security, the Airtime Pro provisioning system creates the database for the user.
|
//For security, the Airtime Pro provisioning system creates the database for the user.
|
||||||
$this->setNewDatabaseConnection();
|
if ($this->dbhost && !empty($this->dbhost)) {
|
||||||
|
$this->setNewDatabaseConnection();
|
||||||
|
|
||||||
//if ($this->checkDatabaseExists()) {
|
//if ($this->checkDatabaseExists()) {
|
||||||
// throw new Exception("ERROR: Airtime database already exists");
|
// throw new Exception("ERROR: Airtime database already exists");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (!$this->checkDatabaseExists()) {
|
if (!$this->checkDatabaseExists()) {
|
||||||
throw new Exception("ERROR: $this->dbname database does not exist.");
|
throw new Exception("ERROR: $this->dbname database does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//We really want to do this check because all the Propel-generated SQL starts with "DROP TABLE IF EXISTS".
|
//We really want to do this check because all the Propel-generated SQL starts with "DROP TABLE IF EXISTS".
|
||||||
//If we don't check, then a second call to this API endpoint would wipe all the tables!
|
//If we don't check, then a second call to this API endpoint would wipe all the tables!
|
||||||
if ($this->checkTablesExist()) {
|
if ($this->checkTablesExist()) {
|
||||||
throw new Exception("ERROR: airtime tables already exists");
|
throw new Exception("ERROR: airtime tables already exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->createDatabaseTables();
|
||||||
|
$this->initializeMusicDirsTable($this->instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//$this->createDatabase();
|
//$this->createDatabase();
|
||||||
|
|
||||||
//All we need to do is create the database tables.
|
//All we need to do is create the database tables.
|
||||||
|
|
||||||
$this->createDatabaseTables();
|
$this->initializePrefs();
|
||||||
$this->initializeMusicDirsTable($this->instanceId);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
http_response_code(400);
|
http_response_code(400);
|
||||||
Logging::error($e->getMessage()
|
Logging::error($e->getMessage());
|
||||||
);
|
|
||||||
echo $e->getMessage() . PHP_EOL;
|
echo $e->getMessage() . PHP_EOL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -94,6 +98,7 @@ class ProvisioningHelper
|
||||||
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
||||||
return $result !== FALSE;
|
return $result !== FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parsePostParams()
|
private function parsePostParams()
|
||||||
{
|
{
|
||||||
$this->dbuser = $_POST['dbuser'];
|
$this->dbuser = $_POST['dbuser'];
|
||||||
|
@ -102,6 +107,9 @@ class ProvisioningHelper
|
||||||
$this->dbhost = $_POST['dbhost'];
|
$this->dbhost = $_POST['dbhost'];
|
||||||
$this->dbowner = $_POST['dbowner'];
|
$this->dbowner = $_POST['dbowner'];
|
||||||
$this->instanceId = $_POST['instanceid'];
|
$this->instanceId = $_POST['instanceid'];
|
||||||
|
|
||||||
|
$this->station_name = $_POST['station_name'];
|
||||||
|
$this->description = $_POST['description'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,9 +119,9 @@ class ProvisioningHelper
|
||||||
private function setNewDatabaseConnection()
|
private function setNewDatabaseConnection()
|
||||||
{
|
{
|
||||||
self::$dbh = new PDO("pgsql:host=" . $this->dbhost
|
self::$dbh = new PDO("pgsql:host=" . $this->dbhost
|
||||||
. ";dbname=" . $this->dbname
|
. ";dbname=" . $this->dbname
|
||||||
. ";port=5432" . ";user=" . $this->dbuser
|
. ";port=5432" . ";user=" . $this->dbuser
|
||||||
. ";password=" . $this->dbpass);
|
. ";password=" . $this->dbpass);
|
||||||
//Turn on PDO exceptions because they're off by default.
|
//Turn on PDO exceptions because they're off by default.
|
||||||
//self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
//self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$err = self::$dbh->errorInfo();
|
$err = self::$dbh->errorInfo();
|
||||||
|
@ -130,8 +138,8 @@ class ProvisioningHelper
|
||||||
{
|
{
|
||||||
Logging::info("Creating database...");
|
Logging::info("Creating database...");
|
||||||
$statement = self::$dbh->prepare("CREATE DATABASE " . pg_escape_string($this->dbname)
|
$statement = self::$dbh->prepare("CREATE DATABASE " . pg_escape_string($this->dbname)
|
||||||
. " WITH ENCODING 'UTF8' TEMPLATE template0"
|
. " WITH ENCODING 'UTF8' TEMPLATE template0"
|
||||||
. " OWNER " . pg_escape_string($this->dbowner));
|
. " OWNER " . pg_escape_string($this->dbowner));
|
||||||
if (!$statement->execute()) {
|
if (!$statement->execute()) {
|
||||||
throw new Exception("ERROR: Failed to create Airtime database");
|
throw new Exception("ERROR: Failed to create Airtime database");
|
||||||
}
|
}
|
||||||
|
@ -182,5 +190,16 @@ class ProvisioningHelper
|
||||||
$musicDir->save();
|
$musicDir->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize preference values passed from the dashboard (if any exist)
|
||||||
|
*/
|
||||||
|
private function initializePrefs() {
|
||||||
|
if ($this->station_name) {
|
||||||
|
Application_Model_Preference::SetStationName($this->station_name);
|
||||||
|
}
|
||||||
|
if ($this->description) {
|
||||||
|
Application_Model_Preference::SetStationDescription($this->description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,40 @@ class ProvisioningController extends Zend_Controller_Action
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint to change Airtime preferences remotely.
|
||||||
|
* Mainly for use with the dashboard right now.
|
||||||
|
*/
|
||||||
|
public function changeAction() {
|
||||||
|
$this->view->layout()->disableLayout();
|
||||||
|
$this->_helper->viewRenderer->setNoRender(true);
|
||||||
|
|
||||||
|
if (!RestAuth::verifyAuth(true, true, $this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// This is hacky and should be genericized
|
||||||
|
if ($_POST['station_name']) {
|
||||||
|
Application_Model_Preference::SetStationName($_POST['station_name']);
|
||||||
|
}
|
||||||
|
if ($_POST['description']) {
|
||||||
|
Application_Model_Preference::SetStationDescription($_POST['description']);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->getResponse()
|
||||||
|
->setHttpResponseCode(400)
|
||||||
|
->appendBody("ERROR: " . $e->getMessage());
|
||||||
|
Logging::error($e->getMessage());
|
||||||
|
echo $e->getMessage() . PHP_EOL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->getResponse()
|
||||||
|
->setHttpResponseCode(200)
|
||||||
|
->appendBody("OK");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the Airtime Pro station's files from Amazon S3
|
* Delete the Airtime Pro station's files from Amazon S3
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -326,6 +326,11 @@ class Application_Model_Preference
|
||||||
return self::getValue("station_name");
|
return self::getValue("station_name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function SetStationName($station_name)
|
||||||
|
{
|
||||||
|
self::setValue("station_name", $station_name);
|
||||||
|
}
|
||||||
|
|
||||||
public static function SetAutoUploadRecordedShowToSoundcloud($upload)
|
public static function SetAutoUploadRecordedShowToSoundcloud($upload)
|
||||||
{
|
{
|
||||||
self::setValue("soundcloud_auto_upload_recorded_show", $upload);
|
self::setValue("soundcloud_auto_upload_recorded_show", $upload);
|
||||||
|
|
Loading…
Reference in New Issue