-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b361e9
commit dd118fb
Showing
29 changed files
with
884 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
@using Client.Models.Events | ||
@using SharpC2.API.Requests | ||
|
||
@inject SharpC2Api Api | ||
|
||
<MudDialog> | ||
<DialogContent> | ||
<MudForm @ref="_form" @bind-IsValid="@_success"> | ||
|
||
<MudItem Class="my-4"> | ||
<MudSelect T="WebhookConsumer" Label="Consumer" Variant="Variant.Outlined" @bind-Value="@_consumer"> | ||
<MudSelectItem T="WebhookConsumer" Value="WebhookConsumer.SLACK"/> | ||
<MudSelectItem T="WebhookConsumer" Value="WebhookConsumer.CUSTOM"/> | ||
</MudSelect> | ||
</MudItem> | ||
|
||
<MudItem Class="my-4"> | ||
<MudTextField T="string" @bind-Value="_name" Label="Name" Required="true" | ||
RequiredError="Name is required" Immediate="@true"/> | ||
</MudItem> | ||
|
||
<MudItem Class="my-4"> | ||
<MudSelect T="EventType" Label="Event" Variant="Variant.Outlined" @bind-Value="@_event"> | ||
<MudSelectItem T="EventType" Value="EventType.USER_AUTH" /> | ||
<MudSelectItem T="EventType" Value="EventType.WEB_LOG" /> | ||
</MudSelect> | ||
</MudItem> | ||
|
||
<MudItem Class="my-4"> | ||
<MudTextField T="string" @bind-Value="_url" Label="URL" Required="true" | ||
RequiredError="URL is required" Immediate="@true"/> | ||
</MudItem> | ||
|
||
</MudForm> | ||
</DialogContent> | ||
<DialogActions> | ||
<MudButton OnClick="Cancel">Cancel</MudButton> | ||
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton> | ||
</DialogActions> | ||
</MudDialog> | ||
|
||
@code { | ||
|
||
[CascadingParameter] | ||
public MudDialogInstance MudDialog { get; set; } | ||
|
||
private MudForm _form; | ||
private bool _success; | ||
|
||
private string _name; | ||
private WebhookConsumer _consumer; | ||
private EventType _event; | ||
private string _url; | ||
|
||
private async Task Submit() | ||
{ | ||
if (!_success) | ||
{ | ||
await _form.Validate(); | ||
return; | ||
} | ||
|
||
var request = new WebhookRequest | ||
{ | ||
Name = _name, | ||
Consumer = (int)_consumer, | ||
Event = (int)_event, | ||
Url = _url | ||
}; | ||
|
||
await Api.CreateWebhook(request); | ||
MudDialog.Close(DialogResult.Ok(true)); | ||
} | ||
|
||
private void Cancel() | ||
=> MudDialog.Cancel(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Client.Models.Events; | ||
using SharpC2.API.Responses; | ||
|
||
namespace Client.Models.Webhooks; | ||
|
||
public sealed class SharpC2Webhook | ||
{ | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
public WebhookConsumer Consumer { get; set; } | ||
public EventType Event { get; set; } | ||
public string Url { get; set; } | ||
|
||
public static implicit operator SharpC2Webhook(WebhookResponse response) | ||
{ | ||
return response is null | ||
? null | ||
: new SharpC2Webhook | ||
{ | ||
Id = response.Id, | ||
Name = response.Name, | ||
Consumer = (WebhookConsumer)response.Consumer, | ||
Event = (EventType)response.Event, | ||
Url = response.Url | ||
}; | ||
} | ||
} | ||
|
||
public enum WebhookConsumer | ||
{ | ||
SLACK, | ||
CUSTOM | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
@attribute [Authorize] | ||
@page "/webhooks" | ||
@using Client.Components.Webhooks | ||
|
||
@inject SharpC2Api Api | ||
@inject SharpC2Hub Hub | ||
@inject IDialogService Dialogs | ||
|
||
<MudContainer MaxWidth="MaxWidth.ExtraExtraLarge"> | ||
<MudTable Items="@_webhooks" Hover="true" Loading="@_loading" LoadingProgressColor="Color.Info"> | ||
<HeaderContent> | ||
<MudTh>Name</MudTh> | ||
<MudTh>Consumer</MudTh> | ||
<MudTh>Event</MudTh> | ||
<MudTh>URL</MudTh> | ||
<MudTh></MudTh> | ||
</HeaderContent> | ||
<RowTemplate> | ||
<MudTd DataLabel="Name">@context.Name</MudTd> | ||
<MudTd DataLabel="Consumer">@context.Consumer</MudTd> | ||
<MudTd DataLabel="Event">@context.Event</MudTd> | ||
<MudTd DataLabel="URL">@context.Url</MudTd> | ||
<MudTd> | ||
<MudTooltip Text="Delete"> | ||
<MudIconButton Icon="@Icons.Material.Filled.DeleteForever" Size="Size.Medium" | ||
Color="@Color.Error" OnClick="@(async () => await DeleteWebhook(context))"/> | ||
</MudTooltip> | ||
</MudTd> | ||
</RowTemplate> | ||
<NoRecordsContent> | ||
No Webhooks | ||
</NoRecordsContent> | ||
</MudTable> | ||
|
||
<MudTooltip Text="Add Webhook"> | ||
<MudFab Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" Size="Size.Medium" Class="mt-4" | ||
OnClick="OpenCreateWebhook"/> | ||
</MudTooltip> | ||
|
||
</MudContainer> | ||
|
||
@code { | ||
|
||
private bool _loading = true; | ||
private readonly List<SharpC2Webhook> _webhooks = new(); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Hub.WebhookCreated += OnWebhookCreated; | ||
Hub.WebhookDeleted += OnWebhookDeleted; | ||
} | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
var webhooks = await Api.GetWebhooks(); | ||
|
||
_webhooks.AddRange(webhooks); | ||
_loading = false; | ||
} | ||
|
||
private async Task DeleteWebhook(SharpC2Webhook webhook) | ||
{ | ||
await Api.DeleteWebhook(webhook.Name); | ||
} | ||
|
||
private async Task OpenCreateWebhook() | ||
{ | ||
var options = new DialogOptions { FullWidth = true }; | ||
await Dialogs.ShowAsync<CreateWebhook>("", options); | ||
} | ||
|
||
private async Task OnWebhookCreated(string name) | ||
{ | ||
var webhook = await Api.GetWebhook(name); | ||
|
||
if (webhook is null) | ||
return; | ||
|
||
_webhooks.Add(webhook); | ||
await InvokeAsync(StateHasChanged); | ||
} | ||
|
||
private async Task OnWebhookDeleted(string name) | ||
{ | ||
_webhooks.RemoveAll(h => h.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); | ||
await InvokeAsync(StateHasChanged); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SharpC2.API.Requests; | ||
|
||
public sealed class WebhookRequest | ||
{ | ||
public string Name { get; set; } | ||
public int Consumer { get; set; } | ||
public int Event { get; set; } | ||
public string Url { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace SharpC2.API.Responses; | ||
|
||
public sealed class WebhookResponse | ||
{ | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
public int Consumer { get; set; } | ||
public int Event { get; set; } | ||
public string Url { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.