feat(web): finalize api cors error & settings field

This commit is contained in:
Zack Spear
2023-09-11 13:05:11 -07:00
parent 46626a58e4
commit 5e67b3ac98
2 changed files with 25 additions and 43 deletions

View File

@@ -87,27 +87,6 @@ div.shade-gray{background-color:#121510;margin-top:10px;padding:8px 0 3px 0}
const hasMyUnraidNetCert = <?=($hasMyUnraidNetCert ? 'true' : 'false')?>;
const wanAccessOrg = "<?=$myservers['remote']['wanaccess']?>";
$('body').on('change keyup', '.js-extraOrigins', function(data) {
console.debug('change keyup', data);
validateExtraOrigins();
if (!isExtraOriginsValid) {
return $('.js-extraOriginsApply').prop("disabled",true);
}
return $('.js-extraOriginsApply').removeAttr('disabled');
});
function applyExtraOrigins(button) {
const postobj = {
"#cfg": "/boot/config/plugins/dynamix.my.servers/myservers.cfg",
"api_extraOrigins": validateExtraOrigins(),
};
$(button).prop("disabled", true).html("_(Applying)_ <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>");
$.post('/webGui/include/Dispatcher.php', postobj, function(_extraOriginsData) {
window.location.reload();
});
}
function registerServer(button) {
const $remoteAccessInput = $('#remoteAccess');
@@ -439,6 +418,18 @@ function buttonStateReset(newstate) {
}
$.post('/plugins/dynamix.my.servers/include/UpdateFlashBackup.php',{command:"status"});
function applyExtraOrigins(button) {
const postobj = {
"#cfg": "/boot/config/plugins/dynamix.my.servers/myservers.cfg",
"api_extraOrigins": validateExtraOrigins(),
};
$(button).prop("disabled", true).html("_(Applying)_ <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>");
$.post('/webGui/include/Dispatcher.php', postobj, function(_extraOriginsData) {
window.location.reload();
});
}
let isExtraOriginsValid = false;
const validateExtraOrigins = () => {
const val = $('.js-extraOrigins').val();
@@ -465,6 +456,15 @@ const isCommaSeparatedURLs = input =>
input
.split(",")
.every(value => /^(http|https):\/\/[^ "]+$/.test(value));
$('body').on('change keyup', '.js-extraOrigins', function(data) {
console.debug('change keyup', data);
validateExtraOrigins();
if (!isExtraOriginsValid) {
return $('.js-extraOriginsApply').prop("disabled",true);
}
return $('.js-extraOriginsApply').removeAttr('disabled');
});
</script>
<form id="UnraidNetSettings" markdown="1" name="UnraidNetSettings" method="POST" action="/update.htm" target="progressFrame">
@@ -700,7 +700,7 @@ _(Account status)_:
: <unraid-i18n-host><unraid-auth></unraid-auth></unraid-i18n-host>
<!-- start extra origins -->
<span class="js-extraOriginsLabel">_(Unraid API extra origins)_:</span>
<span id="extraOriginsSettings" class="js-extraOriginsLabel">_(Unraid API extra origins)_:</span>
: <input class="js-extraOrigins" name="extraOrigins" type="text" value="<?=$myservers['api']['extraOrigins']??''?>">
:unraidnet_extraorigins_help:

View File

@@ -11,7 +11,7 @@ import { defineStore, createPinia, setActivePinia } from 'pinia';
import { UserProfileLink } from 'types/userProfile';
import { WebguiUnraidApiCommand } from '~/composables/services/webgui';
import { GRAPHQL, PLUGIN_SETTINGS } from '~/helpers/urls';
import { GRAPHQL, SETTINGS_MANAGMENT_ACCESS } from '~/helpers/urls';
import { useErrorsStore } from '~/store/errors';
import { useServerStore } from '~/store/server';
@@ -38,24 +38,6 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
if (apiResponse) {
// we have a response, so we're online
unraidApiStatus.value = 'online';
/**
* @todo remove TEMPORARILY FORCING THIS ERROR
*/
const msg = `<p>The CORS policy for this site does not allow access from the specified Origin'./p><p>If you are using a reverse proxy, you need to copy your origin <strong class="font-mono"><em>${window.location.origin}</em></strong> and paste it into the "Extra Origins" list in the Connect settings.</p>`;
errorsStore.setError({
heading: 'Unraid API • CORS Error',
message: msg,
level: 'error',
ref: 'unraidApiCorsError',
type: 'unraidApiGQL',
actions: [
{
href: `${PLUGIN_SETTINGS.toString()}#extraOriginsSettings`,
icon: CogIcon,
text: 'Go to Connect Settings',
}
],
});
}
}
});
@@ -113,7 +95,7 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
}
if (error.error.message && error.error.message.includes(ERROR_CORS_403)) {
prioritizeCorsError = true;
const msg = `<p>${error.error.message}</p><p>If you are using a reverse proxy, you need to copy your origin <strong class="font-mono"><em>${window.location.origin}</em></strong> and paste it into the "Extra Origins" list in the Connect settings.</p>`;
const msg = `<p>The CORS policy for this site does not allow access from the specified Origin.</p><p>If you are using a reverse proxy, you need to copy your origin <strong class="font-mono"><em>${window.location.origin}</em></strong> and paste it into the "Extra Origins" list in the Connect settings.</p>`;
errorsStore.setError({
heading: 'Unraid API • CORS Error',
message: msg,
@@ -122,7 +104,7 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
type: 'unraidApiGQL',
actions: [
{
href: `${PLUGIN_SETTINGS.toString()}#extraOriginsSettings`,
href: `${SETTINGS_MANAGMENT_ACCESS.toString()}#extraOriginsSettings`,
icon: CogIcon,
text: 'Go to Connect Settings',
}