Add link labyrinth, static robots.txt and robots bait paths
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b7027e2a72
commit
a25072e6fb
29 files changed
+774
-34
No files matched your search
@@ -13,22 +13,42 @@ public sealed class ConfiguredStrategySelector(
|
||||
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 (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;
|
||||
string[] wanted = options.CurrentValue.Content switch
|
||||
{
|
||||
DripContent.Text => [TextDripStrategy.StrategyName],
|
||||
DripContent.Alternating => [HtmlDripStrategy.StrategyName, TextDripStrategy.StrategyName],
|
||||
_ => [HtmlDripStrategy.StrategyName]
|
||||
DripContent.Alternating => [page, TextDripStrategy.StrategyName],
|
||||
_ => [page]
|
||||
};
|
||||
|
||||
var matching = candidates.Where(strategy => wanted.Contains(strategy.Name)).ToList();
|
||||
return matching.Count == 0
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user