|
@@ -15,7 +15,9 @@ using System.Windows.Controls;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using Comal.Classes;
|
|
|
using Comal.Stores;
|
|
|
+using GenHTTP.Engine;
|
|
|
using H.Pipes.Extensions;
|
|
|
+using H.Pipes.Factories;
|
|
|
using InABox.Client.IPC;
|
|
|
using InABox.Clients;
|
|
|
using InABox.Configuration;
|
|
@@ -24,6 +26,7 @@ using InABox.Database;
|
|
|
using InABox.Database.SQLite;
|
|
|
using InABox.DeviceIdentifier;
|
|
|
using InABox.DynamicGrid;
|
|
|
+using InABox.IPC.Shared;
|
|
|
using InABox.Scripting;
|
|
|
using InABox.Wpf.Editors;
|
|
|
using InABox.WPF;
|
|
@@ -55,6 +58,8 @@ namespace PRSServer
|
|
|
{ Position = DynamicActionColumnPosition.Start, ToolTip = TypeToolTip });
|
|
|
ActionColumns.Add(new DynamicImageColumn(StateImage, StateAction)
|
|
|
{ Position = DynamicActionColumnPosition.End, ToolTip = StateToolTip });
|
|
|
+ ActionColumns.Add(new DynamicImageColumn(SecureImage)
|
|
|
+ { Position = DynamicActionColumnPosition.End, ToolTip = SecureToolTip });
|
|
|
//ActionColumns.Add(new DynamicImageColumn(ConsoleImage, ConsoleAction)
|
|
|
// { Position = DynamicActionColumnPosition.End, ToolTip = StateToolTip });
|
|
|
ActionColumns.Add(new DynamicMenuColumn(CreateServerMenu,ServerMenuStatus)
|
|
@@ -67,6 +72,52 @@ namespace PRSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private BitmapImage secureImage = Properties.Resources.secure.AsBitmapImage();
|
|
|
+ private BitmapImage insecureImage = Properties.Resources.insecure.AsBitmapImage();
|
|
|
+ private BitmapImage? SecureImage(CoreRow? row)
|
|
|
+ {
|
|
|
+ if(row is null)
|
|
|
+ {
|
|
|
+ return secureImage;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var key = row.Get<Server, string>(x => x.Key);
|
|
|
+ if(DatabaseInfos.TryGetValue(key, out var info))
|
|
|
+ {
|
|
|
+ return info.IsHTTPS
|
|
|
+ ? secureImage
|
|
|
+ : insecureImage;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private FrameworkElement? SecureToolTip(DynamicActionColumn column, CoreRow? row)
|
|
|
+ {
|
|
|
+ if(row is null)
|
|
|
+ {
|
|
|
+ return column.TextToolTip("Connection Security");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var key = row.Get<Server, string>(x => x.Key);
|
|
|
+ if (DatabaseInfos.TryGetValue(key, out var info))
|
|
|
+ {
|
|
|
+ return info.IsHTTPS
|
|
|
+ ? column.TextToolTip("Secure (HTTPS) Connection")
|
|
|
+ : column.TextToolTip("Insecure (HTTP) Connection");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private DynamicMenuStatus ServerMenuStatus(CoreRow arg)
|
|
|
{
|
|
|
if (arg == null)
|
|
@@ -227,6 +278,9 @@ namespace PRSServer
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ private Dictionary<string, DatabaseInfo> DatabaseInfos { get; set; } = new Dictionary<string, DatabaseInfo>();
|
|
|
+ private HashSet<string> LoadingInfos = new HashSet<string>();
|
|
|
+
|
|
|
protected override void Reload(Filters<Server> criteria, Columns<Server> columns, ref SortOrder<Server>? sort,
|
|
|
Action<CoreTable?, Exception?> action)
|
|
|
{
|
|
@@ -256,10 +310,61 @@ namespace PRSServer
|
|
|
table.Rows.Add(row);
|
|
|
}
|
|
|
|
|
|
+ if (table.Rows.Any(x => x.Get<Server, ServerType>(x => x.Type) == ServerType.Certificate))
|
|
|
+ {
|
|
|
+ foreach (var row in table.Rows.Where(x => x.Get<Server, ServerType>(x => x.Type) == ServerType.Database))
|
|
|
+ {
|
|
|
+ var key = row.Get<Server, string>(x => x.Key);
|
|
|
+
|
|
|
+ var service = GetService(key);
|
|
|
+ if (service is not null && service.Status == ServiceControllerStatus.Running)
|
|
|
+ {
|
|
|
+ if (!LoadingInfos.Contains(key))
|
|
|
+ {
|
|
|
+ LoadingInfos.Add(key);
|
|
|
+ Task.Run(() =>
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ var client = IPCClientFactory.GetClient(DatabaseServerProperties.GetPipeName(key));
|
|
|
+
|
|
|
+ var response = client.Send(PipeRequest.Info(new InfoRequest()), 10_000).GetResponse<InfoResponse>();
|
|
|
+ if (response.Status != StatusCode.Error)
|
|
|
+ {
|
|
|
+ DatabaseInfos[key] = response.Info;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DatabaseInfos.Remove(key);
|
|
|
+ var service = GetService(key);
|
|
|
+ if (service is null || service.Status != ServiceControllerStatus.Running)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Dispatcher.Invoke(() =>
|
|
|
+ {
|
|
|
+ InvalidateRow(row);
|
|
|
+ });
|
|
|
+ LoadingInfos.Remove(key);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(DatabaseInfos.TryGetValue(key, out var info))
|
|
|
+ {
|
|
|
+ DatabaseInfos.Remove(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
action(table, null);
|
|
|
|
|
|
- if (_monitor == null)
|
|
|
- _monitor = Task.Run(() =>
|
|
|
+ _monitor ??= Task.Run(() =>
|
|
|
{
|
|
|
while (true)
|
|
|
{
|