diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-01-26 15:40:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-26 15:40:15 -0500 |
| commit | 1cd5e208713a057680b915c9136e0d4493611ed3 (patch) | |
| tree | 59e258ecd246dfb253c06cade5f0092af9874774 /Emby.Server.Implementations/Connect | |
| parent | 0d0e4ad695f3657d7ca3eef1ed54fe8608a490a1 (diff) | |
| parent | 9ebf9162ab68fbf61a1dd5e7801eb9abe985762c (diff) | |
Merge pull request #2425 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Server.Implementations/Connect')
| -rw-r--r-- | Emby.Server.Implementations/Connect/ConnectEntryPoint.cs | 27 | ||||
| -rw-r--r-- | Emby.Server.Implementations/Connect/ConnectManager.cs | 9 |
2 files changed, 30 insertions, 6 deletions
diff --git a/Emby.Server.Implementations/Connect/ConnectEntryPoint.cs b/Emby.Server.Implementations/Connect/ConnectEntryPoint.cs index 170ef07f31..b5639773b4 100644 --- a/Emby.Server.Implementations/Connect/ConnectEntryPoint.cs +++ b/Emby.Server.Implementations/Connect/ConnectEntryPoint.cs @@ -9,6 +9,7 @@ using System; using System.IO; using System.Text; using System.Threading.Tasks; +using MediaBrowser.Controller.Security; using MediaBrowser.Model.IO; using MediaBrowser.Model.Threading; @@ -17,6 +18,7 @@ namespace Emby.Server.Implementations.Connect public class ConnectEntryPoint : IServerEntryPoint { private ITimer _timer; + private IpAddressInfo _cachedIpAddress; private readonly IHttpClient _httpClient; private readonly IApplicationPaths _appPaths; private readonly ILogger _logger; @@ -26,8 +28,9 @@ namespace Emby.Server.Implementations.Connect private readonly IApplicationHost _appHost; private readonly IFileSystem _fileSystem; private readonly ITimerFactory _timerFactory; + private readonly IEncryptionManager _encryption; - public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost, IFileSystem fileSystem, ITimerFactory timerFactory) + public ConnectEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, INetworkManager networkManager, IConnectManager connectManager, IApplicationHost appHost, IFileSystem fileSystem, ITimerFactory timerFactory, IEncryptionManager encryption) { _httpClient = httpClient; _appPaths = appPaths; @@ -37,6 +40,7 @@ namespace Emby.Server.Implementations.Connect _appHost = appHost; _fileSystem = fileSystem; _timerFactory = timerFactory; + _encryption = encryption; } public void Run() @@ -143,17 +147,31 @@ namespace Emby.Server.Implementations.Connect private string CacheFilePath { - get { return Path.Combine(_appPaths.DataPath, "wan.txt"); } + get { return Path.Combine(_appPaths.DataPath, "wan.dat"); } } private void CacheAddress(IpAddressInfo address) { + if (_cachedIpAddress != null && _cachedIpAddress.Equals(address)) + { + // no need to update the file if the address has not changed + return; + } + var path = CacheFilePath; try { _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); - _fileSystem.WriteAllText(path, address.ToString(), Encoding.UTF8); + } + catch (Exception ex) + { + } + + try + { + _fileSystem.WriteAllText(path, _encryption.EncryptString(address.ToString()), Encoding.UTF8); + _cachedIpAddress = address; } catch (Exception ex) { @@ -169,11 +187,12 @@ namespace Emby.Server.Implementations.Connect try { - var endpoint = _fileSystem.ReadAllText(path, Encoding.UTF8); + var endpoint = _encryption.DecryptString(_fileSystem.ReadAllText(path, Encoding.UTF8)); IpAddressInfo ipAddress; if (_networkManager.TryParseIpAddress(endpoint, out ipAddress)) { + _cachedIpAddress = ipAddress; ((ConnectManager)_connectManager).OnWanAddressResolved(ipAddress); } } diff --git a/Emby.Server.Implementations/Connect/ConnectManager.cs b/Emby.Server.Implementations/Connect/ConnectManager.cs index 8c8b7b0268..7e6755f6aa 100644 --- a/Emby.Server.Implementations/Connect/ConnectManager.cs +++ b/Emby.Server.Implementations/Connect/ConnectManager.cs @@ -925,7 +925,11 @@ namespace Emby.Server.Implementations.Connect } _data.PendingAuthorizations = newPendingList; - CacheData(); + + if (!newPendingList.Select(i => i.Id).SequenceEqual(currentPendingList.Select(i => i.Id), StringComparer.Ordinal)) + { + CacheData(); + } await RefreshGuestNames(list, refreshImages).ConfigureAwait(false); } @@ -1118,7 +1122,7 @@ namespace Emby.Server.Implementations.Connect } } - public async Task Authenticate(string username, string passwordMd5) + public async Task<ConnectAuthenticationResult> Authenticate(string username, string passwordMd5) { if (string.IsNullOrWhiteSpace(username)) { @@ -1147,6 +1151,7 @@ namespace Emby.Server.Implementations.Connect // No need to examine the response using (var response = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content) { + return _json.DeserializeFromStream<ConnectAuthenticationResult>(response); } } |
