Record encrypted, xor'd IP of survey clients

This commit is contained in:
TEC 2022-10-17 21:37:32 +08:00
parent e7c18cdec6
commit 7fb590d527
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
3 changed files with 13 additions and 3 deletions

View File

@ -153,12 +153,15 @@ function register!(survey::Survey)
end
end
function register!(response::Response; cache::Bool=true)
function register!(response::Response, exip::Integer=0; cache::Bool=true)
if response.survey keys(surveys(;cache))
register!(response.survey)
end
@assert response.id responseids(response.survey; cache)
SearchLight.query("INSERT INTO responses (survey, id, started, page) VALUES ($(response.survey), $(response.id), '$(string(response.started))', $(response.page))")
SearchLight.query(
"INSERT INTO responses (survey, id, exip, started, page) \
VALUES ($(response.survey), $(response.id), $exip, \
'$(string(response.started))', $(response.page))")
for (qid, ans) in response.answers
qid_s = SearchLight.escape_value(string(qid))
value_s = SearchLight.escape_value(repr(ans.value))

View File

@ -34,10 +34,16 @@ function index()
end
function new()
function encrypted_xord_ip()
ip_str = get(Dict(payload()[:REQUEST].headers), "X-Forwarded-For", "0.0.0.0")
ip = parse.(UInt8, split(ip_str, '.'))
@info "client ip: $ip"
xor(reinterpret(UInt32, Genie.Encryption.encrypt(rand(UInt8, 4)) |> hex2bytes)...)
end
r = Surveys.Response(SURVEY, vcat(responseids(SURVEY),
Vector{Surveys.ResponseID}(keys(INPROGRESS) |> collect)))
INPROGRESS[r.id] = r
register!(r)
register!(r, encrypted_xord_ip())
uid_str = string(r.id, base=UID_ENCBASE)
Genie.Renderer.redirect(HTTP.URIs.URI(currenturl()).path * "?uid=$uid_str&page=1")
end

View File

@ -25,6 +25,7 @@ function up()
[
column(:survey, :integer, not_null=true),
column(:id, :integer, not_null=true),
column(:exip, :integer, not_null=true),
column(:started, :text, not_null=true),
column(:completed, :text),
column(:page, :integer, not_null=true),