Пример #1
0
        OSDMap Authenticated(OSDMap map)
        {
            IUserAccountService accountService = m_registry.RequestModuleInterface <IUserAccountService> ();
            UserAccount         user           = accountService.GetUserAccount(null, map ["UUID"].AsUUID());

            bool   Verified = user != null;
            OSDMap resp     = new OSDMap();

            resp ["Verified"] = OSD.FromBoolean(Verified);

            if (Verified)
            {
                user.UserLevel = 0;
                accountService.StoreUserAccount(user);
                IAgentConnector con   = DataPlugins.RequestPlugin <IAgentConnector> ();
                IAgentInfo      agent = con.GetAgent(user.PrincipalID);
                if (agent != null && agent.OtherAgentInformation.ContainsKey("WebUIActivationToken"))
                {
                    agent.OtherAgentInformation.Remove("WebUIActivationToken");
                    con.UpdateAgent(agent);
                }
            }

            return(resp);
        }
Пример #2
0
        OSDMap DeleteUser(OSDMap map)
        {
            OSDMap resp = new OSDMap();

            resp ["Finished"] = OSD.FromBoolean(true);

            UUID       agentID  = map ["UserID"].AsUUID();
            IAgentInfo GetAgent = DataPlugins.RequestPlugin <IAgentConnector> ().GetAgent(agentID);

            if (GetAgent != null)
            {
                GetAgent.Flags &= ~IAgentFlags.PermBan;
                DataPlugins.RequestPlugin <IAgentConnector> ().UpdateAgent(GetAgent);
            }
            return(resp);
        }
Пример #3
0
        OSDMap CheckBan(OSDMap map)
        {
            OSDMap resp = new OSDMap();

            UUID       agentID   = map ["UserID"].AsUUID();
            IAgentInfo agentInfo = DataPlugins.RequestPlugin <IAgentConnector> ().GetAgent(agentID);

            if (agentInfo != null) //found
            {
                resp ["UserFound"] = OSD.FromBoolean(true);

                bool banned = ((agentInfo.Flags & IAgentFlags.TempBan) == IAgentFlags.TempBan) || ((agentInfo.Flags & IAgentFlags.PermBan) == IAgentFlags.PermBan);

                resp ["banned"] = OSD.FromBoolean(banned);

                if (banned) //get ban type
                {
                    if ((agentInfo.Flags & IAgentFlags.PermBan) == IAgentFlags.PermBan)
                    {
                        resp ["BanType"] = OSD.FromString("PermBan");
                    }
                    else if ((agentInfo.Flags & IAgentFlags.TempBan) == IAgentFlags.TempBan)
                    {
                        resp ["BanType"] = OSD.FromString("TempBan");
                        if (agentInfo.OtherAgentInformation.ContainsKey("TemporaryBanInfo") == true)
                        {
                            resp ["BannedUntil"] = OSD.FromInteger(Util.ToUnixTime(agentInfo.OtherAgentInformation ["TemporaryBanInfo"]));
                        }
                        else
                        {
                            resp ["BannedUntil"] = OSD.FromInteger(0);
                        }
                    }
                    else
                    {
                        resp ["BanType"] = OSD.FromString("Unknown");
                    }
                }
            }
            else   //not found
            {
                resp ["UserFound"] = OSD.FromBoolean(false);
            }

            return(resp);
        }
Пример #4
0
        void doBan(UUID agentID, DateTime?until)
        {
            var        conn      = DataPlugins.RequestPlugin <IAgentConnector> ();
            IAgentInfo agentInfo = conn.GetAgent(agentID);

            if (agentInfo != null)
            {
                agentInfo.Flags |= (until.HasValue) ? IAgentFlags.TempBan : IAgentFlags.PermBan;

                if (until.HasValue)
                {
                    agentInfo.OtherAgentInformation ["TemporaryBanInfo"] = until.Value;
                    MainConsole.Instance.TraceFormat("Temporarily ban for {0} until {1}", agentID, until.Value.ToString("s"));
                }
                conn.UpdateAgent(agentInfo);
            }
        }
