Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vainamov committed Mar 13, 2019
1 parent 1307fd9 commit de685cd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 38 deletions.
8 changes: 6 additions & 2 deletions Authorization/Authorizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ public static bool IsAuthorized(this IAuthorizable authorizable, string permissi
break;
case Member member:
permissionsSets.AddRange(member.Groups.OrderBy(_ => _.SortValue).Select(_ => _.Permissions));
permissionsSets.AddRange(Pool.Server.Groups.FindAll(@group => @group.SortValue <= member.Groups.Select(_ => _.SortValue).Min()).OrderBy(_ => _.SortValue).Select(_ => _.Permissions));
if (member.Groups.Count > 0) {
permissionsSets.AddRange(Pool.Server.Groups.FindAll(@group => @group.SortValue <= member.Groups.Select(_ => _.SortValue).Min()).OrderBy(_ => _.SortValue).Select(_ => _.Permissions));
}

//if (member.ActiveChannel != null && member.ActiveChannel.MemberPermissions.ContainsKey(member.InternalId)) {
// permissionsSets.Add(member.ActiveChannel.MemberPermissions[member.InternalId]);
Expand Down Expand Up @@ -190,7 +192,9 @@ public static Dictionary<string, Permission> GetAllPermissons(this IAuthorizable
break;
case Member member:
permissionsSets.AddRange(member.Groups.OrderBy(_ => _.SortValue).Select(_ => _.Permissions));
permissionsSets.AddRange(Pool.Server.Groups.FindAll(@group => @group.SortValue < member.Groups.Select(_ => _.SortValue).Min()).OrderBy(_ => _.SortValue).Select(_ => _.Permissions));
if (member.Groups.Count > 0) {
permissionsSets.AddRange(Pool.Server.Groups.FindAll(@group => @group.SortValue < member.Groups.Select(_ => _.SortValue).Min()).OrderBy(_ => _.SortValue).Select(_ => _.Permissions));
}

//if (member.ActiveChannel != null && member.ActiveChannel.MemberPermissions.ContainsKey(member.InternalId)) {
// permissionsSets.Add(member.ActiveChannel.MemberPermissions[member.InternalId]);
Expand Down
3 changes: 2 additions & 1 deletion Communication/Packages/MessagePackageContent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Neo.Core.Config;
using Neo.Core.Management;
using Neo.Core.Shared;

namespace Neo.Core.Communication.Packages
Expand Down Expand Up @@ -89,7 +90,7 @@ public static MessagePackageContent GetSentMessage(Guid senderId, Identity ident
/// <param name="channelId">The internal id of the channel this message belongs to.</param>
/// <returns>Returns the created content.</returns>
public static MessagePackageContent GetSystemMessage(string message, Guid channelId) {
return new MessagePackageContent(Guid.Empty, ConfigManager.Instance.Values.RootIdentity, message, DateTime.Now, "system", channelId);
return new MessagePackageContent(Guid.Empty, UserManager.GetRoot().Identity, message, DateTime.Now, "system", channelId);
}
}
}
16 changes: 0 additions & 16 deletions Config/ConfigValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ public class ConfigValues
[EditableProperty("Registrierung zulassen")]
public bool RegistrationAllowed { get; set; } = true;

/// <summary>
/// The identity for the root account.
/// </summary>
public Identity RootIdentity { get; set; } = new Identity { Id = "neo", Name = "Neo" };

/// <summary>
/// The password for the root account.
/// </summary>
public byte[] RootPassword { get; set; } = NeoCryptoProvider.Instance.Sha512ComputeHash("LT6SUK7JBELX3UAL");

/// <summary>
/// The key size used for RSA encryption.
/// </summary>
[Obsolete]
public int RSAKeySize { get; set; } = 4096;

/// <summary>
/// The address the server is listening to.
/// </summary>
Expand Down
5 changes: 4 additions & 1 deletion Management/UserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public static Account GetRoot() {
/// </summary>
public static void RefreshAccounts() {
var accounts = JsonConvert.DeserializeObject<List<Account>>(JsonConvert.SerializeObject(Pool.Server.Accounts));
accounts.ForEach(_ => _.Password = null);
accounts.ForEach(_ => {
_.Password = null;
_.Identity.AvatarFileExtension = Pool.Server.AvatarServerAvailable ? _.Identity.AvatarFileExtension : "";
});

Target.All.SendPackage(new Package(PackageType.AccountListUpdate, accounts));
}
Expand Down
42 changes: 24 additions & 18 deletions Networking/BaseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Neo.Core.Communication;
using Neo.Core.Communication.Packages;
using Neo.Core.Config;
using Neo.Core.Cryptography;
using Neo.Core.Database;
using Neo.Core.Extensibility;
using Neo.Core.Extensibility.Events;
Expand Down Expand Up @@ -65,6 +66,8 @@ public abstract class BaseServer
{ "neo.moderate.kick", "Benutzer kicken" }
};

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

public DataProvider DataProvider { get; set; }

// ReSharper disable once InconsistentNaming
Expand Down Expand Up @@ -121,15 +124,20 @@ public void Initialize(string configPath, string dataDirectoryPath, string plugi
{ "neo.usertype", "root" }
},
Email = "root@internal.neo",
Identity = ConfigManager.Instance.Values.RootIdentity,
Password = ConfigManager.Instance.Values.RootPassword,
Identity = new Identity {
Id = "neo",
Name = "Neo"
},
Password = NeoCryptoProvider.Instance.Sha512ComputeHash("alpine"),
Permissions = new Dictionary<string, Permission> {
{ "*", Permission.Allow }
}
});
Logger.Instance.Log(LogLevel.Debug, "No root account existed. Default root account created");
}

