diff --git a/src/Admin/Controllers/HomeController.cs b/src/Admin/Controllers/HomeController.cs index bada49495c..9f102d21e6 100644 --- a/src/Admin/Controllers/HomeController.cs +++ b/src/Admin/Controllers/HomeController.cs @@ -3,15 +3,31 @@ using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using Bit.Admin.Models; using Microsoft.AspNetCore.Authorization; +using Bit.Core; +using System.Net.Http; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; namespace Bit.Admin.Controllers { public class HomeController : Controller { + private readonly GlobalSettings _globalSettings; + private HttpClient _httpClient = new HttpClient(); + + public HomeController(GlobalSettings globalSettings) + { + _globalSettings = globalSettings; + } + [Authorize] public IActionResult Index() { - return View(); + return View(new HomeModel + { + GlobalSettings = _globalSettings, + CurrentVersion = Core.Utilities.CoreHelpers.GetVersion() + }); } public IActionResult Error() @@ -21,5 +37,48 @@ namespace Bit.Admin.Controllers RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + + public async Task GetLatestDockerHubVersion(string repository) + { + try + { + var response = await _httpClient.GetAsync( + $"https://hub.docker.com/v2/repositories/bitwarden/{repository}/tags/"); + if(response.IsSuccessStatusCode) + { + var json = await response.Content.ReadAsStringAsync(); + var data = JObject.Parse(json); + var results = data["results"] as JArray; + foreach(var result in results) + { + var name = result["name"].ToString(); + if(name != "latest" && name != "beta") + { + return new JsonResult(name); + } + } + } + } + catch(HttpRequestException) { } + + return new JsonResult("-"); + } + + public async Task GetInstalledWebVersion() + { + try + { + var response = await _httpClient.GetAsync($"{_globalSettings.BaseServiceUri.Vault}/version.json"); + if(response.IsSuccessStatusCode) + { + var json = await response.Content.ReadAsStringAsync(); + var data = JObject.Parse(json); + return new JsonResult(data.ToString()); + } + } + catch(HttpRequestException) { } + + return new JsonResult("-"); + } } } diff --git a/src/Admin/Models/HomeModel.cs b/src/Admin/Models/HomeModel.cs new file mode 100644 index 0000000000..d0c1d6bf29 --- /dev/null +++ b/src/Admin/Models/HomeModel.cs @@ -0,0 +1,11 @@ +using System; +using Bit.Core; + +namespace Bit.Admin.Models +{ + public class HomeModel + { + public string CurrentVersion { get; set; } + public GlobalSettings GlobalSettings { get; set; } + } +} diff --git a/src/Admin/Views/Home/Index.cshtml b/src/Admin/Views/Home/Index.cshtml index e2857ebfa7..7416187915 100644 --- a/src/Admin/Views/Home/Index.cshtml +++ b/src/Admin/Views/Home/Index.cshtml @@ -1,5 +1,117 @@ -@{ - ViewData["Title"] = "Home"; +@model HomeModel +@{ + ViewData["Title"] = "Dashboard"; } -Welcome to the Bitwarden Admin Portal. +@section Scripts { + +} + +

Dashboard

+ +

Welcome to the Bitwarden System Administration Portal.

+ +

Version

+ +
+
Core Installed
+
+ @Model.CurrentVersion + + +
+ +
Core Latest
+
+ +
+ +
Web Installed
+
+ + + +
+ +
Web Latest
+
+ +
+
+ +

Settings

+ +

SMTP

+@if(Model.GlobalSettings.Mail.Smtp == null) +{ +

Not configured.

+} +else +{ +
+
Host
+
+ @(string.IsNullOrWhiteSpace(Model.GlobalSettings.Mail.Smtp.Host) ? "-" : Model.GlobalSettings.Mail.Smtp.Host) +
+ +
Port
+
@Model.GlobalSettings.Mail.Smtp.Port
+ +
SSL
+
@(Model.GlobalSettings.Mail.Smtp.Ssl ? "Yes" : "No")
+ +
Default Credentials?
+
@(Model.GlobalSettings.Mail.Smtp.UseDefaultCredentials ? "Yes" : "No")
+ +
Username
+
+ @(string.IsNullOrWhiteSpace(Model.GlobalSettings.Mail.Smtp.Username) ? "-" : Model.GlobalSettings.Mail.Smtp.Username) +
+
+}