-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hector Maldonado
authored and
Hector Maldonado
committed
May 20, 2018
0 parents
commit 84e46cf
Showing
8 changed files
with
693 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
|
||
vendor | ||
|
||
# Created by https://www.gitignore.io/api/go,vim,jetbrains,visualstudiocode | ||
|
||
### Go ### | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
### JetBrains ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff: | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.xml | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
|
||
# Gradle: | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# CMake | ||
cmake-build-debug/ | ||
|
||
# Mongo Explorer plugin: | ||
.idea/**/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Ruby plugin and RubyMine | ||
/.rakeTasks | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
### JetBrains Patch ### | ||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 | ||
|
||
# *.iml | ||
# modules.xml | ||
# .idea/misc.xml | ||
# *.ipr | ||
|
||
# Sonarlint plugin | ||
.idea/sonarlint | ||
|
||
### Vim ### | ||
# swap | ||
.sw[a-p] | ||
.*.sw[a-p] | ||
# session | ||
Session.vim | ||
# temporary | ||
.netrwhist | ||
*~ | ||
# auto-generated tag files | ||
tags | ||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
.history | ||
|
||
|
||
# End of https://www.gitignore.io/api/go,vim,jetbrains,visualstudiocode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/ThomsonReutersEikon/go-ntlm" | ||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "github.com/ThomsonReutersEikon/log4go" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"net/http/httputil" | ||
"net/url" | ||
"github.com/xynova/ntlm-reverse-proxy/ntlmssp" | ||
"github.com/spf13/viper" | ||
"fmt" | ||
"errors" | ||
) | ||
|
||
|
||
type proxyConfig struct { | ||
address string | ||
port int | ||
username string | ||
password string | ||
targetUrl *url.URL | ||
} | ||
|
||
|
||
func main() { | ||
|
||
|
||
var ( | ||
config *proxyConfig | ||
err error | ||
) | ||
|
||
if config, err = parseProxyConfig() ; err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create NTLM transport | ||
authenticator := ntlmssp.NewConnectionAuthenticator( config.username, config.password ) | ||
transport := ntlmssp.NewNtlmTransport(authenticator, ntlmssp.DefaultClient) | ||
|
||
// Create reverse proxy with NTLM transport | ||
proxy := httputil.NewSingleHostReverseProxy(config.targetUrl) | ||
proxy.Transport = transport | ||
|
||
// Start server | ||
listenAddr := fmt.Sprintf("%s:%d",config.address,config.port) | ||
log.Printf("Starting unencrpyed listener on %s:",listenAddr) | ||
log.Fatal(http.ListenAndServe( listenAddr, http.Handler(proxy))) | ||
} | ||
|
||
|
||
func init(){ | ||
viper.SetDefault("targetUrl","") | ||
viper.SetDefault("port","8080") | ||
viper.SetDefault("address","localhost") | ||
viper.SetDefault("username","") | ||
viper.SetDefault("password","") | ||
viper.AutomaticEnv() | ||
} | ||
|
||
|
||
|
||
func parseProxyConfig() (*proxyConfig, error){ | ||
var ( | ||
address = viper.GetString("address") | ||
port = viper.GetInt("port") | ||
username = viper.GetString("username") | ||
password = viper.GetString("password") | ||
targetUrl = viper.GetString("targetUrl") | ||
uri *url.URL | ||
err error | ||
) | ||
|
||
|
||
|
||
if len(targetUrl) == 0 { | ||
return nil,errors.New("targetUrl cannot be empty") | ||
} | ||
|
||
if len(username) == 0 { | ||
return nil,errors.New("username cannot be empty") | ||
} | ||
|
||
if len(password) == 0 { | ||
return nil,errors.New("password cannot be empty") | ||
} | ||
|
||
// Configure reverse proxy | ||
if uri, err = url.ParseRequestURI(targetUrl); err != nil { | ||
return nil, err | ||
} | ||
|
||
rt := proxyConfig{ | ||
address: address, | ||
port:port, | ||
username:username, | ||
password:password, | ||
targetUrl:uri, | ||
|
||
} | ||
|
||
return &rt, nil | ||
} |
Oops, something went wrong.