瀏覽代碼

fix(vpn): push gw changes thru ccd not main server conf

Mustafa Arici 8 年之前
父節點
當前提交
fff2e7a514
共有 8 個文件被更改,包括 23 次插入15 次删除
  1. 2 2
      api/rpc.go
  2. 2 2
      bindata/bindata.go
  3. 1 1
      cmd/ovpm/net.go
  4. 3 3
      cmd/ovpm/user.go
  5. 5 2
      net_test.go
  6. 4 0
      template/ccd.file.tmpl
  7. 1 1
      template/server.conf.tmpl
  8. 5 4
      vpn.go

+ 2 - 2
api/rpc.go

@@ -66,9 +66,9 @@ func (s *UserService) Update(ctx context.Context, req *pb.UserUpdateRequest) (*p
 
 	switch req.Gwpref {
 	case pb.UserUpdateRequest_NOGW:
-		noGW = false
-	case pb.UserUpdateRequest_GW:
 		noGW = true
+	case pb.UserUpdateRequest_GW:
+		noGW = false
 	default:
 		noGW = user.NoGW
 

文件差異過大導致無法顯示
+ 2 - 2
bindata/bindata.go


+ 1 - 1
cmd/ovpm/net.go

@@ -252,7 +252,7 @@ var netAssociateCommand = cli.Command{
 
 var netDissociateCommand = cli.Command{
 	Name:    "dissoc",
-	Aliases: []string{"d"},
+	Aliases: []string{"di"},
 	Usage:   "Dissociate a user from a network.",
 	Flags: []cli.Flag{
 		cli.StringFlag{

+ 3 - 3
cmd/ovpm/user.go

@@ -38,14 +38,14 @@ var userListCommand = cli.Command{
 			return err
 		}
 		table := tablewriter.NewWriter(os.Stdout)
-		table.SetHeader([]string{"#", "username", "ip", "created at", "valid crt", "no gw"})
+		table.SetHeader([]string{"#", "username", "ip", "created at", "valid crt", "gw"})
 		//table.SetBorder(false)
 		for i, user := range resp.Users {
 			static := ""
 			if user.HostID != 0 {
 				static = "s"
 			}
-			data := []string{fmt.Sprintf("%v", i+1), user.Username, fmt.Sprintf("%s %s", user.IPNet, static), user.CreatedAt, fmt.Sprintf("%t", user.ServerSerialNumber == server.SerialNumber), fmt.Sprintf("%t", user.NoGW)}
+			data := []string{fmt.Sprintf("%v", i+1), user.Username, fmt.Sprintf("%s %s", user.IPNet, static), user.CreatedAt, fmt.Sprintf("%t", user.ServerSerialNumber == server.SerialNumber), fmt.Sprintf("%t", !user.NoGW)}
 			table.Append(data)
 		}
 		table.Render()
@@ -120,7 +120,7 @@ var userCreateCommand = cli.Command{
 var userUpdateCommand = cli.Command{
 	Name:    "update",
 	Usage:   "Update a VPN user.",
-	Aliases: []string{"c"},
+	Aliases: []string{"u"},
 	Flags: []cli.Flag{
 		cli.StringFlag{
 			Name:  "username, u",

+ 5 - 2
net_test.go

@@ -183,10 +183,13 @@ func TestNetAssociate(t *testing.T) {
 	cidrStr := "192.168.1.0/24"
 	netType := SERVERNET
 	userName := "testUser2"
-	user, _ := CreateNewUser(userName, "123", false, 0)
+	user, err := CreateNewUser(userName, "123", false, 0)
+	if err != nil {
+		t.Fatal(err)
+	}
 
 	n, _ := CreateNewNetwork(netName, cidrStr, netType, "")
-	err := n.Associate(user.Username)
+	err = n.Associate(user.Username)
 	if err != nil {
 		t.Fatal(err)
 	}

+ 4 - 0
template/ccd.file.tmpl

@@ -1,5 +1,9 @@
 ifconfig-push {{ .IP }} {{ .NetMask }}
 #iroute 192.168.90.0 255.255.255.0
+{{if .RedirectGW }}
+push "redirect-gateway def1 bypass-dhcp"
+{{ end }}
+
 {{range .Routes}}
 push "route {{index . 0}} {{index . 1}} {{index . 2}}"
 {{ end }}

+ 1 - 1
template/server.conf.tmpl

@@ -173,7 +173,7 @@ crl-verify {{ .CRLPath }}
 # or bridge the TUN/TAP interface to the internet
 # in order for this to work properly).
 ;push "redirect-gateway def1 bypass-dhcp"
-push "redirect-gateway def1 bypass-dhcp"
+;push "redirect-gateway def1 bypass-dhcp"
 
 # Certain Windows-specific network settings
 # can be pushed to clients, such as DNS

+ 5 - 4
vpn.go

@@ -522,10 +522,11 @@ func emitCCD() error {
 		}
 		var result bytes.Buffer
 		params := struct {
-			IP      string
-			NetMask string
-			Routes  [][3]string // [0] is IP, [1] is Netmask, [2] is Via
-		}{IP: user.getIP().String(), NetMask: _DefaultServerNetMask, Routes: associatedRoutes}
+			IP         string
+			NetMask    string
+			Routes     [][3]string // [0] is IP, [1] is Netmask, [2] is Via
+			RedirectGW bool
+		}{IP: user.getIP().String(), NetMask: _DefaultServerNetMask, Routes: associatedRoutes, RedirectGW: !user.NoGW}
 
 		data, err := bindata.Asset("template/ccd.file.tmpl")
 		if err != nil {

部分文件因文件數量過多而無法顯示