pluginsGLPI / ocsinventoryng

Plugin ocsinventoryng for GLPI
GNU General Public License v2.0
68 stars 52 forks source link

Echec de connexion à la base de données #331

Open Chibll83 opened 1 year ago

Chibll83 commented 1 year ago

En réalisant la MAJ du plugin ajd en v2.0.2, la connexion à mon serveur OCS c'est coupé. Lorsque je fais un test de connexion au serveur depuis le plugin j'obtiens le message: Echec de connexion à la base de données. Lorsque je regarde dans les log mysql du server OCS j'ai les erreurs suivantes en boucle : 2022-10-10 17:05:16 103 [Warning] Access denied for user 'ocs_user'@'support-servinfo.mondomain.fr' (using password: YES) Si je fais une connexion mysql depuis mon serveur GLPI en mode console vers le serveur OCS je ne rencontre aucun soucis. L'utilisateur ocs_user possède le host % sur la bdd OCS. J'ai réinstallé la version 2.0.0 puis 2.0.1 du plugin, mais idem, toujours problème de connexion à la BDD. Merci d'avance pour votre aide.

Blank-Vcf commented 1 year ago

Pareil pour moi par contre çà à remarché en mettant les fichiers de la 2.0.1

Chibll83 commented 1 year ago

Petite avancé dans mes recherches : Connexion MYSQL depuis SRVGLPI vers SRVOCS en commande ok avec l'utilisateur ocs_user. Toujours une soucis avec le plugin OCSINVENTORYNG, Access denied dans les log MYSQL du SRCOCS, avec le même utilisateur ocs_user. Par contre en rajoutant l'option skip-grant-tables dans le fichier de config my.cnf, le plugin OCSINVENTORYNG fonctionne... Donc là j'ai un gros soucis, cela signifierait qu'il y a un problème avec les privilèges, alors que j'arrive à me connecter depuis le SRVGLPI vers le SRVOCS sans soucis... Je suis à bout de piste, si quelqu'un avait eu une idée je suis preneur ! Merci d'avance.

PS : Voici le résultat de SHOW GRANT FOR ocs_user : GRANT ALL PRIVILEGES ON . TO ocs_user@% IDENTIFIED BY PASSWORD 'monpassword' WITH GRANT OPTION

Chaniac commented 1 year ago

Même problème... Des nouvelles !?

Chibll83 commented 1 year ago

Pour moi c'est un problème lors du chiffrement et/ou du déchiffrement du mot de passe de la BDD OCS saisi dans la configuration du plugin. En effet, en modifiant le fichier ocsserver.class.php pour saisir le mdp en dur à la place de la requête pour rechercher et déchiffrer le mdp, la connexion de test fonctionne. Cependant cela ne fonctionne pas dans l'utilisation du plugin, il doit y avoir d'autres fonctions qui réalisent la même requête... J'ai également tenté un reset de la clé GLPI : php bin/console glpi:security:change_key mais toujours le même problème... Si quelqu'un a une solution, je suis preneur.

Chaniac commented 1 year ago

J'ai également la même chose... Il faudrait que les développeur du plugin interviennent dessus pour qu'on puisse régler ce problème. Je ne sais pas qui a travaillé dessus. Mais je ne suis pas sûr qu'il ait été testé préalablement ou sinon c'est un problème digne des plus grands informaticiens de ce monde xD

Orkote commented 1 year ago

