Skip to content

Commit

Permalink
geolocation_setup: send "TimeZone" with coolserver message
Browse files Browse the repository at this point in the history
Signed-off-by: Rashesh <[email protected]>
Change-Id: Ibad81f5f90cdfdd909ed9f6370147c93119e9578
  • Loading branch information
Rash419 committed Aug 27, 2024
1 parent 209c3a4 commit f6e1cef
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 41 deletions.
1 change: 1 addition & 0 deletions browser/html/cool.html.m4
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ m4_ifelse(MOBILEAPP,[true],
<div id="slow-proxy"></div>
m4_ifelse(DEBUG,[true],[<div id="js-dialog">JSDialogs: <a href="javascript:void(function() { app.socket.sendMessage('uno .uno:WidgetTestDialog') }() )">View widgets</a></div>])
<div id="routeToken"></div>
<div id="timeZone"></div>
m4_ifelse(MOBILEAPP,[],[<div id="wopi-host-id">%WOPI_HOST_ID%</div><div id="proxy-prefix-id">%PROXY_PREFIX_ENABLED%</div>],[<p></p>])
<p class="about-dialog-info-div"><span dir="ltr">Copyright © _YEAR_, VENDOR.</span></p>
</div>
Expand Down
16 changes: 12 additions & 4 deletions browser/src/control/Control.AboutDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,19 @@ class AboutDialog {
) as HTMLElement;
if (windowAny.socketProxy) slowProxyElement.innerText = _('"Slow Proxy"');

const routeTokenElement = content.querySelector(
'#routeToken',
) as HTMLElement;
if (windowAny.indirectSocket)
if (windowAny.indirectSocket) {
const routeTokenElement = content.querySelector(
'#routeToken',
) as HTMLElement;
routeTokenElement.innerText = 'RouteToken: ' + windowAny.routeToken;
if (windowAny.geolocationSetup) {
const timezoneElement = content.querySelector(
'#timeZone',
) as HTMLElement;
timezoneElement.innerText =
'TimeZone: ' + app.socket.WSDServer.TimeZone;
}
}

this.map.uiManager.showYesNoButton(
aboutDialogId + '-box',
Expand Down
55 changes: 46 additions & 9 deletions common/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ namespace Util
return id;
}

std::string getVersionJSON(bool enableExperimental)
std::string getVersionJSON(bool enableExperimental, bool geolocationSetup)
{
std::string version, hash;
Util::getVersionInfo(version, hash);
Expand All @@ -385,14 +385,31 @@ namespace Util
pocoVersion += std::to_string((POCO_VERSION & 0x00ff0000) >> 16) + ".";
pocoVersion += std::to_string((POCO_VERSION & 0x0000ff00) >> 8);

return
"{ \"Version\": \"" + version + "\", "
"\"Hash\": \"" + hash + "\", "
"\"BuildConfig\": \"" + std::string(COOLWSD_BUILDCONFIG) + "\", "
"\"PocoVersion\": \"" + pocoVersion + "\", "
"\"Protocol\": \"" + COOLProtocol::GetProtocolVersion() + "\", "
"\"Id\": \"" + Util::getProcessIdentifier() + "\", "
"\"Options\": \"" + std::string(enableExperimental ? " (E)" : "") + "\" }";
std::string json = "{ \"Version\": \"" + version +
"\", "
"\"Hash\": \"" +
hash +
"\", "
"\"BuildConfig\": \"" +
std::string(COOLWSD_BUILDCONFIG) +
"\", "
"\"PocoVersion\": \"" +
pocoVersion +
"\", "
"\"Protocol\": \"" +
COOLProtocol::GetProtocolVersion() +
"\", "
"\"Id\": \"" +
Util::getProcessIdentifier() + "\", ";

if (geolocationSetup)
json += "\"TimeZone\": \"" + getIANATimezone() +
"\", "
"\"Options\": \"" +
std::string(enableExperimental ? " (E)" : "") + "\" }";
else
json += "\"Options\": \"" + std::string(enableExperimental ? " (E)" : "") + "\" }";
return json;
}

std::string UniqueId()
Expand Down Expand Up @@ -929,6 +946,26 @@ namespace Util
}
}

std::string getIANATimezone()
{
const char* tzfile = "/etc/localtime";
char buf[PATH_MAX];

ssize_t len = readlink(tzfile, buf, sizeof(buf) - 1);
if (len != -1)
{
buf[len] = '\0';
std::string fullPath(buf);

std::string prefix = "../usr/share/zoneinfo/";
if (fullPath.substr(0, prefix.size()) == prefix)
{
return fullPath.substr(prefix.size());
}
}
return std::string();
}

} // namespace Util

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
5 changes: 4 additions & 1 deletion common/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ namespace Util
///< A random hex string that identifies the current process.
const std::string& getProcessIdentifier();

