Working cors URL update

This commit is contained in:
robbt 2020-05-12 13:20:46 -04:00
parent 7ee9a220af
commit f9c009a1be
4 changed files with 29 additions and 42 deletions

View File

@ -26,11 +26,9 @@
<div id="corsSlideToggle">
<span><strong>CORS URL </strong></span><span id="corsCaret" class="caret"></span><hr/>
</div>
<div id="corsFormBody">
<div class="form-group">
<label class="control-label" for="corsURL">CORS URLs</label>
<textarea class="form-control" id="corsURL" rows="4" cols="50"></textarea>
</div>
<div class="form-group">
<label class="control-label" for="corsUrl">CORS URLs</label>
<textarea name="corsUrl" class="form-control" id="corsUrl" rows="4" cols="50"></textarea>
</div>
</div>
<div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

@ -87,6 +87,7 @@ function formSlide(dir) {
steps = parseInt(stepCount.html());
stepCount.html((dir == "next") ? (steps + 1) : (steps - 1));
hideRMQForm();
hideCORSForm();
}
/**
@ -112,6 +113,15 @@ function hideRMQForm() {
$("#advCaret").removeClass("caret-up");
}
/**
* Hide the RMQ form when the slider is called to avoid showing
* scrollbars on slider panels that fit vertically
*/
function hideCORSForm() {
$("#corsFormBody").slideUp(500);
$("#corsCaret").removeClass("caret-up");
}
function submitForm(e, obj) {
resetFeedback();
e.preventDefault();

View File

@ -22,30 +22,33 @@ require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/om/BaseCc
* Wrapper class for validating and setting up general settings during the installation process
*/
class GeneralSetup extends Setup {
static $corsUrl;
// airtime.conf section header
protected static $_section = "[general]";
// Array of key->value pairs for airtime.conf
protected static $_properties;
// Constant form field names for passing errors back to the front-end
const GENERAL_PORT = "generalPort",
GENERAL_HOST = "generalHost";
const CORS_URL = "corsURL";
const CORS_URL = "corsUrl";
// Array of key->value pairs for airtime.conf
protected static $_properties;
static $cors_url;
// Message and error fields to return to the front-end
static $message = null;
static $errors = array();
function __construct($settings) {
self::$corsUrl = $settings[self::CORS_URL];
self::$_properties = array(
"api_key" => $this->generateRandomString(),
"base_url" => $settings[self::GENERAL_HOST],
"base_port" => $settings[self::GENERAL_PORT],
"cors_url" => $settings[self::CORS_URL]
);
self::$cors_url = $settings[self::CORS_URL];
}
/**
@ -57,8 +60,11 @@ class GeneralSetup extends Setup {
if (count(self::$errors) <= 0) {
$this->writeToTemp();
}
$this->setupCorsUrl();
if (strlen(self::$cors_url) == 0) {
}
else {
$this->setupCorsUrl();
}
return array(
"message" => self::$message,
"errors" => self::$errors
@ -75,7 +81,7 @@ class GeneralSetup extends Setup {
$con = Propel::getConnection();
} catch(Exception $e) {
self::$message = "Failed to insert Cors URL; database isn't configured properly!";
self::$errors[] = self::MEDIA_FOLDER;
self::$errors[] = self::CORS_URL;
return;
}
@ -84,38 +90,11 @@ class GeneralSetup extends Setup {
function runCorsUrlQuery($con) {
try {
//Check if key already exists
$sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = 'allowed_cors_urls'";
$paramMap = array();
$paramMap[':key'] = 'allowed_cors_urls';
$sql .= " FOR UPDATE";
$result = Application_Common_Database::prepareAndExecute($sql,
$paramMap,
Application_Common_Database::ROW_COUNT,
PDO::FETCH_ASSOC,
$con);
if ($result > 1) {
}
else {
$pref = new CcPref();
//if (self::$corsUrl != '') {
$pref->setKeyStr('allowed_cors_urls')
->setValStr(self::$corsUrl)
->save();
//$pref::setValue('allowed_cors_urls', self::CORS_URL);
self::$message = "Saved cors_url";
//}
Application_Model_Preference::SetAllowedCorsUrls(self::$cors_url);
Propel::close();
//unset($_SERVER['AIRTIME_CONF']);
}
} catch (Exception $e) {
self::$message = "Failed to insert " . self::$corsUrl . " into cc_pref" . $e;
self::$message = "Failed to insert " . self::$cors_url . " into cc_pref" . $e;
self::$errors[] = self::CORS_URL;
}