Skip to content

Commit

Permalink
Merge branch 'release-v0.1.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
cad committed Sep 1, 2017
2 parents 993d6ad + a78728e commit 870dbc0
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 83 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Change Log

## [v0.1.11](https://github.com/cad/ovpm/tree/v0.1.11) (2017-08-31)
[Full Changelog](https://github.com/cad/ovpm/compare/v0.1.10...v0.1.11)
## [v0.1.12](https://github.com/cad/ovpm/tree/v0.1.12) (2017-09-02)
[Full Changelog](https://github.com/cad/ovpm/compare/v0.1.11...v0.1.12)

**Implemented enhancements:**

- be able to change initial ip block [\#29](https://github.com/cad/ovpm/issues/29)

## [v0.1.11](https://github.com/cad/ovpm/tree/v0.1.11) (2017-08-31)
[Full Changelog](https://github.com/cad/ovpm/compare/v0.1.10...v0.1.11)

**Fixed bugs:**

- can add duplicate static ip [\#37](https://github.com/cad/ovpm/issues/37)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OVPM - OpenVPn Manager
# OVPM - OpenVPN Management Server

[![Build Status](https://travis-ci.org/cad/ovpm.svg?branch=master)](https://travis-ci.org/cad/ovpm)
[![GitHub version](https://badge.fury.io/gh/cad%2Fovpm.svg)](https://badge.fury.io/gh/cad%2Fovpm)
Expand Down
22 changes: 19 additions & 3 deletions api/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}

Expand All @@ -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
}
Expand All @@ -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)

Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -166,7 +182,7 @@ func (s *VPNService) Status(ctx context.Context, req *pb.VPNStatusRequest) (*pb.
SerialNumber: server.SerialNumber,
Hostname: server.Hostname,
Port: server.Port,
Proto: server.Proto,
Proto: server.GetProto(),
Cert: server.Cert,
CACert: server.CACert,
Net: server.Net,
Expand Down
6 changes: 3 additions & 3 deletions bindata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 45 additions & 5 deletions cmd/ovpm/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -76,13 +80,18 @@ 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"
username := c.String("username")
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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -161,21 +180,23 @@ 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))
os.Exit(1)
}

// Check wether if all flags are are empty.
if !(password != "" || gw || nogw || static != "" || noStatic) {
// Check whether if all flags are are empty.
if !(password != "" || gw || nogw || static != "" || noStatic || admin || noAdmin) {
fmt.Println("nothing is updated!")
fmt.Println()
fmt.Println(cli.ShowSubcommandHelp(c))
os.Exit(1)
}

// Given that static is set, check wether it's IPv4.
// Given that static is set, check whether it's IPv4.
if static != "" && !govalidator.IsIPv4(static) {
fmt.Println("--static flag takes a valid ipv4 address")
fmt.Println()
Expand Down Expand Up @@ -218,6 +239,7 @@ var userUpdateCommand = cli.Command{
staticPref = pb.UserUpdateRequest_NOPREFSTATIC
hostid = 0
}

var gwPref pb.UserUpdateRequest_GWPref

switch {
Expand All @@ -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()
Expand All @@ -247,6 +286,7 @@ var userUpdateCommand = cli.Command{
Gwpref: gwPref,
HostID: hostid,
Staticpref: staticPref,
Adminpref: adminPref,
})

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ovpm

const (
// Version defines the version of ovpm.
Version = "0.1.11"
Version = "0.1.12"

// DefaultVPNPort is the default OpenVPN port to listen.
DefaultVPNPort = "1197"
Expand All @@ -28,6 +28,6 @@ const (
_DefaultCRLPath = varBasePath + "crl.pem"
)

// Testing is used to determine wether we are testing or running normally.
// Testing is used to determine whether we are testing or running normally.
// Set it to true when testing.
var Testing = false
6 changes: 3 additions & 3 deletions net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestNetAssociate(t *testing.T) {
cidrStr := "192.168.1.0/24"
netType := SERVERNET
userName := "testUser2"
user, err := CreateNewUser(userName, "123", false, 0)
user, err := CreateNewUser(userName, "123", false, 0, true)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestNetDissociate(t *testing.T) {
cidrStr := "192.168.1.0/24"
netType := SERVERNET
userName := "testUser2"
user, err := CreateNewUser(userName, "123", false, 0)
user, err := CreateNewUser(userName, "123", false, 0, true)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestNetGetAssociatedUsers(t *testing.T) {
cidrStr := "192.168.1.0/24"
netType := SERVERNET
userName := "testUser2"
user, _ := CreateNewUser(userName, "123", false, 0)
user, _ := CreateNewUser(userName, "123", false, 0, true)

n, _ := CreateNewNetwork(netName, cidrStr, netType, "")
n.Associate(user.Username)
Expand Down
Loading

0 comments on commit 870dbc0

Please sign in to comment.