Make MTU and PersistentKeepalive optional (#123)
This commit is contained in:
		
							parent
							
								
									3c1d894b44
								
							
						
					
					
						commit
						2d9eeb08e8
					
				|  | @ -44,17 +44,17 @@ | ||||||
|             </ul> |             </ul> | ||||||
| 
 | 
 | ||||||
|             <!-- SEARCH FORM --> |             <!-- SEARCH FORM --> | ||||||
|             <form class="form-inline ml-3"> | <!--            <form class="form-inline ml-3">--> | ||||||
|                 <div class="input-group input-group-sm"> | <!--                <div class="input-group input-group-sm">--> | ||||||
|                     <input class="form-control form-control-navbar" type="search" placeholder="Search" | <!--                    <input class="form-control form-control-navbar" type="search" placeholder="Search"--> | ||||||
|                         aria-label="Search"> | <!--                        aria-label="Search">--> | ||||||
|                     <div class="input-group-append"> | <!--                    <div class="input-group-append">--> | ||||||
|                         <button class="btn btn-navbar" type="submit"> | <!--                        <button class="btn btn-navbar" type="submit">--> | ||||||
|                             <i class="fas fa-search"></i> | <!--                            <i class="fas fa-search"></i>--> | ||||||
|                         </button> | <!--                        </button>--> | ||||||
|                     </div> | <!--                    </div>--> | ||||||
|                 </div> | <!--                </div>--> | ||||||
|             </form> | <!--            </form>--> | ||||||
| 
 | 
 | ||||||
|             <!-- Right navbar links --> |             <!-- Right navbar links --> | ||||||
|             <div class="navbar-nav ml-auto"> |             <div class="navbar-nav ml-auto"> | ||||||
|  |  | ||||||
|  | @ -47,13 +47,13 @@ Global Settings | ||||||
|                             <div class="form-group"> |                             <div class="form-group"> | ||||||
|                                 <label for="mtu">MTU</label> |                                 <label for="mtu">MTU</label> | ||||||
|                                 <input type="text" class="form-control" id="mtu" name="mtu" placeholder="MTU" |                                 <input type="text" class="form-control" id="mtu" name="mtu" placeholder="MTU" | ||||||
|                                     value="{{ .globalSettings.MTU }}"> |                                     value="{{if .globalSettings.MTU}}{{ .globalSettings.MTU }}{{end}}"> | ||||||
|                             </div> |                             </div> | ||||||
|                             <div class="form-group"> |                             <div class="form-group"> | ||||||
|                                 <label for="persistent_keepalive">Persistent Keepalive</label> |                                 <label for="persistent_keepalive">Persistent Keepalive</label> | ||||||
|                                 <input type="text" class="form-control" id="persistent_keepalive" |                                 <input type="text" class="form-control" id="persistent_keepalive" | ||||||
|                                     name="persistent_keepalive" placeholder="Persistent Keepalive" |                                     name="persistent_keepalive" placeholder="Persistent Keepalive" | ||||||
|                                     value="{{ .globalSettings.PersistentKeepalive }}"> |                                     value="{{if .globalSettings.PersistentKeepalive }}{{ .globalSettings.PersistentKeepalive }}{{end}}"> | ||||||
|                             </div> |                             </div> | ||||||
|                             <div class="form-group"> |                             <div class="form-group"> | ||||||
|                                 <label for="config_file_path">Wireguard Config File Path</label> |                                 <label for="config_file_path">Wireguard Config File Path</label> | ||||||
|  | @ -71,6 +71,37 @@ Global Settings | ||||||
|                 </div> |                 </div> | ||||||
|                 <!-- /.card --> |                 <!-- /.card --> | ||||||
|             </div> |             </div> | ||||||
|  |             <div class="col-md-6"> | ||||||
|  |                 <div class="card card-success"> | ||||||
|  |                     <div class="card-header"> | ||||||
|  |                         <h3 class="card-title">Help</h3> | ||||||
|  |                     </div> | ||||||
|  |                     <!-- /.card-header --> | ||||||
|  |                     <div class="card-body"> | ||||||
|  |                         <dl> | ||||||
|  |                             <dt>1. Endpoint Address</dt> | ||||||
|  |                             <dd>The public IP address of your Wireguard server that the client will connect to. Click on | ||||||
|  |                                 <strong>Suggest</strong> button to auto detect the public IP address of your server.</dd> | ||||||
|  |                             <dt>2. DNS Servers</dt> | ||||||
|  |                             <dd>The DNS servers will be set to client config.</dd> | ||||||
|  |                             <dt>3. MTU</dt> | ||||||
|  |                             <dd>The MTU will be set to server config. By default it is <code>1420</code>. You might want | ||||||
|  |                                 to adjust the MTU size if your connection (e.g PPPoE, 3G, satellite network, etc) has a low MTU.</dd> | ||||||
|  |                             <dd>Leave blank to omit this setting in the Server config.</dd> | ||||||
|  |                             <dt>4. Persistent Keepalive</dt> | ||||||
|  |                             <dd>By default, WireGuard peers remain silent while they do not need to communicate, | ||||||
|  |                                 so peers located behind a NAT and/or firewall may be unreachable from other peers | ||||||
|  |                                 until they reach out to other peers themselves. Adding <code>PersistentKeepalive</code> | ||||||
|  |                                 can ensure that the connection remains open.</dd> | ||||||
|  |                             <dd>Leave blank to omit this setting in the Client config.</dd> | ||||||
|  |                             <dt>5. Wireguard Config File Path</dt> | ||||||
|  |                             <dd>The path of your Wireguard server config file. Please make sure the parent directory | ||||||
|  |                                 exists and is writable.</dd> | ||||||
|  |                         </dl> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|  |                 <!-- /.card --> | ||||||
|  |             </div> | ||||||
|         </div> |         </div> | ||||||
|         <!-- /.row --> |         <!-- /.row --> | ||||||
|     </div> |     </div> | ||||||
|  | @ -172,12 +203,10 @@ Global Settings | ||||||
|             $("#frm_global_settings").validate({ |             $("#frm_global_settings").validate({ | ||||||
|                 rules: { |                 rules: { | ||||||
|                     mtu: { |                     mtu: { | ||||||
|                         required: true, |  | ||||||
|                         digits: true, |                         digits: true, | ||||||
|                         range: [68, 65535] |                         range: [68, 65535] | ||||||
|                     }, |                     }, | ||||||
|                     persistent_keepalive: { |                     persistent_keepalive: { | ||||||
|                         required: true, |  | ||||||
|                         digits: true |                         digits: true | ||||||
|                     }, |                     }, | ||||||
|                     config_file_path: { |                     config_file_path: { | ||||||
|  | @ -186,12 +215,10 @@ Global Settings | ||||||
|                 }, |                 }, | ||||||
|                 messages: { |                 messages: { | ||||||
|                     mtu: { |                     mtu: { | ||||||
|                         required: "Please enter a MTU value", |  | ||||||
|                         digits: "MTU must be an integer", |                         digits: "MTU must be an integer", | ||||||
|                         range: "MTU must be in range 68..65535" |                         range: "MTU must be in range 68..65535" | ||||||
|                     }, |                     }, | ||||||
|                     persistent_keepalive: { |                     persistent_keepalive: { | ||||||
|                         required: "Please enter a Persistent Keepalive value", |  | ||||||
|                         digits: "Persistent keepalive must be an integer" |                         digits: "Persistent keepalive must be an integer" | ||||||
|                     }, |                     }, | ||||||
|                     config_file_path: { |                     config_file_path: { | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ | ||||||
| Address = {{$first :=true}}{{range .serverConfig.Interface.Addresses }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}} | Address = {{$first :=true}}{{range .serverConfig.Interface.Addresses }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}} | ||||||
| ListenPort = {{ .serverConfig.Interface.ListenPort }} | ListenPort = {{ .serverConfig.Interface.ListenPort }} | ||||||
| PrivateKey = {{ .serverConfig.KeyPair.PrivateKey }} | PrivateKey = {{ .serverConfig.KeyPair.PrivateKey }} | ||||||
| MTU = {{ .globalSettings.MTU }} | {{if .globalSettings.MTU}}MTU = {{ .globalSettings.MTU }}{{end}} | ||||||
| PostUp = {{ .serverConfig.Interface.PostUp }} | PostUp = {{ .serverConfig.Interface.PostUp }} | ||||||
| PostDown = {{ .serverConfig.Interface.PostDown }} | PostDown = {{ .serverConfig.Interface.PostDown }} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -41,12 +41,15 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G | ||||||
| 		if n, err := strconv.Atoi(split[1]); err == nil { | 		if n, err := strconv.Atoi(split[1]); err == nil { | ||||||
| 			desiredPort = n | 			desiredPort = n | ||||||
| 		} else { | 		} else { | ||||||
| 			log.Error("Endpoint appears to be incorrectly formated: ", err) | 			log.Error("Endpoint appears to be incorrectly formatted: ", err) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	peerEndpoint := fmt.Sprintf("Endpoint = %s:%d", desiredHost, desiredPort) | 	peerEndpoint := fmt.Sprintf("Endpoint = %s:%d", desiredHost, desiredPort) | ||||||
| 
 | 
 | ||||||
| 	peerPersistentKeepalive := fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive) | 	peerPersistentKeepalive := "" | ||||||
|  | 	if setting.PersistentKeepalive > 0 { | ||||||
|  | 		peerPersistentKeepalive = fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive) | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	// build the config as string
 | 	// build the config as string
 | ||||||
| 	strConfig := "[Interface]\n" + | 	strConfig := "[Interface]\n" + | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue