Add view config page
This commit is contained in:
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
#include <ncurses.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
@@ -23,7 +22,3 @@ func freeCStringArray(cStrings **C.char, length int) {
|
||||
C.free(unsafe.Pointer(s))
|
||||
}
|
||||
}
|
||||
|
||||
func debug(message string) {
|
||||
C.Debug(message)
|
||||
}
|
||||
|
||||
25
go/totp.go
25
go/totp.go
@@ -19,6 +19,7 @@ import (
|
||||
)
|
||||
|
||||
var token string
|
||||
var homeDir string
|
||||
|
||||
var configs map[string]otp.Config
|
||||
|
||||
@@ -26,8 +27,6 @@ func getSha1() func() hash.Hash { return sha1.New }
|
||||
|
||||
//export loadConfigs
|
||||
func loadConfigs() {
|
||||
var homeDir string
|
||||
|
||||
osVar := runtime.GOOS
|
||||
if osVar == "windows" {
|
||||
homeDir = os.Getenv("USERPROFILE")
|
||||
@@ -157,6 +156,28 @@ func getConfigNames() (**C.char, C.int) {
|
||||
return (**C.char)(cArray), C.int(configsLen)
|
||||
}
|
||||
|
||||
//export getConfig
|
||||
func getConfig(configName string) (*C.char, C.int) {
|
||||
files, err := os.ReadDir(homeDir + "/.totp")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, fileEntry := range files {
|
||||
if strings.HasPrefix(fileEntry.Name(), configName) {
|
||||
fileBytes, err := os.ReadFile(homeDir + "/.totp/" + fileEntry.Name())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fileStr := string(fileBytes)
|
||||
cStr := C.CString(fileStr)
|
||||
runtime.KeepAlive(fileStr)
|
||||
return (*C.char)(cStr), (C.int)(len(fileStr))
|
||||
}
|
||||
}
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
//export getCode
|
||||
func getCode(configName string) *C.char {
|
||||
code := configs[configName].TOTP()
|
||||
|
||||
Reference in New Issue
Block a user