std::string getVersionJSON(bool enableExperimental);
std::string getVersionJSON(bool enableExperimental, bool geolocationSetup);

/// Return a string that is unique across processes and calls.
std::string UniqueId();
Expand Down Expand Up @@ -1496,6 +1496,9 @@ int main(int argc, char**argv)
return oss.str();
}

/// Get IANA timezone name
std::string getIANATimezone();

/// Asserts in the debug builds, otherwise just logs.
void assertCorrectThread(std::thread::id owner, const char* fileName, int lineNo);

Expand Down
5 changes: 4 additions & 1 deletion wsd/Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ void AdminSocketHandler::handleMessage(const std::vector<char> &payload)
else if (tokens.equals(0, "version"))
{
// Send COOL version information
sendTextFrame("coolserver " + Util::getVersionJSON(EnableExperimental));
sendTextFrame("coolserver " +
Util::getVersionJSON(EnableExperimental, COOLWSD::IndirectionServerEnabled &&
COOLWSD::GeolocationSetup));

// Send LOKit version information
sendTextFrame("lokitversion " + COOLWSD::LOKitVersion);
}
Expand Down
2 changes: 2 additions & 0 deletions wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ std::set<const Poco::Util::AbstractConfiguration*> COOLWSD::PluginConfigurations
std::chrono::steady_clock::time_point COOLWSD::StartTime;
bool COOLWSD::IsBindMountingEnabled = true;
bool COOLWSD::IndirectionServerEnabled = false;
bool COOLWSD::GeolocationSetup = false;

// If you add global state please update dumpState below too

Expand Down Expand Up @@ -2782,6 +2783,7 @@ void COOLWSD::innerInitialize(Application& self)
NoSeccomp = Util::isKitInProcess() || !getConfigValue<bool>(conf, "security.seccomp", true);
AdminEnabled = getConfigValue<bool>(conf, "admin_console.enable", true);
IndirectionServerEnabled = !getConfigValue<std::string>(conf, "indirection_endpoint.url", "").empty();
GeolocationSetup = getConfigValue("indirection_endpoint.geolocation_setup.enable", false);
#if ENABLE_DEBUG
if (Util::isKitInProcess())
SingleKit = true;
Expand Down
1 change: 1 addition & 0 deletions wsd/COOLWSD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class COOLWSD final : public Poco::Util::ServerApplication,
static std::atomic<unsigned> NumConnections;
static std::unique_ptr<TraceFileWriter> TraceDumper;
static bool IndirectionServerEnabled;
static bool GeolocationSetup;
#if !MOBILEAPP
static std::unique_ptr<ClipboardCache> SavedClipboards;

Expand Down
27 changes: 2 additions & 25 deletions wsd/ClientRequestDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1988,27 +1988,6 @@ std::string ClientRequestDispatcher::getDiscoveryXML()

#if !MOBILEAPP

/// Get IANA timezone name
static std::string getIANATimezone()
{
const char* tzfile = "/etc/localtime";
char buf[PATH_MAX];

ssize_t len = readlink(tzfile, buf, sizeof(buf) - 1);
if (len != -1)
{
buf[len] = '\0';
std::string fullPath(buf);

std::string prefix = "../usr/share/zoneinfo/";
if (fullPath.substr(0, prefix.size()) == prefix)
{
return fullPath.substr(prefix.size());
}
}
return std::string();
}

/// Create the /hosting/capabilities JSON and return as string.
static std::string getCapabilitiesJson(bool convertToAvailable)
{
Expand Down Expand Up @@ -2064,11 +2043,9 @@ static std::string getCapabilitiesJson(bool convertToAvailable)
else if (!serverName.empty())
capabilities->set("podName", serverName);

bool geoLocationSetup =
config::getBool(std::string("indirection_endpoint.geolocation_setup.enable"), false);
if (geoLocationSetup)
if (COOLWSD::IndirectionServerEnabled && COOLWSD::GeolocationSetup)
{
std::string timezoneName = getIANATimezone();
std::string timezoneName = Util::getIANATimezone();
if (!timezoneName.empty())
capabilities->set("timezone", std::string(timezoneName));
}
Expand Down
4 changes: 3 additions & 1 deletion wsd/ClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,9 @@ bool ClientSession::_handleInput(const char *buffer, int length)
}

// Send COOL version information
sendTextFrame("coolserver " + Util::getVersionJSON(EnableExperimental));
sendTextFrame("coolserver " +
Util::getVersionJSON(EnableExperimental, COOLWSD::IndirectionServerEnabled &&
COOLWSD::GeolocationSetup));
// Send LOKit version information
sendTextFrame("lokitversion " + COOLWSD::LOKitVersion);

Expand Down

0 comments on commit f6e1cef

Please sign in to comment.