mirror of
https://github.com/donl/gPanel.git
synced 2026-05-29 06:12:29 -06:00
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
// Package webhost handles the logic of the webhosting panel
|
|
package webhost
|
|
|
|
import (
|
|
"bufio"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/Ennovar/gPanel/pkg/logging"
|
|
"github.com/Ennovar/gPanel/pkg/routing"
|
|
)
|
|
|
|
type PrivateHost struct {
|
|
Auth int
|
|
Directory string
|
|
}
|
|
|
|
// NewPrivateHost returns a new PrivateHost type.
|
|
func NewPrivateHost() PrivateHost {
|
|
return PrivateHost{
|
|
Auth: 1,
|
|
Directory: "document_roots/webhost/",
|
|
}
|
|
}
|
|
|
|
func (priv *PrivateHost) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|
path := req.URL.Path[1:]
|
|
path = (priv.Directory + path)
|
|
|
|
if priv.Auth != 1 {
|
|
routing.HttpThrowStatus(404, w)
|
|
logging.Console(logging.PRIVATE_PREFIX, logging.NORMAL_LOG, "Path \""+path+"\" rendered a 401 error.")
|
|
} else {
|
|
f, err := os.Open(path)
|
|
|
|
if err == nil {
|
|
bufferedReader := bufio.NewReader(f)
|
|
contentType, err := routing.GetContentType(path)
|
|
|
|
if err == nil {
|
|
w.Header().Add("Content Type", contentType)
|
|
bufferedReader.WriteTo(w)
|
|
|
|
logging.Console(logging.PRIVATE_PREFIX, logging.NORMAL_LOG, "Path \""+path+"\" rendered a 200 success.")
|
|
} else {
|
|
routing.HttpThrowStatus(404, w)
|
|
logging.Console(logging.PRIVATE_PREFIX, logging.NORMAL_LOG, "Path \""+path+"\" content type could not be determined, 404 error.")
|
|
}
|
|
|
|
} else {
|
|
routing.HttpThrowStatus(404, w)
|
|
logging.Console(logging.PRIVATE_PREFIX, logging.NORMAL_LOG, "Path \""+path+"\" rendered a 404 error.")
|
|
}
|
|
|
|
}
|
|
|
|
}
|