support different method to get hostaddr

This commit is contained in:
r0n1n7an 2023-12-11 10:30:43 +08:00
parent af9d0eb6a5
commit 0cd47265df
4 changed files with 15 additions and 1 deletions

Binary file not shown.

View File

@ -345,7 +345,18 @@ func handleSetUutInfo(w http.ResponseWriter, r *http.Request) {
return return
} }
host := strings.Split(r.Host, ":")[0] var err error
host := ""
if cfg.Settings.HostMode == 0 {
host = strings.Split(r.Host, ":")[0]
}
if cfg.Settings.HostMode == 1 {
host, err = os.Hostname()
if err != nil {
host = "hostname"
}
}
addr := strings.Split(r.RemoteAddr, ":")[0] addr := strings.Split(r.RemoteAddr, ":")[0]
uri := r.RequestURI uri := r.RequestURI
rst := map[string]string{"RESULT": ""} rst := map[string]string{"RESULT": ""}

View File

@ -1,6 +1,8 @@
Settings: Settings:
ListenPort: 9000 ListenPort: 9000
HookScript: APIHOOK HookScript: APIHOOK
# AddrMode: 0=IP Address; 1=Hostname
AddrMode: 1
ParamCheck: false ParamCheck: false
LogRequest: true LogRequest: true
LogResponse: false LogResponse: false

View File

@ -8,6 +8,7 @@ type Cfg struct {
type Settings struct { type Settings struct {
ListenPort string `yaml:"ListenPort"` ListenPort string `yaml:"ListenPort"`
HookScript string `yaml:"HookScript"` HookScript string `yaml:"HookScript"`
HostMode int `yaml:"HostMode"`
ParamCheck bool `yaml:"ParamCheck"` ParamCheck bool `yaml:"ParamCheck"`
LogRequest bool `yaml:"LogRequest"` LogRequest bool `yaml:"LogRequest"`
LogResponse bool `yaml:"LogResponse"` LogResponse bool `yaml:"LogResponse"`