Merge pull request #1034 from Robbt/cors-in-setup

Cors in setup
This commit is contained in:
Kyle Robbertze 2020-05-13 15:34:19 +02:00 committed by GitHub
commit eaa5ced799
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 5 deletions

View file

@ -19,6 +19,21 @@
<span class="glyphicon glyphicon-remove form-control-feedback"></span> <span class="glyphicon glyphicon-remove form-control-feedback"></span>
</div> </div>
<input class="form-control" type="hidden" name="generalErr" id="generalErr" aria-describedby="helpBlock"/> <input class="form-control" type="hidden" name="generalErr" id="generalErr" aria-describedby="helpBlock"/>
<p>The CORS URL can be setup during install if you are accessing your LibreTime instance behind a Proxy.
This is common with docker setups. If you have a reverse proxy setup enter the URL below, otherwise you
can safely ignore this. Please enter one URL per line. Include the entire URL such as http://example.com
If you are reinstalling LibreTime on an existing setup you can ignore this as well,
the settings in your existing database will be retained unless you enter new values below.
</p>
<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 name="corsUrl" class="form-control" id="corsUrl" rows="4" cols="50"></textarea>
</div>
</div>
</div> </div>
<div> <div>
<input type="submit" formtarget="generalSettingsForm" class="btn btn-primary btn-next" value="Next &#10097;"/> <input type="submit" formtarget="generalSettingsForm" class="btn btn-primary btn-next" value="Next &#10097;"/>
@ -27,6 +42,10 @@
</form> </form>
<script> <script>
$("#corsSlideToggle").click(function() {
$("#corsFormBody").slideToggle(500);
$("#corsCaret").toggleClass("caret-up");
});
$("#generalSettingsForm").submit(function(e) { $("#generalSettingsForm").submit(function(e) {
submitForm(e, "GeneralSetup"); submitForm(e, "GeneralSetup");
}); });

View file

@ -13,7 +13,7 @@
<body> <body>
<div class="header"> <div class="header">
<h3 class="logo"> <h3 class="logo">
<img src="css/images/airtime_logo_jp.png" id="airtimeLogo" /><br/> <img src="css/images/libretime_logo_jp.png" id="LibreTimeLogo" /><br/>
<strong>Setup</strong> <strong>Setup</strong>
</h3> </h3>
<strong>Step <span id="stepCount">1</span> of 5</strong> <strong>Step <span id="stepCount">1</span> of 5</strong>

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

View file

@ -87,6 +87,7 @@ function formSlide(dir) {
steps = parseInt(stepCount.html()); steps = parseInt(stepCount.html());
stepCount.html((dir == "next") ? (steps + 1) : (steps - 1)); stepCount.html((dir == "next") ? (steps + 1) : (steps - 1));
hideRMQForm(); hideRMQForm();
hideCORSForm();
} }
/** /**
@ -112,6 +113,15 @@ function hideRMQForm() {
$("#advCaret").removeClass("caret-up"); $("#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) { function submitForm(e, obj) {
resetFeedback(); resetFeedback();
e.preventDefault(); e.preventDefault();

View file

@ -1,5 +1,18 @@
<?php <?php
define("CONFIG_PATH", dirname(dirname( __DIR__)) . "/application/configs/");
require_once(dirname(dirname( __DIR__)) . "/../vendor/propel/propel1/runtime/lib/Propel.php");
require_once(CONFIG_PATH . 'conf.php');
require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/CcPref.php");
require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/CcPrefPeer.php");
require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/CcPrefQuery.php");
require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/map/CcPrefTableMap.php");
require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/om/BaseCcPref.php");
require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/om/BaseCcPrefPeer.php");
require_once(dirname(dirname( __DIR__)) . "/application/models/airtime/om/BaseCcPrefQuery.php");
/** /**
* User: sourcefabric * User: sourcefabric
* Date: 08/12/14 * Date: 08/12/14
@ -9,16 +22,18 @@
* Wrapper class for validating and setting up general settings during the installation process * Wrapper class for validating and setting up general settings during the installation process
*/ */
class GeneralSetup extends Setup { class GeneralSetup extends Setup {
// airtime.conf section header // airtime.conf section header
protected static $_section = "[general]"; 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 // Constant form field names for passing errors back to the front-end
const GENERAL_PORT = "generalPort", const GENERAL_PORT = "generalPort",
GENERAL_HOST = "generalHost"; GENERAL_HOST = "generalHost";
const CORS_URL = "corsUrl";
// Array of key->value pairs for airtime.conf static $cors_url;
protected static $_properties;
// Message and error fields to return to the front-end // Message and error fields to return to the front-end
static $message = null; static $message = null;
@ -30,7 +45,10 @@ class GeneralSetup extends Setup {
"api_key" => $this->generateRandomString(), "api_key" => $this->generateRandomString(),
"base_url" => $settings[self::GENERAL_HOST], "base_url" => $settings[self::GENERAL_HOST],
"base_port" => $settings[self::GENERAL_PORT], "base_port" => $settings[self::GENERAL_PORT],
"cors_url" => $settings[self::CORS_URL]
); );
self::$cors_url = $settings[self::CORS_URL];
} }
/** /**
@ -42,11 +60,43 @@ class GeneralSetup extends Setup {
if (count(self::$errors) <= 0) { if (count(self::$errors) <= 0) {
$this->writeToTemp(); $this->writeToTemp();
} }
if (strlen(self::$cors_url) == 0) {
}
else {
$this->setupCorsUrl();
}
return array( return array(
"message" => self::$message, "message" => self::$message,
"errors" => self::$errors "errors" => self::$errors
); );
} }
/**
* If the user entered a CORS Url then add it to the system preferences
* TODO Make sure we check for existing CORS URLs and display them on initial form
*/
function setupCorsUrl() {
try {
$_SERVER['AIRTIME_CONF'] = AIRTIME_CONF_TEMP_PATH;
Propel::init(CONFIG_PATH . "airtime-conf-production.php");
$con = Propel::getConnection();
} catch(Exception $e) {
self::$message = "Failed to insert Cors URL; database isn't configured properly!";
self::$errors[] = self::CORS_URL;
return;
}
$this->runCorsUrlQuery($con);
}
function runCorsUrlQuery($con) {
try {
Application_Model_Preference::SetAllowedCorsUrls(self::$cors_url);
Propel::close();
//unset($_SERVER['AIRTIME_CONF']);
} catch (Exception $e) {
self::$message = "Failed to insert " . self::$cors_url . " into cc_pref" . $e;
self::$errors[] = self::CORS_URL;
}
}
} }