2026-06-11 10:19:43 +02:00
|
|
|
using System.Net.Sockets;
|
2026-06-26 13:27:17 +02:00
|
|
|
using System.Text;
|
2026-06-11 10:19:43 +02:00
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace ITNexusAgent.UI;
|
|
|
|
|
|
|
|
|
|
public partial class RdpConsentWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private readonly int _port;
|
2026-06-26 13:27:17 +02:00
|
|
|
private readonly string _secret;
|
2026-06-11 10:19:43 +02:00
|
|
|
private bool _answered = false;
|
|
|
|
|
private System.Threading.CancellationTokenSource _countdownCts = new();
|
|
|
|
|
|
2026-06-26 13:27:17 +02:00
|
|
|
public RdpConsentWindow(int port, string secret)
|
2026-06-11 10:19:43 +02:00
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_port = port;
|
2026-06-26 13:27:17 +02:00
|
|
|
_secret = secret;
|
2026-06-11 10:19:43 +02:00
|
|
|
_ = RunCountdownAsync(_countdownCts.Token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task RunCountdownAsync(System.Threading.CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 30; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (ct.IsCancellationRequested) return;
|
|
|
|
|
Dispatcher.Invoke(() => CountdownText.Text = $"Automatische Ablehnung in {i} Sekunden");
|
|
|
|
|
await Task.Delay(1000, ct).ContinueWith(_ => { });
|
|
|
|
|
}
|
|
|
|
|
if (!_answered)
|
|
|
|
|
{
|
|
|
|
|
SendResponse(false);
|
|
|
|
|
Dispatcher.Invoke(Close);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AcceptButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_countdownCts.Cancel();
|
|
|
|
|
SendResponse(true);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DenyButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_countdownCts.Cancel();
|
|
|
|
|
SendResponse(false);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendResponse(bool accepted)
|
|
|
|
|
{
|
|
|
|
|
if (_answered) return;
|
|
|
|
|
_answered = true;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var tcp = new TcpClient();
|
|
|
|
|
tcp.Connect("127.0.0.1", _port);
|
2026-06-26 13:27:17 +02:00
|
|
|
var stream = tcp.GetStream();
|
|
|
|
|
stream.Write(Encoding.ASCII.GetBytes(_secret));
|
|
|
|
|
stream.WriteByte((byte)(accepted ? 1 : 0));
|
|
|
|
|
stream.Flush();
|
2026-06-11 10:19:43 +02:00
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
}
|