diff --git a/app/resources/results/Results.jl b/app/resources/results/Results.jl index f2f1f35..6de3513 100644 --- a/app/resources/results/Results.jl +++ b/app/resources/results/Results.jl @@ -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)) diff --git a/app/resources/surveys/SurveysController.jl b/app/resources/surveys/SurveysController.jl index 332eb5c..ef4f102 100644 --- a/app/resources/surveys/SurveysController.jl +++ b/app/resources/surveys/SurveysController.jl @@ -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 diff --git a/db/migrations/0000000000000000_create_table_results.jl b/db/migrations/0000000000000000_create_table_results.jl index 83a127e..78d536b 100644 --- a/db/migrations/0000000000000000_create_table_results.jl +++ b/db/migrations/0000000000000000_create_table_results.jl @@ -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),