Compare commits
23
Commits
28c5918a83
...
Frontend
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3822339dd9 | ||
|
|
1c74ae9de5 | ||
|
|
bab8fa6c25 | ||
|
|
cd49d32dd7 | ||
|
|
5fe35192c6 | ||
|
|
a1f5b08ac3 | ||
|
|
2cff817044 | ||
|
|
407bbc1556 | ||
|
|
f2ace6f571 | ||
|
|
3034e66126 | ||
|
|
701ffff27e | ||
|
|
ec9cca59da | ||
|
|
90d1d6b429 | ||
|
|
3d8f903d30 | ||
|
|
eedca27a11 | ||
|
|
69a22fb3eb | ||
|
|
d3270d3117 | ||
|
|
f02203c14c | ||
|
|
7ad691c439 | ||
|
|
4eaaf0f244 | ||
|
|
a160992c08 | ||
|
|
1a361a9524 | ||
|
|
be07cdb13e |
@@ -6,8 +6,8 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<Platform>x64</Platform>
|
<!--<Platform>x64</Platform>-->
|
||||||
<Optimize>true</Optimize>
|
<Optimize>false</Optimize>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -16,12 +16,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FuzzySharp" Version="2.0.2" />
|
<PackageReference Include="FuzzySharp" Version="2.0.2" />
|
||||||
<PackageReference Include="MessagePack" Version="3.0.238-rc.1" />
|
|
||||||
<PackageReference Include="MessagePack.Annotations" Version="3.0.238-rc.1" />
|
|
||||||
<PackageReference Include="MessagePackAnalyzer" Version="3.0.238-rc.1">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="NetMQ" Version="4.0.1.13" />
|
<PackageReference Include="NetMQ" Version="4.0.1.13" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
VACUUM;
|
|
||||||
|
|
||||||
DROP TABLE Filtered;
|
|
||||||
|
|
||||||
CREATE TABLE "Filtered" (
|
|
||||||
"Id" INTEGER NOT NULL,
|
|
||||||
"Ip" TEXT NOT NULL,
|
|
||||||
"Port1" INTEGER NOT NULL,
|
|
||||||
"Port2" INTEGER NOT NULL,
|
|
||||||
"Title1" TEXT NOT NULL,
|
|
||||||
"Title2" TEXT NOT NULL,
|
|
||||||
"Description1" TEXT NOT NULL,
|
|
||||||
"Description2" TEXT NOT NULL,
|
|
||||||
"Url1" TEXT NOT NULL,
|
|
||||||
"Url2" TEXT NOT NULL,
|
|
||||||
"ServerType1" TEXT NOT NULL,
|
|
||||||
"ServerType2" TEXT NOT NULL,
|
|
||||||
"RobotsTXT1" TEXT NOT NULL,
|
|
||||||
"RobotsTXT2" TEXT NOT NULL,
|
|
||||||
"HttpVersion1" TEXT NOT NULL,
|
|
||||||
"HttpVersion2" TEXT NOT NULL,
|
|
||||||
"CertificateIssuerCountry" TEXT NOT NULL,
|
|
||||||
"CertificateOrganizationName" TEXT NOT NULL,
|
|
||||||
"IpV6" TEXT NOT NULL,
|
|
||||||
"TlsVersion" TEXT NOT NULL,
|
|
||||||
"CipherSuite" TEXT NOT NULL,
|
|
||||||
"KeyExchangeAlgorithm" TEXT NOT NULL,
|
|
||||||
"PublicKeyType1" TEXT NOT NULL,
|
|
||||||
"PublicKeyType2" TEXT NOT NULL,
|
|
||||||
"PublicKeyType3" TEXT NOT NULL,
|
|
||||||
"AcceptEncoding1" TEXT NOT NULL,
|
|
||||||
"AcceptEncoding2" TEXT NOT NULL,
|
|
||||||
"ALPN" TEXT NOT NULL,
|
|
||||||
"Connection1" TEXT NOT NULL,
|
|
||||||
"Connection2" TEXT NOT NULL,
|
|
||||||
PRIMARY KEY("Id" AUTOINCREMENT)
|
|
||||||
)
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
DROP TABLE Unfiltered;
|
|
||||||
DROP TABLE Runtimes;
|
|
||||||
|
|
||||||
CREATE TABLE "Unfiltered" (
|
|
||||||
"Id" INTEGER NOT NULL,
|
|
||||||
"Ip" TEXT NOT NULL,
|
|
||||||
"ResponseCode" INTEGER NOT NULL,
|
|
||||||
"Port1" INTEGER NOT NULL,
|
|
||||||
"Port2" INTEGER NOT NULL,
|
|
||||||
"Filtered" INTEGER NOT NULL,
|
|
||||||
CONSTRAINT "PK_Unfiltered" PRIMARY KEY("Id" AUTOINCREMENT)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE "Runtimes" (
|
|
||||||
"Id" INTEGER NOT NULL CONSTRAINT "PK_Runtimes" PRIMARY KEY AUTOINCREMENT,
|
|
||||||
"StartTime" TEXT NOT NULL,
|
|
||||||
"EndTime" TEXT NOT NULL,
|
|
||||||
"ThreadNumber" INTEGER NOT NULL
|
|
||||||
);
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Backend.Helper;
|
using Backend.Helper;
|
||||||
using MessagePack;
|
|
||||||
using Models.Handler;
|
using Models.Handler;
|
||||||
using Models.Model.Backend;
|
using Models.Model.Backend;
|
||||||
using Models.Model.External;
|
using Models.Model.External;
|
||||||
@@ -14,12 +13,18 @@ public class Communication
|
|||||||
{
|
{
|
||||||
private readonly DbHandler _dbHandler;
|
private readonly DbHandler _dbHandler;
|
||||||
private readonly ThreadHandler _threadHandler;
|
private readonly ThreadHandler _threadHandler;
|
||||||
|
private readonly IpScanner _ipScanner;
|
||||||
|
private readonly ContentFilter _contentFilter;
|
||||||
private bool _isRunning = true;
|
private bool _isRunning = true;
|
||||||
|
private string _basePath;
|
||||||
|
|
||||||
public Communication(DbHandler dbHandler, ThreadHandler threadHandler)
|
public Communication(DbHandler dbHandler, ThreadHandler threadHandler, IpScanner ipScanner, ContentFilter contentFilter, string basePath)
|
||||||
{
|
{
|
||||||
_dbHandler = dbHandler;
|
_dbHandler = dbHandler;
|
||||||
_threadHandler = threadHandler;
|
_threadHandler = threadHandler;
|
||||||
|
_ipScanner = ipScanner;
|
||||||
|
_contentFilter = contentFilter;
|
||||||
|
_basePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaitHandle[] Start()
|
public WaitHandle[] Start()
|
||||||
@@ -38,13 +43,22 @@ public class Communication
|
|||||||
{
|
{
|
||||||
using ResponseSocket rep = new();
|
using ResponseSocket rep = new();
|
||||||
|
|
||||||
|
//rep.Options.IPv4Only = true;
|
||||||
|
|
||||||
rep.Bind("tcp://127.0.0.1:5556");
|
rep.Bind("tcp://127.0.0.1:5556");
|
||||||
|
|
||||||
while (_isRunning)
|
while (_isRunning)
|
||||||
{
|
{
|
||||||
byte[] message = rep.ReceiveFrameBytes();
|
byte[] message = rep.ReceiveFrameBytes();
|
||||||
|
|
||||||
CommunicationObject communicationObject = MessagePackSerializer.Deserialize<CommunicationObject>(message);
|
CommunicationObject? communicationObject = JsonSerializer.Deserialize<CommunicationObject>(message);
|
||||||
|
|
||||||
|
//rep.SendFrame(JsonSerializer.SerializeToUtf8Bytes("Success"));
|
||||||
|
|
||||||
|
if (communicationObject is null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
OnServerOnReceiveReady(communicationObject, rep);
|
OnServerOnReceiveReady(communicationObject, rep);
|
||||||
}
|
}
|
||||||
@@ -60,7 +74,7 @@ public class Communication
|
|||||||
{
|
{
|
||||||
case CommunicationCommand.GetScanningProgress:
|
case CommunicationCommand.GetScanningProgress:
|
||||||
{
|
{
|
||||||
DatabaseSizes databaseSizes = FilesystemHelper.GetDatabaseSizes();
|
DatabaseSizes databaseSizes = FilesystemHelper.GetDatabaseSizes(_basePath);
|
||||||
|
|
||||||
long discardedIndexes = _dbHandler.GetDiscardedIndexes();
|
long discardedIndexes = _dbHandler.GetDiscardedIndexes();
|
||||||
|
|
||||||
@@ -77,13 +91,13 @@ public class Communication
|
|||||||
}
|
}
|
||||||
|
|
||||||
status.AmountOfIpv4Left = 4294967296 - discardedIndexes;
|
status.AmountOfIpv4Left = 4294967296 - discardedIndexes;
|
||||||
status.TotalFiltered = DbHandler.GetFilteredIndexes();
|
status.TotalFiltered = _dbHandler.GetFilteredIndexes();
|
||||||
status.TotalDiscarded = discardedIndexes;
|
status.TotalDiscarded = discardedIndexes;
|
||||||
status.MyDbSize = databaseSizes.MyDbSize;
|
status.MyDbSize = databaseSizes.MyDbSize;
|
||||||
status.FilteredDbSize = databaseSizes.FilteredDbSize;
|
status.FilteredDbSize = databaseSizes.FilteredDbSize;
|
||||||
status.DiscardedDbSize = databaseSizes.DiscardedDbSize;
|
status.DiscardedDbSize = databaseSizes.DiscardedDbSize;
|
||||||
|
|
||||||
byte[] serializedResult = MessagePackSerializer.Serialize(status, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray));
|
byte[] serializedResult = JsonSerializer.SerializeToUtf8Bytes(status);
|
||||||
|
|
||||||
rep.SendFrame(serializedResult);
|
rep.SendFrame(serializedResult);
|
||||||
|
|
||||||
@@ -121,13 +135,45 @@ public class Communication
|
|||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case CommunicationCommand.ChangeRuntimeVariable:
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(communicationObject.VariableValue)) break;
|
||||||
|
|
||||||
|
if (communicationObject.Variable == RuntimeVariable.DbContent.ToString())
|
||||||
|
{
|
||||||
|
int value = int.Parse(communicationObject.VariableValue);
|
||||||
|
_dbHandler.SetContentWaitTime(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (communicationObject.Variable == RuntimeVariable.DbDiscarded.ToString())
|
||||||
|
{
|
||||||
|
int value = int.Parse(communicationObject.VariableValue);
|
||||||
|
_dbHandler.SetDiscardedWaitTime(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (communicationObject.Variable == RuntimeVariable.ScannerTimeout.ToString())
|
||||||
|
{
|
||||||
|
int value = int.Parse(communicationObject.VariableValue);
|
||||||
|
_ipScanner.SetTimeout(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (communicationObject.Variable == RuntimeVariable.ContentFilter.ToString())
|
||||||
|
{
|
||||||
|
int value = int.Parse(communicationObject.VariableValue);
|
||||||
|
_contentFilter.SetTimeout(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
rep.SendFrame(JsonSerializer.SerializeToUtf8Bytes("Success"));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendStringResponse(ResponseSocket rep, string response)
|
private static void SendStringResponse(ResponseSocket rep, string response)
|
||||||
{
|
{
|
||||||
MessagePackSerializerOptions withCompression = MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray);
|
byte[] serializedResult = JsonSerializer.SerializeToUtf8Bytes(response);
|
||||||
byte[] serializedResult = MessagePackSerializer.Serialize(response, withCompression);
|
|
||||||
|
|
||||||
rep.SendFrame(serializedResult);
|
rep.SendFrame(serializedResult);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
|
||||||
using Backend.Helper;
|
using Backend.Helper;
|
||||||
using Models.Handler;
|
using Models.Handler;
|
||||||
using Models.Model.Backend;
|
using Models.Model.Backend;
|
||||||
@@ -9,16 +8,31 @@ namespace Backend.Handler;
|
|||||||
|
|
||||||
public class ContentFilter
|
public class ContentFilter
|
||||||
{
|
{
|
||||||
private readonly ConcurrentQueue<QueueItem> _queue;
|
private readonly ConcurrentQueue<Filtered> _queue;
|
||||||
|
private readonly ConcurrentQueue<UnfilteredQueueItem> _unfilteredQueue;
|
||||||
private readonly DbHandler _dbHandler;
|
private readonly DbHandler _dbHandler;
|
||||||
private const string GetDomainPort80 = "/home/skingging/Documents/Projects/CSharp/RSE/Backend/Scripts/GetDomainNamePort80.sh";
|
private readonly string _getDomainPort80;
|
||||||
private const string GetDomainPort443 = "/home/skingging/Documents/Projects/CSharp/RSE/Backend/Scripts/GetDomainNamePort443.sh";
|
private readonly string _getDomainPort443;
|
||||||
private bool _stop;
|
private bool _stop;
|
||||||
|
private int _timeOut;
|
||||||
|
private readonly string _basePath;
|
||||||
|
|
||||||
public ContentFilter(ConcurrentQueue<QueueItem> queue, DbHandler dbHandler)
|
public ContentFilter(ConcurrentQueue<Filtered> queue, ConcurrentQueue<UnfilteredQueueItem> unfilteredQueue, DbHandler dbHandler, string basePath)
|
||||||
{
|
{
|
||||||
_queue = queue;
|
_queue = queue;
|
||||||
_dbHandler = dbHandler;
|
_dbHandler = dbHandler;
|
||||||
|
_basePath = basePath;
|
||||||
|
_unfilteredQueue = unfilteredQueue;
|
||||||
|
|
||||||
|
_getDomainPort80 = $"{basePath}/Backend/Scripts/GetDomainNamePort80.sh";
|
||||||
|
_getDomainPort443 = $"{basePath}/Backend/Scripts/GetDomainNamePort443.sh";
|
||||||
|
|
||||||
|
SetTimeout(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetTimeout(int timeOut)
|
||||||
|
{
|
||||||
|
_timeOut = timeOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaitHandle[] Start()
|
public WaitHandle[] Start()
|
||||||
@@ -26,6 +40,7 @@ public class ContentFilter
|
|||||||
WaitHandle[] waitHandles = new WaitHandle[1];
|
WaitHandle[] waitHandles = new WaitHandle[1];
|
||||||
EventWaitHandle handle = new(false, EventResetMode.ManualReset);
|
EventWaitHandle handle = new(false, EventResetMode.ManualReset);
|
||||||
waitHandles[0] = handle;
|
waitHandles[0] = handle;
|
||||||
|
|
||||||
Thread f = new (Filter!);
|
Thread f = new (Filter!);
|
||||||
f.Start(handle);
|
f.Start(handle);
|
||||||
|
|
||||||
@@ -34,49 +49,50 @@ public class ContentFilter
|
|||||||
|
|
||||||
private void Filter(object obj)
|
private void Filter(object obj)
|
||||||
{
|
{
|
||||||
long indexes = DbHandler.GetUnfilteredIndexes();
|
while (!_stop)
|
||||||
|
|
||||||
for (long i = 0; i < indexes; i++)
|
|
||||||
{
|
{
|
||||||
if (_stop) break;
|
List<long> indexes = _dbHandler.GetUnfilteredIndexes();
|
||||||
|
|
||||||
Unfiltered? unfiltered = DbHandler.ReadUnfilteredWithId(i);
|
for (int i = 0; i < indexes.Count; i++)
|
||||||
|
|
||||||
if (unfiltered is null || unfiltered.Filtered == 1) continue;
|
|
||||||
|
|
||||||
unfiltered.Filtered = 1;
|
|
||||||
|
|
||||||
QueueItem superUnfilteredObject = new()
|
|
||||||
{
|
{
|
||||||
Unfiltered = unfiltered,
|
if (_stop) break;
|
||||||
Operations = Operations.Update
|
|
||||||
};
|
|
||||||
|
|
||||||
_queue.Enqueue(superUnfilteredObject);
|
Unfiltered unfiltered = _dbHandler.ReadUnfilteredWithId(indexes[i]);
|
||||||
|
|
||||||
if (_dbHandler.GetFilteredIp(unfiltered.Ip))
|
if (unfiltered.Filtered) continue;
|
||||||
{
|
|
||||||
continue;
|
Ip ip = unfiltered.Ip;
|
||||||
|
|
||||||
|
unfiltered.Filtered = true;
|
||||||
|
|
||||||
|
UnfilteredQueueItem superUnfilteredObject = new()
|
||||||
|
{
|
||||||
|
Unfiltered = unfiltered,
|
||||||
|
Operations = Operations.Update
|
||||||
|
};
|
||||||
|
|
||||||
|
_unfilteredQueue.Enqueue(superUnfilteredObject);
|
||||||
|
|
||||||
|
if (_dbHandler.FilteredIpExists(unfiltered.Ip))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Filtered filtered = GetSiteData(ip);
|
||||||
|
|
||||||
|
filtered.Port1 = unfiltered.Port1;
|
||||||
|
filtered.Port2 = unfiltered.Port2;
|
||||||
|
|
||||||
|
_queue.Enqueue(filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
Filtered filtered = GetSiteData(unfiltered.Ip);
|
Thread.Sleep(_timeOut);
|
||||||
|
|
||||||
filtered.Port1 = unfiltered.Port1;
|
|
||||||
filtered.Port2 = unfiltered.Port2;
|
|
||||||
|
|
||||||
QueueItem superFilteredObject = new()
|
|
||||||
{
|
|
||||||
Filtered = filtered,
|
|
||||||
Operations = Operations.Insert
|
|
||||||
};
|
|
||||||
|
|
||||||
_queue.Enqueue(superFilteredObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
((EventWaitHandle) obj).Set();
|
((EventWaitHandle) obj).Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Filtered GetSiteData(string ip)
|
private Filtered GetSiteData(Ip ip)
|
||||||
{
|
{
|
||||||
StartProcess(ip, 80);
|
StartProcess(ip, 80);
|
||||||
StartProcess(ip, 443);
|
StartProcess(ip, 443);
|
||||||
@@ -112,7 +128,7 @@ public class ContentFilter
|
|||||||
|
|
||||||
for (int i = 0; i < ports.Length; i++)
|
for (int i = 0; i < ports.Length; i++)
|
||||||
{
|
{
|
||||||
using StreamReader streamReader = new($"{ports[i]}Header.txt");
|
using StreamReader streamReader = new($"{_basePath}/Backend/Scripts/{ports[i]}Header.txt");
|
||||||
|
|
||||||
while (streamReader.Peek() != -1)
|
while (streamReader.Peek() != -1)
|
||||||
{
|
{
|
||||||
@@ -145,19 +161,33 @@ public class ContentFilter
|
|||||||
|
|
||||||
for (int i = 0; i < ports.Length; i++)
|
for (int i = 0; i < ports.Length; i++)
|
||||||
{
|
{
|
||||||
string? html;
|
string? html = "";
|
||||||
|
|
||||||
if (ports[i] == 80)
|
if (ports[i] == 80)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(url1)) continue;
|
if (string.IsNullOrWhiteSpace(url1)) continue;
|
||||||
|
|
||||||
html = Task.Run(() => HttpClientHelper.GetHtml(url1, 80).Result).Result;
|
try
|
||||||
|
{
|
||||||
|
html = HttpClientHelper.GetHtml(url1, 80).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(url2)) continue;
|
if (string.IsNullOrWhiteSpace(url2)) continue;
|
||||||
|
|
||||||
html = Task.Run(() => HttpClientHelper.GetHtml(url2, 443).Result).Result;
|
try
|
||||||
|
{
|
||||||
|
html = HttpClientHelper.GetHtml(url2, 443).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(html)) continue;
|
if (string.IsNullOrWhiteSpace(html)) continue;
|
||||||
@@ -166,8 +196,8 @@ public class ContentFilter
|
|||||||
if (ports[i] == 443 && string.IsNullOrWhiteSpace(title2)) { FilterHelper.GetTitle(html ,out title2); }
|
if (ports[i] == 443 && string.IsNullOrWhiteSpace(title2)) { FilterHelper.GetTitle(html ,out title2); }
|
||||||
if (ports[i] == 80 && string.IsNullOrWhiteSpace(description1)) { FilterHelper.GetDescription(html, out description1); }
|
if (ports[i] == 80 && string.IsNullOrWhiteSpace(description1)) { FilterHelper.GetDescription(html, out description1); }
|
||||||
if (ports[i] == 443 && string.IsNullOrWhiteSpace(description2)) { FilterHelper.GetDescription(html, out description2); }
|
if (ports[i] == 443 && string.IsNullOrWhiteSpace(description2)) { FilterHelper.GetDescription(html, out description2); }
|
||||||
if (ports[i] == 80 && !robotsTxt1) { robotsTxt1 = Task.Run(() => HttpClientHelper.HasRobotsTxt(url1, 80).Result).Result; }
|
if (ports[i] == 80 && !robotsTxt1) { robotsTxt1 = HttpClientHelper.HasRobotsTxt(url1, 80).GetAwaiter().GetResult(); }
|
||||||
if (ports[i] == 443 && !robotsTxt2) { robotsTxt2 = Task.Run(() => HttpClientHelper.HasRobotsTxt(url2, 443).Result).Result; }
|
if (ports[i] == 443 && !robotsTxt2) { robotsTxt2 = HttpClientHelper.HasRobotsTxt(url2, 443).GetAwaiter().GetResult(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
Filtered siteData = new()
|
Filtered siteData = new()
|
||||||
@@ -204,19 +234,18 @@ public class ContentFilter
|
|||||||
return siteData;
|
return siteData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void StartProcess(string ip, int port)
|
private void StartProcess(Ip ip, int port)
|
||||||
{
|
{
|
||||||
string fileName = port == 80 ? GetDomainPort80 : GetDomainPort443;
|
string fileName = port == 80 ? _getDomainPort80 : _getDomainPort443;
|
||||||
|
|
||||||
Process proc = new();
|
Process proc = new();
|
||||||
proc.StartInfo = new()
|
proc.StartInfo = new()
|
||||||
{
|
{
|
||||||
FileName = fileName,
|
FileName = "/bin/bash",
|
||||||
Arguments = $"{ip}",
|
Arguments = $"{fileName} {ip.Ip1}.{ip.Ip2}.{ip.Ip3}.{ip.Ip4} {_basePath}/Backend/Scripts/{port}Header.txt",
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = false,
|
RedirectStandardOutput = false,
|
||||||
RedirectStandardError = false,
|
RedirectStandardError = false,
|
||||||
RedirectStandardInput = false,
|
|
||||||
CreateNoWindow = true
|
CreateNoWindow = true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Globalization;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using Backend.Helper;
|
using Backend.Helper;
|
||||||
@@ -18,19 +17,31 @@ public class ScanSettings
|
|||||||
|
|
||||||
public class IpScanner
|
public class IpScanner
|
||||||
{
|
{
|
||||||
private readonly ConcurrentQueue<QueueItem> _queue;
|
|
||||||
private readonly ConcurrentQueue<Discarded> _discardedQueue;
|
private readonly ConcurrentQueue<Discarded> _discardedQueue;
|
||||||
|
private readonly ConcurrentQueue<UnfilteredQueueItem> _unfilteredQueue;
|
||||||
|
private readonly ConcurrentQueue<ScannerResumeObject> _resumeQueue;
|
||||||
private readonly DbHandler _dbHandler;
|
private readonly DbHandler _dbHandler;
|
||||||
private bool _stop;
|
private bool _stop;
|
||||||
|
private int _timeout;
|
||||||
|
|
||||||
public IpScanner(ConcurrentQueue<QueueItem> queue, DbHandler dbHandler, ConcurrentQueue<Discarded> discardedQueue)
|
public IpScanner(ConcurrentQueue<UnfilteredQueueItem> unfilteredQueue, ConcurrentQueue<Discarded> discardedQueue,
|
||||||
|
ConcurrentQueue<ScannerResumeObject> resumeQueue, DbHandler dbHandler
|
||||||
|
)
|
||||||
{
|
{
|
||||||
_queue = queue;
|
|
||||||
_dbHandler = dbHandler;
|
_dbHandler = dbHandler;
|
||||||
_discardedQueue = discardedQueue;
|
_discardedQueue = discardedQueue;
|
||||||
|
_unfilteredQueue = unfilteredQueue;
|
||||||
|
_resumeQueue = resumeQueue;
|
||||||
|
|
||||||
|
SetTimeout(64);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaitHandle[] Start(int threads)
|
public void SetTimeout(int milliseconds)
|
||||||
|
{
|
||||||
|
_timeout = milliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WaitHandle[]> Start(int threads)
|
||||||
{
|
{
|
||||||
int threadsAmount = 0;
|
int threadsAmount = 0;
|
||||||
if (threads % 2 == 0)
|
if (threads % 2 == 0)
|
||||||
@@ -38,7 +49,22 @@ public class IpScanner
|
|||||||
threadsAmount = 256 / threads;
|
threadsAmount = 256 / threads;
|
||||||
}
|
}
|
||||||
|
|
||||||
WaitHandle[] waitHandles = new WaitHandle[threads];
|
WaitHandle[] waitHandle1;
|
||||||
|
WaitHandle[] waitHandle2;
|
||||||
|
|
||||||
|
if (threads <= 64)
|
||||||
|
{
|
||||||
|
waitHandle1 = new WaitHandle[threads];
|
||||||
|
waitHandle2 = new WaitHandle[threads];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waitHandle1 = new WaitHandle[64];
|
||||||
|
waitHandle2 = new WaitHandle[64];
|
||||||
|
}
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
int counter2 = 0;
|
||||||
|
|
||||||
for (int i = 0; i < threads; i++)
|
for (int i = 0; i < threads; i++)
|
||||||
{
|
{
|
||||||
@@ -52,15 +78,32 @@ public class IpScanner
|
|||||||
Handle = handle
|
Handle = handle
|
||||||
};
|
};
|
||||||
|
|
||||||
waitHandles[i] = handle;
|
if (i < 64)
|
||||||
|
{
|
||||||
|
waitHandle1[counter] = handle;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
waitHandle2[counter2] = handle;
|
||||||
|
counter2++;
|
||||||
|
}
|
||||||
|
|
||||||
Thread f = new (Scan!);
|
Thread f = new (Scan!);
|
||||||
f.Start(scanSettings);
|
f.Start(scanSettings);
|
||||||
|
|
||||||
Console.WriteLine($"Scanner thread ({i}) started");
|
Console.WriteLine($"Scanner thread ({i}) started");
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<WaitHandle[]> waitHandles = new();
|
||||||
|
|
||||||
|
Console.WriteLine("Waithandle 1 count = " + waitHandle1.Length);
|
||||||
|
Console.WriteLine("Waithandle 2 count = " + waitHandle2.Length);
|
||||||
|
|
||||||
|
waitHandles.Add(waitHandle1);
|
||||||
|
waitHandles.Add(waitHandle2);
|
||||||
|
|
||||||
return waitHandles;
|
return waitHandles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +153,6 @@ public class IpScanner
|
|||||||
|
|
||||||
if (_discardedQueue.Count >= 2000)
|
if (_discardedQueue.Count >= 2000)
|
||||||
{
|
{
|
||||||
Console.WriteLine("loooooooooooooooooooooooooooool");
|
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +164,13 @@ public class IpScanner
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ip = $"{i}.{j}.{k}.{l}";
|
Ip ip = new()
|
||||||
|
{
|
||||||
|
Ip1 = i,
|
||||||
|
Ip2 = j,
|
||||||
|
Ip3 = k,
|
||||||
|
Ip4 = l
|
||||||
|
};
|
||||||
|
|
||||||
IPStatus responseCode = IPStatus.Unknown;
|
IPStatus responseCode = IPStatus.Unknown;
|
||||||
|
|
||||||
@@ -130,15 +178,15 @@ public class IpScanner
|
|||||||
{
|
{
|
||||||
// Sometimes, if the pinger gets a Destination Unreachable Communication administratively prohibited response, the pinger will throw an exception.
|
// Sometimes, if the pinger gets a Destination Unreachable Communication administratively prohibited response, the pinger will throw an exception.
|
||||||
// https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol?useskin=vector#Control_messages
|
// https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol?useskin=vector#Control_messages
|
||||||
_ = IPAddress.TryParse(ip, out IPAddress? address);
|
_ = IPAddress.TryParse(ip.ToString(), out IPAddress? address);
|
||||||
if (address is not null)
|
if (address is not null)
|
||||||
{
|
{
|
||||||
responseCode = ping.Send(address, 512, buf, null).Status;
|
responseCode = ping.Send(address, _timeout, buf, null).Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responseCode != IPStatus.Success)
|
if (responseCode != IPStatus.Success)
|
||||||
@@ -147,7 +195,7 @@ public class IpScanner
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
(int, int) ports = TcpClientHelper.CheckPort(ip, 80, 443);
|
(int, int) ports = TcpClientHelper.CheckPort(ip.ToString(), 80, 443);
|
||||||
|
|
||||||
if (ports is { Item1: 0, Item2: 0 })
|
if (ports is { Item1: 0, Item2: 0 })
|
||||||
{
|
{
|
||||||
@@ -155,7 +203,7 @@ public class IpScanner
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_queue.Enqueue(CreateUnfilteredQueueItem(ip, (int)responseCode, ports));
|
_unfilteredQueue.Enqueue(CreateUnfilteredQueueItem(ip, ports));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_stop)
|
if (_stop)
|
||||||
@@ -177,49 +225,39 @@ public class IpScanner
|
|||||||
resumeObject.FirstByte = i;
|
resumeObject.FirstByte = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//Console.WriteLine($"Thread ({scanSettings.ThreadNumber}) is at index ({i}) out of ({scanSettings.End}). Remaining ({scanSettings.End - i})");
|
|
||||||
|
Console.WriteLine($"Thread ({scanSettings.ThreadNumber}) is at index ({i}) out of ({scanSettings.End}). Remaining ({scanSettings.End - i})");
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueItem resume = new()
|
_resumeQueue.Enqueue(resumeObject);
|
||||||
{
|
|
||||||
ResumeObject = resumeObject,
|
|
||||||
Operations = Operations.Insert
|
|
||||||
};
|
|
||||||
|
|
||||||
_queue.Enqueue(resume);
|
|
||||||
|
|
||||||
scanSettings.Handle!.Set();
|
scanSettings.Handle!.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Discarded CreateDiscardedQueueItem(string ip, int responseCode)
|
private static Discarded CreateDiscardedQueueItem(Ip ip, int responseCode)
|
||||||
{
|
{
|
||||||
Discarded discarded = new()
|
return new()
|
||||||
{
|
{
|
||||||
Ip = ip,
|
Ip = ip,
|
||||||
ResponseCode = responseCode
|
ResponseCode = responseCode
|
||||||
};
|
};
|
||||||
|
|
||||||
return discarded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static QueueItem CreateUnfilteredQueueItem(string ip, int responseCode, (int, int) ports)
|
private static UnfilteredQueueItem CreateUnfilteredQueueItem(Ip ip, (int, int) ports)
|
||||||
{
|
{
|
||||||
Unfiltered unfiltered = new()
|
Unfiltered unfiltered = new()
|
||||||
{
|
{
|
||||||
Ip = ip,
|
Ip = ip,
|
||||||
ResponseCode = responseCode,
|
|
||||||
Port1 = ports.Item1,
|
Port1 = ports.Item1,
|
||||||
Port2 = ports.Item2,
|
Port2 = ports.Item2,
|
||||||
Filtered = 0
|
Filtered = false
|
||||||
};
|
};
|
||||||
|
|
||||||
QueueItem superUnfilteredObject = new()
|
return new()
|
||||||
{
|
{
|
||||||
Unfiltered = unfiltered,
|
Unfiltered = unfiltered,
|
||||||
Operations = Operations.Insert
|
Operations = Operations.Insert
|
||||||
};
|
};
|
||||||
|
|
||||||
return superUnfilteredObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
|
|||||||
@@ -14,84 +14,94 @@ public class ThreadHandler
|
|||||||
private bool _communicationStopped;
|
private bool _communicationStopped;
|
||||||
private bool _ipScannerStopped;
|
private bool _ipScannerStopped;
|
||||||
private bool _contentFilterStopped;
|
private bool _contentFilterStopped;
|
||||||
private bool _stopSignal;
|
|
||||||
|
|
||||||
public ThreadHandler()
|
public ThreadHandler(string path)
|
||||||
{
|
{
|
||||||
ConcurrentQueue<QueueItem> contentQueue = new();
|
ConcurrentQueue<Filtered> filteredQueue = new();
|
||||||
ConcurrentQueue<Discarded> discardedQueue = new();
|
ConcurrentQueue<Discarded> discardedQueue = new();
|
||||||
|
ConcurrentQueue<UnfilteredQueueItem> unfilteredQueue = new();
|
||||||
|
ConcurrentQueue<ScannerResumeObject> scannerResumeQueue = new();
|
||||||
|
|
||||||
_dbHandler = new(contentQueue, discardedQueue);
|
_dbHandler = new(filteredQueue, discardedQueue, unfilteredQueue, scannerResumeQueue, path);
|
||||||
_communication = new(_dbHandler, this);
|
_ipScanner = new(unfilteredQueue, discardedQueue, scannerResumeQueue, _dbHandler);
|
||||||
_ipScanner = new(contentQueue, _dbHandler, discardedQueue);
|
_contentFilter = new(filteredQueue, unfilteredQueue, _dbHandler, path);
|
||||||
_contentFilter = new(contentQueue, _dbHandler);
|
_communication = new(_dbHandler, this, _ipScanner, _contentFilter, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Thread scanner = new(StartScanner);
|
Thread scanner = new(StartScanner);
|
||||||
Thread indexer = new(StartIndexer);
|
Thread indexer = new(StartContentFilter);
|
||||||
Thread database = new(StartDbHandler);
|
Thread database = new(StartDbHandler);
|
||||||
Thread discarded = new(StartDiscardedDbHandler);
|
Thread discarded = new(StartDiscardedDbHandler);
|
||||||
|
Thread filtered = new(StartFilteredDbHandler);
|
||||||
|
Thread resume = new(StartResumeDbHandler);
|
||||||
Thread communication = new(StartCommunicationHandler);
|
Thread communication = new(StartCommunicationHandler);
|
||||||
|
|
||||||
scanner.Start();
|
scanner.Start();
|
||||||
indexer.Start();
|
indexer.Start();
|
||||||
database.Start();
|
database.Start();
|
||||||
discarded.Start();
|
discarded.Start();
|
||||||
|
filtered.Start();
|
||||||
|
resume.Start();
|
||||||
communication.Start();
|
communication.Start();
|
||||||
|
|
||||||
scanner.Join();
|
scanner.Join();
|
||||||
indexer.Join();
|
indexer.Join();
|
||||||
database.Join();
|
database.Join();
|
||||||
discarded.Join();
|
discarded.Join();
|
||||||
|
filtered.Join();
|
||||||
|
resume.Join();
|
||||||
communication.Join();
|
communication.Join();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ManualGc()
|
|
||||||
{
|
|
||||||
GC.Collect();
|
|
||||||
GC.WaitForPendingFinalizers();
|
|
||||||
GC.Collect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartScanner()
|
private void StartScanner()
|
||||||
{
|
{
|
||||||
Thread.Sleep(10000); // Let the database handler instantiate and warm up first.
|
Thread.Sleep(5000); // Let the database handler instantiate and warm up first.
|
||||||
|
|
||||||
WaitHandle[] wait = _ipScanner.Start(4);
|
List<WaitHandle[]> wait = _ipScanner.Start(128);
|
||||||
|
|
||||||
WaitHandle.WaitAll(wait);
|
for (int i = 0; i < wait.Count; i++)
|
||||||
|
{
|
||||||
|
WaitHandle.WaitAll(wait[i]);
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("Scanner finished");
|
Console.WriteLine("Scanner finished");
|
||||||
|
|
||||||
_ipScannerStopped = true;
|
_ipScannerStopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartIndexer()
|
private void StartContentFilter()
|
||||||
{
|
{
|
||||||
while (!_stopSignal)
|
Thread.Sleep(5000);
|
||||||
{
|
|
||||||
WaitHandle[] wait = _contentFilter.Start();
|
|
||||||
|
|
||||||
WaitHandle.WaitAll(wait);
|
WaitHandle[] wait = _contentFilter.Start();
|
||||||
|
|
||||||
Thread.Sleep(300000); // 5 minutes
|
WaitHandle.WaitAll(wait);
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Indexer finished");
|
Console.WriteLine("Content filter finished");
|
||||||
|
|
||||||
_contentFilterStopped = true;
|
_contentFilterStopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartDbHandler()
|
private void StartDbHandler()
|
||||||
{
|
{
|
||||||
_dbHandler.StartContent();
|
_dbHandler.UnfilteredDbHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartFilteredDbHandler()
|
||||||
|
{
|
||||||
|
_dbHandler.FilteredDbHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartResumeDbHandler()
|
||||||
|
{
|
||||||
|
_dbHandler.ResumeDbHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartDiscardedDbHandler()
|
private void StartDiscardedDbHandler()
|
||||||
{
|
{
|
||||||
WaitHandle[] wait = _dbHandler.Start(2);
|
WaitHandle[] wait = _dbHandler.Start(4);
|
||||||
|
|
||||||
WaitHandle.WaitAll(wait);
|
WaitHandle.WaitAll(wait);
|
||||||
|
|
||||||
@@ -113,7 +123,6 @@ public class ThreadHandler
|
|||||||
|
|
||||||
private void Stop()
|
private void Stop()
|
||||||
{
|
{
|
||||||
_stopSignal = true;
|
|
||||||
_ipScanner.Stop();
|
_ipScanner.Stop();
|
||||||
_contentFilter.Stop();
|
_contentFilter.Stop();
|
||||||
|
|
||||||
|
|||||||
@@ -4,24 +4,24 @@ namespace Backend.Helper;
|
|||||||
|
|
||||||
public static class FilesystemHelper
|
public static class FilesystemHelper
|
||||||
{
|
{
|
||||||
public static DatabaseSizes GetDatabaseSizes()
|
public static DatabaseSizes GetDatabaseSizes(string basePath)
|
||||||
{
|
{
|
||||||
DatabaseSizes databaseSizes = new();
|
DatabaseSizes databaseSizes = new();
|
||||||
|
|
||||||
FileInfo fileInfo = new("../../../../Models/mydb.db");
|
FileInfo fileInfo = new($"{basePath}/Models/mydb.db");
|
||||||
databaseSizes.MyDbSize = fileInfo.Length.ToSize(SizeUnits.KB);
|
databaseSizes.MyDbSize = fileInfo.Length.ToSize(SizeUnits.KB);
|
||||||
|
|
||||||
databaseSizes.DiscardedDbSize = GetDiscardedDbSizes().ToSize(SizeUnits.KB);
|
databaseSizes.DiscardedDbSize = GetDiscardedDbSizes(basePath).ToSize(SizeUnits.KB);
|
||||||
|
|
||||||
fileInfo = new("../../../../Models/Filtered.db");
|
fileInfo = new($"{basePath}/Models/Filtered.db");
|
||||||
databaseSizes.FilteredDbSize = fileInfo.Length.ToSize(SizeUnits.KB);
|
databaseSizes.FilteredDbSize = fileInfo.Length.ToSize(SizeUnits.KB);
|
||||||
|
|
||||||
return databaseSizes;
|
return databaseSizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long GetDiscardedDbSizes()
|
private static long GetDiscardedDbSizes(string basePath)
|
||||||
{
|
{
|
||||||
const string folder = "../../../../Models";
|
string folder = $"{basePath}/Models";
|
||||||
string[] files = Directory.GetFiles(folder, "*.db");
|
string[] files = Directory.GetFiles(folder, "*.db");
|
||||||
|
|
||||||
long size = 0;
|
long size = 0;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Backend.Helper;
|
namespace Backend.Helper;
|
||||||
|
|
||||||
public static class HttpClientHelper
|
public static class HttpClientHelper
|
||||||
@@ -16,19 +18,20 @@ public static class HttpClientHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Accept.Clear();
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
|
client.Timeout = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
HttpResponseMessage? response;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
response = await client.GetAsync("/");
|
response = await client.GetAsync("/");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response is null || !response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -50,16 +53,17 @@ public static class HttpClientHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Accept.Clear();
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
|
client.Timeout = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
HttpResponseMessage? response = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{//
|
||||||
response = await client.GetAsync("/robots.txt");
|
response = await client.SendAsync(new(HttpMethod.Head, "/robots.txt"));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
return response is not null && response.IsSuccessStatusCode;
|
return response is not null && response.IsSuccessStatusCode;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Backend.Helper;
|
||||||
|
|
||||||
|
public static class ProjectPathHelper
|
||||||
|
{
|
||||||
|
public static string GetProjectPath()
|
||||||
|
{
|
||||||
|
return new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent!.Parent!.Parent!.Parent!.FullName;
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -1,8 +1,9 @@
|
|||||||
using Backend.Handler;
|
using Backend.Handler;
|
||||||
|
using Backend.Helper;
|
||||||
|
|
||||||
Console.WriteLine("Program started");
|
Console.WriteLine("Program started");
|
||||||
|
|
||||||
ThreadHandler threadHandler = new();
|
ThreadHandler threadHandler = new(ProjectPathHelper.GetProjectPath());
|
||||||
threadHandler.Start();
|
threadHandler.Start();
|
||||||
|
|
||||||
Console.WriteLine("Done");
|
Console.WriteLine("Done");
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl -k -vvI -m 10 https://"$1" &> 443Header.txt
|
curl -k -vvI -m 10 https://"$1" &> "$2"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
curl -k -vvI -m 10 http://"$1" &> 80Header.txt
|
curl -k -vvI -m 10 http://"$1" &> "$2"
|
||||||
|
#80Header.txt
|
||||||
|
|||||||
+40
-8
@@ -1,4 +1,6 @@
|
|||||||
using MessagePack;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Models.Model.Backend;
|
||||||
using Models.Model.External;
|
using Models.Model.External;
|
||||||
using NetMQ;
|
using NetMQ;
|
||||||
using NetMQ.Sockets;
|
using NetMQ.Sockets;
|
||||||
@@ -49,6 +51,18 @@ public static class Commands
|
|||||||
Console.WriteLine(SendAndRecieveStringMessage(communicationObject));
|
Console.WriteLine(SendAndRecieveStringMessage(communicationObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetRuntimeVariable(RuntimeVariable runtimeVariable, string value)
|
||||||
|
{
|
||||||
|
CommunicationObject communicationObject = new()
|
||||||
|
{
|
||||||
|
Command = CommunicationCommand.ChangeRuntimeVariable,
|
||||||
|
Variable = runtimeVariable.ToString(),
|
||||||
|
VariableValue = value
|
||||||
|
};
|
||||||
|
|
||||||
|
Console.WriteLine(SendAndRecieveStringMessage(communicationObject));
|
||||||
|
}
|
||||||
|
|
||||||
public static void GetHelp()
|
public static void GetHelp()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Available commands:");
|
Console.WriteLine("Available commands:");
|
||||||
@@ -59,32 +73,50 @@ public static class Commands
|
|||||||
Console.WriteLine(" g - manual garbage collect on the server");
|
Console.WriteLine(" g - manual garbage collect on the server");
|
||||||
Console.WriteLine(" r - manual reindex the databases");
|
Console.WriteLine(" r - manual reindex the databases");
|
||||||
Console.WriteLine(" v - manual vacuum the databases");
|
Console.WriteLine(" v - manual vacuum the databases");
|
||||||
|
Console.WriteLine(" R - change runtime variable");
|
||||||
|
Console.WriteLine(" lR - list runtime variables");
|
||||||
Console.WriteLine(" help - shows this help");
|
Console.WriteLine(" help - shows this help");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string SendAndRecieveStringMessage(CommunicationObject communicationObject)
|
public static void PrintRuntimeVariables()
|
||||||
{
|
{
|
||||||
byte[] bytes = MessagePackSerializer.Serialize(communicationObject);
|
Console.WriteLine("Runtime variables:");
|
||||||
|
Console.WriteLine($"{RuntimeVariable.ScannerTimeout.ToString()} - Sets the timeout in milliseconds for the scanner");
|
||||||
|
Console.WriteLine($"{RuntimeVariable.ContentFilter.ToString()} - Sets the timeout in milliseconds for the content filter");
|
||||||
|
Console.WriteLine($"{RuntimeVariable.DbContent.ToString()} - Sets the wait time in milliseconds for the content database if the queue is empty");
|
||||||
|
Console.WriteLine($"{RuntimeVariable.DbDiscarded.ToString()} - Sets the wait time in milliseconds for the discarded database if the queue is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequiresDynamicCode("Calls System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)")]
|
||||||
|
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)")]
|
||||||
|
private static string? SendAndRecieveStringMessage(CommunicationObject communicationObject)
|
||||||
|
{
|
||||||
|
//byte[] bytes = MessagePackSerializer.Serialize(communicationObject, ContractlessStandardResolver.Options);
|
||||||
|
|
||||||
|
byte[] lol = JsonSerializer.SerializeToUtf8Bytes(communicationObject);
|
||||||
|
|
||||||
using RequestSocket client = new();
|
using RequestSocket client = new();
|
||||||
client.Connect("tcp://127.0.0.1:5556");
|
client.Connect("tcp://127.0.0.1:5556");
|
||||||
client.SendFrame(bytes);
|
client.SendFrame(lol);
|
||||||
byte[] msg = client.ReceiveFrameBytes();
|
byte[] msg = client.ReceiveFrameBytes();
|
||||||
client.Close();
|
client.Close();
|
||||||
return MessagePackSerializer.Deserialize<string>(msg, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray));
|
|
||||||
|
return JsonSerializer.Deserialize<string>(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)")]
|
||||||
|
[RequiresDynamicCode("Calls System.Text.Json.JsonSerializer.SerializeToUtf8Bytes<TValue>(TValue, JsonSerializerOptions)")]
|
||||||
private static ScanningStatus GetProgress(CommunicationObject communicationObject)
|
private static ScanningStatus GetProgress(CommunicationObject communicationObject)
|
||||||
{
|
{
|
||||||
byte[] bytes = MessagePackSerializer.Serialize(communicationObject);
|
byte[] lol = JsonSerializer.SerializeToUtf8Bytes(communicationObject);
|
||||||
|
|
||||||
using RequestSocket client = new();
|
using RequestSocket client = new();
|
||||||
client.Connect("tcp://127.0.0.1:5556");
|
client.Connect("tcp://127.0.0.1:5556");
|
||||||
client.SendFrame(bytes);
|
client.SendFrame(lol);
|
||||||
byte[] msg = client.ReceiveFrameBytes();
|
byte[] msg = client.ReceiveFrameBytes();
|
||||||
client.Close();
|
client.Close();
|
||||||
|
|
||||||
return MessagePackSerializer.Deserialize<ScanningStatus>(msg, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray));
|
return JsonSerializer.Deserialize<ScanningStatus>(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-10
@@ -6,13 +6,12 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<PublishAot>true</PublishAot>
|
<!--<Platform>x64</Platform>
|
||||||
<Platform>x64</Platform>
|
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<!--<PublishAot>true</PublishAot>-->
|
<PublishAot>true</PublishAot>
|
||||||
<PublishTrimmed>true</PublishTrimmed>
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
<TrimMode>link</TrimMode>
|
<TrimMode>link</TrimMode>
|
||||||
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
|
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>-->
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -20,12 +19,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MessagePack" Version="3.0.238-rc.1" />
|
|
||||||
<PackageReference Include="MessagePack.Annotations" Version="3.0.238-rc.1" />
|
|
||||||
<PackageReference Include="MessagePackAnalyzer" Version="3.0.238-rc.1">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="NetMQ" Version="4.0.1.13" />
|
<PackageReference Include="NetMQ" Version="4.0.1.13" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Manager;
|
using Manager;
|
||||||
|
using Models.Model.Backend;
|
||||||
|
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
|
|
||||||
@@ -36,6 +37,46 @@ do
|
|||||||
Commands.ReIndex();
|
Commands.ReIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (string.Equals(input, "R"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Variable name.");
|
||||||
|
string? variable = Console.ReadLine();
|
||||||
|
|
||||||
|
Console.WriteLine("Variable value.");
|
||||||
|
string? value = Console.ReadLine();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(variable) || string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please enter a value.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variable == RuntimeVariable.ScannerTimeout.ToString())
|
||||||
|
{
|
||||||
|
Commands.SetRuntimeVariable(RuntimeVariable.ScannerTimeout, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (variable == RuntimeVariable.ContentFilter.ToString())
|
||||||
|
{
|
||||||
|
Commands.SetRuntimeVariable(RuntimeVariable.ContentFilter, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (variable == RuntimeVariable.DbDiscarded.ToString())
|
||||||
|
{
|
||||||
|
Commands.SetRuntimeVariable(RuntimeVariable.DbDiscarded, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (variable == RuntimeVariable.DbContent.ToString())
|
||||||
|
{
|
||||||
|
Commands.SetRuntimeVariable(RuntimeVariable.DbContent, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (string.Equals(input, "lR"))
|
||||||
|
{
|
||||||
|
Commands.PrintRuntimeVariables();
|
||||||
|
}
|
||||||
|
|
||||||
else if (string.Equals(input, "help"))
|
else if (string.Equals(input, "help"))
|
||||||
{
|
{
|
||||||
Commands.GetHelp();
|
Commands.GetHelp();
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+329
-81
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Diagnostics;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using Models.Model.Backend;
|
using Models.Model.Backend;
|
||||||
using Models.Model.External;
|
using Models.Model.External;
|
||||||
@@ -7,24 +8,78 @@ namespace Models.Handler;
|
|||||||
|
|
||||||
public class DbHandler
|
public class DbHandler
|
||||||
{
|
{
|
||||||
private readonly ConcurrentQueue<QueueItem> _contentQueue;
|
private readonly ConcurrentQueue<Filtered> _filteredQueue;
|
||||||
|
private readonly ConcurrentQueue<UnfilteredQueueItem> _unfilteredQueue;
|
||||||
private readonly ConcurrentQueue<Discarded> _discardedQueue;
|
private readonly ConcurrentQueue<Discarded> _discardedQueue;
|
||||||
|
private readonly ConcurrentQueue<ScannerResumeObject> _resumeQueue;
|
||||||
|
|
||||||
private const string UnfilteredConnectionString = "Data Source=../../../../Models/mydb.db";
|
private readonly string _unfilteredConnectionString;
|
||||||
private const string DiscardedConnectionString = "Data Source=../../../../Models/Discarded.db";
|
private readonly string _discardedConnectionString;
|
||||||
private const string FilteredConnectionString = "Data Source=../../../../Models/Filtered.db";
|
private readonly string _filteredConnectionString;
|
||||||
private const string ResumeConnectionString = "Data Source=../../../../Models/ScannerResume.db";
|
private readonly string _resumeConnectionString;
|
||||||
private readonly List<string> _discardedConnectionStrings = [];
|
private readonly List<string> _discardedConnectionStrings = [];
|
||||||
|
|
||||||
private const string InsertStatement = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Unfiltered (Ip, ResponseCode, Port1, Port2, Filtered) VALUES (@ip, @responseCode, @port1, @port2, @filtered)";
|
private const string InsertStatement = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" +
|
||||||
private const string InsertIntoFiltered = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Filtered (Ip, Port1, Port2, Title1, Title2, Description1, Description2, Url1, Url2, ServerType1, ServerType2, RobotsTXT1, RobotsTXT2, HttpVersion1, HttpVersion2, CertificateIssuerCountry, CertificateOrganizationName, IpV6, TlsVersion, CipherSuite, KeyExchangeAlgorithm, PublicKeyType1, PublicKeyType2, PublicKeyType3, AcceptEncoding1, AcceptEncoding2, ALPN, Connection1, Connection2) VALUES (@ip, @port1, @port2, @title1, @title2, @description1, @description2, @url1, @url2, @serverType1, @serverType2, @robotsTXT1, @robotsTXT2, @httpVersion1, @httpVersion2, @certificateIssuerCountry, @certificateOrganizationName, @ipV6, @tlsVersion, @cipherSuite, @keyExchangeAlgorithm, @publicKeyType1, @publicKeyType2, @publicKeyType3, @acceptEncoding1, @acceptEncoding2, @aLPN, @connection1, @connection2)";
|
" PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off;" +
|
||||||
private const string InsertIntoDiscarded = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Discarded (Ip, ResponseCode) VALUES (@ip, @responseCode)";
|
" INSERT INTO Unfiltered (Ip1, Ip2, Ip3, Ip4, Port1, Port2, Filtered)" +
|
||||||
private const string InsertIntoResume = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off; INSERT INTO Resume (ThreadNumber, StartRange, EndRange, FirstByte, SecondByte, ThirdByte, FourthByte) VALUES (@threadNumber, @startRange, @endRange, @firstByte, @secondByte, @thirdByte, @fourthByte);";
|
" VALUES (@ip1, @ip2, @ip3, @ip4, @port1, @port2, @filtered)";
|
||||||
|
|
||||||
|
private const string InsertIntoFiltered = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" +
|
||||||
|
" PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = on;" +
|
||||||
|
" INSERT INTO Filtered (Ip1, Ip2, Ip3, Ip4, Port1, Port2, Title1, Title2," +
|
||||||
|
" Description1, Description2, Url1, Url2, ServerType1, ServerType2," +
|
||||||
|
" RobotsTXT1, RobotsTXT2, HttpVersion1, HttpVersion2, CertificateIssuerCountry," +
|
||||||
|
" CertificateOrganizationName, IpV6, TlsVersion, CipherSuite, KeyExchangeAlgorithm," +
|
||||||
|
" PublicKeyType1, PublicKeyType2, PublicKeyType3, AcceptEncoding1, AcceptEncoding2," +
|
||||||
|
" ALPN, Connection1, Connection2) VALUES (@ip1, @ip2, @ip3, @ip4, @port1, @port2, " +
|
||||||
|
" @title1, @title2, @description1, @description2, @url1, @url2, " +
|
||||||
|
" (SELECT ServerId FROM ServerType WHERE Type = @serverType1), " +
|
||||||
|
" (SELECT ServerId FROM ServerType WHERE Type = @serverType2), " +
|
||||||
|
" @robotsTXT1, @robotsTXT2," +
|
||||||
|
" (SELECT HttpId FROM HttpVersion WHERE Version = @httpVersion1)," +
|
||||||
|
" (SELECT HttpId FROM HttpVersion WHERE Version = @httpVersion2)," +
|
||||||
|
" (SELECT CertificateIssuerId FROM CertificateIssuerCountry WHERE Country = @certificateIssuerCountry)," +
|
||||||
|
" (SELECT CertificateOrganizationId FROM CertificateOrganizationName WHERE Name = @certificateOrganizationName), " +
|
||||||
|
" @ipV6, " +
|
||||||
|
" (SELECT TlsId FROM TlsVersion WHERE Version = @tlsVersion)," +
|
||||||
|
" (SELECT CipherId FROM CipherSuite WHERE Suite = @cipherSuite)," +
|
||||||
|
" (SELECT KeyExchangeId FROM KeyExchangeAlgorithm WHERE Algorithm = @keyExchangeAlgorithm)," +
|
||||||
|
" (SELECT PublicKeyId FROM PublicKeyType WHERE Type = @publicKeyType1)," +
|
||||||
|
" (SELECT PublicKeyId FROM PublicKeyType WHERE Type = @publicKeyType2)," +
|
||||||
|
" (SELECT PublicKeyId FROM PublicKeyType WHERE Type = @publicKeyType3)," +
|
||||||
|
" (SELECT AcceptId FROM AcceptEncoding WHERE Encoding = @acceptEncoding1)," +
|
||||||
|
" (SELECT AcceptId FROM AcceptEncoding WHERE Encoding = @acceptEncoding2)," +
|
||||||
|
" (SELECT ALPNId FROM ALPN WHERE ALPNValue = @aLPN)," +
|
||||||
|
" (SELECT ConnectionId FROM Connection WHERE ConnectionValue = @connection1)," +
|
||||||
|
" (SELECT ConnectionId FROM Connection WHERE ConnectionValue = @connection2))";
|
||||||
|
|
||||||
|
private const string InsertIntoFilteredServerType = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO ServerType (Type) VALUES (@type)";
|
||||||
|
private const string InsertIntoFilteredHttpVersion = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO HttpVersion (Version) VALUES (@version)";
|
||||||
|
private const string InsertIntoFilteredCertificateIssuerCountry = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO CertificateIssuerCountry (Country) VALUES (@country)";
|
||||||
|
private const string InsertIntoFilteredCertificateOrganizationName = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO CertificateOrganizationName (Name) VALUES (@name)";
|
||||||
|
private const string InsertIntoFilteredTlsVersion = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO TlsVersion (Version) VALUES (@version)";
|
||||||
|
private const string InsertIntoFilteredCipherSuite = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO CipherSuite (Suite) VALUES (@suite)";
|
||||||
|
private const string InsertIntoFilteredKeyExchangeAlgorithm = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO KeyExchangeAlgorithm (Algorithm) VALUES (@algorithm)";
|
||||||
|
private const string InsertIntoFilteredPublicKeyType = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO PublicKeyType (Type) VALUES (@type)";
|
||||||
|
private const string InsertIntoFilteredAcceptEncoding = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO AcceptEncoding (Encoding) VALUES (@encoding)";
|
||||||
|
private const string InsertIntoFilteredALPN = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO ALPN (ALPNValue) VALUES (@alpnValue)";
|
||||||
|
private const string InsertIntoFilteredConnection = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY; PRAGMA journal_mode = MEMORY; INSERT OR IGNORE INTO Connection (ConnectionValue) VALUES (@connectionValue)";
|
||||||
|
|
||||||
|
private const string InsertIntoDiscarded = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" +
|
||||||
|
" PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off;" +
|
||||||
|
" INSERT INTO Discarded (Ip1, Ip2, Ip3, Ip4, ResponseCode)" +
|
||||||
|
" VALUES (@ip1, @ip2, @ip3, @ip4, @responseCode)";
|
||||||
|
|
||||||
|
private const string InsertIntoResume = "PRAGMA synchronous = OFF; PRAGMA temp_store = MEMORY;" +
|
||||||
|
" PRAGMA journal_mode = MEMORY; PRAGMA foreign_keys = off;" +
|
||||||
|
" INSERT INTO Resume (ThreadNumber, StartRange, EndRange, FirstByte, SecondByte, ThirdByte, FourthByte)" +
|
||||||
|
" VALUES (@threadNumber, @startRange, @endRange, @firstByte, @secondByte, @thirdByte, @fourthByte);";
|
||||||
|
|
||||||
private const string ReadUnfilteredStatement = "SELECT * FROM Unfiltered WHERE Id = @id;";
|
private const string ReadUnfilteredStatement = "SELECT * FROM Unfiltered WHERE Id = @id;";
|
||||||
private const string ReadUnfilteredIdsStatement = "SELECT Id FROM Unfiltered WHERE Id != 0 ORDER BY Id DESC LIMIT 1;";
|
private const string ReadUnfilteredIdsStatement = "SELECT Id FROM Unfiltered WHERE Filtered == 0;";
|
||||||
private const string ReadFilteredStatement = "SELECT Title2, Url2 FROM Filtered WHERE (Url2 NOT NULL AND Url2 != '') AND (Title2 NOT NULL AND Title2 != '') ORDER BY Url2 DESC;";
|
private const string ReadFilteredStatement = "SELECT Title2, Url2 FROM Filtered WHERE (Url2 NOT NULL AND Url2 != '') AND (Title2 NOT NULL AND Title2 != '') ORDER BY Url2 DESC;";
|
||||||
private const string ReadFilteredIdsStatement = "SELECT Id FROM Filtered WHERE Id != 0 ORDER BY Id DESC LIMIT 1;";
|
private const string ReadFilteredIdsStatement = "SELECT Id FROM Filtered WHERE Id != 0 ORDER BY Id DESC LIMIT 1;";
|
||||||
|
private const string ReadFilteredIpStatement = "SELECT Ip1, Ip2, Ip3, Ip4 FROM Filtered WHERE Ip1 == @ip1 AND Ip2 == @ip1 AND Ip3 == @ip1 AND Ip4 == @ip1 ORDER BY Ip1 DESC LIMIT 1;";
|
||||||
private const string ReadDiscardedSeqIdsStatement = "SELECT seq FROM sqlite_sequence;";
|
private const string ReadDiscardedSeqIdsStatement = "SELECT seq FROM sqlite_sequence;";
|
||||||
private const string ReadAndDeleteResumeStatement = "SELECT * FROM Resume WHERE ThreadNumber == @threadNumber; DELETE FROM RESUME WHERE ThreadNumber == @threadNumber;";
|
private const string ReadAndDeleteResumeStatement = "SELECT * FROM Resume WHERE ThreadNumber == @threadNumber; DELETE FROM RESUME WHERE ThreadNumber == @threadNumber;";
|
||||||
|
|
||||||
@@ -41,47 +96,114 @@ public class DbHandler
|
|||||||
private bool _pause;
|
private bool _pause;
|
||||||
private bool _paused;
|
private bool _paused;
|
||||||
|
|
||||||
public DbHandler(ConcurrentQueue<QueueItem> contentQueue, ConcurrentQueue<Discarded> discardedQueue)
|
private int _contentWaitTime;
|
||||||
|
private int _discardedWaitTime;
|
||||||
|
|
||||||
|
private readonly string _basePath;
|
||||||
|
|
||||||
|
public DbHandler(ConcurrentQueue<Filtered> filteredQueue,
|
||||||
|
ConcurrentQueue<Discarded> discardedQueue,
|
||||||
|
ConcurrentQueue<UnfilteredQueueItem> unfilteredQueue,
|
||||||
|
ConcurrentQueue<ScannerResumeObject> resumeQueue, string basePath)
|
||||||
{
|
{
|
||||||
_contentQueue = contentQueue;
|
_filteredQueue = filteredQueue;
|
||||||
_discardedQueue = discardedQueue;
|
_discardedQueue = discardedQueue;
|
||||||
|
_unfilteredQueue = unfilteredQueue;
|
||||||
|
_resumeQueue = resumeQueue;
|
||||||
|
|
||||||
|
SetContentWaitTime(100);
|
||||||
|
SetDiscardedWaitTime(10);
|
||||||
|
|
||||||
|
_basePath = basePath;
|
||||||
|
|
||||||
|
_unfilteredConnectionString = $"Data Source={basePath}/Models/mydb.db";
|
||||||
|
_discardedConnectionString = $"Data Source={basePath}/Models/Discarded.db";
|
||||||
|
_filteredConnectionString = $"Data Source={basePath}/Models/Filtered.db";
|
||||||
|
_resumeConnectionString = $"Data Source={basePath}/Models/ScannerResume.db";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartContent()
|
public void SetContentWaitTime(int waitTime)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Content DbHandler started");
|
_contentWaitTime = waitTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetDiscardedWaitTime(int waitTime)
|
||||||
|
{
|
||||||
|
_discardedWaitTime = waitTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnfilteredDbHandler()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Unfiltered DbHandler started");
|
||||||
|
|
||||||
while (!_stop)
|
while (!_stop)
|
||||||
{
|
{
|
||||||
if (_contentQueue.IsEmpty || _pause)
|
if (_unfilteredQueue.IsEmpty || _pause)
|
||||||
{
|
{
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(_contentWaitTime);
|
||||||
_paused = true;
|
_paused = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_contentQueue.TryDequeue(out QueueItem? queueItem);
|
_unfilteredQueue.TryDequeue(out UnfilteredQueueItem queueItem);
|
||||||
|
|
||||||
if (queueItem is null) { continue; }
|
if (queueItem.Operations == Operations.Insert)
|
||||||
|
|
||||||
switch (queueItem.Operations)
|
|
||||||
{
|
{
|
||||||
case Operations.Insert when queueItem.Unfiltered is not null:
|
InsertUnfiltered(queueItem.Unfiltered);
|
||||||
InsertUnfiltered(queueItem.Unfiltered);
|
}
|
||||||
break;
|
|
||||||
case Operations.Insert when queueItem.Filtered is not null:
|
else if (queueItem.Operations == Operations.Update)
|
||||||
InsertFiltered(queueItem.Filtered);
|
{
|
||||||
break;
|
UpdateUnfiltered(queueItem.Unfiltered);
|
||||||
case Operations.Insert when queueItem.ResumeObject is not null:
|
|
||||||
InsertResumeObject(queueItem.ResumeObject);
|
|
||||||
break;
|
|
||||||
case Operations.Update when queueItem.Unfiltered is not null:
|
|
||||||
UpdateUnfiltered(queueItem.Unfiltered);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Content DbHandler stopped.");
|
Console.WriteLine("Unfiltered DbHandler stopped.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FilteredDbHandler()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Filtered DB handler started");
|
||||||
|
|
||||||
|
while (!_stop)
|
||||||
|
{
|
||||||
|
if (_filteredQueue.IsEmpty || _pause)
|
||||||
|
{
|
||||||
|
Thread.Sleep(_contentWaitTime);
|
||||||
|
_paused = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_filteredQueue.TryDequeue(out Filtered? queueItem);
|
||||||
|
|
||||||
|
InsertFiltered(queueItem!);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Filtered DbHandler stopped.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResumeDbHandler()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Resume DB handler started");
|
||||||
|
|
||||||
|
while (!_stop)
|
||||||
|
{
|
||||||
|
if (_resumeQueue.IsEmpty || _pause)
|
||||||
|
{
|
||||||
|
Thread.Sleep(_contentWaitTime);
|
||||||
|
_paused = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_resumeQueue.TryDequeue(out ScannerResumeObject? queueItem);
|
||||||
|
|
||||||
|
if (queueItem is not null)
|
||||||
|
{
|
||||||
|
InsertResumeObject(queueItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Resume DbHandler stopped.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaitHandle[] Start(int threads)
|
public WaitHandle[] Start(int threads)
|
||||||
@@ -100,7 +222,7 @@ public class DbHandler
|
|||||||
|
|
||||||
waitHandles[i] = handle;
|
waitHandles[i] = handle;
|
||||||
|
|
||||||
Thread f = new (RunDiscarded!);
|
Thread f = new (DiscardedDbHandler!);
|
||||||
f.Start(discardedDbHandlerSetting);
|
f.Start(discardedDbHandlerSetting);
|
||||||
|
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
@@ -109,7 +231,7 @@ public class DbHandler
|
|||||||
return waitHandles;
|
return waitHandles;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RunDiscarded(object obj)
|
private void DiscardedDbHandler(object obj)
|
||||||
{
|
{
|
||||||
DiscardedDbHandlerSetting discardedDbHandlerSetting = (DiscardedDbHandlerSetting)obj;
|
DiscardedDbHandlerSetting discardedDbHandlerSetting = (DiscardedDbHandlerSetting)obj;
|
||||||
Console.WriteLine($"Discarded DbHandler started with thread: ({discardedDbHandlerSetting.ThreadId})");
|
Console.WriteLine($"Discarded DbHandler started with thread: ({discardedDbHandlerSetting.ThreadId})");
|
||||||
@@ -120,32 +242,32 @@ public class DbHandler
|
|||||||
{
|
{
|
||||||
if (_discardedQueue.IsEmpty || _pause)
|
if (_discardedQueue.IsEmpty || _pause)
|
||||||
{
|
{
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(_discardedWaitTime);
|
||||||
_paused = true;
|
_paused = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
_discardedQueue.TryDequeue(out Discarded? queueItem);
|
_discardedQueue.TryDequeue(out Discarded queueItem);
|
||||||
|
|
||||||
if (queueItem is null) { continue; }
|
|
||||||
|
|
||||||
InsertDiscarded(queueItem, connectionString);
|
InsertDiscarded(queueItem, connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
discardedDbHandlerSetting.Handle!.Set();
|
discardedDbHandlerSetting.Handle!.Set();
|
||||||
|
|
||||||
Console.WriteLine("Content DbHandler stopped.");
|
Console.WriteLine("Discarded DbHandler stopped.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InsertUnfiltered(Unfiltered unfiltered)
|
private void InsertUnfiltered(Unfiltered unfiltered)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = new(UnfilteredConnectionString);
|
using SqliteConnection connection = new(_unfilteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(InsertStatement, connection);
|
using SqliteCommand command = new(InsertStatement, connection);
|
||||||
|
|
||||||
command.Parameters.AddWithValue("@ip", unfiltered.Ip);
|
command.Parameters.AddWithValue("@ip1", unfiltered.Ip.Ip1);
|
||||||
command.Parameters.AddWithValue("@responseCode", unfiltered.ResponseCode);
|
command.Parameters.AddWithValue("@ip2", unfiltered.Ip.Ip2);
|
||||||
|
command.Parameters.AddWithValue("@ip3", unfiltered.Ip.Ip3);
|
||||||
|
command.Parameters.AddWithValue("@ip4", unfiltered.Ip.Ip4);
|
||||||
command.Parameters.AddWithValue("@port1", unfiltered.Port1);
|
command.Parameters.AddWithValue("@port1", unfiltered.Port1);
|
||||||
command.Parameters.AddWithValue("@port2", unfiltered.Port2);
|
command.Parameters.AddWithValue("@port2", unfiltered.Port2);
|
||||||
command.Parameters.AddWithValue("@filtered", unfiltered.Filtered);
|
command.Parameters.AddWithValue("@filtered", unfiltered.Filtered);
|
||||||
@@ -161,21 +283,94 @@ public class DbHandler
|
|||||||
|
|
||||||
using SqliteCommand command = new(InsertIntoDiscarded, connection);
|
using SqliteCommand command = new(InsertIntoDiscarded, connection);
|
||||||
|
|
||||||
command.Parameters.AddWithValue("@ip", discarded.Ip);
|
command.Parameters.AddWithValue("@ip1", discarded.Ip.Ip1);
|
||||||
|
command.Parameters.AddWithValue("@ip2", discarded.Ip.Ip2);
|
||||||
|
command.Parameters.AddWithValue("@ip3", discarded.Ip.Ip3);
|
||||||
|
command.Parameters.AddWithValue("@ip4", discarded.Ip.Ip4);
|
||||||
command.Parameters.AddWithValue("@responseCode", discarded.ResponseCode);
|
command.Parameters.AddWithValue("@responseCode", discarded.ResponseCode);
|
||||||
_ = command.ExecuteNonQuery();
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
connection.Close();
|
connection.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InsertFiltered(Filtered filtered)
|
private void InsertFiltered(Filtered filtered)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = new(FilteredConnectionString);
|
using SqliteConnection connection = new(_filteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(InsertIntoFiltered, connection);
|
SqliteCommand command = new(InsertIntoFilteredServerType, connection);
|
||||||
|
command.Parameters.AddWithValue("@type", filtered.ServerType1);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
command.Parameters.AddWithValue("@ip", filtered.Ip);
|
command = new(InsertIntoFilteredServerType, connection);
|
||||||
|
command.Parameters.AddWithValue("@type", filtered.ServerType2);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredHttpVersion, connection);
|
||||||
|
command.Parameters.AddWithValue("@version", filtered.HttpVersion1);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredHttpVersion, connection);
|
||||||
|
command.Parameters.AddWithValue("@version", filtered.HttpVersion2);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredCertificateIssuerCountry, connection);
|
||||||
|
command.Parameters.AddWithValue("@country", filtered.CertificateIssuerCountry);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredCertificateOrganizationName, connection);
|
||||||
|
command.Parameters.AddWithValue("@name", filtered.CertificateOrganizationName);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredTlsVersion, connection);
|
||||||
|
command.Parameters.AddWithValue("@version", filtered.TlsVersion);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredCipherSuite, connection);
|
||||||
|
command.Parameters.AddWithValue("@suite", filtered.CipherSuite);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredKeyExchangeAlgorithm, connection);
|
||||||
|
command.Parameters.AddWithValue("@algorithm", filtered.KeyExchangeAlgorithm);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredPublicKeyType, connection);
|
||||||
|
command.Parameters.AddWithValue("@type", filtered.PublicKeyType1);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredPublicKeyType, connection);
|
||||||
|
command.Parameters.AddWithValue("@type", filtered.PublicKeyType2);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredPublicKeyType, connection);
|
||||||
|
command.Parameters.AddWithValue("@type", filtered.PublicKeyType3);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredAcceptEncoding, connection);
|
||||||
|
command.Parameters.AddWithValue("@encoding", filtered.AcceptEncoding1);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredAcceptEncoding, connection);
|
||||||
|
command.Parameters.AddWithValue("@encoding", filtered.AcceptEncoding2);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredALPN, connection);
|
||||||
|
command.Parameters.AddWithValue("@alpnValue", filtered.ALPN);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredConnection, connection);
|
||||||
|
command.Parameters.AddWithValue("@connectionValue", filtered.Connection1);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFilteredConnection, connection);
|
||||||
|
command.Parameters.AddWithValue("@connectionValue", filtered.Connection2);
|
||||||
|
_ = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
command = new(InsertIntoFiltered, connection);
|
||||||
|
command.Parameters.AddWithValue("@ip1", filtered.Ip.Ip1);
|
||||||
|
command.Parameters.AddWithValue("@ip2", filtered.Ip.Ip2);
|
||||||
|
command.Parameters.AddWithValue("@ip3", filtered.Ip.Ip3);
|
||||||
|
command.Parameters.AddWithValue("@ip4", filtered.Ip.Ip4);
|
||||||
command.Parameters.AddWithValue("@port1", filtered.Port1);
|
command.Parameters.AddWithValue("@port1", filtered.Port1);
|
||||||
command.Parameters.AddWithValue("@port2", filtered.Port2);
|
command.Parameters.AddWithValue("@port2", filtered.Port2);
|
||||||
command.Parameters.AddWithValue("@url1", filtered.Url1);
|
command.Parameters.AddWithValue("@url1", filtered.Url1);
|
||||||
@@ -204,14 +399,15 @@ public class DbHandler
|
|||||||
command.Parameters.AddWithValue("@aLPN", filtered.ALPN);
|
command.Parameters.AddWithValue("@aLPN", filtered.ALPN);
|
||||||
command.Parameters.AddWithValue("@connection1", filtered.Connection1);
|
command.Parameters.AddWithValue("@connection1", filtered.Connection1);
|
||||||
command.Parameters.AddWithValue("@connection2", filtered.Connection2);
|
command.Parameters.AddWithValue("@connection2", filtered.Connection2);
|
||||||
|
|
||||||
_ = command.ExecuteNonQuery();
|
_ = command.ExecuteNonQuery();
|
||||||
|
command.Dispose();
|
||||||
|
|
||||||
connection.Close();
|
connection.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InsertResumeObject(ScannerResumeObject resumeObject)
|
private void InsertResumeObject(ScannerResumeObject resumeObject)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = new(ResumeConnectionString);
|
using SqliteConnection connection = new(_resumeConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(InsertIntoResume, connection);
|
using SqliteCommand command = new(InsertIntoResume, connection);
|
||||||
@@ -228,9 +424,9 @@ public class DbHandler
|
|||||||
connection.Close();
|
connection.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateUnfiltered(Unfiltered unfiltered)
|
private void UpdateUnfiltered(Unfiltered unfiltered)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = new(UnfilteredConnectionString);
|
using SqliteConnection connection = new(_unfilteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(UpdateUnfilteredStatement, connection);
|
using SqliteCommand command = new(UpdateUnfilteredStatement, connection);
|
||||||
@@ -241,36 +437,40 @@ public class DbHandler
|
|||||||
connection.Close();
|
connection.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Unfiltered? ReadUnfilteredWithId(long id)
|
public Unfiltered ReadUnfilteredWithId(long id)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = new(UnfilteredConnectionString);
|
using SqliteConnection connection = new(_unfilteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(ReadUnfilteredStatement, connection);
|
using SqliteCommand command = new(ReadUnfilteredStatement, connection);
|
||||||
command.Parameters.AddWithValue("@id", id);
|
command.Parameters.AddWithValue("@id", id);
|
||||||
|
|
||||||
using SqliteDataReader reader = command.ExecuteReader();
|
using SqliteDataReader reader = command.ExecuteReader();
|
||||||
if (!reader.HasRows) return null;
|
if (!reader.HasRows) return new();
|
||||||
|
|
||||||
Unfiltered unfiltered = new();
|
Unfiltered unfiltered = new();
|
||||||
|
Ip ip = new();
|
||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
unfiltered.Id = reader.GetInt32(0);
|
unfiltered.Id = reader.GetInt32(0);
|
||||||
unfiltered.Ip = reader.GetString(1);
|
ip.Ip1 = reader.GetInt32(1);
|
||||||
unfiltered.Port1 = reader.GetInt32(3);
|
ip.Ip2 = reader.GetInt32(2);
|
||||||
unfiltered.Port2 = reader.GetInt32(4);
|
ip.Ip3 = reader.GetInt32(3);
|
||||||
unfiltered.Filtered = reader.GetInt32(5);
|
ip.Ip4 = reader.GetInt32(4);
|
||||||
|
unfiltered.Port1 = reader.GetInt32(5);
|
||||||
|
unfiltered.Port2 = reader.GetInt32(6);
|
||||||
|
unfiltered.Filtered = reader.GetBoolean(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unfiltered.Ip = ip;
|
||||||
|
|
||||||
return unfiltered;
|
return unfiltered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long GetUnfilteredIndexes()
|
public List<long> GetUnfilteredIndexes()
|
||||||
{
|
{
|
||||||
long rowId = 0;
|
using SqliteConnection connection = new(_unfilteredConnectionString);
|
||||||
|
|
||||||
using SqliteConnection connection = new(UnfilteredConnectionString);
|
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(ReadUnfilteredIdsStatement, connection);
|
using SqliteCommand command = new(ReadUnfilteredIdsStatement, connection);
|
||||||
@@ -278,22 +478,24 @@ public class DbHandler
|
|||||||
|
|
||||||
if (!reader.HasRows)
|
if (!reader.HasRows)
|
||||||
{
|
{
|
||||||
return 0;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<long> ids = [];
|
||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
rowId = reader.GetInt64(0);
|
ids.Add(reader.GetInt64(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowId;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long GetFilteredIndexes()
|
public long GetFilteredIndexes()
|
||||||
{
|
{
|
||||||
long rowId = 0;
|
long rowId = 0;
|
||||||
|
|
||||||
using SqliteConnection connection = new(FilteredConnectionString);
|
using SqliteConnection connection = new(_filteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(ReadFilteredIdsStatement, connection);
|
using SqliteCommand command = new(ReadFilteredIdsStatement, connection);
|
||||||
@@ -338,8 +540,54 @@ public class DbHandler
|
|||||||
return rowId;
|
return rowId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetFilteredIp(string ip)
|
public bool FilteredIpExists(Ip ip)
|
||||||
{
|
{
|
||||||
|
using SqliteConnection connection = new(_filteredConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
using SqliteCommand command = new(ReadFilteredIpStatement, connection);
|
||||||
|
command.Parameters.AddWithValue("@ip1", ip.Ip1);
|
||||||
|
command.Parameters.AddWithValue("@ip2", ip.Ip2);
|
||||||
|
command.Parameters.AddWithValue("@ip3", ip.Ip3);
|
||||||
|
command.Parameters.AddWithValue("@ip4", ip.Ip4);
|
||||||
|
|
||||||
|
using SqliteDataReader reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
if (!reader.HasRows)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ip tempIp = new();
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
tempIp.Ip1 = reader.GetInt32(0);
|
||||||
|
tempIp.Ip2 = reader.GetInt32(1);
|
||||||
|
tempIp.Ip3 = reader.GetInt32(2);
|
||||||
|
tempIp.Ip4 = reader.GetInt32(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempIp.Ip1 != ip.Ip1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempIp.Ip2 != ip.Ip2)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempIp.Ip3 != ip.Ip3)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempIp.Ip4 != ip.Ip4)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +595,7 @@ public class DbHandler
|
|||||||
{
|
{
|
||||||
lock (_readFilteredLock)
|
lock (_readFilteredLock)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = new(FilteredConnectionString);
|
using SqliteConnection connection = new(_filteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(ReadFilteredStatement, connection);
|
using SqliteCommand command = new(ReadFilteredStatement, connection);
|
||||||
@@ -377,7 +625,7 @@ public class DbHandler
|
|||||||
{
|
{
|
||||||
lock (_readAndDeleteResumeLock)
|
lock (_readAndDeleteResumeLock)
|
||||||
{
|
{
|
||||||
using SqliteConnection connection = new(ResumeConnectionString);
|
using SqliteConnection connection = new(_resumeConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
using SqliteCommand command = new(ReadAndDeleteResumeStatement, connection);
|
using SqliteCommand command = new(ReadAndDeleteResumeStatement, connection);
|
||||||
@@ -417,21 +665,21 @@ public class DbHandler
|
|||||||
Thread.Sleep(5000); // Just for safety.
|
Thread.Sleep(5000); // Just for safety.
|
||||||
}
|
}
|
||||||
|
|
||||||
SqliteConnection connection = new(DiscardedConnectionString);
|
SqliteConnection connection = new(_discardedConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
SqliteCommand command = new(ReIndexDatabasesStatement, connection);
|
SqliteCommand command = new(ReIndexDatabasesStatement, connection);
|
||||||
_ = command.ExecuteNonQuery();
|
_ = command.ExecuteNonQuery();
|
||||||
connection.Close();
|
connection.Close();
|
||||||
|
|
||||||
connection = new(FilteredConnectionString);
|
connection = new(_filteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
command = new(ReIndexDatabasesStatement, connection);
|
command = new(ReIndexDatabasesStatement, connection);
|
||||||
_ = command.ExecuteNonQuery();
|
_ = command.ExecuteNonQuery();
|
||||||
connection.Close();
|
connection.Close();
|
||||||
|
|
||||||
connection = new(UnfilteredConnectionString);
|
connection = new(_unfilteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
command = new(ReIndexDatabasesStatement, connection);
|
command = new(ReIndexDatabasesStatement, connection);
|
||||||
@@ -456,21 +704,21 @@ public class DbHandler
|
|||||||
Thread.Sleep(5000); // Just for safety.
|
Thread.Sleep(5000); // Just for safety.
|
||||||
}
|
}
|
||||||
|
|
||||||
SqliteConnection connection = new(DiscardedConnectionString);
|
SqliteConnection connection = new(_discardedConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
SqliteCommand command = new(VacuumDatabasesStatement, connection);
|
SqliteCommand command = new(VacuumDatabasesStatement, connection);
|
||||||
_ = command.ExecuteNonQuery();
|
_ = command.ExecuteNonQuery();
|
||||||
connection.Close();
|
connection.Close();
|
||||||
|
|
||||||
connection = new(FilteredConnectionString);
|
connection = new(_filteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
command = new(VacuumDatabasesStatement, connection);
|
command = new(VacuumDatabasesStatement, connection);
|
||||||
_ = command.ExecuteNonQuery();
|
_ = command.ExecuteNonQuery();
|
||||||
connection.Close();
|
connection.Close();
|
||||||
|
|
||||||
connection = new(UnfilteredConnectionString);
|
connection = new(_unfilteredConnectionString);
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
command = new(VacuumDatabasesStatement, connection);
|
command = new(VacuumDatabasesStatement, connection);
|
||||||
@@ -486,9 +734,9 @@ public class DbHandler
|
|||||||
|
|
||||||
private string CreateDiscardedDb(int threadNumber)
|
private string CreateDiscardedDb(int threadNumber)
|
||||||
{
|
{
|
||||||
string databaseName = $"Data Source=../../../../Models/Discarded{threadNumber}.db";
|
string databaseName = $"Data Source={_basePath}/Models/Discarded{threadNumber}.db";
|
||||||
|
|
||||||
const string createStatement = "CREATE TABLE IF NOT EXISTS Discarded (Id INTEGER NOT NULL, Ip TEXT NOT NULL, ResponseCode INTEGER NOT NULL, PRIMARY KEY(Id AUTOINCREMENT))";
|
const string createStatement = "CREATE TABLE IF NOT EXISTS Discarded (Id INTEGER NOT NULL, Ip1 INTEGER NOT NULL, Ip2 INTEGER NOT NULL, Ip3 INTEGER NOT NULL, Ip4 INTEGER NOT NULL, ResponseCode INTEGER NOT NULL, PRIMARY KEY(Id AUTOINCREMENT))";
|
||||||
|
|
||||||
_discardedConnectionStrings.Add(databaseName);
|
_discardedConnectionStrings.Add(databaseName);
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
using MessagePack;
|
|
||||||
|
|
||||||
namespace Models.Model.Backend;
|
namespace Models.Model.Backend;
|
||||||
|
|
||||||
[MessagePackObject]
|
|
||||||
public struct DatabaseSizes
|
public struct DatabaseSizes
|
||||||
{
|
{
|
||||||
[Key(0)]
|
|
||||||
public double DiscardedDbSize { get; set; }
|
public double DiscardedDbSize { get; set; }
|
||||||
|
|
||||||
[Key(1)]
|
|
||||||
public double FilteredDbSize { get; set; }
|
public double FilteredDbSize { get; set; }
|
||||||
|
|
||||||
[Key(2)]
|
|
||||||
public double MyDbSize { get; set; }
|
public double MyDbSize { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
namespace Models.Model.Backend;
|
namespace Models.Model.Backend;
|
||||||
|
|
||||||
public class Discarded
|
public struct Discarded
|
||||||
{
|
{
|
||||||
public string Ip { get; set; } = "";
|
public Ip Ip { get; set; }
|
||||||
|
|
||||||
public int ResponseCode { get; set; }
|
public int ResponseCode { get; set; }
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ namespace Models.Model.Backend;
|
|||||||
|
|
||||||
public class Filtered
|
public class Filtered
|
||||||
{
|
{
|
||||||
public string Ip { get; set; } = "";
|
public Ip Ip { get; set; }
|
||||||
public string Title1 { get; set; } = "";
|
public string Title1 { get; set; } = "";
|
||||||
public string Title2 { get; set; } = "";
|
public string Title2 { get; set; } = "";
|
||||||
public string Description1 { get; set; } = "";
|
public string Description1 { get; set; } = "";
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
namespace Models.Model.Backend;
|
||||||
|
|
||||||
|
public struct Ip
|
||||||
|
{
|
||||||
|
public int Ip1 { get; set; }
|
||||||
|
|
||||||
|
public int Ip2 { get; set; }
|
||||||
|
|
||||||
|
public int Ip3 { get; set; }
|
||||||
|
|
||||||
|
public int Ip4 { get; set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{Ip1}.{Ip2}.{Ip3}.{Ip4}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,5 +4,4 @@ public enum Operations
|
|||||||
{
|
{
|
||||||
Insert,
|
Insert,
|
||||||
Update,
|
Update,
|
||||||
Optimize,
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace Models.Model.Backend;
|
|
||||||
|
|
||||||
public class QueueItem
|
|
||||||
{
|
|
||||||
public Unfiltered? Unfiltered { get; init; }
|
|
||||||
public Filtered? Filtered { get; init; }
|
|
||||||
public ScannerResumeObject? ResumeObject { get; init; }
|
|
||||||
public Operations Operations { get; init; }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Models.Model.Backend;
|
||||||
|
|
||||||
|
public enum RuntimeVariable
|
||||||
|
{
|
||||||
|
DbContent,
|
||||||
|
DbDiscarded,
|
||||||
|
ContentFilter,
|
||||||
|
ScannerTimeout
|
||||||
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
namespace Models.Model.Backend;
|
namespace Models.Model.Backend;
|
||||||
|
|
||||||
public class Unfiltered
|
public struct Unfiltered
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public string Ip { get; set; } = "";
|
public Ip Ip { get; set; }
|
||||||
|
|
||||||
public int ResponseCode { get; init; }
|
|
||||||
|
|
||||||
public int Port1 { get; set; }
|
public int Port1 { get; set; }
|
||||||
|
|
||||||
public int Port2 { get; set; }
|
public int Port2 { get; set; }
|
||||||
|
|
||||||
public int Filtered { get; set; }
|
public bool Filtered { get; set; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Models.Model.Backend;
|
||||||
|
|
||||||
|
public struct UnfilteredQueueItem
|
||||||
|
{
|
||||||
|
public Unfiltered Unfiltered { get; init; }
|
||||||
|
public Operations Operations { get; init; }
|
||||||
|
}
|
||||||
@@ -7,4 +7,5 @@ public enum CommunicationCommand
|
|||||||
StopScanning,
|
StopScanning,
|
||||||
DbReindex,
|
DbReindex,
|
||||||
DbVacuum,
|
DbVacuum,
|
||||||
|
ChangeRuntimeVariable,
|
||||||
}
|
}
|
||||||
+10
-6
@@ -1,13 +1,17 @@
|
|||||||
using MessagePack;
|
|
||||||
|
|
||||||
namespace Models.Model.External;
|
namespace Models.Model.External;
|
||||||
|
|
||||||
[MessagePackObject]
|
//[MessagePackObject]
|
||||||
public class CommunicationObject
|
public class CommunicationObject
|
||||||
{
|
{
|
||||||
[Key(0)]
|
//[Key(0)]
|
||||||
public CommunicationCommand Command { get; set; }
|
public CommunicationCommand Command { get; set; }
|
||||||
|
|
||||||
[Key(1)]
|
//[Key(1)]
|
||||||
public string? SearchTerm { get; set; }
|
public string? SearchTerm { get; set; } = "";
|
||||||
|
|
||||||
|
//[Key(2)]
|
||||||
|
public string? Variable { get; set; } = "";
|
||||||
|
|
||||||
|
//[Key(3)]
|
||||||
|
public string? VariableValue { get; set; } = "";
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
using MessagePack;
|
|
||||||
|
|
||||||
namespace Models.Model.External;
|
namespace Models.Model.External;
|
||||||
|
|
||||||
[MessagePackObject]
|
|
||||||
public class CommunicationResult
|
public class CommunicationResult
|
||||||
{
|
{
|
||||||
[Key(0)]
|
|
||||||
public List<SearchResult?>? Result { get; set; }
|
public List<SearchResult?>? Result { get; set; }
|
||||||
|
|
||||||
[Key(1)]
|
|
||||||
public ScanningStatus? Status { get; set; }
|
public ScanningStatus? Status { get; set; }
|
||||||
}
|
}
|
||||||
-11
@@ -1,29 +1,18 @@
|
|||||||
using MessagePack;
|
|
||||||
using Models.Model.Backend;
|
|
||||||
|
|
||||||
namespace Models.Model.External;
|
namespace Models.Model.External;
|
||||||
|
|
||||||
[MessagePackObject]
|
|
||||||
public struct ScanningStatus
|
public struct ScanningStatus
|
||||||
{
|
{
|
||||||
[Key(0)]
|
|
||||||
public float PercentageOfIpv4Scanned { get; set; }
|
public float PercentageOfIpv4Scanned { get; set; }
|
||||||
|
|
||||||
[Key(1)]
|
|
||||||
public long TotalFiltered { get; set; }
|
public long TotalFiltered { get; set; }
|
||||||
|
|
||||||
[Key(2)]
|
|
||||||
public long AmountOfIpv4Left { get; set; }
|
public long AmountOfIpv4Left { get; set; }
|
||||||
|
|
||||||
[Key(3)]
|
|
||||||
public long TotalDiscarded { get; set; }
|
public long TotalDiscarded { get; set; }
|
||||||
|
|
||||||
[Key(4)]
|
|
||||||
public double DiscardedDbSize { get; set; }
|
public double DiscardedDbSize { get; set; }
|
||||||
|
|
||||||
[Key(5)]
|
|
||||||
public double FilteredDbSize { get; set; }
|
public double FilteredDbSize { get; set; }
|
||||||
|
|
||||||
[Key(6)]
|
|
||||||
public double MyDbSize { get; set; }
|
public double MyDbSize { get; set; }
|
||||||
}
|
}
|
||||||
@@ -7,13 +7,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MessagePack" Version="3.0.238-rc.1" />
|
|
||||||
<PackageReference Include="MessagePack.Annotations" Version="3.0.238-rc.1" />
|
|
||||||
<PackageReference Include="MessagePackAnalyzer" Version="3.0.238-rc.1">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.10" />
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.10" />
|
||||||
<PackageReference Include="SQLite" Version="3.13.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cbackend/@EntryIndexedValue">False</s:Boolean>
|
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cinternal/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
||||||
Binary file not shown.
@@ -0,0 +1,112 @@
|
|||||||
|
VACUUM;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "ServerType" (
|
||||||
|
"ServerId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Type" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "HttpVersion" (
|
||||||
|
"HttpId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Version" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "CertificateIssuerCountry" (
|
||||||
|
"CertificateIssuerId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Country" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "CertificateOrganizationName" (
|
||||||
|
"CertificateOrganizationId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Name" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "TlsVersion" (
|
||||||
|
"TlsId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Version" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "CipherSuite" (
|
||||||
|
"CipherId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Suite" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "KeyExchangeAlgorithm" (
|
||||||
|
"KeyExchangeId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Algorithm" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "PublicKeyType" (
|
||||||
|
"PublicKeyId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Type" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "AcceptEncoding" (
|
||||||
|
"AcceptId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"Encoding" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "ALPN" (
|
||||||
|
"ALPNId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"ALPNValue" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "Connection" (
|
||||||
|
"ConnectionId" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"ConnectionValue" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP TABLE Filtered;
|
||||||
|
|
||||||
|
CREATE TABLE "Filtered" (
|
||||||
|
"Id" INTEGER NOT NULL,
|
||||||
|
"Ip1" INTEGER NOT NULL,
|
||||||
|
"Ip2" INTEGER NOT NULL,
|
||||||
|
"Ip3" INTEGER NOT NULL,
|
||||||
|
"Ip4" INTEGER NOT NULL,
|
||||||
|
"Port1" INTEGER NOT NULL,
|
||||||
|
"Port2" INTEGER NOT NULL,
|
||||||
|
"Title1" TEXT NOT NULL,
|
||||||
|
"Title2" TEXT NOT NULL,
|
||||||
|
"Description1" TEXT NOT NULL,
|
||||||
|
"Description2" TEXT NOT NULL,
|
||||||
|
"Url1" TEXT NOT NULL,
|
||||||
|
"Url2" TEXT NOT NULL,
|
||||||
|
"ServerType1" INTEGER NOT NULL,
|
||||||
|
"ServerType2" INTEGER NOT NULL,
|
||||||
|
"RobotsTXT1" TEXT NOT NULL,
|
||||||
|
"RobotsTXT2" TEXT NOT NULL,
|
||||||
|
"HttpVersion1" INTEGER NOT NULL,
|
||||||
|
"HttpVersion2" INTEGER NOT NULL,
|
||||||
|
"CertificateIssuerCountry" INTEGER NOT NULL,
|
||||||
|
"CertificateOrganizationName" INTEGER NOT NULL,
|
||||||
|
"IpV6" TEXT NOT NULL,
|
||||||
|
"TlsVersion" INTEGER NOT NULL,
|
||||||
|
"CipherSuite" INTEGER NOT NULL,
|
||||||
|
"KeyExchangeAlgorithm" INTEGER NOT NULL,
|
||||||
|
"PublicKeyType1" INTEGER NOT NULL,
|
||||||
|
"PublicKeyType2" INTEGER NOT NULL,
|
||||||
|
"PublicKeyType3" INTEGER NOT NULL,
|
||||||
|
"AcceptEncoding1" INTEGER NOT NULL,
|
||||||
|
"AcceptEncoding2" INTEGER NOT NULL,
|
||||||
|
"ALPN" INTEGER NOT NULL,
|
||||||
|
"Connection1" INTEGER NOT NULL,
|
||||||
|
"Connection2" INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY("Id" AUTOINCREMENT),
|
||||||
|
FOREIGN KEY("ALPN") REFERENCES "ALPN"("ALPNId"),
|
||||||
|
FOREIGN KEY("AcceptEncoding1") REFERENCES "AcceptEncoding"("AcceptId"),
|
||||||
|
FOREIGN KEY("AcceptEncoding2") REFERENCES "AcceptEncoding"("AcceptId"),
|
||||||
|
FOREIGN KEY("CertificateIssuerCountry") REFERENCES "CertificateIssuerCountry"("CertificateIssuerId"),
|
||||||
|
FOREIGN KEY("CertificateOrganizationName") REFERENCES "CertificateOrganizationName"("CertificateOrganizationId"),
|
||||||
|
FOREIGN KEY("CipherSuite") REFERENCES "CipherSuite"("CipherId"),
|
||||||
|
FOREIGN KEY("Connection1") REFERENCES "Connection"("ConnectionId"),
|
||||||
|
FOREIGN KEY("Connection2") REFERENCES "Connection"("ConnectionId"),
|
||||||
|
FOREIGN KEY("HttpVersion1") REFERENCES "HttpVersion"("HttpId"),
|
||||||
|
FOREIGN KEY("HttpVersion2") REFERENCES "HttpVersion"("HttpId"),
|
||||||
|
FOREIGN KEY("KeyExchangeAlgorithm") REFERENCES "KeyExchangeAlgorithm"("KeyExchangeId"),
|
||||||
|
FOREIGN KEY("PublicKeyType1") REFERENCES "PublicKeyType"("PublicKeyId"),
|
||||||
|
FOREIGN KEY("PublicKeyType2") REFERENCES "PublicKeyType"("PublicKeyId"),
|
||||||
|
FOREIGN KEY("PublicKeyType3") REFERENCES "PublicKeyType"("PublicKeyId"),
|
||||||
|
FOREIGN KEY("ServerType1") REFERENCES "ServerType"("ServerId"),
|
||||||
|
FOREIGN KEY("ServerType2") REFERENCES "ServerType"("ServerId"),
|
||||||
|
FOREIGN KEY("TlsVersion") REFERENCES "TlsVersion"("TlsId")
|
||||||
|
)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
DROP TABLE Unfiltered;
|
||||||
|
|
||||||
|
CREATE TABLE "Unfiltered" (
|
||||||
|
"Id" INTEGER NOT NULL,
|
||||||
|
"Ip1" INTEGER NOT NULL,
|
||||||
|
"Ip2" INTEGER NOT NULL,
|
||||||
|
"Ip3" INTEGER NOT NULL,
|
||||||
|
"Ip4" INTEGER NOT NULL,
|
||||||
|
"Port1" INTEGER NOT NULL,
|
||||||
|
"Port2" INTEGER NOT NULL,
|
||||||
|
"Filtered" INTEGER NOT NULL,
|
||||||
|
CONSTRAINT "PK_Unfiltered" PRIMARY KEY("Id" AUTOINCREMENT)
|
||||||
|
)
|
||||||
Binary file not shown.
+38
-12
@@ -1,10 +1,11 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using MessagePack;
|
using AspNetCoreRateLimit;
|
||||||
using Microsoft.AspNetCore.Cors.Infrastructure;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Models.Model.External;
|
using Models.Model.External;
|
||||||
using NetMQ;
|
using NetMQ;
|
||||||
using NetMQ.Sockets;
|
using NetMQ.Sockets;
|
||||||
|
const string myAllowSpecificOrigins = "_myAllowSpecificOrigins";
|
||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
|
WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
|
||||||
|
|
||||||
@@ -15,16 +16,40 @@ builder.Services.ConfigureHttpJsonOptions(options =>
|
|||||||
|
|
||||||
builder.Services.AddCors(options =>
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("CorsPolicy", x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().Build());
|
options.AddPolicy(name: myAllowSpecificOrigins, x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add memory cache and rate limiting services
|
||||||
|
builder.Services.AddMemoryCache();
|
||||||
|
builder.Services.Configure<IpRateLimitOptions>(options =>
|
||||||
|
{
|
||||||
|
options.GeneralRules =
|
||||||
|
[
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Endpoint = "*", // Apply to all endpoints
|
||||||
|
Period = "10s", // Rate limiting window of 10 second
|
||||||
|
Limit = 5 // Maximum 5 requests per 10 seconds
|
||||||
|
}
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddInMemoryRateLimiting();
|
||||||
|
builder.Services.AddSingleton<IRateLimitConfiguration, RateLimitConfiguration>();
|
||||||
|
|
||||||
WebApplication app = builder.Build();
|
WebApplication app = builder.Build();
|
||||||
|
|
||||||
app.UseCors();
|
app.UseForwardedHeaders(new()
|
||||||
|
{
|
||||||
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.UseIpRateLimiting(); // Apply IP-based rate limiting middleware
|
||||||
|
|
||||||
|
app.UseCors(myAllowSpecificOrigins);
|
||||||
|
|
||||||
RouteGroupBuilder progressApi = app.MapGroup("/progress");
|
RouteGroupBuilder progressApi = app.MapGroup("/progress");
|
||||||
progressApi.AllowAnonymous();
|
|
||||||
progressApi.DisableAntiforgery();
|
|
||||||
progressApi.MapGet("/", () =>
|
progressApi.MapGet("/", () =>
|
||||||
{
|
{
|
||||||
CommunicationObject communicationObject = new()
|
CommunicationObject communicationObject = new()
|
||||||
@@ -32,7 +57,7 @@ progressApi.MapGet("/", () =>
|
|||||||
Command = CommunicationCommand.GetScanningProgress
|
Command = CommunicationCommand.GetScanningProgress
|
||||||
};
|
};
|
||||||
|
|
||||||
byte[] bytes = MessagePackSerializer.Serialize(communicationObject);
|
byte[] bytes = JsonSerializer.SerializeToUtf8Bytes(communicationObject);
|
||||||
|
|
||||||
using RequestSocket client = new();
|
using RequestSocket client = new();
|
||||||
client.Connect("tcp://127.0.0.1:5556");
|
client.Connect("tcp://127.0.0.1:5556");
|
||||||
@@ -40,18 +65,18 @@ progressApi.MapGet("/", () =>
|
|||||||
byte[] msg = client.ReceiveFrameBytes();
|
byte[] msg = client.ReceiveFrameBytes();
|
||||||
client.Close();
|
client.Close();
|
||||||
|
|
||||||
return MessagePackSerializer.Deserialize<ScanningStatus>(msg, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray));
|
return JsonSerializer.Deserialize<ScanningStatus>(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
RouteGroupBuilder searchApi = app.MapGroup("/search");
|
RouteGroupBuilder searchApi = app.MapGroup("/search");
|
||||||
progressApi.AllowAnonymous();
|
|
||||||
searchApi.MapGet("/{term}", (string term) =>
|
searchApi.MapGet("/{term}", (string term) =>
|
||||||
{
|
{
|
||||||
CommunicationObject communicationObject = new();
|
CommunicationObject communicationObject = new();
|
||||||
communicationObject.Command = CommunicationCommand.GetSearches;
|
communicationObject.Command = CommunicationCommand.GetSearches;
|
||||||
communicationObject.SearchTerm = term;
|
communicationObject.SearchTerm = term;
|
||||||
|
|
||||||
byte[] bytes = MessagePackSerializer.Serialize(communicationObject);
|
byte[] bytes = JsonSerializer.SerializeToUtf8Bytes(communicationObject);
|
||||||
|
|
||||||
using RequestSocket client = new();
|
using RequestSocket client = new();
|
||||||
client.Connect("tcp://127.0.0.1:5556");
|
client.Connect("tcp://127.0.0.1:5556");
|
||||||
@@ -61,11 +86,12 @@ searchApi.MapGet("/{term}", (string term) =>
|
|||||||
|
|
||||||
return JsonSerializer.Deserialize<SearchResults?>(msg);
|
return JsonSerializer.Deserialize<SearchResults?>(msg);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
[JsonSerializable(typeof(ScanningStatus))]
|
[JsonSerializable(typeof(ScanningStatus))]
|
||||||
[JsonSerializable(typeof(SearchResults))]
|
//[JsonSerializable(typeof(SearchResults))]
|
||||||
|
[JsonSerializable(typeof(CommunicationObject))]
|
||||||
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
internal partial class AppJsonSerializerContext : JsonSerializerContext
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
+2
-7
@@ -5,16 +5,11 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<InvariantGlobalization>true</InvariantGlobalization>
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
<PublishAot>true</PublishAot>
|
<PublishAot>false</PublishAot>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MessagePack" Version="3.0.238-rc.1" />
|
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
|
||||||
<PackageReference Include="MessagePack.Annotations" Version="3.0.238-rc.1" />
|
|
||||||
<PackageReference Include="MessagePackAnalyzer" Version="3.0.238-rc.1">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="NetMQ" Version="4.0.1.13" />
|
<PackageReference Include="NetMQ" Version="4.0.1.13" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Warning",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003A02000006pdb6Low_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003FILViewer_003Fd17d4b69379a42eb90f15b17ef6c846a5400_003F39_003F1eeed291_003F02000006pdb6Low_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003A0200000Cpdb6Low_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003FILViewer_003Fb53c196a821648e4ae3b142a6ae58d7b9400_003Fa8_003F21a43479_003F0200000Cpdb6Low_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003A02000007pdb1Low_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003FILViewer_003F096da63313a8436fb75089601a728c765200_003Fbb_003Ff6383783_003F02000007pdb1Low_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003A02000011pdb3Low_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003FILViewer_003F7c3ed02c2ce44598b7f304f8ac45e58f8600_003F6d_003F99b875d1_003F02000011pdb3Low_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003A02000007pdb1Low_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003FILViewer_003F357247e747614c8297021dd08d79da3d5200_003Ff2_003Fc4ae8c87_003F02000007pdb1Low_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADirectoryInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fe4ec446cfe0489bc3ef68a45c6766d183e999ebdc657e94fb1ad059de2bb9_003FDirectoryInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003A02000010pdb3Low_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003FILViewer_003F80cf8253b0c2409096d0c0e368300af28200_003Fdd_003F8098fc19_003F02000010pdb3Low_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHttpResponseMessage_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F85e97f467d698c9e98eae9e3a1b39d58541173e57992d8f7111eabdd3db3526_003FHttpResponseMessage_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003A02000011pdb4Low_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003FILViewer_003F1f6cfdd1e3a14f6390237f6ab98b06af8000_003F0d_003Febdca535_003F02000011pdb4Low_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARateLimitRule_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F8fbca8b1bca27d45830c443b2c773d979015ea216430366f285514a39fc0b9_003FRateLimitRule_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAttributes_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F9a4cb3a98df697f884fa5f45bc79e4291fa3e948c7f42560e14678e12055e_003FAttributes_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F693e634d7742afaf486acd69d84fe2a9e1ee1b11ba84f29cd1d67668d20dd59_003FThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AAttribute_002ECoreCLR_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fbb9be2cb8efb72a7d2286fbdd10a293b55b3e2a912f49fac6a7719673268e4b_003FAttribute_002ECoreCLR_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConcurrentQueue_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fb049a159646b52d2dd6ced21de315f79dff86421243e94ffd4f29c6f7e4df25_003FConcurrentQueue_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConsole_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F2ccd2056ec55b7b67558d52e32a887ed5ac7e346fc429b218c188d0a99cb5be_003FConsole_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFormatters_002EMessagePack_002EGeneratedMessagePackResolver_002EModels_002EModel_002EExternal_002ESearchResultsFormatter_002Eg_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F99b5d033f8bfb58a6a753ca88a3d956f2228bd48_003FFormatters_002EMessagePack_002EGeneratedMessagePackResolver_002EModels_002EModel_002EExternal_002ESearchResultsFormatter_002Eg_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFuture_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F13cbfe6856867dd1ed4e39575e46d816dae2a146a8ceec8f76b5897f5e0fe_003FFuture_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHttpContent_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F5a55e5df9328b51021ba85b8f12ff49eca8772dba9772c0d61d5e28edf255c_003FHttpContent_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AHttpMethodAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F2e4732e712a98f9ac0d080ac68669b3db6d98781e0d5ad89886cb6bcc890b18_003FHttpMethodAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIFormatterResolver_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fc7d856f45ddf907f9face6c2bdba7836cc70fed4bb2b8ebd83ee6917584af3_003FIFormatterResolver_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIOThread_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F125fae6d49819da7be4fb21fbb4a936a7ec325971cf9264a24af55bf7111ad8_003FIOThread_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIPStatus_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8fe420eaf60c4dfca87ce1d5f1cdfa4816200_003Fbd_003F71bcce16_003FIPStatus_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMessagePackSerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fe5f8b0187e62d74a4b9fefd657c192dab367bb342ef5ffbd90a4ed2ea428ec7a_003FMessagePackSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APingOptions_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F77bf2fbffc5491eadd62f1dbebc233798cd7fcb9b39ab7ee3bb35519f4d94ecc_003FPingOptions_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APing_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F3080b18e3637ea741b5b65abd6aee06e41494a82a58b3e2ed87d4ddb5cc62_003FPing_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APing_002EUnix_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F8d57f5f5fd3290d6a89a5b767ad89988dd893c988eba430cd461b8b88d7ad9d_003FPing_002EUnix_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATask_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F35f3a54f5acb408a3e219b2de039f1a39557b7e4515f11238cba07b60c0ce_003FTask_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATextWriter_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fdda89b2ed0975050b6847325357a756a5866a5435e3ddb4feff535ba36facb7_003FTextWriter_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Nuxt dev/build outputs
|
||||||
|
.output
|
||||||
|
.data
|
||||||
|
.nuxt
|
||||||
|
.nitro
|
||||||
|
.cache
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Node dependencies
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Misc
|
||||||
|
.DS_Store
|
||||||
|
.fleet
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Local env files
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
# Nuxt Minimal Starter
|
||||||
|
|
||||||
|
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Make sure to install dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm install
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn install
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Development Server
|
||||||
|
|
||||||
|
Start the development server on `http://localhost:3000`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm dev
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn dev
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Production
|
||||||
|
|
||||||
|
Build the application for production:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm build
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn build
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun run build
|
||||||
|
```
|
||||||
|
|
||||||
|
Locally preview production build:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# npm
|
||||||
|
npm run preview
|
||||||
|
|
||||||
|
# pnpm
|
||||||
|
pnpm preview
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn preview
|
||||||
|
|
||||||
|
# bun
|
||||||
|
bun run preview
|
||||||
|
```
|
||||||
|
|
||||||
|
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<NuxtRouteAnnouncer />
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<NuxtPage />
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||||||
|
export default defineNuxtConfig({
|
||||||
|
compatibilityDate: '2024-12-16',
|
||||||
|
ssr: true,
|
||||||
|
|
||||||
|
devtools: { enabled: true },
|
||||||
|
css: ['@/assets/css/main.css'],
|
||||||
|
|
||||||
|
postcss: {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
routeRules: {
|
||||||
|
"/": {isr: true},
|
||||||
|
"/progress": {isr: true},
|
||||||
|
},
|
||||||
|
|
||||||
|
modules: ['@nuxtjs/tailwindcss'],
|
||||||
|
})
|
||||||
Generated
+10904
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "nuxt-app",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"build": "nuxt build",
|
||||||
|
"dev": "nuxt dev",
|
||||||
|
"generate": "nuxt generate",
|
||||||
|
"preview": "nuxt preview",
|
||||||
|
"postinstall": "nuxt prepare"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@nuxtjs/partytown": "^1.5.0",
|
||||||
|
"nuxt": "^3.14.1592",
|
||||||
|
"vue": "latest",
|
||||||
|
"vue-router": "latest"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@nuxtjs/tailwindcss": "^6.12.2",
|
||||||
|
"autoprefixer": "^10.4.20",
|
||||||
|
"postcss": "^8.4.49",
|
||||||
|
"tailwindcss": "^3.4.16"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const route = useRoute()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h1>Nuxt Routing set up successfully!</h1>
|
||||||
|
<p>Current route: {{ route.path }}</p>
|
||||||
|
<a href="https://nuxt.com/docs/getting-started/routing" target="_blank">Learn more about Nuxt Routing</a>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { fetchWithCache } from '~/utils/cacheUtil';
|
||||||
|
|
||||||
|
const data = ref<ProgressType | null>(null);
|
||||||
|
const loading = ref<boolean>(true);
|
||||||
|
const error = ref<string | null>(null);
|
||||||
|
|
||||||
|
const fetchMyData = async () => {
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
|
||||||
|
// Use the caching utility
|
||||||
|
data.value = await fetchWithCache<ProgressType>(
|
||||||
|
'Progress',
|
||||||
|
async () => {
|
||||||
|
const response = await fetch('https://proxy.rbwr.dk/progress');
|
||||||
|
if (!response.ok) throw new Error('API fetch failed');
|
||||||
|
return (await response.json()) as ProgressType;
|
||||||
|
},
|
||||||
|
5 // Cache max age in seconds
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
error.value = (err as Error).message;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchMyData();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="h-screen grid place-items-center">
|
||||||
|
<div v-if="data">
|
||||||
|
<table class="table-auto border-gray-300">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="px-4 py-2">Metric</th>
|
||||||
|
<th class="px-4 py-2">Value</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody >
|
||||||
|
<tr>
|
||||||
|
<td class="px-4 py-2">Percentage of Ipv4 scanned</td>
|
||||||
|
<td class="px-4 py-2">{{data.percentageOfIpv4Scanned}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="px-4 py-2">Total filtered</td>
|
||||||
|
<td class="px-4 py-2">{{data.totalFiltered}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="px-4 py-2">Total Discarded</td>
|
||||||
|
<td class="px-4 py-2">{{data.totalDiscarded}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="px-4 py-2">Amount of Ipv4 left</td>
|
||||||
|
<td class="px-4 py-2">{{data.amountOfIpv4Left}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="px-4 py-2">Discarded db size</td>
|
||||||
|
<td class="px-4 py-2">{{data.discardedDbSize}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="px-4 py-2">Filtered db size</td>
|
||||||
|
<td class="px-4 py-2">{{data.filteredDbSize}}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="px-4 py-2">Unfiltered db size</td>
|
||||||
|
<td class="px-4 py-2">{{data.myDbSize}}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../.nuxt/tsconfig.server.json"
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
export default {
|
||||||
|
content: [
|
||||||
|
"./components/**/*.{js,vue,ts}",
|
||||||
|
"./layouts/**/*.vue",
|
||||||
|
"./pages/**/*.vue",
|
||||||
|
"./plugins/**/*.{js,ts}",
|
||||||
|
"./app.vue",
|
||||||
|
"./error.vue",
|
||||||
|
],
|
||||||
|
theme: {
|
||||||
|
extend: {},
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
// https://nuxt.com/docs/guide/concepts/typescript
|
||||||
|
"extends": "./.nuxt/tsconfig.json"
|
||||||
|
}
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
interface ProgressType {
|
||||||
|
percentageOfIpv4Scanned: number; // assuming this is a number
|
||||||
|
totalFiltered: bigint;
|
||||||
|
amountOfIpv4Left: bigint;
|
||||||
|
totalDiscarded: bigint;
|
||||||
|
discardedDbSize: bigint;
|
||||||
|
filteredDbSize: bigint;
|
||||||
|
myDbSize: bigint;
|
||||||
|
}
|
||||||
|
|
||||||
|
type CacheEntry<T> = {
|
||||||
|
data: T;
|
||||||
|
timestamp: number;
|
||||||
|
};
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
export function fetchWithCache<Type>(
|
||||||
|
cacheKey: string,
|
||||||
|
fetchFunction: () => Promise<Type>,
|
||||||
|
maxAge: number = 5 // 30 seconds
|
||||||
|
): Promise<Type> {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
const cachedData = localStorage.getItem(cacheKey);
|
||||||
|
|
||||||
|
if (cachedData) {
|
||||||
|
const { data, timestamp } = JSON.parse(cachedData) as CacheEntry<Type>;
|
||||||
|
const now = Date.now();
|
||||||
|
const ageInSeconds = (now - timestamp) / 1000;
|
||||||
|
|
||||||
|
// Check if cache is still valid
|
||||||
|
if (ageInSeconds < maxAge) {
|
||||||
|
return resolve(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache is missing or expired, fetch fresh data
|
||||||
|
const freshData = await fetchFunction();
|
||||||
|
const cacheEntry: CacheEntry<Type> = {
|
||||||
|
data: freshData,
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
localStorage.setItem(cacheKey, JSON.stringify(cacheEntry));
|
||||||
|
resolve(freshData);
|
||||||
|
} catch (error) {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user