The link labyrinth held every catch that mattered, text-drip was never used. Flypaper__Drip__Content now only triggers the removed-settings warning. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
2.3 KiB
C#
54 lines
2.3 KiB
C#
using Flypaper.Core.Abstractions;
|
|
using Flypaper.Core.Models;
|
|
using Flypaper.Core.Strategies;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Flypaper.Core.Runtime;
|
|
|
|
public sealed class ConfiguredStrategySelector(
|
|
IEnumerable<ITarpitStrategy> strategies,
|
|
IOptionsMonitor<DripOptions> options,
|
|
IRandomSource random) : ITrapStrategySelector
|
|
{
|
|
public ITarpitStrategy? Select(TrapContext context)
|
|
{
|
|
var candidates = strategies.Where(strategy => strategy.Supports(context.Session.Protocol)).ToList();
|
|
if (string.Equals(context.Path, RobotsStaticStrategy.Path, StringComparison.OrdinalIgnoreCase)
|
|
&& candidates.FirstOrDefault(strategy => strategy.Name == RobotsStaticStrategy.StrategyName) is { } robots)
|
|
{
|
|
return robots;
|
|
}
|
|
|
|
if (context.IsNewIp && options.CurrentValue.Lure && LureContent.Handles(context.Path)
|
|
&& candidates.FirstOrDefault(strategy => strategy.Name == (context.Path == LureContent.PagePath ? LureStrategy.PageName : LureStrategy.IconName)) is { } lure)
|
|
{
|
|
return lure;
|
|
}
|
|
|
|
if (BaitPaths.Matches(BaitPaths.Parse(options.CurrentValue.BaitPaths), context.Path)
|
|
&& candidates.FirstOrDefault(strategy => strategy.Name == MazeDripStrategy.BaitName) is { } bait)
|
|
{
|
|
return bait;
|
|
}
|
|
|
|
if (options.CurrentValue.MatchPath && FileContent.Match(context.Path) is { } profile
|
|
&& candidates.FirstOrDefault(strategy => strategy.Name == profile.Name) is { } fileStrategy)
|
|
{
|
|
return fileStrategy;
|
|
}
|
|
|
|
var maze = options.CurrentValue.LinkSpacing > 0
|
|
&& candidates.Any(strategy => strategy.Name == MazeDripStrategy.PageName);
|
|
var page = maze ? MazeDripStrategy.PageName : HtmlDripStrategy.StrategyName;
|
|
var matching = candidates.Where(strategy => strategy.Name == page).ToList();
|
|
var chosen = matching.Count == 0
|
|
? candidates.FirstOrDefault()
|
|
: matching[random.Next(0, matching.Count)];
|
|
|
|
return chosen?.Name == MazeDripStrategy.PageName && MazeContent.IsDirectory(context.Path)
|
|
&& candidates.FirstOrDefault(strategy => strategy.Name == MazeDripStrategy.ListingName) is { } listing
|
|
? listing
|
|
: chosen;
|
|
}
|
|
}
|