68 lines
3.1 KiB
C#
68 lines
3.1 KiB
C#
// SPDX-License-Identifier: MPL-2.0
|
|
using log4net;
|
|
using Nini.Config;
|
|
using OpenSim.Framework.Servers.HttpServer;
|
|
using OpenSim.Server.Base;
|
|
using OpenSim.Server.Handlers.Base;
|
|
using OpenSim.Services.Interfaces;
|
|
|
|
namespace OpenGenesisLINK.SysApi;
|
|
|
|
/// <summary>
|
|
/// Side-by-side ROBUST service plugin. Does not replace NexVerseWorldApiConnector.
|
|
/// Port 8851 is an INTERNAL HTTP listener; HTTPS 8850 requires an ACME-backed
|
|
/// loopback reverse proxy, with no plaintext public listener.
|
|
/// </summary>
|
|
public sealed class SysApiConnector : ServiceConnector
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(SysApiConnector));
|
|
private static SysApiHost? _host;
|
|
private static readonly object Gate = new();
|
|
|
|
public SysApiConnector(IConfigSource config, IHttpServer existingRobustListener, string configName)
|
|
: base(config, existingRobustListener, configName)
|
|
{
|
|
var cfg = config.Configs["SysApi"];
|
|
if (cfg?.GetBoolean("Enabled", false) != true)
|
|
{
|
|
Log.Info("[SYS.API] Disabled by configuration.");
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
int port = cfg.GetInt("InternalPort", 8851);
|
|
if (port is < 1025 or > 65535)
|
|
throw new InvalidOperationException("Invalid SysApi internal port");
|
|
string publicOrigin = cfg.GetString("PublicOrigin", "").Trim();
|
|
string secretDirectory = cfg.GetString("SecretDirectory", "/etc/oglwebinterface").Trim();
|
|
if (string.IsNullOrWhiteSpace(secretDirectory) || !Path.IsPathRooted(secretDirectory))
|
|
throw new InvalidOperationException("SysApi secret directory must be absolute");
|
|
lock (Gate)
|
|
{
|
|
if (_host != null) return;
|
|
var accounts = LoadService<IUserAccountService>(config, "UserAccountService");
|
|
var authentication = LoadService<IAuthenticationService>(config, "AuthenticationService");
|
|
if (accounts is null || authentication is null)
|
|
throw new InvalidOperationException("SYS.API requires local ROBUST account and authentication services");
|
|
var token = PortalSecretStore.OpenOrCreate(secretDirectory);
|
|
var host = new SysApiHost(port, publicOrigin, accounts, authentication, token);
|
|
host.Start();
|
|
_host = host;
|
|
Log.InfoFormat("[SYS.API] Foundation active on loopback 127.0.0.1:{0}; public TLS proxy port 8850 requires ACME certificate.", port);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Never prevent ROBUST/legacy World API startup for an optional SYS.API failure.
|
|
Log.Error("[SYS.API] Optional module initialization failed; ROBUST and legacy World API remain available.", e);
|
|
}
|
|
}
|
|
|
|
private static T? LoadService<T>(IConfigSource config, string section) where T : class
|
|
{
|
|
string id = config.Configs[section]?.GetString("LocalServiceModule", "") ?? "";
|
|
return string.IsNullOrWhiteSpace(id) ? null :
|
|
ServerUtils.LoadPlugin<T>(id, new object[] {config});
|
|
}
|
|
}
|