fix: update myservers config references to connect config references (#1810)

`myservers.cfg` no longer gets written to or read (except for migration
purposes), so it'd be better to read from the new values instead of
continuing to use the old ones @elibosley @Squidly271 .

unless i'm missing something! see #1805

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Switches to a centralized remote-access configuration with a legacy
fallback and richer client-side handling.
* Optional GraphQL submission path for applying remote settings when
available.

* **Bug Fixes**
* Normalized boolean and port handling to prevent incorrect values
reaching the UI.
* Improved error handling and UI state restoration during save/apply
flows.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Pujit Mehrotra
2025-12-18 10:34:06 -05:00
committed by GitHub
parent 8b155d1f1c
commit e1e3ea7eb6

View File

@@ -15,12 +15,29 @@ Tag="globe"
*/ */
require_once "$docroot/plugins/dynamix.my.servers/include/state.php"; require_once "$docroot/plugins/dynamix.my.servers/include/state.php";
require_once "$docroot/plugins/dynamix.my.servers/include/api-config.php"; require_once "$docroot/plugins/dynamix.my.servers/include/api-config.php";
require_once "$docroot/plugins/dynamix.my.servers/include/connect-config.php";
require_once "$docroot/webGui/include/Wrappers.php"; require_once "$docroot/webGui/include/Wrappers.php";
$serverState = new ServerState(); $serverState = new ServerState();
$keyfile = $serverState->keyfileBase64; $keyfile = $serverState->keyfileBase64;
$myServersFlashCfg = $serverState->myServersFlashCfg; $connectConfig = ConnectConfig::getConfig();
$legacyRemoteCfg = $serverState->myServersFlashCfg['remote'] ?? [];
$remoteDynamicRemoteAccessType = $connectConfig['dynamicRemoteAccessType'] ?? ($legacyRemoteCfg['dynamicRemoteAccessType'] ?? null);
$remoteWanAccessRaw = $connectConfig['wanaccess'] ?? ($legacyRemoteCfg['wanaccess'] ?? null);
$remoteUpnpEnabledRaw = $connectConfig['upnpEnabled'] ?? ($legacyRemoteCfg['upnpEnabled'] ?? null);
$remoteWanPortRaw = $connectConfig['wanport'] ?? ($legacyRemoteCfg['wanport'] ?? null);
$wanaccessEnabled = filter_var($remoteWanAccessRaw, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($wanaccessEnabled === null) {
$wanaccessEnabled = false;
}
$upnpEnabled = filter_var($remoteUpnpEnabledRaw, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if ($upnpEnabled === null) {
$upnpEnabled = false;
}
$remoteWanPort = is_numeric($remoteWanPortRaw) ? (int)$remoteWanPortRaw : 0;
$showT2Fa = (file_exists('/boot/config/plugins/dynamix.my.servers/showT2Fa')); $showT2Fa = (file_exists('/boot/config/plugins/dynamix.my.servers/showT2Fa'));
@@ -37,9 +54,7 @@ $passwd_result = exec('/usr/bin/passwd --status root');
$boolWebUIAuth = $isRegistered && (($passwd_result !== false) && (substr($passwd_result, 0, 6) == 'root P')); $boolWebUIAuth = $isRegistered && (($passwd_result !== false) && (substr($passwd_result, 0, 6) == 'root P'));
// Helper to determine the current value for the remote access input // Helper to determine the current value for the remote access input
$dynamicRemoteAccessType = $myServersFlashCfg['remote']['dynamicRemoteAccessType'] ?? null; $dynamicRemoteAccessType = $remoteDynamicRemoteAccessType ?? null;
$upnpEnabled = ($myServersFlashCfg['remote']['upnpEnabled'] ?? null) === 'yes';
$wanaccessEnabled = ($myServersFlashCfg['remote']['wanaccess'] ?? null) === 'yes';
$currentRemoteAccessValue = 'OFF'; $currentRemoteAccessValue = 'OFF';
if ($dynamicRemoteAccessType === 'STATIC') { if ($dynamicRemoteAccessType === 'STATIC') {
@@ -59,6 +74,12 @@ if ($dynamicRemoteAccessType === 'STATIC') {
$enableRemoteT2fa = $showT2Fa && $currentRemoteAccessValue !== 'OFF' && $hasMyUnraidNetCert; $enableRemoteT2fa = $showT2Fa && $currentRemoteAccessValue !== 'OFF' && $hasMyUnraidNetCert;
$enableLocalT2fa = $showT2Fa && $var['USE_SSL'] === 'auto' && $hasMyUnraidNetCert; $enableLocalT2fa = $showT2Fa && $var['USE_SSL'] === 'auto' && $hasMyUnraidNetCert;
$shade="shade-".($display['theme']??'unk'); $shade="shade-".($display['theme']??'unk');
$wanAccessOriginal = $remoteWanAccessRaw;
if (is_bool($wanAccessOriginal)) {
$wanAccessOriginal = $wanAccessOriginal ? 'yes' : 'no';
} elseif (!is_string($wanAccessOriginal)) {
$wanAccessOriginal = '';
}
?> ?>
<style> <style>
div.shade-white{background-color:#ededed;margin-top:10px;padding:8px 0 3px 0} div.shade-white{background-color:#ededed;margin-top:10px;padding:8px 0 3px 0}
@@ -68,13 +89,18 @@ div.shade-gray{background-color:#121510;margin-top:10px;padding:8px 0 3px 0}
</style> </style>
<script> <script>
const hasMyUnraidNetCert = <?=($hasMyUnraidNetCert ? 'true' : 'false')?>; const hasMyUnraidNetCert = <?=($hasMyUnraidNetCert ? 'true' : 'false')?>;
const wanAccessOrg = "<?=$myServersFlashCfg['remote']['wanaccess'] ?? null?>"; const wanAccessOrg = "<?=$wanAccessOriginal?>";
function registerServer(button) { function registerServer(button) {
const $remoteAccessInput = $('#remoteAccess'); const $remoteAccessInput = $('#remoteAccess');
const $remoteAccessManualPort = $('#wanport'); const $remoteAccessManualPort = $('#wanport');
const parsePort = (val) => {
const parsed = parseInt(val, 10);
return isNaN(parsed) ? null : parsed;
};
let computedRemoteAccessConfig = null; let computedRemoteAccessConfig = null;
switch ($remoteAccessInput.val()) { switch ($remoteAccessInput.val()) {
case 'ALWAYS_MANUAL': case 'ALWAYS_MANUAL':
@@ -119,19 +145,64 @@ function registerServer(button) {
break; break;
} }
const enableLocalT2fa = <?=($enableLocalT2fa ? 'true' : 'false')?>; const enableLocalT2fa = <?=($enableLocalT2fa ? 'true' : 'false')?>;
const enableRemoteT2fa = $remoteAccessInput.val() !== 'OFF' && hasMyUnraidNetCert; const enableRemoteT2fa = $remoteAccessInput.val() !== 'OFF' && hasMyUnraidNetCert;
var postobj = { const postobj = {
"#cfg": "/boot/config/plugins/dynamix.my.servers/myservers.cfg", "#cfg": "/boot/config/plugins/dynamix.my.servers/myservers.cfg",
...(computedRemoteAccessConfig ? computedRemoteAccessConfig : {}), ...(computedRemoteAccessConfig ? computedRemoteAccessConfig : {}),
// only allow 'yes' value when fields are enabled // only allow 'yes' value when fields are enabled
"local_2Fa": enableLocalT2fa ? $('#local2fa').val() : 'no', "local_2Fa": enableLocalT2fa ? $('#local2fa').val() : 'no',
"remote_2Fa": enableRemoteT2fa ? $('#remote2fa').val() : 'no', "remote_2Fa": enableRemoteT2fa ? $('#remote2fa').val() : 'no',
}; };
$(button).prop("disabled", true).html("_(Applying)_ <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>"); const buildConnectSettingsInput = () => {
$.post('/webGui/include/Dispatcher.php', postobj, function(data2) { const selection = $remoteAccessInput.val();
switch (selection) {
case 'ALWAYS_MANUAL':
return { accessType: 'ALWAYS', forwardType: 'STATIC', port: parsePort($remoteAccessManualPort.val()) };
case 'ALWAYS_UPNP':
return { accessType: 'ALWAYS', forwardType: 'UPNP', port: null };
case 'DYNAMIC_UPNP':
return { accessType: 'DYNAMIC', forwardType: 'UPNP', port: null };
case 'DYNAMIC_MANUAL':
return { accessType: 'DYNAMIC', forwardType: 'STATIC', port: parsePort($remoteAccessManualPort.val()) };
default:
return { accessType: 'DISABLED', forwardType: 'STATIC', port: null };
}
};
const $button = $(button);
const originalLabel = $button.html();
$button.prop("disabled", true).html("_(Applying)_ <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>");
const saveLegacyConfig = new Promise((resolve, reject) => {
$.post('/webGui/include/Dispatcher.php', postobj).done(resolve).fail(reject);
});
const apolloClient = window.apolloClient;
const gql = window.gql || window.graphqlParse;
const mutations = [saveLegacyConfig];
if (apolloClient && gql) {
const updateConnectSettingsMutation = gql(`
mutation UpdateConnectSettings($input: ConnectSettingsInput!) {
updateApiSettings(input: $input) {
accessType
forwardType
port
}
}
`);
mutations.push(
apolloClient.mutate({
mutation: updateConnectSettingsMutation,
variables: { input: buildConnectSettingsInput() },
})
);
}
Promise.all(mutations).then(function() {
<?if(!$isRegistered):?> <?if(!$isRegistered):?>
swal({ swal({
title: "", title: "",
@@ -150,7 +221,22 @@ function registerServer(button) {
button.form.submit(); button.form.submit();
}, delay); }, delay);
<?endif?> <?endif?>
}); }).catch(function(error) {
let message = "_(Sorry, an error occurred)_";
if (error && error.responseJSON && error.responseJSON.error) {
message = error.responseJSON.error;
} else if (error && error.message) {
message = error.message;
}
$button.prop("disabled", false).html(originalLabel);
swal({
title: "Oops",
text: message,
type: "error",
html: true,
confirmButtonText: "_(Ok)_"
});
});
} }
@@ -196,7 +282,7 @@ function dnsCheckServer(button) {
} else { } else {
swal({ swal({
title: "Oops", title: "Oops",
text: "<?=sprintf(_("The Unraid server is unreachable from outside your network. Be sure you have configured your router to forward port") . " <strong style='font-weight: bold'>%u/TCP</strong> " . _("to the Unraid server at") . " <strong style='font-weight: bold'>%s</strong> " . _("port") . " <strong style='font-weight: bold'>%u</strong>", $myServersFlashCfg['remote']['wanport']??"", htmlspecialchars($eth0['IPADDR:0']??''), $var['PORTSSL']??443)?>", text: "<?=sprintf(_("The Unraid server is unreachable from outside your network. Be sure you have configured your router to forward port") . " <strong style='font-weight: bold'>%u/TCP</strong> " . _("to the Unraid server at") . " <strong style='font-weight: bold'>%s</strong> " . _("port") . " <strong style='font-weight: bold'>%u</strong>", $remoteWanPort, htmlspecialchars($eth0['IPADDR:0']??''), $var['PORTSSL']??443)?>",
type: "error", type: "error",
html: true, html: true,
confirmButtonText: "_(Ok)_" confirmButtonText: "_(Ok)_"