Allowed is a property of the server, copy goes to clients

alphons <alphons@heijden.com> 29 Aug 2025, 21:25
3af5df99b7ae1beb8cbccb8adbe3f6e9a44a03a9
6 files changed
  • WireGuardConfigGenerator/DataModel/AppSettings.cs
  • WireGuardConfigGenerator/Helpers/TreeHelpers.cs
  • WireGuardConfigGenerator/UserControlPeer.Designer.cs
  • WireGuardConfigGenerator/UserControlPeer.cs
  • WireGuardConfigGenerator/UserControlServer.Designer.cs
  • WireGuardConfigGenerator/UserControlServer.cs
diff --git a/WireGuardConfigGenerator/DataModel/AppSettings.cs b/WireGuardConfigGenerator/DataModel/AppSettings.cs
index 554f63f..642a7f9 100644
--- a/WireGuardConfigGenerator/DataModel/AppSettings.cs
+++ b/WireGuardConfigGenerator/DataModel/AppSettings.cs
@@ -2,9 +2,9 @@
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 Endpoint { get; set; } = "vpn.example.com:56900";
+ public string Address { get; set; } = "10.0.0.1/32";
+ public int ListenPort { get; set; } = 56900;
+ public int PersistentKeepalive { get; set; } = 25;
public string PostUp { get; set; } = string.Empty;
}
diff --git a/WireGuardConfigGenerator/Helpers/TreeHelpers.cs b/WireGuardConfigGenerator/Helpers/TreeHelpers.cs
index ab32540..dde18c8 100644
--- a/WireGuardConfigGenerator/Helpers/TreeHelpers.cs
+++ b/WireGuardConfigGenerator/Helpers/TreeHelpers.cs
@@ -86,6 +86,7 @@ public static class TreeHelpers
ParentGroup = group,
ListenPort = settings.ListenPort + (group.Servers.Count * 100) - ((root.Groups.Count - 1) * 1000),
Address = settings.Address,
+ AllowedIPs = $"{GetSubnet(settings.Address)}.0/24",
Endpoint = settings.Endpoint,
PostUp = string.Format(settings.PostUp, name),
PrivateKey = privateKey,
@@ -112,7 +113,6 @@ public static class TreeHelpers
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
diff --git a/WireGuardConfigGenerator/UserControlPeer.Designer.cs b/WireGuardConfigGenerator/UserControlPeer.Designer.cs
index 2d52a22..bf536b2 100644
--- a/WireGuardConfigGenerator/UserControlPeer.Designer.cs
+++ b/WireGuardConfigGenerator/UserControlPeer.Designer.cs
@@ -34,13 +34,13 @@
txtConf = new TextBox();
tabPage1 = new TabPage();
groupBox1 = new GroupBox();
+ txtDnsServers = new TextBox();
+ label7 = new Label();
button3 = new Button();
button1 = new Button();
comboBox1 = new ComboBox();
txtPersistenKeepAlive = new TextBox();
label8 = new Label();
- txtAllowedIPs = new TextBox();
- label5 = new Label();
txtPrivateKey = new TextBox();
label1 = new Label();
txtListenPort = new TextBox();
@@ -54,8 +54,6 @@
buttonEdit = new Button();
lblName = new Label();
label4 = new Label();
- label7 = new Label();
- txtDnsServers = new TextBox();
tabControl1.SuspendLayout();
tabPage0.SuspendLayout();
tabPage1.SuspendLayout();
@@ -137,8 +135,6 @@
groupBox1.Controls.Add(comboBox1);
groupBox1.Controls.Add(txtPersistenKeepAlive);
groupBox1.Controls.Add(label8);
- groupBox1.Controls.Add(txtAllowedIPs);
- groupBox1.Controls.Add(label5);
groupBox1.Controls.Add(txtPrivateKey);
groupBox1.Controls.Add(label1);
groupBox1.Controls.Add(txtListenPort);
@@ -155,6 +151,23 @@
groupBox1.TabStop = false;
groupBox1.Text = "peer";
//
+ // txtDnsServers
+ //
+ txtDnsServers.Font = new Font("Consolas", 8.25F);
+ txtDnsServers.Location = new Point(240, 160);
+ txtDnsServers.Name = "txtDnsServers";
+ txtDnsServers.Size = new Size(159, 20);
+ txtDnsServers.TabIndex = 23;
+ //
+ // label7
+ //
+ label7.AutoSize = true;
+ label7.Location = new Point(145, 162);
+ label7.Name = "label7";
+ label7.Size = new Size(69, 15);
+ label7.TabIndex = 22;
+ label7.Text = "DNS servers";
+ //
// button3
//
button3.Location = new Point(264, 45);
@@ -188,7 +201,7 @@
// txtPersistenKeepAlive
//
txtPersistenKeepAlive.Font = new Font("Consolas", 8.25F);
- txtPersistenKeepAlive.Location = new Point(81, 189);
+ txtPersistenKeepAlive.Location = new Point(81, 160);
txtPersistenKeepAlive.Name = "txtPersistenKeepAlive";
txtPersistenKeepAlive.Size = new Size(40, 20);
txtPersistenKeepAlive.TabIndex = 12;
@@ -196,29 +209,12 @@
// label8
//
label8.AutoSize = true;
- label8.Location = new Point(10, 192);
+ label8.Location = new Point(10, 163);
label8.Name = "label8";
label8.Size = new Size(59, 15);
label8.TabIndex = 11;
label8.Text = "KeepAlive";
//
- // txtAllowedIPs
- //
- txtAllowedIPs.Font = new Font("Consolas", 8.25F);
- txtAllowedIPs.Location = new Point(81, 160);
- txtAllowedIPs.Name = "txtAllowedIPs";
- txtAllowedIPs.Size = new Size(318, 20);
- txtAllowedIPs.TabIndex = 9;
- //
- // label5
- //
- label5.AutoSize = true;
- label5.Location = new Point(10, 163);
- label5.Name = "label5";
- label5.Size = new Size(65, 15);
- label5.TabIndex = 8;
- label5.Text = "AllowedIPs";
- //
// txtPrivateKey
//
txtPrivateKey.Font = new Font("Consolas", 8.25F);
@@ -341,23 +337,6 @@
label4.TabIndex = 12;
label4.Text = "Name:";
//
- // label7
- //
- label7.AutoSize = true;
- label7.Location = new Point(145, 191);
- label7.Name = "label7";
- label7.Size = new Size(69, 15);
- label7.TabIndex = 22;
- label7.Text = "DNS servers";
- //
- // txtDnsServers
- //
- txtDnsServers.Font = new Font("Consolas", 8.25F);
- txtDnsServers.Location = new Point(240, 189);
- txtDnsServers.Name = "txtDnsServers";
- txtDnsServers.Size = new Size(159, 20);
- txtDnsServers.TabIndex = 23;
- //
// UserControlPeer
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -395,8 +374,6 @@
private Button buttonEdit;
private Button button2;
private TextBox txtConf;
- private TextBox txtAllowedIPs;
- private Label label5;
private TextBox txtPersistenKeepAlive;
private Label label8;
private ComboBox comboBox1;
diff --git a/WireGuardConfigGenerator/UserControlPeer.cs b/WireGuardConfigGenerator/UserControlPeer.cs
index 3e2c7a1..6965b95 100644
--- a/WireGuardConfigGenerator/UserControlPeer.cs
+++ b/WireGuardConfigGenerator/UserControlPeer.cs
@@ -33,9 +33,7 @@ public partial class UserControlPeer : UserControl
PrivateKey = {this.peer.PrivateKey}
ListenPort = {this.peer.ListenPort}
Address = {this.peer.Address}
- DNS = {this.peer.DNS}
-
- """;
+ """ + (string.IsNullOrEmpty(peer.DNS) ? "" : $"{Environment.NewLine}DNS = {peer.DNS}{Environment.NewLine}");
var server = peer.ParentServer;
@@ -43,11 +41,11 @@ public partial class UserControlPeer : UserControl
return;
config += $"""
-
+ {Environment.NewLine}
[Peer]
Eindpoint ={server.Endpoint}
PublicKey = {server.PubKey}
- AllowedIPs = {peer.AllowedIPs}
+ AllowedIPs = {server.AllowedIPs}
PersistentKeepalive = {peer.PersistentKeepalive}
""";
@@ -94,7 +92,6 @@ public partial class UserControlPeer : UserControl
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();
this.txtDnsServers.Text = peer.DNS;
}
@@ -109,7 +106,6 @@ public partial class UserControlPeer : UserControl
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.peer.DNS = this.txtDnsServers.Text;
diff --git a/WireGuardConfigGenerator/UserControlServer.Designer.cs b/WireGuardConfigGenerator/UserControlServer.Designer.cs
index cac808f..156ba57 100644
--- a/WireGuardConfigGenerator/UserControlServer.Designer.cs
+++ b/WireGuardConfigGenerator/UserControlServer.Designer.cs
@@ -54,6 +54,8 @@
buttonEdit = new Button();
lblName = new Label();
label7 = new Label();
+ txtAllowedIPs = new TextBox();
+ label8 = new Label();
tabControl1.SuspendLayout();
tabPage0.SuspendLayout();
tabPage1.SuspendLayout();
@@ -80,7 +82,7 @@
// txtPublicKey
//
txtPublicKey.Font = new Font("Consolas", 8.25F);
- txtPublicKey.Location = new Point(73, 117);
+ txtPublicKey.Location = new Point(73, 115);
txtPublicKey.Name = "txtPublicKey";
txtPublicKey.Size = new Size(318, 20);
txtPublicKey.TabIndex = 3;
@@ -97,7 +99,7 @@
// txtListenPort
//
txtListenPort.Font = new Font("Consolas", 8.25F);
- txtListenPort.Location = new Point(316, 156);
+ txtListenPort.Location = new Point(316, 145);
txtListenPort.Name = "txtListenPort";
txtListenPort.Size = new Size(76, 20);
txtListenPort.TabIndex = 5;
@@ -105,7 +107,7 @@
// label3
//
label3.AutoSize = true;
- label3.Location = new Point(250, 159);
+ label3.Location = new Point(250, 146);
label3.Name = "label3";
label3.Size = new Size(60, 15);
label3.TabIndex = 4;
@@ -114,7 +116,7 @@
// txtAddress
//
txtAddress.Font = new Font("Consolas", 8.25F);
- txtAddress.Location = new Point(74, 156);
+ txtAddress.Location = new Point(73, 143);
txtAddress.Name = "txtAddress";
txtAddress.Size = new Size(108, 20);
txtAddress.TabIndex = 7;
@@ -122,7 +124,7 @@
// label4
//
label4.AutoSize = true;
- label4.Location = new Point(18, 159);
+ label4.Location = new Point(17, 146);
label4.Name = "label4";
label4.Size = new Size(49, 15);
label4.TabIndex = 6;
@@ -133,17 +135,17 @@
txtPostUp.AcceptsReturn = true;
txtPostUp.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
txtPostUp.Font = new Font("Consolas", 8.25F);
- txtPostUp.Location = new Point(74, 185);
+ txtPostUp.Location = new Point(73, 198);
txtPostUp.Multiline = true;
txtPostUp.Name = "txtPostUp";
txtPostUp.ScrollBars = ScrollBars.Both;
- txtPostUp.Size = new Size(427, 142);
+ txtPostUp.Size = new Size(429, 129);
txtPostUp.TabIndex = 9;
//
// label5
//
label5.AutoSize = true;
- label5.Location = new Point(23, 188);
+ label5.Location = new Point(22, 198);
label5.Name = "label5";
label5.Size = new Size(45, 15);
label5.TabIndex = 8;
@@ -217,6 +219,8 @@
// groupBox1
//
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ groupBox1.Controls.Add(txtAllowedIPs);
+ groupBox1.Controls.Add(label8);
groupBox1.Controls.Add(button3);
groupBox1.Controls.Add(button2);
groupBox1.Controls.Add(comboBox1);
@@ -265,7 +269,7 @@
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] { "16", "24", "32" });
- comboBox1.Location = new Point(188, 156);
+ comboBox1.Location = new Point(187, 143);
comboBox1.Name = "comboBox1";
comboBox1.Size = new Size(46, 23);
comboBox1.TabIndex = 13;
@@ -273,7 +277,7 @@
// txtEndpoint
//
txtEndpoint.Font = new Font("Consolas", 8.25F);
- txtEndpoint.Location = new Point(74, 22);
+ txtEndpoint.Location = new Point(73, 22);
txtEndpoint.Name = "txtEndpoint";
txtEndpoint.Size = new Size(318, 20);
txtEndpoint.TabIndex = 11;
@@ -326,7 +330,7 @@
//
lblName.AutoSize = true;
lblName.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point, 0);
- lblName.Location = new Point(80, 21);
+ lblName.Location = new Point(79, 21);
lblName.Name = "lblName";
lblName.Size = new Size(16, 15);
lblName.TabIndex = 15;
@@ -341,6 +345,23 @@
label7.TabIndex = 14;
label7.Text = "Name:";
//
+ // txtAllowedIPs
+ //
+ txtAllowedIPs.Font = new Font("Consolas", 8.25F);
+ txtAllowedIPs.Location = new Point(73, 172);
+ txtAllowedIPs.Name = "txtAllowedIPs";
+ txtAllowedIPs.Size = new Size(318, 20);
+ txtAllowedIPs.TabIndex = 22;
+ //
+ // label8
+ //
+ label8.AutoSize = true;
+ label8.Location = new Point(2, 175);
+ label8.Name = "label8";
+ label8.Size = new Size(65, 15);
+ label8.TabIndex = 21;
+ label8.Text = "AllowedIPs";
+ //
// UserControlServer
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -386,5 +407,7 @@
private ComboBox comboBox1;
private Button button2;
private Button button3;
+ private TextBox txtAllowedIPs;
+ private Label label8;
}
}
diff --git a/WireGuardConfigGenerator/UserControlServer.cs b/WireGuardConfigGenerator/UserControlServer.cs
index 7df0239..a492977 100644
--- a/WireGuardConfigGenerator/UserControlServer.cs
+++ b/WireGuardConfigGenerator/UserControlServer.cs
@@ -28,6 +28,7 @@ public partial class UserControlServer : UserControl
this.txtAddress.Text = server.Address?.Split('/')[0];
this.comboBox1.SelectedItem = server.Address?.Split('/')[1];
this.txtPostUp.Text = server.PostUp;
+ this.txtAllowedIPs.Text = server.AllowedIPs;
}
private void Edit_Click(object sender, EventArgs e)
@@ -61,6 +62,7 @@ public partial class UserControlServer : UserControl
this.server.Address = $"{this.txtAddress.Text}/{this.comboBox1.SelectedItem}";
this.server.PostUp = this.txtPostUp.Text;
this.server.PubKey = this.txtPublicKey.Text;
+ this.server.AllowedIPs = this.txtAllowedIPs.Text;
this.buttonEdit.Enabled = true;
this.buttonCancel.Enabled = false;
@@ -93,9 +95,8 @@ public partial class UserControlServer : UserControl
PrivateKey = {this.server.PrivateKey}
ListenPort = {this.server.ListenPort}
Address = {this.server.Address}
- PostUp = {this.server.PostUp}
-
- """;
+ """ + (string.IsNullOrEmpty(server.PostUp) ? "" : $"{Environment.NewLine}PostUp = {server.PostUp}{Environment.NewLine}") +
+ $"{Environment.NewLine}";
foreach (var peer in server.Peers)
{