On Deck tweaks + Bugfixes (#1141)

* Tweaked the On deck to only look for series that have progress in past 30 days. This number is just to test it out, it will be configurable later. Tweaked the layout of the dashboard to remove a redundant section.

* Fixed a bug where archives with __MACOSX/ inside would break the reader during flattening.

* Fixed a bug where confirm service rejection should have resolved as false.

* Fixed an issue with checking if server is accessible with loopback and local ips
This commit is contained in:
Joseph Milazzo 2022-03-08 17:33:58 -06:00 committed by GitHub
parent 5aa40142c4
commit b921a14e12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 16 deletions

View file

@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using API.Data;
using API.DTOs.Email;
@ -40,14 +42,22 @@ public class EmailService : IEmailService
cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());
}
/// <summary>
/// Test if this instance is accessible outside the network
/// </summary>
/// <remarks>This will do some basic filtering to auto return false if the emailUrl is a LAN ip</remarks>
/// <param name="emailUrl"></param>
/// <returns></returns>
public async Task<EmailTestResultDto> TestConnectivity(string emailUrl)
{
// FlurlHttp.ConfigureClient(emailUrl, cli =>
// cli.Settings.HttpClientFactory = new UntrustedCertClientFactory());
var result = new EmailTestResultDto();
try
{
if (IsLocalIpAddress(emailUrl))
{
result.Successful = false;
result.ErrorMessage = "This is a local IP address";
}
result.Successful = await SendEmailWithGet(emailUrl + "/api/email/test");
}
catch (KavitaException ex)
@ -72,6 +82,7 @@ public class EmailService : IEmailService
public async Task<bool> CheckIfAccessible(string host)
{
// This is the only exception for using the default because we need an external service to check if the server is accessible for emails
if (IsLocalIpAddress(host)) return false;
return await SendEmailWithGet(DefaultApiUrl + "/api/email/reachable?host=" + host);
}
@ -138,4 +149,34 @@ public class EmailService : IEmailService
return true;
}
private static bool IsLocalIpAddress(string url)
{
var host = url.Split(':')[0];
try
{
// get host IP addresses
var hostIPs = Dns.GetHostAddresses(host);
// get local IP addresses
var localIPs = Dns.GetHostAddresses(Dns.GetHostName());
// test if any host IP equals to any local IP or to localhost
foreach (var hostIp in hostIPs)
{
// is localhost
if (IPAddress.IsLoopback(hostIp)) return true;
// is local address
if (localIPs.Contains(hostIp))
{
return true;
}
}
}
catch
{
// ignored
}
return false;
}
}