Initial MVP.

This commit is contained in:
femsci 2023-03-03 23:54:09 +01:00
commit 07e08aa5ce
Signed by: femsci
GPG key ID: 08F7911F0E650C67
14 changed files with 243 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
**/bin
**/obj

3
.nyoki Normal file
View file

@ -0,0 +1,3 @@
{
"instanceId": "de389c65-2419-4451-b350-a029cded3175"
}

36
AutoMFA.sln Normal file
View file

@ -0,0 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BFFC3FE0-F692-4AE3-B895-C459E949089E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMFA.Server", "src\AutoMFA.Server\AutoMFA.Server.csproj", "{60293B32-7FBE-49DB-AE7F-C8B0933B8822}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F1A4AF86-865D-4B0F-A47C-A84F73565A41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoMFA.Test", "test\AutoMFA.Test\AutoMFA.Test.csproj", "{AEEDBEB2-14F9-4D50-83FD-774035CA00B0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{60293B32-7FBE-49DB-AE7F-C8B0933B8822}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60293B32-7FBE-49DB-AE7F-C8B0933B8822}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60293B32-7FBE-49DB-AE7F-C8B0933B8822}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60293B32-7FBE-49DB-AE7F-C8B0933B8822}.Release|Any CPU.Build.0 = Release|Any CPU
{AEEDBEB2-14F9-4D50-83FD-774035CA00B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEEDBEB2-14F9-4D50-83FD-774035CA00B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEEDBEB2-14F9-4D50-83FD-774035CA00B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEEDBEB2-14F9-4D50-83FD-774035CA00B0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{60293B32-7FBE-49DB-AE7F-C8B0933B8822} = {BFFC3FE0-F692-4AE3-B895-C459E949089E}
{AEEDBEB2-14F9-4D50-83FD-774035CA00B0} = {F1A4AF86-865D-4B0F-A47C-A84F73565A41}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="TextCopy" Version="6.2.1" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,39 @@
using System.Text.RegularExpressions;
using AutoMFA.Server.Models;
using Microsoft.AspNetCore.Mvc;
using TextCopy;
namespace AutoMFA.Server.Controllers;
[ApiController]
[Route("/data")]
public partial class DataController : ControllerBase
{
private readonly ILogger<DataController> _logger;
private readonly IClipboard _clipboard;
public DataController(ILogger<DataController> logger, IClipboard clipboard)
{
_logger = logger;
_clipboard = clipboard;
}
[HttpPost("publish")]
public async Task<IActionResult> Publish([FromBody] MessageModel model)
{
_logger.LogInformation("SMS at {}", model.Timestamp);
string msg = model.MessageRaw;
var match = _mBankRegex().Match(msg);
if (match.Success)
{
long token = long.Parse(match.Groups[1].Value);
await _clipboard.SetTextAsync(token.ToString());
}
return Ok();
}
[GeneratedRegex("haslo: (\\d{8})")]
private static partial Regex _mBankRegex();
}

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace AutoMFA.Server.Controllers;
[ApiController]
[Route("/")]
public class ServiceController : ControllerBase
{
[HttpGet("ping")]
public IActionResult Ping()
{
return Ok();
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace AutoMFA.Server.Models;
public class MessageModel
{
public long Timestamp { get; set; }
public string MessageRaw { get; set; } = null!;
}

View file

@ -0,0 +1,16 @@
using TextCopy;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.InjectClipboard();
var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

View file

@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49705",
"sslPort": 44307
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://0.0.0.0:8080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7241;http://localhost:5107",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View file

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View file

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View file

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

View file

@ -0,0 +1,19 @@
using System.Text.RegularExpressions;
namespace AutoMFA.Test;
public partial class RegexTests
{
[Fact]
public void MBankRegex()
{
var msg = "58 PLN haslo: 21372137 mBank";
var match = mBank().Match(msg);
Assert.True(match.Success);
Assert.Equal("21372137", match.Groups[1].Value);
}
[GeneratedRegex("haslo: (\\d{8})")]
private static partial Regex mBank();
}

View file

@ -0,0 +1 @@
global using Xunit;