Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wg-gen-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
wg-gen-web
Commits
a1828bfc
Commit
a1828bfc
authored
Jan 30, 2020
by
vx3r
Browse files
Options
Downloads
Patches
Plain Diff
go fmt / badges
parent
9b6d610a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
model/client.go
+1
-1
1 addition, 1 deletion
model/client.go
model/server.go
+1
-1
1 addition, 1 deletion
model/server.go
repository/repository.go
+8
-8
8 additions, 8 deletions
repository/repository.go
util/tpl.go
+2
-2
2 additions, 2 deletions
util/tpl.go
util/util.go
+7
-7
7 additions, 7 deletions
util/util.go
with
19 additions
and
19 deletions
model/client.go
+
1
−
1
View file @
a1828bfc
...
...
@@ -2,7 +2,7 @@ package model
import
"time"
//
c
lient structure
//
C
lient structure
type
Client
struct
{
Id
string
`json:"id"`
Name
string
`json:"name"`
...
...
This diff is collapsed.
Click to expand it.
model/server.go
+
1
−
1
View file @
a1828bfc
...
...
@@ -2,7 +2,7 @@ package model
import
"time"
//
s
erver structure
//
S
erver structure
type
Server
struct
{
Name
string
`json:"name"`
Created
time
.
Time
`json:"created"`
...
...
This diff is collapsed.
Click to expand it.
repository/repository.go
+
8
−
8
View file @
a1828bfc
...
...
@@ -17,7 +17,7 @@ import (
)
/*
* Create client with all necessary data
* Create
Client
client with all necessary data
*/
func
CreateClient
(
client
*
model
.
Client
)
(
*
model
.
Client
,
error
)
{
u
:=
uuid
.
NewV4
()
...
...
@@ -86,7 +86,7 @@ func CreateClient(client *model.Client) (*model.Client, error) {
}
/*
* Read client by id
* Read
Client
client by id
*/
func
ReadClient
(
id
string
)
(
*
model
.
Client
,
error
)
{
v
,
err
:=
deserialize
(
id
)
...
...
@@ -99,7 +99,7 @@ func ReadClient(id string) (*model.Client, error) {
}
/*
*
Get c
lient
c
onfig i
o
n wg format
*
ReadC
lient
C
onfig in wg format
*/
func
ReadClientConfig
(
id
string
)
([]
byte
,
error
)
{
client
,
err
:=
ReadClient
(
id
)
...
...
@@ -121,7 +121,7 @@ func ReadClientConfig(id string) ([]byte, error) {
}
/*
* Update
c
lient preserve keys
* Update
C
lient preserve keys
*/
func
UpdateClient
(
Id
string
,
client
*
model
.
Client
)
(
*
model
.
Client
,
error
)
{
v
,
err
:=
deserialize
(
Id
)
...
...
@@ -154,7 +154,7 @@ func UpdateClient(Id string, client *model.Client) (*model.Client, error) {
}
/*
* Delete
c
lient from disk
* Delete
C
lient from disk
*/
func
DeleteClient
(
id
string
)
error
{
path
:=
filepath
.
Join
(
os
.
Getenv
(
"WG_CONF_DIR"
),
id
)
...
...
@@ -168,7 +168,7 @@ func DeleteClient(id string) error {
}
/*
* Read all clients
* Read
Clients
all clients
*/
func
ReadClients
()
([]
*
model
.
Client
,
error
)
{
clients
:=
make
([]
*
model
.
Client
,
0
)
...
...
@@ -202,7 +202,7 @@ func ReadClients() ([]*model.Client, error) {
}
/*
* Re
turn s
erver object, create default one
* Re
adS
erver object, create default one
*/
func
ReadServer
()
(
*
model
.
Server
,
error
)
{
if
!
util
.
FileExists
(
filepath
.
Join
(
os
.
Getenv
(
"WG_CONF_DIR"
),
"server.json"
))
{
...
...
@@ -245,7 +245,7 @@ func ReadServer() (*model.Server, error) {
}
/*
* Update
s
erver
,
keep private values from existing one
* Update
S
erver keep private values from existing one
*/
func
UpdateServer
(
server
*
model
.
Server
)
(
*
model
.
Server
,
error
)
{
current
,
err
:=
deserialize
(
"server.json"
)
...
...
This diff is collapsed.
Click to expand it.
util/tpl.go
+
2
−
2
View file @
a1828bfc
...
...
@@ -40,7 +40,7 @@ AllowedIPs = {{.Address}}
{{end}}`
)
// dump client wg config with go template
//
DumpClient
dump client wg config with go template
func
DumpClient
(
client
*
model
.
Client
,
server
*
model
.
Server
)
(
bytes
.
Buffer
,
error
)
{
var
tplBuff
bytes
.
Buffer
...
...
@@ -58,7 +58,7 @@ func DumpClient(client *model.Client, server *model.Server) (bytes.Buffer, error
})
}
// dump server wg config with go template
//
DumpServerWg
dump server wg config with go template
func
DumpServerWg
(
clients
[]
*
model
.
Client
,
server
*
model
.
Server
)
(
bytes
.
Buffer
,
error
)
{
var
tplBuff
bytes
.
Buffer
...
...
This diff is collapsed.
Click to expand it.
util/util.go
+
7
−
7
View file @
a1828bfc
...
...
@@ -8,7 +8,7 @@ import (
"strings"
)
//
r
ead file content
//
R
ead
File
file content
func
ReadFile
(
path
string
)
(
bytes
[]
byte
,
err
error
)
{
bytes
,
err
=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
...
...
@@ -18,7 +18,7 @@ func ReadFile(path string) (bytes []byte, err error) {
return
bytes
,
nil
}
//
w
rite content to file
//
W
rite
File
content to file
func
WriteFile
(
path
string
,
bytes
[]
byte
)
(
err
error
)
{
err
=
ioutil
.
WriteFile
(
path
,
bytes
,
0644
)
if
err
!=
nil
{
...
...
@@ -28,7 +28,7 @@ func WriteFile(path string, bytes []byte) (err error) {
return
nil
}
// check if file exists
//
FileExists
check if file exists
func
FileExists
(
name
string
)
bool
{
info
,
err
:=
os
.
Stat
(
name
)
if
os
.
IsNotExist
(
err
)
{
...
...
@@ -37,7 +37,7 @@ func FileExists(name string) bool {
return
!
info
.
IsDir
()
}
// check if directory exists
//
DirectoryExists
check if directory exists
func
DirectoryExists
(
name
string
)
bool
{
info
,
err
:=
os
.
Stat
(
name
)
if
os
.
IsNotExist
(
err
)
{
...
...
@@ -46,7 +46,7 @@ func DirectoryExists(name string) bool {
return
info
.
IsDir
()
}
// search for an available in cidr against a list of reserved ips
//
GetAvailableIp
search for an available in cidr against a list of reserved ips
func
GetAvailableIp
(
cidr
string
,
reserved
[]
string
)
(
string
,
error
)
{
addresses
,
err
:=
GetAllAddressesFromCidr
(
cidr
)
if
err
!=
nil
{
...
...
@@ -69,7 +69,7 @@ func GetAvailableIp(cidr string, reserved []string) (string, error) {
return
""
,
errors
.
New
(
"no more available address from cidr"
)
}
// get all ip addresses from cidr
//
GetAllAddressesFromCidr
get all ip addresses from cidr
func
GetAllAddressesFromCidr
(
cidr
string
)
([]
string
,
error
)
{
ip
,
ipnet
,
err
:=
net
.
ParseCIDR
(
cidr
)
if
err
!=
nil
{
...
...
@@ -94,7 +94,7 @@ func inc(ip net.IP) {
}
}
// check if given ip is IPv6
//
IsIPv6
check if given ip is IPv6
func
IsIPv6
(
address
string
)
bool
{
return
strings
.
Count
(
address
,
":"
)
>=
2
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment