|
@@ -5,6 +5,7 @@ import (
|
|
|
"be-vpn/internal/model"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"log"
|
|
|
+ "math/rand"
|
|
|
"net/http"
|
|
|
"sync"
|
|
|
"time"
|
|
@@ -79,6 +80,24 @@ func List(c *gin.Context) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+func SecretRandom(c *gin.Context) {
|
|
|
+ locker.RLock()
|
|
|
+ defer locker.RUnlock()
|
|
|
+
|
|
|
+ random := rand.Intn(len(nodes))
|
|
|
+
|
|
|
+ for i, node := range nodes {
|
|
|
+ if i == random {
|
|
|
+ c.Header("Content-Disposition", "attachment; filename=client.ovpn")
|
|
|
+ c.Data(http.StatusOK, "plain/text", []byte(node.Secret))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.JSON(http.StatusNotFound, gin.H{
|
|
|
+ "message": "not found",
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
func Secret(c *gin.Context) {
|
|
|
locker.RLock()
|
|
|
defer locker.RUnlock()
|