Skip to content

Commit

Permalink
WebDEV updaded TSL settings
Browse files Browse the repository at this point in the history
release v1
  • Loading branch information
StarmanMartin committed Jul 27, 2022
1 parent 0f6886f commit 63865be
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/args.json
/args.json.bck
/193.196.55.54.crt
/server.crt
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.
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
InfoLogger *log.Logger
ErrorLogger *log.Logger
args Args
tr *http.Transport
tr *http.Transport = nil
)

// init initializes the logger and parses CMD args.
Expand All @@ -31,14 +31,15 @@ func init() {
InfoLogger = log.New(mw, "\rINFO: ", log.Ldate|log.Ltime|log.Lshortfile)
ErrorLogger = log.New(mw, "\rERROR: ", log.Ldate|log.Ltime|log.Lshortfile)

// Read in the cert file

isCert := len(args.crt) > 0
// 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 {
if isCert {
certs, err := ioutil.ReadFile(args.crt)
if err != nil {
ErrorLogger.Fatalf("Failed to append %q to RootCAs: %v", args.crt, err)
Expand All @@ -52,11 +53,12 @@ func init() {

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

tr = &http.Transport{TLSClientConfig: config}

}

// main starts the ELN file watcher. See README for more information.
Expand All @@ -76,6 +78,10 @@ func main() {
pm := newProcessManager(&args, done_files)
go pm.doWork(quit)
tm := newTransferManager(&args, done_files)
if _, err := tm.connect_to_server(); err != nil {
ErrorLogger.Println("Error connecting: ", err)
log.Fatal(err)
}
go tm.doWork(quit)

for {
Expand Down
19 changes: 15 additions & 4 deletions transfer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
)

// TransferManager reacts on the channel done_files.
Expand Down Expand Up @@ -71,15 +72,25 @@ func (m *TransferManager) doWork(quit chan int) {
}
}

// send_file sends a file via WebDAV
func (m *TransferManager) send_file(path_to_file string, _ os.FileInfo) error {
var webdavFilePath, urlPathDir string

func (m *TransferManager) connect_to_server() (*gowebdav.Client, error) {
user := m.args.user
password := m.args.pass

c := gowebdav.NewClient(m.args.dst.String(), user, password, tr)
c.SetTimeout(5 * time.Second)
if err := c.Connect(); err != nil {
return nil, err
}

return c, nil
}

// send_file sends a file via WebDAV
func (m *TransferManager) send_file(path_to_file string, _ os.FileInfo) error {
var webdavFilePath, urlPathDir string

c, err := m.connect_to_server()
if err != nil {
return err
}
if relpath, err := filepath.Rel(m.args.src, path_to_file); err == nil {
Expand Down

0 comments on commit 63865be

Please sign in to comment.