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"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
"git.giftfish.de/ston1th/keyctl/pkg/api/types"
|
||||
serverv1 "git.giftfish.de/ston1th/keyctl/pkg/api/v1/server"
|
||||
"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) {
|
||||
err = godrop.Unveil(socket, "rwc")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = godrop.UnveilBlock()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sock, err = net.Listen("unix", socket)
|
||||
if err != nil {
|
||||
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 (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
|
|
@ -28,6 +27,7 @@ func NewContext(w http.ResponseWriter, r *http.Request, data *ContextData, log l
|
|||
Response: w,
|
||||
Data: data,
|
||||
Log: log,
|
||||
ip: clientip(r.RemoteAddr),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,18 +70,9 @@ func (c *Context) Form(name string) string {
|
|||
return c.Request.FormValue(name)
|
||||
}
|
||||
|
||||
func (c *Context) ClientIP() (host string) {
|
||||
host = c.Request.RemoteAddr
|
||||
if host == "@" {
|
||||
return
|
||||
}
|
||||
if c.ip != "" {
|
||||
func (c *Context) ClientIP() string {
|
||||
return c.ip
|
||||
}
|
||||
host, _, _ = net.SplitHostPort(host)
|
||||
c.ip = host
|
||||
return
|
||||
}
|
||||
|
||||
// Var returns the given url variable
|
||||
func (c *Context) Var(name string) string {
|
||||
|
|
|
|||
|
|
@ -22,10 +22,6 @@ func local(h types.CtxHandler) types.CtxHandler {
|
|||
}
|
||||
}
|
||||
|
||||
func healthzHandler(ctx *types.Context) {
|
||||
ctx.OK()
|
||||
}
|
||||
|
||||
func newHandler(ctx *types.Context) {
|
||||
if ctx.Method() == "POST" {
|
||||
b, err := ctx.ReadBody()
|
||||
|
|
|
|||
|
|
@ -9,18 +9,12 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
healthz = "/healthz"
|
||||
keyID = schema.KeyPath + core.IDRoute
|
||||
keyReqID = schema.KeyPath + core.IDRoute + core.AIDRoute
|
||||
reqID = schema.ReqPath + core.IDRoute
|
||||
)
|
||||
|
||||
var Routes = []types.Route{
|
||||
{
|
||||
Path: healthz,
|
||||
Handler: healthzHandler,
|
||||
Methods: []string{"GET"},
|
||||
},
|
||||
{
|
||||
Path: schema.KeyPath,
|
||||
Handler: local(keyListHandler),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ cat <<'EOF'> /etc/rc.d/keyctl
|
|||
|
||||
daemon="/usr/local/sbin/keyctl"
|
||||
daemon_user="_keyctl"
|
||||
daemon_logger="daemon.info"
|
||||
|
||||
. /etc/rc.d/rc.subr
|
||||
|
||||
|
|
@ -12,14 +13,11 @@ pexp=".*${daemon}.*"
|
|||
rc_bg=YES
|
||||
rc_reload=NO
|
||||
|
||||
rc_start() {
|
||||
rc_exec "${daemon} ${daemon_flags}"
|
||||
}
|
||||
|
||||
rc_cmd $1
|
||||
EOF
|
||||
chmod 555 /etc/rc.d/keyctl
|
||||
rcctl enable keyctl
|
||||
rcctl set keyctl flags server
|
||||
|
||||
mkdir /var/keyctl
|
||||
groupadd _keyctl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue