diff --git a/Dockerfile b/Dockerfile
index 3d73d38..88fa7e6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -35,6 +35,9 @@ RUN mkdir -p assets/plugins && \
/build/node_modules/jquery-tags-input/ \
assets/plugins/
+# Move custom assets
+RUN cp -r /build/custom/ assets/
+
# Get go modules and build tool
RUN go mod download && \
go get github.com/GeertJohan/go.rice/rice
diff --git a/custom/js/helper.js b/custom/js/helper.js
new file mode 100644
index 0000000..42bc17a
--- /dev/null
+++ b/custom/js/helper.js
@@ -0,0 +1,60 @@
+function renderClientList(data) {
+ $.each(data, function(index, obj) {
+ // render client status css tag style
+ let clientStatusHtml = '>'
+ if (obj.Client.enabled) {
+ clientStatusHtml = `style="visibility: hidden;">`
+ }
+
+ // render client allocated ip addresses
+ let allocatedIpsHtml = "";
+ $.each(obj.Client.allocated_ips, function(index, obj) {
+ allocatedIpsHtml += `${obj} `;
+ })
+
+ // render client allowed ip addresses
+ let allowedIpsHtml = "";
+ $.each(obj.Client.allowed_ips, function(index, obj) {
+ allowedIpsHtml += `${obj} `;
+ })
+
+ // render client html content
+ let html = `
-
-
-
+
+
+
+
+
+
@@ -245,7 +246,28 @@
+
+
{{end}}
\ No newline at end of file
diff --git a/util/db.go b/util/db.go
index ba375ac..23f2d23 100644
--- a/util/db.go
+++ b/util/db.go
@@ -209,7 +209,7 @@ func GetClients(hasQRCode bool) ([]model.ClientData, error) {
server, _ := GetServer()
globalSettings, _ := GetGlobalSettings()
- png, _ := qrcode.Encode(BuildClientConfig(client, server, globalSettings), qrcode.Medium, 256)
+ png, err := qrcode.Encode(BuildClientConfig(client, server, globalSettings), qrcode.Medium, 256)
if err == nil {
clientData.QRCode = "data:image/png;base64," + base64.StdEncoding.EncodeToString([]byte(png))
} else {
@@ -226,18 +226,34 @@ func GetClients(hasQRCode bool) ([]model.ClientData, error) {
}
// GetClientByID func to query a client from the database
-func GetClientByID(clientID string) (model.Client, error) {
+func GetClientByID(clientID string, hasQRCode bool) (model.ClientData, error) {
client := model.Client{}
+ clientData := model.ClientData{}
db, err := DBConn()
if err != nil {
- return client, err
+ return clientData, err
}
// read client information
if err := db.Read("clients", clientID, &client); err != nil {
- return client, err
+ return clientData, err
}
- return client, nil
+ // generate client qrcode image in base64
+ if hasQRCode {
+ server, _ := GetServer()
+ globalSettings, _ := GetGlobalSettings()
+
+ png, err := qrcode.Encode(BuildClientConfig(client, server, globalSettings), qrcode.Medium, 256)
+ if err == nil {
+ clientData.QRCode = "data:image/png;base64," + base64.StdEncoding.EncodeToString([]byte(png))
+ } else {
+ fmt.Print("Cannot generate QR code: ", err)
+ }
+ }
+
+ clientData.Client = &client
+
+ return clientData, nil
}
diff --git a/util/util.go b/util/util.go
index 384886f..d98aaec 100644
--- a/util/util.go
+++ b/util/util.go
@@ -173,7 +173,7 @@ func GetIPFromCIDR(cidr string) (string, error) {
}
// GetAllocatedIPs to get all ip addresses allocated to clients and server
-func GetAllocatedIPs() ([]string, error) {
+func GetAllocatedIPs(ignoreClientID string) ([]string, error) {
allocatedIPs := make([]string, 0)
// initialize database directory
@@ -211,12 +211,14 @@ func GetAllocatedIPs() ([]string, error) {
return nil, err
}
- for _, cidr := range client.AllocatedIPs {
- ip, err := GetIPFromCIDR(cidr)
- if err != nil {
- return nil, err
+ if client.ID != ignoreClientID {
+ for _, cidr := range client.AllocatedIPs {
+ ip, err := GetIPFromCIDR(cidr)
+ if err != nil {
+ return nil, err
+ }
+ allocatedIPs = append(allocatedIPs, ip)
}
- allocatedIPs = append(allocatedIPs, ip)
}
}