Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avalonia UI Improvements #63

Merged
merged 20 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
55a00b5
created view for scan configuration
ewilliams0305 Apr 13, 2024
2c2d42a
created scan factory and view
ewilliams0305 Apr 13, 2024
3cc376b
Merge pull request #52 from ewilliams0305/scan-mode-control
ewilliams0305 Apr 13, 2024
fc98f1a
created adapter model
ewilliams0305 Apr 28, 2024
6219acc
renamed field
ewilliams0305 Apr 28, 2024
d7ede56
added scan mode to factory
ewilliams0305 Jun 2, 2024
0f187bb
passed scan options to factory
ewilliams0305 Jun 2, 2024
fd3bcc9
added configured options to delegate factory
ewilliams0305 Jun 2, 2024
0fd96f1
Merge pull request #54 from ewilliams0305/recent-scans-ip
ewilliams0305 Jun 2, 2024
a6794cf
refactored callback as tuple for labels
ewilliams0305 Jun 2, 2024
49c9653
Merge pull request #55 from ewilliams0305/recent-scans-ip
ewilliams0305 Jun 2, 2024
e198c6f
create address validation method
ewilliams0305 Jun 2, 2024
8d9f17d
Merge pull request #57 from ewilliams0305/IP-Address-Form-Validation
ewilliams0305 Jun 2, 2024
f27f1c5
reset factory when data is updated
ewilliams0305 Jun 2, 2024
3a4a76f
Merge pull request #59 from ewilliams0305/58-scan-mode-validation-reset
ewilliams0305 Jun 2, 2024
ff18032
added message containing validation failures
ewilliams0305 Jun 2, 2024
4fe6aa5
Merge pull request #61 from ewilliams0305/60-factory-exceptions-as-va…
ewilliams0305 Jun 2, 2024
b12abe2
Merge pull request #62 from ewilliams0305/scan-mode-control
ewilliams0305 Jun 2, 2024
6f77a47
Update README.md
ewilliams0305 Jun 2, 2024
7c8714f
updated versions
ewilliams0305 Jun 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ The kangaroo network scanner supports (or will support) the following features.
4. [Scanning Networks](#Scanning-Networks)

# Desktop Guide
Complete desktop user guid TDB, for now heres the status:

Desktop UI supports IP Scans with:
- Network Adapter Selection
- IP Address Range
- Subnet Calculation up to /16
- Single Address

Dashboard will display recent scans
- Allows user to select scans for comparison
- Allows user to view latency information

Configuration and compliance views are non-functional

# Command Line Tool

Expand Down
5 changes: 3 additions & 2 deletions source/Kangaroo.CLI/Kangaroo.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
<Nullable>enable</Nullable>
<AssemblyName>$(AssemblyName)</AssemblyName>
<ApplicationIcon>kangaroo.ico</ApplicationIcon>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackAsTool>True</PackAsTool>
<ToolCommandName>kangaroo</ToolCommandName>
<PackageOutputPath>..\..\release</PackageOutputPath>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionPrefix>0.2.1</VersionPrefix>
<Title>Kangaroo CLI Tool</Title>
<Description>A command line IP scanner</Description>
<Copyright></Copyright>
<PackageProjectUrl>https://github.com/ewilliams0305/kangaroo</PackageProjectUrl>
<PackageIcon>kangaroo-logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/ewilliams0305/kangaroo</RepositoryUrl>
<PackageOutputPath>..\..\release\</PackageOutputPath>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions source/Kangaroo.UI.Desktop/Kangaroo.UI.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
One for Windows with net7.0-windows TFM, one for MacOS with net7.0-macos and one with net7.0 TFM for Linux.-->
<TargetFramework>net8.0</TargetFramework>
<VersionPrefix>0.2.1</VersionPrefix>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down
8 changes: 7 additions & 1 deletion source/Kangaroo.UI/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:styling="clr-namespace:FluentAvalonia.Styling;assembly=FluentAvalonia"
xmlns:local="using:Kangaroo.UI"
xmlns:controls="clr-namespace:Kangaroo.UI.Controls"
x:Class="Kangaroo.UI.App"
RequestedThemeVariant="Default">
RequestedThemeVariant="Dark">

<Application.DataTemplates>
<local:ViewLocator/>
Expand All @@ -13,4 +14,9 @@
<StyleInclude Source="avares://Kangaroo.UI/Assets/Icons.axaml"/>
<StyleInclude Source="avares://Kangaroo.UI/Assets/ButtonStyles.axaml"/>
</Application.Styles>

<Application.Resources>
<controls:ScanModeTextConverter x:Key="ScanModeTextConverter"/>
<controls:NetworkAdapterTextConverter x:Key="NetworkAdapterTextConverter"/>
</Application.Resources>
</Application>
21 changes: 21 additions & 0 deletions source/Kangaroo.UI/Controls/ScanConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using Kangaroo.UI.Models;

namespace Kangaroo.UI.Controls;

public sealed class ScanConfiguration
{
public ScanMode ScanMode { get; set; }
public bool WithHttp { get; set; }
public int Ttl { get; set; }
public TimeSpan Timeout { get; set; }
public IPAddress? StartAddress { get; set; }
public IPAddress? EndAddress { get; set; }
public IPAddress? SpecificAddress { get; set; }
public IPAddress? NetmaskAddress { get; set; }
public IEnumerable<IPAddress>? SpecificAddresses { get; set; }
public NetworkInterface? NetworkInterface { get; set; }
}
57 changes: 57 additions & 0 deletions source/Kangaroo.UI/Controls/ScanModeTextConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Globalization;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Kangaroo.UI.Models;

namespace Kangaroo.UI.Controls;

public class ScanModeTextConverter : IValueConverter
{
public static readonly ScanModeTextConverter Instance = new();

public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is ScanMode mode && targetType.IsAssignableTo(typeof(string)))
{
return mode switch
{
ScanMode.NetworkSubnet => "Network Subnet",
ScanMode.AddressRange => "IP Address Range",
ScanMode.NetworkAdapter => "Network Adapter",
ScanMode.SingleAddress => "IP Address",
ScanMode.SpecifiedAddresses => "IP Addresses",
_ => throw new ArgumentOutOfRangeException()
};
}

return new BindingNotification(new InvalidCastException(), BindingErrorType.Error);
}

public object ConvertBack(object? value, Type targetType,
object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}

public class NetworkAdapterTextConverter : IValueConverter
{
public static readonly ScanModeTextConverter Instance = new();

public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is NetworkAdapter apt && targetType.IsAssignableTo(typeof(string)))
{
return $"{apt.Name} | {apt.IpAddress} | {apt.MacAddress}";
}

return new BindingNotification(new InvalidCastException(), BindingErrorType.Error);
}

public object ConvertBack(object? value, Type targetType,
object? parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
5 changes: 5 additions & 0 deletions source/Kangaroo.UI/Kangaroo.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<VersionPrefix>0.2.1</VersionPrefix>
<LangVersion>latest</LangVersion>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
Expand Down Expand Up @@ -58,4 +59,8 @@
<SubType>Designer</SubType>
</AvaloniaXaml>
</ItemGroup>

<ItemGroup>
<Folder Include="Converters\" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions source/Kangaroo.UI/Models/NetworkAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Kangaroo.UI.Models;

/// <summary>
/// Model to store all required network adapter data.
/// </summary>
public class NetworkAdapter
{
/// <summary>
/// Name of the adapter
/// </summary>
public string Name { get; set; } = string.Empty;

/// <summary>
/// IP Address currently assigned to the adapter.
/// </summary>
public string IpAddress { get; set; } = string.Empty;

/// <summary>
/// Physical address of the adapter.
/// </summary>
public string MacAddress { get; set; } = string.Empty;
}
65 changes: 65 additions & 0 deletions source/Kangaroo.UI/Services/ContainerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using Kangaroo.UI.Controls;
using Kangaroo.UI.Services.Database;
using Kangaroo.UI.ViewModels;
using Kangaroo.UI.Views;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ScanConfiguratorView = Kangaroo.UI.Views.ScanConfiguratorView;
using ScanConfiguratorViewModel = Kangaroo.UI.ViewModels.ScanConfiguratorViewModel;

namespace Kangaroo.UI.Services;

public static class ContainerExtensions
{
public static HostApplicationBuilder AddKangaroo(this HostApplicationBuilder builder, Action<ServiceOptions>? options = null)
{
var ops = new ServiceOptions();
options?.Invoke(ops);

return builder
.AddDatabaseServices(ops)
.AddScannerServices(ops)
.AddViewModels(ops);
}

public static HostApplicationBuilder AddDatabaseServices(this HostApplicationBuilder builder, ServiceOptions options)
{
builder.Services.AddTransient<IDbConnectionFactory, SqliteDbConnectionFactory>(sp => new SqliteDbConnectionFactory(options.DatabaseConnection));
builder.Services.AddTransient<IDbInitializer, SqliteDbInitializer>();

builder.Services.AddTransient<RecentScansRepository>();
return builder;
}
public static HostApplicationBuilder AddScannerServices(this HostApplicationBuilder builder, ServiceOptions options)
{
builder.Services.AddTransient<IScannerBuilder, ScannerBuilder>();
builder.Services.AddSingleton<IScannerFactory, ScannerFactory>();
return builder;
}

public static HostApplicationBuilder AddViewModels(this HostApplicationBuilder builder, ServiceOptions options)
{
builder.Services.AddTransient<MainWindow>();
builder.Services.AddTransient<MainView>();
builder.Services.AddTransient<MainViewModel>();

builder.Services.AddTransient<HomePageView>();
builder.Services.AddTransient<HomePageViewModel>();

builder.Services.AddTransient<IpScannerView>();
builder.Services.AddSingleton<IpScannerViewModel>();

builder.Services.AddTransient<PortScannerView>();
builder.Services.AddTransient<PortScannerViewModel>();

builder.Services.AddTransient<ConfigurationView>();
builder.Services.AddTransient<ConfigurationViewModel>();


builder.Services.AddTransient<ScanConfiguratorView>();
builder.Services.AddTransient<ScanConfiguratorViewModel>();

return builder;
}
}
37 changes: 23 additions & 14 deletions source/Kangaroo.UI/Services/Database/RecentScans/RecentScan.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net;
using Kangaroo.UI.Controls;
using Kangaroo.UI.Models;

namespace Kangaroo.UI.Services.Database;
Expand All @@ -17,10 +18,23 @@ public sealed class RecentScan
public TimeSpan ElapsedTime { get; set; }
public int OnlineDevices { get; set; }

public static RecentScan FromResults(ScanResults? results, ScanConfiguration config, TimeProvider time) =>
results == null
? new RecentScan()
: new RecentScan
{
Id = Guid.NewGuid(),
ScanMode = config.ScanMode,
StartAddress = results.StartAddress.ToString(),
EndAddress = results.EndAddress.ToString(),
CreatedDateTime = time.GetLocalNow().DateTime,
ElapsedTime = results.ElapsedTime,
OnlineDevices = results.NumberOfAliveNodes
};


public static RecentScan FromRange(string start, string end, TimeProvider time, TimeSpan elapsedTime, int onlineDevices)
{
return new RecentScan
public static RecentScan FromRange(string start, string end, TimeProvider time, TimeSpan elapsedTime, int onlineDevices) =>
new()
{
Id = Guid.NewGuid(),
ScanMode = ScanMode.AddressRange,
Expand All @@ -30,10 +44,9 @@ public static RecentScan FromRange(string start, string end, TimeProvider time,
ElapsedTime = elapsedTime,
OnlineDevices = onlineDevices
};
}
public static RecentScan FromAdapter(string adapter, IPAddress address, IPAddress subnet, TimeProvider time, TimeSpan elapsedTime, int onlineDevices)
{
return new RecentScan

public static RecentScan FromAdapter(string adapter, IPAddress address, IPAddress subnet, TimeProvider time, TimeSpan elapsedTime, int onlineDevices) =>
new()
{
Id = Guid.NewGuid(),
ScanMode = ScanMode.NetworkAdapter,
Expand All @@ -43,11 +56,9 @@ public static RecentScan FromAdapter(string adapter, IPAddress address, IPAddres
ElapsedTime = elapsedTime,
OnlineDevices = onlineDevices
};
}

public static RecentScan FromSubnet(IPAddress address, IPAddress subnet, TimeProvider time, TimeSpan elapsedTime, int onlineDevices)
{
return new RecentScan

public static RecentScan FromSubnet(IPAddress address, IPAddress subnet, TimeProvider time, TimeSpan elapsedTime, int onlineDevices) =>
new()
{
Id = Guid.NewGuid(),
ScanMode = ScanMode.NetworkSubnet,
Expand All @@ -57,6 +68,4 @@ public static RecentScan FromSubnet(IPAddress address, IPAddress subnet, TimePro
ElapsedTime = elapsedTime,
OnlineDevices = onlineDevices
};
}

}
21 changes: 21 additions & 0 deletions source/Kangaroo.UI/Services/IScannerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Kangaroo.UI.Controls;

namespace Kangaroo.UI.Services;

/// <summary>
/// Creates scanners from configuration options.
/// </summary>
public interface IScannerFactory
{
/// <summary>
/// Provides the scan and the required contextual data to run and display a scan.
/// </summary>
Action<(IScanner? scanner, ScanConfiguration? configuration, bool valid)>? OnScannerCreated { get; set; }

/// <summary>
/// Creates the correct scanner for the data provided
/// </summary>
/// <param name="options">scan configuration data</param>
void CreateScanner(ScanConfiguration options);
}
Loading
Loading