From 735db3d5f5e8a3f8841f5f281b883e50cdc91ad7 Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Mon, 11 Dec 2023 16:38:29 -0500 Subject: [PATCH] refactor: connect page and state php data sharing --- .../plugins/dynamix.my.servers/Connect.page | 103 +++++----------- .../dynamix.my.servers/include/state.php | 113 ++++++++++++++---- 2 files changed, 119 insertions(+), 97 deletions(-) diff --git a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page index 3f41f61c7..1447bcf23 100644 --- a/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page +++ b/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page @@ -13,48 +13,29 @@ Tag="globe" * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. */ -$keyfile = empty($var['regFILE']) ? null : @file_get_contents($var['regFILE']); -if ($keyfile !== false) { - $keyfile = @base64_encode($keyfile); -} -$myservers_flash_cfg_path = '/boot/config/plugins/dynamix.my.servers/myservers.cfg'; -$myservers = file_exists($myservers_flash_cfg_path) ? @parse_ini_file($myservers_flash_cfg_path,true) : []; -// ensure some vars are defined here so we don't have to test them later -if (empty($myservers['remote']['apikey'])) { - $myservers['remote']['apikey'] = ""; -} -if (empty($myservers['remote']['wanaccess'])) { - $myservers['remote']['wanaccess'] = "no"; -} -if (empty($myservers['remote']['wanport'])) { - $myservers['remote']['wanport'] = 33443; -} -if (empty($myservers['remote']['upnpEnabled'])) { - $myservers['remote']['upnpEnabled'] = "no"; -} -if (empty($myservers['remote']['dynamicRemoteAccessType'])) { - $myservers['remote']['dynamicRemoteAccessType'] = "DISABLED"; -} +require_once "$docroot/plugins/dynamix.my.servers/include/state.php"; +$serverState = new ServerState(); + +$keyfile = $serverState->keyfileBase64; + +$myServersFlashCfg = $serverState->myServersFlashCfg; + $showT2Fa = (file_exists('/boot/config/plugins/dynamix.my.servers/showT2Fa')); -$nginx = parse_ini_file('/var/local/emhttp/nginx.ini'); -$hasMyUnraidNetCert = preg_match('/.*\.myunraid\.net$/', $nginx['NGINX_CERTNAME']); +$hasMyUnraidNetCert = preg_match('/.*\.myunraid\.net$/', $serverState->nginxCfg['NGINX_CERTNAME']); -$isRegistered = !empty($myservers['remote']['username']); +$isRegistered = $serverState->registered; +$isMiniGraphConnected = $serverState->myServersMiniGraphConnected; -$myservers_memory_cfg_path ='/var/local/emhttp/myservers.cfg'; -$mystatus = (file_exists($myservers_memory_cfg_path)) ? @parse_ini_file($myservers_memory_cfg_path) : []; -$isConnected = (($mystatus['minigraph']??'')==='CONNECTED') ? true : false; -$flashbackup_ini = '/var/local/emhttp/flashbackup.ini'; -$flashbackup_status = (file_exists($flashbackup_ini)) ? @parse_ini_file($flashbackup_ini) : []; +$flashbackup_status = $serverState->flashbackupStatus; $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 = $myservers['remote']['dynamicRemoteAccessType']; -$upnpEnabled = $myservers['remote']['upnpEnabled'] === 'yes'; -$wanaccessEnabled = $myservers['remote']['wanaccess'] === 'yes'; +$dynamicRemoteAccessType = $myServersFlashCfg['remote']['dynamicRemoteAccessType']; +$upnpEnabled = $myServersFlashCfg['remote']['upnpEnabled'] === 'yes'; +$wanaccessEnabled = $myServersFlashCfg['remote']['wanaccess'] === 'yes'; $currentRemoteAccessValue = 'OFF'; if ($dynamicRemoteAccessType === 'STATIC') { @@ -83,7 +64,7 @@ div.shade-gray{background-color:#121510;margin-top:10px;padding:8px 0 3px 0}