Skip to content

Commit

Permalink
Merge pull request #2366 from abarz722/develop
Browse files Browse the repository at this point in the history
further modelling fixes + improvements
  • Loading branch information
tpurschke committed Mar 25, 2024
2 parents 1aa9a4c + fcef842 commit 80da5e3
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 137 deletions.
8 changes: 7 additions & 1 deletion roles/database/files/sql/idempotent/fworch-texts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,10 @@ INSERT INTO txt VALUES ('modelling_settings', 'German', 'Modellierungseinstel
INSERT INTO txt VALUES ('modelling_settings', 'English', 'Modelling Settings');
INSERT INTO txt VALUES ('modIconify', 'German', 'Nutzung von Piktogrammen');
INSERT INTO txt VALUES ('modIconify', 'English', 'Prefer use of Icons');
INSERT INTO txt VALUES ('use_in_src', 'German', 'in Quelle');
INSERT INTO txt VALUES ('use_in_src', 'English', 'in Source');
INSERT INTO txt VALUES ('use_in_dst', 'German', 'in Ziel');
INSERT INTO txt VALUES ('use_in_dst', 'English', 'in Destination');

-- monitoring
INSERT INTO txt VALUES ('open_alerts', 'German', 'Offene Alarme');
Expand Down Expand Up @@ -4441,9 +4445,11 @@ INSERT INTO txt VALUES ('H5619', 'German', 'Eigentümernamen verwenden: Der
INSERT INTO txt VALUES ('H5619', 'English', 'Use Owner Name: The name of the owner is used in the middle part of the naming convention for App Roles.');
INSERT INTO txt VALUES ('H5620', 'German', 'Gemeinsame Netzwerkareas: Vom Administrator vorgegebene Netzwerkareas, welche von allen Verbindungen genutzt werden dürfen.
Sie sind in der Bibliothek immer sichtbar und stehen dann nicht mehr in der Liste der auszuwählenden Areas für Common Services.
Die beiden Auswahlfelder "in Quelle" und "in Ziel" legen fest, wo die Netzwerkarea genutzt werden darf.
');
INSERT INTO txt VALUES ('H5620', 'English', 'Common Network Areas: Network areas defined by the administrator, which are permitted to be used by all connections.
They are visible in the object library and are not offered in the list of available areas for Common Services.
They are visible in the object library and are not offered in the list of available areas for Common Services.
The flags "in Source" and "in Destination" determine, where the Common Network Area are allowed to be used.
');
INSERT INTO txt VALUES ('H5621', 'German', 'Ein Modellierer kann einige persönliche Voreinstellungen für die Darstellung der Modellierung überschreiben.
Ausgangswert ist der vom Admin in den <a href="/help/settings/modelling">Modellierungseinstellungen</a> gesetzte Wert.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ mutation newAppServer(
$name: String
$appId: Int
$ip: cidr
$ipEnd: cidr
$importSource: String
) {
insert_owner_network(objects: {
name: $name
owner_id: $appId
ip: $ip
ip_end: $ip
ip_end: $ipEnd
import_source: $importSource
is_deleted: false
nw_type: 10
Expand Down
134 changes: 83 additions & 51 deletions roles/lib/files/FWO.Api.Client/Data/DisplayBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
using NetTools;
using FWO.Logging;
using System.Net;
using System.Text.RegularExpressions;

namespace FWO.Api.Data
{
public static class DisplayBase
{
public static StringBuilder DisplayService(NetworkService service, bool isTechReport, string? serviceName = null)
{
StringBuilder result = new StringBuilder();
StringBuilder result = new ();
string ports = service.DestinationPortEnd == null || service.DestinationPortEnd == 0 || service.DestinationPort == service.DestinationPortEnd ?
$"{service.DestinationPort}" : $"{service.DestinationPort}-{service.DestinationPortEnd}";
if (isTechReport)
{
if (service.DestinationPort == null)
{
result.Append($"{service.Name}");
if (service.Protocol?.Name != null)
{
result.Append($"{service.Protocol?.Name}");
}
else
{
result.Append($"{service.Name}");
}
}
else
{
Expand All @@ -41,18 +47,21 @@ public static StringBuilder DisplayService(NetworkService service, bool isTechRe

public static string DisplayIpWithName(NetworkObject elem)
{
string ip = DisplayIp(elem.IP, elem.IpEnd);
if(elem.Name != null && elem.Name != "")
{
return elem.Name + " (" + ip + ")";
return elem.Name + DisplayIp(elem.IP, elem.IpEnd, true);
}
return ip;
return DisplayIp(elem.IP, elem.IpEnd);
}

public static string DisplayIp(string ip1, string ip2, bool inBrackets = false)
{
try
{
if (ip2 == "")
{
ip2 = ip1;
}
string nwObjType = AutoDetectType(ip1, ip2);
return DisplayIp(ip1, ip2, nwObjType, inBrackets);
}
Expand All @@ -66,72 +75,88 @@ public static string DisplayIp(string ip1, string ip2, bool inBrackets = false)
public static string DisplayIp(string ip1, string ip2, string nwObjType, bool inBrackets = false)
{
string result = "";
IPAddressRange IpRange;
string IpStart;
string IpEnd;
if (nwObjType != ObjectType.Group)
{
if (ip2 == null)
if (!IsV4Address(ip1) && !IsV6Address(ip1))
{
Log.WriteError("Ip displaying", $"Found undefined IP family: {ip1} - {ip2}");
}
else if (IsV4Address(ip1) == IsV6Address(ip2))
{
Log.WriteError("Ip displaying", $"Found undefined IpEnd {ip2}");
Log.WriteError("Ip displaying", $"Found mixed IP family: {ip1} - {ip2}");
}
else
{
if (!isV4Address(ip1) && !isV6Address(ip1))
if (ip2 == "")
{
Log.WriteError("Ip displaying", $"Found undefined IP family: {ip1} - {ip2}");
ip2 = ip1;
}
else
{
if (isV4Address(ip1))
{
IpStart = ip1.Replace("/32", "");
IpEnd = ip2.Replace("/32", "");
}
else
{
IpStart = ip1.Replace("/128", "");
IpEnd = ip2.Replace("/128", "");
}
string IpStart = StripOffUnnecessaryNetmask(ip1);
string IpEnd = StripOffUnnecessaryNetmask(ip2);

try
try
{
result = inBrackets ? " (" : "";
if (nwObjType == ObjectType.Network)
{
IpRange = new IPAddressRange(IPAddress.Parse(IpStart), IPAddress.Parse(IpEnd));
if (IpRange != null)
if(GetNetmask(IpStart) == "")
{
result = inBrackets ? " (" : "";
if (nwObjType == ObjectType.Network)
{
result += IpRange.ToCidrString();
}
else
IPAddressRange ipRange = new (IPAddress.Parse(IpStart), IPAddress.Parse(IpEnd));
if (ipRange != null)
{
result += IpStart;
if (nwObjType.Contains(ObjectType.IPRange))
{
result += $"-{IpEnd}";
}
result += ipRange.ToCidrString();
}
result += inBrackets ? ")" : "";
}
else
{
result += IpStart;
}
}
catch (Exception exc)
else
{
Log.WriteError("Ip displaying", $"Wrong ip format {IpStart} - {IpEnd}\nMessage: {exc.Message}");
result += IpStart;
if (nwObjType == ObjectType.IPRange)
{
result += $"-{IpEnd}";
}
}
result += inBrackets ? ")" : "";
}
catch (Exception exc)
{
Log.WriteError("Ip displaying", $"Wrong ip format {IpStart} - {IpEnd}\nMessage: {exc.Message}");
}
}
}
return result;
}

public static string GetNetmask(string ip)
{
int pos = ip.LastIndexOf("/");
if (pos > -1 && ip.Length > pos + 1)
{
return ip[(pos + 1)..];
}
return "";
}

private static string StripOffNetmask(string ip)
{
Match match = Regex.Match(ip, @"^([\d\.\:]+)\/");
if (match.Success)
int pos = ip.LastIndexOf("/");
if (pos > -1 && ip.Length > pos + 1)
{
return ip[..pos];
}
return ip;
}

private static string StripOffUnnecessaryNetmask(string ip)
{
string netmask = GetNetmask(ip);
if (IsV4Address(ip) && netmask == "32" || IsV6Address(ip) && netmask == "128")
{
string matchedString = match.Value;
return matchedString.Remove( matchedString.Length - 1 );
return StripOffNetmask(ip);
}
return ip;
}
Expand All @@ -152,10 +177,17 @@ private static bool SpanSingleNetwork(string ipInStart, string ipInEnd)
return true;
}

private static string AutoDetectType(string ip1, string ip2)
public static string AutoDetectType(string ip1, string ip2)
{
ip1 = StripOffUnnecessaryNetmask(ip1);
ip2 = StripOffUnnecessaryNetmask(ip2);
if (ip1 == ip2)
{
string netmask = GetNetmask(ip1);
if(netmask != "")
{
return ObjectType.Network;
}
return ObjectType.Host;
}
if (SpanSingleNetwork(ip1, ip2))
Expand All @@ -165,14 +197,14 @@ private static string AutoDetectType(string ip1, string ip2)
return ObjectType.IPRange;
}

private static bool isV6Address(string ip)
private static bool IsV6Address(string ip)
{
return ip.Contains(":");
return ip.Contains(':');
}

private static bool isV4Address(string ip)
private static bool IsV4Address(string ip)
{
return ip.Contains(".");
return ip.Contains('.');
}
}
}
9 changes: 7 additions & 2 deletions roles/lib/files/FWO.Api.Client/Data/ModellingAppServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class ModellingAppServer : ModellingNwObject
[JsonProperty("ip"), JsonPropertyName("ip")]
public string Ip { get; set; } = "";

[JsonProperty("ip_end"), JsonPropertyName("ip_end")]
public string IpEnd { get; set; } = "";

[JsonProperty("import_source"), JsonPropertyName("import_source")]
public string ImportSource { get; set; } = "";

Expand All @@ -34,6 +37,7 @@ public override bool Sanitize()
{
bool shortened = base.Sanitize();
Ip = Sanitizer.SanitizeCidrMand(Ip, ref shortened);
IpEnd = Sanitizer.SanitizeCidrMand(IpEnd, ref shortened);
ImportSource = Sanitizer.SanitizeMand(ImportSource, ref shortened);
return shortened;
}
Expand All @@ -46,7 +50,7 @@ public static NetworkObject ToNetworkObject(ModellingAppServer appServer)
Number = appServer.Number,
Name = appServer.Name,
IP = appServer.Ip,
IpEnd = appServer.Ip
IpEnd = appServer.IpEnd
};
}

Expand All @@ -61,6 +65,7 @@ public ModellingAppServer(ModellingAppServer appServer)
Name = appServer.Name;
IsDeleted = appServer.IsDeleted;
Ip = appServer.Ip;
IpEnd = appServer.IpEnd;
ImportSource = appServer.ImportSource;
InUse = appServer.InUse;
}
Expand All @@ -70,7 +75,7 @@ public override bool Equals(object? obj)
return obj switch
{
ModellingAppServer apps => Id == apps.Id && AppId == apps.AppId && Name == apps.Name && IsDeleted == apps.IsDeleted
&& Ip == apps.Ip && ImportSource == apps.ImportSource && InUse == apps.InUse,
&& Ip == apps.Ip && IpEnd == apps.IpEnd && ImportSource == apps.ImportSource && InUse == apps.InUse,
_ => base.Equals(obj),
};
}
Expand Down
32 changes: 32 additions & 0 deletions roles/lib/files/FWO.Config.Api/Data/CommonArea.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using FWO.Api.Data;

namespace FWO.Config.Api.Data
{
public class CommonAreaConfig
{
[JsonProperty("area_id"), JsonPropertyName("area_id")]
public long AreaId { get; set; } = 0;

[JsonProperty("use_in_src"), JsonPropertyName("use_in_src")]
public bool UseInSrc { get; set; } = true;

[JsonProperty("use_in_dst"), JsonPropertyName("use_in_dst")]
public bool UseInDst { get; set; } = true;
}

public class CommonArea
{
public ModellingNwGroupWrapper Area { get; set; } = new();

public bool UseInSrc { get; set; } = true;

public bool UseInDst { get; set; } = true;

public CommonAreaConfig ToConfigItem()
{
return new(){ AreaId = Area.Content.Id, UseInSrc = UseInSrc, UseInDst = UseInDst};
}
}
}
3 changes: 2 additions & 1 deletion roles/lib/files/FWO.Report.Filter/Ast/AstNodeFilterInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ private DynGraphqlQuery ExtractDestinationPortFilter(DynGraphqlQuery query)
string queryVarName = AddVariable<int>(query, "dport", Operator.Kind, semanticValue);
query.ruleWhereStatement += "rule_services: { service: { svcgrp_flats: { serviceBySvcgrpFlatMemberId: { svc_port: {_lte" +
": $" + queryVarName + "}, svc_port_end: {_gte: $" + queryVarName + " } } } } }";
query.connectionWhereStatement += $"service_connections: {{service: {{port: {{ _lte: ${queryVarName} }}, port_end: {{ _gte: ${queryVarName} }} }} }}";
query.connectionWhereStatement += $"_or: [ {{ service_connections: {{service: {{ port: {{ _lte: ${queryVarName} }}, port_end: {{ _gte: ${queryVarName} }} }} }} }}, " +
$"{{ service_group_connections: {{service_group: {{ service_service_groups: {{ service: {{ port: {{ _lte: ${queryVarName} }}, port_end: {{ _gte: ${queryVarName} }} }} }} }} }} }} ]";
return query;
}

Expand Down
9 changes: 6 additions & 3 deletions roles/lib/files/FWO.Report.Filter/Ast/AstNodeFilterString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private DynGraphqlQuery ExtractProtocolFilter(DynGraphqlQuery query)
{
string queryVarName = AddVariable<string>(query, "proto", Operator.Kind, semanticValue!);
query.ruleWhereStatement += $"rule_services: {{service: {{stm_ip_proto: {{ip_proto_name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }}";
query.connectionWhereStatement += $"service_connections: {{service: {{stm_ip_proto: {{ip_proto_name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }}";
query.connectionWhereStatement += $"_or: [ {{ service_connections: {{service: {{stm_ip_proto: {{ip_proto_name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }} }}, " +
$"{{ service_group_connections: {{service_group: {{ service_service_groups: {{ service: {{ stm_ip_proto: {{ip_proto_name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }} }} }} }} ]";
return query;
}

Expand All @@ -137,8 +138,10 @@ private DynGraphqlQuery ExtractActionFilter(DynGraphqlQuery query)
private DynGraphqlQuery ExtractServiceFilter(DynGraphqlQuery query)
{
string queryVarName = AddVariable<string>(query, "svc", Operator.Kind, semanticValue!);
query.ruleWhereStatement += $"rule_services: {{ service: {{svcgrp_flats: {{serviceBySvcgrpFlatMemberId: {{svc_name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }} }} ";
query.connectionWhereStatement += $"_or: [ {{ service_connections: {{service: {{name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }}, {{ service_group_connections: {{service_group: {{name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }} ]";
query.ruleWhereStatement += $"rule_services: {{ service: {{ svcgrp_flats: {{ serviceBySvcgrpFlatMemberId: {{ svc_name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }} }} ";
query.connectionWhereStatement += $"_or: [ {{ service_connections: {{ service: {{ name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }}, " +
$"{{ service_group_connections: {{service_group: {{ _or: [ {{ name: {{ {ExtractOperator()}: ${queryVarName} }} }}, " +
$"{{ service_service_groups: {{ service: {{ name: {{ {ExtractOperator()}: ${queryVarName} }} }} }} }} ] }} }} }} ]";
return query;
}
}
Expand Down
10 changes: 8 additions & 2 deletions roles/lib/files/FWO.Report/ReportConnections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ private void AppendNetworkObjectsHtml(List<NetworkObject> networkObjects, ref St
{
report.AppendLine($"<h4>{userConfig.GetText("network_objects")}</h4>");
report.AppendLine("<table>");
AppendNWObjHeadlineHtml(ref report);
if(networkObjects.Count > 0)
{
AppendNWObjHeadlineHtml(ref report);
}
foreach (var nwObj in networkObjects)
{
report.AppendLine("<tr>");
Expand Down Expand Up @@ -164,7 +167,10 @@ private void AppendNetworkServicesHtml(List<NetworkService> networkServices, ref
{
report.AppendLine($"<h4>{userConfig.GetText("network_services")}</h4>");
report.AppendLine("<table>");
AppendNWSvcHeadlineHtml(ref report);
if(networkServices.Count > 0)
{
AppendNWSvcHeadlineHtml(ref report);
}
foreach (var svc in networkServices)
{
report.AppendLine("<tr>");
Expand Down
Loading

0 comments on commit 80da5e3

Please sign in to comment.