diff --git a/bitwarden_license/src/Sso/Controllers/HomeController.cs b/bitwarden_license/src/Sso/Controllers/HomeController.cs index 7536a1ca43..1a5d31e005 100644 --- a/bitwarden_license/src/Sso/Controllers/HomeController.cs +++ b/bitwarden_license/src/Sso/Controllers/HomeController.cs @@ -18,14 +18,6 @@ namespace Bit.Sso.Controllers _interaction = interaction; } - [HttpGet("~/alive")] - [HttpGet("~/now")] - [AllowAnonymous] - public DateTime GetAlive() - { - return DateTime.UtcNow; - } - [Route("~/Error")] [Route("~/Home/Error")] [AllowAnonymous] diff --git a/bitwarden_license/src/Sso/Controllers/InfoController.cs b/bitwarden_license/src/Sso/Controllers/InfoController.cs new file mode 100644 index 0000000000..4d949bf9c4 --- /dev/null +++ b/bitwarden_license/src/Sso/Controllers/InfoController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Sso.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + } +} diff --git a/src/Admin/Controllers/HomeController.cs b/src/Admin/Controllers/HomeController.cs index 6b9fb9fb40..c8aa35c04d 100644 --- a/src/Admin/Controllers/HomeController.cs +++ b/src/Admin/Controllers/HomeController.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using Bit.Admin.Models; using Microsoft.AspNetCore.Authorization; @@ -29,13 +28,6 @@ namespace Bit.Admin.Controllers CurrentVersion = Core.Utilities.CoreHelpers.GetVersion() }); } - - [HttpGet("~/alive")] - [HttpGet("~/now")] - public DateTime Get() - { - return DateTime.UtcNow; - } public IActionResult Error() { diff --git a/src/Admin/Controllers/InfoController.cs b/src/Admin/Controllers/InfoController.cs new file mode 100644 index 0000000000..b49a9a29de --- /dev/null +++ b/src/Admin/Controllers/InfoController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Admin.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + } +} diff --git a/src/Api/Controllers/InfoController.cs b/src/Api/Controllers/InfoController.cs new file mode 100644 index 0000000000..25c9e0423e --- /dev/null +++ b/src/Api/Controllers/InfoController.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Api.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + + [HttpGet("~/ip")] + public JsonResult Ip() + { + var headerSet = new HashSet { "x-forwarded-for", "cf-connecting-ip", "client-ip" }; + var headers = HttpContext.Request?.Headers + .Where(h => headerSet.Contains(h.Key.ToLower())) + .ToDictionary(h => h.Key); + return new JsonResult(new + { + Ip = HttpContext.Connection?.RemoteIpAddress?.ToString(), + Headers = headers, + }); + } + } +} diff --git a/src/Api/Controllers/MiscController.cs b/src/Api/Controllers/MiscController.cs index c3ee2efa7b..2c01513ae2 100644 --- a/src/Api/Controllers/MiscController.cs +++ b/src/Api/Controllers/MiscController.cs @@ -1,5 +1,4 @@ -using System; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Bit.Core.Models.Api; using System.Threading.Tasks; using Bit.Core.Utilities; @@ -24,33 +23,6 @@ namespace Bit.Api.Controllers _globalSettings = globalSettings; } - [HttpGet("~/alive")] - [HttpGet("~/now")] - public DateTime Get() - { - return DateTime.UtcNow; - } - - [HttpGet("~/version")] - public VersionResponseModel Version() - { - return new VersionResponseModel(); - } - - [HttpGet("~/ip")] - public JsonResult Ip() - { - var headerSet = new HashSet { "x-forwarded-for", "cf-connecting-ip", "client-ip" }; - var headers = HttpContext.Request?.Headers - .Where(h => headerSet.Contains(h.Key.ToLower())) - .ToDictionary(h => h.Key); - return new JsonResult(new - { - Ip = HttpContext.Connection?.RemoteIpAddress?.ToString(), - Headers = headers, - }); - } - [Authorize("Application")] [HttpPost("~/bitpay-invoice")] [SelfHosted(NotSelfHostedOnly = true)] diff --git a/src/Billing/Controllers/HomeController.cs b/src/Billing/Controllers/HomeController.cs deleted file mode 100644 index e4e9918196..0000000000 --- a/src/Billing/Controllers/HomeController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace Billing.Controllers -{ - public class HomeController : Controller - { - [HttpGet("~/alive")] - [HttpGet("~/now")] - [AllowAnonymous] - public DateTime GetAlive() - { - return DateTime.UtcNow; - } - - /* - [Authorize] - public IActionResult Index() - { - return View(); - } - */ - } -} diff --git a/src/Billing/Controllers/InfoController.cs b/src/Billing/Controllers/InfoController.cs new file mode 100644 index 0000000000..fb3a85914f --- /dev/null +++ b/src/Billing/Controllers/InfoController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Billing.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + } +} diff --git a/src/Core/Models/Api/Response/VersionResponseModel.cs b/src/Core/Models/Api/Response/VersionResponseModel.cs deleted file mode 100644 index e28923193f..0000000000 --- a/src/Core/Models/Api/Response/VersionResponseModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using Bit.Core.Utilities; - -namespace Bit.Core.Models.Api -{ - public class VersionResponseModel : ResponseModel - { - public VersionResponseModel() - : base("version") - { - Version = CoreHelpers.GetVersion(); - } - - public string Version { get; set; } - } -} diff --git a/src/Events/Controllers/CollectController.cs b/src/Events/Controllers/CollectController.cs index 7fede39b1c..5a5293d794 100644 --- a/src/Events/Controllers/CollectController.cs +++ b/src/Events/Controllers/CollectController.cs @@ -32,14 +32,6 @@ namespace Bit.Events.Controllers _cipherRepository = cipherRepository; } - [HttpGet("~/alive")] - [HttpGet("~/now")] - [AllowAnonymous] - public DateTime GetAlive() - { - return DateTime.UtcNow; - } - [HttpPost] public async Task Post([FromBody]IEnumerable model) { diff --git a/src/Events/Controllers/InfoController.cs b/src/Events/Controllers/InfoController.cs new file mode 100644 index 0000000000..abd939c8e1 --- /dev/null +++ b/src/Events/Controllers/InfoController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Events.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + } +} diff --git a/src/EventsProcessor/Startup.cs b/src/EventsProcessor/Startup.cs index 247192b897..fad3cc85bf 100644 --- a/src/EventsProcessor/Startup.cs +++ b/src/EventsProcessor/Startup.cs @@ -49,7 +49,12 @@ namespace Bit.EventsProcessor app.UseEndpoints(endpoints => { endpoints.MapGet("/alive", - async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString())); + async context => await context.Response.WriteAsJsonAsync(System.DateTime.UtcNow)); + endpoints.MapGet("/now", + async context => await context.Response.WriteAsJsonAsync(System.DateTime.UtcNow)); + endpoints.MapGet("/version", + async context => await context.Response.WriteAsJsonAsync(CoreHelpers.GetVersion())); + }); } } diff --git a/src/Icons/Controllers/IconsController.cs b/src/Icons/Controllers/IconsController.cs index 1ed71b51fe..ec9d7f0756 100644 --- a/src/Icons/Controllers/IconsController.cs +++ b/src/Icons/Controllers/IconsController.cs @@ -39,13 +39,6 @@ namespace Bit.Icons.Controllers _iconsSettings = iconsSettings; } - [HttpGet("~/alive")] - [HttpGet("~/now")] - public DateTime GetAlive() - { - return DateTime.UtcNow; - } - [HttpGet("~/config")] public IActionResult GetConfig() { diff --git a/src/Icons/Controllers/InfoController.cs b/src/Icons/Controllers/InfoController.cs new file mode 100644 index 0000000000..c61dce1b1b --- /dev/null +++ b/src/Icons/Controllers/InfoController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Icons.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + } +} diff --git a/src/Identity/Controllers/InfoController.cs b/src/Identity/Controllers/InfoController.cs new file mode 100644 index 0000000000..bf1b3b6c41 --- /dev/null +++ b/src/Identity/Controllers/InfoController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Identity.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + } +} diff --git a/src/Identity/Controllers/MiscController.cs b/src/Identity/Controllers/MiscController.cs deleted file mode 100644 index 5d4a39f324..0000000000 --- a/src/Identity/Controllers/MiscController.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using Microsoft.AspNetCore.Mvc; - -namespace Bit.Identity.Controllers -{ - public class MiscController : Controller - { - public MiscController() { } - - [HttpGet("~/alive")] - [HttpGet("~/now")] - public DateTime Get() - { - return DateTime.UtcNow; - } - } -} diff --git a/src/Notifications/Controllers/InfoController.cs b/src/Notifications/Controllers/InfoController.cs new file mode 100644 index 0000000000..b743e70738 --- /dev/null +++ b/src/Notifications/Controllers/InfoController.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Bit.Core.Utilities; + +namespace Bit.Notifications.Controllers +{ + public class InfoController : Controller + { + [HttpGet("~/alive")] + [HttpGet("~/now")] + public DateTime GetAlive() + { + return DateTime.UtcNow; + } + + [HttpGet("~/version")] + public JsonResult GetVersion() + { + return Json(CoreHelpers.GetVersion()); + } + } +} diff --git a/src/Notifications/Controllers/SendController.cs b/src/Notifications/Controllers/SendController.cs index f8e92ff770..773879fcdc 100644 --- a/src/Notifications/Controllers/SendController.cs +++ b/src/Notifications/Controllers/SendController.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using System.Text; using System.Threading.Tasks; using Bit.Core.Utilities; @@ -19,14 +18,6 @@ namespace Bit.Notifications _hubContext = hubContext; } - [HttpGet("~/alive")] - [HttpGet("~/now")] - [AllowAnonymous] - public DateTime GetAlive() - { - return DateTime.UtcNow; - } - [HttpPost("~/send")] [SelfHosted(SelfHostedOnly = true)] public async Task PostSend()