Skip to content

Commit

Permalink
NuGet Update + code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Seji64 committed Aug 9, 2024
1 parent a4843bc commit 19fe763
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 352 deletions.
4 changes: 2 additions & 2 deletions src/Components/LapsInformationDetail.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@inherits MudComponentBase
@inject ISnackbar Snackbar
@inject ClipboardService clipboard
@inject ClipboardService Clipboard
@using CurrieTechnologies.Razor.Clipboard

@if (LapsInfo != null)
Expand All @@ -13,7 +13,7 @@
</AdornmentStart>
<AdornmentEnd>
<MudTooltip Text="@(IsCopyToClipboardSupported ? "Copy Password to clipboard" : "Your browser does not support Clipboard API - please use STRG+C")">
<MudIconButton Class="mb-1" Disabled="@(IsCopyButtonDisabled())" Icon="@Icons.Material.Outlined.ContentCopy" Color="Color.Primary" OnClick="@(async (_) => await CopyLAPSPasswordToClipboardAsync())" aria-label="Copy Password to clipbard" />
<MudIconButton Class="mb-1" Disabled="@(IsCopyButtonDisabled())" Icon="@Icons.Material.Outlined.ContentCopy" Color="Color.Primary" OnClick="@(async (_) => await CopyLapsPasswordToClipboardAsync())" aria-label="Copy Password to clipbard" />
</MudTooltip>

</AdornmentEnd>
Expand Down
6 changes: 3 additions & 3 deletions src/Components/LapsInformationDetail.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
IsCopyToClipboardSupported = await clipboard.IsSupportedAsync();
IsCopyToClipboardSupported = await Clipboard.IsSupportedAsync();
}
}

