-api_key autogeneration and usage implemented
This commit is contained in:
parent
92545b53a6
commit
8ad5d23ee6
7 changed files with 63 additions and 33 deletions
|
@ -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";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue