mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
WIP: auto env generator
This commit is contained in:
parent
3cc0a2017d
commit
0a4e798e86
5 changed files with 99 additions and 8 deletions
|
|
@ -39,8 +39,6 @@ func ApiGet(w http.ResponseWriter, r *http.Request) {
|
||||||
file = "../public/index.html" // default
|
file = "../public/index.html" // default
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.MCRMLog("GET:", file)
|
|
||||||
|
|
||||||
http.ServeFile(w, r, file) // serve file
|
http.ServeFile(w, r, file) // serve file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"math"
|
||||||
|
mathRand "math/rand"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -62,7 +65,7 @@ func DecryptAES(key string, cryptedText string) (string, error) {
|
||||||
return origDataString, nil
|
return origDataString, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomString(length int) string {
|
func GenerateRandomString(length int) string {
|
||||||
b := make([]byte, length)
|
b := make([]byte, length)
|
||||||
_, err := rand.Read(b)
|
_, err := rand.Read(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -71,8 +74,15 @@ func generateRandomString(length int) string {
|
||||||
return base64.StdEncoding.EncodeToString(b)
|
return base64.StdEncoding.EncodeToString(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateRandomIntegerString(length int) string {
|
||||||
|
min := int64(0)
|
||||||
|
max := int64(math.Pow10(length))
|
||||||
|
randInt := min + mathRand.Int63()%(max-min+1)
|
||||||
|
return strconv.FormatInt(randInt, 10)
|
||||||
|
}
|
||||||
|
|
||||||
func GenerateKey() string {
|
func GenerateKey() string {
|
||||||
return strings.Replace(generateRandomString(24), "=", "", -1)
|
return strings.Replace(GenerateRandomString(24), "=", "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func keyToBytes(key string) []byte {
|
func keyToBytes(key string) []byte {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,60 @@
|
||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func EnvGet(key string) string {
|
func EnvGet(key string) string {
|
||||||
err := godotenv.Load("../.env")
|
envFile := "../.env"
|
||||||
|
fileExists := func() bool {
|
||||||
|
_, err := os.Stat(envFile)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
if !fileExists() {
|
||||||
|
createEnvFile(envFile)
|
||||||
|
}
|
||||||
|
err := godotenv.Load(envFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return os.Getenv("VITE_" + key)
|
return os.Getenv("VITE_" + key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createEnvFile(filename string) {
|
||||||
|
log.Println("Creating .env file...")
|
||||||
|
file, err := os.Create(filename)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
// You can add some default values to the .env file here if needed
|
||||||
|
// For example:
|
||||||
|
port, err := findOpenPort()
|
||||||
|
salt := GenerateRandomString(28)
|
||||||
|
iv := GenerateRandomIntegerString(16)
|
||||||
|
|
||||||
|
log.Println(err, salt, iv)
|
||||||
|
|
||||||
|
_, err = file.WriteString("VITE_MCRM__PORT=" + string(port) + "\nVITE_MCRM__SALT=" + salt + "\nVITE_MCRM__IV=" + iv)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func findOpenPort() (string, error) {
|
||||||
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
l, err := net.ListenTCP("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer l.Close()
|
||||||
|
return strconv.Itoa(l.Addr().(*net.TCPAddr).Port), nil
|
||||||
|
}
|
||||||
|
|
|
||||||
37
be/log.txt
37
be/log.txt
|
|
@ -1,3 +1,34 @@
|
||||||
ApiPost EndPointAccess Error: /macro/list: endpoint access: accessible
|
listen tcp: lookup tcp/셁: unknown port
|
||||||
ApiPost EndPointAccess Error: /macro/list: endpoint access: accessible
|
listen tcp: lookup tcp/셁: unknown port
|
||||||
ApiPost EndPointAccess Error: /panel/list: endpoint access: accessible
|
listen tcp: lookup tcp/죫: unknown port
|
||||||
|
listen tcp: lookup tcp/죫: unknown port
|
||||||
|
listen tcp: lookup tcp/촙: unknown port
|
||||||
|
listen tcp: lookup tcp/촙: unknown port
|
||||||
|
listen tcp: lookup tcp/촙: unknown port
|
||||||
|
DeviceAccessCheck: UUID: 7e7084c3-890c-485d-9168-09d207507077 ; Access: Unlinked
|
||||||
|
PingLink Error: keyErr: open devices/7e7084c3-890c-485d-9168-09d207507077.key: The system cannot find the file specified. ; pinErr: open devices/7e7084c3-890c-485d-9168-09d207507077.tmp: The system cannot find the file specified. ; encErr: crypto/aes: invalid key size 0
|
||||||
|
PingLink Error: keyErr: open devices/7e7084c3-890c-485d-9168-09d207507077.key: The system cannot find the file specified. ; pinErr: open devices/7e7084c3-890c-485d-9168-09d207507077.tmp: The system cannot find the file specified. ; encErr: crypto/aes: invalid key size 0
|
||||||
|
PingLink Error: keyErr: open devices/7e7084c3-890c-485d-9168-09d207507077.key: The system cannot find the file specified. ; pinErr: open devices/7e7084c3-890c-485d-9168-09d207507077.tmp: The system cannot find the file specified. ; encErr: crypto/aes: invalid key size 0
|
||||||
|
PingLink Error: keyErr: open devices/7e7084c3-890c-485d-9168-09d207507077.key: The system cannot find the file specified. ; pinErr: open devices/7e7084c3-890c-485d-9168-09d207507077.tmp: The system cannot find the file specified. ; encErr: crypto/aes: invalid key size 0
|
||||||
|
PingLink Error: keyErr: open devices/7e7084c3-890c-485d-9168-09d207507077.key: The system cannot find the file specified. ; pinErr: open devices/7e7084c3-890c-485d-9168-09d207507077.tmp: The system cannot find the file specified. ; encErr: crypto/aes: invalid key size 0
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
PingLink Error: keyErr: <nil> ; pinErr: <nil> ; encErr: crypto/aes: invalid key size 44
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,18 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
app.MCRMLogInit()
|
app.MCRMLogInit()
|
||||||
|
|
||||||
|
if helper.EnvGet("MCRM__PORT") == "" {
|
||||||
|
app.MCRMLog("Error: MCRM__PORT is not set")
|
||||||
|
}
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
apiInit(w, r)
|
apiInit(w, r)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
helper.OpenBrowser("http://localhost:" + helper.EnvGet("MCRM__PORT"))
|
||||||
|
|
||||||
app.MCRMLog(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil))
|
app.MCRMLog(http.ListenAndServe(":"+helper.EnvGet("MCRM__PORT"), nil))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiInit(w http.ResponseWriter, r *http.Request) {
|
func apiInit(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue