Write UserReport data to local logfiles, so that users can review the personal data impact without exposing the data to JS/mods, refs #5257, b3438cabd2.

Write the logfiles even if the UserReporter is disabled, so that the
assessment can be done prior to use.

This was SVN commit r21868.
This commit is contained in:
elexis 2018-08-22 22:17:42 +00:00
parent b3438cabd2
commit dd008af2f8
3 changed files with 32 additions and 6 deletions

View File

@ -344,7 +344,11 @@ void RunHardwareDetection()
scriptInterface.SetProperty(settings, "timer_resolution", timer_Resolution());
// Send the same data to the reporting system
g_UserReporter.SubmitReport("hwdetect", 11, scriptInterface.StringifyJSON(&settings, false));
g_UserReporter.SubmitReport(
"hwdetect",
11,
scriptInterface.StringifyJSON(&settings, false),
scriptInterface.StringifyJSON(&settings, true));
// Run the detection script:
JS::RootedValue global(cx, scriptInterface.GetGlobalObject());

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2016 Wildfire Games.
/* Copyright (C) 2018 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -25,12 +25,16 @@
#include "lib/external_libraries/libsdl.h"
#include "lib/external_libraries/zlib.h"
#include "lib/file/archive/stream.h"
#include "lib/os_path.h"
#include "lib/sysdep/sysdep.h"
#include "ps/ConfigDB.h"
#include "ps/Filesystem.h"
#include "ps/Profiler2.h"
#include "ps/ThreadUtil.h"
#include <fstream>
#include <string>
#define DEBUG_UPLOADS 0
/*
@ -569,7 +573,6 @@ std::string CUserReporter::GetStatus()
return m_Worker->GetStatus();
}
void CUserReporter::Initialize()
{
ENSURE(!m_Worker); // must only be called once
@ -607,12 +610,28 @@ void CUserReporter::Update()
m_Worker->Update();
}
void CUserReporter::SubmitReport(const char* type, int version, const std::string& data)
void CUserReporter::SubmitReport(const std::string& type, int version, const std::string& data, const std::string& dataHumanReadable)
{
// Write to logfile, enabling users to assess privacy concerns before the data is submitted
if (!dataHumanReadable.empty())
{
OsPath path = psLogDir() / OsPath("userreport_" + type + ".txt");
std::ofstream stream(OsString(path), std::ofstream::trunc);
if (stream)
{
debug_printf("UserReport written to %s\n", path.string8().c_str());
stream << dataHumanReadable << std::endl;
stream.close();
}
else
debug_printf("Failed to write UserReport to %s\n", path.string8().c_str());
}
// If not initialised, discard the report
if (!m_Worker)
return;
// Actual submit
shared_ptr<CUserReport> report(new CUserReport);
report->m_Time = time(NULL);
report->m_Type = type;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2018 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,6 +18,8 @@
#ifndef INCLUDED_USERREPORT
#define INCLUDED_USERREPORT
#include <string>
class CUserReporterWorker;
class CUserReporter
@ -48,8 +50,9 @@ public:
* @param version positive integer that should be incremented if the data is changed in
* a non-compatible way and the server will have to distinguish old and new formats
* @param data the actual data (typically UTF-8-encoded text, or JSON, but could be binary)
* @param dataHumanReadable an optional, readable representation of the same data, allowing users to assess for privacy concerns
*/
void SubmitReport(const char* type, int version, const std::string& data);
void SubmitReport(const std::string& type, int version, const std::string& data, const std::string& dataHumanReadable);
private:
std::string LoadUserID();