コード例 #1
0
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            m_connector = DataManager.DataManager.RequestPlugin<WebAPIConnector>();
            if (m_connector == null || m_connector.Enabled == false || m_connector.Handler != Name)
            {
                return;
            }

            IConfig webapiConfig = config.Configs["WebAPI"];
            UUID.TryParse(webapiConfig.GetString("AdminID", UUID.Zero.ToString()), out AdminAgentID);

            if (m_connector.Handler != Name)
            {
                MainConsole.Instance.Warn("[WebAPI]: module not loaded");
                return;
            }
            MainConsole.Instance.Info("[WebAPI]: module loaded");

            m_registry = registry;

            IConfig GridInfoConfig = config.Configs["GridInfoService"];
            if (GridInfoConfig != null)
            {
                m_servernick = GridInfoConfig.GetString("gridnick", m_servernick);
            }

            m_GridInfo = new OSDMap();
            if (GridInfoConfig != null && (GridInfoConfig.GetString("gridname", "") != "" && GridInfoConfig.GetString("gridnick", "") != ""))
            {
                foreach (string k in GridInfoConfig.GetKeys())
                {
                    m_GridInfo[k] = GridInfoConfig.GetString(k);
                }
            }

            m_APIAuthentication = webapiConfig.GetString("SupportedAuthentication", "Digest");
            m_EnableCORS = webapiConfig.GetBoolean("CORS", false);
            m_AccessControlAllowOrigin = (new List<string>(webapiConfig.GetString("AccessControlAllowOrigin", "*").Split(' '))).ConvertAll<string>(x=>x.Trim());

            ISimulationBase simBase = registry.RequestModuleInterface<ISimulationBase>();

            m_server = simBase.GetHttpServer(webapiConfig.GetUInt("Port", m_connector.HandlerPort));
            foreach (WebAPIHttpMethod method in Enum.GetValues(typeof(WebAPIHttpMethod)))
            {
                m_server.AddStreamHandler(new WebAPI_StreamHandler(this, method)); // This handler is for WebAPI methods that only read data
            }

            m_server2 = simBase.GetHttpServer(webapiConfig.GetUInt("TextureServerPort", m_connector.TexturePort));
            m_server2.AddHTTPHandler("GridTexture", OnHTTPGetTextureImage);

            m_GridInfo[Name + "TextureServer"] = m_server2.ServerURI;

            m_authNonces = new ExpiringCache<string, string>();

            #region Users

            MainConsole.Instance.Commands.AddCommand("webapi user promote", "Grants the specified user administrative powers within WebAPI.", "webapi user promote", PromoteUser);
            MainConsole.Instance.Commands.AddCommand("webapi user demote", "Revokes administrative powers for WebAPI from the specified user.", "webapi user demote", DemoteUser);

            #endregion

            #region News

            MainConsole.Instance.Commands.AddCommand("webapi news source add", "Sets a group as a news source so in-world group notices can be used as a publishing tool for the website.", "webapi news source add", AddGroupAsNewsSource);
            MainConsole.Instance.Commands.AddCommand("webapi news source remove", "Removes a group as a news source so it's notices will stop showing up on the news page.", "webapi news source remove", RemoveGroupAsNewsSource);

            #endregion

            #region Access Tokens

            MainConsole.Instance.Commands.AddCommand("webapi access token", "Gets the current access token to the API for the specified user", "webapi access token", GetAccessToken);
            MainConsole.Instance.Commands.AddCommand("webapi access token new", "Gets a new access token to the API for the specified user", "webapi access token new", GetNewAccessToken);

            #endregion

            #region ACL

            MainConsole.Instance.Commands.AddCommand("webapi access grant", "Grants access to a specified method for a specified user.", "webapi access grant [method]", GrantAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi access revoke", "Revokes access for a specified user.", "webapi access revoke", RevokeAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi access reset", "Resets access to defaults for a specified method for a specified user.", "webapi access reset", ResetAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi access display", "Displays information about the API usage for the specified user.", "webapi access display", DisplayAPIAccessInfo);

            MainConsole.Instance.Commands.AddCommand("webapi access threat get", "Gets maximum threat level for API access for the specified user.", "webapi access threat get", GetMaxThreatLevel);
            MainConsole.Instance.Commands.AddCommand("webapi access threat set", "Sets maximum threat level for API access for the specified user.", "webapi access threat set", SetMaxThreatLevel);

            #endregion

            #region Log

            MainConsole.Instance.Commands.AddCommand("webapi log clear", "Clears the API access log", "webapi log clear [staleonly]", ClearLog);
            MainConsole.Instance.Commands.AddCommand("webapi log usage", "Get the current usage rate for the specified user on the specified method.", "webapi log usage", GetUsageRate);

            #endregion

            MainConsole.Instance.Commands.AddCommand("webapi list methods", "List API methods", "webapi list methods", ListAPImethods);
        }
コード例 #2
0
ファイル: WebAPIHandler.cs プロジェクト: KSLcom/Aurora-WebAPI
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            m_connector = DataManager.DataManager.RequestPlugin<WebAPIConnector>();
            if (m_connector == null || m_connector.Enabled == false || m_connector.Handler != Name)
            {
                return;
            }

            IConfig handlerConfig = config.Configs["Handlers"];
            UUID.TryParse(handlerConfig.GetString("WebAPIAdminID", UUID.Zero.ToString()), out AdminAgentID);

            if (m_connector.Handler != Name)
            {
                MainConsole.Instance.Warn("[WebAPI]: module not loaded");
                return;
            }
            MainConsole.Instance.Info("[WebAPI]: module loaded");

            m_registry = registry;

            IConfig GridInfoConfig = config.Configs["GridInfoService"];
            if (GridInfoConfig != null)
            {
                m_servernick = GridInfoConfig.GetString("gridnick", m_servernick);
            }

            m_GridInfo = new OSDMap();
            if (GridInfoConfig != null && (GridInfoConfig.GetString("gridname", "") != "" && GridInfoConfig.GetString("gridnick", "") != ""))
            {
                foreach (string k in GridInfoConfig.GetKeys())
                {
                    m_GridInfo[k] = GridInfoConfig.GetString(k);
                }
            }

            ISimulationBase simBase = registry.RequestModuleInterface<ISimulationBase>();

            m_server = simBase.GetHttpServer(handlerConfig.GetUInt(Name + "Port", m_connector.HandlerPort));
            foreach (WebAPIHttpMethod method in Enum.GetValues(typeof(WebAPIHttpMethod)))
            {
                m_server.AddStreamHandler(new WebAPI_StreamHandler(this, method)); // This handler is for WebAPI methods that only read data
            }

            m_server2 = simBase.GetHttpServer(handlerConfig.GetUInt(Name + "TextureServerPort", m_connector.TexturePort));
            m_server2.AddHTTPHandler("GridTexture", OnHTTPGetTextureImage);

            m_GridInfo[Name + "TextureServer"] = m_server2.ServerURI;

            m_authNonces = new ExpiringCache<string, string>();

            MainConsole.Instance.Commands.AddCommand("webapi promote user", "Grants the specified user administrative powers within WebAPI.", "webapi promote user", PromoteUser);
            MainConsole.Instance.Commands.AddCommand("webapi demote user", "Revokes administrative powers for WebAPI from the specified user.", "webapi demote user", DemoteUser);
            MainConsole.Instance.Commands.AddCommand("webapi add group as news source", "Sets a group as a news source so in-world group notices can be used as a publishing tool for the website.", "webapi add group as news source", AddGroupAsNewsSource);
            MainConsole.Instance.Commands.AddCommand("webapi remove group as news source", "Removes a group as a news source so it's notices will stop showing up on the news page.", "webapi remove group as news source", RemoveGroupAsNewsSource);
            MainConsole.Instance.Commands.AddCommand("webapi list methods", "List API methods", "webapi list methods", ListAPImethods);
            MainConsole.Instance.Commands.AddCommand("webapi get access token", "Gets the current access token to the API for the specified user", "webapi get access token", GetAccessToken);
            MainConsole.Instance.Commands.AddCommand("webapi get new access token", "Gets a new access token to the API for the specified user", "webapi get new access token", GetNewAccessToken);
            MainConsole.Instance.Commands.AddCommand("webapi clear log", "Clears the API access log", "webapi clear log [staleonly]", ClearLog);
            MainConsole.Instance.Commands.AddCommand("webapi get usage rate", "Get the current usage rate for the specified user on the specified method.", "webapi get usage rate", GetUsageRate);
            MainConsole.Instance.Commands.AddCommand("webapi grant access", "Grants access to a specified method for a specified user.", "webapi grant access [method]", GrantAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi revoke access", "Revokes access for a specified user.", "webapi revoke access", RevokeAPIAccess);
            MainConsole.Instance.Commands.AddCommand("webapi reset access", "Resets access to defaults for a specified method for a specified user.", "webapi reset access", ResetAPIAccess);
        }