From 3bfff0e2fff77177f592108e3a54e179209ad5e6 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Mon, 27 Jul 2020 15:05:27 -0500 Subject: [PATCH] feat(plg): store avatar url and username in dynamix.cfg --- dynamix.unraid.net.plg | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/dynamix.unraid.net.plg b/dynamix.unraid.net.plg index d093e0dbf..5f09405db 100644 --- a/dynamix.unraid.net.plg +++ b/dynamix.unraid.net.plg @@ -876,14 +876,24 @@ function handleMessage(e) { break; case "REG_WIZARD": if (data.apikey) { - var postargs = {'#file': 'dynamix/dynamix.cfg', '#section': 'remote', apikey: data.apikey}; - if (data.email) { - postargs['email'] = data.email; - } - $.post('/update.php', postargs, function() { - console.log('dynamix/dynamix.cfg: Updated apikey under [remote] section'); + $.post('https://keys.lime-technology.com/ips/details', {'apikey': data.apikey}, function(details) { + var postargs = {'#file': 'dynamix/dynamix.cfg', '#section': 'remote', apikey: data.apikey}; + if (data.email) { + postargs['email'] = data.email; + } + if (details.username) { + postargs['username'] = details.username; + } + if (details.avatar) { + postargs['avatar'] = details.avatar; + } + $.post('/update.php', postargs, function() { + console.log('dynamix/dynamix.cfg: Updated apikey under [remote] section'); + }).fail(function() { + console.error('Failed to update apikey under [remote] section'); + }); }).fail(function() { - console.error('Failed to update apikey under [remote] section'); + console.error('Failed to retrieve details from key server'); }); } // duplicate conditional so we don't get the error from HANDLE_LICENSES() @@ -900,7 +910,7 @@ function handleMessage(e) { }); break; case "MYSERVERS_UNREGISTER": - $.post('/update.php', {'#file': 'dynamix/dynamix.cfg', '#section': 'remote', apikey: ''}, function() { + $.post('/update.php', {'#file': 'dynamix/dynamix.cfg', '#section': 'remote', apikey: '', username: '', avatar: ''}, function() { console.log('dynamix/dynamix.cfg: Unregistered myservers, cleared apikey under [remote] section'); }).fail(function() { console.error('Failed to unregister'); @@ -956,10 +966,18 @@ if (file_exists('/boot/config/plugins/dynamix/dynamix.cfg')) { if (empty($remote)) { $remote = [ "apikey" => "", + "username" => "", + "avatar" => "", "wanaccess" => "no", "wanport" => "443" ]; } +if (empty($remote['username'])) { + $remote['username'] = ''; +} +if (empty($remote['avatar'])) { + $remote['avatar'] = ''; +} $arr = []; $arr['event'] = 'STATE'; @@ -975,6 +993,8 @@ $arr['serverip'] = $_SERVER['SERVER_ADDR']; $arr['internalport'] = $_SERVER['SERVER_PORT']; $arr['protocol'] = $_SERVER['REQUEST_SCHEME']; $arr['registered'] = empty($remote['apikey']) || empty($var['regFILE']) ? 0 : 1; +$arr['username'] = $remote['username']; +$arr['avatar'] = $remote['avatar']; echo json_encode($arr); ?>