fix error logs, add timestamp to http request logs, add back password funcs to sandbox
This commit is contained in:
parent
22c340648b
commit
ff01a1f0b1
@ -17,6 +17,7 @@ import (
|
|||||||
"Moonshark/utils/logger"
|
"Moonshark/utils/logger"
|
||||||
"Moonshark/utils/metadata"
|
"Moonshark/utils/metadata"
|
||||||
|
|
||||||
|
luajit "git.sharkk.net/Sky/LuaJIT-to-Go"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -292,9 +293,22 @@ func (s *Server) sendError(ctx *fasthttp.RequestCtx, status int, pathBytes []byt
|
|||||||
s.errorCacheMu.RLock()
|
s.errorCacheMu.RLock()
|
||||||
ctx.SetBody(s.cached500)
|
ctx.SetBody(s.cached500)
|
||||||
s.errorCacheMu.RUnlock()
|
s.errorCacheMu.RUnlock()
|
||||||
} else {
|
return
|
||||||
ctx.SetBody([]byte(utils.InternalErrorPage(s.errorConfig, string(pathBytes), err.Error())))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errorMessage string
|
||||||
|
if luaErr, ok := err.(*luajit.LuaError); ok {
|
||||||
|
// Use just the message if stack trace is empty
|
||||||
|
if luaErr.StackTrace == "" {
|
||||||
|
errorMessage = luaErr.Message
|
||||||
|
} else {
|
||||||
|
errorMessage = err.Error() // Full error with stack trace
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errorMessage = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.SetBody([]byte(utils.InternalErrorPage(s.errorConfig, string(pathBytes), errorMessage)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleDebugStats(ctx *fasthttp.RequestCtx) {
|
func (s *Server) handleDebugStats(ctx *fasthttp.RequestCtx) {
|
||||||
|
@ -4,6 +4,7 @@ function __execute(script_func, ctx, response)
|
|||||||
-- Store context and response globally for function access
|
-- Store context and response globally for function access
|
||||||
__ctx = ctx
|
__ctx = ctx
|
||||||
__response = response
|
__response = response
|
||||||
|
_G.ctx = ctx
|
||||||
|
|
||||||
-- Execute script in global environment
|
-- Execute script in global environment
|
||||||
local ok, result = pcall(script_func)
|
local ok, result = pcall(script_func)
|
||||||
@ -82,7 +83,7 @@ function cookie_get(name)
|
|||||||
return __ctx._request_cookies and __ctx._request_cookies[name]
|
return __ctx._request_cookies and __ctx._request_cookies[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
function cookie_remove(name, path, domain)
|
function cookie_delete(name, path, domain)
|
||||||
return cookie_set(name, "", {expires = -1, path = path or "/", domain = domain})
|
return cookie_set(name, "", {expires = -1, path = path or "/", domain = domain})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -388,3 +389,35 @@ function iparse(template_str, values)
|
|||||||
|
|
||||||
return table.concat(output)
|
return table.concat(output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ======================================================================
|
||||||
|
-- PASSWORD FUNCTIONS
|
||||||
|
-- ======================================================================
|
||||||
|
|
||||||
|
-- Hash a password using Argon2id
|
||||||
|
-- Options:
|
||||||
|
-- memory: Amount of memory to use in KB (default: 128MB)
|
||||||
|
-- iterations: Number of iterations (default: 4)
|
||||||
|
-- parallelism: Number of threads (default: 4)
|
||||||
|
-- salt_length: Length of salt in bytes (default: 16)
|
||||||
|
-- key_length: Length of the derived key in bytes (default: 32)
|
||||||
|
function password_hash(plain_password, options)
|
||||||
|
if type(plain_password) ~= "string" then
|
||||||
|
error("password_hash: expected string password", 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
return __password_hash(plain_password, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Verify a password against a hash
|
||||||
|
function password_verify(plain_password, hash_string)
|
||||||
|
if type(plain_password) ~= "string" then
|
||||||
|
error("password_verify: expected string password", 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(hash_string) ~= "string" then
|
||||||
|
error("password_verify: expected string hash", 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
return __password_verify(plain_password, hash_string)
|
||||||
|
end
|
@ -162,13 +162,22 @@ func Request(status int, method, path string, duration time.Duration) {
|
|||||||
dur = fmt.Sprintf("%.2fs", duration.Seconds())
|
dur = fmt.Sprintf("%.2fs", duration.Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := fmt.Sprintf("%s %s %s %s",
|
var parts []string
|
||||||
|
|
||||||
|
if global.timestamp.Load() {
|
||||||
|
ts := applyColor(time.Now().Format("3:04PM"), color.Gray)
|
||||||
|
parts = append(parts, ts)
|
||||||
|
}
|
||||||
|
|
||||||
|
parts = append(parts,
|
||||||
applyColor("["+method+"]", color.Gray),
|
applyColor("["+method+"]", color.Gray),
|
||||||
applyColor(fmt.Sprintf("%d", status), statusColor),
|
applyColor(fmt.Sprintf("%d", status), statusColor),
|
||||||
applyColor(path, color.Gray),
|
applyColor(path, color.Gray),
|
||||||
applyColor(dur, color.Gray),
|
applyColor(dur, color.Gray),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
msg := strings.Join(parts, " ")
|
||||||
|
|
||||||
global.mu.Lock()
|
global.mu.Lock()
|
||||||
fmt.Fprint(global.out, msg+"\n")
|
fmt.Fprint(global.out, msg+"\n")
|
||||||
global.mu.Unlock()
|
global.mu.Unlock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user