kmahyyg 4 лет назад
Родитель
Сommit
fe861b1446
3 измененных файлов с 22 добавлено и 5 удалено
  1. 2 0
      README.md
  2. 19 4
      argon2g/main.go
  3. 1 1
      start_ztncui.sh

+ 2 - 0
README.md

@@ -33,3 +33,5 @@ This image additional specific:
 | YES | MYADDR | your ip address, public ip address preferred | NO DEFAULT |
 
 Also, this image exposed an http server at port 3180, you could save file in `/mydata/ztncui/myfs/` to serve it. (You could use this to build your own root server and distribute planet file)
+
+**WARNING: IF YOU DO NOT SET PASSWORD, YOU HAVE TO USE `docker exec -it <CONTAINER NAME> bash`, and then `cat /var/log/docker-ztncui.log` to get your random password. This is gatekeeper.**

+ 19 - 4
argon2g/main.go

@@ -1,12 +1,13 @@
 package main
 
 import (
-	"crypto/rand"
 	"encoding/base64"
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"log"
+	"math/rand"
+	"os"
 
 	"golang.org/x/crypto/argon2"
 )
@@ -21,10 +22,24 @@ type PasswdDef struct {
 	Admin UserDef `json:"admin"`
 }
 
+const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
+
+func RandStringBytes(n int) string {
+	b := make([]byte, n)
+	for i := range b {
+		b[i] = letterBytes[rand.Intn(len(letterBytes))] // It's not safe for password purpose, but i'm lazy.
+	}
+	return string(b)
+}
+
 func main() {
-	var password string
-	fmt.Print("Input Password: ")
-	fmt.Scanln(&password)
+	var password string = os.Getenv("ZTNCUI_PASSWD")
+	if len(password) < 2 {
+		log.Println("Current Password: " + password + " is too weak or not set...")
+		password = RandStringBytes(10)
+	} else {
+		log.Println("Current Password: " + password)
+	}
 
 	var ag2_memory uint32 = 4096
 	var ag2_iter uint32 = 3

+ 1 - 1
start_ztncui.sh

@@ -49,7 +49,7 @@ mkdir -p /opt/key-networks/ztncui/etc/myfs # for planet files
 if [ ! -f /opt/key-networks/ztncui/etc/passwd ]; then
     echo "Default Password File Not Exists... Generating..."
     cd /opt/key-networks/ztncui/etc
-    echo $ZTNCUI_PASSWD | /usr/local/bin/argon2g 
+    /usr/local/bin/argon2g 
     cd ../
 fi