@@ -26,6 +26,14 @@ var englishTxt embed.FS
26
26
27
27
28
28
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
+
29
37
if ! checkKeycardBinaryExists () {
30
38
fmt .Println ("Keycard binary not found. Downloading..." )
31
39
err := downloadKeycardBinary ()
@@ -51,49 +59,66 @@ func main() {
51
59
52
60
switch choice {
53
61
case "1" :
54
- filename , err := generalAskUser ("Enter the filename to encrypt: " )
62
+ filename , err := generalAskUser ("Enter the filename to encrypt and upload : " )
55
63
if err != nil {
56
64
fmt .Println ("Error:" , err )
57
65
continue
58
66
}
59
- if err := encryptFile (filename ); err != nil {
67
+ if err := encryptAndUploadFile (filename ); err != nil {
60
68
fmt .Println ("Error:" , err )
61
69
}
62
70
63
71
case "2" :
64
- err := decryptFileOption ()
65
- if err != nil {
72
+
73
+ if err := decryptAndDownloadFile (); err != nil {
66
74
fmt .Println ("Error:" , err )
67
75
}
68
76
69
77
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
+ }
71
100
101
+ case "5" :
102
+ qr ()
72
103
73
- case "4 " :
104
+ case "6 " :
74
105
fmt .Println ("Installing Dependencies..." )
75
106
keycard_link .JavaDependency ()
76
107
keycard_link .GlobalPlatformDependency ()
77
108
78
- case "5 " :
109
+ case "7 " :
79
110
fmt .Println ("Installing Keycard..." )
80
111
err := keycard_link .InstallKeycard ()
81
112
if err != nil {
82
113
fmt .Println ("Error installing keycard:" , err )
83
114
}
84
115
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
88
119
runIPFSTestWithViu (cid )
89
120
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" :
97
122
fmt .Println ("Exiting..." )
98
123
os .Exit (0 )
99
124
@@ -161,20 +186,22 @@ func menu() (string, error) {
161
186
return generalAskUser ("Enter your choice: " )
162
187
}
163
188
164
- func encryptAndUploadFile (filename string , level string ) error {
189
+ func encryptAndUploadFile (filename string ) error {
165
190
if err := encryptFile (filename ); err != nil {
166
191
return err
167
192
}
168
193
encryptedFilename := filename + ".aes"
169
- return ipfsUpload (encryptedFilename , level )
170
- }
171
- //
172
- func decryptAndDownloadFile () error {
173
- filePath , err := ipfsDownload ()
194
+ level , err := readConfig ()
174
195
if err != nil {
175
196
return err
176
197
}
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 ()
178
205
}
179
206
180
207
@@ -323,11 +350,7 @@ func decryptFileOption() error {
323
350
if useLog {
324
351
return decryptFileFromLog ()
325
352
} 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 ()
331
354
}
332
355
}
333
356
@@ -555,7 +578,12 @@ func ipfsDownload() (string, error) {
555
578
return savePath , nil
556
579
}
557
580
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
+
559
587
level , err := generalAskUser ("Enter the encryption level used on the file (easy, medium, hard): " )
560
588
if err != nil {
561
589
return fmt .Errorf ("\033 [1;31merror reading encryption level: %w\033 [0m" , err )
@@ -611,6 +639,7 @@ func decryptFile(filePath string) error {
611
639
return nil
612
640
}
613
641
642
+
614
643
func setupConfig () error {
615
644
configDir := os .Getenv ("HOME" ) + "/.config/DangerousNet"
616
645
configFile := configDir + "/config"
@@ -624,7 +653,7 @@ func setupConfig() error {
624
653
// Check if the config file exists
625
654
if _ , err := os .Stat (configFile ); os .IsNotExist (err ) {
626
655
// Create a default config file
627
- defaultConfig := []byte ("encryptionLevel=medium \n " )
656
+ defaultConfig := []byte ("encryptionLevel=easy \n " )
628
657
err = os .WriteFile (configFile , defaultConfig , 0644 )
629
658
if err != nil {
630
659
return fmt .Errorf ("error creating default config file: %w" , err )
0 commit comments