mirror of
https://github.com/unraid/api.git
synced 2025-12-30 21:19:49 -06:00
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 -->
This commit is contained in:
@@ -166,22 +166,23 @@ _enabled() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
_connected() {
|
_connected() {
|
||||||
CFG=$API_CONFIG_HOME/connect.json
|
local connect_config username status_cfg connection_status
|
||||||
[[ ! -f "${CFG}" ]] && return 1
|
connect_config=$API_CONFIG_HOME/connect.json
|
||||||
|
[[ ! -f "${connect_config}" ]] && return 1
|
||||||
|
|
||||||
username=$(jq -r '.username // empty' "${CFG}" 2>/dev/null)
|
# is the user signed in?
|
||||||
|
username=$(jq -r '.username // empty' "${connect_config}" 2>/dev/null)
|
||||||
if [ -z "${username}" ]; then
|
if [ -z "${username}" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# the minigraph status is no longer synced to the connect config file
|
# are we connected to mothership?
|
||||||
# to avoid a false negative, we'll omit this check for now.
|
status_cfg="/var/local/emhttp/connectStatus.json"
|
||||||
#
|
[[ ! -f "${status_cfg}" ]] && return 1
|
||||||
# shellcheck disable=SC1090
|
connection_status=$(jq -r '.connectionStatus // empty' "${status_cfg}" 2>/dev/null)
|
||||||
# source <(sed -nr '/\[connectionStatus\]/,/\[/{/minigraph/p}' "${CFG}" 2>/dev/null)
|
if [[ "${connection_status}" != "CONNECTED" ]]; then
|
||||||
# # ensure connected
|
return 1
|
||||||
# if [[ -z "${minigraph}" || "${minigraph}" != "CONNECTED" ]]; then
|
fi
|
||||||
# return 1
|
|
||||||
# fi
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
_haserror() {
|
_haserror() {
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ $cli = php_sapi_name()=='cli';
|
|||||||
|
|
||||||
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
|
$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
|
||||||
require_once "$docroot/webGui/include/Wrappers.php";
|
require_once "$docroot/webGui/include/Wrappers.php";
|
||||||
|
require_once "$docroot/plugins/dynamix.my.servers/include/connect-config.php";
|
||||||
|
|
||||||
$myservers_flash_cfg_path='/boot/config/plugins/dynamix.my.servers/myservers.cfg';
|
$isRegistered = ConnectConfig::isUserSignedIn();
|
||||||
$myservers = file_exists($myservers_flash_cfg_path) ? @parse_ini_file($myservers_flash_cfg_path,true) : [];
|
|
||||||
$isRegistered = !empty($myservers['remote']['username']);
|
|
||||||
|
|
||||||
// Read connection status from the new API status file
|
// Read connection status from the new API status file
|
||||||
$statusFilePath = '/var/local/emhttp/connectStatus.json';
|
$statusFilePath = '/var/local/emhttp/connectStatus.json';
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||||
|
require_once "$docroot/plugins/dynamix.my.servers/include/api-config.php";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper around the API's connect.json configuration file.
|
||||||
|
*/
|
||||||
|
class ConnectConfig
|
||||||
|
{
|
||||||
|
public const CONFIG_PATH = ApiConfig::CONFIG_DIR . '/connect.json';
|
||||||
|
|
||||||
|
public static function getConfig()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return json_decode(file_get_contents(self::CONFIG_PATH), true) ?? [];
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isUserSignedIn()
|
||||||
|
{
|
||||||
|
$config = self::getConfig();
|
||||||
|
return ApiConfig::isConnectPluginEnabled() && !empty($config['username'] ?? '');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user