Files
go_clientinfo/server/consts.go
brent saner 9f97fcaf81 v0.2.0
ADDED:
* The ability to show both IPv4 and IPv6 addresses (if the client has
  dual-stack and either the server does as well or a separate ClientInfo
  is running on the "other" net family).
2025-12-13 04:19:05 -05:00

96 lines
2.3 KiB
Go

package server
import (
`embed`
`encoding/json`
`encoding/xml`
`html/template`
`os`
`syscall`
sysdUtil `github.com/coreos/go-systemd/util`
`github.com/goccy/go-yaml`
)
const (
convertTag string = "uaField"
prettyTag string = "renderName"
baseTitle string = "r00t^2 Client Info Revealer"
titleSep string = " || "
xmlHdrElem string = "header"
xmlHdrElemName string = "name"
xmlHdrVal string = "value"
nilUaFieldStr string = "(N/A)"
trueUaFieldStr string = "Yes"
falseUaFieldStr string = "No"
dfltIndent string = " "
httpRealHdr string = "X-ClientInfo-RealIP" // TODO: advise https://nginx.org/en/docs/http/ngx_http_realip_module.html NGINX module? Allow config for user-specified header?
)
var (
//go:embed "tpl"
tplDir embed.FS
tpl *template.Template = template.Must(
template.New("").
Funcs(
template.FuncMap{
"getTitle": getTitle,
"getIpver": getIpver,
"safeUrl": safeUrl,
},
).ParseFS(tplDir, "tpl/*.tpl"),
)
)
// Signal traps
var (
stopSigs []os.Signal = []os.Signal{
syscall.SIGQUIT,
os.Interrupt,
syscall.SIGTERM,
}
reloadSigs []os.Signal = []os.Signal{
syscall.SIGHUP,
// We also add stopSigs so we trigger the Reload loop to close. TODO.
syscall.SIGQUIT,
os.Interrupt,
syscall.SIGTERM,
}
isSystemd bool = sysdUtil.IsRunningSystemd()
)
// media/MIME types
const (
mediaJSON string = "application/json"
mediaXML string = "application/xml"
mediaYAML string = "application/yaml"
mediaHTML string = "text/html"
// TODO: plain/text? CSV? TOML?
)
var (
// mediaNoIndent covers everything (except HTML).
mediaNoIndent map[string]func(obj any) (b []byte, err error) = map[string]func(obj any) (b []byte, err error){
mediaJSON: json.Marshal,
mediaXML: xml.Marshal,
mediaYAML: yaml.Marshal,
// HTML is handled explicitly.
}
// mediaIndent only contains MIME types that support configured indents.
mediaIndent map[string]func(obj any, pfx string, indent string) (b []byte, err error) = map[string]func(obj any, pfx string, indent string) (b []byte, err error){
mediaJSON: json.MarshalIndent,
mediaXML: xml.MarshalIndent,
}
// valid MIMEs.
okAcceptMime []string = []string{
mediaJSON,
mediaXML,
mediaYAML,
mediaHTML,
}
// These are actually HTML.
htmlOverride map[string]bool = map[string]bool{
"Links": true,
}
)