Skip to content

Commit 13fdb03

Browse files
authored
Add files via upload
Signed-off-by: Anthony Grace <[email protected]>
1 parent 963af93 commit 13fdb03

File tree

1 file changed

+60
-31
lines changed

1 file changed

+60
-31
lines changed

main.go

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ var englishTxt embed.FS
2626

2727

2828
func main() {
29+
// Setup configuration file
30+
if err := setupConfig(); err != nil {
31+
fmt.Printf("Failed to set up config: %s\n", err)
32+
os.Exit(1)
33+
}
34+
35+
36+
2937
if !checkKeycardBinaryExists() {
3038
fmt.Println("Keycard binary not found. Downloading...")
3139
err := downloadKeycardBinary()
@@ -51,49 +59,66 @@ func main() {
5159

5260
switch choice {
5361
case "1":
54-
filename, err := generalAskUser("Enter the filename to encrypt: ")
62+
filename, err := generalAskUser("Enter the filename to encrypt and upload: ")
5563
if err != nil {
5664
fmt.Println("Error:", err)
5765
continue
5866
}
59-
if err := encryptFile(filename); err != nil {
67+
if err := encryptAndUploadFile(filename); err != nil {
6068
fmt.Println("Error:", err)
6169
}
6270

6371
case "2":
64-
err := decryptFileOption()
65-
if err != nil {
72+
73+
if err := decryptAndDownloadFile(); err != nil {
6674
fmt.Println("Error:", err)
6775
}
6876

6977
case "3":
70-
qr()
78+
savePath, err := ipfsDownload()
79+
if err != nil {
80+
fmt.Println("Error:", err)
81+
} else {
82+
fmt.Printf("File downloaded successfully to %s\n", savePath)
83+
}
84+
85+
case "4":
86+
filePath, err := generalAskUser("Enter the file path to upload to IPFS: ")
87+
if err != nil {
88+
fmt.Println("Error:", err)
89+
continue
90+
}
91+
// Assuming the level is read from the configuration file
92+
level, err := readConfig()
93+
if err != nil {
94+
fmt.Println("Error:", err)
95+
continue
96+
}
97+
if err := ipfsUpload(filePath, level); err != nil {
98+
fmt.Println("Error:", err)
99+
}
71100

101+
case "5":
102+
qr()
72103

73-
case "4":
104+
case "6":
74105
fmt.Println("Installing Dependencies...")
75106
keycard_link.JavaDependency()
76107
keycard_link.GlobalPlatformDependency()
77108

78-
case "5":
109+
case "7":
79110
fmt.Println("Installing Keycard...")
80111
err := keycard_link.InstallKeycard()
81112
if err != nil {
82113
fmt.Println("Error installing keycard:", err)
83114
}
84115

85-
case "6":
86-
fmt.Println("Running Connection test to the IPFS Network.")
87-
cid := "bafkreie7ohywtosou76tasm7j63yigtzxe7d5zqus4zu3j6oltvgtibeom" // Welcome to IPFS CID
116+
case "8":
117+
fmt.Println("Running Connection test to the IPFS Network.")
118+
cid := "bafkreie7ohywtosou76tasm7j63yigtzxe7d5zqus4zu3j6oltvgtibeom" // Welcome to IPFS CID
88119
runIPFSTestWithViu(cid)
89120

90-
91-
case "7":
92-
err := art_link.PrintFileSlowly("apexflexflexsecure.txt")
93-
if err != nil {
94-
fmt.Println("Error displaying ASCII art:", err)
95-
}
96-
121+
case "9":
97122
fmt.Println("Exiting...")
98123
os.Exit(0)
99124

@@ -161,20 +186,22 @@ func menu() (string, error) {
161186
return generalAskUser("Enter your choice: ")
162187
}
163188

164-
func encryptAndUploadFile(filename string, level string) error {
189+
func encryptAndUploadFile(filename string) error {
165190
if err := encryptFile(filename); err != nil {
166191
return err
167192
}
168193
encryptedFilename := filename + ".aes"
169-
return ipfsUpload(encryptedFilename, level)
170-
}
171-
//
172-
func decryptAndDownloadFile() error {
173-
filePath, err := ipfsDownload()
194+
level, err := readConfig()
174195
if err != nil {
175196
return err
176197
}
177-
return decryptFile(filePath)
198+
return ipfsUpload(encryptedFilename, level)
199+
}
200+
201+
202+
func decryptAndDownloadFile() error {
203+
// IPFS DOWNLOAD IS ALREADY CALLED WITHIN DECRYPT FILE FUNCTION! :)
204+
return decryptFile()
178205
}
179206

180207

@@ -323,11 +350,7 @@ func decryptFileOption() error {
323350
if useLog {
324351
return decryptFileFromLog()
325352
} else {
326-
filename, err := generalAskUser("\033[1;36mEnter the filename to decrypt ('Save file as'):\033[0m")
327-
if err != nil {
328-
return fmt.Errorf("\033[1;31merror reading filename: %w\033[0m", err)
329-
}
330-
return decryptFile(filename)
353+
return decryptFile()
331354
}
332355
}
333356

@@ -555,7 +578,12 @@ func ipfsDownload() (string, error) {
555578
return savePath, nil
556579
}
557580

558-
func decryptFile(filePath string) error {
581+
func decryptFile() error {
582+
filePath, err := generalAskUser("Enter the path of the encrypted file to decrypt: ")
583+
if err != nil {
584+
return fmt.Errorf("\033[1;31merror reading file path: %w\033[0m", err)
585+
}
586+
559587
level, err := generalAskUser("Enter the encryption level used on the file (easy, medium, hard): ")
560588
if err != nil {
561589
return fmt.Errorf("\033[1;31merror reading encryption level: %w\033[0m", err)
@@ -611,6 +639,7 @@ func decryptFile(filePath string) error {
611639
return nil
612640
}
613641

642+
614643
func setupConfig() error {
615644
configDir := os.Getenv("HOME") + "/.config/DangerousNet"
616645
configFile := configDir + "/config"
@@ -624,7 +653,7 @@ func setupConfig() error {
624653
// Check if the config file exists
625654
if _, err := os.Stat(configFile); os.IsNotExist(err) {
626655
// Create a default config file
627-
defaultConfig := []byte("encryptionLevel=medium\n")
656+
defaultConfig := []byte("encryptionLevel=easy\n")
628657
err = os.WriteFile(configFile, defaultConfig, 0644)
629658
if err != nil {
630659
return fmt.Errorf("error creating default config file: %w", err)

0 commit comments

Comments
 (0)