From 7f7fce65dfdbb259ab4d39eff3da820218cc4f67 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Mon, 19 Aug 2019 21:43:01 -0400 Subject: [PATCH 1/3] fixing some remote stuff --- sftp.go | 13 +++---------- ssh.go | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/sftp.go b/sftp.go index 26b1abe..d0cbc64 100644 --- a/sftp.go +++ b/sftp.go @@ -3,20 +3,18 @@ package main import ( "fmt" "os" - "time" "github.com/pkg/sftp" "golang.org/x/crypto/ssh" ) var ( - dstPath string = "/root/" + dstPath string = "/home/wyatt/" srcPath string = "/var/log/" - filename string = "dmesg" + filename string = "dpkg.log" ) func getFile(client *ssh.Client) { - t := time.Now() sftp, err := sftp.NewClient(client) if err != nil { @@ -33,8 +31,7 @@ func getFile(client *ssh.Client) { defer srcFile.Close() - timeResult := timeToString(t) - dstFile, err := os.Create(dstPath + filename + timeResult) + dstFile, err := os.Create(dstPath + filename) if err != nil { fmt.Errorf("FUCK") @@ -44,7 +41,3 @@ func getFile(client *ssh.Client) { srcFile.WriteTo(dstFile) } - -func timeToString(currentTime time.Time) string { - return currentTime.String() -} diff --git a/ssh.go b/ssh.go index d640448..ed7f553 100644 --- a/ssh.go +++ b/ssh.go @@ -96,7 +96,7 @@ func (s SSHConnection) executeSFTP(execute SSHClients) SSHSFTP { // TODO: this is just a placeholder, change to the actual tarring executable getFile(j) - err := gzipit("/root/"+filename, ".") + err := gzipit("/home/wyatt/"+filename, ".") if err != nil { fmt.Errorf("Cannot gzip file(s)", err) From fdb39506705f2108cbcbdbd2bad8d10d1d94ba75 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Mon, 19 Aug 2019 21:43:26 -0400 Subject: [PATCH 2/3] added string file i feel there be many more ToString functions in the future --- string.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 string.go diff --git a/string.go b/string.go new file mode 100644 index 0000000..aa937e3 --- /dev/null +++ b/string.go @@ -0,0 +1,7 @@ +package main + +import "time" + +func timeToString(currentTime time.Time) string { + return currentTime.String() +} From 9683e884644b18a4cee858f8318fce5777fec179 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Mon, 19 Aug 2019 21:46:11 -0400 Subject: [PATCH 3/3] i got logs! in a gzip file! more to come later --- .gitignore | 4 +++- main.go | 4 ++-- tar.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 9133085..c938d89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ config.yaml .vscode/ -vendor/ \ No newline at end of file +vendor/ +*.log +*.tar.gz \ No newline at end of file diff --git a/main.go b/main.go index 294d103..eeca9d1 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,6 @@ package main -import "fmt" +import "log" func main() { config := initializeConfig("config.yaml") @@ -8,5 +8,5 @@ func main() { clientConns := sshConn.dialConnection(sshConfig) _ = sshConn.openSession(clientConns) success := sshConn.executeSFTP(clientConns) - fmt.Println(success) + log.Println(success) } diff --git a/tar.go b/tar.go index d727416..2ca37f9 100644 --- a/tar.go +++ b/tar.go @@ -42,7 +42,7 @@ func gzipit(source string, target string) error { return err } -func ungzipit(source string, target string) { +func gunzipit(source string, target string) { reader, err := os.Open(source) if err != nil {