Skip to content

Commit

Permalink
Added: new variable filename to change the name of the configuration …
Browse files Browse the repository at this point in the history
…file that we download
  • Loading branch information
nathanael-h authored and DasSkelett committed May 6, 2022
1 parent e72829f commit 27170df
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/serve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/2-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
5 changes: 5 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/services/server_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
28 changes: 19 additions & 9 deletions proto/proto/server.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ message InfoRes {
string allowed_ips = 7;
bool dns_enabled = 8;
string dns_address = 9;
string filename = 10;
}
4 changes: 3 additions & 1 deletion website/src/components/GetConnected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,8 +32,9 @@ export class GetConnected extends React.Component<Props> {
};

download = () => {
const info = AppState.info!;
download({
filename: 'WireGuard.conf',
filename: info.filename.length > 0 ? info.filename + '.conf' : 'WireGuard.conf',
content: this.props.configFile,
});
};
Expand Down
18 changes: 18 additions & 0 deletions website/src/sdk/server_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export declare namespace InfoRes {
allowedIps: string,
dnsEnabled: boolean,
dnsAddress: string,
filename: string,
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -213,6 +221,7 @@ export class InfoRes extends jspb.Message {
allowedIps: this.getAllowedIps(),
dnsEnabled: this.getDnsEnabled(),
dnsAddress: this.getDnsAddress(),
filename: this.getFilename(),
};
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 27170df

Please sign in to comment.