-CC-2044: remove hardcoded settings from application/configs/conf.php

-rearranged some stuff...some bugs still to go
This commit is contained in:
martin 2011-03-29 18:32:53 -04:00
parent 161505a6df
commit 2702363a33
15 changed files with 130 additions and 92 deletions

View file

@ -1,12 +1,4 @@
<?php <?php
define('AIRTIME_VERSION', '1.7.0-alpha');
define('AIRTIME_COPYRIGHT_DATE', '2010-2011');
define('AIRTIME_REST_VERSION', '1.1');
// These are the default values for the config.
global $CC_CONFIG;
$values = load_airtime_config();
// ********************************** // **********************************
// ***** START CUSTOMIZING HERE ***** // ***** START CUSTOMIZING HERE *****
// ********************************** // **********************************
@ -16,37 +8,45 @@ $values = load_airtime_config();
// For example: // For example:
// $baseFilesDir = '/home/john/radio-files'; // $baseFilesDir = '/home/john/radio-files';
$baseFilesDir = __DIR__.'/../../files'; $baseFilesDir = __DIR__.'/../../files';
// ***********************************************************************
// STOP CUSTOMIZING HERE
//
// You don't need to touch anything below this point.
// ***********************************************************************
define('AIRTIME_VERSION', '1.7.0-alpha');
define('AIRTIME_COPYRIGHT_DATE', '2010-2011');
define('AIRTIME_REST_VERSION', '1.1');
// These are the default values for the config.
global $CC_CONFIG;
$values = load_airtime_config();
$CC_CONFIG = array( $CC_CONFIG = array(
// Name of the web server user // Name of the web server user
'webServerUser' => 'www-data', 'webServerUser' => $values['general']['webServerUser'],
'rabbitmq' => array("host" => "127.0.0.1", 'rabbitmq' => $values['rabbitmq'],
"port" => "5672",
"user" => "guest",
"password" => "guest",
"vhost" => "/"),
// ***********************************************************************
// STOP CUSTOMIZING HERE
//
// You don't need to touch anything below this point.
// ***********************************************************************
'baseFilesDir' => $baseFilesDir, 'baseFilesDir' => $baseFilesDir,
// main directory for storing binary media files // main directory for storing binary media files
'storageDir' => "$baseFilesDir/stor", 'storageDir' => "$baseFilesDir/stor",
// Database config // Database config
'dsn' => $values['database'], 'dsn' => array(
'username' => $values['database']['dbuser'],
'password' => $values['database']['dbpass'],
'hostspec' => $values['database']['host'],
'phptype' => 'pgsql',
'database' => $values['database']['dbname']),
// prefix for table names in the database // prefix for table names in the database
'tblNamePrefix' => 'cc_', 'tblNamePrefix' => 'cc_',
/* ================================================ storage configuration */ /* ================================================ storage configuration */
'apiKey' => $values['api_key'], 'apiKey' => array($values['general']['api_key']),
'apiPath' => '/api/', 'apiPath' => '/api/',
'soundcloud-client-id' => '2CLCxcSXYzx7QhhPVHN4A', 'soundcloud-client-id' => '2CLCxcSXYzx7QhhPVHN4A',
@ -90,8 +90,9 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
.PATH_SEPARATOR.$old_include_path); .PATH_SEPARATOR.$old_include_path);
function load_airtime_config(){ function load_airtime_config(){
$ini_array = parse_ini_file(dirname(__FILE__).'/../../build/airtime.conf', true); $ini_array = parse_ini_file('/etc/airtime/airtime.conf', true);
return $ini_array;
/*
return array( return array(
'database' => array( 'database' => array(
'username' => $ini_array['database']['dbuser'], 'username' => $ini_array['database']['dbuser'],
@ -101,4 +102,5 @@ function load_airtime_config(){
'database' => $ini_array['database']['dbname']), 'database' => $ini_array['database']['dbname']),
'api_key' => array($ini_array['general']['api_key']) 'api_key' => array($ini_array['general']['api_key'])
); );
*/
} }

View file

@ -4,6 +4,13 @@ dbname = airtime
dbuser = airtime dbuser = airtime
dbpass = airtime dbpass = airtime
[rabbitmq]
host = 127.0.0.1
port = 5672
user = guest
password = guest
vhost = /
[general] [general]
api_key = AAA api_key = AAA
webServerUser = www-data

View file

@ -5,21 +5,16 @@
* @license http://www.gnu.org/licenses/gpl.txt * @license http://www.gnu.org/licenses/gpl.txt
*/ */
// Do not allow remote execution
$arr = array_diff_assoc($_SERVER, $_ENV);
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable\r\n";
exit(1);
}
require_once(dirname(__FILE__).'/../application/configs/conf.php');
require_once(dirname(__FILE__).'/installInit.php');
echo "******************************** Install Begin *********************************".PHP_EOL; echo "******************************** Install Begin *********************************".PHP_EOL;
AirtimeInstall::ExitIfNotRoot(); require_once(dirname(__FILE__).'/include/installInit.php');
ExitIfNotRoot();
CreateINIFile();
require_once(dirname(__FILE__).'/../application/configs/conf.php');
require_once(dirname(__FILE__).'/include/AirtimeInstall.php');
AirtimeInstall::CreateApiKey(); AirtimeInstall::CreateApiKey();
AirtimeInstall::UpdateIniValue('../build/build.properties', 'project.home', realpath(__dir__.'/../')); AirtimeInstall::UpdateIniValue('../build/build.properties', 'project.home', realpath(__dir__.'/../'));

View file

