quarantaine.js 5.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Base64 functions
  2. var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(r){var t,e,o,a,h,n,c,d="",C=0;for(r=Base64._utf8_encode(r);C<r.length;)a=(t=r.charCodeAt(C++))>>2,h=(3&t)<<4|(e=r.charCodeAt(C++))>>4,n=(15&e)<<2|(o=r.charCodeAt(C++))>>6,c=63&o,isNaN(e)?n=c=64:isNaN(o)&&(c=64),d=d+this._keyStr.charAt(a)+this._keyStr.charAt(h)+this._keyStr.charAt(n)+this._keyStr.charAt(c);return d},decode:function(r){var t,e,o,a,h,n,c="",d=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<r.length;)t=this._keyStr.indexOf(r.charAt(d++))<<2|(a=this._keyStr.indexOf(r.charAt(d++)))>>4,e=(15&a)<<4|(h=this._keyStr.indexOf(r.charAt(d++)))>>2,o=(3&h)<<6|(n=this._keyStr.indexOf(r.charAt(d++))),c+=String.fromCharCode(t),64!=h&&(c+=String.fromCharCode(e)),64!=n&&(c+=String.fromCharCode(o));return c=Base64._utf8_decode(c)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var t="",e=0;e<r.length;e++){var o=r.charCodeAt(e);o<128?t+=String.fromCharCode(o):o>127&&o<2048?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t},_utf8_decode:function(r){for(var t="",e=0,o=c1=c2=0;e<r.length;)(o=r.charCodeAt(e))<128?(t+=String.fromCharCode(o),e++):o>191&&o<224?(c2=r.charCodeAt(e+1),t+=String.fromCharCode((31&o)<<6|63&c2),e+=2):(c2=r.charCodeAt(e+1),c3=r.charCodeAt(e+2),t+=String.fromCharCode((15&o)<<12|(63&c2)<<6|63&c3),e+=3);return t}};
  3. jQuery(function($){
  4. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  5. var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
  6. function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
  7. function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
  8. function draw_quarantaine_table() {
  9. ft_quarantainetable = FooTable.init('#quarantainetable', {
  10. "columns": [
  11. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  12. {"name":"id","type":"ID","filterable": false,"sorted": true,"direction":"DESC","title":"ID","style":{"width":"50px"}},
  13. {"name":"qid","type":"text","title":lang.qid,"style":{"width":"125px"}},
  14. {"name":"sender","title":lang.sender,"breakpoints":"xs sm"},
  15. {"name":"rcpt","title":lang.rcpt, "type": "text"},
  16. {"name":"created","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.received,"style":{"width":"170px"}},
  17. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right"},"style":{"width":"205px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  18. ],
  19. "rows": $.ajax({
  20. dataType: 'json',
  21. url: '/api/v1/get/quarantaine/all',
  22. jsonp: false,
  23. error: function () {
  24. console.log('Cannot draw quarantaine table');
  25. },
  26. success: function (data) {
  27. $.each(data, function (i, item) {
  28. item.action = '<div class="btn-group">' +
  29. '<a href="#" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-info show_qid_info"><span class="glyphicon glyphicon-modal-window"></span> ' + lang.show_item + '</a>' +
  30. '<a href="#" id="delete_selected" data-id="del-single-qitem" data-api-url="delete/qitem" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  31. '</div>';
  32. item.chkbox = '<input type="checkbox" data-id="qitems" name="multi_select" value="' + item.id + '" />';
  33. });
  34. }
  35. }),
  36. "empty": lang.empty,
  37. "paging": {"enabled": true,"limit": 5,"size": pagination_size},
  38. "sorting": {"enabled": true},
  39. "on": {
  40. "ready.ft.table": function(ev, ft){
  41. $('.show_qid_info').on('click', function (e) {
  42. e.preventDefault();
  43. var qitem = $(this).data('item');
  44. $('#qidDetailModal').modal('show');
  45. $( "#qid_error" ).hide();
  46. $.ajax({
  47. url: '/inc/ajax/qitem_details.php',
  48. data: { id: qitem },
  49. dataType: 'json',
  50. success: function(data){
  51. if (typeof data.error !== 'undefined') {
  52. $( "#qid_error" ).text(data.error);
  53. $( "#qid_error" ).show();
  54. }
  55. $('#qid_detail_subj').text(escapeHtml(data.subject));
  56. $('#qid_detail_text').text(escapeHtml(data.text_plain));
  57. if (typeof data.attachments !== 'undefined') {
  58. $( "#qid_detail_atts" ).text('');
  59. $.each(data.attachments, function( index, value ) {
  60. $( "#qid_detail_atts" ).append(
  61. '<p><a href="/inc/ajax/qitem_details.php?id=' + qitem + '&att=' + index + '" target="_blank">' + value[0] + '</a> (' + value[1] + ')' +
  62. ' - <small><a href="' + value[3] + '" target="_blank">' + lang.check_hash + '</a></small></p>'
  63. );
  64. });
  65. }
  66. else {
  67. $( "#qid_detail_atts" ).text('-');
  68. }
  69. }
  70. });
  71. })
  72. }
  73. },
  74. "filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
  75. });
  76. }
  77. // Initial table drawings
  78. draw_quarantaine_table();
  79. });