Fix wg config template
This commit is contained in:
		
							parent
							
								
									58f1bd65bb
								
							
						
					
					
						commit
						d00d7bd8fe
					
				|  | @ -2,7 +2,8 @@ version: '3' | |||
| 
 | ||||
| services: | ||||
|   wg: | ||||
|     image: ngoduykhanh/wireguard-ui:latest | ||||
|     #image: ngoduykhanh/wireguard-ui:latest | ||||
|     image: wgui:latest | ||||
|     container_name: wgui | ||||
|     ports: | ||||
|       - 5000:5000 | ||||
|  | @ -12,4 +13,4 @@ services: | |||
|         max-size: 50m | ||||
|     volumes: | ||||
|       - ./db:/app/db | ||||
|       - /etc/wireguard:/etc/wireguard | ||||
| #      - /etc/wireguard:/etc/wireguard | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ package handler | |||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	rice "github.com/GeertJohan/go.rice" | ||||
| 	"net/http" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | @ -429,7 +430,7 @@ func SuggestIPAllocation() echo.HandlerFunc { | |||
| } | ||||
| 
 | ||||
| // ApplyServerConfig handler to write config file and restart Wireguard server
 | ||||
| func ApplyServerConfig() echo.HandlerFunc { | ||||
| func ApplyServerConfig(tmplBox *rice.Box) echo.HandlerFunc { | ||||
| 	return func(c echo.Context) error { | ||||
| 		// access validation
 | ||||
| 		validSession(c) | ||||
|  | @ -453,7 +454,7 @@ func ApplyServerConfig() echo.HandlerFunc { | |||
| 		} | ||||
| 
 | ||||
| 		// Write config file
 | ||||
| 		err = util.WriteWireGuardServerConfig(server, clients, settings) | ||||
| 		err = util.WriteWireGuardServerConfig(tmplBox, server, clients, settings) | ||||
| 		if err != nil { | ||||
| 			log.Error("Cannot apply server config: ", err) | ||||
| 			return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, fmt.Sprintf("Cannot apply server config: %v", err)}) | ||||
|  |  | |||
							
								
								
									
										2
									
								
								main.go
								
								
								
								
							
							
						
						
									
										2
									
								
								main.go
								
								
								
								
							|  | @ -41,7 +41,7 @@ func main() { | |||
| 	app.POST("/global-settings", handler.GlobalSettingSubmit()) | ||||
| 	app.GET("/api/machine-ips", handler.MachineIPAddresses()) | ||||
| 	app.GET("/api/suggest-client-ips", handler.SuggestIPAllocation()) | ||||
| 	app.GET("/api/apply-wg-config", handler.ApplyServerConfig()) | ||||
| 	app.GET("/api/apply-wg-config", handler.ApplyServerConfig(tmplBox)) | ||||
| 
 | ||||
| 	// servers other static files
 | ||||
| 	app.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler))) | ||||
|  |  | |||
							
								
								
									
										10
									
								
								util/util.go
								
								
								
								
							
							
						
						
									
										10
									
								
								util/util.go
								
								
								
								
							|  | @ -313,15 +313,9 @@ func ValidateIPAllocation(serverAddresses []string, ipAllocatedList []string, ip | |||
| } | ||||
| 
 | ||||
| // WriteWireGuardServerConfig to write Wireguard server config. e.g. wg0.conf
 | ||||
| func WriteWireGuardServerConfig(serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error { | ||||
| 	// create go rice box for wireguard config
 | ||||
| 	templateBox, err := rice.FindBox("../templates") | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| func WriteWireGuardServerConfig(tmplBox *rice.Box, serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error { | ||||
| 	// read wg.conf template file to string
 | ||||
| 	tmplWireguardConf, err := templateBox.String("wg.conf") | ||||
| 	tmplWireguardConf, err := tmplBox.String("wg.conf") | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue