Add project files.

alphons <alphons@heijden.com> 29 Aug 2025, 16:50
4219b4f490fd4c85bcf6fcb65704bc1bb933d54e
19 files changed
  • WireGuardConfigGenerator.sln
  • WireGuardConfigGenerator/DataModel/AppSettings.cs
  • WireGuardConfigGenerator/DataModel/Root.cs
  • WireGuardConfigGenerator/Form1.Designer.cs
  • WireGuardConfigGenerator/Form1.cs
  • WireGuardConfigGenerator/Form1.resx
  • WireGuardConfigGenerator/Helpers/WireGuard.cs
  • WireGuardConfigGenerator/Program.cs
  • WireGuardConfigGenerator/UserControlPeer.Designer.cs
  • WireGuardConfigGenerator/UserControlPeer.cs
  • WireGuardConfigGenerator/UserControlPeer.resx
  • WireGuardConfigGenerator/UserControlServer.Designer.cs
  • WireGuardConfigGenerator/UserControlServer.cs
  • WireGuardConfigGenerator/UserControlServer.resx
  • WireGuardConfigGenerator/UserControlTree.Designer.cs
  • WireGuardConfigGenerator/UserControlTree.cs
  • WireGuardConfigGenerator/UserControlTree.resx
  • WireGuardConfigGenerator/WireGuardConfigGenerator.csproj
  • WireGuardConfigGenerator/config.json
diff --git a/WireGuardConfigGenerator.sln b/WireGuardConfigGenerator.sln
new file mode 100644
index 0000000..3cb5b1f
--- /dev/null
+++ b/WireGuardConfigGenerator.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.14.36408.4 d17.14
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireGuardConfigGenerator", "WireGuardConfigGenerator\WireGuardConfigGenerator.csproj", "{6128C892-FF63-405E-BDD8-5555DBB8D6A5}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6128C892-FF63-405E-BDD8-5555DBB8D6A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6128C892-FF63-405E-BDD8-5555DBB8D6A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6128C892-FF63-405E-BDD8-5555DBB8D6A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6128C892-FF63-405E-BDD8-5555DBB8D6A5}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {BD343489-6E82-4C33-88C9-55741032F11D}
+ EndGlobalSection
+EndGlobal
diff --git a/WireGuardConfigGenerator/DataModel/AppSettings.cs b/WireGuardConfigGenerator/DataModel/AppSettings.cs
new file mode 100644
index 0000000..554f63f
--- /dev/null
+++ b/WireGuardConfigGenerator/DataModel/AppSettings.cs
@@ -0,0 +1,10 @@
+namespace WireGuardConfigGenerator.DataModel;
+
+public class AppSettings
+{
+ public string Endpoint { get; set; } = null!;
+ public string Address { get; set; } = string.Empty;
+ public int ListenPort { get; set; }
+ public int PersistentKeepalive { get; set; }
+ public string PostUp { get; set; } = string.Empty;
+}
diff --git a/WireGuardConfigGenerator/DataModel/Root.cs b/WireGuardConfigGenerator/DataModel/Root.cs
new file mode 100644
index 0000000..0c04f59
--- /dev/null
+++ b/WireGuardConfigGenerator/DataModel/Root.cs
@@ -0,0 +1,107 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace WireGuardConfigGenerator.DataModel;
+
+
+public class Root
+{
+ private static readonly JsonSerializerOptions options = new()
+ {
+ WriteIndented = true,
+ DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
+ };
+
+ public List<Group> Groups { get; set; } = [];
+
+ public void Save()
+ {
+ var json =JsonSerializer.Serialize(this, options);
+ File.WriteAllText("root.json", json);
+ }
+
+ public void Load()
+ {
+ if (File.Exists("root.json"))
+ {
+ var json = File.ReadAllText("root.json");
+ var obj = JsonSerializer.Deserialize<Root>(json);
+ if (obj != null)
+ {
+ Groups = obj.Groups;
+ }
+ }
+ }
+}
+
+public class Group
+{
+ public string Name { get; set; } = string.Empty;
+ public List<Server> Servers { get; set; } = [];
+}
+
+public class WireGuardItem
+{
+ public string Name { get; set; } = string.Empty;
+ public string? PubKey { get; set; }
+ public string? PrivateKey { get; set; }
+ public int ListenPort { get; set; }
+ public string? AllowedIPs { get; set; }
+ public string Address { get; set; } = "0.0.0.0";
+ public string? DNS { get; set; }
+}
+
+public class Server : WireGuardItem
+{
+ public int MTU { get; set; }
+ public string? PreUp { get; set; }
+ public string? PostUp { get; set; }
+ public string? PreDown { get; set; }
+ public string? PostDown { get; set; }
+ public string? Comment { get; set; }
+ public bool Disabled { get; set; }
+ public bool SaveConfig { get; set; }
+ public bool UseDNS { get; set; }
+ public bool UseMTU { get; set; }
+ public bool UsePreUp { get; set; }
+ public bool UsePostUp { get; set; }
+ public bool UsePreDown { get; set; }
+ public bool UsePostDown { get; set; }
+ public string? Endpoint { get; set; }
+
+ [JsonIgnore]
+ public Group? ParentGroup { get; set; }
+ public List<Peer> Peers { get; set; } = [];
+}
+
+public class Peer : WireGuardItem
+{
+ public int PersistentMaxConnections { get; set; }
+ public int PersistentMinConnections { get; set; }
+ public string? PersistentConnectionInterval { get; set; }
+ public int MTU { get; set; }
+ public string? PreUp { get; set; }
+ public string? PostUp { get; set; }
+ public string? PreDown { get; set; }
+ public string? PostDown { get; set; }
+ public string? Comment { get; set; }
+ public bool Disabled { get; set; }
+ public bool SaveConfig { get; set; }
+ public bool UseDNS { get; set; }
+ public bool UseMTU { get; set; }
+ public bool UsePreUp { get; set; }
+ public bool UsePostUp { get; set; }
+ public bool UsePreDown { get; set; }
+ public bool UsePostDown { get; set; }
+ public bool UsePersistentKeepalive { get; set; }
+ public bool UsePersistentMaxConnections { get; set; }
+ public bool UsePersistentMinConnections { get; set; }
+ public bool UsePersistentConnectionInterval { get; set; }
+ public bool UsePersistentConnectionTimeout { get; set; }
+ public int PersistentKeepalive { get; set; }
+
+ [JsonIgnore]
+ public Server? ParentServer { get; set; }
+
+
+}
diff --git a/WireGuardConfigGenerator/Form1.Designer.cs b/WireGuardConfigGenerator/Form1.Designer.cs
new file mode 100644
index 0000000..834a6da
--- /dev/null
+++ b/WireGuardConfigGenerator/Form1.Designer.cs
@@ -0,0 +1,124 @@
+namespace WireGuardConfigGenerator
+{
+ partial class Form1
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ menuStrip1 = new MenuStrip();
+ fileToolStripMenuItem = new ToolStripMenuItem();
+ exitToolStripMenuItem = new ToolStripMenuItem();
+ statusStrip1 = new StatusStrip();
+ splitContainer1 = new SplitContainer();
+ userControlTree1 = new UserControlTree();
+ menuStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
+ splitContainer1.Panel1.SuspendLayout();
+ splitContainer1.SuspendLayout();
+ SuspendLayout();
+ //
+ // menuStrip1
+ //
+ menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
+ menuStrip1.Location = new Point(0, 0);
+ menuStrip1.Name = "menuStrip1";
+ menuStrip1.Size = new Size(1022, 24);
+ menuStrip1.TabIndex = 0;
+ menuStrip1.Text = "menuStrip1";
+ //
+ // fileToolStripMenuItem
+ //
+ fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { exitToolStripMenuItem });
+ fileToolStripMenuItem.Name = "fileToolStripMenuItem";
+ fileToolStripMenuItem.Size = new Size(37, 20);
+ fileToolStripMenuItem.Text = "File";
+ //
+ // exitToolStripMenuItem
+ //
+ exitToolStripMenuItem.Name = "exitToolStripMenuItem";
+ exitToolStripMenuItem.Size = new Size(93, 22);
+ exitToolStripMenuItem.Text = "Exit";
+ exitToolStripMenuItem.Click += Exit_Click;
+ //
+ // statusStrip1
+ //
+ statusStrip1.Location = new Point(0, 539);
+ statusStrip1.Name = "statusStrip1";
+ statusStrip1.Size = new Size(1022, 22);
+ statusStrip1.TabIndex = 1;
+ statusStrip1.Text = "statusStrip1";
+ //
+ // splitContainer1
+ //
+ splitContainer1.Dock = DockStyle.Fill;
+ splitContainer1.Location = new Point(0, 24);
+ splitContainer1.Name = "splitContainer1";
+ //
+ // splitContainer1.Panel1
+ //
+ splitContainer1.Panel1.Controls.Add(userControlTree1);
+ splitContainer1.Size = new Size(1022, 515);
+ splitContainer1.SplitterDistance = 339;
+ splitContainer1.TabIndex = 2;
+ //
+ // userControlTree1
+ //
+ userControlTree1.Dock = DockStyle.Fill;
+ userControlTree1.Location = new Point(0, 0);
+ userControlTree1.Name = "userControlTree1";
+ userControlTree1.Size = new Size(339, 515);
+ userControlTree1.TabIndex = 0;
+ //
+ // Form1
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1022, 561);
+ Controls.Add(splitContainer1);
+ Controls.Add(statusStrip1);
+ Controls.Add(menuStrip1);
+ MainMenuStrip = menuStrip1;
+ Name = "Form1";
+ Text = "WireGuardConfigGenerator";
+ menuStrip1.ResumeLayout(false);
+ menuStrip1.PerformLayout();
+ splitContainer1.Panel1.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
+ splitContainer1.ResumeLayout(false);
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem fileToolStripMenuItem;
+ private ToolStripMenuItem exitToolStripMenuItem;
+ private StatusStrip statusStrip1;
+ private SplitContainer splitContainer1;
+ private UserControlTree userControlTree1;
+ }
+}
diff --git a/WireGuardConfigGenerator/Form1.cs b/WireGuardConfigGenerator/Form1.cs
new file mode 100644
index 0000000..0460222
--- /dev/null
+++ b/WireGuardConfigGenerator/Form1.cs
@@ -0,0 +1,17 @@
+namespace WireGuardConfigGenerator;
+
+public partial class Form1 : Form
+{
+ public Form1()
+ {
+ InitializeComponent();
+ }
+
+ public Panel GetPanel() => this.splitContainer1.Panel2;
+
+ private void Exit_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+}
diff --git a/WireGuardConfigGenerator/Form1.resx b/WireGuardConfigGenerator/Form1.resx
new file mode 100644
index 0000000..4ce0ae7
--- /dev/null
+++ b/WireGuardConfigGenerator/Form1.resx
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>17, 17</value>
+ </metadata>
+ <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>132, 17</value>
+ </metadata>
+</root>
\ No newline at end of file
diff --git a/WireGuardConfigGenerator/Helpers/WireGuard.cs b/WireGuardConfigGenerator/Helpers/WireGuard.cs
new file mode 100644
index 0000000..21ce34b
--- /dev/null
+++ b/WireGuardConfigGenerator/Helpers/WireGuard.cs
@@ -0,0 +1,26 @@
+using System.Diagnostics;
+
+namespace WireGuardConfigGenerator.Helpers;
+
+public class WireGuard
+{
+ public static async Task<string> ExecuteAsync(string command)
+ {
+ using Process process = new()
+ {
+ StartInfo = new ProcessStartInfo
+ {
+ FileName = "cmd.exe",
+ Arguments = $"/C {command}",
+ RedirectStandardOutput = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ }
+ };
+
+ process.Start();
+ string output = await process.StandardOutput.ReadToEndAsync();
+ await process.WaitForExitAsync();
+ return output.Trim();
+ }
+}
diff --git a/WireGuardConfigGenerator/Program.cs b/WireGuardConfigGenerator/Program.cs
new file mode 100644
index 0000000..78ddd9f
--- /dev/null
+++ b/WireGuardConfigGenerator/Program.cs
@@ -0,0 +1,17 @@
+namespace WireGuardConfigGenerator
+{
+ internal static class Program
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main()
+ {
+ // To customize application configuration such as set high DPI settings or default font,
+ // see https://aka.ms/applicationconfiguration.
+ ApplicationConfiguration.Initialize();
+ Application.Run(new Form1());
+ }
+ }
+}
\ No newline at end of file
diff --git a/WireGuardConfigGenerator/UserControlPeer.Designer.cs b/WireGuardConfigGenerator/UserControlPeer.Designer.cs
new file mode 100644
index 0000000..24ac761
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlPeer.Designer.cs
@@ -0,0 +1,364 @@
+namespace WireGuardConfigGenerator
+{
+ partial class UserControlPeer
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ tabControl1 = new TabControl();
+ tabPage0 = new TabPage();
+ button2 = new Button();
+ txtConf = new TextBox();
+ tabPage1 = new TabPage();
+ groupBox1 = new GroupBox();
+ comboBox1 = new ComboBox();
+ txtPersistenKeepAlive = new TextBox();
+ label8 = new Label();
+ txtAllowedIPs = new TextBox();
+ label5 = new Label();
+ txtPrivKey = new TextBox();
+ label1 = new Label();
+ txtListenPort = new TextBox();
+ txtAddress = new TextBox();
+ label3 = new Label();
+ label2 = new Label();
+ txtPublicKey = new TextBox();
+ label6 = new Label();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ buttonEdit = new Button();
+ lblName = new Label();
+ label4 = new Label();
+ button1 = new Button();
+ tabControl1.SuspendLayout();
+ tabPage0.SuspendLayout();
+ tabPage1.SuspendLayout();
+ groupBox1.SuspendLayout();
+ SuspendLayout();
+ //
+ // tabControl1
+ //
+ tabControl1.Controls.Add(tabPage0);
+ tabControl1.Controls.Add(tabPage1);
+ tabControl1.Dock = DockStyle.Fill;
+ tabControl1.Location = new Point(0, 0);
+ tabControl1.Name = "tabControl1";
+ tabControl1.SelectedIndex = 0;
+ tabControl1.Size = new Size(459, 399);
+ tabControl1.TabIndex = 12;
+ tabControl1.SelectedIndexChanged += TabControl_SelectedIndexChanged;
+ //
+ // tabPage0
+ //
+ tabPage0.Controls.Add(button2);
+ tabPage0.Controls.Add(txtConf);
+ tabPage0.Location = new Point(4, 24);
+ tabPage0.Name = "tabPage0";
+ tabPage0.Padding = new Padding(3);
+ tabPage0.Size = new Size(451, 259);
+ tabPage0.TabIndex = 1;
+ tabPage0.Text = "peer conf";
+ tabPage0.UseVisualStyleBackColor = true;
+ //
+ // button2
+ //
+ button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ button2.Location = new Point(339, 230);
+ button2.Name = "button2";
+ button2.Size = new Size(75, 23);
+ button2.TabIndex = 5;
+ button2.Text = "Copy";
+ button2.UseVisualStyleBackColor = true;
+ button2.Click += Copy_Click;
+ //
+ // txtConf
+ //
+ txtConf.AcceptsReturn = true;
+ txtConf.AcceptsTab = true;
+ txtConf.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ txtConf.Location = new Point(6, 6);
+ txtConf.Multiline = true;
+ txtConf.Name = "txtConf";
+ txtConf.ReadOnly = true;
+ txtConf.ScrollBars = ScrollBars.Both;
+ txtConf.Size = new Size(408, 218);
+ txtConf.TabIndex = 4;
+ //
+ // tabPage1
+ //
+ tabPage1.Controls.Add(groupBox1);
+ tabPage1.Controls.Add(buttonSave);
+ tabPage1.Controls.Add(buttonCancel);
+ tabPage1.Controls.Add(buttonEdit);
+ tabPage1.Controls.Add(lblName);
+ tabPage1.Controls.Add(label4);
+ tabPage1.Location = new Point(4, 24);
+ tabPage1.Name = "tabPage1";
+ tabPage1.Padding = new Padding(3);
+ tabPage1.Size = new Size(451, 371);
+ tabPage1.TabIndex = 0;
+ tabPage1.Text = "peer settings";
+ tabPage1.UseVisualStyleBackColor = true;
+ //
+ // groupBox1
+ //
+ groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ groupBox1.Controls.Add(button1);
+ groupBox1.Controls.Add(comboBox1);
+ groupBox1.Controls.Add(txtPersistenKeepAlive);
+ groupBox1.Controls.Add(label8);
+ groupBox1.Controls.Add(txtAllowedIPs);
+ groupBox1.Controls.Add(label5);
+ groupBox1.Controls.Add(txtPrivKey);
+ groupBox1.Controls.Add(label1);
+ groupBox1.Controls.Add(txtListenPort);
+ groupBox1.Controls.Add(txtAddress);
+ groupBox1.Controls.Add(label3);
+ groupBox1.Controls.Add(label2);
+ groupBox1.Controls.Add(txtPublicKey);
+ groupBox1.Controls.Add(label6);
+ groupBox1.Enabled = false;
+ groupBox1.Location = new Point(7, 31);
+ groupBox1.Name = "groupBox1";
+ groupBox1.Size = new Size(438, 305);
+ groupBox1.TabIndex = 19;
+ groupBox1.TabStop = false;
+ groupBox1.Text = "peer";
+ //
+ // comboBox1
+ //
+ comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBox1.FormattingEnabled = true;
+ comboBox1.Items.AddRange(new object[] { "16", "24", "32" });
+ comboBox1.Location = new Point(191, 122);
+ comboBox1.Name = "comboBox1";
+ comboBox1.Size = new Size(46, 23);
+ comboBox1.TabIndex = 14;
+ //
+ // txtPersistenKeepAlive
+ //
+ txtPersistenKeepAlive.Location = new Point(73, 180);
+ txtPersistenKeepAlive.Name = "txtPersistenKeepAlive";
+ txtPersistenKeepAlive.Size = new Size(40, 23);
+ txtPersistenKeepAlive.TabIndex = 12;
+ //
+ // label8
+ //
+ label8.AutoSize = true;
+ label8.Location = new Point(2, 183);
+ label8.Name = "label8";
+ label8.Size = new Size(59, 15);
+ label8.TabIndex = 11;
+ label8.Text = "KeepAlive";
+ //
+ // txtAllowedIPs
+ //
+ txtAllowedIPs.Location = new Point(73, 151);
+ txtAllowedIPs.Name = "txtAllowedIPs";
+ txtAllowedIPs.Size = new Size(318, 23);
+ txtAllowedIPs.TabIndex = 9;
+ //
+ // label5
+ //
+ label5.AutoSize = true;
+ label5.Location = new Point(2, 154);
+ label5.Name = "label5";
+ label5.Size = new Size(65, 15);
+ label5.TabIndex = 8;
+ label5.Text = "AllowedIPs";
+ //
+ // txtPrivKey
+ //
+ txtPrivKey.Location = new Point(73, 22);
+ txtPrivKey.Name = "txtPrivKey";
+ txtPrivKey.Size = new Size(318, 23);
+ txtPrivKey.TabIndex = 1;
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(7, 125);
+ label1.Name = "label1";
+ label1.Size = new Size(49, 15);
+ label1.TabIndex = 6;
+ label1.Text = "Address";
+ //
+ // txtListenPort
+ //
+ txtListenPort.Location = new Point(315, 122);
+ txtListenPort.Name = "txtListenPort";
+ txtListenPort.Size = new Size(76, 23);
+ txtListenPort.TabIndex = 5;
+ //
+ // txtAddress
+ //
+ txtAddress.Location = new Point(73, 122);
+ txtAddress.Name = "txtAddress";
+ txtAddress.Size = new Size(112, 23);
+ txtAddress.TabIndex = 7;
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(249, 125);
+ label3.Name = "label3";
+ label3.Size = new Size(60, 15);
+ label3.TabIndex = 4;
+ label3.Text = "ListenPort";
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(20, 25);
+ label2.Name = "label2";
+ label2.Size = new Size(46, 15);
+ label2.TabIndex = 0;
+ label2.Text = "PrivKey";
+ //
+ // txtPublicKey
+ //
+ txtPublicKey.Location = new Point(73, 51);
+ txtPublicKey.Name = "txtPublicKey";
+ txtPublicKey.Size = new Size(318, 23);
+ txtPublicKey.TabIndex = 3;
+ //
+ // label6
+ //
+ label6.AutoSize = true;
+ label6.Location = new Point(7, 54);
+ label6.Name = "label6";
+ label6.Size = new Size(59, 15);
+ label6.TabIndex = 2;
+ label6.Text = "PublicKey";
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Enabled = false;
+ buttonSave.Location = new Point(373, 342);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 22;
+ buttonSave.Text = "Save";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += Save_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Enabled = false;
+ buttonCancel.Location = new Point(240, 342);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 21;
+ buttonCancel.Text = "Cancel";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += Cancel_Click;
+ //
+ // buttonEdit
+ //
+ buttonEdit.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonEdit.Location = new Point(159, 342);
+ buttonEdit.Name = "buttonEdit";
+ buttonEdit.Size = new Size(75, 23);
+ buttonEdit.TabIndex = 20;
+ buttonEdit.Text = "Edit";
+ buttonEdit.UseVisualStyleBackColor = true;
+ buttonEdit.Click += Edit_Click;
+ //
+ // lblName
+ //
+ lblName.AutoSize = true;
+ lblName.Location = new Point(51, 13);
+ lblName.Name = "lblName";
+ lblName.Size = new Size(16, 15);
+ lblName.TabIndex = 13;
+ lblName.Text = "...";
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(7, 13);
+ label4.Name = "label4";
+ label4.Size = new Size(39, 15);
+ label4.TabIndex = 12;
+ label4.Text = "Name";
+ //
+ // button1
+ //
+ button1.Location = new Point(73, 80);
+ button1.Name = "button1";
+ button1.Size = new Size(108, 23);
+ button1.TabIndex = 20;
+ button1.Text = "Renew keys";
+ button1.UseVisualStyleBackColor = true;
+ button1.Click += RenewKeys_Click;
+ //
+ // UserControlPeer
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ Controls.Add(tabControl1);
+ Name = "UserControlPeer";
+ Size = new Size(459, 399);
+ tabControl1.ResumeLayout(false);
+ tabPage0.ResumeLayout(false);
+ tabPage0.PerformLayout();
+ tabPage1.ResumeLayout(false);
+ tabPage1.PerformLayout();
+ groupBox1.ResumeLayout(false);
+ groupBox1.PerformLayout();
+ ResumeLayout(false);
+ }
+
+ #endregion
+ private TabControl tabControl1;
+ private TabPage tabPage1;
+ private TabPage tabPage0;
+ private Label lblName;
+ private Label label4;
+ private GroupBox groupBox1;
+ private TextBox txtPrivKey;
+ private Label label1;
+ private TextBox txtListenPort;
+ private TextBox txtAddress;
+ private Label label3;
+ private Label label2;
+ private TextBox txtPublicKey;
+ private Label label6;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private Button buttonEdit;
+ private Button button2;
+ private TextBox txtConf;
+ private TextBox txtAllowedIPs;
+ private Label label5;
+ private TextBox txtPersistenKeepAlive;
+ private Label label8;
+ private ComboBox comboBox1;
+ private Button button1;
+ }
+}
diff --git a/WireGuardConfigGenerator/UserControlPeer.cs b/WireGuardConfigGenerator/UserControlPeer.cs
new file mode 100644
index 0000000..c361ba8
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlPeer.cs
@@ -0,0 +1,144 @@
+using WireGuardConfigGenerator.DataModel;
+using WireGuardConfigGenerator.Helpers;
+
+namespace WireGuardConfigGenerator;
+
+public partial class UserControlPeer : UserControl
+{
+ private readonly Peer? peer;
+ public UserControlPeer(Peer peer)
+ {
+ this.peer = peer;
+
+ InitializeComponent();
+
+ MakeConfig();
+ }
+
+ private void TabControl_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (this.tabControl1.SelectedIndex == 0)
+ MakeConfig();
+ if (this.tabControl1.SelectedIndex == 1)
+ ShowPeer();
+ }
+
+ private void MakeConfig()
+ {
+ if (this.peer == null)
+ return;
+
+ string config = $"""
+ [Interface]
+ PrivateKey = {this.peer.PrivateKey}
+ ListenPort = {this.peer.ListenPort}
+ Address = {this.peer.Address}
+
+ """;
+
+ var server = peer.ParentServer;
+
+ if (server == null)
+ return;
+
+ config += $"""
+
+ [Peer]
+ Eindpoint ={server.Endpoint}
+ PublicKey = {server.PubKey}
+ AllowedIPs = {peer.AllowedIPs}
+ PersistentKeepalive = {peer.PersistentKeepalive}
+ """;
+
+ this.txtConf.Text = config;
+ }
+
+ private void Copy_Click(object sender, EventArgs e)
+ {
+ Clipboard.SetText(this.txtConf.Text);
+ }
+
+ private void Edit_Click(object sender, EventArgs e)
+ {
+ this.buttonEdit.Enabled = false;
+ this.buttonCancel.Enabled = true;
+ this.buttonSave.Enabled = true;
+ this.groupBox1.Enabled = true;
+ }
+
+ private void Cancel_Click(object sender, EventArgs e)
+ {
+
+ this.buttonEdit.Enabled = true;
+ this.buttonCancel.Enabled = false;
+ this.buttonSave.Enabled = false;
+ this.groupBox1.Enabled = false;
+
+
+ ShowPeer();
+ }
+
+ private void ShowPeer()
+ {
+ if (peer == null)
+ return;
+
+ this.lblName.Text = peer.Name;
+
+ if (string.IsNullOrWhiteSpace(peer.AllowedIPs))
+ peer.AllowedIPs = $"{peer.ParentServer?.Address}";
+
+ this.txtPrivKey.Text = peer.PrivateKey;
+ this.txtPublicKey.Text = peer.PubKey;
+ this.txtListenPort.Text = peer.ListenPort.ToString();
+ this.txtAddress.Text = peer.Address?.Split('/')[0];
+ this.comboBox1.SelectedItem = peer.Address?.Split('/')[1];
+ this.txtAllowedIPs.Text = peer.AllowedIPs;
+ this.txtPersistenKeepAlive.Text = peer.PersistentKeepalive.ToString();
+ }
+
+
+ private void Save_Click(object sender, EventArgs e)
+ {
+ if (peer == null)
+ return;
+
+ this.peer.PrivateKey = this.txtPrivKey.Text;
+ this.peer.PubKey = this.txtPublicKey.Text;
+ this.peer.ListenPort = int.TryParse(this.txtListenPort.Text, out int port) ? port : 0;
+ this.peer.Address = $"{this.txtAddress.Text}/{this.comboBox1.SelectedItem}";
+ this.peer.AllowedIPs = this.txtAllowedIPs.Text;
+ this.peer.PersistentKeepalive = int.TryParse(this.txtPersistenKeepAlive.Text, out int pka) ? pka : 0;
+
+ this.buttonEdit.Enabled = true;
+ this.buttonCancel.Enabled = false;
+ this.buttonSave.Enabled = false;
+ this.groupBox1.Enabled = false;
+
+ ShowPeer();
+ }
+
+ private async Task RenewKeysAsync()
+ {
+ if (peer == null)
+ return;
+
+ string privateKey = await WireGuard.ExecuteAsync("wg genkey");
+ string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
+
+ peer.PrivateKey = privateKey;
+ peer.PubKey = publicKey;
+
+ this.Invoke(() =>
+ {
+ this.txtPrivKey.Text = peer.PrivateKey;
+ this.txtPublicKey.Text = peer.PubKey;
+ MakeConfig();
+ });
+ }
+
+ private async void RenewKeys_Click(object sender, EventArgs e)
+ {
+ await RenewKeysAsync();
+ }
+}
diff --git a/WireGuardConfigGenerator/UserControlPeer.resx b/WireGuardConfigGenerator/UserControlPeer.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlPeer.resx
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
\ No newline at end of file
diff --git a/WireGuardConfigGenerator/UserControlServer.Designer.cs b/WireGuardConfigGenerator/UserControlServer.Designer.cs
new file mode 100644
index 0000000..76e7a61
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlServer.Designer.cs
@@ -0,0 +1,368 @@
+namespace WireGuardConfigGenerator
+{
+ partial class UserControlServer
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ label1 = new Label();
+ txtPrivKey = new TextBox();
+ txtPublicKey = new TextBox();
+ label2 = new Label();
+ txtListenPort = new TextBox();
+ label3 = new Label();
+ txtAddress = new TextBox();
+ label4 = new Label();
+ txtPostUp = new TextBox();
+ label5 = new Label();
+ tabControl1 = new TabControl();
+ tabPage0 = new TabPage();
+ button1 = new Button();
+ txtConf = new TextBox();
+ tabPage1 = new TabPage();
+ groupBox1 = new GroupBox();
+ comboBox1 = new ComboBox();
+ txtEndpoint = new TextBox();
+ label6 = new Label();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ buttonEdit = new Button();
+ lblName = new Label();
+ label7 = new Label();
+ button2 = new Button();
+ tabControl1.SuspendLayout();
+ tabPage0.SuspendLayout();
+ tabPage1.SuspendLayout();
+ groupBox1.SuspendLayout();
+ SuspendLayout();
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(21, 59);
+ label1.Name = "label1";
+ label1.Size = new Size(46, 15);
+ label1.TabIndex = 0;
+ label1.Text = "PrivKey";
+ //
+ // txtPrivKey
+ //
+ txtPrivKey.Location = new Point(74, 56);
+ txtPrivKey.Name = "txtPrivKey";
+ txtPrivKey.Size = new Size(318, 23);
+ txtPrivKey.TabIndex = 1;
+ //
+ // txtPublicKey
+ //
+ txtPublicKey.Location = new Point(74, 85);
+ txtPublicKey.Name = "txtPublicKey";
+ txtPublicKey.Size = new Size(318, 23);
+ txtPublicKey.TabIndex = 3;
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(8, 88);
+ label2.Name = "label2";
+ label2.Size = new Size(59, 15);
+ label2.TabIndex = 2;
+ label2.Text = "PublicKey";
+ //
+ // txtListenPort
+ //
+ txtListenPort.Location = new Point(316, 156);
+ txtListenPort.Name = "txtListenPort";
+ txtListenPort.Size = new Size(76, 23);
+ txtListenPort.TabIndex = 5;
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(250, 159);
+ label3.Name = "label3";
+ label3.Size = new Size(60, 15);
+ label3.TabIndex = 4;
+ label3.Text = "ListenPort";
+ //
+ // txtAddress
+ //
+ txtAddress.Location = new Point(74, 156);
+ txtAddress.Name = "txtAddress";
+ txtAddress.Size = new Size(108, 23);
+ txtAddress.TabIndex = 7;
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(18, 159);
+ label4.Name = "label4";
+ label4.Size = new Size(49, 15);
+ label4.TabIndex = 6;
+ label4.Text = "Address";
+ //
+ // txtPostUp
+ //
+ txtPostUp.AcceptsReturn = true;
+ txtPostUp.Location = new Point(74, 185);
+ txtPostUp.Multiline = true;
+ txtPostUp.Name = "txtPostUp";
+ txtPostUp.ScrollBars = ScrollBars.Both;
+ txtPostUp.Size = new Size(318, 145);
+ txtPostUp.TabIndex = 9;
+ //
+ // label5
+ //
+ label5.AutoSize = true;
+ label5.Location = new Point(23, 188);
+ label5.Name = "label5";
+ label5.Size = new Size(45, 15);
+ label5.TabIndex = 8;
+ label5.Text = "PostUp";
+ //
+ // tabControl1
+ //
+ tabControl1.Controls.Add(tabPage0);
+ tabControl1.Controls.Add(tabPage1);
+ tabControl1.Dock = DockStyle.Fill;
+ tabControl1.Location = new Point(0, 0);
+ tabControl1.Name = "tabControl1";
+ tabControl1.SelectedIndex = 0;
+ tabControl1.Size = new Size(418, 453);
+ tabControl1.TabIndex = 12;
+ tabControl1.SelectedIndexChanged += TabControl_SelectedIndexChanged;
+ //
+ // tabPage0
+ //
+ tabPage0.Controls.Add(button1);
+ tabPage0.Controls.Add(txtConf);
+ tabPage0.Location = new Point(4, 24);
+ tabPage0.Name = "tabPage0";
+ tabPage0.Padding = new Padding(3);
+ tabPage0.Size = new Size(410, 376);
+ tabPage0.TabIndex = 1;
+ tabPage0.Text = "server conf";
+ tabPage0.UseVisualStyleBackColor = true;
+ //
+ // button1
+ //
+ button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ button1.Location = new Point(329, 347);
+ button1.Name = "button1";
+ button1.Size = new Size(75, 23);
+ button1.TabIndex = 1;
+ button1.Text = "Copy";
+ button1.UseVisualStyleBackColor = true;
+ button1.Click += Copy_Click;
+ //
+ // txtConf
+ //
+ txtConf.AcceptsReturn = true;
+ txtConf.AcceptsTab = true;
+ txtConf.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ txtConf.Location = new Point(3, 3);
+ txtConf.Multiline = true;
+ txtConf.Name = "txtConf";
+ txtConf.ReadOnly = true;
+ txtConf.ScrollBars = ScrollBars.Both;
+ txtConf.Size = new Size(401, 338);
+ txtConf.TabIndex = 0;
+ //
+ // tabPage1
+ //
+ tabPage1.Controls.Add(groupBox1);
+ tabPage1.Controls.Add(buttonSave);
+ tabPage1.Controls.Add(buttonCancel);
+ tabPage1.Controls.Add(buttonEdit);
+ tabPage1.Controls.Add(lblName);
+ tabPage1.Controls.Add(label7);
+ tabPage1.Location = new Point(4, 24);
+ tabPage1.Name = "tabPage1";
+ tabPage1.Padding = new Padding(3);
+ tabPage1.Size = new Size(410, 425);
+ tabPage1.TabIndex = 0;
+ tabPage1.Text = "server settings";
+ tabPage1.UseVisualStyleBackColor = true;
+ //
+ // groupBox1
+ //
+ groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ groupBox1.Controls.Add(button2);
+ groupBox1.Controls.Add(comboBox1);
+ groupBox1.Controls.Add(txtEndpoint);
+ groupBox1.Controls.Add(label6);
+ groupBox1.Controls.Add(txtPrivKey);
+ groupBox1.Controls.Add(label4);
+ groupBox1.Controls.Add(txtListenPort);
+ groupBox1.Controls.Add(txtAddress);
+ groupBox1.Controls.Add(label3);
+ groupBox1.Controls.Add(label5);
+ groupBox1.Controls.Add(label1);
+ groupBox1.Controls.Add(txtPublicKey);
+ groupBox1.Controls.Add(label2);
+ groupBox1.Controls.Add(txtPostUp);
+ groupBox1.Enabled = false;
+ groupBox1.Location = new Point(6, 48);
+ groupBox1.Name = "groupBox1";
+ groupBox1.Size = new Size(398, 342);
+ groupBox1.TabIndex = 13;
+ groupBox1.TabStop = false;
+ groupBox1.Text = "server";
+ //
+ // comboBox1
+ //
+ comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBox1.FormattingEnabled = true;
+ comboBox1.Items.AddRange(new object[] { "16", "24", "32" });
+ comboBox1.Location = new Point(188, 156);
+ comboBox1.Name = "comboBox1";
+ comboBox1.Size = new Size(46, 23);
+ comboBox1.TabIndex = 13;
+ //
+ // txtEndpoint
+ //
+ txtEndpoint.Location = new Point(74, 22);
+ txtEndpoint.Name = "txtEndpoint";
+ txtEndpoint.Size = new Size(318, 23);
+ txtEndpoint.TabIndex = 11;
+ //
+ // label6
+ //
+ label6.AutoSize = true;
+ label6.Location = new Point(13, 25);
+ label6.Name = "label6";
+ label6.Size = new Size(55, 15);
+ label6.TabIndex = 10;
+ label6.Text = "Endpoint";
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Enabled = false;
+ buttonSave.Location = new Point(322, 399);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 18;
+ buttonSave.Text = "Save";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += Save_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Enabled = false;
+ buttonCancel.Location = new Point(202, 399);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 17;
+ buttonCancel.Text = "Cancel";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += Cancel_Click;
+ //
+ // buttonEdit
+ //
+ buttonEdit.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonEdit.Location = new Point(121, 399);
+ buttonEdit.Name = "buttonEdit";
+ buttonEdit.Size = new Size(75, 23);
+ buttonEdit.TabIndex = 16;
+ buttonEdit.Text = "Edit";
+ buttonEdit.UseVisualStyleBackColor = true;
+ buttonEdit.Click += Edit_Click;
+ //
+ // lblName
+ //
+ lblName.AutoSize = true;
+ lblName.Location = new Point(68, 21);
+ lblName.Name = "lblName";
+ lblName.Size = new Size(16, 15);
+ lblName.TabIndex = 15;
+ lblName.Text = "...";
+ //
+ // label7
+ //
+ label7.AutoSize = true;
+ label7.Location = new Point(24, 21);
+ label7.Name = "label7";
+ label7.Size = new Size(39, 15);
+ label7.TabIndex = 14;
+ label7.Text = "Name";
+ //
+ // button2
+ //
+ button2.Location = new Point(74, 114);
+ button2.Name = "button2";
+ button2.Size = new Size(108, 23);
+ button2.TabIndex = 19;
+ button2.Text = "Renew keys";
+ button2.UseVisualStyleBackColor = true;
+ button2.Click += RenewKeys_Click;
+ //
+ // UserControlServer
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ Controls.Add(tabControl1);
+ Name = "UserControlServer";
+ Size = new Size(418, 453);
+ tabControl1.ResumeLayout(false);
+ tabPage0.ResumeLayout(false);
+ tabPage0.PerformLayout();
+ tabPage1.ResumeLayout(false);
+ tabPage1.PerformLayout();
+ groupBox1.ResumeLayout(false);
+ groupBox1.PerformLayout();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Label label1;
+ private TextBox txtPrivKey;
+ private TextBox txtPublicKey;
+ private Label label2;
+ private TextBox txtListenPort;
+ private Label label3;
+ private TextBox txtAddress;
+ private Label label4;
+ private TextBox txtPostUp;
+ private Label label5;
+ private TabControl tabControl1;
+ private TabPage tabPage1;
+ private TabPage tabPage0;
+ private TextBox txtConf;
+ private Label lblName;
+ private Label label7;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private Button buttonEdit;
+ private GroupBox groupBox1;
+ private Button button1;
+ private TextBox txtEndpoint;
+ private Label label6;
+ private ComboBox comboBox1;
+ private Button button2;
+ }
+}
diff --git a/WireGuardConfigGenerator/UserControlServer.cs b/WireGuardConfigGenerator/UserControlServer.cs
new file mode 100644
index 0000000..0adb110
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlServer.cs
@@ -0,0 +1,138 @@
+using WireGuardConfigGenerator.DataModel;
+using WireGuardConfigGenerator.Helpers;
+
+namespace WireGuardConfigGenerator;
+
+public partial class UserControlServer : UserControl
+{
+ private readonly Server? server;
+ public UserControlServer(Server server)
+ {
+ InitializeComponent();
+
+ this.server = server;
+
+ MakeConfig();
+ }
+
+ private void ShowServer()
+ {
+ if (server == null)
+ return;
+
+ this.txtEndpoint.Text = server.Endpoint;
+ this.txtPrivKey.Text = server.PrivateKey;
+ this.txtPublicKey.Text = server.PubKey;
+ this.lblName.Text = server.Name;
+ this.txtListenPort.Text = server.ListenPort.ToString();
+ this.txtAddress.Text = server.Address?.Split('/')[0];
+ this.comboBox1.SelectedItem = server.Address?.Split('/')[1];
+ this.txtPostUp.Text = server.PostUp;
+ }
+
+ private void Edit_Click(object sender, EventArgs e)
+ {
+ this.buttonEdit.Enabled = false;
+ this.buttonCancel.Enabled = true;
+ this.buttonSave.Enabled = true;
+ this.groupBox1.Enabled = true;
+ }
+
+ private void Cancel_Click(object sender, EventArgs e)
+ {
+
+ this.buttonEdit.Enabled = true;
+ this.buttonCancel.Enabled = false;
+ this.buttonSave.Enabled = false;
+ this.groupBox1.Enabled = false;
+
+
+ ShowServer();
+ }
+
+ private void Save_Click(object sender, EventArgs e)
+ {
+ if (server == null)
+ return;
+
+ this.server.Endpoint = this.txtEndpoint.Text;
+ this.server.PrivateKey = this.txtPrivKey.Text;
+ this.server.ListenPort = int.TryParse(this.txtListenPort.Text, out int port) ? port : 0;
+ this.server.Address = $"{this.txtAddress.Text}/{this.comboBox1.SelectedItem}";
+ this.server.PostUp = this.txtPostUp.Text;
+ this.server.PubKey = this.txtPublicKey.Text;
+
+ this.buttonEdit.Enabled = true;
+ this.buttonCancel.Enabled = false;
+ this.buttonSave.Enabled = false;
+ this.groupBox1.Enabled = false;
+
+ ShowServer();
+ }
+
+ private void Copy_Click(object sender, EventArgs e)
+ {
+ Clipboard.SetText(this.txtConf.Text);
+ }
+
+ private void TabControl_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ if (this.tabControl1.SelectedIndex == 0)
+ MakeConfig();
+ if (this.tabControl1.SelectedIndex == 1)
+ ShowServer();
+ }
+
+ private void MakeConfig()
+ {
+ if (this.server == null)
+ return;
+
+ string config = $"""
+ [Interface]
+ PrivateKey = {this.server.PrivateKey}
+ ListenPort = {this.server.ListenPort}
+ Address = {this.server.Address}
+ PostUp = {this.server.PostUp}
+
+ """;
+
+ foreach (var peer in server.Peers)
+ {
+ config += $"""
+
+ [Peer]
+ PublicKey = {peer.PubKey}
+ AllowedIPs = {peer.Address}
+ PersistentKeepalive = {peer.PersistentKeepalive}
+
+ """;
+ }
+
+ this.txtConf.Text = config;
+ }
+
+ private async void RenewKeys_Click(object sender, EventArgs e)
+ {
+ await RenewKeysAsync();
+ }
+
+ private async Task RenewKeysAsync()
+ {
+ if (server == null)
+ return;
+
+ string privateKey = await WireGuard.ExecuteAsync("wg genkey");
+ string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
+
+ server.PrivateKey = privateKey;
+ server.PubKey = publicKey;
+
+ this.Invoke(() =>
+ {
+ this.txtPrivKey.Text = server.PrivateKey;
+ this.txtPublicKey.Text = server.PubKey;
+ MakeConfig();
+ });
+ }
+}
diff --git a/WireGuardConfigGenerator/UserControlServer.resx b/WireGuardConfigGenerator/UserControlServer.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlServer.resx
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
\ No newline at end of file
diff --git a/WireGuardConfigGenerator/UserControlTree.Designer.cs b/WireGuardConfigGenerator/UserControlTree.Designer.cs
new file mode 100644
index 0000000..ecbf697
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlTree.Designer.cs
@@ -0,0 +1,72 @@
+namespace WireGuardConfigGenerator
+{
+ partial class UserControlTree
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ components = new System.ComponentModel.Container();
+ treeView1 = new TreeView();
+ contextMenuStrip1 = new ContextMenuStrip(components);
+ SuspendLayout();
+ //
+ // treeView1
+ //
+ treeView1.ContextMenuStrip = contextMenuStrip1;
+ treeView1.Dock = DockStyle.Fill;
+ treeView1.LabelEdit = true;
+ treeView1.Location = new Point(0, 0);
+ treeView1.Name = "treeView1";
+ treeView1.Size = new Size(138, 130);
+ treeView1.TabIndex = 0;
+ treeView1.AfterLabelEdit += TreeView_AfterLabelEdit;
+ treeView1.AfterSelect += TreeView_AfterSelect;
+ treeView1.DoubleClick += TreeView_DoubleClick;
+ treeView1.KeyDown += TreeView_KeyDown;
+ treeView1.MouseDown += TreeView_MouseDown;
+ //
+ // contextMenuStrip1
+ //
+ contextMenuStrip1.Name = "contextMenuStrip1";
+ contextMenuStrip1.Size = new Size(61, 4);
+ //
+ // UserControlTree
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ Controls.Add(treeView1);
+ Name = "UserControlTree";
+ Size = new Size(138, 130);
+ Load += UserControlTree_Load;
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private TreeView treeView1;
+ private ContextMenuStrip contextMenuStrip1;
+ }
+}
diff --git a/WireGuardConfigGenerator/UserControlTree.cs b/WireGuardConfigGenerator/UserControlTree.cs
new file mode 100644
index 0000000..98f12a5
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlTree.cs
@@ -0,0 +1,254 @@
+using System.Text.Json;
+using System.Xml.Linq;
+using WireGuardConfigGenerator.DataModel;
+using WireGuardConfigGenerator.Helpers;
+
+namespace WireGuardConfigGenerator;
+public partial class UserControlTree : UserControl
+{
+ private readonly AppSettings Settings;
+
+ private readonly Root root = new();
+ public UserControlTree()
+ {
+ InitializeComponent();
+
+ var path = Path.Combine(AppContext.BaseDirectory, "config.json");
+ if (File.Exists(path))
+ this.Settings = JsonSerializer.Deserialize<AppSettings>(File.ReadAllText(path)) ?? new();
+ else
+ this.Settings = new();
+ }
+
+ private void UserControlTree_Load(object sender, EventArgs e)
+ {
+ if (this.ParentForm is Form1 form)
+ form.FormClosing += (s, e) => root.Save();
+
+ LoadTree();
+ }
+
+ private void LoadTree()
+ {
+ root.Load();
+
+ this.treeView1.Nodes.Clear();
+ foreach (var group in root.Groups)
+ {
+ var groupNode = new TreeNode(group.Name) { Tag = group };
+ this.treeView1.Nodes.Add(groupNode);
+ foreach (var server in group.Servers)
+ {
+ server.ParentGroup = group;
+ var serverNode = new TreeNode(server.Name) { Tag = server };
+ groupNode.Nodes.Add(serverNode);
+ foreach (var peer in server.Peers)
+ {
+ peer.ParentServer = server;
+ var peerNode = new TreeNode(peer.Name) { Tag = peer };
+ serverNode.Nodes.Add(peerNode);
+ }
+ }
+ }
+ this.treeView1.ExpandAll();
+ }
+
+ private static DialogResult DeleteIt() =>
+ MessageBox.Show("Delete", "Delete it", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
+
+
+ private static string GetSubnet(string? ipAddress) =>
+ ipAddress == null ? "10.0.0" : ipAddress[..ipAddress.LastIndexOf('.')];
+
+
+ private static void DeleteGroup(Root root, TreeNode node, Group group)
+ {
+ if (DeleteIt() == DialogResult.OK)
+ {
+ root.Groups.Remove(group);
+ node.Remove();
+ }
+ }
+
+ private static void DeleteServer(TreeNode node, Server server)
+ {
+ if (DeleteIt() == DialogResult.OK)
+ {
+ server.ParentGroup?.Servers.Remove(server);
+ node.Remove();
+ }
+ }
+
+ private static void DeletePeer(TreeNode node, Peer peer)
+ {
+ if (DeleteIt() == DialogResult.OK)
+ {
+ peer.ParentServer?.Peers.Remove(peer);
+ node.Remove();
+ }
+ }
+
+ private async Task CreateNewServerAsync(TreeNode node, Group group)
+ {
+ string privateKey = await WireGuard.ExecuteAsync("wg genkey");
+ string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
+
+ var offset = group.Servers.Count + 1;
+ var name = $"Server {offset}";
+ Server server = new()
+ {
+ Name = name,
+ ParentGroup = group,
+ ListenPort = Settings.ListenPort + (group.Servers.Count * 100) - ((this.root.Groups.Count - 1) * 1000),
+ Address = Settings.Address,
+ Endpoint = Settings.Endpoint,
+ PostUp = string.Format(Settings.PostUp, name),
+ PrivateKey = privateKey,
+ PubKey = publicKey
+ };
+
+ group.Servers.Add(server);
+ node.Nodes.Add(new TreeNode(server.Name) { Tag = server });
+ node.Expand();
+ }
+
+ private async Task CreateNewPeerAsync(TreeNode node, Server server)
+ {
+ string privateKey = await WireGuard.ExecuteAsync("wg genkey");
+ string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
+
+ var offset = server.Peers.Count + 1;
+ var subnet = GetSubnet(server.Address);
+ Peer newPeer = new()
+ {
+ ParentServer = server,
+ Name = $"Peer {offset}",
+ Address = $"{subnet}.{offset + 1}/32",
+ ListenPort = server.ListenPort + offset + 1,
+ AllowedIPs = $"{server.Address.Split('/')[0]}/24",
+ PersistentKeepalive = Settings.PersistentKeepalive,
+ PrivateKey = privateKey,
+ PubKey = publicKey
+ };
+ server.Peers.Add(newPeer);
+ node.Nodes.Add(new TreeNode(newPeer.Name) { Tag = newPeer });
+ node.Expand();
+ }
+
+ private void ShowContextMenu(Point location)
+ {
+ this.contextMenuStrip1.Items.Clear();
+
+ if (this.treeView1.SelectedNode is not TreeNode node)
+ {
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Group", null, (s, e) =>
+ {
+ Group newGroup = new() { Name = "New Group" };
+ root.Groups.Add(newGroup);
+ this.treeView1.Nodes.Add(new TreeNode(newGroup.Name) { Tag = newGroup });
+ }));
+ }
+ else if (node.Tag is Group group)
+ {
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Server", null, async (s, e) => await CreateNewServerAsync(node, group)));
+
+ if (group.Servers.Count == 0)
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Group", null, (s, e) => DeleteGroup(root, node, group)));
+ }
+ else if (node.Tag is Server server)
+ {
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Peer", null, async (s, e) => await CreateNewPeerAsync(node, server)));
+
+ if (server.Peers.Count == 0)
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Server", null, (s, e) => DeleteServer(node, server)));
+ }
+ else if (node.Tag is Peer peer)
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Peer", null, (s, e) => DeletePeer(node, peer)));
+
+ this.contextMenuStrip1.Show(this.treeView1, location);
+ }
+
+ private void TreeView_AfterSelect(object sender, TreeViewEventArgs e)
+ {
+ if (this.ParentForm is not Form1 form)
+ return;
+
+ var panel = form.GetPanel();
+ panel.Controls.Clear();
+
+ if (e.Node?.Tag is Peer peer)
+ {
+ panel.Controls.Add(new UserControlPeer(peer) { Dock = DockStyle.Fill });
+ return;
+ }
+
+ if (e.Node?.Tag is Server server)
+ {
+ panel.Controls.Add(new UserControlServer(server) { Dock = DockStyle.Fill });
+ return;
+ }
+ }
+
+ private void TreeView_MouseDown(object sender, MouseEventArgs e)
+ {
+
+ var node = treeView1.GetNodeAt(e.X, e.Y);
+
+ this.treeView1.LabelEdit = node == this.treeView1.SelectedNode;
+
+ this.treeView1.SelectedNode = node;
+
+ if (e.Button == MouseButtons.Right)
+ ShowContextMenu(e.Location);
+
+ }
+
+ private void TreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
+ {
+ if (string.IsNullOrWhiteSpace(e.Label))
+ {
+ e.CancelEdit = true;
+ return;
+ }
+
+ if (e.Node?.Tag is Group group)
+ group.Name = e.Label;
+ else if (e.Node?.Tag is Server server)
+ {
+ server.Name = e.Label;
+ server.PostUp = string.Format(Settings.PostUp, server.Name);
+ }
+ else
+ if (e.Node?.Tag is Peer peer)
+ peer.Name = e.Label;
+ }
+
+ private void TreeView_DoubleClick(object sender, EventArgs e)
+ {
+ var treeNode = this.treeView1.SelectedNode;
+
+ if (treeNode == null)
+ return;
+
+ if (treeNode.Tag is not Peer peer)
+ return;
+
+
+ }
+
+ private void TreeView_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode != Keys.Delete)
+ return;
+
+ if (this.treeView1.SelectedNode is not TreeNode node)
+ return;
+
+ if (node.Tag is Group group && group.Servers.Count == 0)
+ DeleteGroup(root, node, group);
+ else if (node.Tag is Server server && server.Peers.Count == 0)
+ DeleteServer(node, server);
+ else if (node.Tag is Peer peer)
+ DeletePeer(node, peer);
+ }
+}
diff --git a/WireGuardConfigGenerator/UserControlTree.resx b/WireGuardConfigGenerator/UserControlTree.resx
new file mode 100644
index 0000000..68d1a99
--- /dev/null
+++ b/WireGuardConfigGenerator/UserControlTree.resx
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>17, 17</value>
+ </metadata>
+</root>
\ No newline at end of file
diff --git a/WireGuardConfigGenerator/WireGuardConfigGenerator.csproj b/WireGuardConfigGenerator/WireGuardConfigGenerator.csproj
new file mode 100644
index 0000000..dc7c573
--- /dev/null
+++ b/WireGuardConfigGenerator/WireGuardConfigGenerator.csproj
@@ -0,0 +1,21 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>WinExe</OutputType>
+ <TargetFramework>net8.0-windows</TargetFramework>
+ <Nullable>enable</Nullable>
+ <UseWindowsForms>true</UseWindowsForms>
+ <ImplicitUsings>enable</ImplicitUsings>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <None Remove="config.json" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <Content Include="config.json">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+
+</Project>
\ No newline at end of file
diff --git a/WireGuardConfigGenerator/config.json b/WireGuardConfigGenerator/config.json
new file mode 100644
index 0000000..09727ac
--- /dev/null
+++ b/WireGuardConfigGenerator/config.json
@@ -0,0 +1,7 @@
+{
+ "Endpoint": "vpn.example.com:56900",
+ "Address": "10.0.0.1/32",
+ "ListenPort": 56900,
+ "PersistentKeepalive": 25,
+ "PostUp": "powershell.exe -ExecutionPolicy Bypass -Command \u0022Set-NetConnectionProfile -InterfaceAlias \u0027{0}\u0027 -NetworkCategory Private; Set-NetIPInterface -InterfaceAlias \u0027{0}\u0027 -Forwarding Enabled\u0022"
+}
\ No newline at end of file