using LiteDB;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RuriLib.Models
{
///
/// Represents the outcome of a successful check, used as Data Type in a Database.
///
public class Hit
{
/// Needed for NoSQL storage.
public Guid Id { get; set; }
/// The data line that was used.
public string Data { get; set; }
/// The list of all variables marked as Capture.
public VariableList CapturedData { get; set; }
/// The list of all variables marked as Capture as a chained string.
[JsonIgnore]
[BsonIgnore]
public string CapturedString { get { return CapturedData.ToCaptureString(); } }
/// The proxy that was used.
public string Proxy { get; set; }
/// The timestamp of when the Hit was found.
public DateTime Date { get; set; }
/// The type of Hit.
public string Type { get; set; }
/// The name of the Config that was used.
public string ConfigName { get; set; }
/// The name of the Wordlist that was used.
public string WordlistName { get; set; }
/// Needed for NoSQL deserialization.
public Hit() { }
///
/// Creates a Hit given its details.
///
/// The data line used
/// The VariableList of all captured data
/// The proxy used
/// The type of the Hit
/// The Config's name
/// The Wordlist's name
public Hit(string data, VariableList capturedData, string proxy, string type, string configName, string wordlistName)
{
Data = data;
CapturedData = capturedData;
Proxy = proxy;
Date = DateTime.Now;
Type = type;
ConfigName = configName;
WordlistName = wordlistName;
}
///
/// Outputs the Hit details in a given format.
///
/// The format in which variables should be replaced
/// The formatted string with all variables replaced
public string ToFormattedString(string format)
{
StringBuilder sb = new StringBuilder(format)
.Replace("", Data)
.Replace("", Proxy)
.Replace("", Date.ToLongDateString() + " " + Date.ToLongTimeString())
.Replace("", ConfigName)
.Replace("", WordlistName)
.Replace("", Type)
.Replace("", CapturedData.ToCaptureString());
foreach(var cap in CapturedData.All)
sb.Replace("<" + cap.Name + ">", cap.ToString());
return sb.ToString();
}
}
}