From b95b03b409578da87f1dbaf809001e88e4e4fd56 Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 11 Sep 2020 00:41:12 +1000 Subject: Automatically add members to certain groups, and HGers from specific grids to certain other groups. It doesn't let them know, though the last group added will be their active group. This replaces a PHP script I used to use, that got broken by a PHP update. It also didn't let people know, no one complained. This is better. Another attempt at sorting out the auto group chicken and egg problems. Are you a local? Asking for a friend. Hypergridders have their full name in firstname, and their grid in lastname. Sometimes. Code filled with gotos may be spaghetti code, but object oriented code can be like chopped spaghetti that's hidden all over the kitchen. At least with gotos you can follow them. --- OpenSim/Addons/Groups/GroupsModule.cs | 9 ++ .../Authorization/AuthorizationService.cs | 11 +- .../LocalAuthorizationServiceConnector.cs | 7 +- .../RemoteAuthorizationServiceConnector.cs | 6 +- .../Region/Framework/Interfaces/IGroupsModule.cs | 3 +- OpenSim/Region/Framework/Scenes/Scene.cs | 131 ++++++++++++++++++++- .../Avatar/XmlRpcGroups/GroupsModule.cs | 7 ++ .../AuthorizationServerPostHandler.cs | 3 +- .../AuthorizationService/AuthorizationService.cs | 5 +- .../Services/Interfaces/IAuthorizationService.cs | 4 +- 10 files changed, 166 insertions(+), 20 deletions(-) diff --git a/OpenSim/Addons/Groups/GroupsModule.cs b/OpenSim/Addons/Groups/GroupsModule.cs index 98264ad..327504d 100644 --- a/OpenSim/Addons/Groups/GroupsModule.cs +++ b/OpenSim/Addons/Groups/GroupsModule.cs @@ -1015,6 +1015,15 @@ namespace OpenSim.Groups remoteClient.SendJoinGroupReply(groupID, false); } + public void JoinGroup(string agentID, UUID groupID) + { + string reason = string.Empty; + m_groupData.AddAgentToGroup(agentID, agentID, groupID, UUID.Zero, string.Empty, out reason); + if (reason != string.Empty) + // A warning + m_log.Warn("[Groups]: Join group warning - " + reason); + } + public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID) { if (m_debugEnabled) m_log.DebugFormat("[Groups]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs index 2e06bc8..91e0ebc 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs @@ -88,8 +88,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization } public bool IsAuthorizedForRegion( - string user, string firstName, string lastName, string regionID, out string message) + string user, string firstName, string lastName, string regionID, out string message, out bool isLocal) { + UUID userID = new UUID(user); + isLocal = m_UserManagement.IsLocalGridUser(userID); + // This should not happen if (m_Scene.RegionInfo.RegionID.ToString() != regionID) { @@ -105,11 +108,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization return true; } - UUID userID = new UUID(user); +//// UUID userID = new UUID(user); if ((m_accessValue & AccessFlags.DisallowForeigners) != 0) { - if (!m_UserManagement.IsLocalGridUser(userID)) + if (!isLocal) { message = "No foreign users allowed in this region"; return false; @@ -130,4 +133,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs index 0be0676..59ffc1d 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs @@ -114,13 +114,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization } public bool IsAuthorizedForRegion( - string userID, string firstName, string lastName, string regionID, out string message) + string userID, string firstName, string lastName, string regionID, out string message, out bool isLocal) { message = ""; + isLocal = false; if (!m_Enabled) return true; - return m_AuthorizationService.IsAuthorizedForRegion(userID, firstName, lastName, regionID, out message); + return m_AuthorizationService.IsAuthorizedForRegion(userID, firstName, lastName, regionID, out message, out isLocal); } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs index f312b0d..f06180a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs @@ -120,7 +120,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization } public bool IsAuthorizedForRegion( - string userID, string firstName, string lastName, string regionID, out string message) + string userID, string firstName, string lastName, string regionID, out string message, out bool isLocal) { m_log.InfoFormat( "[REMOTE AUTHORIZATION CONNECTOR]: IsAuthorizedForRegion checking {0} for region {1}", userID, regionID); @@ -141,6 +141,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization } } + isLocal = false; if (scene != null) { string mail = String.Empty; @@ -153,6 +154,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization mail = account.Email; firstName = account.FirstName; lastName = account.LastName; + isLocal = true; } isAuthorized @@ -169,4 +171,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization return isAuthorized; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs b/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs index 0d1f4f4..c7e29bd 100644 --- a/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IGroupsModule.cs @@ -92,6 +92,7 @@ namespace OpenSim.Region.Framework.Interfaces GridInstantMessage CreateGroupNoticeIM(UUID agentID, UUID groupNoticeID, byte dialog); void SendAgentGroupDataUpdate(IClientAPI remoteClient); void JoinGroupRequest(IClientAPI remoteClient, UUID GroupID); + void JoinGroup(string agentID, UUID GroupID); void LeaveGroupRequest(IClientAPI remoteClient, UUID GroupID); void EjectGroupMemberRequest(IClientAPI remoteClient, UUID GroupID, UUID EjecteeID); void EjectGroupMember(IClientAPI remoteClient, UUID agentID, UUID GroupID, UUID EjecteeID); @@ -101,4 +102,4 @@ namespace OpenSim.Region.Framework.Interfaces List FindGroups(IClientAPI remoteClient, string query); } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 5f1497a..eee288a 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -338,6 +338,9 @@ namespace OpenSim.Region.Framework.Scenes protected ICapabilitiesModule m_capsModule; protected IGroupsModule m_groupsModule; + // The lists of groups to automatically add to logging in users. + private Dictionary m_AutoGroups; + private Dictionary m_extraSettings; /// @@ -1156,6 +1159,50 @@ namespace OpenSim.Region.Framework.Scenes #endregion Interest Management + #region Group + + IConfig groupsConfig = m_config.Configs["Groups"]; + m_AutoGroups = new Dictionary(); + if (groupsConfig != null) + { + string groups = groupsConfig.GetString("AddDefaultGroup", string.Empty); + if (groups.Length > 0) + { + try + { + m_AutoGroups.Add("local", groups.Split('|')); + } + catch (ArgumentException) + { + m_log.Warn("[SCENE]: Duplicated AddDefaultGroup option."); + } + } + string[] keys = groupsConfig.GetKeys(); + if (0 < keys.Length) + { + foreach (string k in keys) + { + if (k.StartsWith("AddHGDefaultGroup_")) + { + groups = groupsConfig.GetString(k, string.Empty); + if (groups.Length > 0) + { + try + { + m_AutoGroups.Add(k.Substring(18), groups.Split('|')); + } + catch (ArgumentException) + { + m_log.WarnFormat("[SCENE]: Duplicated {0} option.", k); + } + } + } + } + } + } + + #endregion Group + StatsReporter = new SimStatsReporter(this); StatsReporter.OnSendStatsResult += SendSimStatsPackets; @@ -4333,6 +4380,7 @@ namespace OpenSim.Region.Framework.Scenes protected virtual bool AuthorizeUser(AgentCircuitData agent, bool bypassAccessControl, out string reason) { reason = String.Empty; + bool isLocal = false; if (!m_strictAccessControl) return true; @@ -4342,7 +4390,7 @@ namespace OpenSim.Region.Framework.Scenes if (AuthorizationService != null) { if (!AuthorizationService.IsAuthorizedForRegion( - agent.AgentID.ToString(), agent.firstname, agent.lastname, RegionInfo.RegionID.ToString(), out reason)) + agent.AgentID.ToString(), agent.firstname, agent.lastname, RegionInfo.RegionID.ToString(), out reason, out isLocal)) { m_log.WarnFormat("[CONNECTION BEGIN]: Denied access to: {0} ({1} {2}) at {3} because: {4}", agent.AgentID, agent.firstname, agent.lastname, RegionInfo.RegionName, reason); @@ -4375,6 +4423,79 @@ namespace OpenSim.Region.Framework.Scenes return false; } + List agentGroups = new List(); + GroupMembershipData[] GroupMembership = null; + if(m_groupsModule != null) + GroupMembership = m_groupsModule.GetMembershipData(agent.AgentID); + + if (null != GroupMembership) + { + for(int i = 0;i < GroupMembership.Length;i++) + agentGroups.Add(GroupMembership[i].GroupID); + // We get called twice, the first time the name is set to a single space. + // The first time is from QueryAccess(), the second from NewUserConnection() +// if (" " != agent.Name) + { + string grid = ""; + if (isLocal) + { + grid = "local"; + m_log.InfoFormat("[CONNECTION BEGIN]: LOCAL agent {0} {1} {2} {3}, checking auto groups.", agent.firstname, agent.lastname, agent.Name, agent.AgentID); + } + else + { + // agent.AgentID could look like this - @grid.com:8002 01234567-89ab-cdef-0123-456789abcdef + // Or agent.lastname could. + string a = agent.AgentID.ToString(); + if ("@" == a.Substring(0, 1)) + { + grid = a.Split(':')[0].Substring(1); + m_log.InfoFormat("[CONNECTION BEGIN]: HYPERGRID agent {0} from grid {1}, checking auto groups.", agent.AgentID, grid); + } + else + { + a = agent.lastname; + if (String.Empty != a) + { + if ("@" == a.Substring(0, 1)) + { + grid = a.Split(':')[0].Substring(1); + m_log.InfoFormat("[CONNECTION BEGIN]: HYPERGRID agent {0} from grid {1}, checking auto groups.", agent.firstname, grid); + } + } + } + } + string[] groupIDs = null; + try + { + groupIDs = m_AutoGroups[grid]; + } + catch (KeyNotFoundException) + { + // Do nothing. + } + if (null != groupIDs) + { + foreach(string name in groupIDs) + { + GroupRecord g = m_groupsModule.GetGroupRecord(name); + if (null != g) + { + UUID group = g.GroupID; + if(!agentGroups.Contains(group)) + { + m_groupsModule.JoinGroup(agent.AgentID.ToString(), group); + agentGroups.Add(group); + m_log.InfoFormat("[CONNECTION BEGIN]: Automatically added {0} to group {1}.", agent.AgentID, name); + } + } + else + m_log.ErrorFormat("[CONNECTION BEGIN]: Bogus group {0}, not adding {1}.", name, agent.AgentID); + } + } + } + } + // public access if (RegionInfo.EstateSettings.PublicAccess) return true; @@ -4401,8 +4522,8 @@ namespace OpenSim.Region.Framework.Scenes if(estateGroups.Length == 0) goto Label_GroupsDone; - List agentGroups = new List(); - GroupMembershipData[] GroupMembership = m_groupsModule.GetMembershipData(agent.AgentID); +//// List agentGroups = new List(); +//// GroupMembershipData[] GroupMembership = m_groupsModule.GetMembershipData(agent.AgentID); if(GroupMembership == null) { @@ -4413,8 +4534,8 @@ namespace OpenSim.Region.Framework.Scenes if(GroupMembership.Length == 0) goto Label_GroupsDone; - for(int i = 0;i < GroupMembership.Length;i++) - agentGroups.Add(GroupMembership[i].GroupID); +//// for(int i = 0;i < GroupMembership.Length;i++) +//// agentGroups.Add(GroupMembership[i].GroupID); foreach(UUID group in estateGroups) { diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index 1d65d8b..4b24a56 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs @@ -1113,6 +1113,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups SendAgentGroupDataUpdate(remoteClient, true); } + public void JoinGroup(string agentID, UUID groupID) + { + // Should check to see if OpenEnrollment, or if there's an outstanding invitation + UUID u = new UUID(agentID); + m_groupData.AddAgentToGroup(u, u, groupID, UUID.Zero); + } + public void LeaveGroupRequest(IClientAPI remoteClient, UUID groupID) { if (m_debugEnabled) m_log.DebugFormat("[GROUPS]: {0} called", System.Reflection.MethodBase.GetCurrentMethod().Name); diff --git a/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs b/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs index 310a542..07e09bc 100644 --- a/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Authorization/AuthorizationServerPostHandler.cs @@ -61,7 +61,8 @@ namespace OpenSim.Server.Handlers.Authorization AuthorizationRequest Authorization = (AuthorizationRequest) xs.Deserialize(request); string message = String.Empty; - bool authorized = m_AuthorizationService.IsAuthorizedForRegion(Authorization.ID, Authorization.FirstName, Authorization.SurName, Authorization.RegionID, out message); + bool isLocal = false; + bool authorized = m_AuthorizationService.IsAuthorizedForRegion(Authorization.ID, Authorization.FirstName, Authorization.SurName, Authorization.RegionID, out message, out isLocal); AuthorizationResponse result = new AuthorizationResponse(authorized, Authorization.ID + " has been authorized"); diff --git a/OpenSim/Services/AuthorizationService/AuthorizationService.cs b/OpenSim/Services/AuthorizationService/AuthorizationService.cs index 03da6e1..206c99f 100644 --- a/OpenSim/Services/AuthorizationService/AuthorizationService.cs +++ b/OpenSim/Services/AuthorizationService/AuthorizationService.cs @@ -49,10 +49,11 @@ namespace OpenSim.Services.AuthorizationService } public bool IsAuthorizedForRegion( - string userID, string firstName, string lastName, string regionID, out string message) + string userID, string firstName, string lastName, string regionID, out string message, out bool isLocal) { message = "Authorized"; + isLocal = true; return true; } } -} \ No newline at end of file +} diff --git a/OpenSim/Services/Interfaces/IAuthorizationService.cs b/OpenSim/Services/Interfaces/IAuthorizationService.cs index d4c697a..1f80a74 100644 --- a/OpenSim/Services/Interfaces/IAuthorizationService.cs +++ b/OpenSim/Services/Interfaces/IAuthorizationService.cs @@ -48,7 +48,7 @@ namespace OpenSim.Services.Interfaces /// /// bool IsAuthorizedForRegion( - string userID, string firstName, string lastName, string regionID, out string message); + string userID, string firstName, string lastName, string regionID, out string message, out bool isLocal); } public class AuthorizationRequest @@ -145,4 +145,4 @@ namespace OpenSim.Services.Interfaces set { m_message = value; } } } -} \ No newline at end of file +} -- cgit v1.1