| 324 | richard | 1 | <?php
 | 
        
           | 2168 | tom.houday | 2 | /**
 | 
        
           |  |  | 3 |  * Print credentials of imported users
 | 
        
           |  |  | 4 |  *
 | 
        
           |  |  | 5 |  * @author    Tom Houdayer
 | 
        
           |  |  | 6 |  * @copyright Copyright (C) ALCASAR (http://www.alcasar.net)
 | 
        
           |  |  | 7 |  * @license   GPL-3.0
 | 
        
           |  |  | 8 |  * @version   $Id: import_file.php 2168 2017-04-18 17:39:54Z tom.houdayer $
 | 
        
           |  |  | 9 |  */
 | 
        
           | 324 | richard | 10 |   | 
        
           | 2168 | tom.houday | 11 | if ((!isset($_GET['file'])) || (empty($_GET['file']))) {
 | 
        
           |  |  | 12 | 	exit();
 | 
        
           |  |  | 13 | }
 | 
        
           | 324 | richard | 14 |   | 
        
           | 2168 | tom.houday | 15 | $filename = $_GET['file'];
 | 
        
           |  |  | 16 | $format   = ((isset($_GET['format'])) ? $_GET['format'] : 'txt');
 | 
        
           | 324 | richard | 17 |   | 
        
           | 2168 | tom.houday | 18 | if (($format !== 'txt') && ($format !== 'pdf')) {
 | 
        
           |  |  | 19 | 	exit();
 | 
        
           |  |  | 20 | }
 | 
        
           | 324 | richard | 21 |   | 
        
           | 2168 | tom.houday | 22 | $filePath = '/tmp/'.$filename.'.pwd';
 | 
        
           |  |  | 23 | if ((!is_file($filePath)) || (!is_readable($filePath))) {
 | 
        
           |  |  | 24 | 	exit('FILE_NOT_FOUND');
 | 
        
           | 324 | richard | 25 | }
 | 
        
           |  |  | 26 |   | 
        
           | 2168 | tom.houday | 27 | if ($format === 'txt') {
 | 
        
           |  |  | 28 | 	header('Content-Type: application/x-download');
 | 
        
           |  |  | 29 | 	header('Content-Length: '.filesize($filePath));
 | 
        
           |  |  | 30 | 	header('Content-Disposition: attachment; filename="'.$filename.'.txt"');
 | 
        
           |  |  | 31 | 	header('Content-Type: application/force-download; filename="'.$filename.'.txt"');
 | 
        
           |  |  | 32 | 	header('Cache-Control: private, max-age=0, must-revalidate');
 | 
        
           |  |  | 33 | 	header('Pragma: public');
 | 
        
           |  |  | 34 | 	ini_set('zlib.output_compression', '0');
 | 
        
           |  |  | 35 | 	readfile($filePath);
 | 
        
           |  |  | 36 | } else if ($format === 'pdf') {
 | 
        
           |  |  | 37 | 	// Convert to PDF
 | 
        
           |  |  | 38 | 	$html  = '<!doctype html><html><head><meta charset="utf-8"></head><body><pre>';
 | 
        
           |  |  | 39 | 	$html .= file_get_contents($filePath);
 | 
        
           |  |  | 40 | 	$html .= '</pre></body></html>';
 | 
        
           |  |  | 41 | 	file_put_contents("$filePath.pdf.html", $html);
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 | 	$command = 'wkhtmltopdf' . ' --quiet --disable-smart-shrinking --footer-font-size 8 --footer-left "ALCASAR" --footer-center "[page] / [toPage]" --footer-right "' . date('Y-m-d H:i:s') . '" ' . escapeshellarg("$filePath.pdf.html") . ' ' . escapeshellarg("$filePath.pdf");
 | 
        
           |  |  | 44 | 	$output;
 | 
        
           |  |  | 45 | 	$exitCode;
 | 
        
           |  |  | 46 | 	exec($command, $output, $exitCode);
 | 
        
           |  |  | 47 |   | 
        
           |  |  | 48 | 	header('Content-Type: application/pdf');
 | 
        
           |  |  | 49 | 	header('Content-Length: '.filesize("$filePath.pdf"));
 | 
        
           |  |  | 50 | 	header('Content-Disposition: attachment; filename="'.$filename.'.pdf"');
 | 
        
           |  |  | 51 | 	header('Cache-Control: private, max-age=0, must-revalidate');
 | 
        
           |  |  | 52 | 	header('Pragma: public');
 | 
        
           |  |  | 53 | 	readfile("$filePath.pdf");
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 | 	unlink("$filePath.pdf");
 | 
        
           |  |  | 56 | 	unlink("$filePath.pdf.html");
 | 
        
           | 324 | richard | 57 | }
 |