mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 00:31:58 +01:00
you can download individual attachments
This commit is contained in:
parent
0c20a5f1e1
commit
d6b0c3def4
@ -72,6 +72,7 @@ define('DIR_IMAP', '/var/piler/imap');
|
||||
define('DIR_TMP', '/var/piler/tmp');
|
||||
|
||||
define('DECRYPT_BINARY', '/usr/local/bin/pilerget');
|
||||
define('DECRYPT_ATTACHMENT_BINARY', '/usr/local/bin/pileraget');
|
||||
define('DECRYPT_BUFFER_LENGTH', 65536);
|
||||
|
||||
define('QSHAPE_ACTIVE_INCOMING', DIR_STAT . '/active+incoming');
|
||||
@ -220,6 +221,8 @@ define('ACTION_CHANGE_USER_SETTINGS', 12);
|
||||
|
||||
define('ACTION_REMOVE_MESSAGE', 13);
|
||||
define('ACTION_UNAUTHORIZED_REMOVE_MESSAGE', 14);
|
||||
define('ACTION_DOWNLOAD_ATTACHMENT', 15);
|
||||
define('ACTION_UNAUTHORIZED_DOWNLOAD_ATTACHMENT', 16);
|
||||
|
||||
|
||||
define('NOW', time());
|
||||
|
51
webui/controller/message/attachment.php
Normal file
51
webui/controller/message/attachment.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
class ControllerMessageAttachment 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');
|
||||
|
||||
$this->load->model('search/search');
|
||||
$this->load->model('search/message');
|
||||
|
||||
$this->document->title = $this->data['text_message'];
|
||||
|
||||
$this->data['id'] = @$this->request->get['id'];
|
||||
|
||||
if(!verify_piler_id($this->data['id'])) {
|
||||
AUDIT(ACTION_UNKNOWN, '', '', $this->data['id'], 'unknown id: ' . $this->data['id']);
|
||||
die("invalid id: " . $this->data['id']);
|
||||
}
|
||||
|
||||
$this->data['attachment'] = $this->model_search_message->get_attachment_by_id($this->data['id']);
|
||||
|
||||
if(!isset($this->data['attachment']['filename'])) {
|
||||
die("invalid filename");
|
||||
}
|
||||
|
||||
|
||||
AUDIT(ACTION_DOWNLOAD_ATTACHMENT, '', '', $this->data['id'], '');
|
||||
|
||||
header("Cache-Control: public, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Disposition: attachment; filename=\"" . $this->data['attachment']['filename'] . "\"");
|
||||
header("Content-Transfer-Encoding: binary\n");
|
||||
|
||||
print $this->data['attachment']['attachment'];
|
||||
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -59,6 +59,8 @@ class ControllerMessageView extends Controller {
|
||||
|
||||
$this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']);
|
||||
|
||||
$this->data['attachments'] = $this->model_search_message->get_attachment_list($this->data['piler_id']);
|
||||
|
||||
$this->data['message'] = $this->model_search_message->extract_message($this->data['piler_id']);
|
||||
$this->data['message']['tag'] = $this->model_search_message->get_message_tag($this->data['id'], $_SESSION['uid']);
|
||||
$this->data['message']['note'] = $this->model_search_message->get_message_note($this->data['id'], $_SESSION['uid']);
|
||||
|
@ -54,6 +54,25 @@ class ModelSearchMessage extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function get_attachment($piler_id = '', $attachment_id = '') {
|
||||
$data = '';
|
||||
|
||||
if($piler_id == '' || $attachment_id == '' || !preg_match("/^([0-9a-f]+)$/", $piler_id) || !preg_match("/^([0-9]+)$/", $attachment_id)) { return $data; }
|
||||
|
||||
$handle = popen(DECRYPT_ATTACHMENT_BINARY . " $piler_id $attachment_id", "r");
|
||||
|
||||
while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))){
|
||||
$data .= $buf;
|
||||
}
|
||||
|
||||
pclose($handle);
|
||||
|
||||
/* TODO: decode only if it's a base64 encoded attachment */
|
||||
|
||||
return base64_decode(preg_replace("/\s/", "", $data));
|
||||
}
|
||||
|
||||
|
||||
public function get_message_headers($id = '') {
|
||||
$data = '';
|
||||
|
||||
@ -383,6 +402,56 @@ class ModelSearchMessage extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function get_id_by_piler_id($piler_id = '') {
|
||||
if($piler_id == '') { return -1; }
|
||||
|
||||
$query = $this->db->query("SELECT `id` FROM `" . TABLE_META . "` WHERE piler_id=?", array($piler_id));
|
||||
if(isset($query->row['id'])) { return $query->row['id']; }
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
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, ptr FROM " . TABLE_ATTACHMENT . " WHERE id=?", array($id));
|
||||
|
||||
if(isset($query->row)) {
|
||||
$metaid = $this->get_id_by_piler_id($query->row['piler_id']);
|
||||
|
||||
if($metaid > 0 && $this->model_search_search->check_your_permission_by_id($metaid) == 1) {
|
||||
if($query->row['ptr'] > 0) {
|
||||
$query = $this->db->query("SELECT id, piler_id, attachment_id, name, type FROM " . TABLE_ATTACHMENT . " WHERE id=?", array($query->row['ptr']));
|
||||
}
|
||||
|
||||
$attachment = $this->get_attachment($query->row['piler_id'], $query->row['attachment_id']);
|
||||
|
||||
return array('filename' => $query->row['name'], 'attachment' => $attachment);
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
public function get_attachment_list($piler_id = 0) {
|
||||
$data = array();
|
||||
|
||||
if($piler_id == '') { return array(); }
|
||||
|
||||
$query = $this->db->query("SELECT id, name, type, ptr FROM " . TABLE_ATTACHMENT . " WHERE piler_id=?", array($piler_id));
|
||||
|
||||
if(!isset($query->rows)) { return array(); }
|
||||
|
||||
foreach($query->rows as $q) {
|
||||
array_push($data, $q);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function get_message_tag($id = '', $uid = 0) {
|
||||
if($id == '' || $uid <= 0) { return ''; }
|
||||
|
||||
|
@ -10,5 +10,9 @@
|
||||
<strong><?php print $message['to']; ?></strong><br />
|
||||
<strong><?php print $message['date']; ?></strong> <?php print $text_notes; ?>: <input type="text" size="60" id="note" name="note" class="advtextgrey" style="width: 500px;margin: 0px; color: #000000; height:10px;" value="<?php print $message['note']; ?>" /> <input type="button" value="<?php print $text_save; ?>" style="vertical-align: middle; font: bold 11px Arial, sans-serif; height:16px;" onclick="javascript:var p = 'id=<?php print $id; ?>¬e=' + encodeURI(document.getElementById('note').value); send_ajax_post_request('<?php print MESSAGE_NOTE_URL; ?>', p); show_message('messagebox1', '<p>SAVED</p>', 0.85); " /><br />
|
||||
|
||||
<?php foreach($attachments as $a) { ?>
|
||||
<span><img src="<?php print ICON_ATTACHMENT; ?>" /><a href="index.php?route=message/attachment&id=<?php print $a['id']; ?>"><?php print $a['name']; ?></a></span>
|
||||
<?php } ?>
|
||||
|
||||
<hr />
|
||||
<?php print $message['message']; ?><br />
|
||||
|
Loading…
Reference in New Issue
Block a user