Skip to content

Commit 8a2cb5e

Browse files
authored
Merge pull request CactuseSecurity#3809 from tpurschke/develop
Develop sonar fixes
2 parents 22a809d + b2c18a0 commit 8a2cb5e

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

roles/lib/files/FWO.Report/ReportRules.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public override async Task Generate(int elementsPerFetch, ApiConnection apiConne
2727
List<ManagementReport> managementsWithRelevantImportId = await GetRelevantImportIds(apiConnection);
2828

2929
ReportData.ManagementData = [];
30-
foreach(var management in managementsWithRelevantImportId)
30+
foreach (var management in managementsWithRelevantImportId)
3131
{
3232
SetMgtQueryVars(management);
3333
ManagementReport managementReport = (await apiConnection.SendQueryAsync<List<ManagementReport>>(Query.FullQuery, Query.QueryVariables))[0];
@@ -44,11 +44,11 @@ public override async Task Generate(int elementsPerFetch, ApiConnection apiConne
4444
}
4545
keepFetching = false;
4646
Query.QueryVariables[QueryVar.Offset] = (int)Query.QueryVariables[QueryVar.Offset] + elementsPerFetch;
47-
foreach(var management in managementsWithRelevantImportId)
47+
foreach (var management in managementsWithRelevantImportId)
4848
{
4949
SetMgtQueryVars(management);
5050
ManagementReport? mgtToFill = ReportData.ManagementData.FirstOrDefault(m => m.Id == management.Id);
51-
if(mgtToFill != null)
51+
if (mgtToFill != null)
5252
{
5353
(bool newObjects, Dictionary<string, int> maxAddedCounts) = mgtToFill.Merge((await apiConnection.SendQueryAsync<List<ManagementReport>>(Query.FullQuery, Query.QueryVariables))[0]);
5454
// new objects might have been added, but if none reached the limit of elementsPerFetch, we can stop fetching
@@ -64,7 +64,7 @@ private void SetMgtQueryVars(ManagementReport management)
6464
{
6565
Query.QueryVariables[QueryVar.MgmId] = management.Id;
6666
Query.QueryVariables[QueryVar.ImportIdStart] = management.Import.ImportAggregate.ImportAggregateMax.RelevantImportId ?? -1; /* managment was not yet imported at that time */;
67-
Query.QueryVariables[QueryVar.ImportIdEnd] = management.Import.ImportAggregate.ImportAggregateMax.RelevantImportId ?? -1; /* managment was not yet imported at that time */;
67+
Query.QueryVariables[QueryVar.ImportIdEnd] = management.Import.ImportAggregate.ImportAggregateMax.RelevantImportId ?? -1; /* managment was not yet imported at that time */;
6868
}
6969

7070
public override async Task<bool> GetObjectsInReport(int objectsPerFetch, ApiConnection apiConnection, Func<ReportData, Task> callback) // to be called when exporting
@@ -104,15 +104,15 @@ public override async Task<bool> GetObjectsForManagementInReport(Dictionary<stri
104104
objQueryVariables.Add(QueryVar.ImportIdStart, managementReport.Import.ImportAggregate.ImportAggregateMax.RelevantImportId!);
105105
objQueryVariables.Add(QueryVar.ImportIdEnd, managementReport.Import.ImportAggregate.ImportAggregateMax.RelevantImportId!);
106106

107-
string query = GetQuery(objects);
107+
string getObjQuery = GetQuery(objects);
108108
bool keepFetching = true;
109109
int fetchCount = 0;
110110
int elementsPerFetch = (int)objQueryVariables.GetValueOrDefault(QueryVar.Limit)!;
111111
ManagementReport filteredObjects;
112-
ManagementReport allFilteredObjects = new ();
112+
ManagementReport allFilteredObjects = new();
113113
while (keepFetching && ++fetchCount <= maxFetchCycles)
114114
{
115-
filteredObjects = (await apiConnection.SendQueryAsync<List<ManagementReport>>(query, objQueryVariables))[0];
115+
filteredObjects = (await apiConnection.SendQueryAsync<List<ManagementReport>>(getObjQuery, objQueryVariables))[0];
116116

117117
if (fetchCount == 1)
118118
{
@@ -136,7 +136,7 @@ public override async Task<bool> GetObjectsForManagementInReport(Dictionary<stri
136136

137137
private void FillReport(ManagementReport allFilteredObjects, ManagementReport managementReport, ObjCategory objects)
138138
{
139-
if(UseAdditionalFilter)
139+
if (UseAdditionalFilter)
140140
{
141141
AdditionalFilter(allFilteredObjects, managementReport.RelevantObjectIds);
142142
}
@@ -154,7 +154,7 @@ private void FillReport(ManagementReport allFilteredObjects, ManagementReport ma
154154
managementReport.ReportUsers = allFilteredObjects.ReportUsers;
155155
}
156156
}
157-
157+
158158
private static string GetQuery(ObjCategory objects)
159159
{
160160
return objects switch
@@ -196,7 +196,7 @@ private void SetReportedRuleIds()
196196
{
197197
foreach (var dev in mgt.Devices.Where(d => d.Rules != null && d.Rules.Length > 0))
198198
{
199-
if (dev.Rules !=null)
199+
if (dev.Rules != null)
200200
{
201201
foreach (Rule rule in dev.Rules)
202202
{
@@ -214,8 +214,8 @@ public override string ExportToCsv()
214214
{
215215
if (ReportType.IsResolvedReport())
216216
{
217-
StringBuilder report = new ();
218-
RuleDisplayCsv ruleDisplayCsv = new (userConfig);
217+
StringBuilder report = new();
218+
RuleDisplayCsv ruleDisplayCsv = new(userConfig);
219219

220220
report.Append(DisplayReportHeaderCsv());
221221
report.AppendLine($"\"management-name\",\"device-name\",\"rule-number\",\"rule-name\",\"source-zone\",\"source\",\"destination-zone\",\"destination\",\"service\",\"action\",\"track\",\"rule-enabled\",\"rule-uid\",\"rule-comment\"");
@@ -275,10 +275,10 @@ public override string ExportToJson()
275275

276276
private string ExportResolvedRulesToJson()
277277
{
278-
StringBuilder report = new ("{");
278+
StringBuilder report = new("{");
279279
report.Append(DisplayReportHeaderJson());
280280
report.AppendLine("\"managements\": [");
281-
RuleDisplayJson ruleDisplayJson = new (userConfig);
281+
RuleDisplayJson ruleDisplayJson = new(userConfig);
282282
foreach (var managementReport in ReportData.ManagementData.Where(mgt => !mgt.Ignore && mgt.Devices != null &&
283283
Array.Exists(mgt.Devices, device => device.Rules != null && device.Rules.Length > 0)))
284284
{
@@ -334,20 +334,20 @@ private string ExportResolvedRulesToJson()
334334
{
335335
Formatting = Formatting.Indented
336336
};
337-
return JsonConvert.SerializeObject(json, settings);
337+
return JsonConvert.SerializeObject(json, settings);
338338
}
339339

340340
public override string ExportToHtml()
341341
{
342-
StringBuilder report = new ();
342+
StringBuilder report = new();
343343
int chapterNumber = 0;
344344
ConstructHtmlReport(ref report, ReportData.ManagementData, chapterNumber);
345345
return GenerateHtmlFrame(userConfig.GetText(ReportType.ToString()), Query.RawFilter, DateTime.Now, report);
346346
}
347347

348348
public void ConstructHtmlReport(ref StringBuilder report, List<ManagementReport> managementData, int chapterNumber, int levelshift = 0)
349349
{
350-
RuleDisplayHtml ruleDisplayHtml = new (userConfig);
350+
RuleDisplayHtml ruleDisplayHtml = new(userConfig);
351351
Levelshift = levelshift;
352352

353353
foreach (var managementReport in managementData.Where(mgt => !mgt.Ignore && mgt.Devices != null &&
@@ -375,14 +375,14 @@ private void AppendRuleHeadlineHtml(ref StringBuilder report)
375375
{
376376
report.AppendLine("<tr>");
377377
report.AppendLine($"<th>{userConfig.GetText("number")}</th>");
378-
if(ReportType == ReportType.Recertification)
378+
if (ReportType == ReportType.Recertification)
379379
{
380380
report.AppendLine($"<th>{userConfig.GetText("next_recert_date")}</th>");
381381
report.AppendLine($"<th>{userConfig.GetText("owner")}</th>");
382382
report.AppendLine($"<th>{userConfig.GetText("ip_matches")}</th>");
383383
report.AppendLine($"<th>{userConfig.GetText("last_hit")}</th>");
384384
}
385-
if(ReportType == ReportType.UnusedRules || ReportType == ReportType.AppRules)
385+
if (ReportType == ReportType.UnusedRules || ReportType == ReportType.AppRules)
386386
{
387387
report.AppendLine($"<th>{userConfig.GetText("last_hit")}</th>");
388388
}
@@ -422,14 +422,14 @@ private void AppendRuleForManagementHtml(ref StringBuilder report, int chapterNu
422422
{
423423
report.AppendLine("<tr>");
424424
report.AppendLine($"<td>{ruleDisplayHtml.DisplayNumber(rule)}</td>");
425-
if(ReportType == ReportType.Recertification)
425+
if (ReportType == ReportType.Recertification)
426426
{
427427
report.AppendLine($"<td>{RuleDisplayHtml.DisplayNextRecert(rule)}</td>");
428428
report.AppendLine($"<td>{RuleDisplayHtml.DisplayOwner(rule)}</td>");
429429
report.AppendLine($"<td>{RuleDisplayHtml.DisplayRecertIpMatches(rule)}</td>");
430430
report.AppendLine($"<td>{RuleDisplayHtml.DisplayLastHit(rule)}</td>");
431431
}
432-
if(ReportType == ReportType.UnusedRules || ReportType == ReportType.AppRules)
432+
if (ReportType == ReportType.UnusedRules || ReportType == ReportType.AppRules)
433433
{
434434
report.AppendLine($"<td>{RuleDisplayHtml.DisplayLastHit(rule)}</td>");
435435
}
@@ -526,7 +526,7 @@ private void AppendServiceForManagementHtml(ref StringBuilder report, int chapte
526526
report.AppendLine($"<td>{objNumber}</td>");
527527
report.AppendLine($"<td><a name={ObjCatString.Svc}{chapterNumber}x{svcobj.Id}>{svcobj.Name}</a></td>");
528528
report.AppendLine($"<td>{(svcobj.Type.Name != "" ? userConfig.GetText(svcobj.Type.Name) : "")}</td>");
529-
report.AppendLine($"<td>{((svcobj.Type.Name!=ServiceType.Group && svcobj.Protocol != null) ? svcobj.Protocol.Name : "")}</td>");
529+
report.AppendLine($"<td>{((svcobj.Type.Name != ServiceType.Group && svcobj.Protocol != null) ? svcobj.Protocol.Name : "")}</td>");
530530
if (svcobj.DestinationPortEnd != null && svcobj.DestinationPortEnd != svcobj.DestinationPort)
531531
{
532532
report.AppendLine($"<td>{svcobj.DestinationPort}-{svcobj.DestinationPortEnd}</td>");

roles/ui/files/FWO.UI/wwwroot/js/scrollIntoView.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11

22
function scrollIntoRSBView(htmlObjId) {
3-
let obj = document.getElementById(htmlObjId)?.parentElement?.parentElement; // gets the tr element containing the obj
4-
if (!obj)
5-
return false;
3+
let obj = document.getElementById(htmlObjId)?.parentElement?.parentElement; // gets the tr element containing the obj
4+
if (!obj)
5+
{
6+
return false;
7+
}
68
obj.scrollIntoView({ behavior: "smooth", block: "center" });
79
// Expand row
810
let toggleLink = obj.previousElementSibling.querySelector("a");

0 commit comments

Comments
 (0)