Пример #5
0
        OSDMap Login(OSDMap map, bool asAdmin)
        {
            bool   Verified = false;
            string Name     = map ["Name"].AsString();
            string Password = map ["Password"].AsString();

            var         loginService   = m_registry.RequestModuleInterface <ILoginService> ();
            var         accountService = m_registry.RequestModuleInterface <IUserAccountService> ();
            UserAccount account        = null;
            var         resp           = new OSDMap();

            resp ["Verified"] = OSD.FromBoolean(false);

            if (accountService == null || CheckIfUserExists(map) ["Verified"] != true)
            {
                return(resp);
            }

            account = accountService.GetUserAccount(null, Name);
            if (account == null)
            {
                return(resp);            // something nasty here
            }
            if (loginService.VerifyClient(account.PrincipalID, Name, "UserAccount", Password))
            {
                if (asAdmin)
                {
                    IAgentInfo agent = DataPlugins.RequestPlugin <IAgentConnector> ().GetAgent(account.PrincipalID);
                    if (agent.OtherAgentInformation ["WebUIEnabled"].AsBoolean() == false)
                    {
                        return(resp);
                    }
                }
                resp ["UUID"]      = OSD.FromUUID(account.PrincipalID);
                resp ["FirstName"] = OSD.FromString(account.FirstName);
                resp ["LastName"]  = OSD.FromString(account.LastName);
                resp ["Email"]     = OSD.FromString(account.Email);
                Verified           = true;
            }

            resp ["Verified"] = OSD.FromBoolean(Verified);

            return(resp);
        }
Пример #6
0
        // TODO:  This probably should be replaced with the auth key processing
        OSDMap SetWebLoginKey(OSDMap map)
        {
            var resp        = new OSDMap();
            var principalID = map ["PrincipalID"].AsUUID();
            var webLoginKey = UUID.Random();
            var authService = m_registry.RequestModuleInterface <IAuthenticationService> ();

            if (authService != null)
            {
                //Remove the old
                DataPlugins.RequestPlugin <IAuthenticationData> ().Delete(principalID, "WebLoginKey");
                authService.SetPlainPassword(principalID, "WebLoginKey", webLoginKey.ToString());
                resp ["WebLoginKey"] = webLoginKey;
            }

            resp ["Failed"] = OSD.FromString(string.Format("No auth service, cannot set WebLoginKey for user {0}.", map ["PrincipalID"].AsUUID()));

            return(resp);
        }
Пример #7
0
        OSDMap GetEvents(OSDMap map)
        {
            var resp      = new OSDMap();
            var directory = DataPlugins.RequestPlugin <IDirectoryServiceConnector> ();

            if (directory != null)
            {
                var events    = new List <EventData> ();
                var timeframe = map.Keys.Contains("timeframe")
                                   ? map ["timeframe"].AsInteger()
                                   : 24;
                var category = map.Keys.Contains("category")
                                  ? map ["category"].AsInteger()
                                  :(int)DirectoryManager.EventCategories.All;
                int eventMaturity = map.Keys.Contains("maturity")
                                       ? map ["maturity"].AsInteger()
                                       : Util.ConvertEventMaturityToDBMaturity(DirectoryManager.EventFlags.PG);

                events = directory.GetAllEvents(timeframe, category, eventMaturity);

                if (events.Count > 0)
                {
                    // build a list of classifieds
                    var evarry = new OSDArray();
                    foreach (var evnt in events)
                    {
                        evarry.Add(evnt.ToOSD());
                    }

                    resp ["events"] = evarry;
                    resp ["count"]  = evarry.Count.ToString();

                    return(resp);
                }
            }

            // no eventss
            resp ["events"] = new OSDArray();
            resp ["count"]  = "0";

            return(resp);
        }
Пример #8
0
        OSDMap EditUser(OSDMap map)
        {
            bool   editRLInfo = (map.ContainsKey("RLName") && map.ContainsKey("RLAddress") && map.ContainsKey("RLZip") && map.ContainsKey("RLCity") && map.ContainsKey("RLCountry"));
            OSDMap resp       = new OSDMap();

            resp ["agent"]   = OSD.FromBoolean(!editRLInfo); // if we have no RLInfo, editing account is assumed to be successful.
            resp ["account"] = OSD.FromBoolean(false);
            UUID        principalID = map ["UserID"].AsUUID();
            UserAccount account     = m_registry.RequestModuleInterface <IUserAccountService> ().GetUserAccount(null, principalID);

            if (account != null)
            {
                account.Email = map ["Email"];
                if (m_registry.RequestModuleInterface <IUserAccountService> ().GetUserAccount(null, map ["Name"].AsString()) == null)
                {
                    account.Name = map ["Name"];
                }

                if (editRLInfo)
                {
                    IAgentConnector agentConnector = DataPlugins.RequestPlugin <IAgentConnector> ();
                    IAgentInfo      agent          = agentConnector.GetAgent(account.PrincipalID);
                    if (agent == null)
                    {
                        agentConnector.CreateNewAgent(account.PrincipalID);
                        agent = agentConnector.GetAgent(account.PrincipalID);
                    }
                    if (agent != null)
                    {
                        agent.OtherAgentInformation ["RLName"]    = map ["RLName"];
                        agent.OtherAgentInformation ["RLAddress"] = map ["RLAddress"];
                        agent.OtherAgentInformation ["RLZip"]     = map ["RLZip"];
                        agent.OtherAgentInformation ["RLCity"]    = map ["RLCity"];
                        agent.OtherAgentInformation ["RLCountry"] = map ["RLCountry"];
                        agentConnector.UpdateAgent(agent);
                        resp ["agent"] = OSD.FromBoolean(true);
                    }
                }
                resp ["account"] = OSD.FromBoolean(m_registry.RequestModuleInterface <IUserAccountService> ().StoreUserAccount(account));
            }
            return(resp);
        }
Пример #9
0
        OSDMap ActivateAccount(OSDMap map)
        {
            OSDMap resp = new OSDMap();

            resp ["Verified"] = OSD.FromBoolean(false);

            if (map.ContainsKey("UserName") && map.ContainsKey("PasswordHash") && map.ContainsKey("ActivationToken"))
            {
                IUserAccountService accountService = m_registry.RequestModuleInterface <IUserAccountService> ();
                UserAccount         user           = accountService.GetUserAccount(null, map ["UserName"].ToString());
                if (user != null)
                {
                    IAgentConnector con   = DataPlugins.RequestPlugin <IAgentConnector> ();
                    IAgentInfo      agent = con.GetAgent(user.PrincipalID);
                    if (agent != null && agent.OtherAgentInformation.ContainsKey("WebUIActivationToken"))
                    {
                        UUID   activationToken      = map ["ActivationToken"];
                        string WebUIActivationToken = agent.OtherAgentInformation ["WebUIActivationToken"];
                        string PasswordHash         = map ["PasswordHash"];
                        if (!PasswordHash.StartsWith("$1$"))
                        {
                            PasswordHash = "$1$" + Util.Md5Hash(PasswordHash);
                        }
                        PasswordHash = PasswordHash.Remove(0, 3);  //remove $1$

                        bool verified = Utils.MD5String(activationToken.ToString() + ":" + PasswordHash) == WebUIActivationToken;
                        resp ["Verified"] = verified;
                        if (verified)
                        {
                            user.UserLevel = 0;
                            accountService.StoreUserAccount(user);
                            agent.OtherAgentInformation.Remove("WebUIActivationToken");
                            con.UpdateAgent(agent);
                        }
                    }
                }
            }

            return(resp);
        }
Пример #10
0
        OSDMap UnBanUser(OSDMap map)
        {
            OSDMap resp = new OSDMap();

            resp ["Finished"] = OSD.FromBoolean(true);

            UUID       agentID  = map ["UserID"].AsUUID();
            IAgentInfo GetAgent = DataPlugins.RequestPlugin <IAgentConnector> ().GetAgent(agentID);

            if (GetAgent != null)
            {
                GetAgent.Flags &= IAgentFlags.PermBan;
                GetAgent.Flags &= IAgentFlags.TempBan;
                if (GetAgent.OtherAgentInformation.ContainsKey("TemporaryBanInfo") == true)
                {
                    GetAgent.OtherAgentInformation.Remove("TemporaryBanInfo");
                }

                DataPlugins.RequestPlugin <IAgentConnector> ().UpdateAgent(GetAgent);
            }

            return(resp);
        }
