-
Notifications
You must be signed in to change notification settings - Fork 22
fix: update myservers config references to connect config references #1810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| $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')); | ||
|
|
||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Connect becomes the source of truth, Useful? React with 👍 / 👎. |
||
|
|
@@ -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} | ||
|
|
@@ -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': | ||
|
|
@@ -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: "", | ||
|
|
@@ -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)_" | ||
| }); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -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)_" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.