From 437452f148ebda6e3cfcb27b42458257272d1ae9 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 26 Mar 2025 16:37:31 +0100 Subject: [PATCH] wip #7378 @3 --- .docker/dev/update | 1 + .docker/images/php-fpm/Dockerfile | 3 ++ .docker/images/php-fpm/startup | 2 +- .docker/production/update | 1 + CubeIT/js/phantomjs/rasterize.js | 2 +- framework/application/configs/application.ini | 8 ++-- .../controllers/DevisController.php | 11 ++++- .../library/CubeIT/CommandLine/Phantomjs.php | 41 ++++++++++--------- .../CubeIT/Controller/Plugin/HttpAuth.php | 2 + less/common.less | 3 ++ 10 files changed, 47 insertions(+), 27 deletions(-) diff --git a/.docker/dev/update b/.docker/dev/update index acfc4cc..3d551b0 100644 --- a/.docker/dev/update +++ b/.docker/dev/update @@ -2,6 +2,7 @@ cd /docker/dtlc-dev docker network create dtlc-dev +chown 0:0 ./config/sudoers chown 0:0 ./config/cron/crontab chown -R 999:999 ./database/data diff --git a/.docker/images/php-fpm/Dockerfile b/.docker/images/php-fpm/Dockerfile index e751b45..270f429 100644 --- a/.docker/images/php-fpm/Dockerfile +++ b/.docker/images/php-fpm/Dockerfile @@ -62,6 +62,9 @@ ENV LANG fr_FR.UTF-8 ENV LANGUAGE fr_FR:$localshort ENV LC_ALL fr_FR.UTF-8 +RUN apt -y --no-install-recommends install fontconfig libfontconfig bzip2 +RUN cd /root;wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2;tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2;mv phantomjs-2.1.1-linux-x86_64 /usr/local/share;ln -sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin + COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # IF you need some npm globally installed packages diff --git a/.docker/images/php-fpm/startup b/.docker/images/php-fpm/startup index fa84977..fe9ab6d 100644 --- a/.docker/images/php-fpm/startup +++ b/.docker/images/php-fpm/startup @@ -4,8 +4,8 @@ umask 0000 chmod -R 777 /tmp -chown -R root:root /etc/sudoers.d chown -R dtlc:www-data /application +chown -R root:root /etc/sudoers.d # Rsyslog start-stop-daemon --start -b -x /usr/sbin/rsyslogd -- -n diff --git a/.docker/production/update b/.docker/production/update index 763a093..d7990bd 100644 --- a/.docker/production/update +++ b/.docker/production/update @@ -2,6 +2,7 @@ cd /docker/dtlc docker network create dtlc +chown 0:0 ./config/sudoers chown 0:0 ./config/cron/crontab chown -R 999:999 ./database/data diff --git a/CubeIT/js/phantomjs/rasterize.js b/CubeIT/js/phantomjs/rasterize.js index 8de3192..7baba2c 100644 --- a/CubeIT/js/phantomjs/rasterize.js +++ b/CubeIT/js/phantomjs/rasterize.js @@ -44,7 +44,7 @@ if (system.args.length < 3 || system.args.length > 5) { window.setTimeout(function () { page.render(output); phantom.exit(); - }, 200); + }, 1000); } }); } \ No newline at end of file diff --git a/framework/application/configs/application.ini b/framework/application/configs/application.ini index 2e3e626..92819a6 100644 --- a/framework/application/configs/application.ini +++ b/framework/application/configs/application.ini @@ -69,14 +69,16 @@ sogecommerce.key = gLAsQjFhDOBFPXBH [testing : production] seo.robots = false -dev = true +dev = false firephp = false httpauth.username = dtlc httpauth.password = dtlc17 httpauth.ip_whitelist[] = 176.134.43.17 -httpauth.excludepath = /payment/auto -httpauth.excludepath = /sogecommerce/auto +httpauth.excludepath[] = /devis +httpauth.excludepath[] = /payment/auto +httpauth.excludepath[] = /sogecommerce/auto +httpauth.excludepath[] = /images database.params.host = dtlc-dev-mariadb sogenactif.url = https://payment-webinit.simu.sips-atos.com/paymentInit diff --git a/framework/application/controllers/DevisController.php b/framework/application/controllers/DevisController.php index 9efc77c..b73e152 100644 --- a/framework/application/controllers/DevisController.php +++ b/framework/application/controllers/DevisController.php @@ -45,7 +45,7 @@ class DevisController extends CubeIT_Controller_PageController $this->view->print = isset($_GET['print']); - if($amounts['ttc']>0) { + if ($amounts['ttc'] > 0) { $currency = 978; if ($this->view->devis->magasin == 'paris11') { $this->view->magasin = 11; @@ -119,9 +119,16 @@ class DevisController extends CubeIT_Controller_PageController $this->disableLayout(true); $p = $this->_parseParams(); + $file = CubeIT_Files::tempnam(); + $f = $file . '.pdf'; + + $url = SITE_URL . '/devis/index/' . $p[0] . '/' . $p[1] . "?print=1&j=" . time(); + + CubeIT_CommandLine_Phantomjs::html2pdf($url, $f, '210mm*297mm*0*0*0*0'); + $response = $this->getResponse(); $response->setHeader('Content-type', CubeIT_Files::getMimeType('file.pdf')) - ->setBody(file_get_contents('https://extranet.cubedesigners.com/tools/phantomjs?url=' . urlencode(SITE_URL . '/devis/index/' . $p[0] . '/' . $p[1] . "?print=1&j=" . time()) . '&pageformat=210mm*297mm*0*0*0*0')); + ->setBody(file_get_contents($f)); $response->sendResponse(); } diff --git a/framework/library/CubeIT/CommandLine/Phantomjs.php b/framework/library/CubeIT/CommandLine/Phantomjs.php index 62b4a01..e3d7bd5 100644 --- a/framework/library/CubeIT/CommandLine/Phantomjs.php +++ b/framework/library/CubeIT/CommandLine/Phantomjs.php @@ -26,28 +26,29 @@ class CubeIT_CommandLine_Phantomjs extends CubeIT_CommandLine $this->setArg('local-storage-path', $cache . 'cache'); $this->setArg('cookies-file', $cache . 'cookies.txt'); $this->setArg('output-encoding', 'utf8'); + $this->setArg('load-images', 'true'); $this->setArg(null, $script); } - public static function html2pdf($url, $dest, $format = '210mm*297mm', $script = null, $exe = '/usr/local/bin/phantomjs') - { - $dir = dirname($dest); - if (!file_exists($dir)) { - mkdir($dir, 0777, true); - } - - if (null === $script) { - $script = PUBLIC_PATH . '/CubeIT/js/phantomjs/rasterize.js'; - } - - $cl = new CubeIT_CommandLine_Phantomjs($script, null, true, $exe); - $cl->setArg(null, '"' . $url . '"'); - $cl->setArg(null, '"' . $dest . '"'); - $cl->setArg(null, '"' . $format . '"'); - $cl->execute(); - $cl->debug(); - - return $cl; - } + public static function html2pdf($url, $dest, $format = '210mm*297mm', $script = null, $exe = 'phantomjs') + { + $dir = dirname($dest); + if (!file_exists($dir)) { + mkdir($dir, 0777, true); + } + + if (null === $script) { + $script = PUBLIC_PATH . '/CubeIT/js/phantomjs/rasterize.js'; + } + + $cl = new CubeIT_CommandLine_Phantomjs($script, null, true, $exe); + $cl->setEnv('OPENSSL_CONF','/dev/null'); + $cl->setArg(null, '"' . $url . '"'); + $cl->setArg(null, '"' . $dest . '"'); + $cl->setArg(null, '"' . $format . '"'); + $cl->execute(); + + return $cl; + } } diff --git a/framework/library/CubeIT/Controller/Plugin/HttpAuth.php b/framework/library/CubeIT/Controller/Plugin/HttpAuth.php index 633b0a3..89147df 100644 --- a/framework/library/CubeIT/Controller/Plugin/HttpAuth.php +++ b/framework/library/CubeIT/Controller/Plugin/HttpAuth.php @@ -7,6 +7,7 @@ class CubeIT_Controller_Plugin_HttpAuth extends Zend_Controller_Plugin_Abstract $bootstrap = Bootstrap::getInstance(); $http = $bootstrap->getOption('httpauth'); + $skip = false; if (isset($http['excludepath'])) { $url = ltrim($_SERVER["REQUEST_URI"], '/'); @@ -14,6 +15,7 @@ class CubeIT_Controller_Plugin_HttpAuth extends Zend_Controller_Plugin_Abstract $http['excludepath'] = array(ltrim($http['excludepath'], '/')); } foreach ($http['excludepath'] as $e) { + $e=ltrim($e, '/'); if (strpos($url, $e) === 0) { $skip = true; break; diff --git a/less/common.less b/less/common.less index 3bdd04e..f7be6f5 100644 --- a/less/common.less +++ b/less/common.less @@ -1,6 +1,9 @@ * { background-repeat: repeat; vertical-align: top; + -webkit-print-color-adjust: exact !important; /* Chrome, Safari 6 – 15.3, Edge */ + color-adjust: exact !important; /* Firefox 48 – 96 */ + print-color-adjust: exact !important; /* Firefox 97+, Safari 15.4+ */ } body { -- 2.39.5