Пример #11
0
        OSDMap CreateAccount(OSDMap map)
        {
            bool   Verified = false;
            string Name     = map ["Name"].AsString();

            string Password = "";

            if (map.ContainsKey("Password"))
            {
                Password = map ["Password"].AsString();
            }
            else
            {
                Password = map ["PasswordHash"].AsString();  //is really plaintext password, the system hashes it later. Not sure why it was called PasswordHash to start with. I guess the original design was to have the PHP code generate the salt and password hash, then just simply store it here
            }

            //string PasswordSalt = map["PasswordSalt"].AsString(); //not being used
            string HomeRegion    = map ["HomeRegion"].AsString();
            string Email         = map ["Email"].AsString();
            string AvatarArchive = map ["AvatarArchive"].AsString();
            int    userLevel     = map ["UserLevel"].AsInteger();
            string UserTitle     = map ["UserTitle"].AsString();

            //server expects: 0 is PG, 1 is Mature, 2 is Adult - use this when setting MaxMaturity and MaturityRating
            //viewer expects: 13 is PG, 21 is Mature, 42 is Adult

            int MaxMaturity = 2;                //set to adult by default

            if (map.ContainsKey("MaxMaturity")) //MaxMaturity is the highest level that they can change the maturity rating to in the viewer
            {
                MaxMaturity = map ["MaxMaturity"].AsInteger();
            }

            int MaturityRating = MaxMaturity;      //set the default to whatever MaxMaturity was set tom incase they didn't define MaturityRating

            if (map.ContainsKey("MaturityRating")) //MaturityRating is the rating the user wants to be able to see
            {
                MaturityRating = map ["MaturityRating"].AsInteger();
            }

            bool activationRequired = map.ContainsKey("ActivationRequired") ? map ["ActivationRequired"].AsBoolean() : false;

            IUserAccountService accountService = m_registry.RequestModuleInterface <IUserAccountService> ();

            if (accountService == null)
            {
                return(null);
            }

            if (!Password.StartsWith("$1$", System.StringComparison.Ordinal))
            {
                Password = "******" + Util.Md5Hash(Password);
            }
            Password = Password.Remove(0, 3);  //remove $1$

            accountService.CreateUser(Name, Password, Email);
            UserAccount       user             = accountService.GetUserAccount(null, Name);
            IAgentInfoService agentInfoService = m_registry.RequestModuleInterface <IAgentInfoService> ();
            IGridService      gridService      = m_registry.RequestModuleInterface <IGridService> ();

            if (agentInfoService != null && gridService != null)
            {
                GridRegion r = gridService.GetRegionByName(null, HomeRegion);
                if (r != null)
                {
                    agentInfoService.SetHomePosition(user.PrincipalID.ToString(), r.RegionID, new Vector3(r.RegionSizeX / 2, r.RegionSizeY / 2, 20), Vector3.Zero);
                }
                else
                {
                    MainConsole.Instance.DebugFormat("[API]: Could not set home position for user {0}, region \"{1}\" did not produce a result from the grid service", Name, HomeRegion);
                }
            }

            Verified = user != null;
            UUID userID = UUID.Zero;

            OSDMap resp = new OSDMap();

            resp ["Verified"] = OSD.FromBoolean(Verified);

            if (Verified)
            {
                userID         = user.PrincipalID;
                user.UserLevel = userLevel;

                // could not find a way to save this data here.
                DateTime RLDOB     = map ["RLDOB"].AsDate();
                string   RLGender  = map ["RLGender"].AsString();
                string   RLName    = map ["RLName"].AsString();
                string   RLAddress = map ["RLAddress"].AsString();
                string   RLCity    = map ["RLCity"].AsString();
                string   RLZip     = map ["RLZip"].AsString();
                string   RLCountry = map ["RLCountry"].AsString();
                string   RLIP      = map ["RLIP"].AsString();



                IAgentConnector con = DataPlugins.RequestPlugin <IAgentConnector> ();
                con.CreateNewAgent(userID);

                IAgentInfo agent = con.GetAgent(userID);

                agent.MaxMaturity    = MaxMaturity;
                agent.MaturityRating = MaturityRating;

                agent.OtherAgentInformation ["RLDOB"]     = RLDOB;
                agent.OtherAgentInformation ["RLGender"]  = RLGender;
                agent.OtherAgentInformation ["RLName"]    = RLName;
                agent.OtherAgentInformation ["RLAddress"] = RLAddress;
                agent.OtherAgentInformation ["RLCity"]    = RLCity;
                agent.OtherAgentInformation ["RLZip"]     = RLZip;
                agent.OtherAgentInformation ["RLCountry"] = RLCountry;
                agent.OtherAgentInformation ["RLIP"]      = RLIP;
                if (activationRequired)
                {
                    UUID activationToken = UUID.Random();
                    agent.OtherAgentInformation ["WebUIActivationToken"] = Util.Md5Hash(activationToken.ToString() + ":" + Password);
                    resp ["WebUIActivationToken"] = activationToken;
                }
                con.UpdateAgent(agent);

                accountService.StoreUserAccount(user);

                IProfileConnector profileData = DataPlugins.RequestPlugin <IProfileConnector> ();
                IUserProfileInfo  profile     = profileData.GetUserProfile(user.PrincipalID);
                if (profile == null)
                {
                    profileData.CreateNewProfile(user.PrincipalID);
                    profile = profileData.GetUserProfile(user.PrincipalID);
                }
                if (AvatarArchive.Length > 0)
                {
                    profile.AArchiveName = AvatarArchive;
                }
                //    MainConsole.Instance.InfoFormat("[Builtin Web Interface] Triggered Archive load of " + profile.AArchiveName);
                profile.IsNewUser = true;

                profile.MembershipGroup = UserTitle;
                profile.CustomType      = UserTitle;

                profileData.UpdateUserProfile(profile);
                //   MainConsole.Instance.RunCommand("load avatar archive " + user.FirstName + " " + user.LastName + " Devil");
            }

            resp ["UUID"] = OSD.FromUUID(userID);
            return(resp);
        }
