#!/usr/bin/lua5.2

local json = require 'cjson'
local aas = require 'aaudit.server'

local req = json.decode(io.read())
req.remote_ip = (os.getenv("SSH_CLIENT") or ""):match("[^ ]+")
req.identity = arg[1]

local ok, msg, extra = aas.handle(req, io.stdin)

local object = extra or {}
object.ok = ok
object.msg = msg
print(json.encode(object))
