Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@ Tag="globe"
*/
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/connect-config.php";
require_once "$docroot/webGui/include/Wrappers.php";
$serverState = new ServerState();

$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);
Comment thread
pujitm marked this conversation as resolved.
$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'));

Expand All @@ -37,9 +54,7 @@ $passwd_result = exec('/usr/bin/passwd --status root');
$boolWebUIAuth = $isRegistered && (($passwd_result !== false) && (substr($passwd_result, 0, 6) == 'root P'));

// Helper to determine the current value for the remote access input
$dynamicRemoteAccessType = $myServersFlashCfg['remote']['dynamicRemoteAccessType'] ?? null;
$upnpEnabled = ($myServersFlashCfg['remote']['upnpEnabled'] ?? null) === 'yes';
$wanaccessEnabled = ($myServersFlashCfg['remote']['wanaccess'] ?? null) === 'yes';
$dynamicRemoteAccessType = $remoteDynamicRemoteAccessType ?? null;

$currentRemoteAccessValue = 'OFF';
if ($dynamicRemoteAccessType === 'STATIC') {
Comment on lines 59 to 60

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle always-on Connect settings correctly

When Connect becomes the source of truth, updateRemoteAccess writes dynamicRemoteAccessType as STATIC or UPNP even for always-on selections. This branch uses that field before checking wanaccess, so a config saved as ALWAYS+UPNP/STATIC in connect.json is rendered as DYNAMIC_UPNP/DYNAMIC_MANUAL on page load. The UI then hides the always-on messaging and disables the remote 2FA control even though remote access is already permanently enabled. The dropdown should consider the wanaccess flags before treating the state as dynamic to avoid misrepresenting an always-on configuration.

Useful? React with 👍 / 👎.

Expand All @@ -59,6 +74,12 @@ if ($dynamicRemoteAccessType === 'STATIC') {
$enableRemoteT2fa = $showT2Fa && $currentRemoteAccessValue !== 'OFF' && $hasMyUnraidNetCert;
$enableLocalT2fa = $showT2Fa && $var['USE_SSL'] === 'auto' && $hasMyUnraidNetCert;
$shade="shade-".($display['theme']??'unk');
$wanAccessOriginal = $remoteWanAccessRaw;
if (is_bool($wanAccessOriginal)) {
$wanAccessOriginal = $wanAccessOriginal ? 'yes' : 'no';
} elseif (!is_string($wanAccessOriginal)) {
$wanAccessOriginal = '';
}
?>
<style>
div.shade-white{background-color:#ededed;margin-top:10px;padding:8px 0 3px 0}
Expand All @@ -68,13 +89,18 @@ div.shade-gray{background-color:#121510;margin-top:10px;padding:8px 0 3px 0}
</style>
<script>
const hasMyUnraidNetCert = <?=($hasMyUnraidNetCert ? 'true' : 'false')?>;
const wanAccessOrg = "<?=$myServersFlashCfg['remote']['wanaccess'] ?? null?>";
const wanAccessOrg = "<?=$wanAccessOriginal?>";

function registerServer(button) {

const $remoteAccessInput = $('#remoteAccess');
const $remoteAccessManualPort = $('#wanport');

const parsePort = (val) => {
const parsed = parseInt(val, 10);
return isNaN(parsed) ? null : parsed;
};

let computedRemoteAccessConfig = null;
switch ($remoteAccessInput.val()) {
case 'ALWAYS_MANUAL':
Expand Down Expand Up @@ -119,19 +145,64 @@ function registerServer(button) {
break;
}

const enableLocalT2fa = <?=($enableLocalT2fa ? 'true' : 'false')?>;
const enableRemoteT2fa = $remoteAccessInput.val() !== 'OFF' && hasMyUnraidNetCert;
const enableLocalT2fa = <?=($enableLocalT2fa ? 'true' : 'false')?>;
const enableRemoteT2fa = $remoteAccessInput.val() !== 'OFF' && hasMyUnraidNetCert;

var postobj = {
"#cfg": "/boot/config/plugins/dynamix.my.servers/myservers.cfg",
...(computedRemoteAccessConfig ? computedRemoteAccessConfig : {}),
// only allow 'yes' value when fields are enabled
"local_2Fa": enableLocalT2fa ? $('#local2fa').val() : 'no',
"remote_2Fa": enableRemoteT2fa ? $('#remote2fa').val() : 'no',
};
const postobj = {
"#cfg": "/boot/config/plugins/dynamix.my.servers/myservers.cfg",
...(computedRemoteAccessConfig ? computedRemoteAccessConfig : {}),
// only allow 'yes' value when fields are enabled
"local_2Fa": enableLocalT2fa ? $('#local2fa').val() : 'no',
"remote_2Fa": enableRemoteT2fa ? $('#remote2fa').val() : 'no',
};

const buildConnectSettingsInput = () => {
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);
});

$(button).prop("disabled", true).html("_(Applying)_ <i class=\"fa fa-spinner fa-spin\" aria-hidden=\"true\"></i>");
$.post('/webGui/include/Dispatcher.php', postobj, function(data2) {
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):?>
swal({
title: "",
Expand All @@ -150,7 +221,22 @@ function registerServer(button) {
button.form.submit();
}, delay);
<?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)_"
});
});

}

Expand Down Expand Up @@ -196,7 +282,7 @@ function dnsCheckServer(button) {
} else {
swal({
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",
html: true,
confirmButtonText: "_(Ok)_"
Expand Down
Loading