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
38c86f32
Commit
38c86f32
authored
5 years ago
by
vx3r
Browse files
Options
Downloads
Patches
Plain Diff
go fmt / badges
parent
a1828bfc
Loading
Loading
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
repository/repository.go
+12
-36
12 additions, 36 deletions
repository/repository.go
with
12 additions
and
36 deletions
repository/repository.go
+
12
−
36
View file @
38c86f32
...
...
@@ -16,9 +16,7 @@ import (
"time"
)
/*
* CreateClient client with all necessary data
*/
// CreateClient client with all necessary data
func
CreateClient
(
client
*
model
.
Client
)
(
*
model
.
Client
,
error
)
{
u
:=
uuid
.
NewV4
()
client
.
Id
=
u
.
String
()
...
...
@@ -85,9 +83,7 @@ func CreateClient(client *model.Client) (*model.Client, error) {
return
client
,
nil
}
/*
* ReadClient client by id
*/
// ReadClient client by id
func
ReadClient
(
id
string
)
(
*
model
.
Client
,
error
)
{
v
,
err
:=
deserialize
(
id
)
if
err
!=
nil
{
...
...
@@ -98,9 +94,7 @@ func ReadClient(id string) (*model.Client, error) {
return
client
,
nil
}
/*
* ReadClientConfig in wg format
*/
// ReadClientConfig in wg format
func
ReadClientConfig
(
id
string
)
([]
byte
,
error
)
{
client
,
err
:=
ReadClient
(
id
)
if
err
!=
nil
{
...
...
@@ -120,9 +114,7 @@ func ReadClientConfig(id string) ([]byte, error) {
return
configDataWg
.
Bytes
(),
nil
}
/*
* UpdateClient preserve keys
*/
// UpdateClient preserve keys
func
UpdateClient
(
Id
string
,
client
*
model
.
Client
)
(
*
model
.
Client
,
error
)
{
v
,
err
:=
deserialize
(
Id
)
if
err
!=
nil
{
...
...
@@ -153,9 +145,7 @@ func UpdateClient(Id string, client *model.Client) (*model.Client, error) {
return
client
,
nil
}
/*
* DeleteClient from disk
*/
// DeleteClient from disk
func
DeleteClient
(
id
string
)
error
{
path
:=
filepath
.
Join
(
os
.
Getenv
(
"WG_CONF_DIR"
),
id
)
err
:=
os
.
Remove
(
path
)
...
...
@@ -167,9 +157,7 @@ func DeleteClient(id string) error {
return
generateWgConfig
()
}
/*
* ReadClients all clients
*/
// ReadClients all clients
func
ReadClients
()
([]
*
model
.
Client
,
error
)
{
clients
:=
make
([]
*
model
.
Client
,
0
)
...
...
@@ -201,9 +189,7 @@ func ReadClients() ([]*model.Client, error) {
return
clients
,
nil
}
/*
* ReadServer object, create default one
*/
// ReadServer object, create default one
func
ReadServer
()
(
*
model
.
Server
,
error
)
{
if
!
util
.
FileExists
(
filepath
.
Join
(
os
.
Getenv
(
"WG_CONF_DIR"
),
"server.json"
))
{
server
:=
&
model
.
Server
{}
...
...
@@ -244,9 +230,7 @@ func ReadServer() (*model.Server, error) {
return
c
.
(
*
model
.
Server
),
nil
}
/*
* UpdateServer keep private values from existing one
*/
// UpdateServer keep private values from existing one
func
UpdateServer
(
server
*
model
.
Server
)
(
*
model
.
Server
,
error
)
{
current
,
err
:=
deserialize
(
"server.json"
)
if
err
!=
nil
{
...
...
@@ -272,9 +256,7 @@ func UpdateServer(server *model.Server) (*model.Server, error) {
return
server
,
nil
}
/*
* Write object to disk
*/
// Write object to disk
func
serialize
(
id
string
,
c
interface
{})
error
{
b
,
err
:=
json
.
Marshal
(
c
)
if
err
!=
nil
{
...
...
@@ -290,9 +272,7 @@ func serialize(id string, c interface{}) error {
return
generateWgConfig
()
}
/*
* Read client from disc
*/
// Read client from disc
func
deserializeClient
(
data
[]
byte
)
(
*
model
.
Client
,
error
)
{
var
c
*
model
.
Client
err
:=
json
.
Unmarshal
(
data
,
&
c
)
...
...
@@ -303,9 +283,7 @@ func deserializeClient(data []byte) (*model.Client, error) {
return
c
,
nil
}
/*
* Read server from disc
*/
// Read server from disc
func
deserializeServer
(
data
[]
byte
)
(
*
model
.
Server
,
error
)
{
var
c
*
model
.
Server
err
:=
json
.
Unmarshal
(
data
,
&
c
)
...
...
@@ -329,9 +307,7 @@ func deserialize(id string) (interface{}, error) {
return
deserializeClient
(
b
)
}
/*
* Generate Wireguard interface configuration
*/
// Generate Wireguard interface configuration
func
generateWgConfig
()
error
{
clients
,
err
:=
ReadClients
()
if
err
!=
nil
{
...
...
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