Skip to content

Commit ddef0c4

Browse files
committed
Merge branch 'release-v0.1.11'
2 parents ee64794 + 397da9d commit ddef0c4

21 files changed

+417
-181
lines changed

CHANGELOG.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
# Change Log
22

3-
## [v0.1.10](https://github.com/cad/ovpm/tree/v0.1.10) (2017-08-27)
3+
## [v0.1.11](https://github.com/cad/ovpm/tree/v0.1.11) (2017-08-31)
4+
[Full Changelog](https://github.com/cad/ovpm/compare/v0.1.10...v0.1.11)
5+
6+
**Implemented enhancements:**
7+
8+
- be able to change initial ip block [\#29](https://github.com/cad/ovpm/issues/29)
9+
10+
**Fixed bugs:**
11+
12+
- can add duplicate static ip [\#37](https://github.com/cad/ovpm/issues/37)
13+
- net def --via flag doesn't work as documented [\#36](https://github.com/cad/ovpm/issues/36)
14+
- Error when group 'nobody' doesn't exist [\#32](https://github.com/cad/ovpm/issues/32)
15+
- --static option doesn't work when user update [\#28](https://github.com/cad/ovpm/issues/28)
16+
17+
**Merged pull requests:**
18+
19+
- openvpn user created by openvpn package, so use openvpn user instead. [\#35](https://github.com/cad/ovpm/pull/35) ([ilkerdagli](https://github.com/ilkerdagli))
20+
21+
## [v0.1.10](https://github.com/cad/ovpm/tree/v0.1.10) (2017-08-29)
422
[Full Changelog](https://github.com/cad/ovpm/compare/v0.1.9...v0.1.10)
523

624
**Implemented enhancements:**
725

26+
- command line flags for tcp or udp at initialize [\#30](https://github.com/cad/ovpm/issues/30)
827
- show network types in cli [\#27](https://github.com/cad/ovpm/issues/27)
928

1029
## [v0.1.9](https://github.com/cad/ovpm/tree/v0.1.9) (2017-08-27)
@@ -76,4 +95,3 @@
7695
- implement remote control proto [\#8](https://github.com/cad/ovpm/issues/8)
7796
- write docs [\#4](https://github.com/cad/ovpm/issues/4)
7897
- write unit tests [\#3](https://github.com/cad/ovpm/issues/3)
79-

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ $ sudo yum-config-manager --add-repo https://cad.github.io/ovpm/rpm/ovpm.repo
2222
$ sudo yum install ovpm
2323
```
2424

25+
**from DEB (Ubuntu/DEBIAN):**
26+
27+
This is tested only on Ubuntu >=16.04.3 LTS
28+
29+
```bash
30+
# Add APT Repo
31+
$ sudo sh -c 'echo "deb [trusted=yes] https://cad.github.io/ovpm/deb/ ovpm main" >> /etc/apt/sources.list'
32+
33+
# Install OVPM
34+
$ sudo yum install ovpm
35+
```
36+
2537
**from Source (go get):**
2638

2739
Only dependency for ovpm is **OpenVPN>=2.3**.

api/rpc.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ func (s *UserService) Update(ctx context.Context, req *pb.UserUpdateRequest) (*p
7676

7777
}
7878

79-
user.Update(req.Password, noGW, req.HostID)
79+
err = user.Update(req.Password, noGW, req.HostID)
80+
if err != nil {
81+
return nil, err
82+
}
8083
pbUser := pb.UserResponse_User{
8184
Username: user.GetUsername(),
8285
ServerSerialNumber: user.GetServerSerialNumber(),
@@ -184,7 +187,8 @@ func (s *VPNService) Init(ctx context.Context, req *pb.VPNInitRequest) (*pb.VPNI
184187
case pb.VPNProto_NOPREF:
185188
proto = ovpm.UDPProto
186189
}
187-
if err := ovpm.Init(req.Hostname, req.Port, proto); err != nil {
190+
191+
if err := ovpm.Init(req.Hostname, req.Port, proto, req.IPBlock); err != nil {
188192
logrus.Errorf("server can not be created: %v", err)
189193
}
190194
return &pb.VPNInitResponse{}, nil

bindata/bindata.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/ovpm/net.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ var netDefineCommand = cli.Command{
4949

5050
switch ovpm.NetworkTypeFromString(typ) {
5151
case ovpm.ROUTE:
52-
if via != "" && !govalidator.IsCIDR(via) {
53-
fmt.Printf("validation error: `%s` must be a network in the CIDR form", via)
52+
if via != "" && !govalidator.IsIPv4(via) {
53+
fmt.Printf("validation error: `%s` must be a network in the IPv4 form", via)
5454
fmt.Println()
5555
fmt.Println(cli.ShowSubcommandHelp(c))
5656
os.Exit(1)
57-
} else {
58-
via = ""
5957
}
58+
6059
case ovpm.SERVERNET:
6160
if via != "" {
6261
fmt.Println("--via flag can only be used with --type ROUTE")

cmd/ovpm/user.go

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88

99
"github.com/Sirupsen/logrus"
10+
"github.com/asaskevich/govalidator"
1011
"github.com/cad/ovpm"
1112
"github.com/cad/ovpm/pb"
1213
"github.com/olekukonko/tablewriter"
@@ -87,12 +88,17 @@ var userCreateCommand = cli.Command{
8788
fmt.Println(cli.ShowSubcommandHelp(c))
8889
os.Exit(1)
8990
}
90-
91+
if static != "" && !govalidator.IsIPv4(static) {
92+
fmt.Println("--static flag takes a valid ipv4 address")
93+
fmt.Println()
94+
fmt.Println(cli.ShowSubcommandHelp(c))
95+
os.Exit(1)
96+
}
9197
var hostid uint32
9298
if static != "" {
9399
h := ovpm.IP2HostID(net.ParseIP(static).To4())
94100
if h == 0 {
95-
fmt.Println("--static flag takes a valid ipv4 address")
101+
fmt.Printf("can not parse %s as IPv4", static)
96102
fmt.Println()
97103
fmt.Println(cli.ShowSubcommandHelp(c))
98104
os.Exit(1)
@@ -142,6 +148,10 @@ var userUpdateCommand = cli.Command{
142148
Name: "static",
143149
Usage: "ip address for the vpn user",
144150
},
151+
cli.BoolFlag{
152+
Name: "no-static",
153+
Usage: "do not set static ip address for the vpn user",
154+
},
145155
},
146156
Action: func(c *cli.Context) error {
147157
action = "user:update"
@@ -150,32 +160,64 @@ var userUpdateCommand = cli.Command{
150160
nogw := c.Bool("no-gw")
151161
gw := c.Bool("gw")
152162
static := c.String("static")
163+
noStatic := c.Bool("no-static")
153164

154165
if username == "" {
155166
fmt.Println(cli.ShowSubcommandHelp(c))
156167
os.Exit(1)
157168
}
158169

159-
if !(password != "" || gw || nogw) {
170+
// Check wether if all flags are are empty.
171+
if !(password != "" || gw || nogw || static != "" || noStatic) {
160172
fmt.Println("nothing is updated!")
161173
fmt.Println()
162174
fmt.Println(cli.ShowSubcommandHelp(c))
163175
os.Exit(1)
164176
}
165177

178+
// Given that static is set, check wether it's IPv4.
179+
if static != "" && !govalidator.IsIPv4(static) {
180+
fmt.Println("--static flag takes a valid ipv4 address")
181+
fmt.Println()
182+
fmt.Println(cli.ShowSubcommandHelp(c))
183+
os.Exit(1)
184+
}
185+
var staticPref pb.UserUpdateRequest_StaticPref
186+
staticPref = pb.UserUpdateRequest_NOPREFSTATIC
166187
var hostid uint32
167-
if static != "" {
168-
h := ovpm.IP2HostID(net.ParseIP(static).To4())
169-
if h == 0 {
170-
fmt.Println("--static flag takes a valid ipv4 address")
171-
fmt.Println()
172-
fmt.Println(cli.ShowSubcommandHelp(c))
173-
os.Exit(1)
174-
}
175188

176-
hostid = h
189+
switch {
190+
case static != "" && !noStatic:
191+
// means static is set.
192+
if static != "" {
193+
h := ovpm.IP2HostID(net.ParseIP(static).To4())
194+
if h == 0 {
195+
fmt.Printf("can't parse %s as IPv4", static)
196+
fmt.Println()
197+
fmt.Println(cli.ShowSubcommandHelp(c))
198+
os.Exit(1)
199+
}
200+
201+
hostid = h
202+
}
203+
staticPref = pb.UserUpdateRequest_STATIC
204+
205+
case static == "" && noStatic:
206+
// means no-static
207+
hostid = 0
208+
staticPref = pb.UserUpdateRequest_NOSTATIC
209+
case static != "" && noStatic:
210+
// means invalid
211+
fmt.Println("--static flag and --no-static flag cannot be used together")
212+
fmt.Println()
213+
fmt.Println(cli.ShowSubcommandHelp(c))
214+
os.Exit(1)
215+
case static == "" && !noStatic:
216+
default:
217+
// means no pref
218+
staticPref = pb.UserUpdateRequest_NOPREFSTATIC
219+
hostid = 0
177220
}
178-
179221
var gwPref pb.UserUpdateRequest_GWPref
180222

181223
switch {
@@ -200,10 +242,11 @@ var userUpdateCommand = cli.Command{
200242
userSvc := pb.NewUserServiceClient(conn)
201243

202244
response, err := userSvc.Update(context.Background(), &pb.UserUpdateRequest{
203-
Username: username,
204-
Password: password,
205-
Gwpref: gwPref,
206-
HostID: hostid,
245+
Username: username,
246+
Password: password,
247+
Gwpref: gwPref,
248+
HostID: hostid,
249+
Staticpref: staticPref,
207250
})
208251

209252
if err != nil {

cmd/ovpm/vpn.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77

88
"github.com/Sirupsen/logrus"
9+
"github.com/asaskevich/govalidator"
910
"github.com/cad/ovpm"
1011
"github.com/cad/ovpm/pb"
1112
"github.com/olekukonko/tablewriter"
@@ -60,12 +61,16 @@ var vpnInitCommand = cli.Command{
6061
Name: "tcp, t",
6162
Usage: "use TCP for vpn protocol, instead of UDP",
6263
},
64+
cli.StringFlag{
65+
Name: "net, n",
66+
Usage: fmt.Sprintf("VPN network to give clients IP addresses from, in the CIDR form (default: %s)", ovpm.DefaultVPNNetwork),
67+
},
6368
},
6469
Action: func(c *cli.Context) error {
6570
action = "vpn:init"
6671
hostname := c.String("hostname")
6772
if hostname == "" {
68-
logrus.Errorf("'hostname' is needed")
73+
logrus.Errorf("'hostname' is required")
6974
fmt.Println(cli.ShowSubcommandHelp(c))
7075
os.Exit(1)
7176

@@ -78,13 +83,17 @@ var vpnInitCommand = cli.Command{
7883

7984
tcp := c.Bool("tcp")
8085

81-
var proto pb.VPNProto
82-
83-
switch tcp {
84-
case true:
86+
proto := pb.VPNProto_UDP
87+
if tcp {
8588
proto = pb.VPNProto_TCP
86-
default:
87-
proto = pb.VPNProto_UDP
89+
}
90+
91+
ipblock := c.String("net")
92+
if ipblock != "" && !govalidator.IsCIDR(ipblock) {
93+
fmt.Println("--net takes an ip network in the CIDR form. e.g. 10.9.0.0/24")
94+
fmt.Println()
95+
fmt.Println(cli.ShowSubcommandHelp(c))
96+
os.Exit(1)
8897
}
8998

9099
conn := getConn(c.GlobalString("daemon-port"))
@@ -106,7 +115,7 @@ var vpnInitCommand = cli.Command{
106115
okayResponses := []string{"y", "Y", "yes", "Yes", "YES"}
107116
nokayResponses := []string{"n", "N", "no", "No", "NO"}
108117
if stringInSlice(response, okayResponses) {
109-
if _, err := vpnSvc.Init(context.Background(), &pb.VPNInitRequest{Hostname: hostname, Port: port, Protopref: proto}); err != nil {
118+
if _, err := vpnSvc.Init(context.Background(), &pb.VPNInitRequest{Hostname: hostname, Port: port, Protopref: proto, IPBlock: ipblock}); err != nil {
110119
logrus.Errorf("server can not be initialized: %v", err)
111120
os.Exit(1)
112121
return err

const.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ package ovpm
22

33
const (
44
// Version defines the version of ovpm.
5-
Version = "0.1.10"
5+
Version = "0.1.11"
66

77
// DefaultVPNPort is the default OpenVPN port to listen.
88
DefaultVPNPort = "1197"
99

10+
// DefaultVPNProto is the default OpenVPN protocol to use.
11+
DefaultVPNProto = UDPProto
12+
13+
// DefaultVPNNetwork is the default OpenVPN network to use.
14+
DefaultVPNNetwork = "10.9.0.0/24"
15+
1016
etcBasePath = "/etc/ovpm/"
1117
varBasePath = "/var/db/ovpm/"
1218

@@ -20,9 +26,6 @@ const (
2026
_DefaultCAKeyPath = varBasePath + "ca.key"
2127
_DefaultDHParamsPath = varBasePath + "dh4096.pem"
2228
_DefaultCRLPath = varBasePath + "crl.pem"
23-
24-
_DefaultServerNetwork = "10.9.0.0"
25-
_DefaultServerNetMask = "255.255.255.0"
2629
)
2730

2831
// Testing is used to determine wether we are testing or running normally.

net.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ func CreateNewNetwork(name, cidr string, nettype NetworkType, via string) (*DBNe
133133
return nil, fmt.Errorf("validation error: `%s` must be a network in the CIDR form", cidr)
134134
}
135135

136-
if !govalidator.IsCIDR(via) && via != "" {
137-
return nil, fmt.Errorf("validation error: `%s` must be a network in the CIDR form", via)
136+
if via != "" && !govalidator.IsIPv4(via) {
137+
return nil, fmt.Errorf("validation error: `%s` must be a network in the IPv4 form", via)
138138
}
139139

140140
if nettype == UNDEFINEDNET {
@@ -146,13 +146,13 @@ func CreateNewNetwork(name, cidr string, nettype NetworkType, via string) (*DBNe
146146
return nil, fmt.Errorf("can not parse CIDR %s: %v", cidr, err)
147147
}
148148

149-
// Overwrite via with the parsed CIDR string.
149+
// Overwrite via with the parsed IPv4 string.
150150
if nettype == ROUTE && via != "" {
151-
_, viaNet, err := net.ParseCIDR(via)
151+
viaIP := net.ParseIP(via).To4()
152152
if err != nil {
153-
return nil, fmt.Errorf("can not parse CIDR %s: %v", via, err)
153+
return nil, fmt.Errorf("can not parse IPv4 %s: %v", via, err)
154154
}
155-
via = viaNet.String()
155+
via = viaIP.String()
156156

157157
} else {
158158
via = ""
@@ -507,14 +507,21 @@ func HostID2IP(hostid uint32) net.IP {
507507
return net.IP(ip)
508508
}
509509

510-
//IP2HostID converts an IP address to a host id (32-bit unsigned integer).
510+
// IP2HostID converts an IP address to a host id (32-bit unsigned integer).
511511
func IP2HostID(ip net.IP) uint32 {
512512
hostid := binary.BigEndian.Uint32(ip)
513513
return hostid
514514
}
515515

516516
// IncrementIP will return next ip address within the network.
517517
func IncrementIP(ip, mask string) (string, error) {
518+
if !govalidator.IsIPv4(ip) {
519+
return "", fmt.Errorf("'ip' is expected to be a valid IPv4 %s", ip)
520+
}
521+
if !govalidator.IsIPv4(ip) {
522+
return "", fmt.Errorf("'mask' is expected to be a valid IPv4 %s", mask)
523+
}
524+
518525
ipAddr := net.ParseIP(ip).To4()
519526
netMask := net.IPMask(net.ParseIP(mask).To4())
520527
ipNet := net.IPNet{IP: ipAddr, Mask: netMask}

0 commit comments

Comments
 (0)