Specify path to write encryted files to
This commit is contained in:
parent
8a230bdc64
commit
f600f4fe93
@ -13,6 +13,8 @@
|
||||
Password for login (default "123456")
|
||||
-gpgkey path
|
||||
File of the public GPG key to encrypt files to
|
||||
-output
|
||||
Path to directory to write encrypted files to
|
||||
|
||||
```
|
||||
|
||||
|
21
main.go
21
main.go
@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"flag"
|
||||
@ -16,6 +17,7 @@ import (
|
||||
|
||||
type ForwarderDriver struct {
|
||||
RecipientKey *crypto.Key
|
||||
OutputPath string
|
||||
server.Perm
|
||||
}
|
||||
|
||||
@ -107,10 +109,12 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa
|
||||
t := time.Now()
|
||||
encrypted_filename := fmt.Sprintf("scan_%04d-%02d-%02d-%02d-%02d_%v.asc", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), dest_filename)
|
||||
|
||||
log.Printf("Writing to %v", encrypted_filename)
|
||||
encrypted_file_path := filepath.Join(driver.OutputPath, encrypted_filename)
|
||||
|
||||
log.Printf("Writing to %v", encrypted_file_path)
|
||||
|
||||
log.Printf("Opening output file")
|
||||
encryptedFile, err := os.Create(encrypted_filename)
|
||||
encryptedFile, err := os.Create(encrypted_file_path)
|
||||
if err != nil {
|
||||
log.Printf("Error: %v", err)
|
||||
return 0, err
|
||||
@ -147,11 +151,12 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa
|
||||
|
||||
type ForwarderDriverFactory struct {
|
||||
RecipientKey *crypto.Key
|
||||
OutputPath string
|
||||
server.Perm
|
||||
}
|
||||
|
||||
func (factory *ForwarderDriverFactory) NewDriver() (server.Driver, error) {
|
||||
return &ForwarderDriver{factory.RecipientKey, factory.Perm}, nil
|
||||
return &ForwarderDriver{factory.RecipientKey, factory.OutputPath, factory.Perm}, nil
|
||||
}
|
||||
|
||||
|
||||
@ -164,8 +169,17 @@ func main() {
|
||||
host = flag.String("host", "localhost", "Host")
|
||||
passiveports = flag.String("passiveports", "2130-2134", "Passive ports")
|
||||
gpgkey_path = flag.String("gpgkey", "", "File of the public GPG key to encrypt files to")
|
||||
output_path = flag.String("output", ".", "Path to directory to write encrypted files to")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
absolute_output_path, err := filepath.Abs(*output_path)
|
||||
if err != nil {
|
||||
log.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Writing encrypted files to %v", absolute_output_path)
|
||||
|
||||
if *gpgkey_path == "" {
|
||||
log.Fatalf("Specify path to GPG key with -gpgkey")
|
||||
}
|
||||
@ -190,6 +204,7 @@ func main() {
|
||||
|
||||
factory := &ForwarderDriverFactory{
|
||||
RecipientKey: gpgkey,
|
||||
OutputPath: absolute_output_path,
|
||||
Perm: server.NewSimplePerm("user","group"),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user