Skip to content

Commit

Permalink
[~] Fix crash on new appserver in appzone CactuseSecurity#2597
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidProgramming committed Nov 24, 2024
1 parent 4c7d7f4 commit a2b7f7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
41 changes: 24 additions & 17 deletions roles/lib/files/FWO.Services/ModellingVarianceAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,10 @@ private async Task AnalyseAppZones(Management mgt, FwoOwner owner)
else if (AppZoneChanged(appZone))
{
RequestUpdateAppZone(appZone, mgt);
allExistingAppZones[mgt.Id] = existingAppZones;
}
}

allExistingAppZones[mgt.Id] = existingAppZones;
}

if (existingAppZones is null || existingAppZones.Count == 0)
Expand Down Expand Up @@ -311,13 +312,13 @@ private bool ResolveExistingAppRole(ModellingAppRole appRole, Management mgt)

private bool ResolveExistingAppZone(ModellingAppZone appZone, Management mgt)
{
if (allExistingAppZones.ContainsKey(mgt.Id))
if (allExistingAppZones.TryGetValue(mgt.Id, out List<ModellingAppZone>? mgtAppZones))
{
existingAppZone = allExistingAppZones[mgt.Id].FirstOrDefault(_ => new AppZoneComparer().Equals(_, appZone));
existingAppZone = mgtAppZones.FirstOrDefault(_ => new AppZoneComparer().Equals(_, appZone));
}
if (existingAppZone != null)
{
//Log.WriteDebug("Search AppRole", $"Found!!");
Log.WriteDebug("Search AppZone", $"Found!!");
}
return existingAppZone != null;
}
Expand All @@ -326,14 +327,15 @@ private bool AppZoneAlreadyRequested(ModellingAppZone appZone, Management mgt)
{
Log.WriteDebug("Search AppZone", $"Name: {appZone.Name}, AppId: {appZone.AppId}, Management: {mgt.Name}");

if (alreadyCreatedAppZones.TryGetValue(mgt.Id, out List<ModellingAppZone>? alreadyRequestedAppZones) && alreadyRequestedAppZones.Contains(appZone, new AppZoneComparer()))
{
return true;
}
else
{
return false;
}
return ( alreadyCreatedAppZones.TryGetValue(mgt.Id, out List<ModellingAppZone>? alreadyRequestedAppZones)
&& alreadyRequestedAppZones.Contains(appZone, new AppZoneComparer()) );
}
private bool AppServerAlreadyRequested(ModellingAppServer appServer, Management mgt)
{
Log.WriteDebug("Search AppServer", $"Name: {appServer.Name}, AppId: {appServer.AppId}, Management: {mgt.Name}");

return ( alreadyCreatedAppServers.TryGetValue(mgt.Id, out List<ModellingAppServer>? alreadyRequestedAppServers)
&& alreadyRequestedAppServers.Contains(appServer, new AppServerComparer()) );
}

private bool AreEqual(ModellingAppServer appServer1, ModellingAppServer appServer2)
Expand All @@ -342,7 +344,6 @@ private bool AreEqual(ModellingAppServer appServer1, ModellingAppServer appServe
return appServer1.Name.ToLower().Trim() == appServer2Name.ToLower().Trim();
}


private bool AppRoleChanged(ModellingAppRole appRole)
{
newAppServers = [];
Expand Down Expand Up @@ -617,7 +618,8 @@ private void FillGroupMembersAppZone(ModellingAppZone appZone, Management mgt)
unchangedGroupMembersDuringCreate = [];
foreach (ModellingAppServerWrapper appServer in newAppServers)
{
(long? networkId, bool alreadyRequested) = ResolveAppServerId(appServer.Content, mgt);
bool alreadyRequested = AppServerAlreadyRequested(appServer.Content, mgt);

newGroupMembers.Add(new()
{
RequestAction = alreadyRequested ? RequestAction.addAfterCreation.ToString() : RequestAction.create.ToString(),
Expand All @@ -626,7 +628,7 @@ private void FillGroupMembersAppZone(ModellingAppZone appZone, Management mgt)
IpString = appServer.Content.Ip,
IpEnd = appServer.Content.IpEnd,
GroupName = appZone.IdString,
NetworkId = networkId
//NetworkId = networkId
});
newCreatedGroupMembers.Add(new()
{
Expand All @@ -636,8 +638,14 @@ private void FillGroupMembersAppZone(ModellingAppZone appZone, Management mgt)
IpString = appServer.Content.Ip,
IpEnd = appServer.Content.IpEnd,
GroupName = appZone.IdString,
NetworkId = networkId
//NetworkId = networkId
});

if (!alreadyCreatedAppServers.ContainsKey(mgt.Id))
{
alreadyCreatedAppServers.Add(mgt.Id, []);
}
alreadyCreatedAppServers[mgt.Id].Add(appServer.Content);
}
foreach (ModellingAppServerWrapper appServer in unchangedAppServers)
{
Expand All @@ -653,7 +661,6 @@ private void FillGroupMembersAppZone(ModellingAppZone appZone, Management mgt)
}
foreach (ModellingAppServerWrapper appServer in deletedAppServers)
{
//warum unchanged hier?
unchangedGroupMembersDuringCreate.Add(new()
{
RequestAction = RequestAction.unchanged.ToString(),
Expand Down
2 changes: 1 addition & 1 deletion roles/ui/files/FWO.UI/Pages/Settings/EditExtStates.razor
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
actExtState.Id = returnIds[0].NewId;
}
}
RefreshExtStates();
await RefreshExtStates();
}
CloseSelect();
}
Expand Down

0 comments on commit a2b7f7b

Please sign in to comment.