Skip to content

Commit

Permalink
added Mtu,Pre/Post Up/Down
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Albrecht committed Apr 1, 2024
1 parent 07600b6 commit 41f3e77
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ mkdir configfiles
# or for help of specific verb
./wgcfghelp gen-site --help
```

## Copyright

"WireGuard" and the "WireGuard" logo are registered trademarks of Jason A. Donenfeld.
5 changes: 5 additions & 0 deletions WgCfgHelp.CLI/Handler/ServerConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ private static int GenerateServerAccessFile(SiteConfigFile configFile,
var serverConfig = WgConfigFactory.GenServerConfig(address,
configFile.Port!.Value,
configFile.PrivateKey!,
configFile.PreUp,
configFile.PostUp,
configFile.PreDown,
configFile.PostDown,
configFile.Mtu,
wgQuickPeers
);

Expand Down
10 changes: 10 additions & 0 deletions WgCfgHelp.CLI/Models/SiteConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public class SiteConfigFile

public string? AllowedIPs { 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 List<PeerConfig> Peers { get; set; } = new List<PeerConfig>();

public static SiteConfigFile LoadFromFile(string path)
Expand Down
15 changes: 15 additions & 0 deletions WgCfgHelp.Lib/Models/WgQuickConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ public class WgQuickConfigFile

public int? ListenPort { 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 List<WgQuickPeer> Peers { get; set; } = new List<WgQuickPeer>();

public string ToConfigFileFormat()
Expand All @@ -28,6 +38,11 @@ public string ToConfigFileFormat()
output += $"PrivateKey = {PrivateKey}\n";
output += $"# PublicKey = {PublicKey}\n";
if(!string.IsNullOrWhiteSpace(DNS)) output += $"DNS = {DNS}\n";
if(Mtu is not null) output += $"MTU = {Mtu}\n";
if(!string.IsNullOrWhiteSpace(PreUp)) output += $"PreUp = {PreUp}\n";
if(!string.IsNullOrWhiteSpace(PreDown)) output += $"PreDown = {PreDown}\n";
if(!string.IsNullOrWhiteSpace(PostUp)) output += $"PostUp = {PostUp}\n";
if(!string.IsNullOrWhiteSpace(PostDown)) output += $"PostDown = {PostDown}\n";
if (ListenPort.HasValue) output += $"ListenPort = {ListenPort}\n";

foreach (var peer in Peers)
Expand Down
12 changes: 11 additions & 1 deletion WgCfgHelp.Lib/WgConfigFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public class WgConfigFactory
public static WgQuickConfigFile GenServerConfig(
string address,
int port,
string privateKey,
string privateKey,
string? preUp,
string? postUp,
string? preDown,
string? postDown,
int? mtu,
List<WgQuickPeer> peers)
{
var wgExeInt = WgExeInterface.Create();
Expand All @@ -23,6 +28,11 @@ public static WgQuickConfigFile GenServerConfig(
Address = address,
PrivateKey = privateKey,
ListenPort = port,
PreUp = preUp,
PostUp = postUp,
PreDown = preDown,
PostDown = postDown,
Mtu = mtu,
};
wgConfig.PublicKey = wgExeInt.GenPublicKey(wgConfig.PrivateKey);
wgConfig.Peers = peers;
Expand Down

0 comments on commit 41f3e77

Please sign in to comment.