Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit b5992fe

Browse files
authored
Merge pull request Place1#178 from nathanael-h/feature/filename
Feature: new variable filename to change the name of the configuration file
2 parents e72829f + 27170df commit b5992fe

File tree

8 files changed

+49
-10
lines changed

8 files changed

+49
-10
lines changed

cmd/serve/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func Register(app *kingpin.Application) *servecmd {
4545
cli.Flag("external-host", "The external origin of the server (e.g. https://mydomain.com)").Envar("WG_EXTERNAL_HOST").StringVar(&cmd.AppConfig.ExternalHost)
4646
cli.Flag("storage", "The storage backend connection string").Envar("WG_STORAGE").Default("memory://").StringVar(&cmd.AppConfig.Storage)
4747
cli.Flag("disable-metadata", "Disable metadata collection (i.e. metrics)").Envar("WG_DISABLE_METADATA").Default("false").BoolVar(&cmd.AppConfig.DisableMetadata)
48+
cli.Flag("filename", "The configuration filename (e.g. WireGuard-Home)").Envar("WG_FILENAME").StringVar(&cmd.AppConfig.Filename)
4849
cli.Flag("wireguard-enabled", "Enable or disable the embedded wireguard server (useful for development)").Envar("WG_WIREGUARD_ENABLED").Default("true").BoolVar(&cmd.AppConfig.WireGuard.Enabled)
4950
cli.Flag("wireguard-interface", "Set the wireguard interface name").Default("wg0").Envar("WG_WIREGUARD_INTERFACE").StringVar(&cmd.AppConfig.WireGuard.Interface)
5051
cli.Flag("wireguard-private-key", "Wireguard private key").Envar("WG_WIREGUARD_PRIVATE_KEY").StringVar(&cmd.AppConfig.WireGuard.PrivateKey)

docs/2-configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Here's what you can configure:
3737
| `WG_EXTERNAL_HOST` | `--external-host` | `externalHost` | | | The external domain for the server (e.g. www.mydomain.com) |
3838
| `WG_STORAGE` | `--storage` | `storage` | | `sqlite3:///data/db.sqlite3` | A storage backend connection string. See [storage docs](./3-storage.md) |
3939
| `WG_DISABLE_METADATA` | `--disable-metadata` | `disableMetadata` | | `false` | Turn off collection of device metadata logging. Includes last handshake time and RX/TX bytes only. |
40+
| `WG_FILENAME ` | `--filename` | `filename` | | `WireGuard` | Change the name of the configuration file the user can download (Do not include the '.conf' extension )|
4041
| `WG_WIREGUARD_ENABLED` | `--[no-]wireguard-enabled` | `wireguard.enabled` | | `true` | Enable/disable the wireguard server. Useful for development on non-linux machines. |
4142
| `WG_WIREGUARD_INTERFACE` | `--wireguard-interface` | `wireguard.interface` | | `wg0` | The wireguard network interface name |
4243
| `WG_WIREGUARD_PRIVATE_KEY` | `--wireguard-private-key` | `wireguard.privateKey` | Yes | | The wireguard private key. This value is required and must be stable. If this value changes all devices must re-register. |

internal/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ type AppConfig struct {
2929
// DisableMetadata allows you to turn off collection of device
3030
// metadata including last handshake time & rx/tx bytes
3131
DisableMetadata bool `yaml:"disableMetadata"`
32+
// The name of the WireGuard configuration file that can
33+
// be downloaded through the web UI after adding a device.
34+
// Do not include the '.conf' extension
35+
// Defaults to 'WireGuard' (resulting full name 'WireGuard.conf')
36+
Filename string `yaml:"filename"`
3237
// Configure WireGuard related settings
3338
WireGuard struct {
3439
// Set this to false to disable the embedded wireguard

internal/services/server_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (s *ServerService) Info(ctx context.Context, req *proto.InfoReq) (*proto.In
6767
AllowedIps: allowedIPs(s.Config),
6868
DnsEnabled: s.Config.DNS.Enabled,
6969
DnsAddress: dnsAddress,
70+
Filename: s.Config.Filename,
7071
}, nil
7172
}
7273

proto/proto/server.pb.go

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/server.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ message InfoRes {
2424
string allowed_ips = 7;
2525
bool dns_enabled = 8;
2626
string dns_address = 9;
27+
string filename = 10;
2728
}

website/src/components/GetConnected.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { GetApp } from '@material-ui/icons';
1111
import Laptop from '@material-ui/icons/Laptop';
1212
import PhoneIphone from '@material-ui/icons/PhoneIphone';
1313
import React from 'react';
14+
import { AppState } from '../AppState';
1415
import { isMobile } from '../Platform';
1516
import { download } from '../Util';
1617
import { LinuxIcon, MacOSIcon, WindowsIcon } from './Icons';
@@ -31,8 +32,9 @@ export class GetConnected extends React.Component<Props> {
3132
};
3233

3334
download = () => {
35+
const info = AppState.info!;
3436
download({
35-
filename: 'WireGuard.conf',
37+
filename: info.filename.length > 0 ? info.filename + '.conf' : 'WireGuard.conf',
3638
content: this.props.configFile,
3739
});
3840
};

website/src/sdk/server_pb.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export declare namespace InfoRes {
116116
allowedIps: string,
117117
dnsEnabled: boolean,
118118
dnsAddress: string,
119+
filename: string,
119120
}
120121
}
121122

@@ -195,6 +196,13 @@ export class InfoRes extends jspb.Message {
195196
(jspb.Message as any).setProto3StringField(this, 9, value);
196197
}
197198

199+
getFilename(): string {return jspb.Message.getFieldWithDefault(this, 10, "");
200+
}
201+
202+
setFilename(value: string): void {
203+
(jspb.Message as any).setProto3StringField(this, 10, value);
204+
}
205+
198206
serializeBinary(): Uint8Array {
199207
const writer = new jspb.BinaryWriter();
200208
InfoRes.serializeBinaryToWriter(this, writer);
@@ -213,6 +221,7 @@ export class InfoRes extends jspb.Message {
213221
allowedIps: this.getAllowedIps(),
214222
dnsEnabled: this.getDnsEnabled(),
215223
dnsAddress: this.getDnsAddress(),
224+
filename: this.getFilename(),
216225
};
217226
}
218227

@@ -253,6 +262,10 @@ export class InfoRes extends jspb.Message {
253262
if (field9.length > 0) {
254263
writer.writeString(9, field9);
255264
}
265+
const field10 = message.getFilename();
266+
if (field10.length > 0) {
267+
writer.writeString(10, field10);
268+
}
256269
}
257270

258271
static deserializeBinary(bytes: Uint8Array): InfoRes {
@@ -305,6 +318,10 @@ export class InfoRes extends jspb.Message {
305318
const field9 = reader.readString()
306319
message.setDnsAddress(field9);
307320
break;
321+
case 10:
322+
const field10 = reader.readString()
323+
message.setFilename(field10);
324+
break;
308325
default:
309326
reader.skipField();
310327
break;
@@ -338,6 +355,7 @@ function InfoResFromObject(obj: InfoRes.AsObject | undefined): InfoRes | undefin
338355
message.setAllowedIps(obj.allowedIps);
339356
message.setDnsEnabled(obj.dnsEnabled);
340357
message.setDnsAddress(obj.dnsAddress);
358+
message.setFilename(obj.filename);
341359
return message;
342360
}
343361

0 commit comments

Comments
 (0)