mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 21:31:58 +01:00
Added wkhtmltopdf support
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
d6ab3d0c9a
commit
099fe93a87
@ -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;
|
||||
|
62
webui/controller/message/pdf.php
Normal file
62
webui/controller/message/pdf.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerMessagePDF extends Controller {
|
||||
|
||||
public function index(){
|
||||
|
||||
$this->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, "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" /></head><body>");
|
||||
fwrite($fp, $message['message']['message']);
|
||||
|
||||
foreach($images as $img) {
|
||||
fwrite($fp, "<p><img src=" . SITE_URL . "/tmp/" . $img['name'] . " alt=\"\" /></p>\n");
|
||||
}
|
||||
|
||||
fwrite($fp, "</body></html>");
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
76
webui/model/message/attachment.php
Normal file
76
webui/model/message/attachment.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
class ModelMessageAttachment extends Model {
|
||||
|
||||
|
||||
public function get_attachment_by_id($id = 0) {
|
||||
if($id <= 0) { return array(); }
|
||||
|
||||
$query = $this->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;
|
||||
}
|
||||
|
||||
}
|
@ -574,5 +574,3 @@ class ModelSearchMessage extends Model {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -22,6 +22,11 @@
|
||||
<a class="messagelink" href="#" onclick="Piler.restore_message(<?php print $id; ?>);"><i class="icon-reply"></i> <?php print $text_restore_to_mailbox; ?></a> |
|
||||
<?php } } ?>
|
||||
<a class="messagelink" href="#" onclick="Piler.view_message(<?php print $id; ?>);"><i class="icon-envelope-alt"></i> <?php print $text_view_message; ?></a>
|
||||
|
||||
<?php if(ENABLE_PDF_DOWNLOAD) { ?>
|
||||
| <a class="messagelink" href="index.php?route=message/pdf&id=<?php print $id; ?>"><img src="/view/theme/default/assets/images/fileicons/pdf.png" /> <?php print "PDF"; ?></a>
|
||||
<?php } ?>
|
||||
|
||||
<?php if($message['has_journal'] == 1 && Registry::get('auditor_user') == 1 && SHOW_ENVELOPE_JOURNAL == 1) { ?>
|
||||
| <a class="messagelink" href="#" onclick="Piler.view_journal(<?php print $id; ?>);"><i class="icon-envelope-alt"></i> <?php print $text_view_journal_envelope; ?></a>
|
||||
<?php } ?>
|
||||
|
@ -22,6 +22,11 @@
|
||||
<a class="messagelink" href="#" onclick="Piler.restore_message(<?php print $id; ?>);"><i class="icon-reply"></i> <?php print $text_restore_to_mailbox; ?></a> |
|
||||
<?php } } ?>
|
||||
<a class="messagelink" href="#" onclick="Piler.view_headers(<?php print $id; ?>);"><i class="icon-envelope-alt"></i> <?php print $text_view_headers; ?></a>
|
||||
|
||||
<?php if(ENABLE_PDF_DOWNLOAD) { ?>
|
||||
| <a class="messagelink" href="index.php?route=message/pdf&id=<?php print $id; ?>"><img src="/view/theme/default/assets/images/fileicons/pdf.png" /> <?php print "PDF"; ?></a>
|
||||
<?php } ?>
|
||||
|
||||
<?php if($message['has_journal'] == 1 && Registry::get('auditor_user') == 1 && SHOW_ENVELOPE_JOURNAL == 1) { ?>
|
||||
| <a class="messagelink" href="#" onclick="Piler.view_journal(<?php print $id; ?>);"><i class="icon-envelope-alt"></i> <?php print $text_view_journal_envelope; ?></a>
|
||||
<?php } ?>
|
||||
|
Loading…
Reference in New Issue
Block a user