From 078742e4a3ad42bc4fd886a42c082bd95edb6b5b Mon Sep 17 00:00:00 2001 From: SJ Date: Fri, 11 May 2012 23:42:55 +0200 Subject: [PATCH] added bulk download feature --- util/Makefile.in | 1 + webui/config.php | 2 + webui/controller/message/bulkrestore.php | 19 ++++- webui/model/message/restore.php | 45 ++++++++++ webui/system/misc.php | 10 ++- webui/tmp/.htaccess | 2 + webui/view/javascript/piler.js | 77 +++++++++++++++++- .../theme/default/images/download_icon.jpg | Bin 0 -> 2422 bytes .../default/stylesheet/style-default.css | 2 +- .../theme/default/templates/search/helper.tpl | 6 +- 10 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 webui/model/message/restore.php create mode 100644 webui/tmp/.htaccess create mode 100644 webui/view/theme/default/images/download_icon.jpg diff --git a/util/Makefile.in b/util/Makefile.in index fb5f228e..34e8e120 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -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: diff --git a/webui/config.php b/webui/config.php index 334bb733..366ec7ac 100644 --- a/webui/config.php +++ b/webui/config.php @@ -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'); diff --git a/webui/controller/message/bulkrestore.php b/webui/controller/message/bulkrestore.php index f97a4b8d..08718302 100644 --- a/webui/controller/message/bulkrestore.php +++ b/webui/controller/message/bulkrestore.php @@ -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(); } diff --git a/webui/model/message/restore.php b/webui/model/message/restore.php new file mode 100644 index 00000000..f080b865 --- /dev/null +++ b/webui/model/message/restore.php @@ -0,0 +1,45 @@ +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); + + } + + +} + + +?> diff --git a/webui/system/misc.php b/webui/system/misc.php index 929c2d81..36d13cb9 100644 --- a/webui/system/misc.php +++ b/webui/system/misc.php @@ -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); } diff --git a/webui/tmp/.htaccess b/webui/tmp/.htaccess new file mode 100644 index 00000000..ff2beb84 --- /dev/null +++ b/webui/tmp/.htaccess @@ -0,0 +1,2 @@ +order deny,allow +deny from all diff --git a/webui/view/javascript/piler.js b/webui/view/javascript/piler.js index c22731a0..52e05d0b 100644 --- a/webui/view/javascript/piler.js +++ b/webui/view/javascript/piler.js @@ -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 = '
spinner
'; - 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 = ' '; +} + + +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; if;aiwTL62jd36efJ32B7!(eJ!6o40y$K12 zBR8Q@s7)voS_=IWQfREClq41{Ese)ZOK&F-2-_9^0SJLWV9*#@DJfYw8JvvVKZ*bM zve5$Ikbn!|0s-LwFb)L4fi~KJ60trQ2m})A{2O2x9D#&_AmShx^1lfH0s}+gASvSfltY#mVX8R8YzJosQiV;%H+ zNYv;4R&vM?i330oFjxZm*DL>pxC;)dhgWuDgq^9`EDh78>C2dBs7zXHhyb)$2N(yz z0Tf^ur39w7VEkHea`*8I^Ue=^0-0|Vo3kCbdYQk@rO!ssxo8z)qK@ifC9l?RWqY-+ ze#jrOt?n@BEBv$m;gZ(qD=$Si(u3UNPri*aqWBA;HzjXmd-v5cW8YUdcYii~mLje` zK6cwQa`fm-4B=htJGD{$Ad#X;5b5LH^iPwYG8eYh2a9{-)&u@cQ-jxTrFezzCoj*Y zu>`tAft0nWuiTL6-acwU7WvAO`Rv{<>mO^z3;b)2In0UMNbmB~TO;ZyuQ>~cG7W(o@$ZPoFtahQox%Ow$gqM_A`+et0ziMVR zI1TX4n-VZjfgcB|Nlgn^u4(T1WM`}9Uuv{P^sBp>s&}30yyJPb#`KF;+FMh#e8Mx! z&vLr4%HQSVXKTJ>D4bG^(%;qm2`9RXDzz#nI|z6Czmex={8!K1S(ml>ss1 zrhVBej(mN%NZ?W4+a?yyNfCBM4{|O?#?M zE@N$1Op=w=)H;5ux1zDVL??n!b|<6&QK3sFHBsN>dIv}7;=jr_{xa2;+ehDC$T|@H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ezr%l{*xNh3we=S*tW-dxaYaR#`5beP#I z96K0OfOI;nVI^2qE?73#n8CbXF+-{!;~6##D4gx}Z_E|Nod=oKbP~qja)4_3&+|8s aFGa~-fxcpOMe@)!!}p+B4rl?iG4>yJe-uRk literal 0 HcmV?d00001 diff --git a/webui/view/theme/default/stylesheet/style-default.css b/webui/view/theme/default/stylesheet/style-default.css index 37d3b8e5..7285111c 100644 --- a/webui/view/theme/default/stylesheet/style-default.css +++ b/webui/view/theme/default/stylesheet/style-default.css @@ -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; } diff --git a/webui/view/theme/default/templates/search/helper.tpl b/webui/view/theme/default/templates/search/helper.tpl index 1bb7a3ee..abf000eb 100644 --- a/webui/view/theme/default/templates/search/helper.tpl +++ b/webui/view/theme/default/templates/search/helper.tpl @@ -38,8 +38,8 @@
0){ ?> -
 
-
 
+
+
aaa
@@ -79,7 +79,7 @@
.
', BALLOON, true, ABOVE, true)" onmouseout="UnTip();">
- +
0) { ?>