diff --git a/config.php.in b/config.php.in index b557a4df..1f14bda2 100644 --- a/config.php.in +++ b/config.php.in @@ -64,6 +64,11 @@ $config['SITE_DESCRIPTION'] = 'piler email archiver'; $config['INDEXER_BEACON'] = '/var/piler/stat/indexer'; $config['PURGE_BEACON'] = '/var/piler/stat/purge'; +$config['ENABLE_PDF_DOWNLOAD'] = 0; +// You may need to run "Xvfb :1 -screen 0 1024x768x16" +// In this case specify WKHTMLTOPDF_COMMAND = "DISPLAY=:1.0 wkhtmltopdf"; +$config['WKHTMLTOPDF_COMMAND'] = "wkhtmltopdf"; + // authentication against an ldap directory (disabled by default) $config['ENABLE_LDAP_AUTH'] = 0; diff --git a/webui/controller/message/pdf.php b/webui/controller/message/pdf.php new file mode 100644 index 00000000..e1acf871 --- /dev/null +++ b/webui/controller/message/pdf.php @@ -0,0 +1,62 @@ +id = "content"; + $this->template = "message/headers.tpl"; + $this->layout = "common/layout-empty"; + + $request = Registry::get('request'); + $db = Registry::get('db'); + $session = Registry::get('session'); + + $this->load->model('search/search'); + $this->load->model('search/message'); + $this->load->model('message/attachment'); + $this->load->model('audit/audit'); + + $this->document->title = $this->data['text_message']; + + $this->data['id'] = @$this->request->get['id']; + + $this->data['search'] = ""; + + // FIXME!!! + $message = $this->model_search_message->get_message_array($this->data['id'], $this->data['search']); + + $images = $this->model_message_attachment->write_image_attachments_to_tmp($message['attachments'], $this->data['id']); + + + $tmpname = $message['piler_id'] . "-tmp-" . microtime(true) . ".html"; + + $fp = fopen(DIR_BASE . 'tmp/' . $tmpname, "w+"); + if($fp) { + fwrite($fp, "
"); + fwrite($fp, $message['message']['message']); + + foreach($images as $img) { + fwrite($fp, "\n"); + } + + fwrite($fp, ""); + fclose($fp); + } + + AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $this->data['id'], ''); + + header("Cache-Control: public, must-revalidate"); + header("Pragma: no-cache"); + header("Content-Type: application/pdf"); + header("Content-Disposition: attachment; filename=" . $message['piler_id'] . ".pdf"); + header("Content-Transfer-Encoding: binary\n"); + + print(system(WKHTMLTOPDF_COMMAND . " " . SITE_URL . "tmp/$tmpname -")); + + unlink(DIR_BASE . 'tmp/' . $tmpname); + } + + +} diff --git a/webui/model/message/attachment.php b/webui/model/message/attachment.php new file mode 100644 index 00000000..a3aecaa5 --- /dev/null +++ b/webui/model/message/attachment.php @@ -0,0 +1,76 @@ +db->query("SELECT id, piler_id, attachment_id, name, type FROM " . TABLE_ATTACHMENT . " WHERE id=?", array($id)); + + if(isset($query->row)) { + $metaid = $this->model_search_message->get_id_by_piler_id($query->row['piler_id']); + + if($metaid > 0 && $this->model_search_search->check_your_permission_by_id($metaid) == 1) { + $attachment = $this->get_attachment_content($query->row['piler_id'], $query->row['attachment_id']); + + return array('filename' => fix_evolution_mime_name_crap($query->row['name']), 'piler_id' => $query->row['piler_id'], 'attachment' => $attachment); + } + } + + return array(); + } + + + public function get_attachment_content($piler_id = '', $attachment_id = '') { + $data = ''; + + if($piler_id == '' || $attachment_id == '' || !preg_match("/^([0-9a-f]+)$/", $piler_id) || !preg_match("/^([0-9m]+)$/", $attachment_id)) { return $data; } + + $cmd = DECRYPT_ATTACHMENT_BINARY . " -i $piler_id -a $attachment_id"; + + if(LOG_LEVEL >= DEBUG) { syslog(LOG_INFO, "attachment cmd: $cmd"); } + + $handle = popen($cmd, "r"); + + while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))){ + $data .= $buf; + } + pclose($handle); + + /* check if it's a base64 encoded stuff */ + + $s = substr($data, 0, 4096); + $s = preg_replace("/(\r|\n)/", "", $s); + + if(!preg_match("/\s/", $s)) { + return base64_decode(preg_replace("/\s/", "", $data)); + } + + return $data; + } + + + public function write_image_attachments_to_tmp($attachments, $id) { + $images = []; + + foreach($attachments as $a) { + + if(preg_match("/image/", $a['type'])) { + + $attachment = $this->get_attachment_by_id($a['id']); + + $fp = fopen(DIR_BASE . 'tmp/' . "i." . $a['id'], "w+"); + if($fp) { + fwrite($fp, $attachment['attachment']); + fclose($fp); + + $images[] = array('name' => "i." . $a['id']); + } + } + } + + return $images; + } + +} diff --git a/webui/model/search/message.php b/webui/model/search/message.php index 3c942594..eb214d68 100644 --- a/webui/model/search/message.php +++ b/webui/model/search/message.php @@ -574,5 +574,3 @@ class ModelSearchMessage extends Model { } } - -?> diff --git a/webui/view/theme/default/templates/message/headers.tpl b/webui/view/theme/default/templates/message/headers.tpl index a7a48cda..0e416f2f 100644 --- a/webui/view/theme/default/templates/message/headers.tpl +++ b/webui/view/theme/default/templates/message/headers.tpl @@ -22,6 +22,11 @@ | + + + | + + | diff --git a/webui/view/theme/default/templates/message/view.tpl b/webui/view/theme/default/templates/message/view.tpl index df1ddd1a..100ce9aa 100644 --- a/webui/view/theme/default/templates/message/view.tpl +++ b/webui/view/theme/default/templates/message/view.tpl @@ -22,6 +22,11 @@ | + + + | + + |