Skip to content

Commit

Permalink
Implement Debug Point, basically a console log that only outputs whil…
Browse files Browse the repository at this point in the history
…e in debug mode. Also updated README.md
  • Loading branch information
sakakun committed Nov 21, 2024
1 parent dd2bb16 commit bb5af05
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 34 deletions.
31 changes: 20 additions & 11 deletions Classes/pveAPI/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net.Http.Headers;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
Expand Down Expand Up @@ -47,22 +48,30 @@ public ApiClient(string server, string port, bool skipSSL)

public async Task<List<RealmData>> GetRealmsAsync()
{
try
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)))
{
var response = await _httpClient.GetAsync("access/domains").ConfigureAwait(false);
Console.WriteLine(response);
response.EnsureSuccessStatusCode();
try
{
var response = await _httpClient.GetAsync("access/domains", cts.Token).ConfigureAwait(false);
response.EnsureSuccessStatusCode();

var jsonData = JsonConvert.DeserializeObject<Dictionary<string, List<RealmData>>>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
return jsonData?["data"] ?? new List<RealmData>();
}
catch (Exception ex)
{
// Log or handle the exception as needed
return new List<RealmData>();
var jsonData = JsonConvert.DeserializeObject<Dictionary<string, List<RealmData>>>(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
return jsonData?["data"] ?? new List<RealmData>();
}
catch (TaskCanceledException)
{
MessageBox.Show("Could not reach the Proxmox API.\n\rPlease check your settings and try again.", "Server Error");
return new List<RealmData>();
}
catch (Exception)
{
MessageBox.Show("The server information provided doesn't lead to the Proxmox API.\n\rPlease check your settings and try again.", "Server Error");
return new List<RealmData>();
}
}
}


public async Task<bool> LoginAsync(string username, string password, string realm, string otp = null)
{

Expand Down
24 changes: 17 additions & 7 deletions Panels/ClientLogin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Proxmox_Desktop_Client.Classes;
using Proxmox_Desktop_Client.Classes.pveAPI;
Expand Down Expand Up @@ -33,35 +34,44 @@ private async void ClickCheckServer(object sender = null, EventArgs e = null)
string port = textBox_port.Text;
bool validateSsl = checkBox_ssl.Checked;

Console.WriteLine("Checking Server");
this.panel_credentials.Enabled = false;
this.panel_server.Enabled = false;
this.Width = 290;
CenterToScreen();

Program.DebugPoint($"Connecting to server: {server}:{port}, SSL:{validateSsl}");
_api = new ApiClient(server, port, validateSsl);
Console.WriteLine("Connected Server");

Program.DebugPoint($"Collecting Realm Data...");
var realms = await _api.GetRealmsAsync();
Console.WriteLine("Realms");

Program.DebugPoint($"Validating Realm Data...");
if (realms != null && realms.Count > 0)
{
comboBox_realm.DataSource = realms;
comboBox_realm.DisplayMember = "Comment";
comboBox_realm.ValueMember = "Realm";

string savedRealm = (string)Program._Config.GetSetting("Login_Realm");
if (!string.IsNullOrEmpty(savedRealm))
{
comboBox_realm.SelectedValue = savedRealm;
}


Program.DebugPoint($"Has Realm Data...");
panel_credentials.Visible = true;
Width = 570;
CenterToScreen();
}
else
{
{
Program.DebugPoint($"No Realm Data/Connection Error...");
comboBox_realm.DataSource = null;
Width = 290;
}

CenterToScreen();
this.panel_credentials.Enabled = true;
this.panel_server.Enabled = true;
}

private async void ValidateLogin(object sender, EventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions Panels/MainPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ private void xTermJS_Client(MachineData machineData)
new NoVNCClient(_api, machineData);
}

private void Spice_Client(int vmid)
private async void Spice_Client(int vmid)
{
var spiceClient = new SpiceClient(_api, _api.Machines.FirstOrDefault(m => m.Vmid == vmid));
spiceClient.RequestSpiceConnection();
await spiceClient.RequestSpiceConnection();
}

private async Task<bool> CheckSpiceAble(MachineData Machine)
Expand Down
10 changes: 10 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,15 @@ static void Main()
Application.Run(new ClientLogin());
}

public static void DebugPoint(string content)
{
bool debugMode = false;
#if DEBUG
debugMode = true;
#endif

Console.WriteLine(content);
}

}
}
15 changes: 2 additions & 13 deletions Proxmox Desktop Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<WarningLevel>3</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FubarCoder.RestSharp.Portable.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=be81bb0f53eab22f, processorArchitecture=MSIL">
Expand Down Expand Up @@ -139,7 +139,6 @@
<Compile Include="Classes\pveAPI\objects\dataServerUser.cs" />
<Compile Include="Classes\pveAPI\UserPermissions.cs" />
<Compile Include="Classes\Ticker.cs" />
<Compile Include="obj\Debug\.NETFramework,Version=v4.8.1.AssemblyAttributes.cs" />
<Compile Include="Panels\ClientLogin.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -193,16 +192,6 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="obj\Debug\Proxmox .1D3D995B.Up2Date" />
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.AssemblyReference.cache" />
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.CoreCompileInputs.cache" />
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.FileListAbsolute.txt" />
<Content Include="obj\Debug\Proxmox Desktop Client.csproj.GenerateResource.cache" />
<Content Include="obj\Debug\Proxmox_Desktop_Client.ClientLogin.resources" />
<Content Include="obj\Debug\Proxmox_Desktop_Client.exe" />
<Content Include="obj\Debug\Proxmox_Desktop_Client.MainPanel.resources" />
<Content Include="obj\Debug\Proxmox_Desktop_Client.pdb" />
<Content Include="obj\Debug\Proxmox_Desktop_Client.Properties.Resources.resources" />
<Content Include="Resources\Icons\default-icon.ico" />
<Content Include="Resources\Icons\default.png" />
<Content Include="Resources\icons_dots.png" />
Expand Down
2 changes: 2 additions & 0 deletions Proxmox Desktop Client.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeEditing/Localization/Localizable/@EntryValue">No</s:String></wpf:ResourceDictionary>
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ A Windows Desktop Client for Proxmox VE.
It's purpose is as designed. A way to remote virtual machines in my homelab without having to log in to Proxmox WebGUI.
The intent mostly was for the use of SPICE (virt-viewer) connectivity as some of my remote needs I can't use RDP but console view.
## Requirements for SPICE
- Virt-viewer && UsbDk (https://www.spice-space.org/download.html).
- Virt-viewer && UsbDk (https://www.spice-space.org/download.html).
- .Net 4.8.1 or Newer
## Functionality
- Plain & TOTP Login
- Remote (NoVNC/SPICE/xtermJS)
Expand Down

0 comments on commit bb5af05

Please sign in to comment.