mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
dashboard version and smtp settings
This commit is contained in:
@ -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<IActionResult> 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<IActionResult> 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("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user