Rework redirect to config page at the end of the web install

This commit is contained in:
Duncan Sommerville 2015-01-12 14:40:22 -05:00
parent 23f33cd8da
commit d07195f048
2 changed files with 42 additions and 27 deletions

View file

@ -24,7 +24,6 @@
<script> <script>
$("#finishSettingsForm").submit(function(e) { $("#finishSettingsForm").submit(function(e) {
window.location.replace("/?config"); window.location.assign("/?config");
// submitForm(e, "FinishSetup");
}); });
</script> </script>

View file

@ -1,11 +1,12 @@
<?php <?php
define("BUILD_PATH", dirname(dirname(__DIR__)) . "/build/");
define("BUILD_PATH", dirname(dirname( __DIR__)) . "/build/");
define("AIRTIME_CONF_TEMP_PATH", "/tmp/airtime.conf.temp"); define("AIRTIME_CONF_TEMP_PATH", "/tmp/airtime.conf.temp");
/** /**
* Class Setup * Class Setup
* *
* @author sourcefabric
*
* Abstract superclass for the setup and installation process * Abstract superclass for the setup and installation process
*/ */
abstract class Setup { abstract class Setup {
@ -14,6 +15,14 @@ abstract class Setup {
abstract function runSetup(); abstract function runSetup();
/**
* Write new property values to a given section in airtime.conf.temp
*
* @param string $section
* the configuration section to write to
* @param array $properties
* the configuration properties and values to overwrite
*/
protected function writeToTemp($section, $properties) { protected function writeToTemp($section, $properties) {
if (!file_exists(AIRTIME_CONF_TEMP_PATH)) { if (!file_exists(AIRTIME_CONF_TEMP_PATH)) {
copy(BUILD_PATH . "airtime.example.conf", AIRTIME_CONF_TEMP_PATH); copy(BUILD_PATH . "airtime.example.conf", AIRTIME_CONF_TEMP_PATH);
@ -24,8 +33,8 @@ abstract class Setup {
$inSection = false; $inSection = false;
foreach($file as $line) { foreach ($file as $line) {
if(strpos($line, $section) !== false) { if (strpos($line, $section) !== false) {
$inSection = true; $inSection = true;
} else if (strpos($line, "[") !== false) { } else if (strpos($line, "[") !== false) {
$inSection = false; $inSection = false;
@ -45,15 +54,16 @@ abstract class Setup {
/** /**
* Generates a random string. * Generates a random string.
* *
* @param integer $p_len length of the output string * @param integer $p_len
* @param string $p_chars characters to use in the output string * length of the output string
* @param string $p_chars
* characters to use in the output string
* @return string the generated random string * @return string the generated random string
*/ */
protected function generateRandomString($p_len=20, $p_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') { protected function generateRandomString($p_len = 20, $p_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
$string = ''; $string = '';
for ($i = 0; $i < $p_len; $i++) for($i = 0; $i < $p_len; $i++) {
{ $pos = mt_rand(0, strlen($p_chars) - 1);
$pos = mt_rand(0, strlen($p_chars)-1);
$string .= $p_chars{$pos}; $string .= $p_chars{$pos};
} }
return $string; return $string;
@ -61,6 +71,13 @@ abstract class Setup {
} }
/**
* Class AirtimeDatabaseException
*
* @author sourcefabric
*
* Exception class for database setup errors
*/
class AirtimeDatabaseException extends Exception { class AirtimeDatabaseException extends Exception {
protected $message = "Unknown Airtime database exception"; protected $message = "Unknown Airtime database exception";
@ -78,11 +95,10 @@ class AirtimeDatabaseException extends Exception {
} }
// Import Setup subclasses // Import Setup subclasses
require_once ('database-setup.php');
require_once('database-setup.php'); require_once ('rabbitmq-setup.php');
require_once('rabbitmq-setup.php'); require_once ('general-setup.php');
require_once('general-setup.php'); require_once ('media-setup.php');
require_once('media-setup.php');
// If airtime.conf exists, we shouldn't be here // If airtime.conf exists, we shouldn't be here
if (!file_exists("/etc/airtime/airtime.conf")) { if (!file_exists("/etc/airtime/airtime.conf")) {
@ -91,10 +107,10 @@ if (!file_exists("/etc/airtime/airtime.conf")) {
if ($obj instanceof Setup) { if ($obj instanceof Setup) {
try { try {
$response = $obj->runSetup(); $response = $obj->runSetup();
} catch(AirtimeDatabaseException $e) { } catch (AirtimeDatabaseException $e) {
$response = array( $response = array(
"message" => $e->getMessage(), "message" => $e->getMessage(),
"errors" => $e->getErrorFields(), "errors" => $e->getErrorFields()
); );
} }