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