From 27170dfb56864f7602ea98b1b93e067e3102fbf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20HANNEBERT?= Date: Wed, 4 May 2022 11:40:11 +0200 Subject: [PATCH] Added: new variable filename to change the name of the configuration file that we download --- cmd/serve/main.go | 1 + docs/2-configuration.md | 1 + internal/config/config.go | 5 +++++ internal/services/server_service.go | 1 + proto/proto/server.pb.go | 28 +++++++++++++++++-------- proto/server.proto | 1 + website/src/components/GetConnected.tsx | 4 +++- website/src/sdk/server_pb.ts | 18 ++++++++++++++++ 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/cmd/serve/main.go b/cmd/serve/main.go index 7d712777..6759623b 100644 --- a/cmd/serve/main.go +++ b/cmd/serve/main.go @@ -45,6 +45,7 @@ func Register(app *kingpin.Application) *servecmd { cli.Flag("external-host", "The external origin of the server (e.g. https://mydomain.com)").Envar("WG_EXTERNAL_HOST").StringVar(&cmd.AppConfig.ExternalHost) cli.Flag("storage", "The storage backend connection string").Envar("WG_STORAGE").Default("memory://").StringVar(&cmd.AppConfig.Storage) cli.Flag("disable-metadata", "Disable metadata collection (i.e. metrics)").Envar("WG_DISABLE_METADATA").Default("false").BoolVar(&cmd.AppConfig.DisableMetadata) + cli.Flag("filename", "The configuration filename (e.g. WireGuard-Home)").Envar("WG_FILENAME").StringVar(&cmd.AppConfig.Filename) 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) cli.Flag("wireguard-interface", "Set the wireguard interface name").Default("wg0").Envar("WG_WIREGUARD_INTERFACE").StringVar(&cmd.AppConfig.WireGuard.Interface) cli.Flag("wireguard-private-key", "Wireguard private key").Envar("WG_WIREGUARD_PRIVATE_KEY").StringVar(&cmd.AppConfig.WireGuard.PrivateKey) diff --git a/docs/2-configuration.md b/docs/2-configuration.md index 400d37d1..225e8616 100644 --- a/docs/2-configuration.md +++ b/docs/2-configuration.md @@ -37,6 +37,7 @@ Here's what you can configure: | `WG_EXTERNAL_HOST` | `--external-host` | `externalHost` | | | The external domain for the server (e.g. www.mydomain.com) | | `WG_STORAGE` | `--storage` | `storage` | | `sqlite3:///data/db.sqlite3` | A storage backend connection string. See [storage docs](./3-storage.md) | | `WG_DISABLE_METADATA` | `--disable-metadata` | `disableMetadata` | | `false` | Turn off collection of device metadata logging. Includes last handshake time and RX/TX bytes only. | +| `WG_FILENAME ` | `--filename` | `filename` | | `WireGuard` | Change the name of the configuration file the user can download (Do not include the '.conf' extension )| | `WG_WIREGUARD_ENABLED` | `--[no-]wireguard-enabled` | `wireguard.enabled` | | `true` | Enable/disable the wireguard server. Useful for development on non-linux machines. | | `WG_WIREGUARD_INTERFACE` | `--wireguard-interface` | `wireguard.interface` | | `wg0` | The wireguard network interface name | | `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. | diff --git a/internal/config/config.go b/internal/config/config.go index b5a41aa7..8d4aa25e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -29,6 +29,11 @@ type AppConfig struct { // DisableMetadata allows you to turn off collection of device // metadata including last handshake time & rx/tx bytes DisableMetadata bool `yaml:"disableMetadata"` + // The name of the WireGuard configuration file that can + // be downloaded through the web UI after adding a device. + // Do not include the '.conf' extension + // Defaults to 'WireGuard' (resulting full name 'WireGuard.conf') + Filename string `yaml:"filename"` // Configure WireGuard related settings WireGuard struct { // Set this to false to disable the embedded wireguard diff --git a/internal/services/server_service.go b/internal/services/server_service.go index 64329e10..0a71f4bf 100644 --- a/internal/services/server_service.go +++ b/internal/services/server_service.go @@ -67,6 +67,7 @@ func (s *ServerService) Info(ctx context.Context, req *proto.InfoReq) (*proto.In AllowedIps: allowedIPs(s.Config), DnsEnabled: s.Config.DNS.Enabled, DnsAddress: dnsAddress, + Filename: s.Config.Filename, }, nil } diff --git a/proto/proto/server.pb.go b/proto/proto/server.pb.go index 31a95ecc..8344c9ae 100644 --- a/proto/proto/server.pb.go +++ b/proto/proto/server.pb.go @@ -73,6 +73,7 @@ type InfoRes struct { AllowedIps string `protobuf:"bytes,7,opt,name=allowed_ips,json=allowedIps,proto3" json:"allowed_ips,omitempty"` DnsEnabled bool `protobuf:"varint,8,opt,name=dns_enabled,json=dnsEnabled,proto3" json:"dns_enabled,omitempty"` DnsAddress string `protobuf:"bytes,9,opt,name=dns_address,json=dnsAddress,proto3" json:"dns_address,omitempty"` + Filename string `protobuf:"bytes,10,opt,name=filename,proto3" json:"filename,omitempty"` } func (x *InfoRes) Reset() { @@ -170,6 +171,13 @@ func (x *InfoRes) GetDnsAddress() string { return "" } +func (x *InfoRes) GetFilename() string { + if x != nil { + return x.Filename + } + return "" +} + var File_server_proto protoreflect.FileDescriptor var file_server_proto_rawDesc = []byte{ @@ -177,7 +185,7 @@ var file_server_proto_rawDesc = []byte{ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x09, 0x0a, 0x07, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, - 0x22, 0xb7, 0x02, 0x0a, 0x07, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, + 0x22, 0xd3, 0x02, 0x0a, 0x07, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x12, 0x30, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, @@ -196,14 +204,16 @@ var file_server_proto_rawDesc = []byte{ 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x64, 0x6e, 0x73, 0x45, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x64, 0x6e, 0x73, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x64, 0x6e, 0x73, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x32, 0x32, 0x0a, 0x06, 0x53, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x12, 0x28, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x0e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x22, 0x00, 0x42, 0x35, - 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x66, 0x72, 0x65, - 0x69, 0x66, 0x75, 0x6e, 0x6b, 0x4d, 0x55, 0x43, 0x2f, 0x77, 0x67, 0x2d, 0x61, 0x63, 0x63, 0x65, - 0x73, 0x73, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x6e, 0x73, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x69, + 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, + 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x32, 0x32, 0x0a, 0x06, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x12, 0x28, 0x0a, 0x04, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x0e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x22, 0x00, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x66, 0x72, 0x65, 0x69, 0x66, 0x75, 0x6e, + 0x6b, 0x4d, 0x55, 0x43, 0x2f, 0x77, 0x67, 0x2d, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x2d, 0x73, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/server.proto b/proto/server.proto index 9654781f..4895d7ee 100644 --- a/proto/server.proto +++ b/proto/server.proto @@ -24,4 +24,5 @@ message InfoRes { string allowed_ips = 7; bool dns_enabled = 8; string dns_address = 9; + string filename = 10; } diff --git a/website/src/components/GetConnected.tsx b/website/src/components/GetConnected.tsx index c974948b..44c4a88f 100644 --- a/website/src/components/GetConnected.tsx +++ b/website/src/components/GetConnected.tsx @@ -11,6 +11,7 @@ import { GetApp } from '@material-ui/icons'; import Laptop from '@material-ui/icons/Laptop'; import PhoneIphone from '@material-ui/icons/PhoneIphone'; import React from 'react'; +import { AppState } from '../AppState'; import { isMobile } from '../Platform'; import { download } from '../Util'; import { LinuxIcon, MacOSIcon, WindowsIcon } from './Icons'; @@ -31,8 +32,9 @@ export class GetConnected extends React.Component { }; download = () => { + const info = AppState.info!; download({ - filename: 'WireGuard.conf', + filename: info.filename.length > 0 ? info.filename + '.conf' : 'WireGuard.conf', content: this.props.configFile, }); }; diff --git a/website/src/sdk/server_pb.ts b/website/src/sdk/server_pb.ts index e8ccf963..5f2fe3d6 100644 --- a/website/src/sdk/server_pb.ts +++ b/website/src/sdk/server_pb.ts @@ -116,6 +116,7 @@ export declare namespace InfoRes { allowedIps: string, dnsEnabled: boolean, dnsAddress: string, + filename: string, } } @@ -195,6 +196,13 @@ export class InfoRes extends jspb.Message { (jspb.Message as any).setProto3StringField(this, 9, value); } + getFilename(): string {return jspb.Message.getFieldWithDefault(this, 10, ""); + } + + setFilename(value: string): void { + (jspb.Message as any).setProto3StringField(this, 10, value); + } + serializeBinary(): Uint8Array { const writer = new jspb.BinaryWriter(); InfoRes.serializeBinaryToWriter(this, writer); @@ -213,6 +221,7 @@ export class InfoRes extends jspb.Message { allowedIps: this.getAllowedIps(), dnsEnabled: this.getDnsEnabled(), dnsAddress: this.getDnsAddress(), + filename: this.getFilename(), }; } @@ -253,6 +262,10 @@ export class InfoRes extends jspb.Message { if (field9.length > 0) { writer.writeString(9, field9); } + const field10 = message.getFilename(); + if (field10.length > 0) { + writer.writeString(10, field10); + } } static deserializeBinary(bytes: Uint8Array): InfoRes { @@ -305,6 +318,10 @@ export class InfoRes extends jspb.Message { const field9 = reader.readString() message.setDnsAddress(field9); break; + case 10: + const field10 = reader.readString() + message.setFilename(field10); + break; default: reader.skipField(); break; @@ -338,6 +355,7 @@ function InfoResFromObject(obj: InfoRes.AsObject | undefined): InfoRes | undefin message.setAllowedIps(obj.allowedIps); message.setDnsEnabled(obj.dnsEnabled); message.setDnsAddress(obj.dnsAddress); + message.setFilename(obj.filename); return message; }