Make the hold method configurable in the dashboard
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a56fc5b48
commit
6b9bf3cd5f
40 files changed
+815
-134
No files matched your search
@@ -0,0 +1,8 @@
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
public enum DripContent
|
||||
{
|
||||
Html,
|
||||
Text,
|
||||
Alternating
|
||||
}
|
||||
@@ -4,6 +4,8 @@ public sealed class DripOptions
|
||||
{
|
||||
public const string SectionName = "Flypaper:Drip";
|
||||
|
||||
public DripContent Content { get; set; } = DripContent.Html;
|
||||
|
||||
public TimeSpan MinDelay { get; set; } = TimeSpan.FromMilliseconds(50);
|
||||
|
||||
public TimeSpan MaxDelay { get; set; } = TimeSpan.FromSeconds(1);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Globalization;
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
public abstract class DripStrategy(
|
||||
IOptionsMonitor<DripOptions> options,
|
||||
IRandomSource random,
|
||||
TimeProvider timeProvider) : ITarpitStrategy, IStrategyDetails
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
public abstract string MediaType { get; }
|
||||
|
||||
public bool Supports(TrapProtocol protocol) => protocol == TrapProtocol.Http;
|
||||
|
||||
public string Describe()
|
||||
{
|
||||
var current = options.CurrentValue;
|
||||
return string.Create(
|
||||
CultureInfo.InvariantCulture,
|
||||
$"{Name} {current.MinDelay.TotalMilliseconds:0}-{current.MaxDelay.TotalMilliseconds:0}ms {current.MinChunkSize}-{current.MaxChunkSize}B");
|
||||
}
|
||||
|
||||
public async Task RunAsync(ITrapChannel channel, CancellationToken ct)
|
||||
{
|
||||
foreach (var step in DripSchedule.Create(Content(random), random, options.CurrentValue))
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
await channel.WriteAsync(step.Chunk, ct);
|
||||
await Task.Delay(step.Delay, timeProvider, ct);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<string> Content(IRandomSource random);
|
||||
}
|
||||
@@ -14,24 +14,6 @@ public static class HtmlContent
|
||||
a { color: #0b5cad; }
|
||||
""";
|
||||
|
||||
private static readonly string[] Vocabulary =
|
||||
[
|
||||
"lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "sed", "do", "eiusmod",
|
||||
"tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua", "enim", "ad", "minim",
|
||||
"veniam", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "aliquip", "ex", "ea",
|
||||
"commodo", "consequat", "duis", "aute", "irure", "in", "reprehenderit", "voluptate", "velit", "esse",
|
||||
"cillum", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", "cupidatat", "non", "proident",
|
||||
"sunt", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum", "praesent",
|
||||
"luctus", "vitae", "semper", "facilisis", "integer", "nec", "odio", "mauris", "massa", "vestibulum",
|
||||
"lacinia", "arcu", "eget", "nunc", "tristique", "fermentum", "pellentesque", "habitant", "morbi",
|
||||
"senectus", "netus", "malesuada", "fames", "turpis", "egestas", "porttitor", "rhoncus", "dapibus",
|
||||
"ornare", "sapien", "volutpat", "blandit", "aliquam", "etiam", "erat", "velit", "scelerisque",
|
||||
"viverra", "orci", "sagittis", "eu", "tellus", "cras", "pulvinar", "mattis", "pharetra", "convallis",
|
||||
"posuere", "morbi", "leo", "urna", "molestie", "at", "elementum", "sodales", "neque", "gravida",
|
||||
"dictum", "fusce", "ultrices", "placerat", "euismod", "quam", "suspendisse", "potenti", "nullam",
|
||||
"accumsan", "tincidunt", "varius", "sollicitudin", "imperdiet", "hendrerit", "bibendum", "cursus"
|
||||
];
|
||||
|
||||
private static readonly string[] Sections =
|
||||
["docs", "blog", "wiki", "support", "products", "archive", "news", "help", "files", "guides", "kb", "releases"];
|
||||
|
||||
@@ -78,7 +60,7 @@ public static class HtmlContent
|
||||
var count = random.Next(3, 7);
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
builder.Append($"<a href=\"/{Pick(random, Sections)}/\">{Capitalize(Pick(random, Vocabulary))}</a>\n");
|
||||
builder.Append($"<a href=\"/{Pick(random, Sections)}/\">{LoremText.Capitalize(LoremText.Word(random))}</a>\n");
|
||||
}
|
||||
|
||||
return builder.Append("</nav>\n").ToString();
|
||||
@@ -145,8 +127,8 @@ public static class HtmlContent
|
||||
continue;
|
||||
}
|
||||
|
||||
var word = Pick(random, Vocabulary);
|
||||
builder.Append(i == 0 ? Capitalize(word) : word);
|
||||
var word = LoremText.Word(random);
|
||||
builder.Append(i == 0 ? LoremText.Capitalize(word) : word);
|
||||
}
|
||||
|
||||
return builder.Append(random.Next(0, 10) == 0 ? '?' : '.').ToString();
|
||||
@@ -154,17 +136,13 @@ public static class HtmlContent
|
||||
|
||||
private static string Link(IRandomSource random, int words)
|
||||
{
|
||||
var text = Phrase(random, words);
|
||||
var text = LoremText.Phrase(random, words);
|
||||
var slug = text.Replace(' ', '-');
|
||||
return $"<a href=\"/{Pick(random, Sections)}/{slug}\">{text}</a>";
|
||||
}
|
||||
|
||||
private static string Title(IRandomSource random, int min, int max) => Capitalize(Phrase(random, random.Next(min, max + 1)));
|
||||
|
||||
private static string Phrase(IRandomSource random, int count) =>
|
||||
string.Join(' ', Enumerable.Range(0, count).Select(_ => Pick(random, Vocabulary)));
|
||||
private static string Title(IRandomSource random, int min, int max) => LoremText.Capitalize(LoremText.Phrase(random, random.Next(min, max + 1)));
|
||||
|
||||
private static string Pick(IRandomSource random, string[] values) => values[random.Next(0, values.Length)];
|
||||
|
||||
private static string Capitalize(string value) => value.Length == 0 ? value : char.ToUpperInvariant(value[0]) + value[1..];
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
@@ -7,19 +6,13 @@ namespace Flypaper.Core.Strategies;
|
||||
public sealed class HtmlDripStrategy(
|
||||
IOptionsMonitor<DripOptions> options,
|
||||
IRandomSource random,
|
||||
TimeProvider timeProvider) : ITarpitStrategy
|
||||
TimeProvider timeProvider) : DripStrategy(options, random, timeProvider)
|
||||
{
|
||||
public string Name => "html-drip";
|
||||
public const string StrategyName = "html-drip";
|
||||
|
||||
public bool Supports(TrapProtocol protocol) => protocol == TrapProtocol.Http;
|
||||
public override string Name => StrategyName;
|
||||
|
||||
public async Task RunAsync(ITrapChannel channel, CancellationToken ct)
|
||||
{
|
||||
foreach (var step in DripSchedule.Create(HtmlContent.Generate(random), random, options.CurrentValue))
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
await channel.WriteAsync(step.Chunk, ct);
|
||||
await Task.Delay(step.Delay, timeProvider, ct);
|
||||
}
|
||||
}
|
||||
public override string MediaType => "text/html; charset=utf-8";
|
||||
|
||||
protected override IEnumerable<string> Content(IRandomSource random) => HtmlContent.Generate(random);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System.Text;
|
||||
using Flypaper.Core.Abstractions;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
internal static class LoremText
|
||||
{
|
||||
private static readonly string[] Vocabulary =
|
||||
[
|
||||
"lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "sed", "do", "eiusmod",
|
||||
"tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua", "enim", "ad", "minim",
|
||||
"veniam", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "aliquip", "ex", "ea",
|
||||
"commodo", "consequat", "duis", "aute", "irure", "in", "reprehenderit", "voluptate", "velit", "esse",
|
||||
"cillum", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", "cupidatat", "non", "proident",
|
||||
"sunt", "culpa", "qui", "officia", "deserunt", "mollit", "anim", "id", "est", "laborum", "praesent",
|
||||
"luctus", "vitae", "semper", "facilisis", "integer", "nec", "odio", "mauris", "massa", "vestibulum",
|
||||
"lacinia", "arcu", "eget", "nunc", "tristique", "fermentum", "pellentesque", "habitant", "morbi",
|
||||
"senectus", "netus", "malesuada", "fames", "turpis", "egestas", "porttitor", "rhoncus", "dapibus",
|
||||
"ornare", "sapien", "volutpat", "blandit", "aliquam", "etiam", "erat", "velit", "scelerisque",
|
||||
"viverra", "orci", "sagittis", "eu", "tellus", "cras", "pulvinar", "mattis", "pharetra", "convallis",
|
||||
"posuere", "morbi", "leo", "urna", "molestie", "at", "elementum", "sodales", "neque", "gravida",
|
||||
"dictum", "fusce", "ultrices", "placerat", "euismod", "quam", "suspendisse", "potenti", "nullam",
|
||||
"accumsan", "tincidunt", "varius", "sollicitudin", "imperdiet", "hendrerit", "bibendum", "cursus"
|
||||
];
|
||||
|
||||
public static string Word(IRandomSource random) => Vocabulary[random.Next(0, Vocabulary.Length)];
|
||||
|
||||
public static string Phrase(IRandomSource random, int count) =>
|
||||
string.Join(' ', Enumerable.Range(0, count).Select(_ => Word(random)));
|
||||
|
||||
public static string Sentence(IRandomSource random)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
var words = random.Next(4, 21);
|
||||
for (var i = 0; i < words; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
builder.Append(i > 2 && random.Next(0, 9) == 0 ? ", " : " ");
|
||||
}
|
||||
|
||||
var word = Word(random);
|
||||
builder.Append(i == 0 ? Capitalize(word) : word);
|
||||
}
|
||||
|
||||
return builder.Append(random.Next(0, 10) == 0 ? '?' : '.').ToString();
|
||||
}
|
||||
|
||||
public static string Capitalize(string value) => value.Length == 0 ? value : char.ToUpperInvariant(value[0]) + value[1..];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Text;
|
||||
using Flypaper.Core.Abstractions;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
public static class TextContent
|
||||
{
|
||||
public static IEnumerable<string> Generate(IRandomSource random)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
var sentences = random.Next(1, 7);
|
||||
for (var i = 0; i < sentences; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
builder.Append(' ');
|
||||
}
|
||||
|
||||
builder.Append(LoremText.Sentence(random));
|
||||
}
|
||||
|
||||
yield return builder.Append(random.Next(0, 4) == 0 ? "\n\n" : "\n").ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Flypaper.Core.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core.Strategies;
|
||||
|
||||
public sealed class TextDripStrategy(
|
||||
IOptionsMonitor<DripOptions> options,
|
||||
IRandomSource random,
|
||||
TimeProvider timeProvider) : DripStrategy(options, random, timeProvider)
|
||||
{
|
||||
public const string StrategyName = "text-drip";
|
||||
|
||||
public override string Name => StrategyName;
|
||||
|
||||
public override string MediaType => "text/plain; charset=utf-8";
|
||||
|
||||
protected override IEnumerable<string> Content(IRandomSource random) => TextContent.Generate(random);
|
||||
}
|
||||
Reference in new issue
Block a user