update
This commit is contained in:
parent
7650951518
commit
deb6fef747
@ -10,10 +10,13 @@ reverse=/::https://www.b612.me
|
|||||||
replace=www.b612.me::127.0.0.1:9999
|
replace=www.b612.me::127.0.0.1:9999
|
||||||
inheader=Accept-Encoding::none
|
inheader=Accept-Encoding::none
|
||||||
host=b612.me
|
host=b612.me
|
||||||
|
proxyhost=www.b612.me
|
||||||
authuser=b612
|
authuser=b612
|
||||||
authpasswd=b612
|
authpasswd=b612
|
||||||
whiteip=
|
whiteip=
|
||||||
blackip=
|
blackip=
|
||||||
|
blackpath=
|
||||||
|
whitepath=
|
||||||
wanringpage=
|
wanringpage=
|
||||||
ipfiltermode=3
|
ipfiltermode=3
|
||||||
filterxforward=
|
filterxforward=
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
var remote, config string
|
var remote, config string
|
||||||
var addr, key, cert, log string
|
var addr, key, cert, log string
|
||||||
var port int
|
var port int
|
||||||
var enablessl, skipsslverify bool
|
var enablessl, skipsslverify, autogencert, allowHttpInTls bool
|
||||||
var host string
|
var host string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -25,6 +25,8 @@ func init() {
|
|||||||
Cmd.Flags().BoolVarP(&enablessl, "enable-ssl", "s", false, "启用ssl")
|
Cmd.Flags().BoolVarP(&enablessl, "enable-ssl", "s", false, "启用ssl")
|
||||||
Cmd.Flags().BoolVarP(&skipsslverify, "skil-ssl-verify", "S", false, "跳过证书验证")
|
Cmd.Flags().BoolVarP(&skipsslverify, "skil-ssl-verify", "S", false, "跳过证书验证")
|
||||||
Cmd.Flags().IntVarP(&port, "port", "p", 8080, "监听端口")
|
Cmd.Flags().IntVarP(&port, "port", "p", 8080, "监听端口")
|
||||||
|
Cmd.Flags().BoolVarP(&autogencert, "autogen-cert", "G", false, "自动生成证书,此时使用--ssl-cert和--ssl-key参数无效")
|
||||||
|
Cmd.Flags().BoolVarP(&allowHttpInTls, "allow-http-in-tls", "A", false, "允许在TLS下使用HTTP协议")
|
||||||
}
|
}
|
||||||
|
|
||||||
var Cmd = &cobra.Command{
|
var Cmd = &cobra.Command{
|
||||||
@ -69,6 +71,8 @@ var Cmd = &cobra.Command{
|
|||||||
ReverseURL: map[string]any{
|
ReverseURL: map[string]any{
|
||||||
"/": u,
|
"/": u,
|
||||||
},
|
},
|
||||||
|
AllowHTTPWithHttps: allowHttpInTls,
|
||||||
|
AutoGenerateCert: autogencert,
|
||||||
UsingSSL: enablessl,
|
UsingSSL: enablessl,
|
||||||
SkipSSLVerify: skipsslverify,
|
SkipSSLVerify: skipsslverify,
|
||||||
Key: key,
|
Key: key,
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"b612.me/starlog"
|
"b612.me/starlog"
|
||||||
"b612.me/staros/sysconf"
|
"b612.me/staros/sysconf"
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -25,6 +26,7 @@ type ReverseConfig struct {
|
|||||||
Config []*SingleReverseConfig
|
Config []*SingleReverseConfig
|
||||||
routes map[string]*SingleReverseConfig
|
routes map[string]*SingleReverseConfig
|
||||||
autogenCert bool //是否自动生成证书
|
autogenCert bool //是否自动生成证书
|
||||||
|
hostnameTlsCache map[string]*tls.Config //缓存证书
|
||||||
}
|
}
|
||||||
|
|
||||||
type SingleReverseConfig struct {
|
type SingleReverseConfig struct {
|
||||||
@ -94,6 +96,7 @@ func Parse(cfgPath string) (HttpReverseServer, error) {
|
|||||||
var ins = SingleReverseConfig{
|
var ins = SingleReverseConfig{
|
||||||
Name: v.Name,
|
Name: v.Name,
|
||||||
Host: v.Get("host"),
|
Host: v.Get("host"),
|
||||||
|
ProxyHost: v.Get("proxyhost"),
|
||||||
UsingSSL: v.Bool("enablessl"),
|
UsingSSL: v.Bool("enablessl"),
|
||||||
AllowHTTPWithHttps: v.Bool("tlsallowhttp"),
|
AllowHTTPWithHttps: v.Bool("tlsallowhttp"),
|
||||||
AutoGenerateCert: v.Bool("autogencert"),
|
AutoGenerateCert: v.Bool("autogencert"),
|
||||||
|
@ -96,7 +96,6 @@ func (h *ReverseConfig) Run() error {
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if !ppr && bp.FullPath != checkPath {
|
if !ppr && bp.FullPath != checkPath {
|
||||||
fmt.Println(bp.FullPath, checkPath)
|
|
||||||
starlog.Errorf("<%s> Path:%s is not in the write path, reject request\n", c.Name, checkPath)
|
starlog.Errorf("<%s> Path:%s is not in the write path, reject request\n", c.Name, checkPath)
|
||||||
rejectWith403(writer, request)
|
rejectWith403(writer, request)
|
||||||
return
|
return
|
||||||
@ -121,7 +120,6 @@ func (h *ReverseConfig) Run() error {
|
|||||||
FullPath: leaf.FullPath,
|
FullPath: leaf.FullPath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(leaf.Val)
|
|
||||||
if leaf == nil {
|
if leaf == nil {
|
||||||
starlog.Errorf("<%s> No Reverse Proxy Found For Path:%s\n", c.Name, request.URL.Path)
|
starlog.Errorf("<%s> No Reverse Proxy Found For Path:%s\n", c.Name, request.URL.Path)
|
||||||
writer.WriteHeader(404)
|
writer.WriteHeader(404)
|
||||||
@ -183,7 +181,6 @@ func (h *ReverseConfig) Run() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var certCache = make(map[string]tls.Certificate)
|
|
||||||
var toolCa *x509.Certificate
|
var toolCa *x509.Certificate
|
||||||
var toolCaKey any
|
var toolCaKey any
|
||||||
|
|
||||||
@ -394,11 +391,14 @@ func (h *ReverseConfig) fileHandle(dirPath, diskpath string, writer http.Respons
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *ReverseConfig) getCert(hostname string) *tls.Config {
|
func (h *ReverseConfig) getCert(hostname string) *tls.Config {
|
||||||
if h.autogenCert {
|
if tlsCfg, ok := h.hostnameTlsCache[hostname]; ok {
|
||||||
return h.autoGenCert(hostname)
|
return tlsCfg
|
||||||
}
|
}
|
||||||
c, ok := h.routes[hostname]
|
c, ok := h.routes[hostname]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
if h.autogenCert {
|
||||||
|
return h.autoGenCert(hostname)
|
||||||
|
}
|
||||||
if _, ok := h.routes[""]; ok {
|
if _, ok := h.routes[""]; ok {
|
||||||
c = h.routes[""]
|
c = h.routes[""]
|
||||||
} else {
|
} else {
|
||||||
@ -413,19 +413,25 @@ func (h *ReverseConfig) getCert(hostname string) *tls.Config {
|
|||||||
if c == nil {
|
if c == nil {
|
||||||
return &tls.Config{}
|
return &tls.Config{}
|
||||||
}
|
}
|
||||||
|
if c.AutoGenerateCert {
|
||||||
|
return h.autoGenCert(hostname)
|
||||||
|
}
|
||||||
cert, err := tls.LoadX509KeyPair(c.Cert, c.Key)
|
cert, err := tls.LoadX509KeyPair(c.Cert, c.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
starlog.Errorln("Load X509 Key Pair Error:", err)
|
starlog.Errorln("Load X509 Key Pair Error:", err)
|
||||||
return &tls.Config{}
|
return &tls.Config{}
|
||||||
}
|
}
|
||||||
return &tls.Config{
|
|
||||||
|
if h.hostnameTlsCache == nil {
|
||||||
|
h.hostnameTlsCache = make(map[string]*tls.Config)
|
||||||
|
}
|
||||||
|
h.hostnameTlsCache[hostname] = &tls.Config{
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
}
|
}
|
||||||
|
return h.hostnameTlsCache[hostname]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ReverseConfig) autoGenCert(hostname string) *tls.Config {
|
func (h *ReverseConfig) autoGenCert(hostname string) *tls.Config {
|
||||||
if cert, ok := certCache[hostname]; ok {
|
|
||||||
return &tls.Config{Certificates: []tls.Certificate{cert}}
|
|
||||||
}
|
|
||||||
if toolCa == nil {
|
if toolCa == nil {
|
||||||
toolCa, toolCaKey = utils.ToolCert("")
|
toolCa, toolCaKey = utils.ToolCert("")
|
||||||
}
|
}
|
||||||
@ -451,8 +457,11 @@ func (h *ReverseConfig) autoGenCert(hostname string) *tls.Config {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
certCache[hostname] = cert
|
if h.hostnameTlsCache == nil {
|
||||||
return &tls.Config{Certificates: []tls.Certificate{cert}}
|
h.hostnameTlsCache = make(map[string]*tls.Config)
|
||||||
|
}
|
||||||
|
h.hostnameTlsCache[hostname] = &tls.Config{Certificates: []tls.Certificate{cert}}
|
||||||
|
return h.hostnameTlsCache[hostname]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ReverseConfig) Close() error {
|
func (h *ReverseConfig) Close() error {
|
||||||
|
@ -106,6 +106,7 @@
|
|||||||
function uploadFile(file, fileUpload) {
|
function uploadFile(file, fileUpload) {
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append('victorique', file);
|
formData.append('victorique', file);
|
||||||
|
formData.append("path",window.location.pathname);
|
||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
var lastLoaded = 0;
|
var lastLoaded = 0;
|
||||||
var progressBar = fileUpload.progressBar;
|
var progressBar = fileUpload.progressBar;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user