added CORS handling, added external API access toggle to settings UI and updated front end script
parent
2f1f6678b7
commit
3df2720009
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class handleCors
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//check settings to see if external api access is allowed
|
||||||
|
$config = new Settings();
|
||||||
|
$settings = $config->getSettings();
|
||||||
|
if ($settings["global"]["externalAPI"]) {
|
||||||
|
//echo "API STATUS: " . $settings["global"]["externalAPI"];
|
||||||
|
if ($settings["global"]["externalAPI"] == "true") {
|
||||||
|
//echo "API ACCESS ACTIVE";
|
||||||
|
// checks to see if origin is set
|
||||||
|
if (isset($_SERVER["HTTP_ORIGIN"])) {
|
||||||
|
// You can decide if the origin in $_SERVER['HTTP_ORIGIN'] is something you want to allow, or as we do here, just allow all
|
||||||
|
header("Access-Control-Allow-Origin: {$_SERVER["HTTP_ORIGIN"]}");
|
||||||
|
} else {
|
||||||
|
//No HTTP_ORIGIN set, so we allow any. You can disallow if needed here
|
||||||
|
//never allow just any domain, so turn CORS off if no No HTTP_ORIGIN is set
|
||||||
|
//header("Access-Control-Allow-Origin: *");
|
||||||
|
}
|
||||||
|
|
||||||
|
header("Access-Control-Allow-Credentials: true");
|
||||||
|
header("Access-Control-Max-Age: 600"); // cache for 10 minutes
|
||||||
|
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "OPTIONS") {
|
||||||
|
if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_METHOD"])) {
|
||||||
|
header(
|
||||||
|
"Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT"
|
||||||
|
);
|
||||||
|
} //Make sure you remove those you do not want to support
|
||||||
|
|
||||||
|
if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"])) {
|
||||||
|
header(
|
||||||
|
"Access-Control-Allow-Headers: {$_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"]}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Just exit with 200 OK with the above headers for OPTIONS method
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//echo "API ACCESS ACTIVE";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//value doesn't exist, so whatevs
|
||||||
|
//echo "API ACCESS VALUE NOT PRESENT";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require "../vendor/autoload.php";
|
require "../vendor/autoload.php";
|
||||||
include "../brain/App.inc.php";
|
include "../brain/App.inc.php";
|
||||||
new App();
|
new App();
|
||||||
|
@ -1,67 +1,72 @@
|
|||||||
export default class SettingsActions {
|
export default class SettingsActions {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
//--------------------------
|
//--------------------------
|
||||||
constructor() {}
|
constructor() {}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// methods
|
||||||
//--------------------------
|
//--------------------------
|
||||||
getInfo() {
|
getInfo() {
|
||||||
let handle = document.getElementById('settings-handle').value;
|
let handle = document.getElementById("settings-handle").value;
|
||||||
let email = document.getElementById('settings-email').value;
|
let email = document.getElementById("settings-email").value;
|
||||||
let url = document.getElementById('settings-url').value;
|
let url = document.getElementById("settings-url").value;
|
||||||
let title = document.getElementById('settings-title').value;
|
let title = document.getElementById("settings-title").value;
|
||||||
let desc = document.getElementById('settings-desc').value;
|
let desc = document.getElementById("settings-desc").value;
|
||||||
//let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
|
//let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
|
||||||
let render = document.getElementById('render-toggle').getAttribute('data-render');
|
let render = false; //document.getElementById("render-toggle").getAttribute("data-render");
|
||||||
let background = document.getElementById('background').src;
|
let background = document.getElementById("background").src;
|
||||||
let selected = '';
|
let selected = "";
|
||||||
let selects = document.querySelectorAll('.theme-select');
|
let selects = document.querySelectorAll(".theme-select");
|
||||||
let smtpDomain = document.getElementById('smtp-domain').value;
|
let smtpDomain = document.getElementById("smtp-domain").value;
|
||||||
let smtpEmail = document.getElementById('smtp-email').value;
|
let smtpEmail = document.getElementById("smtp-email").value;
|
||||||
let smtpPass = document.getElementById('smtp-pass').value;
|
let smtpPass = document.getElementById("smtp-pass").value;
|
||||||
let mgDomain = document.getElementById('mg-domain').value;
|
let mgDomain = document.getElementById("mg-domain").value;
|
||||||
let mgKey = document.getElementById('mg-key').value;
|
let mgKey = document.getElementById("mg-key").value;
|
||||||
let mailActive = '';
|
let mailActive = "";
|
||||||
let mailOptions = document.querySelectorAll('.mail-option');
|
let mailOptions = document.querySelectorAll(".mail-option");
|
||||||
var i, count;
|
let apiStatus = document
|
||||||
for (i = 0, count = selects.length; i < count; i++) {
|
.getElementById("api-access-toggle")
|
||||||
if (selects[i].getAttribute('data-enabled') == 'true') selected = selects[i].id;
|
.getAttribute("data-enabled");
|
||||||
}
|
var i, count;
|
||||||
|
for (i = 0, count = selects.length; i < count; i++) {
|
||||||
|
if (selects[i].getAttribute("data-enabled") == "true")
|
||||||
|
selected = selects[i].id;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0, count = mailOptions.length; i < count; i++) {
|
for (i = 0, count = mailOptions.length; i < count; i++) {
|
||||||
if (mailOptions[i].getAttribute('data-enabled') == 'true')
|
if (mailOptions[i].getAttribute("data-enabled") == "true")
|
||||||
mailActive = mailOptions[i].id;
|
mailActive = mailOptions[i].id;
|
||||||
}
|
}
|
||||||
let settingsData = {
|
let settingsData = {
|
||||||
global: {
|
global: {
|
||||||
base_url: url,
|
base_url: url,
|
||||||
title: title,
|
title: title,
|
||||||
descriptions: desc,
|
descriptions: desc,
|
||||||
background: background,
|
background: background,
|
||||||
private: false,
|
private: false,
|
||||||
renderOnSave: render,
|
renderOnSave: render,
|
||||||
theme: selected
|
theme: selected,
|
||||||
},
|
externalAPI: apiStatus
|
||||||
member: { handle: handle, email: email },
|
},
|
||||||
email: {
|
member: { handle: handle, email: email },
|
||||||
active: mailActive,
|
email: {
|
||||||
smtp: {
|
active: mailActive,
|
||||||
domain: smtpDomain,
|
smtp: {
|
||||||
email: smtpEmail,
|
domain: smtpDomain,
|
||||||
password: smtpPass
|
email: smtpEmail,
|
||||||
},
|
password: smtpPass
|
||||||
mailgun: {
|
},
|
||||||
domain: mgDomain,
|
mailgun: {
|
||||||
key: mgKey
|
domain: mgDomain,
|
||||||
}
|
key: mgKey
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
return new Promise(function (resolve) {
|
};
|
||||||
resolve(settingsData);
|
return new Promise(function (resolve) {
|
||||||
});
|
resolve(settingsData);
|
||||||
}
|
});
|
||||||
//--------------------------
|
}
|
||||||
// event handlers
|
//--------------------------
|
||||||
//--------------------------
|
// event handlers
|
||||||
|
//--------------------------
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue