Skip to content

Commit 441e180

Browse files
authored
fix: replace myservers.cfg reads in UpdateFlashBackup.php (#1517)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a new method for verifying user sign-in status using a dedicated configuration handler. * Introduced a class to manage connection configuration and status checks. * **Refactor** * Updated logic for checking connection and registration status to use new configuration handling methods for improved clarity and reliability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 29dcb7d commit 441e180

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

plugin/source/dynamix.unraid.net/etc/rc.d/rc.flash_backup

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,23 @@ _enabled() {
166166
return 1
167167
}
168168
_connected() {
169-
CFG=$API_CONFIG_HOME/connect.json
170-
[[ ! -f "${CFG}" ]] && return 1
169+
local connect_config username status_cfg connection_status
170+
connect_config=$API_CONFIG_HOME/connect.json
171+
[[ ! -f "${connect_config}" ]] && return 1
171172

172-
username=$(jq -r '.username // empty' "${CFG}" 2>/dev/null)
173+
# is the user signed in?
174+
username=$(jq -r '.username // empty' "${connect_config}" 2>/dev/null)
173175
if [ -z "${username}" ]; then
174176
return 1
175177
fi
176-
# the minigraph status is no longer synced to the connect config file
177-
# to avoid a false negative, we'll omit this check for now.
178-
#
179-
# shellcheck disable=SC1090
180-
# source <(sed -nr '/\[connectionStatus\]/,/\[/{/minigraph/p}' "${CFG}" 2>/dev/null)
181-
# # ensure connected
182-
# if [[ -z "${minigraph}" || "${minigraph}" != "CONNECTED" ]]; then
183-
# return 1
184-
# fi
178+
# are we connected to mothership?
179+
status_cfg="/var/local/emhttp/connectStatus.json"
180+
[[ ! -f "${status_cfg}" ]] && return 1
181+
connection_status=$(jq -r '.connectionStatus // empty' "${status_cfg}" 2>/dev/null)
182+
if [[ "${connection_status}" != "CONNECTED" ]]; then
183+
return 1
184+
fi
185+
185186
return 0
186187
}
187188
_haserror() {

plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/include/UpdateFlashBackup.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
2020
require_once "$docroot/webGui/include/Wrappers.php";
21+
require_once "$docroot/plugins/dynamix.my.servers/include/connect-config.php";
2122

22-
$myservers_flash_cfg_path='/boot/config/plugins/dynamix.my.servers/myservers.cfg';
23-
$myservers = file_exists($myservers_flash_cfg_path) ? @parse_ini_file($myservers_flash_cfg_path,true) : [];
24-
$isRegistered = !empty($myservers['remote']['username']);
23+
$isRegistered = ConnectConfig::isUserSignedIn();
2524

2625
// Read connection status from the new API status file
2726
$statusFilePath = '/var/local/emhttp/connectStatus.json';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
3+
require_once "$docroot/plugins/dynamix.my.servers/include/api-config.php";
4+
5+
/**
6+
* Wrapper around the API's connect.json configuration file.
7+
*/
8+
class ConnectConfig
9+
{
10+
public const CONFIG_PATH = ApiConfig::CONFIG_DIR . '/connect.json';
11+
12+
public static function getConfig()
13+
{
14+
try {
15+
return json_decode(file_get_contents(self::CONFIG_PATH), true) ?? [];
16+
} catch (Throwable $e) {
17+
return [];
18+
}
19+
}
20+
21+
public static function isUserSignedIn()
22+
{
23+
$config = self::getConfig();
24+
return ApiConfig::isConnectPluginEnabled() && !empty($config['username'] ?? '');
25+
}
26+
}

0 commit comments

Comments
 (0)