Skip to content

Commit

Permalink
WebDEV added TSL settings
Browse files Browse the repository at this point in the history
  • Loading branch information
StarmanMartin committed Jun 17, 2022
1 parent 23eac9d commit 0f6886f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/testDir/
/args.json
/args.json.bck
/193.196.55.54.crt
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ the subdirectory is sent to a remote WebDAV server at <CMD arg -dst>.

**Important** this project has to be compiled with go version 1.10.8. Otherwise, it cannot be guaranteed to run on Win XP.

**Important** This project uses the WebDAV protocol to transfer data. Therefore, the project *https://github.com/studio-b12/gowebdav* is used. In order to be compatible to go v1.10.8 the release https://github.com/studio-b12/gowebdav/releases/tag/5 has been used.

## Usage

efw -duration &lt;integer&gt; -src &lt;folder&gt; -dst &lt;url&gt;/ -user &lt;username&gt; -pass &lt;password&gt; [-zip]


-crt [string]
Path to server TLS certificate. Only needed if the server has a self signed certificate.

-duration [int]
Duration in seconds, i.e., how long a file must
not be changed before sent. (default 300)
Expand Down
Binary file modified bin/efw_linux64
Binary file not shown.
Binary file modified bin/efw_win386.exe
Binary file not shown.
Binary file modified bin/efw_win64.exe
Binary file not shown.
Binary file modified bin/efw_winAMD64.exe
Binary file not shown.
13 changes: 7 additions & 6 deletions cmd_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
)

type Args struct {
src, user, pass string
dst url.URL
duration time.Duration
zipped bool
src, user, pass, crt string
dst url.URL
duration time.Duration
zipped bool
}

// GetCmdArgs Get/Parse command line arguments manager
func GetCmdArgs() Args {
var fp, dst, user, pass string
var fp, dst, user, pass, crt string
var duration int
var zipped bool

Expand All @@ -25,6 +25,7 @@ func GetCmdArgs() Args {
flag.StringVar(&user, "user", "", "WebDAV user")
flag.StringVar(&pass, "pass", "", "WebDAV Password")
flag.IntVar(&duration, "duration", 300, "Duration in seconds, i.e., how long a file must not be changed before sent.")
flag.StringVar(&crt, "crt", "", "Path to server TLS certificate. Only needed if the server has a self signed certificate.")
/// Only considered if result are stored in a folder.
/// If zipped is set the result folder will be transferred as zip file
flag.BoolVar(&zipped, "zip", false, "Only considered if result are stored in a folder. If zipped is set the result folder will be transferred as zip file.")
Expand All @@ -42,6 +43,6 @@ func GetCmdArgs() Args {
log.Fatal(err)
}

return Args{src: fp, dst: *u, user: user, pass: pass, duration: time.Duration(duration) * time.Second, zipped: zipped}
return Args{src: fp, dst: *u, user: user, pass: pass, crt: crt, duration: time.Duration(duration) * time.Second, zipped: zipped}

}
34 changes: 33 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package main

import (
"crypto/tls"
"crypto/x509"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"time"
)
Expand All @@ -11,6 +15,7 @@ var (
InfoLogger *log.Logger
ErrorLogger *log.Logger
args Args
tr *http.Transport
)

// init initializes the logger and parses CMD args.
Expand All @@ -25,6 +30,33 @@ func init() {

InfoLogger = log.New(mw, "\rINFO: ", log.Ldate|log.Ltime|log.Lshortfile)
ErrorLogger = log.New(mw, "\rERROR: ", log.Ldate|log.Ltime|log.Lshortfile)

// Get the SystemCertPool, continue with an empty pool on error
rootCAs, _ := x509.SystemCertPool()
if rootCAs == nil {
rootCAs = x509.NewCertPool()
}

// Read in the cert file
if len(args.crt) > 0 {
certs, err := ioutil.ReadFile(args.crt)
if err != nil {
ErrorLogger.Fatalf("Failed to append %q to RootCAs: %v", args.crt, err)
}

// Append our cert to the system pool
if ok := rootCAs.AppendCertsFromPEM(certs); !ok {
ErrorLogger.Println("No certs appended, using system certs only")
}
}

// Trust the augmented cert pool in our client
config := &tls.Config{
InsecureSkipVerify: false,
RootCAs: rootCAs,
}

tr = &http.Transport{TLSClientConfig: config}
}

// main starts the ELN file watcher. See README for more information.
Expand All @@ -40,7 +72,7 @@ func main() {
done_files := make(chan string, 20)
// For potential (not jet implemented quit conditions)
quit := make(chan int)
InfoLogger.Printf("\n-----------------------------\nCMD Args:\n dst=%s,\n src=%s,\n duration=%d sec.,\n user=%s,\n zip=%t\n-----------------------------\n", args.dst.String(), args.src, int(args.duration.Seconds()), args.user, args.zipped)
InfoLogger.Printf("\n-----------------------------\nCMD Args:\n dst=%s,\n src=%s,\n duration=%d sec.,\n user=%s,\n zip=%t,\n crt= %s \n-----------------------------\n", args.dst.String(), args.src, int(args.duration.Seconds()), args.user, args.zipped, args.crt)
pm := newProcessManager(&args, done_files)
go pm.doWork(quit)
tm := newTransferManager(&args, done_files)
Expand Down
4 changes: 2 additions & 2 deletions transfer_manager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/studio-b12/gowebdav"
"github.com/StarmanMartin/gowebdav"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -78,7 +78,7 @@ func (m *TransferManager) send_file(path_to_file string, _ os.FileInfo) error {
user := m.args.user
password := m.args.pass

c := gowebdav.NewClient(m.args.dst.String(), user, password)
c := gowebdav.NewClient(m.args.dst.String(), user, password, tr)
if err := c.Connect(); err != nil {
return err
}
Expand Down

0 comments on commit 0f6886f

Please sign in to comment.