Skip to content

Commit f87fdb8

Browse files
authored
Merge branch 'develop' into Statistic-Report-Improvements-2254
2 parents b66ae10 + f82d3ca commit f87fdb8

File tree

62 files changed

+855
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+855
-259
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
.test_data/
44
roles/importer/venv/
55
ansible_venv/
6+
**/.venv/
67

78
.vscode/launch.json

roles/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## files generated by popular Visual Studio add-ons.
33
##
44
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5-
5+
**/.venv/
66
# User-specific files
77
*.rsuser
88
*.suo

roles/lib/files/FWO.Api.Client/GraphQlApiConnection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace FWO.Api.Client
1212
public class GraphQlApiConnection : ApiConnection
1313
{
1414
// Server URL
15-
public string ApiServerUri { get; private set; }
15+
public string ApiServerUri { get; private set; } = "";
1616

17-
private GraphQLHttpClient graphQlClient;
17+
private GraphQLHttpClient graphQlClient = null!;
1818

1919
private string prevRole = "";
2020

@@ -40,7 +40,7 @@ private void Initialize(string ApiServerUri)
4040
// 1 hour timeout
4141
graphQlClient.HttpClient.Timeout = new TimeSpan(1, 0, 0);
4242
}
43-
43+
4444
public GraphQlApiConnection(string ApiServerUri, string jwt)
4545
{
4646
Initialize(ApiServerUri);

roles/lib/files/FWO.Api.Client/GraphQlApiSubscription.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace FWO.Api.Client
77
{
88
public class GraphQlApiSubscription<SubscriptionResponseType> : ApiSubscription, IDisposable
99
{
10-
public delegate void SubscriptionUpdate(SubscriptionResponseType reponse);
10+
public delegate void SubscriptionUpdate(SubscriptionResponseType response);
1111
public event SubscriptionUpdate OnUpdate;
1212

13-
private IObservable<GraphQLResponse<dynamic>> subscriptionStream;
14-
private IDisposable subscription;
13+
private IObservable<GraphQLResponse<dynamic>> subscriptionStream = null!;
14+
private IDisposable subscription = null!;
1515
private readonly GraphQLHttpClient graphQlClient;
1616
private readonly GraphQLRequest request;
1717
private readonly Action<Exception> internalExceptionHandler;
@@ -20,7 +20,6 @@ public void Initialize()
2020
{
2121
CreateSubscription();
2222
}
23-
2423
public GraphQlApiSubscription(ApiConnection apiConnection, GraphQLHttpClient graphQlClient, GraphQLRequest request, Action<Exception> exceptionHandler, SubscriptionUpdate OnUpdate)
2524
{
2625
this.OnUpdate = OnUpdate;

roles/lib/files/FWO.Basics/StringExtensionsSanitizer.cs

Lines changed: 182 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,194 @@ public static string SanitizeMand(this string text)
1313

1414
public static string SanitizeMand(this string text, ref bool shortened)
1515
{
16-
string output = RemoveSpecialChars().Replace(text, "").Trim();
16+
string output = StandardSanitizationRegex().Replace(text, "").Trim();
1717
if (output.Length < text.Length)
1818
{
1919
shortened = true;
2020
}
2121
return output;
2222
}
2323

24-
[GeneratedRegex(@"[^\w\.\*\-\:\?@/\(\)\[\]\{\}\$\+<>#\$\=\, ]")]
25-
private static partial Regex RemoveSpecialChars();
24+
public static string? SanitizeOpt(this string? text, ref bool shortened)
25+
{
26+
if (text != null)
27+
{
28+
return text.SanitizeMand(ref shortened);
29+
}
30+
else return null;
31+
}
32+
33+
public static string SanitizeLdapNameMand(this string input, ref bool shortened)
34+
{
35+
string output = LdapNameRegex().Replace(input, "").Trim();
36+
if (output.Length < input.Length)
37+
{
38+
shortened = true;
39+
}
40+
return output;
41+
}
42+
43+
public static string? SanitizeLdapNameOpt(this string? input, ref bool shortened)
44+
{
45+
if (input != null)
46+
{
47+
return input.SanitizeLdapNameMand(ref shortened);
48+
}
49+
else return null;
50+
}
51+
52+
public static string SanitizeLdapPathMand(this string input, ref bool shortened)
53+
{
54+
string output = LdapPathRegex().Replace(input, "").Trim();
55+
if (output.Length < input.Length)
56+
{
57+
shortened = true;
58+
}
59+
return output;
60+
}
61+
62+
public static string? SanitizeLdapPathOpt(this string? input, ref bool shortened)
63+
{
64+
if (input != null)
65+
{
66+
return input.SanitizeLdapPathMand(ref shortened);
67+
}
68+
else return null;
69+
}
70+
71+
public static string SanitizePasswMand(this string input, ref bool shortened)
72+
{
73+
string output = PasswdRegex().Replace(input, "").Trim();
74+
if (output.Length < input.Length)
75+
{
76+
shortened = true;
77+
}
78+
return output;
79+
}
80+
81+
public static string? SanitizePasswOpt(this string? input, ref bool shortened)
82+
{
83+
if (input != null)
84+
{
85+
return input.SanitizePasswMand(ref shortened);
86+
}
87+
else return null;
88+
}
89+
90+
public static string SanitizeKeyMand(this string input, ref bool shortened)
91+
{
92+
string output = input.Trim();
93+
if (output.Length < input.Length)
94+
{
95+
shortened = true;
96+
}
97+
return output;
98+
}
99+
100+
public static string? SanitizeKeyOpt(this string? input, ref bool shortened)
101+
{
102+
if (input != null)
103+
{
104+
return input.SanitizeKeyMand(ref shortened);
105+
}
106+
else return null;
107+
}
108+
109+
public static string SanitizeCommentMand(this string input, ref bool shortened)
110+
{
111+
string output = CommentRegex().Replace(input, "").Trim();
112+
string ignorableChangeCompareString = output + "\n";
113+
if (input != null && output.Length < input.Length && ignorableChangeCompareString != input)
114+
{
115+
shortened = true;
116+
}
117+
return output;
118+
}
119+
120+
public static string? SanitizeCommentOpt(this string? input, ref bool shortened)
121+
{
122+
if (input != null)
123+
{
124+
return input.SanitizeCommentMand(ref shortened);
125+
}
126+
else return null;
127+
}
128+
129+
public static string SanitizeCidrMand(this string input, ref bool shortened)
130+
{
131+
string output = CidrRegex().Replace(input, "").Trim();
132+
if (output.Length < input.Length)
133+
{
134+
shortened = true;
135+
}
136+
return output;
137+
}
138+
139+
public static string? SanitizeCidrOpt(this string? input, ref bool shortened)
140+
{
141+
if (input != null)
142+
{
143+
return input.SanitizeCidrMand(ref shortened);
144+
}
145+
else return null;
146+
}
147+
148+
public static string SanitizeJsonMand(this string input, ref bool shortened)
149+
{
150+
string output = JsonRegex().Replace(input, "").Trim();
151+
if (output.Length < input.Length)
152+
{
153+
shortened = true;
154+
}
155+
return output;
156+
}
157+
158+
public static string SanitizeJsonFieldMand(this string input, ref bool changed)
159+
{
160+
string output = JsonFieldRegex().Replace(input.Trim(), "_");
161+
if (output != input)
162+
{
163+
changed = true;
164+
}
165+
return output;
166+
}
167+
168+
public static string SanitizeEolMand(this string input, ref bool shortened)
169+
{
170+
string output = EolRegex().Replace(input, " ").Trim();
171+
if (output.Length < input.Length)
172+
{
173+
shortened = true;
174+
}
175+
return output;
176+
}
177+
178+
[GeneratedRegex(@"[^\w\.\*\-\:\?@/\(\)\[\]\{\}\$\+<>#\$ ]")]
179+
private static partial Regex StandardSanitizationRegex();
180+
181+
[GeneratedRegex(@"[^\w\.\*\-\:\?@/\(\) ]")]
182+
private static partial Regex LdapNameRegex();
183+
184+
[GeneratedRegex(@"[^\w\.\*\-\:\?@/\(\)\=\, \\]")]
185+
private static partial Regex LdapPathRegex();
186+
187+
[GeneratedRegex(@"[^\S ]")]
188+
private static partial Regex PasswdRegex();
189+
190+
[GeneratedRegex(@"[""'']")]
191+
private static partial Regex CommentRegex();
192+
193+
[GeneratedRegex(@"[^a-fA-F0-9\.\:/]")]
194+
private static partial Regex CidrRegex();
195+
196+
[GeneratedRegex(@"[^\S ]")]
197+
private static partial Regex JsonRegex();
198+
199+
[GeneratedRegex(@"[\+\*\(\)\{\}\[\]\?\!#<>\=\,\;\/\\\t@\$\%\^\|\&\~ ]")]
200+
private static partial Regex JsonFieldRegex();
201+
202+
[GeneratedRegex(@"[\n\r]")]
203+
private static partial Regex EolRegex();
204+
26205
}
27206
}

roles/lib/files/FWO.Config.Api/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class Config : ConfigData
1313
/// <summary>
1414
/// Internal connection to api server. Used to get/edit config data.
1515
/// </summary>
16-
protected ApiConnection apiConnection;
16+
protected ApiConnection? apiConnection;
1717

1818
public int UserId { get; private set; }
1919
public bool Initialized { get; private set; } = false;

roles/lib/files/FWO.Config.Api/UserConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public string GetApiText(string key)
195195
public async Task<Dictionary<string, string>> GetCustomDict(string languageName)
196196
{
197197
Dictionary<string, string> dict = [];
198+
if (apiConnection == null)
199+
{
200+
Log.WriteError("ApiConnection is null", "The ApiConnection is not initialized.");
201+
return dict;
202+
}
198203
try
199204
{
200205
List<UiText> uiTexts = await apiConnection.SendQueryAsync<List<UiText>>(ConfigQueries.getCustomTextsPerLanguage, new { language = languageName });

roles/lib/files/FWO.Data/Device.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text.Json.Serialization;
1+
using System.Text.Json.Serialization;
2+
using FWO.Basics;
23
using Newtonsoft.Json;
34

45
namespace FWO.Data
@@ -65,11 +66,11 @@ public Device(Device device)
6566
public bool Sanitize()
6667
{
6768
bool shortened = false;
68-
Name = Sanitizer.SanitizeOpt(Name, ref shortened);
69-
LocalRulebase = Sanitizer.SanitizeOpt(LocalRulebase, ref shortened);
70-
GlobalRulebase = Sanitizer.SanitizeOpt(GlobalRulebase, ref shortened);
71-
Package = Sanitizer.SanitizeOpt(Package, ref shortened);
72-
Comment = Sanitizer.SanitizeCommentOpt(Comment, ref shortened);
69+
Name = Name.SanitizeOpt(ref shortened);
70+
LocalRulebase = LocalRulebase.SanitizeOpt(ref shortened);
71+
GlobalRulebase = GlobalRulebase.SanitizeOpt(ref shortened);
72+
Package = Package.SanitizeOpt(ref shortened);
73+
Comment = Comment.SanitizeCommentOpt(ref shortened);
7374
return shortened;
7475
}
7576
}

roles/lib/files/FWO.Data/DisplayBase.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static StringBuilder DisplayService(NetworkService service, bool isTechRe
2222
}
2323
else
2424
{
25-
result.Append(service.Protocol?.Name != null ? $"{service.Protocol?.Name}" : $"{service.Name}");
25+
result.Append(ShouldDisplayProtocolName(service) ? $"{service.Protocol?.Name}" : $"{service.Name}");
2626
}
2727
}
2828
else
@@ -32,7 +32,7 @@ public static StringBuilder DisplayService(NetworkService service, bool isTechRe
3232
{
3333
result.Append($" ({ports}/{service.Protocol?.Name})");
3434
}
35-
else if (service.Protocol?.Name != null)
35+
else if (ShouldDisplayProtocolName(service))
3636
{
3737
result.Append($" ({service.Protocol?.Name})");
3838
}
@@ -253,5 +253,12 @@ public static string DisplayPort(int? port, int? portEnd, bool inBrackets = fals
253253
}
254254
return result;
255255
}
256+
257+
private static bool ShouldDisplayProtocolName(NetworkService service)
258+
{
259+
return service.Protocol?.Name != null &&
260+
!(service.Protocol.Id == 0 &&
261+
(service.Name.Equals("Any") || service.Name.Equals("ALL")));
262+
}
256263
}
257264
}

