Skip to content

Commit e9357d8

Browse files
authored
Added Table to global settings (ngoduykhanh#308)
1 parent 5913332 commit e9357d8

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ docker-compose up
5050
| `WGUI_MTU` | The default MTU used in global settings | `1450` |
5151
| `WGUI_PERSISTENT_KEEPALIVE` | The default persistent keepalive for WireGuard in global settings | `15` |
5252
| `WGUI_FIREWALL_MARK` | The default WireGuard firewall mark | `0xca6c` (51820) |
53+
| `WGUI_TABLE` | The default WireGuard table value settings | `auto` |
5354
| `WGUI_CONFIG_FILE_PATH` | The default WireGuard config file path used in global settings | `/etc/wireguard/wg0.conf` |
5455
| `WGUI_LOG_LEVEL` | The default log level. Possible values: `DEBUG`, `INFO`, `WARN`, `ERROR`, `OFF` | `INFO` |
5556
| `WG_CONF_TEMPLATE` | The custom `wg.conf` config file template. Please refer to our [default template](https://github.com/ngoduykhanh/wireguard-ui/blob/master/templates/wg.conf) | N/A |

model/setting.go

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type GlobalSetting struct {
1111
MTU int `json:"mtu,string"`
1212
PersistentKeepalive int `json:"persistent_keepalive,string"`
1313
FirewallMark string `json:"firewall_mark"`
14+
Table string `json:"table"`
1415
ConfigFilePath string `json:"config_file_path"`
1516
UpdatedAt time.Time `json:"updated_at"`
1617
}

store/jsondb/jsondb.go

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (o *JsonDB) Init() error {
102102
globalSetting.MTU = util.LookupEnvOrInt(util.MTUEnvVar, util.DefaultMTU)
103103
globalSetting.PersistentKeepalive = util.LookupEnvOrInt(util.PersistentKeepaliveEnvVar, util.DefaultPersistentKeepalive)
104104
globalSetting.FirewallMark = util.LookupEnvOrString(util.FirewallMarkEnvVar, util.DefaultFirewallMark)
105+
globalSetting.Table = util.LookupEnvOrString(util.TableEnvVar, util.DefaultTable)
105106
globalSetting.ConfigFilePath = util.LookupEnvOrString(util.ConfigFilePathEnvVar, util.DefaultConfigFilePath)
106107
globalSetting.UpdatedAt = time.Now().UTC()
107108
o.conn.Write("server", "global_settings", globalSetting)

templates/global_settings.html

+14-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ <h3 class="card-title">Wireguard Global Settings</h3>
6161
name="firewall_mark" placeholder="Firewall Mark"
6262
value="{{ .globalSettings.FirewallMark }}">
6363
</div>
64+
<div class="form-group">
65+
<label for="Table">Table</label>
66+
<input type="text" class="form-control" id="table"
67+
name="table" placeholder="auto"
68+
value="{{ .globalSettings.Table }}">
69+
</div>
6470
<div class="form-group">
6571
<label for="config_file_path">Wireguard Config File Path</label>
6672
<input type="text" class="form-control" id="config_file_path"
@@ -102,7 +108,9 @@ <h3 class="card-title">Help</h3>
102108
<dd>Leave blank to omit this setting in the Client config.</dd>
103109
<dt>5. Firewall Mark</dt>
104110
<dd>Add a matching <code>fwmark</code> on all packets going out of a WireGuard non-default-route tunnel. Default value: <code>0xca6c</code></dd>
105-
<dt>6. Wireguard Config File Path</dt>
111+
<dt>6. Table</dt>
112+
<dd>Value for the <code>Table</code> setting in the wg conf file. Default value: <code>auto</code></dd>
113+
<dt>7. Wireguard Config File Path</dt>
106114
<dd>The path of your Wireguard server config file. Please make sure the parent directory
107115
exists and is writable.</dd>
108116
</dl>
@@ -150,8 +158,9 @@ <h4 class="modal-title">Endpoint Address Suggestion</h4>
150158
const mtu = $("#mtu").val();
151159
const persistent_keepalive = $("#persistent_keepalive").val();
152160
const firewall_mark = $("#firewall_mark").val();
161+
const table = $("#table").val();
153162
const config_file_path = $("#config_file_path").val();
154-
const data = {"endpoint_address": endpoint_address, "dns_servers": dns_servers, "mtu": mtu, "persistent_keepalive": persistent_keepalive, "firewall_mark": firewall_mark, "config_file_path": config_file_path};
163+
const data = {"endpoint_address": endpoint_address, "dns_servers": dns_servers, "mtu": mtu, "persistent_keepalive": persistent_keepalive, "firewall_mark": firewall_mark, "table": table, "config_file_path": config_file_path};
155164

156165
$.ajax({
157166
cache: false,
@@ -224,6 +233,9 @@ <h4 class="modal-title">Endpoint Address Suggestion</h4>
224233
},
225234
firewall_mark: {
226235
required: false
236+
},
237+
table: {
238+
required: false
227239
}
228240
},
229241
messages: {

templates/wg.conf

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PrivateKey = {{ .serverConfig.KeyPair.PrivateKey }}
1010
{{if .globalSettings.MTU}}MTU = {{ .globalSettings.MTU }}{{end}}
1111
PostUp = {{ .serverConfig.Interface.PostUp }}
1212
PostDown = {{ .serverConfig.Interface.PostDown }}
13+
Table = {{ .globalSettings.Table }}
1314

1415
{{range .clientDataList}}{{if eq .Client.Enabled true}}
1516
# ID: {{ .Client.ID }}

util/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
DefaultMTU = 1450
3232
DefaultPersistentKeepalive = 15
3333
DefaultFirewallMark = "0xca6c" // i.e. 51820
34+
DefaultTable = "auto"
3435
DefaultConfigFilePath = "/etc/wireguard/wg0.conf"
3536
UsernameEnvVar = "WGUI_USERNAME"
3637
PasswordEnvVar = "WGUI_PASSWORD"
@@ -41,6 +42,7 @@ const (
4142
MTUEnvVar = "WGUI_MTU"
4243
PersistentKeepaliveEnvVar = "WGUI_PERSISTENT_KEEPALIVE"
4344
FirewallMarkEnvVar = "WGUI_FIREWALL_MARK"
45+
TableEnvVar = "WGUI_TABLE"
4446
ConfigFilePathEnvVar = "WGUI_CONFIG_FILE_PATH"
4547
LogLevel = "WGUI_LOG_LEVEL"
4648
ServerAddressesEnvVar = "WGUI_SERVER_INTERFACE_ADDRESSES"

0 commit comments

Comments
 (0)