From 7158757fa12e4cc7d02a6d4abc212aa7006ba7e2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 31 Mar 2024 23:48:29 +0200 Subject: [PATCH] Debug v20 --- .../barcode/doc/phpbarcode.modules.php | 12 ++++++++- .../barcode/doc/tcpdfbarcode.modules.php | 26 ++++++++++++++++--- htdocs/viewimage.php | 1 + 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/barcode/doc/phpbarcode.modules.php b/htdocs/core/modules/barcode/doc/phpbarcode.modules.php index 231b55f37b7..3a3eb8cbbca 100644 --- a/htdocs/core/modules/barcode/doc/phpbarcode.modules.php +++ b/htdocs/core/modules/barcode/doc/phpbarcode.modules.php @@ -188,12 +188,22 @@ class modPhpbarcode extends ModeleBarCode dol_mkdir($conf->barcode->dir_temp); if (!is_writable($conf->barcode->dir_temp)) { + if ($langs instanceof Translate) { + $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->barcode->dir_temp); + } else { + $this->error = "ErrorFailedToWriteInTempDirectory ".$conf->barcode->dir_temp; + } $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->barcode->dir_temp); dol_syslog('Error in write_file: ' . $this->error, LOG_ERR); return -1; } - $file = $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png'; + $newcode = $code; + if (!preg_match('/^\w+$/', $code) || dol_strlen($code) > 32) { + $newcode = dol_hash($newcode, 'md5'); // No need for security here, we can use md5 + } + + $file = $conf->barcode->dir_temp . '/barcode_' . $newcode . '_' . $encoding . '.png'; $filebarcode = $file; // global var to be used in barcode_outimage called by barcode_print in buildBarCode diff --git a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php index b3d62ca0901..21829deb88f 100644 --- a/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php +++ b/htdocs/core/modules/barcode/doc/tcpdfbarcode.modules.php @@ -152,16 +152,33 @@ class modTcpdfbarcode extends ModeleBarCode */ public function writeBarCode($code, $encoding, $readable = 'Y', $scale = 1, $nooutputiferror = 0) { - global $conf, $langs, $_GET; + global $conf, $langs; + + // Force value of temp directory because we may call this even if module barcode is disabled + if (empty($conf->barcode)) { + $conf->barcode = new stdClass(); + } + if (empty($conf->barcode->dir_temp)) { + $conf->barcode->dir_temp = DOL_DATA_ROOT.'/barcode/temp'; + } dol_mkdir($conf->barcode->dir_temp); if (!is_writable($conf->barcode->dir_temp)) { - $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->barcode->dir_temp); + if ($langs instanceof Translate) { + $this->error = $langs->transnoentities("ErrorFailedToWriteInTempDirectory", $conf->barcode->dir_temp); + } else { + $this->error = "ErrorFailedToWriteInTempDirectory ".$conf->barcode->dir_temp; + } dol_syslog('Error in write_file: ' . $this->error, LOG_ERR); return -1; } - $file = $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png'; + $newcode = $code; + if (!preg_match('/^\w+$/', $code) || dol_strlen($code) > 32) { + $newcode = dol_hash($newcode, 'md5'); // No need for security here, we can use md5 + } + + $file = $conf->barcode->dir_temp . '/barcode_' . $newcode . '_' . $encoding . '.png'; $tcpdfEncoding = $this->getTcpdfEncodingType($encoding); if (empty($tcpdfEncoding)) { @@ -188,7 +205,8 @@ class modTcpdfbarcode extends ModeleBarCode $barcodeobj = new TCPDFBarcode($code, $tcpdfEncoding); } - dol_syslog("writeBarCode::TCPDF.getBarcodePngData"); + dol_syslog("writeBarCode::TCPDF.getBarcodePngData file=".$file); + if ($imageData = (string) $barcodeobj->getBarcodePngData($width, $height, $color)) { if (function_exists('imagecreate')) { $imageData = imagecreatefromstring($imageData); diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php index 2ebe4c8e9a4..b415af7be7b 100644 --- a/htdocs/viewimage.php +++ b/htdocs/viewimage.php @@ -339,6 +339,7 @@ if ($modulepart == 'barcode') { // Load barcode class $classname = "mod".ucfirst($generator); + $module = new $classname($db); if ($module->encodingIsSupported($encoding)) { $result = $module->buildBarCode($code, $encoding, $readable);