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")
|
Password for login (default "123456")
|
||||||
-gpgkey path
|
-gpgkey path
|
||||||
File of the public GPG key to encrypt files to
|
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"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"flag"
|
"flag"
|
||||||
@ -16,6 +17,7 @@ import (
|
|||||||
|
|
||||||
type ForwarderDriver struct {
|
type ForwarderDriver struct {
|
||||||
RecipientKey *crypto.Key
|
RecipientKey *crypto.Key
|
||||||
|
OutputPath string
|
||||||
server.Perm
|
server.Perm
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,10 +109,12 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa
|
|||||||
t := time.Now()
|
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)
|
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")
|
log.Printf("Opening output file")
|
||||||
encryptedFile, err := os.Create(encrypted_filename)
|
encryptedFile, err := os.Create(encrypted_file_path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error: %v", err)
|
log.Printf("Error: %v", err)
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -147,11 +151,12 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa
|
|||||||
|
|
||||||
type ForwarderDriverFactory struct {
|
type ForwarderDriverFactory struct {
|
||||||
RecipientKey *crypto.Key
|
RecipientKey *crypto.Key
|
||||||
|
OutputPath string
|
||||||
server.Perm
|
server.Perm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory *ForwarderDriverFactory) NewDriver() (server.Driver, error) {
|
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")
|
host = flag.String("host", "localhost", "Host")
|
||||||
passiveports = flag.String("passiveports", "2130-2134", "Passive ports")
|
passiveports = flag.String("passiveports", "2130-2134", "Passive ports")
|
||||||
gpgkey_path = flag.String("gpgkey", "", "File of the public GPG key to encrypt files to")
|
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()
|
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 == "" {
|
if *gpgkey_path == "" {
|
||||||
log.Fatalf("Specify path to GPG key with -gpgkey")
|
log.Fatalf("Specify path to GPG key with -gpgkey")
|
||||||
}
|
}
|
||||||
@ -190,6 +204,7 @@ func main() {
|
|||||||
|
|
||||||
factory := &ForwarderDriverFactory{
|
factory := &ForwarderDriverFactory{
|
||||||
RecipientKey: gpgkey,
|
RecipientKey: gpgkey,
|
||||||
|
OutputPath: absolute_output_path,
|
||||||
Perm: server.NewSimplePerm("user","group"),
|
Perm: server.NewSimplePerm("user","group"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user