@ -5,20 +5,13 @@
* @license http://www.gnu.org/licenses/gpl.txt * @license http://www.gnu.org/licenses/gpl.txt
*/ */
// Do not allow remote execution. require_once(dirname(__FILE__).'/include/installInit.php');
$arr = array_diff_assoc($_SERVER, $_ENV); // Need to check that we are superuser before running this.
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) { ExitIfNotRoot();
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable".PHP_EOL;
exit;
}
require_once(dirname(__FILE__).'/../application/configs/conf.php'); require_once(dirname(__FILE__).'/../application/configs/conf.php');
require_once(dirname(__FILE__).'/installInit.php'); require_once(dirname(__FILE__).'/include/AirtimeInstall.php');
// Need to check that we are superuser before running this.
AirtimeInstall::ExitIfNotRoot();
AirtimeInstall::RemoveSymlinks(); AirtimeInstall::RemoveSymlinks();
@ -80,7 +73,7 @@ if ($results == 0) {
// Delete files // Delete files
//------------------------------------------------------------------------ //------------------------------------------------------------------------
AirtimeInstall::DeleteFilesRecursive($CC_CONFIG['storageDir']); AirtimeInstall::DeleteFilesRecursive($CC_CONFIG['storageDir']);
RemoveINIFile();
$command = "python ".__DIR__."/../python_apps/pypo/install/pypo-uninstall.py"; $command = "python ".__DIR__."/../python_apps/pypo/install/pypo-uninstall.py";
system($command); system($command);

View file

@ -1,11 +1,7 @@
<?php <?php
if (!function_exists('pg_connect')) {
trigger_error("PostgreSQL PHP extension required and not found.", E_USER_ERROR);
exit(2);
}
require_once(dirname(__FILE__).'/../library/pear/DB.php'); require_once(dirname(__FILE__).'/../../library/pear/DB.php');
require_once(dirname(__FILE__).'/../application/configs/conf.php'); require_once(dirname(__FILE__).'/../../application/configs/conf.php');
class AirtimeInstall { class AirtimeInstall {
@ -78,18 +74,9 @@ class AirtimeInstall {
public static function CreateApiKey() public static function CreateApiKey()
{ {
$api_key = AirtimeInstall::GenerateRandomString(); $api_key = AirtimeInstall::GenerateRandomString();
AirtimeInstall::UpdateIniValue(__DIR__.'/../build/airtime.conf', 'api_key', $api_key); AirtimeInstall::UpdateIniValue('/etc/airtime/airtime.conf', 'api_key', $api_key);
AirtimeInstall::UpdateIniValue(__DIR__.'/../python_apps/pypo/config.cfg', 'api_key', "'$api_key'"); AirtimeInstall::UpdateIniValue('/etc/airtime/pypo.cfg', 'api_key', "'$api_key'");
AirtimeInstall::UpdateIniValue(__DIR__.'/../python_apps/show-recorder/config.cfg', 'api_key', "'$api_key'"); AirtimeInstall::UpdateIniValue('/etc/airtime/recorder.cfg', 'api_key', "'$api_key'");
}
public static function ExitIfNotRoot()
{
// Need to check that we are superuser before running this.
if(exec("whoami") != "root"){
echo "Must be root user.\n";
exit(1);
}
} }
public static function UpdateIniValue($filename, $property, $value) public static function UpdateIniValue($filename, $property, $value)
@ -181,7 +168,7 @@ class AirtimeInstall {
public static function CreateDatabaseTables() public static function CreateDatabaseTables()
{ {
// Put Propel sql files in Database // Put Propel sql files in Database
$command = __DIR__."/../library/propel/generator/bin/propel-gen ../build/ insert-sql 2>propel-error.log"; $command = __DIR__."/../../library/propel/generator/bin/propel-gen ../build/ insert-sql 2>propel-error.log";
@exec($command, $output, $results); @exec($command, $output, $results);
} }
@ -200,10 +187,10 @@ class AirtimeInstall {
public static function CreateSymlinks(){ public static function CreateSymlinks(){
AirtimeInstall::RemoveSymlinks(); AirtimeInstall::RemoveSymlinks();
$dir = realpath(__DIR__."/../utils/airtime-import"); $dir = realpath(__DIR__."/../../utils/airtime-import");
exec("ln -s $dir /usr/bin/airtime-import"); exec("ln -s $dir /usr/bin/airtime-import");
$dir = realpath(__DIR__."/../utils/airtime-clean-storage"); $dir = realpath(__DIR__."/../../utils/airtime-clean-storage");
exec("ln -s $dir /usr/bin/airtime-clean-storage"); exec("ln -s $dir /usr/bin/airtime-clean-storage");
} }
@ -211,6 +198,4 @@ class AirtimeInstall {
exec("rm -f /usr/bin/airtime-import"); exec("rm -f /usr/bin/airtime-import");
exec("rm -f /usr/bin/airtime-clean-storage"); exec("rm -f /usr/bin/airtime-clean-storage");
} }
} }

View file

@ -0,0 +1,56 @@
<?php
// Do not allow remote execution
$arr = array_diff_assoc($_SERVER, $_ENV);
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable\r\n";
exit(1);
}
if (!function_exists('pg_connect')) {
trigger_error("PostgreSQL PHP extension required and not found.", E_USER_ERROR);
exit(2);
}
function CreateINIFile(){
if (!file_exists("/etc/airtime/")){
if (!mkdir("/etc/airtime/", 0755, true)){
echo "Could not create /etc/airtime/ directory. Exiting.";
exit(1);
}
}
if (!copy(__DIR__."/../../build/airtime.conf", "/etc/airtime/airtime.conf")){
echo "Could not copy airtime.conf to /etc/airtime/. Exiting.";
exit(1);
}
if (!copy(__DIR__."/../../python_apps/pypo/pypo.cfg", "/etc/airtime/pypo.cfg")){
echo "Could not copy pypo.cfg to /etc/airtime/. Exiting.";
exit(1);
}
if (!copy(__DIR__."/../../python_apps/show-recorder/recorder.cfg", "/etc/airtime/recorder.cfg")){
echo "Could not copy recorder.cfg to /etc/airtime/. Exiting.";
exit(1);
}
}
function RemoveINIFile(){
if (file_exists("/etc/airtime/airtime.conf")){
unlink("/etc/airtime/airtime.conf");
}
if (file_exists("etc/airtime")){
rmdir("/etc/airtime/");
}
}
function ExitIfNotRoot()
{
// Need to check that we are superuser before running this.
if(exec("whoami") != "root"){
echo "Must be root user.\n";
exit(1);
}
}

View file

@ -117,7 +117,7 @@ class AirTimeApiClient(ApiClientInterface):
def __get_airtime_version(self, verbose = True): def __get_airtime_version(self, verbose = True):
logger = logging.getLogger() logger = logging.getLogger()
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["version_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["version_url"])
logger.debug("Trying to contact %s", url) logger.debug("Trying to contact %s", url)
url = url.replace("%%api_key%%", self.config["api_key"]) url = url.replace("%%api_key%%", self.config["api_key"])
@ -199,7 +199,7 @@ class AirTimeApiClient(ApiClientInterface):
# Construct the URL # Construct the URL
#export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"] #export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
export_url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["export_url"]) export_url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["export_url"])
logger.info("Fetching schedule from %s", export_url) logger.info("Fetching schedule from %s", export_url)
export_url = export_url.replace('%%api_key%%', self.config["api_key"]) export_url = export_url.replace('%%api_key%%', self.config["api_key"])
@ -239,7 +239,7 @@ class AirTimeApiClient(ApiClientInterface):
playlist = schedule[pkey] playlist = schedule[pkey]
schedule_id = playlist["schedule_id"] schedule_id = playlist["schedule_id"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"] #url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_item_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_item_url"])
url = url.replace("%%schedule_id%%", str(schedule_id)) url = url.replace("%%schedule_id%%", str(schedule_id))
logger.debug(url) logger.debug(url)
@ -268,7 +268,7 @@ class AirTimeApiClient(ApiClientInterface):
try: try:
schedule_id = data schedule_id = data
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"] #url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_start_playing_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_start_playing_url"])
url = url.replace("%%media_id%%", str(media_id)) url = url.replace("%%media_id%%", str(media_id))
url = url.replace("%%schedule_id%%", str(schedule_id)) url = url.replace("%%schedule_id%%", str(schedule_id))
logger.debug(url) logger.debug(url)
@ -297,7 +297,7 @@ class AirTimeApiClient(ApiClientInterface):
logger = logging.getLogger() logger = logging.getLogger()
response = '' response = ''
try: try:
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["show_schedule_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["show_schedule_url"])
#url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"] #url = self.config["base_url"] + self.config["api_base"] + self.config["show_schedule_url"]
logger.debug(url) logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"]) url = url.replace("%%api_key%%", self.config["api_key"])
@ -316,7 +316,7 @@ class AirTimeApiClient(ApiClientInterface):
response = '' response = ''
try: try:
#url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"] #url = self.config["base_url"] + self.config["api_base"] + self.config["upload_file_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["upload_file_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["upload_file_url"])
logger.debug(url) logger.debug(url)
url = url.replace("%%api_key%%", self.config["api_key"]) url = url.replace("%%api_key%%", self.config["api_key"])
@ -379,7 +379,7 @@ class ObpApiClient():
# lookup OBP version # lookup OBP version
#url = self.config["base_url"] + self.config["api_base"]+ self.config["version_url"] #url = self.config["base_url"] + self.config["api_base"]+ self.config["version_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["version_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["version_url"])
try: try:
@ -440,7 +440,7 @@ class ObpApiClient():
# Construct the URL # Construct the URL
#export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"] #export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
export_url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["export_url"]) export_url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["export_url"])
# Insert the start and end times into the URL # Insert the start and end times into the URL
export_url = export_url.replace('%%api_key%%', self.config["api_key"]) export_url = export_url.replace('%%api_key%%', self.config["api_key"])
@ -479,7 +479,7 @@ class ObpApiClient():
#def update_scheduled_item(self, item_id, value): #def update_scheduled_item(self, item_id, value):
logger = logging.getLogger() logger = logging.getLogger()
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"] #url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_item_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_item_url"])
url = url.replace("%%item_id%%", str(schedule[pkey]["id"])) url = url.replace("%%item_id%%", str(schedule[pkey]["id"]))
url = url.replace("%%played%%", "1") url = url.replace("%%played%%", "1")
@ -510,7 +510,7 @@ class ObpApiClient():
transmission_id = data["transmission_id"] transmission_id = data["transmission_id"]
#url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"] #url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["update_start_playing_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["update_start_playing_url"])
url = url.replace("%%playlist_type%%", str(playlist_type)) url = url.replace("%%playlist_type%%", str(playlist_type))
url = url.replace("%%export_source%%", str(export_source)) url = url.replace("%%export_source%%", str(export_source))
url = url.replace("%%media_id%%", str(media_id)) url = url.replace("%%media_id%%", str(media_id))
@ -537,7 +537,7 @@ class ObpApiClient():
logger = logging.getLogger() logger = logging.getLogger()
#url = self.config["base_url"] + self.config["api_base"] + self.config["generate_range_url"] #url = self.config["base_url"] + self.config["api_base"] + self.config["generate_range_url"]
url = "http://%s:%s/%s/%s" % (self.config["base_url"], self.config["base_port"], self.config["api_base"], self.config["generate_range_url"]) url = "http://%s:%s/%s/%s" % (self.config["base_url"], str(self.config["base_port"]), self.config["api_base"], self.config["generate_range_url"])
try: try:
response = urllib.urlopen(url, self.api_auth) response = urllib.urlopen(url, self.api_auth)

