Skip to content

Commit 7d716f7

Browse files
authored
Ipban client feature (#339)
* Add IPBanClient * Fix to logfiletest, file argument
1 parent e518fd0 commit 7d716f7

File tree

9 files changed

+358
-28
lines changed

9 files changed

+358
-28
lines changed

IPBan.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
2626
testEnvironments.json = testEnvironments.json
2727
EndProjectSection
2828
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPBanClient", "IPBanClient\IPBanClient.csproj", "{0810D0FB-8E69-4E85-9392-A7B5A2F13F5E}"
30+
EndProject
2931
Global
3032
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3133
Debug|Any CPU = Debug|Any CPU
@@ -44,6 +46,10 @@ Global
4446
{9940E02E-7136-4357-BA2E-157839F60CED}.Debug|Any CPU.Build.0 = Debug|Any CPU
4547
{9940E02E-7136-4357-BA2E-157839F60CED}.Release|Any CPU.ActiveCfg = Release|Any CPU
4648
{9940E02E-7136-4357-BA2E-157839F60CED}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{0810D0FB-8E69-4E85-9392-A7B5A2F13F5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{0810D0FB-8E69-4E85-9392-A7B5A2F13F5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{0810D0FB-8E69-4E85-9392-A7B5A2F13F5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{0810D0FB-8E69-4E85-9392-A7B5A2F13F5E}.Release|Any CPU.Build.0 = Release|Any CPU
4753
EndGlobalSection
4854
GlobalSection(SolutionProperties) = preSolution
4955
HideSolutionNode = FALSE

IPBan/IPBan.csproj.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<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">
2+
<s:String x:Key="/Default/CodeEditing/Localization/Localizable/@EntryValue">No</s:String></wpf:ResourceDictionary>

IPBan/IPBanMain.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
using System;
2828
using System.Threading;
2929
using System.Threading.Tasks;
30+
using DigitalRuby.IPBanCore.Core.Utility;
3031

3132
namespace DigitalRuby.IPBan
3233
{
@@ -42,8 +43,9 @@ public static class IPBanApp
4243
/// <returns>Task</returns>
4344
public static async Task Main(string[] args)
4445
{
45-
if (ProcessCommandLine(args))
46+
if (args.Length != 0)
4647
{
48+
await CommandLineProcessor.ProcessAsync(args);
4749
return;
4850
}
4951

@@ -62,31 +64,5 @@ await IPBanServiceRunner.MainService(args, (CancellationToken cancelToken) =>
6264
});
6365
}
6466

65-
private static bool ProcessCommandLine(string[] args)
66-
{
67-
if (args.Length != 0)
68-
{
69-
if (args[0].Contains("info", StringComparison.OrdinalIgnoreCase))
70-
{
71-
Logger.Warn("System info: {0}", OSUtility.OSString());
72-
return true;
73-
}
74-
else if (args[0].Contains("logfiletest", StringComparison.OrdinalIgnoreCase))
75-
{
76-
if (args.Length != 2)
77-
{
78-
Console.WriteLine("Usage: param file with lines of log-filename regex-failure regex-failure-timestamp-format regex-success regex-success-timestamp-format");
79-
Console.WriteLine("Can use a . to not specify the regex or timestamp format");
80-
}
81-
else
82-
{
83-
var lines = System.IO.File.ReadAllLines(args[1]);
84-
IPBanLogFileTester.RunLogFileTest(lines[0], lines[1], lines[2], lines[3], lines[4]);
85-
}
86-
return true;
87-
}
88-
}
89-
return false;
90-
}
9167
}
9268
}

IPBanClient/IPBanClient.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\IPBanCore\IPBanCore.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

IPBanClient/IpBanClientMain.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using DigitalRuby.IPBanCore.Core.Utility;
2+
3+
namespace IPBanClient
4+
{
5+
internal class Program
6+
{
7+
public static async Task Main(string[] args)
8+
{
9+
await CommandLineProcessor.ProcessAsync(args);
10+
}
11+
}
12+
}

IPBanCore/Core/IPBan/IPBanDB.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ private static long GetInt64(object value)
134134
}
135135
}
136136

137-
private static IPAddressEntry ParseIPAddressEntry(SqliteDataReader reader)
137+
/// <summary>
138+
/// Parses a DB record.
139+
/// </summary>
140+
public static IPAddressEntry ParseIPAddressEntry(SqliteDataReader reader)
138141
{
139142
string ipAddress = reader.GetString(0);
140143
long lastFailedLogin = reader.GetInt64(1);

0 commit comments

Comments
 (0)