roles/lib/files/FWO.Data/ExternalTicketSystem.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FWO.Basics;
1+
using FWO.Basics;
22
using FWO.Data.Workflow;
33
using Newtonsoft.Json;
44
using System.Text.Json;
@@ -83,11 +83,11 @@ public List<string> TaskTypesToBundleGateways()
8383
public bool Sanitize()
8484
{
8585
bool shortened = false;
86-
Name = Sanitizer.SanitizeMand(Name, ref shortened);
87-
Url = Sanitizer.SanitizePasswMand(Url, ref shortened);
88-
TicketTemplate = Sanitizer.SanitizeJsonMand(TicketTemplate, ref shortened);
89-
TasksTemplate = Sanitizer.SanitizeJsonMand(TasksTemplate, ref shortened);
90-
foreach(var template in Templates)
86+
Name = Name.SanitizeMand(ref shortened);
87+
Url = Url.SanitizeMand(ref shortened);
88+
TicketTemplate = TicketTemplate.SanitizeJsonMand(ref shortened);
89+
TasksTemplate = TasksTemplate.SanitizeJsonMand(ref shortened);
90+
foreach (var template in Templates)
9191
{
9292
shortened = template.Sanitize();
9393
}
@@ -131,16 +131,16 @@ public class ExternalTicketTemplate
131131
public bool Sanitize()
132132
{
133133
bool shortened = false;
134-
TaskType = Sanitizer.SanitizeMand(TaskType, ref shortened);
135-
TicketTemplate = Sanitizer.SanitizeJsonMand(TicketTemplate, ref shortened);
136-
TasksTemplate = Sanitizer.SanitizeJsonMand(TasksTemplate, ref shortened);
137-
ObjectTemplate = Sanitizer.SanitizeJsonMand(ObjectTemplate, ref shortened);
138-
ObjectTemplateShort = Sanitizer.SanitizeJsonMand(ObjectTemplateShort, ref shortened);
139-
IpTemplate = Sanitizer.SanitizeJsonMand(IpTemplate, ref shortened);
140-
NwObjGroupTemplate = Sanitizer.SanitizeJsonMand(NwObjGroupTemplate, ref shortened);
141-
ServiceTemplate = Sanitizer.SanitizeJsonMand(ServiceTemplate, ref shortened);
142-
IcmpTemplate = Sanitizer.SanitizeJsonMand(IcmpTemplate, ref shortened);
143-
IpProtocolTemplate = Sanitizer.SanitizeJsonMand(IpProtocolTemplate, ref shortened);
134+
TaskType = TaskType.SanitizeMand(ref shortened);
135+
TicketTemplate = TicketTemplate.SanitizeJsonMand(ref shortened);
136+
TasksTemplate = TasksTemplate.SanitizeJsonMand(ref shortened);
137+
ObjectTemplate = ObjectTemplate.SanitizeJsonMand(ref shortened);
138+
ObjectTemplateShort = ObjectTemplateShort.SanitizeJsonMand(ref shortened);
139+
IpTemplate = IpTemplate.SanitizeJsonMand(ref shortened);
140+
NwObjGroupTemplate = NwObjGroupTemplate.SanitizeJsonMand(ref shortened);
141+
ServiceTemplate = ServiceTemplate.SanitizeJsonMand(ref shortened);
142+
IcmpTemplate = IcmpTemplate.SanitizeJsonMand(ref shortened);
143+
IpProtocolTemplate = IpProtocolTemplate.SanitizeJsonMand(ref shortened);
144144
return shortened;
145145
}
146146
}

0 commit comments

Comments
 (0)