View file

@ -31,7 +31,7 @@ import unittest
logging.config.fileConfig("logging-api-validator.cfg") logging.config.fileConfig("logging-api-validator.cfg")
try: try:
config = ConfigObj('config.cfg') config = ConfigObj('/etc/airtime/pypo.cfg')
except Exception, e: except Exception, e:
print 'Error loading config file: ', e print 'Error loading config file: ', e
sys.exit() sys.exit()

View file

@ -63,7 +63,7 @@ logging.config.fileConfig("logging.cfg")
# loading config file # loading config file
try: try:
config = ConfigObj('config.cfg') config = ConfigObj('/etc/airtime/pypo.cfg')
except Exception, e: except Exception, e:
print 'Error loading config file: ', e print 'Error loading config file: ', e
sys.exit() sys.exit()

View file

@ -58,7 +58,7 @@ logging.config.fileConfig("logging.cfg")
# loading config file # loading config file
try: try:
config = ConfigObj('config.cfg') config = ConfigObj('/etc/airtime/pypo.cfg')
except Exception, e: except Exception, e:
print 'error: ', e print 'error: ', e

View file

@ -75,7 +75,7 @@ cue_style = 'pre'
# Airtime Config # # Airtime Config #
##################### #####################
# Value needed to access the API # Value needed to access the API
api_key = 'AAA' api_key = 'OTBGMVOAWNJZEK7AEWSM'
# Path to the base of the API # Path to the base of the API
api_base = 'api' api_base = 'api'