private bool IsCopyButtonDisabled()
{
return !IsCopyToClipboardSupported || LapsInfo is null || string.IsNullOrEmpty(LapsInfo.Password);
}
private async Task CopyLAPSPasswordToClipboardAsync()
private async Task CopyLapsPasswordToClipboardAsync()
{
if (LapsInfo != null && !string.IsNullOrEmpty(LapsInfo.Password))
{
await clipboard.WriteTextAsync(LapsInfo.Password);
await Clipboard.WriteTextAsync(LapsInfo.Password);
Snackbar.Add("Copied password to clipboard!", Severity.Success);
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/Dialogs/Confirmation.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<MudDialog DisableSidePadding="true">
<MudDialog>
<DialogContent>
<MudContainer Style="max-height: 500px; overflow-y: scroll">

<MudAlert ContentAlignment="HorizontalAlignment.Center" CloseIcon="false" Variant="Variant.Outlined" Icon="@Icon" Severity="@Severity">@ContentText</MudAlert>

@if (ContentListItems != null && ContentListItems.Any())
{
foreach (var item in ContentListItems)
foreach (string? item in ContentListItems)
{
<MudList Clickable=false Dense=true>
<MudList T="string" Dense=true>
<MudListItem Text=@item Icon="@Icons.Material.Outlined.LabelImportant" IconSize=Size.Small />
</MudList>
}
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/ILDAPService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface ILdapService
Task<bool> TestCredentialsAsync(string domainName, string username, string password);
Task<bool> TestCredentialsAsync(string domainName, LdapCredential ldapCredential);
Task<List<Domain>> GetDomainsAsync();
public Task<ADComputer?> GetADComputerAsync(string domainName, LdapCredential ldapCredential, string distinguishedName);
public Task<List<ADComputer>> SearchADComputersAsync(string domainName, LdapCredential ldapCredential, string query);
public Task<AdComputer?> GetAdComputerAsync(string domainName, LdapCredential ldapCredential, string distinguishedName);
public Task<List<AdComputer>> SearchAdComputersAsync(string domainName, LdapCredential ldapCredential, string query);
public Task<bool> ClearLapsPassword(string domainName, LdapCredential ldapCredential, string distinguishedName, LAPSVersion version);
}
}
14 changes: 7 additions & 7 deletions src/LAPS-WebUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
<ItemGroup>
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="6.9.2" />
<PackageReference Include="CodeBeam.MudBlazor.Extensions" Version="7.0.0" />
<PackageReference Include="CurrieTechnologies.Razor.Clipboard" Version="1.6.0" />
<PackageReference Include="LdapForNet" Version="2.7.15" />
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="8.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="8.0.7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="MudBlazor" Version="7.6.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
</ItemGroup>

Expand Down
32 changes: 6 additions & 26 deletions src/Models/ADComputer.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
namespace LAPS_WebUI.Models
{
public class ADComputer
public class AdComputer(string distinguishedName, string name)
{
public ADComputer(string DistinguishedName, string name)
{
this.DistinguishedName = DistinguishedName;
this.Name = name;
}

public string Name { get; set; }

public string DistinguishedName { get; set; }
public List<LapsInformation>? LAPSInformations { get; set; }
public bool FailedToRetrieveLAPSDetails { get; set; }
public bool Loading
{
get
{
if (LAPSInformations is null)
{
return true;
}
else
{
return false;
}
}
}
public string Name { get; set; } = name;
public string DistinguishedName { get; set; } = distinguishedName;
public List<LapsInformation>? LapsInformations { get; set; }
public bool FailedToRetrieveLapsDetails { get; set; }
public bool Loading => LapsInformations is null;
}
}
2 changes: 1 addition & 1 deletion src/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@page "/"
@inject ISessionManagerService sessionManager
@inject ISessionManagerService SessionManager
@inject NavigationManager NavigationManager
2 changes: 1 addition & 1 deletion src/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public partial class Index
protected override async Task OnAfterRenderAsync(bool firstRender)
{
// redirect to home if already logged in
if (await sessionManager.IsUserLoggedInAsync())
if (await SessionManager.IsUserLoggedInAsync())
{
NavigationManager.NavigateTo("/laps");
}
Expand Down
101 changes: 47 additions & 54 deletions src/Pages/LAPS.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@page "/laps"
@inject ISessionManagerService sessionManager
@inject ISessionManagerService SessionManager
@inject NavigationManager NavigationManager
@inject ILdapService LDAPService
@inject ILdapService LdapService
@inject ISnackbar Snackbar
@inject IDialogService Dialog

Expand All @@ -13,9 +13,9 @@
}
else
{
<MudAutocomplete Label="Search by Computername" HelperTextOnFocus="true" HelperText="Minimum query length is 4. Wildcard (*) is supported" Variant="Variant.Outlined" ShowProgressIndicator="true" AutoFocus="true" Immediate="true" ResetValueOnEmptyText="true" @ref="AutoCompleteSearchBox"
MaxItems=null ValueChanged="@(async (ADComputer a) => OnSelectedItemChangedAsync(a).AndForget())" MinCharacters="4" MaxLength="15" SearchFunc="@SearchAsync" ToStringFunc="@(x => (x is null ? string.Empty : x.Name))"
AdornmentIcon="@Icons.Material.Outlined.Search" AdornmentColor="Color.Default" Adornment="Adornment.Start" SelectOnClick="true" SelectValueOnTab=true Clearable=true aria-label="Search Computer" >
<MudAutocomplete Label="Search by Computername" HelperTextOnFocus="true" HelperText="Minimum query length is 4. Wildcard (*) is supported" Variant="Variant.Outlined" ShowProgressIndicator="true" AutoFocus="true" Immediate="true" ResetValueOnEmptyText="true" @ref="_autoCompleteSearchBox"
MaxItems=null ValueChanged="@(async (AdComputer a) => await OnSelectedItemChangedAsync(a))" MinCharacters="4" MaxLength="15" SearchFunc="@SearchAsync" ToStringFunc="@(x => (x?.Name ?? string.Empty))"
AdornmentIcon="@Icons.Material.Outlined.Search" AdornmentColor="Color.Default" Adornment="Adornment.Start" SelectOnActivation="true" SelectValueOnTab=true Clearable=true aria-label="Search Computer" >
<ItemTemplate Context="e">
<MudText>
<MudIcon Icon="@Icons.Material.Filled.Computer" Class="mb-n1 mr-3" aria-label=@($"{e.Name}")/>@($"{e.Name}")
Expand All @@ -36,7 +36,7 @@

<MudGrid Class="mt-8" Justify="Justify.SpaceEvenly">

@foreach(var computer in SelectedComputers)
@foreach(AdComputer computer in SelectedComputers)
{
<MudItem xs="10" lg="6">
<MudCard>
Expand All @@ -57,59 +57,52 @@
</CardHeaderActions>
</MudCardHeader>
<MudCardContent>
@if(!computer.Loading)
{
@if(!computer.FailedToRetrieveLAPSDetails)
<MudLoading Loading="@computer.Loading" LoaderType="LoaderType.Circular">
@if (!computer.FailedToRetrieveLapsDetails)
{
<MudTabs Position="Position.Top" Rounded="true" Border="false" ApplyEffectsToContainer="true" PanelClass="pa-4" @key="computer.Name" @ref="MudTabsDict[computer.Name]">
<MudTabPanel Icon="@Icons.Material.Outlined.Filter1" ID="@("v1")" Text="v1" Disabled=@(!computer.LAPSInformations!.Any(x => x.Version == Enums.LAPSVersion.v1 && x.IsCurrent))>
<LapsInformationDetail LapsInfo="computer.LAPSInformations!.SingleOrDefault(x => x.Version == Enums.LAPSVersion.v1)" />
</MudTabPanel>
<MudTabPanel Icon="@Icons.Material.Outlined.Filter2" ID="@("v2")" Text="v2" Disabled=@(!computer.LAPSInformations!.Any(x => x.Version == Enums.LAPSVersion.v2 && x.IsCurrent))>
<LapsInformationDetail LapsInfo="computer.LAPSInformations!.SingleOrDefault(x => x.Version == Enums.LAPSVersion.v2 && x.IsCurrent)" />
</MudTabPanel>
<MudTabPanel Icon="@Icons.Material.Outlined.History" ID="@("history")" Text="History" Disabled=@(!computer.LAPSInformations!.Any(x => x.Version == Enums.LAPSVersion.v2 && !x.IsCurrent))>
<MudSimpleTable Style="overflow-x: auto;" Dense="true" Hover="true" Striped="true">
<thead>
<tr>
<th>Account</th>
<th>Password</th>
<th>Date set</th>
</tr>
</thead>
<tbody>
@foreach (var entry in computer.LAPSInformations!.Where(x => x.IsCurrent == false && x.Version == Enums.LAPSVersion.v2))
{
<tr>
<td>
@entry.Account
</td>
<td>
@entry.Password
</td>
<td>
@entry.PasswordSetDate
</td>
</tr>
}
</tbody>
</MudSimpleTable>
</MudTabPanel>
</MudTabs>
<MudTabs Position="Position.Top" Rounded="true" Border="false" ApplyEffectsToContainer="true" PanelClass="pa-4" @key="computer.Name" @ref="_mudTabsDict[computer.Name]">
<MudTabPanel Icon="@Icons.Material.Outlined.Filter1" ID="@("v1")" Text="v1" Disabled=@(!computer.LapsInformations!.Any(x => x is { Version: Enums.LAPSVersion.v1, IsCurrent: true }))>
<LapsInformationDetail LapsInfo="computer.LapsInformations!.SingleOrDefault(x => x.Version == Enums.LAPSVersion.v1)"/>
</MudTabPanel>
<MudTabPanel Icon="@Icons.Material.Outlined.Filter2" ID="@("v2")" Text="v2" Disabled=@(!computer.LapsInformations!.Any(x => x is { Version: Enums.LAPSVersion.v2, IsCurrent: true }))>
<LapsInformationDetail LapsInfo="computer.LapsInformations!.SingleOrDefault(x => x is { Version: Enums.LAPSVersion.v2, IsCurrent: true })"/>
</MudTabPanel>
<MudTabPanel Icon="@Icons.Material.Outlined.History" ID="@("history")" Text="History" Disabled=@(!computer.LapsInformations!.Any(x => x is { Version: Enums.LAPSVersion.v2, IsCurrent: false }))>
<MudSimpleTable Style="overflow-x: auto;" Dense="true" Hover="true" Striped="true">
<thead>
<tr>
<th>Account</th>
<th>Password</th>
<th>Date set</th>
</tr>
</thead>
<tbody>
@foreach (LapsInformation entry in computer.LapsInformations!.Where(x => x is { IsCurrent: false, Version: Enums.LAPSVersion.v2 }))
{
<tr>
<td>
@entry.Account
</td>
<td>
@entry.Password
</td>
<td>
@entry.PasswordSetDate
</td>
</tr>
}
</tbody>
</MudSimpleTable>
</MudTabPanel>
</MudTabs>
}
else
{
<MudAlert Icon="@Icons.Material.Outlined.Warning" ShowCloseIcon="false" Variant="Variant.Outlined" Severity="Severity.Warning">
<MudText Typo="Typo.inherit">No permission to retrieve LAPS Password or no LAPS Password set!</MudText>
</MudAlert>
<MudAlert Icon="@Icons.Material.Outlined.Warning" ShowCloseIcon="false" Variant="Variant.Outlined" Severity="Severity.Warning">
<MudText Typo="Typo.inherit">No permission to retrieve LAPS Password or no LAPS Password set!</MudText>
</MudAlert>
}
}
else
{
<div class="d-flex justify-center">
<MudProgressCircular Class="" Indeterminate="true" Size="Size.Large" Disabled=@(computer.Loading) />
</div>
}
</MudLoading>
</MudCardContent>
</MudCard>
</MudItem>
Expand Down
Loading

0 comments on commit 19fe763

Please sign in to comment.