-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
70 lines (52 loc) · 1.42 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
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
type toChange struct {
name string
url string
}
func main() {
// might not need
var websiteArr []Website
var appsArr []Application
var needChange []toChange
Setup() // setup Source, Destination, Delimiter
f, err := os.Open(SourcePath)
if err != nil {
log.Fatal(err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
if strings.Contains(scanner.Text(), "Websites") {
websiteArr = readWebsites(scanner)
}
if strings.Contains(scanner.Text(), "Applications") {
appsArr = readApps(scanner)
}
}
// write header to file
os.Remove(DestPath) // delete the file if it exists
outputFile, err := os.OpenFile(DestPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
log.Fatal(err)
}
defer outputFile.Close()
outputFile.WriteString("App" + Delimiter + "name" + Delimiter + "url" + Delimiter + "username" + Delimiter + "password\n")
addWebsToFile(websiteArr, Delimiter, &needChange, outputFile)
addAppsToFile(appsArr, Delimiter, &needChange, outputFile)
outputFile.Sync()
// notify the user of what needs to be changed
fmt.Printf("The following account passwords need to be changed because they contain the Delimiter ( %v ):\n", Delimiter)
for index, entry := range needChange {
fmt.Printf("\t%d. %v -> %v\n", index+1, entry.name, entry.url)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}