some fixes
This commit is contained in:
parent
9e68b46346
commit
fa65b381a4
7 changed files with 37 additions and 26 deletions
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.giftfish.de/ston1th/godrop/v2"
|
||||||
"git.giftfish.de/ston1th/keyctl/pkg/api/types"
|
"git.giftfish.de/ston1th/keyctl/pkg/api/types"
|
||||||
serverv1 "git.giftfish.de/ston1th/keyctl/pkg/api/v1/server"
|
serverv1 "git.giftfish.de/ston1th/keyctl/pkg/api/v1/server"
|
||||||
"git.giftfish.de/ston1th/keyctl/pkg/db"
|
"git.giftfish.de/ston1th/keyctl/pkg/db"
|
||||||
|
|
@ -86,6 +87,14 @@ func NewServer(log logr.Logger, listen, socket string, db *db.DB) (*Server, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func unixListener(socket string) (sock net.Listener, err error) {
|
func unixListener(socket string) (sock net.Listener, err error) {
|
||||||
|
err = godrop.Unveil(socket, "rwc")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = godrop.UnveilBlock()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
sock, err = net.Listen("unix", socket)
|
sock, err = net.Listen("unix", socket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
10
pkg/api/types/clientip.go
Normal file
10
pkg/api/types/clientip.go
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
// Copyright (C) 2023 Marius Schellenberger
|
||||||
|
|
||||||
|
//go:build !openbsd
|
||||||
|
// +build !openbsd
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
func clientip(ip string) string {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
13
pkg/api/types/clientip_openbsd.go
Normal file
13
pkg/api/types/clientip_openbsd.go
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright (C) 2023 Marius Schellenberger
|
||||||
|
|
||||||
|
//go:build openbsd
|
||||||
|
// +build openbsd
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
func clientip(ip string) string {
|
||||||
|
if ip == "" {
|
||||||
|
return "@"
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ package types
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
|
|
@ -28,6 +27,7 @@ func NewContext(w http.ResponseWriter, r *http.Request, data *ContextData, log l
|
||||||
Response: w,
|
Response: w,
|
||||||
Data: data,
|
Data: data,
|
||||||
Log: log,
|
Log: log,
|
||||||
|
ip: clientip(r.RemoteAddr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,17 +70,8 @@ func (c *Context) Form(name string) string {
|
||||||
return c.Request.FormValue(name)
|
return c.Request.FormValue(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) ClientIP() (host string) {
|
func (c *Context) ClientIP() string {
|
||||||
host = c.Request.RemoteAddr
|
return c.ip
|
||||||
if host == "@" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if c.ip != "" {
|
|
||||||
return c.ip
|
|
||||||
}
|
|
||||||
host, _, _ = net.SplitHostPort(host)
|
|
||||||
c.ip = host
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Var returns the given url variable
|
// Var returns the given url variable
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,6 @@ func local(h types.CtxHandler) types.CtxHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func healthzHandler(ctx *types.Context) {
|
|
||||||
ctx.OK()
|
|
||||||
}
|
|
||||||
|
|
||||||
func newHandler(ctx *types.Context) {
|
func newHandler(ctx *types.Context) {
|
||||||
if ctx.Method() == "POST" {
|
if ctx.Method() == "POST" {
|
||||||
b, err := ctx.ReadBody()
|
b, err := ctx.ReadBody()
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
healthz = "/healthz"
|
|
||||||
keyID = schema.KeyPath + core.IDRoute
|
keyID = schema.KeyPath + core.IDRoute
|
||||||
keyReqID = schema.KeyPath + core.IDRoute + core.AIDRoute
|
keyReqID = schema.KeyPath + core.IDRoute + core.AIDRoute
|
||||||
reqID = schema.ReqPath + core.IDRoute
|
reqID = schema.ReqPath + core.IDRoute
|
||||||
)
|
)
|
||||||
|
|
||||||
var Routes = []types.Route{
|
var Routes = []types.Route{
|
||||||
{
|
|
||||||
Path: healthz,
|
|
||||||
Handler: healthzHandler,
|
|
||||||
Methods: []string{"GET"},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Path: schema.KeyPath,
|
Path: schema.KeyPath,
|
||||||
Handler: local(keyListHandler),
|
Handler: local(keyListHandler),
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ cat <<'EOF'> /etc/rc.d/keyctl
|
||||||
|
|
||||||
daemon="/usr/local/sbin/keyctl"
|
daemon="/usr/local/sbin/keyctl"
|
||||||
daemon_user="_keyctl"
|
daemon_user="_keyctl"
|
||||||
|
daemon_logger="daemon.info"
|
||||||
|
|
||||||
. /etc/rc.d/rc.subr
|
. /etc/rc.d/rc.subr
|
||||||
|
|
||||||
|
|
@ -12,14 +13,11 @@ pexp=".*${daemon}.*"
|
||||||
rc_bg=YES
|
rc_bg=YES
|
||||||
rc_reload=NO
|
rc_reload=NO
|
||||||
|
|
||||||
rc_start() {
|
|
||||||
rc_exec "${daemon} ${daemon_flags}"
|
|
||||||
}
|
|
||||||
|
|
||||||
rc_cmd $1
|
rc_cmd $1
|
||||||
EOF
|
EOF
|
||||||
chmod 555 /etc/rc.d/keyctl
|
chmod 555 /etc/rc.d/keyctl
|
||||||
rcctl enable keyctl
|
rcctl enable keyctl
|
||||||
|
rcctl set keyctl flags server
|
||||||
|
|
||||||
mkdir /var/keyctl
|
mkdir /var/keyctl
|
||||||
groupadd _keyctl
|
groupadd _keyctl
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue