tomolimo / ticketcleaner

Home for Ticket Cleaner GLPI plugin
8 stars 2 forks source link

Version 10 #25

Closed blippercop closed 2 years ago

blippercop commented 2 years ago

The plugin gives an error on page /front/plugin.php as superadmin (Debugmode?)

PHP User Warning (512): Unknown attributes "classname" used in "PluginTicketCleaner" class registration in /var/www/html/helpdesk/src/Plugin.php at line 1410

tomolimo commented 2 years ago

Hello @blippercop Could you give info in order to reproduce the issue? Thank you, Regards, Tomolimo

tomolimo commented 2 years ago

And anyway, TicketCleaner is NOT currently compatible with GLPI 10!

blippercop commented 2 years ago

I don't understand. It is not compatible okay.. but will it be updated to be compatible with GLPI 10 or is the project dead?

tomolimo commented 2 years ago

Hello @blippercop Yes version 10 compatibility is planned to take place this year :) Thank, you Regards, Tomolimo

blippercop commented 2 years ago

Awesome. Thank you!

For my own documentation purposes to proceed with the testing (maybe helpful for you?) :

--- hook.php    2021-04-06 15:40:10.000000000 
+++ hook.php    2022-05-04 12:27:46.000000000 
@@ -31,12 +31,13 @@
 // Purpose of file: Provides cleaning of Ticket, for title, description
 //                  and followups.
 //                  It cleans text for creation and edition (from email or from web interface)
 //                  and it cleans attached pictures to emails
 //                  It has been succesfully tested with plain TEXT and HTML emails
 // ----------------------------------------------------------------------
+use Glpi\Toolbox\Sanitizer;

 /**
  * Summary of loadSha1IntoDB
  * This function checks if an update of SHA is mandatory
  * The check is based on last modification date of folder 'pictures'
@@ -269,14 +270,14 @@
             $temp_content = $parm->input['content'];
             if ($is_debug) {
                Toolbox::logInFile('TicketCleaner', "\tInitial text content: " . $temp_content . "\n" );
             }

             // unsanitize doesn't exist, so reverse one by one the sanitize
-            $temp_content = Toolbox::unclean_cross_side_scripting_deep($temp_content);
-            $temp_content = Toolbox::stripslashes_deep($temp_content);
+            $temp_content = Sanitizer::unsanitize($temp_content);
+
             if ($is_debug) {
                 Toolbox::logInFile('TicketCleaner', "\tText content after un-sanitize: " . $temp_content . "\n" );
             }
             $did_something = false;
             foreach ($filters[ PluginTicketcleanerFilter::DESCRIPTION_TYPE ] as $ptn) {
                $temp_content_new = preg_replace( $ptn['regex'], $ptn['replacement'], $temp_content );
@@ -286,13 +287,13 @@
                   if ($is_debug) {
                      Toolbox::logInFile('TicketCleaner', "\tText content after filter: " . $ptn['name'] . "\t content: " . $temp_content . "\n" );
                   }
                }
             }
             if ($did_something) {
-               $temp_content = Toolbox::sanitize([$temp_content]); // sanitize only accepts an array
+               $temp_content = Sanitizer::sanitize([$temp_content]); // sanitize only accepts an array
                $parm->input['content'] = $temp_content[0];
             }
          }

          if ($is_name && isset($filters[ PluginTicketcleanerFilter::TITLE_TYPE ])) {
             if ($is_debug) {
--- setup.php   2021-04-06 15:40:10.000000000 
+++ setup.php   2022-05-04 11:50:14.000000000 
@@ -45,13 +45,13 @@
    global $PLUGIN_HOOKS, $CFG_GLPI, $DEFAULT_PLURAL_NUMBER;

    if ((!isset($_SESSION["glpicronuserrunning"]) || (Session::getLoginUserID() != $_SESSION["glpicronuserrunning"])) && !isset($_SESSION['glpiticketcleanertranslationmode'])) {
       $_SESSION['glpiticketcleanertranslationmode'] = 0;
    }

-   Plugin::registerClass('PluginTicketCleaner', ['classname' => 'PluginTicketCleaner']);
+   Plugin::registerClass('PluginTicketCleaner');

    $PLUGIN_HOOKS['csrf_compliant']['ticketcleaner'] = true;

    $PLUGIN_HOOKS['pre_item_add']['ticketcleaner'] = [
          'Ticket' => ['PluginTicketCleaner', 'plugin_pre_item_add_ticketcleaner'],
          'ITILFollowup' => ['PluginTicketCleaner', 'plugin_pre_item_add_ticketcleaner_followup']
@@ -105,26 +105,25 @@
                'version'        => PLUGIN_TICKETCLEANER_VERSION,
                'author'         => 'Olivier Moron',
                'license'        => 'GPLv3+',
                'homepage'       => 'https://github.com/tomolimo/ticketcleaner',
                'requirements'   => [
                   'glpi'   => [
-                     'min' => '9.5',
-                     'max' => '9.6'
+                     'min' => '9.5'
                   ],
                ]
             ];
 }

 /**
  * Summary of plugin_ticketcleaner_check_prerequisites
  * @return false when GLPI version is not ok!
  */
 function plugin_ticketcleaner_check_prerequisites() {
-   if (version_compare(GLPI_VERSION, '9.5', 'lt') || version_compare(GLPI_VERSION, '9.6', 'ge')) {
+   if (version_compare(GLPI_VERSION, '9.5', 'lt') || version_compare(GLPI_VERSION, '10.1', 'ge')) {
       echo "This plugin requires GLPI >= 9.5 and < 10.1";
       return false;
    }
    return true;
 }

unclean_cross_side_scripting_deep has been replaced by Sanitized. Usage is the same here https://github.com/pluginsGLPI/datainjection

Regex need to be edited: add the /s -> /regexpart/s

Sinature filters work. Saving Regex work. Picture filter not testet.