diff --git a/pkg/api/domain/link.go b/pkg/api/domain/link.go
index 2462345..ca56b90 100644
--- a/pkg/api/domain/link.go
+++ b/pkg/api/domain/link.go
@@ -8,7 +8,7 @@ import (
"encoding/json"
)
-func Link(res http.ResponseWriter, req *http.Request, logger *log.Logger) bool {
+func Link(res http.ResponseWriter, req *http.Request, logger *log.Logger, PublicPort int) bool {
if req.Method != "POST" {
logger.Println(req.URL.Path + "::" + req.Method + "::" + strconv.Itoa(http.StatusMethodNotAllowed) + "::" + http.StatusText(http.StatusMethodNotAllowed))
http.Error(res, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
@@ -37,6 +37,7 @@ func Link(res http.ResponseWriter, req *http.Request, logger *log.Logger) bool {
var domainDatabaseData database.Struct_Domain
domainDatabaseData.BundleName = linkDomainReqData.Bundle
+ domainDatabaseData.PublicPort = PublicPort
err = ds.Put(database.BUCKET_DOMAINS, []byte(linkDomainReqData.Domain), domainDatabaseData)
if err != nil {
diff --git a/pkg/database/domains.go b/pkg/database/domains.go
index 2dedfc7..eeb0965 100644
--- a/pkg/database/domains.go
+++ b/pkg/database/domains.go
@@ -7,10 +7,11 @@ import (
type Struct_Domain struct {
BundleName string `json:"name"`
+ PublicPort int `json:"port"`
}
-func (ds *Datastore) ListDomains(bundle string) (map[string]string, error) {
- filtered := make(map[string]string)
+func (ds *Datastore) ListDomains(bundle string) (map[string]Struct_Domain, error) {
+ filtered := make(map[string]Struct_Domain)
var holder Struct_Domain
ds.handle.View(func(tx *bolt.Tx) error {
@@ -21,7 +22,7 @@ func (ds *Datastore) ListDomains(bundle string) (map[string]string, error) {
json.Unmarshal(v, &holder)
if bundle == "*" || holder.BundleName == bundle {
- filtered[holder.BundleName] = string(k)
+ filtered[string(k)] = holder
}
}
diff --git a/pkg/gpaccount/apihandler.go b/pkg/gpaccount/apihandler.go
index bbeb324..55484cb 100644
--- a/pkg/gpaccount/apihandler.go
+++ b/pkg/gpaccount/apihandler.go
@@ -62,7 +62,7 @@ func (con *Controller) apiHandler(res http.ResponseWriter, req *http.Request) (b
case "/domain/list":
return true, domain.List(res, req, con.APILogger)
case "/domain/link":
- return true, domain.Link(res, req, con.APILogger)
+ return true, domain.Link(res, req, con.APILogger, con.Public.Port)
case "/domain/unlink":
return true, domain.Unlink(res, req, con.APILogger)
default:
diff --git a/pkg/router/router.go b/pkg/router/router.go
index 39f76e8..b39ccf9 100644
--- a/pkg/router/router.go
+++ b/pkg/router/router.go
@@ -5,6 +5,7 @@ import (
"strconv"
"time"
"github.com/Ennovar/gPanel/pkg/database"
+ "net/url"
)
type Router struct {
@@ -33,7 +34,9 @@ func (r *Router) Start() {
go server.ListenAndServe()
}
-func (r *Router) Route(domain string, res http.ResponseWriter) {
+func (r *Router) ServeHTTP(res http.ResponseWriter, req *http.Request) {
+ domain := req.Host
+
ds, err := database.Open("server/" + database.DB_DOMAINS)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
@@ -48,12 +51,12 @@ func (r *Router) Route(domain string, res http.ResponseWriter) {
return
}
+ cURL, err := url.Parse("localhost:"+strconv.Itoa(client.PublicPort)+"/"+req.URL.Path[1:])
+ if err != nil {
+ http.Error(res, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
res.WriteHeader(http.StatusOK)
- res.Write([]byte(domain + " is linked to bundle " + client.BundleName))
-}
-
-func (r *Router) ServeHTTP(res http.ResponseWriter, req *http.Request) {
- d := req.Host
-
- r.Route(d, res)
+ res.Write([]byte(cURL.String()))
}
\ No newline at end of file
diff --git a/server/document_root/gPanel.html b/server/document_root/gPanel.html
index dc3c9ac..1ac812d 100644
--- a/server/document_root/gPanel.html
+++ b/server/document_root/gPanel.html
@@ -409,7 +409,7 @@