WindowsAgent
WindowsAgent copied to clipboard
text label field doesn't support "rich text" for user notification during deployments
General information
Operating system : Windows 10 64bits
OCS Inventory information
Windows agent version : 2.4.0.0
Problem's description
When you deploy a package where you want to tell something to the user after the package's installation, you choose "Yes" for "Installation completion need user action" and specify some text in a text label field:
Unfortunatelly, this text label field doesn't support "rich text".
Here's for example the result of a text where I tried to put non-ascii characters and newline characters:
Expected result
Be able to supply non-ascii characters and newlines.
So, after some reading, it looks like the ouput text contains mojibake (https://en.wikipedia.org/wiki/Mojibake) which comes from the call to xml_escape_string
in function "create_pack" (file "require/function_telediff.php").
This xml_escape_string function in turn calls utf8_encode
and, according to https://stackoverflow.com/questions/2507608/error-input-is-not-proper-utf-8-indicate-encoding-using-phps-simplexml-lo using utf8_encode() is a workaround which has the downside that
if that XML contains both valid UTF-8 and some ISO-8859-1 then the result will contain mojibake
The following page seems to give good hints how to properly handle UTF-8 in a PHP application:
https://stackoverflow.com/questions/279170/utf-8-all-the-way-through
So, I confirm newlines can be added by using the <br/>
HTML tag.
So, I'm guessing this field may contain HTML.
Note though, that using the HTML "&aecute" code to represent the "lowercase e, acute accent" (é) character still creates Mojibake
hmm, it seems it's ocsinventory-reports (the call to utf8_encode
?) which breaks the encoding.
In the following log excerpt, I used mb_detect_encoding
to identify the encoding of NOTIF_TEXT before the call to create_pack
. And, it's properly detected as UTF-8:
[Tue Apr 30 09:34:59.865542 2019] [php7:notice] [pid 19566] [client 10.4.1.142:2688] DONE_ACTION TEXT seems to be encoded in ASCII, referer: https://houdini.fw.belnet.be/ocsreports/index.php?function=tele_package
[Tue Apr 30 09:34:59.865914 2019] [php7:notice] [pid 19566] [client 10.4.1.142:2688] NOTIF TEXT Cher(e) coll\xc3\xa8gue,<br/>Votre application de VPN "Pulse Secure" va \xc3\xaatre mise \xc3\xa0 jour.<br/>Veuillez noter que vous devrez red\xc3\xa9marrer votre ordinateur avant de pouvoir \xc3\xa0 nouveau ouvrir une session VPN.<br/><br/>Geachte colleagua,<br/>uw VPN programma "Pulse Secure" zal updaten worden.<br/>Merk op dat uw computer moet herstarten worden voor dat u een nieuwe VPN sessie kan starten.<br/><br/>ICT & Logistics seems to be encoded in UTF-8, referer: https://houdini.fw.belnet.be/ocsreports/index.php?function=tele_package
[Tue Apr 30 09:35:26.712864 2019] [php7:warn] [pid 23833] [client 10.4.1.142:2698] PHP Warning: simplexml_load_string(): Entity: line 2: parser error : Input is not proper UTF-8, indicate encoding !\nBytes: 0xE8 0x67 0x75 0x65 in /usr/share/ocsinventory-reports/require/teledeploy/Teledeploy.php on line 47, referer: https://houdini.fw.belnet.be/ocsreports/index.php?function=tele_activate
[Tue Apr 30 09:35:26.713034 2019] [php7:warn] [pid 23833] [client 10.4.1.142:2698] PHP Warning: simplexml_load_string(): IGEST_ENCODE="Hexa" NAME="install.bat" NOTIFY_USER="1" NOTIFY_TEXT="Cher(e) coll in /usr/share/ocsinventory-reports/require/teledeploy/Teledeploy.php on line 47, referer: https://houdini.fw.belnet.be/ocsreports/index.php?function=tele_activate
[Tue Apr 30 09:35:26.713267 2019] [php7:warn] [pid 23833] [client 10.4.1.142:2698] PHP Warning: simplexml_load_string(): ^ in /usr/share/ocsinventory-reports/require/teledeploy/Teledeploy.php on line 47, referer: https://houdini.fw.belnet.be/ocsreports/index.php?function=tele_activate
[Tue Apr 30 09:35:26.713511 2019] [php7:error] [pid 23833] [client 10.4.1.142:2698] PHP Fatal error: Uncaught Error: Call to a member function attributes() on boolean in /usr/share/ocsinventory-reports/require/teledeploy/Teledeploy.php:50\nStack trace:\n#0 /usr/share/ocsinventory-reports/plugins/main_sections/ms_teledeploy/ms_tele_package.php(156): Teledeploy->get_package('1556609417')\n#1 /usr/share/ocsinventory-reports/require/header.php(444): require('/usr/share/ocsi...')\n#2 /usr/share/ocsinventory-reports/index.php(44): require('/usr/share/ocsi...')\n#3 {main}\n thrown in /usr/share/ocsinventory-reports/require/teledeploy/Teledeploy.php on line 50, referer: https://houdini.fw.belnet.be/ocsreports/index.php?function=tele_activate
Herea re the lines I've added at line 35 of file plugins/main_sections/ms_teledeploy/ms_tele_package.php
$encoding = mb_detect_encoding($protectedPost['NEED_DONE_ACTION_TEXT']);
$text = $protectedPost['NEED_DONE_ACTION_TEXT'];
error_log("DONE_ACTION TEXT $text seems to be encoded in $encoding");
$encoding = mb_detect_encoding($protectedPost['NOTIFY_TEXT']);
$text = $protectedPost['NOTIFY_TEXT'];
error_log("NOTIF TEXT $text seems to be encoded in $encoding");
Summary atm:
- newlines can be added by using the
HTML tag. - Using the HTML "&aecute" code to represent the "lowercase e, acute accent" (é) character still creates Mojibake
- using the HTML """ code terminates the string (ie: the rest of the string is not displayed)
- documentation has been updated to inform users that they can use HTML tags.
- the problem with the "lowercase e, acute accent" (é) may be fixed by https://github.com/OCSInventory-NG/OCSInventory-ocsreports/pull/734
We have the problem too.
Additional info here: https://github.com/OCSInventory-NG/OCSInventory-ocsreports/issues/913