Same problem here :(

Chibll83 commented 1 year ago

Aujourd'hui j'ai réussi à résoudre en partie mon problème en ne diminuant pas trop sécurité de mon système. Après plusieurs tests en modifiant les sources du plugin je me suis apperçu qu'il décrypté mal le mot de passe, et qu'il n'arrivait pas à traduire les symboles spéciaux type @ * et + J'ai créé un nouvel utilisateur sur ma BDD OCS pour lequel j'ai donné les mêmes droits qu'ocs_user, mais pour lequel j'ai un mdp dans aucun symbole. Pour compenser, c'est un mot de passe de 30 caractères avec majuscules et minuscules. En attendant une prochaine MAJ qui corrigera peut être ce problème.

Chaniac commented 1 year ago

Pouvez-vous préciser plus précisément, pour le mot de passe j'ai essayé et cela ne change rien vous avez fait un autre changement?

Chibll83 commented 1 year ago

Dans le fichier ocsserver.class.php, vous trouverez la fonction suivante :

static function getDBocs($serverId) {

  if ($serverId) {
     $config = self::getConfig($serverId);

     if ($config['conn_type'] == self::CONN_TYPE_DB) {
        return new PluginOcsinventoryngOcsDbClient(
           $serverId, $config['ocs_db_host'], $config['ocs_db_user'],
           (new GLPIKey())->decrypt($config['ocs_db_passwd']), $config['ocs_db_name']
        );
     } else {
        return new PluginOcsinventoryngOcsSoapClient(
           $serverId, $config['ocs_db_host'], $config['ocs_db_user'],
           (new GLPIKey())->decrypt($config['ocs_db_passwd'])
        );
     }
  }

}

On voit que c'est ce bout de code : (new GLPIKey())->decrypt($config['ocs_db_passwd']) qui permet d'aller chercher le mdp de la BDD que vous avez saisi lors de la configuration du plugin OCS. Ce mdp est stocké dans la BDD GLPI. Pour voir ce que retourne ce code j'ai ajouté le code suivant à la ligne 1501 afin qu'il m'affiche en plein milieu de la page de config du plugin le contenu déchiffré du mdp :

$config = self::getConfig(1); $pwddb1 = (new GLPIKey())->decrypt(stripslashes($config['ocs_db_passwd'])); echo $pwddb1;

Et c'est là que j'ai vu que les symboles @ + et * sont affichés en code ASCII.

J'ai alors modifié la ligne suivante :

$pwddb1 = rawurldecode(stripslashes((new GLPIKey())->decrypt(stripslashes($config['ocs_db_passwd']))));

Là le mdp est correct. J'ai donc tenté de rajouter rawurldecode(stripslashes( ...) dans la fonction de base, mais toujours le même problème de connexion à la BDD OCS...

J'ai donc conclu que le problème vient des caractères spéciaux de mon mot de passe. J'ai créé un nouvel utilisateur sur la BDD OCS avec un mot de passe sans aucun caractère spécial, uniquement des lettres majuscules et minuscules. Et là miracle, la connexion du plugin se fait sans aucun soucis.

Orkote commented 1 year ago

Works for me! I've created a new user without special characters on password only for localhost to be able to connect with the bbdd. Thanks a lot!!!

Waiting for the official fix to remove this new user.

En el archivo ocsserver.class.php encontrará la siguiente función:

función estática getDBocs($serverId) {

  if ($serverId) {
     $config = self::getConfig($serverId);

     if ($config['conn_type'] == self::CONN_TYPE_DB) {
        return new PluginOcsinventoryngOcsDbClient(
           $serverId, $config['ocs_db_host'], $config['ocs_db_user'],
           (new GLPIKey())->decrypt($config['ocs_db_passwd']), $config['ocs_db_name']
        );
     } else {
        return new PluginOcsinventoryngOcsSoapClient(
           $serverId, $config['ocs_db_host'], $config['ocs_db_user'],
           (new GLPIKey())->decrypt($config['ocs_db_passwd'])
        );
     }
  }

}

Vemos que es este trozo de código: (new GLPIKey())->decrypt($config['ocs_db_passwd']) el que permite buscar el mdp del BDD que introdujo al configurar el plugin OCS. Este mdp se almacena en el BDD GLPI.Para ver qué devuelve este código, he añadido el siguiente código a la línea 1501 para que me muestre en medio de la página de configuración del plugin el contenido descifrado del mdp:

$config = self::getConfig(1);$pwddb1 = (new GLPIKey())->decrypt(stripslashes($config['ocs_db_passwd']));echo $pwddb1;

Y ahí es donde vi que los símbolos @ + y * se muestran en código ASCII.

Luego cambié la siguiente línea:

$pwddb1 = rawurldecode(stripslashes((new GLPIKey())->decrypt(stripslashes($config['ocs_db_passwd']))));

Ahí el mdp es correcto. Así que intenté añadir rawurldecode(stripslashes(...) en la función básica, pero siempre el mismo problema de conexión al BDD OCS...

Así que he llegado a la conclusión de que el problema proviene de los caracteres especiales de mi contraseña. He creado un nuevo usuario en el BDD OCS con una contraseña sin ningún carácter especial, sólo letras mayúsculas y minúsculas. Y ahí milagro, la conexión del plugin se realiza sin preocupaciones.

Chaniac commented 1 year ago

C'est bon cela marche :D merci beaucoup

tsmr commented 1 year ago

If one of you can test master version ? https://github.com/pluginsGLPI/ocsinventoryng/archive/refs/heads/master.zip

jmarmag commented 1 year ago

If one of you can test master version ? https://github.com/pluginsGLPI/ocsinventoryng/archive/refs/heads/master.zip

I just tried, but the same problem.

Operating system: Linux glpi 4.19.0-21-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64 PHP 7.4.28 apache2handler (Core, FFI, PDO, Phar, Reflection, SPL, SimpleXML, Zend OPcache, apache2handler, apc, apcu, bz2, calendar, ctype, curl, date, dom, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imap, intl, json, ldap, libxml, mbstring, mysqli, mysqlnd, openssl, pcre, pdo_mysql, posix, readline, session, shmop, sockets, sodium, standard, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, zlib) Setup: max_execution_time="30" memory_limit="128M" post_max_size="8M" safe_mode="" session.save_handler="files" upload_max_filesize="2M" Software: Apache/2.4.53 (Debian) (Apache/2.4.53 (Debian) Server at glpi.oamc.es Port 80 ) Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52 Server Software: mariadb.org binary distribution Server Version: 10.7.5-MariaDB-1:10.7.5+maria~ubu2004 Server SQL Mode: STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION Parameters: root@mariadb/glpi-cau Host info: mariadb via TCP/IP PHP version (7.4.28) is supported. Sessions configuration is OK. Allocated memory is sufficient. mysqli extension is installed. Following extensions are installed: dom, fileinfo, json, simplexml. curl extension is installed. gd extension is installed. intl extension is installed. libxml extension is installed. zlib extension is installed. The constant SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES is present. Database engine version (10.7.5) is supported. The log file has been created successfully. Write access to /var/www/html/glpi/files/_cache has been validated. Write access to /var/www/html/glpi/config has been validated. Write access to /var/www/html/glpi/files/_cron has been validated. Write access to /var/www/html/glpi/files has been validated. Write access to /var/www/html/glpi/files/_dumps has been validated. Write access to /var/www/html/glpi/files/_graphs has been validated. Write access to /var/www/html/glpi/files/_lock has been validated. Write access to /var/www/html/glpi/files/_pictures has been validated. Write access to /var/www/html/glpi/files/_plugins has been validated. Write access to /var/www/html/glpi/files/_rss has been validated. Write access to /var/www/html/glpi/files/_sessions has been validated. Write access to /var/www/html/glpi/files/_tmp has been validated. Write access to /var/www/html/glpi/files/_uploads has been validated. Web access to the files directory should not be allowed but this cannot be checked automatically on this instance. Make sure access to error log file (/files/_log/php-errors.log) is forbidden; otherwise review .htaccess file and web server configuration. PHP directive "session.cookie_httponly" should be set to "on" to prevent client-side script to access cookie values. exif extension is installed. ldap extension is installed. openssl extension is installed. zip extension is installed. bz2 extension is installed. Zend OPcache extension is installed. Following extensions are installed: ctype, iconv, mbstring, sodium. Write access to /var/www/html/glpi/marketplace has been validated. Timezones seems loaded in database. -- GLPI_ROOT: /var/www/html/glpi GLPI_CONFIG_DIR: /var/www/html/glpi/config GLPI_VAR_DIR: /var/www/html/glpi/files GLPI_MARKETPLACE_DIR: /var/www/html/glpi/marketplace GLPI_USE_CSRF_CHECK: 1 GLPI_CSRF_EXPIRES: 7200 GLPI_CSRF_MAX_TOKENS: 100 GLPI_USE_IDOR_CHECK: 1 GLPI_IDOR_EXPIRES: 7200 GLPI_ALLOW_IFRAME_IN_RICH_TEXT: GLPI_SERVERSIDE_URL_ALLOWLIST: Array GLPI_TELEMETRY_URI: https://telemetry.glpi-project.org GLPI_INSTALL_MODE: TARBALL GLPI_NETWORK_MAIL: glpi@teclib.com GLPI_NETWORK_SERVICES: https://services.glpi-network.com GLPI_MARKETPLACE_ALLOW_OVERRIDE: 1 GLPI_MARKETPLACE_MANUAL_DOWNLOADS: 1 GLPI_USER_AGENT_EXTRA_COMMENTS: GLPI_DISABLE_ONLY_FULL_GROUP_BY_SQL_MODE: 1 GLPI_AJAX_DASHBOARD: 1 GLPI_CALDAV_IMPORT_STATE: 0 GLPI_DEMO_MODE: 0 GLPI_CENTRAL_WARNINGS: 1 GLPI_DOC_DIR: /var/www/html/glpi/files GLPI_CACHE_DIR: /var/www/html/glpi/files/_cache GLPI_CRON_DIR: /var/www/html/glpi/files/_cron GLPI_DUMP_DIR: /var/www/html/glpi/files/_dumps GLPI_GRAPH_DIR: /var/www/html/glpi/files/_graphs GLPI_LOCAL_I18N_DIR: /var/www/html/glpi/files/_locales GLPI_LOCK_DIR: /var/www/html/glpi/files/_lock GLPI_LOG_DIR: /var/www/html/glpi/files/_log GLPI_PICTURE_DIR: /var/www/html/glpi/files/_pictures GLPI_PLUGIN_DOC_DIR: /var/www/html/glpi/files/_plugins GLPI_RSS_DIR: /var/www/html/glpi/files/_rss GLPI_SESSION_DIR: /var/www/html/glpi/files/_sessions GLPI_TMP_DIR: /var/www/html/glpi/files/_tmp GLPI_UPLOAD_DIR: /var/www/html/glpi/files/_uploads GLPI_INVENTORY_DIR: /var/www/html/glpi/files/_inventories GLPI_NETWORK_REGISTRATION_API_URL: https://services.glpi-network.com/api/registration/ GLPI_MARKETPLACE_PLUGINS_API_URI: https://services.glpi-network.com/api/glpi-plugins/ GLPI_I18N_DIR: /var/www/html/glpi/locales GLPI_VERSION: 10.0.3 GLPI_SCHEMA_VERSION: 10.0.3@a130db99c7d9b131c2e2ea59fe0d6260fe93d831 GLPI_MARKETPLACE_PRERELEASES: GLPI_MIN_PHP: 7.4.0 GLPI_MAX_PHP: 8.3.0 GLPI_YEAR: 2022 htmlawed/htmlawed version 1.2.9 in (/var/www/html/glpi/vendor/htmlawed/htmlawed) phpmailer/phpmailer version 6.6.0 in (/var/www/html/glpi/vendor/phpmailer/phpmailer/src) simplepie/simplepie version 1.5.8 in (/var/www/html/glpi/vendor/simplepie/simplepie/library) tecnickcom/tcpdf version 6.4.4 in (/var/www/html/glpi/plugins/pdf/vendor/tecnickcom/tcpdf) michelf/php-markdown in (/var/www/html/glpi/vendor/michelf/php-markdown/Michelf) true/punycode in (/var/www/html/glpi/vendor/true/punycode/src) iamcal/lib_autolink in (/var/www/html/glpi/vendor/iamcal/lib_autolink) sabre/dav in (/var/www/html/glpi/vendor/sabre/dav/lib/DAV) sabre/http in (/var/www/html/glpi/vendor/sabre/http/lib) sabre/uri in (/var/www/html/glpi/vendor/sabre/uri/lib) sabre/vobject in (/var/www/html/glpi/vendor/sabre/vobject/lib) laminas/laminas-i18n in (/var/www/html/glpi/vendor/laminas/laminas-i18n/src) laminas/laminas-servicemanager in (/var/www/html/glpi/vendor/laminas/laminas-servicemanager/src) monolog/monolog in (/var/www/html/glpi/vendor/monolog/monolog/src/Monolog) sebastian/diff in (/var/www/html/glpi/vendor/sebastian/diff/src) donatj/phpuseragentparser in (/var/www/html/glpi/vendor/donatj/phpuseragentparser/src/UserAgent) elvanto/litemoji in (/var/www/html/glpi/vendor/elvanto/litemoji/src) symfony/console in (/var/www/html/glpi/vendor/symfony/console) scssphp/scssphp in (/var/www/html/glpi/vendor/scssphp/scssphp/src) laminas/laminas-mail in (/var/www/html/glpi/vendor/laminas/laminas-mail/src/Protocol) laminas/laminas-mime in (/var/www/html/glpi/vendor/laminas/laminas-mime/src) rlanvin/php-rrule in (/var/www/html/glpi/vendor/rlanvin/php-rrule/src) blueimp/jquery-file-upload in (/var/www/html/glpi/vendor/blueimp/jquery-file-upload/server/php) ramsey/uuid in (/var/www/html/glpi/vendor/ramsey/uuid/src) psr/log in (/var/www/html/glpi/vendor/psr/log/Psr/Log) psr/simple-cache in (/var/www/html/glpi/vendor/psr/simple-cache/src) psr/cache in (/var/www/html/glpi/vendor/psr/cache/src) league/csv in (/var/www/html/glpi/vendor/league/csv/src) mexitek/phpcolors in (/var/www/html/glpi/vendor/mexitek/phpcolors/src/Mexitek/PHPColors) guzzlehttp/guzzle in (/var/www/html/glpi/vendor/guzzlehttp/guzzle/src) guzzlehttp/psr7 in (/var/www/html/glpi/vendor/guzzlehttp/psr7/src) glpi-project/inventory_format in (/var/www/html/glpi/vendor/glpi-project/inventory_format/lib/php) wapmorgan/unified-archive in (/var/www/html/glpi/vendor/wapmorgan/unified-archive/src) paragonie/sodium_compat in (/var/www/html/glpi/vendor/paragonie/sodium_compat/src) symfony/cache in (/var/www/html/glpi/vendor/symfony/cache) html2text/html2text in (/var/www/html/glpi/vendor/html2text/html2text/src) symfony/css-selector in (/var/www/html/glpi/vendor/symfony/css-selector) symfony/dom-crawler in (/var/www/html/glpi/vendor/symfony/dom-crawler) twig/twig in (/var/www/html/glpi/vendor/twig/twig/src) twig/string-extra in (/var/www/html/glpi/vendor/twig/string-extra) symfony/polyfill-ctype not found symfony/polyfill-iconv not found symfony/polyfill-mbstring not found symfony/polyfill-php80 in (/var/www/html/glpi/vendor/symfony/polyfill-php80) symfony/polyfill-php81 in (/var/www/html/glpi/vendor/symfony/polyfill-php81) symfony/polyfill-php82 in (/var/www/html/glpi/vendor/symfony/polyfill-php82) phpCas version 1.3.8 in (/usr/share/php/CAS/source) Plugins list -- databases Name: Bases de datos Version: 2.3.2 State: Not installed Install Method: Marketplace accounts Name: Cuentas Version: 3.0.2 State: Enabled Install Method: Marketplace addressing Name: Direccionamiento IP Version: 3.0.1 State: Enabled Install Method: Marketplace pdf Name: Impresión a pdf Version: 2.1.0 State: Enabled Install Method: Manual ocsinventoryng Name: OCS Inventory NG Version: 2.0.2 State: Enabled Install Method: Marketplace shellcommands Name: Órdenes de consola Version: 4.0.1 State: Enabled Install Method: Marketplace manufacturersimports Name: Suppliers imports Version: 3.0.2 State: Enabled Install Method: Marketplace Host: xxxxxxxxxxx Connection: KOUse the OCSNG software dictionary: No
tsmr commented 1 year ago

I think you must update setup too for test it