-api_key autogeneration and usage implemented
This commit is contained in:
parent
92545b53a6
commit
8ad5d23ee6
|
@ -5,9 +5,11 @@ define('CAMPCASTER_COPYRIGHT_DATE', '2010');
|
||||||
// These are the default values for the config.
|
// These are the default values for the config.
|
||||||
global $CC_CONFIG;
|
global $CC_CONFIG;
|
||||||
|
|
||||||
|
$values = load_airtime_config();
|
||||||
|
|
||||||
$CC_CONFIG = array(
|
$CC_CONFIG = array(
|
||||||
// Database config
|
// Database config
|
||||||
'dsn' => load_db_config(),
|
'dsn' => $values['database'],
|
||||||
|
|
||||||
// Name of the web server user
|
// Name of the web server user
|
||||||
'webServerUser' => 'www-data',
|
'webServerUser' => 'www-data',
|
||||||
|
@ -17,7 +19,7 @@ $CC_CONFIG = array(
|
||||||
|
|
||||||
/* ================================================ storage configuration */
|
/* ================================================ storage configuration */
|
||||||
|
|
||||||
'apiKey' => array('AAA'),
|
'apiKey' => $values['api_key'],
|
||||||
|
|
||||||
'apiPath' => "/api/",
|
'apiPath' => "/api/",
|
||||||
|
|
||||||
|
@ -162,22 +164,20 @@ set_include_path('.'.PATH_SEPARATOR.$CC_CONFIG['pearPath']
|
||||||
.PATH_SEPARATOR.$CC_CONFIG['zendPath']
|
.PATH_SEPARATOR.$CC_CONFIG['zendPath']
|
||||||
.PATH_SEPARATOR.$old_include_path);
|
.PATH_SEPARATOR.$old_include_path);
|
||||||
|
|
||||||
//$dsn = $CC_CONFIG['dsn'];
|
function load_airtime_config(){
|
||||||
//$CC_DBC = DB::connect($dsn, TRUE);
|
$ini_array = parse_ini_file(dirname(__FILE__).'/../../build/airtime.conf', true);
|
||||||
//if (PEAR::isError($CC_DBC)) {
|
|
||||||
// echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
|
|
||||||
// exit(1);
|
|
||||||
//}
|
|
||||||
//$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
||||||
function load_db_config(){
|
|
||||||
$ini_array = parse_ini_file(dirname(__FILE__).'/../../build/database.conf', true);
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'username' => $ini_array['database']['dbuser'],
|
'database' => array(
|
||||||
'password' => $ini_array['database']['dbpass'],
|
'username' => $ini_array['database']['dbuser'],
|
||||||
'hostspec' => $ini_array['database']['host'],
|
'password' => $ini_array['database']['dbpass'],
|
||||||
'phptype' => 'pgsql',
|
'hostspec' => $ini_array['database']['host'],
|
||||||
'database' => $ini_array['database']['dbname']);
|
'phptype' => 'pgsql',
|
||||||
|
'database' => $ini_array['database']['dbname']),
|
||||||
|
'api_key' => array($ini_array['general']['api_key'])
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -432,6 +432,8 @@ class Schedule {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global $CC_CONFIG;
|
||||||
|
|
||||||
$date = new Application_Model_DateHelper;
|
$date = new Application_Model_DateHelper;
|
||||||
$timeNow = $date->getDate();
|
$timeNow = $date->getDate();
|
||||||
return array("env"=>APPLICATION_ENV,
|
return array("env"=>APPLICATION_ENV,
|
||||||
|
@ -442,7 +444,8 @@ class Schedule {
|
||||||
"currentShow"=>Show_DAL::GetCurrentShow($timeNow),
|
"currentShow"=>Show_DAL::GetCurrentShow($timeNow),
|
||||||
"nextShow"=>Show_DAL::GetNextShow($timeNow),
|
"nextShow"=>Show_DAL::GetNextShow($timeNow),
|
||||||
"timezone"=> date("T"),
|
"timezone"=> date("T"),
|
||||||
"timezoneOffset"=> date("Z"));
|
"timezoneOffset"=> date("Z"),
|
||||||
|
"apiKey"=>$CC_CONFIG['apiKey'][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,3 +4,6 @@ dbname = airtime
|
||||||
dbuser = airtime
|
dbuser = airtime
|
||||||
dbpass = airtime
|
dbpass = airtime
|
||||||
|
|
||||||
|
[general]
|
||||||
|
api_key = AAA
|
||||||
|
|
|
@ -11,7 +11,7 @@ from xml.dom.minidom import Node
|
||||||
|
|
||||||
#Read the universal values
|
#Read the universal values
|
||||||
parser = ConfigParser.SafeConfigParser()
|
parser = ConfigParser.SafeConfigParser()
|
||||||
parser.read('database.conf')
|
parser.read('airtime.conf')
|
||||||
section_names = parser.sections();
|
section_names = parser.sections();
|
||||||
items_in_section = parser.items(section_names[0])
|
items_in_section = parser.items(section_names[0])
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,31 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createAPIKey();
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../application/configs/conf.php');
|
require_once(dirname(__FILE__).'/../application/configs/conf.php');
|
||||||
require_once(dirname(__FILE__).'/../application/models/GreenBox.php');
|
require_once(dirname(__FILE__).'/../application/models/GreenBox.php');
|
||||||
require_once(dirname(__FILE__).'/installInit.php');
|
require_once(dirname(__FILE__).'/installInit.php');
|
||||||
|
|
||||||
|
|
||||||
|
function rand_string($len=20, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
|
||||||
|
{
|
||||||
|
$string = '';
|
||||||
|
for ($i = 0; $i < $len; $i++)
|
||||||
|
{
|
||||||
|
$pos = mt_rand(0, strlen($chars)-1);
|
||||||
|
$string .= $chars{$pos};
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAPIKey(){
|
||||||
|
|
||||||
|
$api_key = rand_string();
|
||||||
|
updateINIKeyValues('../build/airtime.conf', 'api_key', $api_key);
|
||||||
|
updateINIKeyValues('../pypo/config.cfg', 'api_key', "'$api_key'");
|
||||||
|
}
|
||||||
|
|
||||||
function checkIfRoot(){
|
function checkIfRoot(){
|
||||||
// Need to check that we are superuser before running this.
|
// Need to check that we are superuser before running this.
|
||||||
if(exec("whoami") != "root"){
|
if(exec("whoami") != "root"){
|
||||||
|
@ -27,21 +48,21 @@ function checkIfRoot(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to check if build.properties project home is set correctly.
|
function updateINIKeyValues($filename, $property, $value){
|
||||||
function setBuildPropertiesPath(){
|
$lines = file($filename);
|
||||||
$property = 'project.home';
|
$n=count($lines);
|
||||||
$lines = file('../build/build.properties');
|
for ($i=0; $i<$n; $i++) {
|
||||||
foreach ($lines as $key => &$line) {
|
if (strlen($lines[$i]) > strlen($property))
|
||||||
if ($property == substr($line, 0, strlen($property))){
|
if ($property == substr($lines[$i], 0, strlen($property))){
|
||||||
$line = $property." = ".realpath(__dir__.'/../')."\n";
|
$lines[$i] = "$property = $value\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$fp=fopen('../build/build.properties', 'w');
|
$fp=fopen($filename, 'w');
|
||||||
foreach($lines as $key => $line){
|
for($i=0; $i<$n; $i++){
|
||||||
fwrite($fp, $line);
|
fwrite($fp, $lines[$i]);
|
||||||
}
|
}
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
function directorySetup($CC_CONFIG){
|
function directorySetup($CC_CONFIG){
|
||||||
|
@ -75,7 +96,7 @@ echo " *** Directory Setup ***\n";
|
||||||
|
|
||||||
|
|
||||||
checkIfRoot();
|
checkIfRoot();
|
||||||
setBuildPropertiesPath();
|
updateINIKeyValues('../build/build.properties', 'project.home', realpath(__dir__.'/../'));
|
||||||
|
|
||||||
echo "******************************** Install Begin *********************************\n";
|
echo "******************************** Install Begin *********************************\n";
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ function audioPreview(filename, elemID){
|
||||||
}
|
}
|
||||||
|
|
||||||
var ext = getFileExt(filename);
|
var ext = getFileExt(filename);
|
||||||
var uri = "/api/get-media/api_key/AAA/file/" + filename;
|
var uri = "/api/get-media/api_key/" + apiKey + "/file/" + filename;
|
||||||
|
|
||||||
var media;
|
var media;
|
||||||
var supplied;
|
var supplied;
|
||||||
|
|
|
@ -23,6 +23,8 @@ var APPLICATION_ENV = "";
|
||||||
var nextSongPrepare = true;
|
var nextSongPrepare = true;
|
||||||
var nextShowPrepare = true;
|
var nextShowPrepare = true;
|
||||||
|
|
||||||
|
var apiKey = "";
|
||||||
|
|
||||||
function getTrackInfo(song){
|
function getTrackInfo(song){
|
||||||
var str = "";
|
var str = "";
|
||||||
|
|
||||||
|
@ -187,6 +189,7 @@ function calcAdditionalShowData(show){
|
||||||
|
|
||||||
function parseItems(obj){
|
function parseItems(obj){
|
||||||
APPLICATION_ENV = obj.env;
|
APPLICATION_ENV = obj.env;
|
||||||
|
apiKey = obj.apiKey;
|
||||||
|
|
||||||
$('#time-zone').text(obj.timezone);
|
$('#time-zone').text(obj.timezone);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue