using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; using System.Collections.Generic; using Oqtane.Shared; using System; using Microsoft.AspNetCore.Hosting; using Oqtane.Infrastructure; namespace Oqtane.Controllers { [Route(ControllerRoutes.ApiRoute)] public class SystemController : Controller { private readonly IWebHostEnvironment _environment; private readonly IConfigManager _configManager; public SystemController(IWebHostEnvironment environment, IConfigManager configManager) { _environment = environment; _configManager = configManager; } // GET: api/ [HttpGet] [Authorize(Roles = RoleNames.Host)] public Dictionary Get() { Dictionary systeminfo = new Dictionary(); systeminfo.Add("rendermode", _configManager.GetSetting("RenderMode", "Server")); systeminfo.Add("clrversion", Environment.Version.ToString()); systeminfo.Add("osversion", Environment.OSVersion.ToString()); systeminfo.Add("machinename", Environment.MachineName); systeminfo.Add("serverpath", _environment.ContentRootPath); systeminfo.Add("servertime", DateTime.Now.ToString()); return systeminfo; } [HttpPost] [Authorize(Roles = RoleNames.Host)] public void Post([FromBody] Dictionary settings) { foreach(KeyValuePair kvp in settings) { switch (kvp.Key) { case "runtime": _configManager.AddOrUpdateSetting("Runtime", kvp.Value, false); break; case "rendermode": _configManager.AddOrUpdateSetting("RenderMode", kvp.Value, false); break; } } } } }