-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
135 lines (114 loc) · 2.77 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"bufio"
"crypto/sha512"
"fmt"
"io/ioutil"
"log"
"os"
"passcypher"
"safeui"
"strings"
"tableactions"
"github.com/howeyc/gopass"
)
const dataDirectory = "./data/"
const prefrenceFile = "./data/prefrences"
func create(scanner *bufio.Scanner, hash *[]byte) {
fmt.Println("Please enter the Platform:")
scanner.Scan()
platform := scanner.Text()
fmt.Println("Please enter the Username:")
scanner.Scan()
id := scanner.Text()
fmt.Println("Please enter the Password:")
scanner.Scan()
secret := scanner.Text()
if secret == "" {
secret, _ = safeui.GeneratePass(12)
}
t := passcypher.Credentials{
Platform: platform,
User: id,
Password: secret,
}
encodedValue, _ := passcypher.GenerateEncryptedPEM(t, *hash)
tableactions.InsertValue(*encodedValue)
}
func read(hash *[]byte) {
arr, err := tableactions.DecypherTable(*hash)
fck(err)
for index, obj := range arr {
fmt.Printf("%d. Platform: %s | Username: %s | Password: %s", index+1, obj.Platform, obj.User, obj.Password)
}
}
func login() (*bufio.Scanner, []byte) {
scanner := bufio.NewScanner(os.Stdin)
fmt.Println("Login..")
fmt.Println("User Name")
scanner.Scan()
userName := scanner.Text()
fmt.Println("Password")
password, err := gopass.GetPasswdMasked()
fck(err)
creds := userName + string(password)
err = tableactions.Validate(creds)
fck(err)
sha512Pass := sha512.New()
sha512Pass.Write([]byte(creds))
return scanner, sha512Pass.Sum(nil)
}
func main() {
_, err := ioutil.ReadDir(dataDirectory)
if err != nil {
os.MkdirAll(dataDirectory, 0755)
}
_, err = ioutil.ReadFile(prefrenceFile)
if err != nil {
os.Create(prefrenceFile)
}
if len(os.Args) > 1 {
if strings.ToLower(os.Args[1]) == "create" {
var mapField map[int]string
err := safeui.ReadPrefrences(&mapField, prefrenceFile)
if err != nil {
fck(err)
}
tableactions.SetDB(mapField[0], mapField[1])
scanner, sha512PassHash := login()
create(scanner, &sha512PassHash)
} else if strings.ToLower(os.Args[1]) == "read" {
var mapField map[int]string
err := safeui.ReadPrefrences(&mapField, prefrenceFile)
if err != nil {
fck(err)
}
tableactions.SetDB(mapField[0], mapField[1])
_, sha512PassHash := login()
read(&sha512PassHash)
} else if strings.ToLower(os.Args[1]) == "sqlite" {
tableactions.SetSQLite()
login()
fmt.Println("Set SQLite DB")
} else if strings.ToLower(os.Args[1]) == "mysql" {
tableactions.SetMySQL()
login()
fmt.Println("Set MySQL DB")
} else if strings.ToLower(os.Args[1]) == "psql" {
tableactions.SetPLSQL()
login()
fmt.Println("Set PSQL DB")
} else {
panic("Invalid Arguement!")
}
} else {
safeui.LoadUI(prefrenceFile)
}
}
func fck(err error) error {
if err != nil {
log.Fatal(err)
return err
}
return nil
}