Skip to content

Commit

Permalink
Merge pull request CactuseSecurity#2443 from abarz722/develop
Browse files Browse the repository at this point in the history
Modelling enhancements
  • Loading branch information
tpurschke authored Jun 4, 2024
2 parents da795cd + 5c6bb3e commit aa7edab
Show file tree
Hide file tree
Showing 17 changed files with 311 additions and 150 deletions.
6 changes: 6 additions & 0 deletions roles/database/files/sql/idempotent/fworch-texts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,8 @@ INSERT INTO txt VALUES ('created_by', 'German', 'Erstellt von');
INSERT INTO txt VALUES ('created_by', 'English', 'Created by');
INSERT INTO txt VALUES ('requested_by', 'German', 'Beantragt von');
INSERT INTO txt VALUES ('requested_by', 'English', 'Requested by');
INSERT INTO txt VALUES ('for', 'German', 'für');
INSERT INTO txt VALUES ('for', 'English', 'for');
INSERT INTO txt VALUES ('log_change', 'German', 'Änderung loggen');
INSERT INTO txt VALUES ('log_change', 'English', 'Log Change');
INSERT INTO txt VALUES ('show_history', 'German', 'Änderungshistorie');
Expand Down Expand Up @@ -1461,6 +1463,10 @@ INSERT INTO txt VALUES ('default_app_server_type','German', 'Standardtyp');
INSERT INTO txt VALUES ('default_app_server_type','English','Default Type');
INSERT INTO txt VALUES ('replace', 'German', 'Ersetzen');
INSERT INTO txt VALUES ('replace', 'English', 'Replace');
INSERT INTO txt VALUES ('share_link', 'German', 'Link teilen');
INSERT INTO txt VALUES ('share_link', 'English', 'Share Link');
INSERT INTO txt VALUES ('copy_to_clipboard', 'German', 'in Zwischenablage kopieren');
INSERT INTO txt VALUES ('copy_to_clipboard', 'English', 'Copy to clipboard');

-- compliance
INSERT INTO txt VALUES ('compliance', 'German', 'Compliance');
Expand Down
2 changes: 2 additions & 0 deletions roles/lib/files/FWO.Api.Client/Data/Icons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public struct Icons
public const string Requirement = "oi oi-eye";
public const string Security = "oi oi-shield";
public const string FurtherReading = "oi oi-external-link";
public const string Clipboard = "oi oi-clipboard";

// Actions
public const string Add = "oi oi-plus";
Expand All @@ -27,6 +28,7 @@ public struct Icons
public const string CollapseDown = "oi oi-collapse-down";
public const string CollapseLeft = "oi oi-collapse-left";
public const string CollapseRight = "oi oi-collapse-right";
public const string Share = "oi oi-fork"; // oi-share-boxed? oi-share?

// Object types: General
public const string Ldap = "oi oi-key";
Expand Down
2 changes: 2 additions & 0 deletions roles/lib/files/FWO.GlobalConstants/GlobalConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public struct GlobalConst
public const int kTenant0Id = 1;

public const int kSidebarLeftWidth = 300;
public const int kGlobLibraryWidth = kSidebarLeftWidth + 400;
public const int kObjLibraryWidth = kSidebarLeftWidth + 300;
public const int kSidebarRightWidth = 300;
public const int kHoursToMilliseconds = 3600000;

Expand Down
15 changes: 7 additions & 8 deletions roles/lib/files/FWO.Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ namespace FWO.Logging
{
public static class Log
{
private static SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
private static string lockFilePath = $"/var/fworch/lock/{Assembly.GetEntryAssembly()?.GetName().Name}_log.lock";
private static Random random = new Random();
private static SemaphoreSlim semaphore = new (1, 1);
private static readonly string lockFilePath = $"/var/fworch/lock/{Assembly.GetEntryAssembly()?.GetName().Name}_log.lock";
private static readonly Random random = new ();

static Log()
{
Task.Factory.StartNew(async () =>
{
// log switch - log file locking
bool logOwnedByExternal = false;
Stopwatch stopwatch = new Stopwatch();
Stopwatch stopwatch = new ();

while (true)
{
Expand All @@ -25,13 +25,13 @@ static Log()
// Open file
using FileStream file = await GetFile(lockFilePath);
// Read file content
using StreamReader reader = new StreamReader(file);
using StreamReader reader = new (file);
string lockFileContent = (await reader.ReadToEndAsync()).Trim();

// Forcefully release lock after timeout
if (logOwnedByExternal && stopwatch.ElapsedMilliseconds > 10_000)
{
using StreamWriter writer = new StreamWriter(file);
using StreamWriter writer = new (file);
await writer.WriteLineAsync("FORCEFULLY RELEASED");
stopwatch.Reset();
semaphore.Release();
Expand Down Expand Up @@ -59,7 +59,7 @@ static Log()
stopwatch.Restart();
logOwnedByExternal = true;
}
using StreamWriter writer = new StreamWriter(file);
using StreamWriter writer = new (file);
await writer.WriteLineAsync("GRANTED");
}
// RELEASED - lock was released by log swap process
Expand Down Expand Up @@ -128,7 +128,6 @@ public static void WriteError(string Title, string? Text = null, Exception? Erro
$"Stack Trace: \n {Error?.StackTrace?.TrimStart()}"
: "");


WriteLog("Error", Title, DisplayText, callerName, callerFile, callerLineNumber, ConsoleColor.Red);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@


private ModellingDnDContainer Container { get; set; } = new();
int sidebarLeftWidth = GlobalConst.kSidebarLeftWidth + 300;
int sidebarLeftWidth = GlobalConst.kObjLibraryWidth;

private List<ModellingNetworkArea> areas = new();
private ModellingAppRole unchangedAppRole = new();
Expand Down
5 changes: 2 additions & 3 deletions roles/ui/files/FWO.UI/Pages/NetworkModelling/EditConn.razor
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
}
}
}
else
else
{
<div class="@DestClass()"
ondragover="event.preventDefault();"
Expand Down Expand Up @@ -373,7 +373,7 @@


private ModellingDnDContainer Container { get; set; } = new();
private int sidebarInitWidth = GlobalConst.kSidebarLeftWidth + 400;
private int sidebarInitWidth = GlobalConst.kGlobLibraryWidth;
private int sidebarLeftWidth;

private List<ModellingService> services = new();
Expand Down Expand Up @@ -619,7 +619,6 @@

private void Cancel()
{
sidebarLeftWidth = sidebarInitWidth;
ConnHandler.Reset();
Close();
}
Expand Down
108 changes: 72 additions & 36 deletions roles/ui/files/FWO.UI/Pages/NetworkModelling/EditConnLeftSide.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@
@inject ApiConnection apiConnection
@inject UserConfig userConfig

<Sidebar Collapsible="true" Resizeable="true" PositionLeft="true" @bind-Width="sidebarLeftWidth" >
<Sidebar Collapsible="true" Resizeable="true" PositionLeft="true" @bind-Width="sidebarLeftWidth" StartCollapsed="ConnHandler.LastCollapsed">
<h3>
<div class="d-flex col-sm-12 pad-10 mt-3 me-auto justify-content-between">
<div >@(userConfig.GetText("library")) </div>
<div >@(userConfig.GetText("library"))&nbsp</div>
<div class="align-self-end"><small>@ConnHandler.Application.Display()</small></div>
</div>
</h3>
<div class="col-sm-12 me-auto border rounded p-2">
<h5>@(userConfig.GetText("network_objects"))</h5>
<div class="form-group row">
<div class="col-sm-10">
<div class="@ColWidthClass()">
<DraggableList AllElements="ConnHandler.AvailableNwElems" @bind-SelectedElements="selectedNwElems"
HandleDragStart="HandleNwDragStart" Display="@DisplayNwObject" MaxHeight="25"/>
</div>
<div class="col-sm-2">
@if(!ConnHandler.SrcDropForbidden() && selectedNwElems.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100" @onclick="() =>
{NetworkElemsToConn(true); ConnHandlerChanged.InvokeAsync(ConnHandler);}">
@(ConnHandler.DisplayButton("to_source", Icons.Use, "source"))</button>
}
@if(!ConnHandler.DstDropForbidden() && selectedNwElems.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100 mt-2" @onclick="() =>
{NetworkElemsToConn(false); ConnHandlerChanged.InvokeAsync(ConnHandler);}">
@(ConnHandler.DisplayButton("to_dest", Icons.Use, "destination"))</button>
}
</div>
@if(!OverviewMode)
{
<div class="col-sm-2">
@if(!ConnHandler.SrcDropForbidden() && selectedNwElems.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100" @onclick="() =>
{NetworkElemsToConn(true); ConnHandlerChanged.InvokeAsync(ConnHandler);}">
@(ConnHandler.DisplayButton("to_source", Icons.Use, "source"))</button>
}
@if(!ConnHandler.DstDropForbidden() && selectedNwElems.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100 mt-2" @onclick="() =>
{NetworkElemsToConn(false); ConnHandlerChanged.InvokeAsync(ConnHandler);}">
@(ConnHandler.DisplayButton("to_dest", Icons.Use, "destination"))</button>
}
</div>
}
</div>
<div class="btn-group mt-1">
@if(ConnHandler.Application.CommSvcPossible)
Expand Down Expand Up @@ -74,18 +77,21 @@
{
<h5>@(userConfig.GetText("services"))</h5>
<div class="form-group row">
<div class="col-sm-10">
<div class="@ColWidthClass()">
<DraggableList AllElements="ConnHandler.AvailableSvcElems" @bind-SelectedElements="selectedSvcElems"
HandleDragStart="HandleSvcDragStart" Display="@DisplaySvcObject" MaxHeight="25"/>
</div>
<div class="col-sm-2">
@if(selectedSvcElems.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100" @onclick="() =>
{ServiceElemsToConn(); ConnHandlerChanged.InvokeAsync(ConnHandler);}">
@(ConnHandler.DisplayButton("to_service", Icons.Use))</button>
}
</div>
@if(!OverviewMode)
{
<div class="col-sm-2">
@if(selectedSvcElems.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100" @onclick="() =>
{ServiceElemsToConn(); ConnHandlerChanged.InvokeAsync(ConnHandler);}">
@(ConnHandler.DisplayButton("to_service", Icons.Use))</button>
}
</div>
}
</div>
<div class="btn-group mt-1">
<button type="button" class="btn btn-sm btn-success" @onclick="() => {ConnHandler.CreateServiceGroup(); ConnHandlerChanged.InvokeAsync(ConnHandler);}">
Expand Down Expand Up @@ -135,17 +141,20 @@
<br><br>
<h5>@(userConfig.GetText("interfaces"))</h5>
<div class="form-group row">
<div class="col-sm-10">
<div class="@ColWidthClass()">
<DraggableList AllElements="ConnHandler.PreselectedInterfaces" @bind-SelectedElements="selectedInterfaces"
HandleDragStart="HandleConnDragStart" Display="@DisplayInterfaceWithIcon" MaxHeight="15" Multiselect="false"/>
</div>
<div class="col-sm-2">
@if(selectedInterfaces.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100" @onclick="() => {InterfaceToConn(selectedInterfaces[0]);}">
@(ConnHandler.DisplayButton("use", Icons.Use))</button>
}
</div>
@if(!OverviewMode)
{
<div class="col-sm-2">
@if(selectedInterfaces.Count > 0)
{
<button type="button" class="btn btn-sm btn-primary w-100" @onclick="() => {InterfaceToConn(selectedInterfaces[0]);}">
@(ConnHandler.DisplayButton("use", Icons.Use))</button>
}
</div>
}
</div>
<div class="btn-group mt-1">
<button type="button" class="btn btn-sm btn-success" @onclick="SearchInterface">
Expand All @@ -165,7 +174,7 @@
</div>
<br>
}
else if(ConnHandler.ActConn.IsInterface && ConnHandler.ActConn.IsRequested)
else if(ConnHandler.ActConn.IsInterface && ConnHandler.ActConn.IsRequested && !OverviewMode)
{
<br><br>
<h5>@(userConfig.GetText("own_interfaces"))</h5>
Expand Down Expand Up @@ -229,14 +238,36 @@
[Parameter]
public EventCallback<ModellingConnectionHandler> ConnHandlerChanged { get; set; }

[Parameter]
public bool OverviewMode { get; set; } = false;

private List<KeyValuePair<int, long>> selectedNwElems = new();
private List<KeyValuePair<int, int>> selectedSvcElems = new();
private List<ModellingConnection> selectedInterfaces = new();
private bool SearchInterfaceMode = false;
private bool SearchNwObjectMode = false;
private bool SelectAppMode = false;
private int sidebarLeftWidth { get { return Width; } set { Width = value; WidthChanged.InvokeAsync(Width);}}
private int sidebarLeftWidth
{
get { return Width; }
set
{
Width = value;
if(OverviewMode)
{
if(value == 0)
{
ConnHandler.LastCollapsed = true;
}
else
{
ConnHandler.LastCollapsed = false;
ConnHandler.LastWidth = value;
}
}
WidthChanged.InvokeAsync(Width);
}
}


private string DisplayInterfaceWithIcon(ModellingConnection interf)
Expand Down Expand Up @@ -562,4 +593,9 @@
await calledFunc();
await ConnHandlerChanged.InvokeAsync(ConnHandler);
}

private string ColWidthClass()
{
return OverviewMode ? "col-sm-12" : "col-sm-10";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
public bool AsAdmin { get; set; } = false;

private ModellingDnDContainer Container { get; set; } = new();
int sidebarLeftWidth = GlobalConst.kSidebarLeftWidth + 300;
int sidebarLeftWidth = GlobalConst.kObjLibraryWidth;
private bool workInProgress = false;
private bool firstTry = true;
private ModellingServiceGroup unchangedServiceGroup = new();
Expand Down
Loading

0 comments on commit aa7edab

Please sign in to comment.