tdf#130568 - Add server os pretty name to help->about
Change-Id: Id6de533dfb8e34a05d348f8ae701bf3c524c9b95
diff --git a/common/Util.cpp b/common/Util.cpp
index 137ec38..2abbd4d 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -929,6 +929,30 @@
return false;
#endif
}
std::map<std::string, std::string> stringVectorToMap(std::vector<std::string> sVector, const char delimiter)
{
std::map<std::string, std::string> result;
for (std::vector<std::string>::iterator it = sVector.begin(); it != sVector.end(); it++)
{
size_t delimiterPosition = 0;
delimiterPosition = (*it).find(delimiter, 0);
if (delimiterPosition != std::string::npos)
{
std::string key = (*it).substr(0, delimiterPosition);
delimiterPosition++;
std::string value = (*it).substr(delimiterPosition);
result[key] = value;
}
else
{
LOG_WRN("Util::stringVectorToMap => record is misformed: " << (*it));
}
}
return result;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/common/Util.hpp b/common/Util.hpp
index 5204369..fd1589c 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -72,7 +72,7 @@
/// to send data to the child.
int spawnProcess(const std::string &cmd, const StringVector &args,
const std::vector<int>* fdsToKeep = nullptr, int *stdInput = nullptr);
#endif
/// Hex to unsigned char
@@ -972,6 +972,32 @@
* test tool targets (typically fuzzing) where start-up speed is critical.
*/
bool isFuzzing();
/**
* Splits string into vector<string>. Does not accept referenced variables for easy
* usage like (splitString("test", ..)) or (splitString(getStringOnTheFly(), ..))
*/
inline std::vector<std::string> splitStringToVector(std::string const str, const char delim)
{
size_t start;
size_t end = 0;
std::vector<std::string> result;
while ((start = str.find_first_not_of(delim, end)) != std::string::npos)
{
end = str.find(delim, start);
result.push_back(str.substr(start, end - start));
}
return result;
}
/**
* Converts vector of strings to map. Strings should have formed like this: key + delimiter + value.
* In case of a misformed string or zero length vector, returns an empty map.
*/
std::map<std::string, std::string> stringVectorToMap(std::vector<std::string> sVector, const char delimiter);
} // end namespace Util
#endif
diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index 1bb0c44..a2c1a45 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -220,6 +220,7 @@
<div id="loolwsd-id"></div>
<h3>LOKit</h3>
<div id="lokit-version"></div>
<div id="os-name" style="text-align:center"><label>%OS_INFO%</label></div>
<p>Copyright © _YEAR_, VENDOR.</p>
</div>
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index ce9e127..9d833c5 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -649,6 +649,7 @@
Poco::replaceInPlace(preprocess, std::string("%HOST%"), host);
Poco::replaceInPlace(preprocess, std::string("%VERSION%"), std::string(LOOLWSD_VERSION_HASH));
Poco::replaceInPlace(preprocess, std::string("%SERVICE_ROOT%"), LOOLWSD::ServiceRoot);
Poco::replaceInPlace(preprocess, std::string("%OS_INFO%"), LOOLWSD::OSInfo);
std::string protocolDebug = "false";
if (config.getBool("logging.protocol"))
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 9c040a8..54ba8e2 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -726,6 +726,7 @@
std::string LOOLWSD::FileServerRoot;
std::string LOOLWSD::ServiceRoot;
std::string LOOLWSD::LOKitVersion;
std::string LOOLWSD::OSInfo;
std::string LOOLWSD::HostIdentifier;
std::string LOOLWSD::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
std::string LOOLWSD::ConfigDir = LOOLWSD_CONFIGDIR "/conf.d";
@@ -749,6 +750,25 @@
std::unique_ptr<ClipboardCache> LOOLWSD::SavedClipboards;
#endif
void LOOLWSD::getOSInfo(){
#if !MOBILEAPP
// It might be neither mobile nor linux (in the future). That is not handled. If it is not mobile, it is Linux.
// Read operating system info. We can read "os-release" file, located in /etc.
std::ifstream ifs("/etc/os-release");
std::string str(std::istreambuf_iterator<char>{ifs}, {});
std::vector<std::string> infoList = Util::splitStringToVector(str, '\n');
std::map<std::string, std::string> releaseInfo = Util::stringVectorToMap(infoList, '=');
LOOLWSD::OSInfo = "unknown";
if (releaseInfo.find("PRETTY_NAME") != releaseInfo.end()) {
LOOLWSD::OSInfo = releaseInfo["PRETTY_NAME"];
}
#else
// Some more cases might be added in the future.
#endif
}
/// This thread polls basic web serving, and handling of
/// websockets before upgrade: when upgraded they go to the
/// relevant DocumentBroker poll instead.
@@ -886,6 +906,8 @@
AutoPtr<AppConfigMap> defConfig(new AppConfigMap(DefAppConfig));
conf.addWriteable(defConfig, PRIO_SYSTEM); // Lowest priority
LOOLWSD::getOSInfo();
#if !MOBILEAPP
// Load default configuration files, if present.
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 3832633..469d26b 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -70,6 +70,7 @@
static std::string FileServerRoot;
static std::string ServiceRoot; ///< There are installations that need prefixing every page with some path.
static std::string LOKitVersion;
static std::string OSInfo;
static std::string HostIdentifier; ///< A unique random hash that identifies this server
static std::string LogLevel;
static bool AnonymizeUserData;
@@ -219,6 +220,9 @@
static std::string getVersionJSON();
/// Reads OS information, puts them into LOOLWSD::OSInfo variable
static void getOSInfo();
int innerMain();
protected: