WindowsAgent icon indicating copy to clipboard operation
WindowsAgent copied to clipboard

text label field doesn't support "rich text" for user notification during deployments

Open StCyr opened this issue 5 years ago • 7 comments

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:

image

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:

image

Expected result

Be able to supply non-ascii characters and newlines.

StCyr avatar Apr 26 '19 12:04 StCyr

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

StCyr avatar Apr 26 '19 14:04 StCyr

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

StCyr avatar Apr 29 '19 10:04 StCyr

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=&quot;Hexa&quot; NAME=&quot;install.bat&quot; NOTIFY_USER=&quot;1&quot; NOTIFY_TEXT=&quot;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

StCyr avatar Apr 30 '19 07:04 StCyr

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");

StCyr avatar Apr 30 '19 07:04 StCyr

Summary atm:

  1. newlines can be added by using the
    HTML tag.
  2. Using the HTML "&aecute" code to represent the "lowercase e, acute accent" (é) character still creates Mojibake
  3. using the HTML "&quot" code terminates the string (ie: the rest of the string is not displayed)

StCyr avatar Apr 30 '19 12:04 StCyr

  1. documentation has been updated to inform users that they can use HTML tags.
  2. the problem with the "lowercase e, acute accent" (é) may be fixed by https://github.com/OCSInventory-NG/OCSInventory-ocsreports/pull/734

StCyr avatar May 13 '19 09:05 StCyr

We have the problem too.

Additional info here: https://github.com/OCSInventory-NG/OCSInventory-ocsreports/issues/913

thenamelessthing avatar Mar 05 '20 18:03 thenamelessthing