added bulk download feature

This commit is contained in:
SJ 2012-05-11 23:42:55 +02:00
parent 9212dff26b
commit 078742e4a3
10 changed files with 152 additions and 12 deletions

View File

@ -28,6 +28,7 @@ all:
install:
$(INSTALL) -m 0755 $(srcdir)/ldap_sync.php $(DESTDIR)$(libexecdir)/piler
$(INSTALL) -m 0755 $(srcdir)/daily-report.php $(DESTDIR)$(libexecdir)/piler
clean:

View File

@ -22,6 +22,7 @@ define('ICON_ATTACHMENT', '/view/theme/default/images/attachment_icon.png');
define('ICON_TAG', '/view/theme/default/images/tag_blue.png');
define('ICON_GREEN_OK', '/view/theme/default/images/green_ok.png');
define('ICON_RED_X', '/view/theme/default/images/red_x.png');
define('ICON_DOWNLOAD', '/view/theme/default/images/download_icon.jpg');
define('MAX_CGI_FROM_SUBJ_LEN', 45);
define('PAGE_LEN', 20);
@ -53,6 +54,7 @@ define('DIR_APPLICATION', DIR_BASE . 'controller/');
define('DIR_THEME', DIR_BASE . 'view/theme/');
define('DIR_REPORT', DIR_BASE . 'reports/');
define('DIR_LOG', DIR_BASE . 'log/');
define('DIR_TMP', DIR_BASE . 'tmp/');
define('DIR_STORE', '/var/piler/store');
define('DIR_STAT', '/var/piler/stat');

View File

@ -14,6 +14,7 @@ class ControllerMessageBulkrestore extends Controller {
$this->load->model('search/search');
$this->load->model('search/message');
$this->load->model('message/restore');
$this->load->model('user/user');
$this->load->model('mail/mail');
@ -24,13 +25,28 @@ class ControllerMessageBulkrestore extends Controller {
list($a, $idlist) = $this->model_search_search->check_your_permission_by_id_list(explode(",", $this->request->post['idlist']));
$download = $this->request->post['download'];
if($download == 1) {
$this->model_message_restore->download_files_as_zip($idlist);
exit;
}
$this->data['username'] = Registry::get('username');
$rcpt = array();
array_push($rcpt, $_SESSION['email']);
/* send the email to all the recipients of the original email if we are admin or auditor users */
if(Registry::get('admin_user') == 1 || Registry::get('auditor_user') == 1) {
$rcpt = $this->model_search_search->get_message_recipients($this->data['id']);
}
else {
array_push($rcpt, $_SESSION['email']);
}
$this->data['restored'] = 0;
@ -45,6 +61,7 @@ class ControllerMessageBulkrestore extends Controller {
if($x == 1) { $this->data['restored']++; }
}
$this->render();
}

View File

@ -0,0 +1,45 @@
<?php
class ModelMessageRestore extends Model {
public function download_files_as_zip($idlist = array()) {
$zip = new ZipArchive();
$randomid = generate_random_string(16);
$filename = DIR_TMP . "/" . $randomid;
if($zip->open($filename, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$filename>\n"); }
foreach($idlist as $id) {
$rawemail = $this->model_search_message->get_raw_message($id);
$zip->addFromString($id . ".eml", $rawemail);
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $id, '');
}
$zip->close();
header("Cache-Control: public, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/zip");
header("Expires: 0");
header("Content-Length: " . filesize($filename));
header("Content-Disposition: attachment; filename=archive-$randomid.zip");
header("Content-Transfer-Encoding: binary\n");
readfile($filename);
unlink($filename);
}
}
?>

View File

@ -163,8 +163,7 @@ function verify_piler_id($id = '') {
}
function createTempName($dir = '', $prefix = '') {
$length = 8;
function generate_random_string($length = 8) {
$rnd = "";
$aZ09 = array_merge(range('A', 'Z'), range('a', 'z'),range(0, 9));
@ -172,7 +171,12 @@ function createTempName($dir = '', $prefix = '') {
$rnd .= $aZ09[mt_rand(0, count($aZ09)-1)];
}
return $dir . "/" . $prefix . $rnd;
return $rnd;
}
function createTempName($dir = '', $prefix = '') {
return $dir . "/" . $prefix . generate_random_string(8);
}

2
webui/tmp/.htaccess Normal file
View File

@ -0,0 +1,2 @@
order deny,allow
deny from all

View File

@ -385,7 +385,7 @@ function tag_search_results(url){
}
function restore_selected_emails(url) {
function assemble_idlist() {
var a = document.getElementById('results');
var idlist = "";
@ -407,6 +407,14 @@ function restore_selected_emails(url) {
}
}
return idlist;
}
function restore_selected_emails(url) {
var idlist = assemble_idlist();
if(idlist) {
var http = getXMLHttp();
@ -414,10 +422,9 @@ function restore_selected_emails(url) {
document.getElementById('A1').innerHTML = '<div class="restore_spinner"><img src="/view/theme/default/images/spinner.gif" id="spinner_restore" alt="spinner" /></div>';
http.open("POST", url, true);
params = "idlist=" + idlist;
params = "idlist=" + idlist + "&download=0";
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
@ -438,7 +445,69 @@ function restore_selected_emails(url) {
http.send(params);
}
//document.getElementById('A1').innerHTML = '&nbsp;';
}
function download_selected_emails(url) {
var hiddenField;
var idlist = assemble_idlist();
if(idlist) {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", url);
form.setAttribute("name", "download");
hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "download");
hiddenField.setAttribute("value", "1");
form.appendChild(hiddenField);
hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "idlist");
hiddenField.setAttribute("value", idlist);
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
}
}
function toggle_bulk_check() {
var isChecked = document.getElementById('bulkcheck').value;
var a = document.getElementById('results');
len = a.childNodes.length;
for(i=0; i<a.childNodes.length; i++) {
if(a.childNodes[i].nodeName == "DIV" && a.childNodes[i].id.substring(0, 2) == "e_") {
id = a.childNodes[i].id.substring(2,1000);
b = document.getElementById('r_' + id);
if(isChecked == 1) { b.checked = 0; }
else { b.checked = 1; }
}
}
if(isChecked == 1) {
document.getElementById('bulkcheck').checked = 0;
document.getElementById('bulkcheck').value = 0;
}
else {
document.getElementById('bulkcheck').checked = 1;
document.getElementById('bulkcheck').value = 1;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -80,7 +80,7 @@
.cell1 { display: table-cell; height: 25px; text-align: left; padding: 3px; font: bold 12px Arial, sans-serif; width: 80px; }
.cell1s { display: table-cell; height: 25px; text-align: left; padding: 3px; font: bold 12px Arial, sans-serif; width: 85px; }
.cell1q { display: table-cell; height: 25px; text-align: left; padding: 3px; font: bold 12px Arial, sans-serif; width: 50px; }
.cell1r { display: table-cell; height: 25px; text-align: left; padding: 3px; font: bold 12px Arial, sans-serif; width: 15px; }
.cell1r { display: table-cell; height: 25px; text-align: left; padding: 0px; font: bold 12px Arial, sans-serif; width: 15px; }
.cell3 { display: table-cell; height: 25px; text-align: left; padding: 0px; padding-top: 3px; font: bold 19px Arial, sans-serif; }
.cell3.title { color: black; text-align: left; }

View File

@ -38,8 +38,8 @@
<div class="resultrow">
<?php if($n > 0){ ?>
<div class="cell1r">&nbsp;</div>
<div class="cell1q">&nbsp;</div>
<div class="cell1r" style="vertical-align:middle;"><input type="checkbox" id="bulkcheck" name="bulkcheck" value="1" checked="checked" class="restorebox" onchange="javascript:toggle_bulk_check(); return false;" /></div>
<div class="cell1q" style="text-align: center;"><a href="#" onclick="javascript: download_selected_emails('<?php print BULK_RESTORE_URL; ?>'); return false;"><img style="margin: 0px 0 -2px 0; border: 0px solid black;" src="<?php print ICON_DOWNLOAD; ?>" width="18" height="18" alt="aaa" border="0"></a></div>
<div class="cell3 date">
<?php print $text_date; ?>
<a href="#" onclick="script:fix_search_order('date', 1); load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), 0); return false;"><img src="<?php print ICON_ARROW_UP; ?>" alt="" border="0"></a>
@ -79,7 +79,7 @@
<div class="cell5 id"><?php print ($page*$page_len) + $i; ?>.</div>
<div class="cell5 date"><?php print $message['date']; ?></div>
<div class="cell5 from"><?php if($message['from'] != $message['shortfrom']) { ?><span onmouseover="Tip('<?php print preg_replace("/&/", "&amp;", $message['from']); ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();"><?php print $message['shortfrom']; ?></span><?php } else { print $message['from']; } ?></div>
<div class="cell5 subject"><a class="messagelink<?php if($message['spam'] == 1) { ?> spam<?php } ?>" href="<?php print SITE_URL; ?>message.php/<?php print $message['piler_id']; ?>"><?php if($message['subject'] != $message['shortsubject']) { ?><span onmouseover="Tip('<?php print preg_replace("/&/", "&amp;", $message['subject']); ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();"><?php print $message['shortsubject']; ?></span><?php } else { print $message['subject']; } ?></a><?php if($message['reference']) { ?> <a href="#" onclick="script:add_message_reference_to_form('<?php print $message['reference']; ?>'); load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), 0); a = document.getElementById('ref'); a.value=''; return false;"><span onmouseover="Tip('<?php print $text_conversation_available; ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();">[+]</span></a><?php } ?></div>
<div class="cell5 subject"><a class="messagelink<?php if($message['spam'] == 1) { ?> spam<?php } ?>" href="<?php print SITE_URL; ?>message.php/<?php print $message['piler_id']; ?>"><?php if($message['subject'] != $message['shortsubject']) { ?><span onmouseover="Tip('<?php print preg_replace("/&/", "&amp;", $message['subject']); ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();"><?php print $message['shortsubject']; ?></span><?php } else { print $message['subject']; } ?></a><?php if($message['reference']) { ?> <a href="#" onclick="script:add_message_reference_to_form('<?php print $message['reference']; ?>'); load_search_results('<?php print SEARCH_HELPER_URL; ?>', assemble_search_term(count), 0); a = document.getElementById('ref'); a.value=''; return false;"><span onmouseover="Tip('<?php print $text_conversation_available; ?>', BALLOON, true, ABOVE, true);" onmouseout="UnTip();">[+]</span></a><?php } ?></div>
<div class="cell5 size"><?php print $message['size']; ?></div>
<div class="cell5"><?php if($message['attachments'] > 0) { ?><img src="<?php print ICON_ATTACHMENT; ?>" alt="" width="16" height="18" /><?php } else { ?>&nbsp;<?php } ?></div>
<div class="cell5"><?php if($message['tag']) { ?><span onmouseover="Tip('<?php print $message['tag']; ?>', BALLOON, true, ABOVE, true)" onmouseout="UnTip();"><img src="<?php print ICON_TAG; ?>" alt="" /></span><?php } else { ?>&nbsp;<?php } ?></div>