View file

@ -27,7 +27,7 @@ logging.config.fileConfig("logging.cfg")
# loading config file # loading config file
try: try:
config = ConfigObj('config.cfg') config = ConfigObj('/etc/airtime/pypo.cfg')
LS_HOST = config['ls_host'] LS_HOST = config['ls_host']
LS_PORT = config['ls_port'] LS_PORT = config['ls_port']
POLL_INTERVAL = int(config['poll_interval']) POLL_INTERVAL = int(config['poll_interval'])

View file

@ -20,7 +20,7 @@ logging.config.fileConfig("logging.cfg")
# loading config file # loading config file
try: try:
config = ConfigObj('config.cfg') config = ConfigObj('/etc/airtime/pypo.cfg')
LS_HOST = config['ls_host'] LS_HOST = config['ls_host']
LS_PORT = config['ls_port'] LS_PORT = config['ls_port']
PUSH_INTERVAL = 2 PUSH_INTERVAL = 2

View file

@ -7,7 +7,7 @@ base_url = 'localhost'
base_recorded_files = '/home/pypo/Music/' base_recorded_files = '/home/pypo/Music/'
# Value needed to access the API # Value needed to access the API
api_key = 'AAA' api_key = 'OTBGMVOAWNJZEK7AEWSM'
# Path to the base of the API # Path to the base of the API
api_base = 'api' api_base = 'api'

View file

@ -32,7 +32,7 @@ except Exception, e:
# loading config file # loading config file
try: try:
config = ConfigObj('config.cfg') config = ConfigObj('/etc/airtime/recorder.cfg')
except Exception, e: except Exception, e:
print 'Error loading config file: ', e print 'Error loading config file: ', e
sys.exit() sys.exit()