1
0
Эх сурвалжийг харах

feat(user): add admin user type

Mustafa Arici 8 жил өмнө
parent
commit
3c5c52d32b
7 өөрчлөгдсөн 197 нэмэгдсэн , 49 устгасан
  1. 18 2
      api/rpc.go
  2. 1 1
      bindata/bindata.go
  3. 43 3
      cmd/ovpm/user.go
  4. 96 41
      pb/user.pb.go
  5. 8 0
      pb/user.proto
  6. 20 0
      pb/user.swagger.json
  7. 11 2
      user.go

+ 18 - 2
api/rpc.go

@@ -32,6 +32,7 @@ func (s *UserService) List(ctx context.Context, req *pb.UserListRequest) (*pb.Us
 			IPNet:              user.GetIPNet(),
 			NoGW:               user.IsNoGW(),
 			HostID:             user.GetHostID(),
+			IsAdmin:            user.IsAdmin(),
 		})
 	}
 
@@ -41,7 +42,7 @@ func (s *UserService) List(ctx context.Context, req *pb.UserListRequest) (*pb.Us
 func (s *UserService) Create(ctx context.Context, req *pb.UserCreateRequest) (*pb.UserResponse, error) {
 	logrus.Debugf("rpc call: user create: %s", req.Username)
 	var ut []*pb.UserResponse_User
-	user, err := ovpm.CreateNewUser(req.Username, req.Password, req.NoGW, req.HostID)
+	user, err := ovpm.CreateNewUser(req.Username, req.Password, req.NoGW, req.HostID, req.IsAdmin)
 	if err != nil {
 		return nil, err
 	}
@@ -51,6 +52,7 @@ func (s *UserService) Create(ctx context.Context, req *pb.UserCreateRequest) (*p
 		ServerSerialNumber: user.GetServerSerialNumber(),
 		NoGW:               user.IsNoGW(),
 		HostID:             user.GetHostID(),
+		IsAdmin:            user.IsAdmin(),
 	}
 	ut = append(ut, &pbUser)
 
@@ -76,7 +78,18 @@ func (s *UserService) Update(ctx context.Context, req *pb.UserUpdateRequest) (*p
 
 	}
 
-	err = user.Update(req.Password, noGW, req.HostID)
+	var admin bool
+
+	switch req.Adminpref {
+	case pb.UserUpdateRequest_ADMIN:
+		admin = true
+	case pb.UserUpdateRequest_NOADMIN:
+		admin = false
+	case pb.UserUpdateRequest_NOPREFADMIN:
+		admin = user.IsAdmin()
+	}
+
+	err = user.Update(req.Password, noGW, req.HostID, admin)
 	if err != nil {
 		return nil, err
 	}
@@ -85,6 +98,7 @@ func (s *UserService) Update(ctx context.Context, req *pb.UserUpdateRequest) (*p
 		ServerSerialNumber: user.GetServerSerialNumber(),
 		NoGW:               user.IsNoGW(),
 		HostID:             user.GetHostID(),
+		IsAdmin:            user.IsAdmin(),
 	}
 
 	ut = append(ut, &pbUser)
@@ -104,6 +118,7 @@ func (s *UserService) Delete(ctx context.Context, req *pb.UserDeleteRequest) (*p
 		Username:           user.GetUsername(),
 		ServerSerialNumber: user.GetServerSerialNumber(),
 		HostID:             user.GetHostID(),
+		IsAdmin:            user.IsAdmin(),
 	}
 	ut = append(ut, &pbUser)
 
@@ -127,6 +142,7 @@ func (s *UserService) Renew(ctx context.Context, req *pb.UserRenewRequest) (*pb.
 		Username:           user.GetUsername(),
 		ServerSerialNumber: user.GetServerSerialNumber(),
 		HostID:             user.GetHostID(),
+		IsAdmin:            user.IsAdmin(),
 	}
 	ut = append(ut, &pbUser)
 

+ 1 - 1
bindata/bindata.go

@@ -167,7 +167,7 @@ func templateServerConfTmpl() (*asset, error) {
 		return nil, err
 	}
 
-	info := bindataFileInfo{name: "template/server.conf.tmpl", size: 9597, mode: os.FileMode(420), modTime: time.Unix(1504030791, 0)}
+	info := bindataFileInfo{name: "template/server.conf.tmpl", size: 9597, mode: os.FileMode(420), modTime: time.Unix(1504196445, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }

+ 43 - 3
cmd/ovpm/user.go

@@ -46,7 +46,11 @@ var userListCommand = cli.Command{
 			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)}
+			username := user.Username
+			if user.IsAdmin {
+				username = fmt.Sprintf("%s *", username)
+			}
+			data := []string{fmt.Sprintf("%v", i+1), 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()
@@ -76,6 +80,10 @@ var userCreateCommand = cli.Command{
 			Name:  "static",
 			Usage: "ip address for the vpn user",
 		},
+		cli.BoolFlag{
+			Name:  "admin, a",
+			Usage: "this user has admin rights",
+		},
 	},
 	Action: func(c *cli.Context) error {
 		action = "user:create"
@@ -83,6 +91,7 @@ var userCreateCommand = cli.Command{
 		password := c.String("password")
 		noGW := c.Bool("no-gw")
 		static := c.String("static")
+		admin := c.Bool("admin")
 
 		if username == "" || password == "" {
 			fmt.Println(cli.ShowSubcommandHelp(c))
@@ -112,7 +121,9 @@ var userCreateCommand = cli.Command{
 		defer conn.Close()
 		userSvc := pb.NewUserServiceClient(conn)
 
-		response, err := userSvc.Create(context.Background(), &pb.UserCreateRequest{Username: username, Password: password, NoGW: noGW, HostID: hostid})
+		response, err := userSvc.Create(context.Background(),
+			&pb.UserCreateRequest{Username: username, Password: password, NoGW: noGW, HostID: hostid, IsAdmin: admin},
+		)
 		if err != nil {
 			logrus.Errorf("user can not be created '%s': %v", username, err)
 			os.Exit(1)
@@ -152,6 +163,14 @@ var userUpdateCommand = cli.Command{
 			Name:  "no-static",
 			Usage: "do not set static ip address for the vpn user",
 		},
+		cli.BoolFlag{
+			Name:  "admin",
+			Usage: "this user has admin rights",
+		},
+		cli.BoolFlag{
+			Name:  "no-admin",
+			Usage: "this user has no admin rights",
+		},
 	},
 	Action: func(c *cli.Context) error {
 		action = "user:update"
@@ -161,6 +180,8 @@ var userUpdateCommand = cli.Command{
 		gw := c.Bool("gw")
 		static := c.String("static")
 		noStatic := c.Bool("no-static")
+		admin := c.Bool("admin")
+		noAdmin := c.Bool("no-admin")
 
 		if username == "" {
 			fmt.Println(cli.ShowSubcommandHelp(c))
@@ -168,7 +189,7 @@ var userUpdateCommand = cli.Command{
 		}
 
 		// Check wether if all flags are are empty.
-		if !(password != "" || gw || nogw || static != "" || noStatic) {
+		if !(password != "" || gw || nogw || static != "" || noStatic || admin || noAdmin) {
 			fmt.Println("nothing is updated!")
 			fmt.Println()
 			fmt.Println(cli.ShowSubcommandHelp(c))
@@ -218,6 +239,7 @@ var userUpdateCommand = cli.Command{
 			staticPref = pb.UserUpdateRequest_NOPREFSTATIC
 			hostid = 0
 		}
+
 		var gwPref pb.UserUpdateRequest_GWPref
 
 		switch {
@@ -236,6 +258,23 @@ var userUpdateCommand = cli.Command{
 
 		}
 
+		var adminPref pb.UserUpdateRequest_AdminPref
+
+		switch {
+		case admin && !noAdmin:
+			adminPref = pb.UserUpdateRequest_ADMIN
+		case !admin && noAdmin:
+			adminPref = pb.UserUpdateRequest_NOADMIN
+		case !admin && !noAdmin:
+			adminPref = pb.UserUpdateRequest_NOPREFADMIN
+		case admin && noAdmin:
+			// Ambigius.
+			fmt.Println("you can't use --admin together with --no-admin")
+			fmt.Println()
+			fmt.Println(cli.ShowSubcommandHelp(c))
+			os.Exit(1)
+		}
+
 		//conn := getConn(c.String("port"))
 		conn := getConn(c.GlobalString("daemon-port"))
 		defer conn.Close()
@@ -247,6 +286,7 @@ var userUpdateCommand = cli.Command{
 			Gwpref:     gwPref,
 			HostID:     hostid,
 			Staticpref: staticPref,
+			Adminpref:  adminPref,
 		})
 
 		if err != nil {

+ 96 - 41
pb/user.pb.go

@@ -112,6 +112,32 @@ func (UserUpdateRequest_StaticPref) EnumDescriptor() ([]byte, []int) {
 	return fileDescriptor0, []int{2, 1}
 }
 
+type UserUpdateRequest_AdminPref int32
+
+const (
+	UserUpdateRequest_NOPREFADMIN UserUpdateRequest_AdminPref = 0
+	UserUpdateRequest_NOADMIN     UserUpdateRequest_AdminPref = 1
+	UserUpdateRequest_ADMIN       UserUpdateRequest_AdminPref = 2
+)
+
+var UserUpdateRequest_AdminPref_name = map[int32]string{
+	0: "NOPREFADMIN",
+	1: "NOADMIN",
+	2: "ADMIN",
+}
+var UserUpdateRequest_AdminPref_value = map[string]int32{
+	"NOPREFADMIN": 0,
+	"NOADMIN":     1,
+	"ADMIN":       2,
+}
+
+func (x UserUpdateRequest_AdminPref) String() string {
+	return proto.EnumName(UserUpdateRequest_AdminPref_name, int32(x))
+}
+func (UserUpdateRequest_AdminPref) EnumDescriptor() ([]byte, []int) {
+	return fileDescriptor0, []int{2, 2}
+}
+
 type UserListRequest struct {
 }
 
@@ -125,6 +151,7 @@ type UserCreateRequest struct {
 	Password string `protobuf:"bytes,2,opt,name=Password" json:"Password,omitempty"`
 	NoGW     bool   `protobuf:"varint,3,opt,name=NoGW" json:"NoGW,omitempty"`
 	HostID   uint32 `protobuf:"varint,4,opt,name=HostID" json:"HostID,omitempty"`
+	IsAdmin  bool   `protobuf:"varint,5,opt,name=IsAdmin" json:"IsAdmin,omitempty"`
 }
 
 func (m *UserCreateRequest) Reset()                    { *m = UserCreateRequest{} }
@@ -160,12 +187,20 @@ func (m *UserCreateRequest) GetHostID() uint32 {
 	return 0
 }
 
+func (m *UserCreateRequest) GetIsAdmin() bool {
+	if m != nil {
+		return m.IsAdmin
+	}
+	return false
+}
+
 type UserUpdateRequest struct {
 	Username   string                       `protobuf:"bytes,1,opt,name=Username" json:"Username,omitempty"`
 	Password   string                       `protobuf:"bytes,2,opt,name=Password" json:"Password,omitempty"`
 	Gwpref     UserUpdateRequest_GWPref     `protobuf:"varint,3,opt,name=gwpref,enum=pb.UserUpdateRequest_GWPref" json:"gwpref,omitempty"`
 	HostID     uint32                       `protobuf:"varint,4,opt,name=HostID" json:"HostID,omitempty"`
 	Staticpref UserUpdateRequest_StaticPref `protobuf:"varint,5,opt,name=staticpref,enum=pb.UserUpdateRequest_StaticPref" json:"staticpref,omitempty"`
+	Adminpref  UserUpdateRequest_AdminPref  `protobuf:"varint,6,opt,name=adminpref,enum=pb.UserUpdateRequest_AdminPref" json:"adminpref,omitempty"`
 }
 
 func (m *UserUpdateRequest) Reset()                    { *m = UserUpdateRequest{} }
@@ -208,6 +243,13 @@ func (m *UserUpdateRequest) GetStaticpref() UserUpdateRequest_StaticPref {
 	return UserUpdateRequest_NOPREFSTATIC
 }
 
+func (m *UserUpdateRequest) GetAdminpref() UserUpdateRequest_AdminPref {
+	if m != nil {
+		return m.Adminpref
+	}
+	return UserUpdateRequest_NOPREFADMIN
+}
+
 type UserDeleteRequest struct {
 	Username string `protobuf:"bytes,1,opt,name=Username" json:"Username,omitempty"`
 }
@@ -280,6 +322,7 @@ type UserResponse_User struct {
 	IPNet              string `protobuf:"bytes,5,opt,name=IPNet" json:"IPNet,omitempty"`
 	NoGW               bool   `protobuf:"varint,6,opt,name=NoGW" json:"NoGW,omitempty"`
 	HostID             uint32 `protobuf:"varint,7,opt,name=HostID" json:"HostID,omitempty"`
+	IsAdmin            bool   `protobuf:"varint,8,opt,name=IsAdmin" json:"IsAdmin,omitempty"`
 }
 
 func (m *UserResponse_User) Reset()                    { *m = UserResponse_User{} }
@@ -336,6 +379,13 @@ func (m *UserResponse_User) GetHostID() uint32 {
 	return 0
 }
 
+func (m *UserResponse_User) GetIsAdmin() bool {
+	if m != nil {
+		return m.IsAdmin
+	}
+	return false
+}
+
 type UserGenConfigResponse struct {
 	ClientConfig string `protobuf:"bytes,1,opt,name=ClientConfig" json:"ClientConfig,omitempty"`
 }
@@ -364,6 +414,7 @@ func init() {
 	proto.RegisterType((*UserGenConfigResponse)(nil), "pb.UserGenConfigResponse")
 	proto.RegisterEnum("pb.UserUpdateRequest_GWPref", UserUpdateRequest_GWPref_name, UserUpdateRequest_GWPref_value)
 	proto.RegisterEnum("pb.UserUpdateRequest_StaticPref", UserUpdateRequest_StaticPref_name, UserUpdateRequest_StaticPref_value)
+	proto.RegisterEnum("pb.UserUpdateRequest_AdminPref", UserUpdateRequest_AdminPref_name, UserUpdateRequest_AdminPref_value)
 }
 
 // Reference imports to suppress errors if they are not otherwise used.
@@ -606,45 +657,49 @@ var _UserService_serviceDesc = grpc.ServiceDesc{
 func init() { proto.RegisterFile("user.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{
-	// 628 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xc1, 0x6e, 0xd3, 0x4c,
-	0x10, 0xc7, 0x6b, 0x37, 0xf1, 0x97, 0x4c, 0xd3, 0xd6, 0xdd, 0xa6, 0x1f, 0x6e, 0x54, 0xa4, 0x68,
-	0x0f, 0x28, 0x2a, 0x52, 0x22, 0x02, 0x07, 0x54, 0x2e, 0x54, 0x29, 0x98, 0x22, 0x70, 0x23, 0xa7,
-	0x55, 0x8e, 0xc8, 0x49, 0xa6, 0x91, 0xa5, 0xd4, 0x36, 0xbb, 0x9b, 0xe6, 0x8e, 0x78, 0x03, 0x9e,
-	0x87, 0x2b, 0x2f, 0xc0, 0x2b, 0xf0, 0x00, 0x3c, 0x02, 0xda, 0x5d, 0xc7, 0x6e, 0x8a, 0x41, 0x39,
-	0x70, 0x9b, 0x99, 0x9d, 0xf9, 0x8d, 0x77, 0xf6, 0x3f, 0x06, 0x98, 0x73, 0x64, 0xed, 0x84, 0xc5,
-	0x22, 0x26, 0x66, 0x32, 0x6a, 0x1c, 0x4d, 0xe3, 0x78, 0x3a, 0xc3, 0x4e, 0x90, 0x84, 0x9d, 0x20,
-	0x8a, 0x62, 0x11, 0x88, 0x30, 0x8e, 0xb8, 0xce, 0xa0, 0x7b, 0xb0, 0x7b, 0xc5, 0x91, 0xbd, 0x0b,
-	0xb9, 0xf0, 0xf1, 0xe3, 0x1c, 0xb9, 0xa0, 0x0b, 0xd8, 0x93, 0xa1, 0x1e, 0xc3, 0x40, 0x60, 0x1a,
-	0x24, 0x0d, 0xa8, 0xc8, 0x60, 0x14, 0xdc, 0xa0, 0x63, 0x34, 0x8d, 0x56, 0xd5, 0xcf, 0x7c, 0x79,
-	0xd6, 0x0f, 0x38, 0x5f, 0xc4, 0x6c, 0xe2,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 0x0c, 0x36,
-	0x56, 0x15, 0x29, 0x4e, 0xaf, 0x42, 0x8e, 0x5b, 0x59, 0x8d, 0xb5, 0x70, 0x73, 0x55, 0x91, 0xe2,
-	0xb4, 0x96, 0x73, 0xdc, 0x8a, 0xb6, 0xd7, 0xc2, 0x4d, 0x54, 0x85, 0xc4, 0xbd, 0x85, 0xb2, 0x52,
-	0x3a, 0xa9, 0xe7, 0x65, 0xb9, 0xf0, 0x0b, 0x60, 0x87, 0x0a, 0xb6, 0x4f, 0x77, 0x32, 0x18, 0x93,
-	0x05, 0x92, 0xf5, 0x01, 0xaa, 0xd9, 0x53, 0x12, 0x67, 0x59, 0x79, 0x7f, 0x31, 0x1a, 0x87, 0x05,
-	0x27, 0x29, 0xfc, 0xa1, 0x82, 0x3f, 0xa0, 0x24, 0x83, 0x4f, 0x31, 0x1a, 0xab, 0x9c, 0x13, 0xe3,
-	0x78, 0x64, 0xa9, 0xdf, 0xf3, 0xd3, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x92, 0x5d, 0x0b, 0xf4,
-	0xce, 0x05, 0x00, 0x00,
+	// 696 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0xc1, 0x6e, 0xd3, 0x40,
+	0x10, 0x86, 0x6b, 0x27, 0x71, 0xe3, 0x49, 0xda, 0xba, 0xd3, 0x14, 0xdc, 0xa8, 0x88, 0x68, 0x0f,
+	0x28, 0x2a, 0x52, 0x22, 0x42, 0x0f, 0xa8, 0x08, 0x89, 0x28, 0x85, 0x10, 0x44, 0x9d, 0xc8, 0x69,
+	0x95, 0x23, 0x72, 0x92, 0x6d, 0x64, 0x29, 0xb5, 0x8d, 0xd7, 0x69, 0xef, 0xbc, 0x01, 0xe2, 0xce,
+	0x43, 0xf0, 0x2a, 0xbc, 0x00, 0x07, 0x1e, 0x80, 0x47, 0x40, 0xbb, 0xeb, 0xd8, 0x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x56, 0xa6, 0x7e, 0x2d, 0xdc, 0x54, 0x28, 0x38,
+	0xee, 0x3d, 0x14, 0x84, 0x07, 0xb0, 0x92, 0xca, 0x52, 0x4b, 0x64, 0xc0, 0x0e, 0x04, 0x6c, 0x8f,
+	0x6c, 0x27, 0xb0, 0x90, 0x0b, 0x38, 0xeb, 0x23, 0xe8, 0xc9, 0x53, 0xa2, 0xb9, 0x54, 0xde, 0xb5,
+	0x4c, 0xf5, 0x20, 0xe3, 0x24, 0x86, 0x3f, 0x12, 0xf0, 0x87, 0x04, 0x13, 0xf8, 0x8c, 0x7a, 0x13,
+	0x91, 0x73, 0xa2, 0x1c, 0x8d, 0x35, 0xf1, 0x47, 0xf2, 0xfc, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff,
+	0x77, 0x7f, 0x37, 0xa5, 0x78, 0x06, 0x00, 0x00,
 }

+ 8 - 0
pb/user.proto

@@ -13,6 +13,7 @@ message UserCreateRequest {
   string Password = 2;
   bool NoGW = 3;
   uint32 HostID = 4;
+  bool IsAdmin = 5;
 }
 
 message UserUpdateRequest {
@@ -31,6 +32,12 @@ message UserUpdateRequest {
     STATIC = 2;
   }
   StaticPref staticpref = 5;
+  enum AdminPref {
+    NOPREFADMIN = 0;
+    NOADMIN = 1;
+    ADMIN = 2;
+  }
+  AdminPref adminpref = 6;
 }
 
 
@@ -98,6 +105,7 @@ message UserResponse {
     string IPNet = 5;
     bool NoGW = 6;
     uint32 HostID = 7;
+    bool IsAdmin = 8;
   }
 
   repeated User users = 1;

+ 20 - 0
pb/user.swagger.json

@@ -198,9 +198,22 @@
         "HostID": {
           "type": "integer",
           "format": "int64"
+        },
+        "IsAdmin": {
+          "type": "boolean",
+          "format": "boolean"
         }
       }
     },
+    "UserUpdateRequestAdminPref": {
+      "type": "string",
+      "enum": [
+        "NOPREFADMIN",
+        "NOADMIN",
+        "ADMIN"
+      ],
+      "default": "NOPREFADMIN"
+    },
     "UserUpdateRequestGWPref": {
       "type": "string",
       "enum": [
@@ -235,6 +248,10 @@
         "HostID": {
           "type": "integer",
           "format": "int64"
+        },
+        "IsAdmin": {
+          "type": "boolean",
+          "format": "boolean"
         }
       }
     },
@@ -302,6 +319,9 @@
         },
         "staticpref": {
           "$ref": "#/definitions/UserUpdateRequestStaticPref"
+        },
+        "adminpref": {
+          "$ref": "#/definitions/UserUpdateRequestAdminPref"
         }
       }
     }

+ 11 - 2
user.go

@@ -21,6 +21,7 @@ type User interface {
 	GetIPNet() string
 	IsNoGW() bool
 	GetHostID() uint32
+	IsAdmin() bool
 }
 
 // DBUser is database model for VPN users.
@@ -36,6 +37,7 @@ type DBUser struct {
 	Key                string // not user writable
 	NoGW               bool
 	HostID             uint32 // not user writable
+	Admin              bool
 }
 
 // DBRevoked is a database model for revoked VPN users.
@@ -89,7 +91,7 @@ func GetAllUsers() ([]*DBUser, error) {
 //
 // It also generates the necessary client keys and signs certificates with the current
 // server's CA.
-func CreateNewUser(username, password string, nogw bool, hostid uint32) (*DBUser, error) {
+func CreateNewUser(username, password string, nogw bool, hostid uint32, admin bool) (*DBUser, error) {
 	if !IsInitialized() {
 		return nil, fmt.Errorf("you first need to create server")
 	}
@@ -137,6 +139,7 @@ func CreateNewUser(username, password string, nogw bool, hostid uint32) (*DBUser
 		ServerSerialNumber: server.SerialNumber,
 		NoGW:               nogw,
 		HostID:             hostid,
+		Admin:              admin,
 	}
 	user.setPassword(password)
 
@@ -158,7 +161,7 @@ func CreateNewUser(username, password string, nogw bool, hostid uint32) (*DBUser
 // Update updates the user's attributes and writes them to the database.
 //
 // How this method works is similiar to PUT semantics of REST. It sets the user record fields to the provided function arguments.
-func (u *DBUser) Update(password string, nogw bool, hostid uint32) error {
+func (u *DBUser) Update(password string, nogw bool, hostid uint32, admin bool) error {
 	if !IsInitialized() {
 		return fmt.Errorf("you first need to create server")
 	}
@@ -170,6 +173,7 @@ func (u *DBUser) Update(password string, nogw bool, hostid uint32) error {
 
 	u.NoGW = nogw
 	u.HostID = hostid
+	u.Admin = admin
 
 	if hostid != 0 {
 		server, err := GetServerInstance()
@@ -362,6 +366,11 @@ func (u *DBUser) GetHostID() uint32 {
 	return u.HostID
 }
 
+// IsAdmin returns whether user is admin or not.
+func (u *DBUser) IsAdmin() bool {
+	return u.Admin
+}
+
 func getStaticHostUsers() []*DBUser {
 	var users []*DBUser
 	db.Unscoped().Not(DBUser{HostID: 0}).Find(&users)