Пример #12
0
        OSDMap GetProfile(OSDMap map)
        {
            OSDMap resp   = new OSDMap();
            string Name   = map ["Name"].AsString();
            UUID   userID = map ["UUID"].AsUUID();

            UserAccount account = Name != "" ?
                                  m_registry.RequestModuleInterface <IUserAccountService> ().GetUserAccount(null, Name) :
                                  m_registry.RequestModuleInterface <IUserAccountService> ().GetUserAccount(null, userID);

            if (account != null)
            {
                OSDMap accountMap = new OSDMap();

                accountMap ["Created"]     = account.Created;
                accountMap ["Name"]        = account.Name;
                accountMap ["PrincipalID"] = account.PrincipalID;
                accountMap ["Email"]       = account.Email;

                TimeSpan diff  = DateTime.Now - Util.ToDateTime(account.Created);
                int      years = (int)diff.TotalDays / 356;
                int      days  = years > 0 ? (int)diff.TotalDays / years : (int)diff.TotalDays;
                accountMap ["TimeSinceCreated"] = years + " years, " + days + " days"; // if we're sending account.Created do we really need to send this string ?

                IProfileConnector profileConnector = DataPlugins.RequestPlugin <IProfileConnector> ();
                IUserProfileInfo  profile          = profileConnector.GetUserProfile(account.PrincipalID);
                if (profile != null)
                {
                    resp ["profile"] = profile.ToOSD(false); //not trusted, use false

                    if (account.UserFlags == 0)
                    {
                        account.UserFlags = 2; //Set them to no info given
                    }
                    string flags = ((IUserProfileInfo.ProfileFlags)account.UserFlags).ToString();
                    IUserProfileInfo.ProfileFlags.NoPaymentInfoOnFile.ToString();

                    accountMap ["AccountInfo"] = (profile.CustomType != "" ? profile.CustomType :
                                                  account.UserFlags == 0 ? "Resident" : "Admin") + "\n" + flags;
                    UserAccount partnerAccount = m_registry.RequestModuleInterface <IUserAccountService> ().GetUserAccount(null, profile.Partner);
                    if (partnerAccount != null)
                    {
                        accountMap ["Partner"]     = partnerAccount.Name;
                        accountMap ["PartnerUUID"] = partnerAccount.PrincipalID;
                    }
                    else
                    {
                        accountMap ["Partner"]     = "";
                        accountMap ["PartnerUUID"] = UUID.Zero;
                    }
                }
                IAgentConnector agentConnector = DataPlugins.RequestPlugin <IAgentConnector> ();
                IAgentInfo      agent          = agentConnector.GetAgent(account.PrincipalID);
                if (agent != null)
                {
                    OSDMap agentMap = new OSDMap();
                    agentMap ["RLName"]    = agent.OtherAgentInformation ["RLName"].AsString();
                    agentMap ["RLGender"]  = agent.OtherAgentInformation ["RLGender"].AsString();
                    agentMap ["RLAddress"] = agent.OtherAgentInformation ["RLAddress"].AsString();
                    agentMap ["RLZip"]     = agent.OtherAgentInformation ["RLZip"].AsString();
                    agentMap ["RLCity"]    = agent.OtherAgentInformation ["RLCity"].AsString();
                    agentMap ["RLCountry"] = agent.OtherAgentInformation ["RLCountry"].AsString();
                    resp ["agent"]         = agentMap;
                }
                resp ["account"] = accountMap;
            }

            return(resp);
        }
Пример #13
0
        OSDMap Login2(OSDMap map)
        {
            string Name     = map ["Name"].AsString();
            string Password = map ["Password"].AsString();

            var resp = new OSDMap();

            resp ["GoodLogin"] = OSD.FromBoolean(false);

            var         loginService   = m_registry.RequestModuleInterface <ILoginService> ();
            var         accountService = m_registry.RequestModuleInterface <IUserAccountService> ();
            UserAccount account        = null;

            if (accountService == null || CheckIfUserExists(map) ["Verified"] != true)
            {
                resp ["Error"] = OSD.FromString("AccountNotFound");
                return(resp);
            }

            account = accountService.GetUserAccount(null, Name);
            if (account == null)
            {
                return(resp);            // something nasty here
            }
            if (loginService.VerifyClient(account.PrincipalID, Name, "UserAccount", Password))
            {
                UUID agentID = account.PrincipalID;

                var agentInfo = DataPlugins.RequestPlugin <IAgentConnector> ().GetAgent(agentID);

                bool banned = ((agentInfo.Flags & IAgentFlags.TempBan) == IAgentFlags.TempBan) || ((agentInfo.Flags & IAgentFlags.PermBan) == IAgentFlags.PermBan);

                if (banned) //get ban type
                {
                    if ((agentInfo.Flags & IAgentFlags.PermBan) == IAgentFlags.PermBan)
                    {
                        resp ["Error"] = OSD.FromString("PermBan");
                    }
                    else if ((agentInfo.Flags & IAgentFlags.TempBan) == IAgentFlags.TempBan)
                    {
                        resp ["Error"] = OSD.FromString("TempBan");

                        if (agentInfo.OtherAgentInformation.ContainsKey("TemporaryBanInfo") == true)
                        {
                            resp ["BannedUntil"] = OSD.FromInteger(Util.ToUnixTime(agentInfo.OtherAgentInformation ["TemporaryBanInfo"]));
                        }
                        else
                        {
                            resp ["BannedUntil"] = OSD.FromInteger(0);
                        }
                    }
                    else
                    {
                        resp ["Error"] = OSD.FromString("UnknownBan");
                    }

                    return(resp);
                }

                resp ["GoodLogin"] = OSD.FromBoolean(true);

                resp ["UserLevel"] = OSD.FromInteger(account.UserLevel);
                resp ["UUID"]      = OSD.FromUUID(agentID);
                resp ["FirstName"] = OSD.FromString(account.FirstName);
                resp ["LastName"]  = OSD.FromString(account.LastName);
                resp ["Email"]     = OSD.FromString(account.Email);

                return(resp);
            }

            resp ["Error"] = OSD.FromString("BadPassword");
            return(resp);
        }