Staged changes after testing PoC

main
Evgeny Kovalev 2 years ago
parent 1bf61dd7ce
commit f0acc77a4b
  1. 3
      Management/management.go
  2. 3
      Management/webserver.go
  3. 2
      Proxy/proxy.go
  4. 27
      config.json
  5. 1
      go.mod
  6. 2
      go.sum
  7. 0
      internal/Domains/domains.go
  8. 76
      shield.go
  9. 3
      static/domains.html

@ -9,9 +9,8 @@ import (
"time" "time"
"domains"
"github.com/asaskevich/govalidator" "github.com/asaskevich/govalidator"
domains "github.com/cr3a70r/shield/internal/Domains"
) )
var Settings T_Management var Settings T_Management

@ -2,7 +2,6 @@ package management
import ( import (
"bytes" "bytes"
"domains"
"encoding/json" "encoding/json"
"log" "log"
"net/http" "net/http"
@ -14,6 +13,8 @@ import (
"github.com/cr3a70r/shield/Utils" "github.com/cr3a70r/shield/Utils"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/securecookie" "github.com/gorilla/securecookie"
domains "github.com/cr3a70r/shield/internal/Domains"
) )
var hashKey = []byte("ckjstkldx-rlkjcmskl-rdlskjtmd") var hashKey = []byte("ckjstkldx-rlkjcmskl-rdlskjtmd")

@ -50,7 +50,7 @@ func NewProxy(urlString string, transport http.RoundTripper, director *httputil.
p := httputil.NewSingleHostReverseProxy(providedUrl) p := httputil.NewSingleHostReverseProxy(providedUrl)
p.Transport = transport p.Transport = transport
p.Director = director.Director p.Director = director.Director
p.ModifyResponse = UpdateResponse //p.ModifyResponse = UpdateResponse
return &ReverseProxy{ return &ReverseProxy{
url: providedUrl, url: providedUrl,

@ -3,12 +3,29 @@
{ {
"Email": "defadm@daydev.org", "Email": "defadm@daydev.org",
"Password": "siconmas", "Password": "siconmas",
"JWTHash": "", "Cookie": "MTY2NzIyMTEzN3xZTW9jS3FfcjJodHdDcEZZMm5WWS1NR1gzTnZUMmpQTmRMeU1NZ3B3MURQVFNJaXhvMUhJUTlfa2RiQzJUR1dPY25wNmRYODFfSjBQWXdid0RMTHBLZW1QZ2w1M2h2ZU5vZVpVYVlZYXx2qdnWNB1WFFqbCG6onfVbVhiWLGYkMGzfyeRVsfKGjw==",
"CreatedDate": "2022-July-13" "CreatedDate": "2022-September-15"
}
],
"Names": [
{
"DomainName": "test.com",
"RealServer": "10.10.50.5",
"RealPort": "443",
"Satus": "Onboarding"
},
{
"DomainName": "test.dev.corp.daydev.org",
"RealServer": "10.10.20.40",
"RealPort": "9090",
"Satus": "Onboarding"
},
{
"DomainName": "jenkins.dev.corp.daydev.org",
"RealServer": "10.10.101",
"RealPort": "65300",
"Satus": "Onboarding"
} }
], ],
"Names": {
"Domains": null
},
"Debug": false "Debug": false
} }

@ -6,4 +6,5 @@ require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/gorilla/securecookie v1.1.1 github.com/gorilla/securecookie v1.1.1
github.com/xlab/closer v1.1.0
) )

@ -4,3 +4,5 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/xlab/closer v1.1.0 h1:yrDiOXjd/B7pZ3lZkl/EZ1gWrR2M2N5XpBnixynm4mc=
github.com/xlab/closer v1.1.0/go.mod h1:Ff8YcUPbn5jju6nClrMCmJHQABM0S/obEK0za/1yVMk=

@ -3,9 +3,17 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"net"
"net/http"
"net/http/httputil"
"os" "os"
"runtime"
"time"
management "github.com/cr3a70r/shield/Management" management "github.com/cr3a70r/shield/Management"
proxy "github.com/cr3a70r/shield/Proxy"
"github.com/cr3a70r/shield/Utils"
"github.com/xlab/closer"
) )
func main() { func main() {
@ -17,28 +25,70 @@ func main() {
} }
defer logFile.Close() defer logFile.Close()
/* closer.Bind(cleanup)
proxyLog, err := os.OpenFile("proxy.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer proxyLog.Close() logger := Utils.New(os.Stdout, Utils.LevelInfo)
test := workingProxyForDomain(logger, "test.dev.corp.daydev.org", "10.10.20.40", "9090")
http.HandleFunc("/", test.Handler)
proxysrv := &http.Server{
Addr: ":8085",
Handler: nil,
}
//proxy go func() {
transport := &http.Transport{ if err := proxysrv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
DialContext: (&net.Dialer{ logger.PrintError(err, map[string]string{
Timeout: 5 * time.Second, "err": "failed to start proxy server",
}).DialContext, })
} }
*/ }()
management.Settings.Initialize() management.Settings.Initialize()
management.StartWebserver("0.0.0.0:8080") fmt.Println(runtime.NumGoroutine())
go management.StartWebserver("0.0.0.0:8080")
closer.Hold()
} }
func cleanup() { func cleanup() {
fmt.Println("Closing Application") fmt.Println("Closing Application")
} }
func workingProxyForDomain(logger *Utils.Logger, domain string, realServer string, port string) *proxy.ReverseProxy {
transport := &http.Transport{
DialContext: (&net.Dialer{
Timeout: 5 * time.Second,
}).DialContext,
}
conf := &proxy.Config{
Path: domain,
Host: realServer,
Override: proxy.Override{},
}
director := &httputil.ReverseProxy{Director: func(req *http.Request) {
originHost := conf.Host
logger.PrintInfo("provided host", map[string]string{
"host": originHost,
})
req.Header.Add("X-Forwarded-Host", req.Host)
req.Header.Add("X-Origin-Host", originHost)
req.Header.Add("Accept-Encoding", "")
req.Host = originHost
req.URL.Host = originHost
req.URL.Scheme = "http"
if conf.Override.Header != "" && conf.Override.Match != "" {
if req.Header.Get(conf.Override.Header) == conf.Override.Match {
req.URL.Path = conf.Override.Path
}
}
}}
prv := proxy.NewProxy(conf.Host, transport, director, logger, port)
return prv
}

@ -101,7 +101,7 @@ $.ajax({
} }
var content = '' var content = ''
for (var i = 0; i<result.length; i++) { for (var i = 0; i<result.length; i++) {
content += '<th scope="row">' + i + "</th>"
content += '<tr>' content += '<tr>'
content += '<td>' content += '<td>'
@ -123,6 +123,7 @@ $.ajax({
content += '</tr>' content += '</tr>'
} }
console.log(content)
$('#Domains tbody').html(content) $('#Domains tbody').html(content)

Loading…
Cancel
Save