Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Jan 8, 2024
1 parent 3e7f78c commit 41d3de7
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 96 deletions.
6 changes: 3 additions & 3 deletions Tikhole.Engine/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ private static void AddRuleHostFile(this Rules Rules, XmlNode Node)
)
);
}
public static string GetDisplayName(this Type Type)
public static string GetRuleName(this Type Type)
{
DisplayNameAttribute? attribute = Type.GetCustomAttribute<DisplayNameAttribute>();
RuleAttribute? attribute = Type.GetCustomAttribute<RuleAttribute>();
if (attribute == null) return "Unknown";
return attribute.DisplayName;
return attribute.Name;
}
}
}
28 changes: 26 additions & 2 deletions Tikhole.Engine/Matcher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.ComponentModel;
using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace Tikhole.Engine
Expand Down Expand Up @@ -85,7 +87,7 @@ private void Parser_ParsedResponseData(object? sender, ParsedResponseDataEventAr
}
public class MatchTableRegex : List<KeyValuePair<string, Regex>> { }
public class Rules : List<Rule> { }
[DisplayName("Host File")]
[Rule("Host File")]
public class RuleHashSetDownloadableHostFile : RuleHashSetDownloadable
{
public RuleHashSetDownloadableHostFile(string Name, Uri Uri, System.Timers.Timer UpdateTimer) : base(Name, Uri, UpdateTimer) { }
Expand Down Expand Up @@ -118,7 +120,9 @@ public override void UpdateList(object? a = null, object? b = null)
}
public abstract class RuleHashSetDownloadable : RuleHashSet
{
[RuleParameter("File Download URL")]
public Uri Uri;
[RuleParameter("Update Timer MS")]
public System.Timers.Timer UpdateTimer;
private protected static HttpClient HttpClient = new();
public RuleHashSetDownloadable(string Name, Uri Uri, System.Timers.Timer UpdateTimer) : base(Name)
Expand All @@ -144,9 +148,10 @@ public override void Dispose()
UpdateTimer.Dispose();
}
}
[DisplayName("Regular Expression")]
[Rule("Regular Expression")]
public class RuleRegex : Rule
{
[RuleParameter("Regular Expression")]
public Regex Regex;
public RuleRegex(string Name, Regex Regex) : base(Name)
{
Expand All @@ -165,6 +170,7 @@ protected RuleHashSet(string Name) : base(Name) { }
}
public abstract class Rule : IDisposable
{
[RuleParameter("Name")]
public string Name;
public Rule(string Name)
{
Expand All @@ -181,4 +187,22 @@ public class ResponseMatchedEventArgs : EventArgs
public required string[] Aliases;
public required IPAddress[] Addresses;
}
[AttributeUsage(AttributeTargets.Class)]
public class RuleAttribute : Attribute
{
public string Name;
public RuleAttribute(string Name)
{
this.Name = Name;
}
}
[AttributeUsage(AttributeTargets.Field)]
public class RuleParameterAttribute : Attribute
{
public string Name;
public RuleParameterAttribute(string Name)
{
this.Name = Name;
}
}
}
4 changes: 2 additions & 2 deletions Tikhole.Website/Components/Pages/Dashboard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@
{
base.OnInitialized();
CPULast = Process.TotalProcessorTime;
Timer.Elapsed += TimerElapsed;
Timer.Elapsed += Timer_Elapsed;
Timer.Enabled = true;
Timer.Start();
if (Engine.Tikhole.Listener != null) Engine.Tikhole.Listener.RecievedRequestData += InvokeStateChange;
if (Engine.Tikhole.Matcher != null) Engine.Tikhole.Matcher.MatchesMatchedAndOrCommitted += InvokeStateChange;
if (Engine.Tikhole.Parser != null) Engine.Tikhole.Parser.ParsedResponseData += Parser_ParsedResponseData;
}
private void TimerElapsed(object? sender = null, EventArgs? e = null)
private void Timer_Elapsed(object? sender = null, EventArgs? e = null)
{
Process.Refresh();
CPUUsage = Math.Round(Process.TotalProcessorTime.Subtract(CPULast).Milliseconds / Timer.Interval * 10, 2);
Expand Down
42 changes: 21 additions & 21 deletions Tikhole.Website/Components/Pages/Rule.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@

<h1>📃 Rule: @ERule?.Name</h1>
<p class="text-secondary">
<small>@ERule?.GetType().GetDisplayName()</small>
<small>@ERule?.GetType().GetRuleName()</small>
</p>
<hr />
<a href="/Rules" class="btn btn-dark">⬅️ Back</a>
@if (DeleteIntent)
{
<button class="btn btn-dark float-end" @onclick="InvokeDelete">⚠️ Confirm?</button>
}
else
{
<button class="btn btn-dark float-end" @onclick="InvokeDelete">🗑️ Delete</button>
}
@if (ERule != null)
{
@if (DeleteIntent)
{
<button class="btn btn-dark float-end" @onclick="InvokeDelete">⚠️ Confirm?</button>
}
else
{
<button class="btn btn-dark float-end" @onclick="InvokeDelete">🗑️ Delete</button>
}
}
<hr />

<div style="max-width:500px;">
@if (ERule != null)
@if (ERule == null)
{
foreach (Type rule in System.Reflection.Assembly.GetAssembly(typeof(Engine.Tikhole)).GetTypes())
{
var asdf = rule.GetFields();
<button class="btn btn-dark" @onclick="() => {}">@rule.GetRuleName()</button>
}
}
else
{
<div class="mb-3">
<label class="form-label">Name</label>
<InputText @bind-Value="ERule!.Name" class="form-control" />
</div>
}
@if (ERule?.GetType() == typeof(Engine.RuleRegex))
{
Engine.RuleRegex rule = (Engine.RuleRegex)ERule;
<RuleRegex @bind-Rule="rule" />
}
@if (ERule?.GetType() == typeof(Engine.RuleHashSetDownloadableHostFile))
{
Engine.RuleHashSetDownloadableHostFile rule = (Engine.RuleHashSetDownloadableHostFile)ERule;
<RuleHashSetDownloadableHostFile @bind-Rule="rule" />
}
</div>

@code {
Expand Down
4 changes: 2 additions & 2 deletions Tikhole.Website/Components/Pages/Rules.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<small>A list of rules that Tikhole uses to identify domains to send to RouterOS IP lists.</small>
</p>
<hr />
<button class="btn btn-dark" @onclick="() => { }">➕ Add</button>
<a href="/Rules/-1" class="btn btn-dark">➕ Add</a>
<hr />
@{
int index = 0;
Expand All @@ -30,7 +30,7 @@
<span class="input-group-text"><strong>Name</strong></span>
<span class="input-group-text">@rule.Name</span>
<span class="input-group-text"><strong>Type</strong></span>
<span class="input-group-text flex-grow-1">@rule.GetType().GetDisplayName()</span>
<span class="input-group-text flex-grow-1">@rule.GetType().GetRuleName()</span>
<button class="btn btn-outline-secondary" @onclick="() => {}">⬆️</button>
<button class="btn btn-outline-secondary" @onclick="() => {}">⬇️</button>
<a href="/Rules/@index" class="btn btn-outline-secondary">✏️</a>
Expand Down

This file was deleted.

25 changes: 0 additions & 25 deletions Tikhole.Website/Components/RuleTypes/RuleRegex.razor

This file was deleted.

3 changes: 1 addition & 2 deletions Tikhole.Website/Components/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
@using Microsoft.JSInterop
@using global::Tikhole.Website
@using global::Tikhole.Website.Components
@using global::Tikhole.Website.Components.Pages
@using global::Tikhole.Website.Components.RuleTypes
@using global::Tikhole.Website.Components.Pages

0 comments on commit 41d3de7

Please sign in to comment.