Channels.ForEach(_ => _.MemberIds.Remove(UserManager.GetRoot().InternalId));

// Create main channel
if (ChannelManager.GetMainChannel() == null) {
Channels.Insert(0, new Channel {
Expand All @@ -156,7 +164,6 @@ public void Initialize(string configPath, string dataDirectoryPath, string plugi
Id = "admins",
Name = "Administratoren",
Permissions = new Dictionary<string, Permission> {
// TODO: Fix default admin group rights
{ "neo.*", Permission.Allow }
},
SortValue = 999
Expand All @@ -168,35 +175,34 @@ public void Initialize(string configPath, string dataDirectoryPath, string plugi
if (GroupManager.GetGuestGroup() == null) {
Groups.Add(new Group {
Attributes = new Dictionary<string, object> {
{ "neo.grouptype", "user" }
{ "neo.grouptype", "guest" }
},
Id = "users",
Name = "Benutzer",
Id = "guests",
Name = "Gäste",
Permissions = new Dictionary<string, Permission> {
// TODO: Fix default user group rights
{ "neo.*", Permission.Allow }
{ "neo.channel.join.$", Permission.Allow },
{ "neo.global.*", Permission.Allow }
},
SortValue = 1
SortValue = 0
});
DataProvider.Save();
Logger.Instance.Log(LogLevel.Debug, "No user group existed. Default user group created");
Logger.Instance.Log(LogLevel.Debug, "No guest group existed. Default guest group created");
}

if (GroupManager.GetGuestGroup() == null) {
if (GroupManager.GetUserGroup() == null) {
Groups.Add(new Group {
Attributes = new Dictionary<string, object> {
{ "neo.grouptype", "guest" }
{ "neo.grouptype", "user" }
},
Id = "guests",
Name = "Gäste",
Id = "users",
Name = "Benutzer",
Permissions = new Dictionary<string, Permission> {
// TODO: Fix default guest group rights
{ "neo.*", Permission.Allow }
{ "neo.channel.create", Permission.Allow }
},
SortValue = 0
SortValue = 1
});
DataProvider.Save();
Logger.Instance.Log(LogLevel.Debug, "No guest group existed. Default guest group created");
Logger.Instance.Log(LogLevel.Debug, "No user group existed. Default user group created");
}

foreach (var pluginFile in new DirectoryInfo(pluginDirectoryPath).EnumerateFiles("*.dll")) {
Expand Down
1 change: 1 addition & 0 deletions Networking/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private void Listen(object obj) {
// TODO: Improve Log Messages
Logger.Instance.Log(LogLevel.Error, "HttpServer couldn't be started. Make sure you are running in high priviledged mode.");
Logger.Instance.Log(LogLevel.Error, "Error starting HttpServer on :" + Port + ". Avatars won't be available.");
Pool.Server.AvatarServerAvailable = false;
return;
}

Expand Down
8 changes: 8 additions & 0 deletions Shared/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public class Channel : IAttributable
/// <summary>
/// Contains the internal ids of all groups that are not allowed to enter this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public List<Guid> BlacklistedGroupIds { get; set; } = new List<Guid>();

/// <summary>
/// Contains the internal ids of all users who are not allowed to enter this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public List<Guid> BlacklistedUserIds { get; set; } = new List<Guid>();

Expand Down Expand Up @@ -78,6 +80,7 @@ public class Channel : IAttributable
/// <summary>
/// The permissions assigned to the individual members of this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public Dictionary<Guid, Dictionary<string, Permission>> MemberPermissions { get; set; } = new Dictionary<Guid, Dictionary<string, Permission>>();

Expand Down Expand Up @@ -110,30 +113,35 @@ public class Channel : IAttributable
/// <summary>
/// The status message of this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public string StatusMessage { get; set; }

/// <summary>
/// Contains the internal ids of all groups that are allowed to join this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public List<Guid> WhitelistedGroupIds { get; set; } = new List<Guid>();

/// <summary>
/// Contains the internal ids of all users who are allowed to join this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public List<Guid> WhitelistedUserIds { get; set; } = new List<Guid>();

/// <summary>
/// Contains the internal ids of all groups that are allowed to see this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public List<Guid> VisibleToGroupIds { get; set; } = new List<Guid>();

/// <summary>
/// Contains the internal ids of all users who are allowed to see this <see cref="Channel"/>.
/// </summary>
[JsonIgnore]
[Obsolete]
public List<Guid> VisibleToUserIds { get; set; } = new List<Guid>();

Expand Down

0 comments on commit de685cd

Please sign in to comment.