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. 25
      config.json
  5. 1
      go.mod
  6. 2
      go.sum
  7. 0
      internal/Domains/domains.go
  8. 74
      shield.go
  9. 3
      static/domains.html

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

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

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

@ -3,12 +3,29 @@
{
"Email": "defadm@daydev.org",
"Password": "siconmas",
"JWTHash": "",
"CreatedDate": "2022-July-13"
"Cookie": "MTY2NzIyMTEzN3xZTW9jS3FfcjJodHdDcEZZMm5WWS1NR1gzTnZUMmpQTmRMeU1NZ3B3MURQVFNJaXhvMUhJUTlfa2RiQzJUR1dPY25wNmRYODFfSjBQWXdid0RMTHBLZW1QZ2w1M2h2ZU5vZVpVYVlZYXx2qdnWNB1WFFqbCG6onfVbVhiWLGYkMGzfyeRVsfKGjw==",
"CreatedDate": "2022-September-15"
}
],
"Names": {
"Domains": null
"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"
}
],
"Debug": false
}

@ -6,4 +6,5 @@ require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/gorilla/mux v1.8.0
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/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/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 (
"fmt"
"log"
"net"
"net/http"
"net/http/httputil"
"os"
"runtime"
"time"
management "github.com/cr3a70r/shield/Management"
proxy "github.com/cr3a70r/shield/Proxy"
"github.com/cr3a70r/shield/Utils"
"github.com/xlab/closer"
)
func main() {
@ -17,28 +25,70 @@ func main() {
}
defer logFile.Close()
/*
proxyLog, err := os.OpenFile("proxy.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
closer.Bind(cleanup)
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,
}
go func() {
if err := proxysrv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
logger.PrintError(err, map[string]string{
"err": "failed to start proxy server",
})
}
}()
defer proxyLog.Close()
management.Settings.Initialize()
fmt.Println(runtime.NumGoroutine())
go management.StartWebserver("0.0.0.0:8080")
closer.Hold()
}
func cleanup() {
fmt.Println("Closing Application")
}
//proxy
func workingProxyForDomain(logger *Utils.Logger, domain string, realServer string, port string) *proxy.ReverseProxy {
transport := &http.Transport{
DialContext: (&net.Dialer{
Timeout: 5 * time.Second,
}).DialContext,
}
*/
management.Settings.Initialize()
conf := &proxy.Config{
Path: domain,
Host: realServer,
Override: proxy.Override{},
}
management.StartWebserver("0.0.0.0:8080")
}
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"
func cleanup() {
fmt.Println("Closing Application")
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 = ''
for (var i = 0; i<result.length; i++) {
content += '<th scope="row">' + i + "</th>"
content += '<tr>'
content += '<td>'
@ -123,6 +123,7 @@ $.ajax({
content += '</tr>'
}
console.log(content)
$('#Domains tbody').html(content)

Loading…
Cancel
Save