admin.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. $("#refresh_postfix_log").on('click', function(e) {
  9. e.preventDefault();
  10. draw_postfix_logs();
  11. });
  12. $("#refresh_autodiscover_log").on('click', function(e) {
  13. e.preventDefault();
  14. draw_autodiscover_logs();
  15. });
  16. $("#refresh_dovecot_log").on('click', function(e) {
  17. e.preventDefault();
  18. draw_dovecot_logs();
  19. });
  20. $("#refresh_sogo_log").on('click', function(e) {
  21. e.preventDefault();
  22. draw_sogo_logs();
  23. });
  24. $("#refresh_fail2ban_log").on('click', function(e) {
  25. e.preventDefault();
  26. draw_fail2ban_logs();
  27. });
  28. $("#refresh_rspamd_history").on('click', function(e) {
  29. e.preventDefault();
  30. draw_rspamd_history();
  31. });
  32. $("#import_dkim_legend").on('click', function(e) {
  33. e.preventDefault();
  34. $('#import_dkim_arrow').toggleClass("animation");
  35. });
  36. function draw_autodiscover_logs() {
  37. ft_autodiscover_logs = FooTable.init('#autodiscover_log', {
  38. "columns": [
  39. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  40. {"name":"ua","title":"User-Agent","style":{"min-width":"200px"}},
  41. {"name":"user","title":"Username","style":{"min-width":"200px"}},
  42. {"name":"service","title":"Service"},
  43. ],
  44. "rows": $.ajax({
  45. dataType: 'json',
  46. url: '/api/v1/get/logs/autodiscover/100',
  47. jsonp: false,
  48. error: function () {
  49. console.log('Cannot draw autodiscover log table');
  50. },
  51. success: function (data) {
  52. return process_table_data(data, 'autodiscover_log');
  53. }
  54. }),
  55. "empty": lang.empty,
  56. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  57. "filtering": {"enabled": true,"position": "left","placeholder": lang.filter_table},
  58. "sorting": {"enabled": true},
  59. "on": {"ready.ft.table": function(e, ft){
  60. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  61. $(heading).children('.log-lines').text(function(){
  62. var ft_paging = ft.use(FooTable.Paging)
  63. return ft_paging.totalRows;
  64. })
  65. }
  66. }
  67. });
  68. }
  69. function draw_postfix_logs() {
  70. ft_postfix_logs = FooTable.init('#postfix_log', {
  71. "columns": [
  72. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  73. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  74. {"name":"message","title":lang.message},
  75. ],
  76. "rows": $.ajax({
  77. dataType: 'json',
  78. url: '/api/v1/get/logs/postfix',
  79. jsonp: false,
  80. error: function () {
  81. console.log('Cannot draw postfix log table');
  82. },
  83. success: function (data) {
  84. return process_table_data(data, 'general_syslog');
  85. }
  86. }),
  87. "empty": lang.empty,
  88. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  89. "filtering": {"enabled": true,"position": "left","placeholder": lang.filter_table},
  90. "sorting": {"enabled": true},
  91. "on": {
  92. "ready.ft.table": function(e, ft){
  93. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  94. $(heading).children('.log-lines').text(function(){
  95. var ft_paging = ft.use(FooTable.Paging)
  96. return ft_paging.totalRows;
  97. })
  98. }
  99. }
  100. });
  101. }
  102. function draw_fail2ban_logs() {
  103. ft_fail2ban_logs = FooTable.init('#fail2ban_log', {
  104. "columns": [
  105. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  106. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  107. {"name":"message","title":lang.message},
  108. ],
  109. "rows": $.ajax({
  110. dataType: 'json',
  111. url: '/api/v1/get/logs/fail2ban',
  112. jsonp: false,
  113. error: function () {
  114. console.log('Cannot draw fail2ban log table');
  115. },
  116. success: function (data) {
  117. return process_table_data(data, 'general_syslog');
  118. }
  119. }),
  120. "empty": lang.empty,
  121. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  122. "filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
  123. "sorting": {"enabled": true},
  124. "on": {
  125. "ready.ft.table": function(e, ft){
  126. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  127. $(heading).children('.log-lines').text(function(){
  128. var ft_paging = ft.use(FooTable.Paging)
  129. return ft_paging.totalRows;
  130. })
  131. }
  132. }
  133. });
  134. }
  135. function draw_sogo_logs() {
  136. ft_sogo_logs = FooTable.init('#sogo_log', {
  137. "columns": [
  138. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  139. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  140. {"name":"message","title":lang.message},
  141. ],
  142. "rows": $.ajax({
  143. dataType: 'json',
  144. url: '/api/v1/get/logs/sogo',
  145. jsonp: false,
  146. error: function () {
  147. console.log('Cannot draw sogo log table');
  148. },
  149. success: function (data) {
  150. return process_table_data(data, 'general_syslog');
  151. }
  152. }),
  153. "empty": lang.empty,
  154. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  155. "filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
  156. "sorting": {"enabled": true},
  157. "on": {
  158. "ready.ft.table": function(e, ft){
  159. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  160. $(heading).children('.log-lines').text(function(){
  161. var ft_paging = ft.use(FooTable.Paging)
  162. return ft_paging.totalRows;
  163. })
  164. }
  165. }
  166. });
  167. }
  168. function draw_dovecot_logs() {
  169. ft_dovecot_logs = FooTable.init('#dovecot_log', {
  170. "columns": [
  171. {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  172. {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
  173. {"name":"message","title":lang.message},
  174. ],
  175. "rows": $.ajax({
  176. dataType: 'json',
  177. url: '/api/v1/get/logs/dovecot',
  178. jsonp: false,
  179. error: function () {
  180. console.log('Cannot draw dovecot log table');
  181. },
  182. success: function (data) {
  183. return process_table_data(data, 'general_syslog');
  184. }
  185. }),
  186. "empty": lang.empty,
  187. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  188. "filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
  189. "sorting": {"enabled": true},
  190. "on": {
  191. "ready.ft.table": function(e, ft){
  192. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  193. $(heading).children('.log-lines').text(function(){
  194. var ft_paging = ft.use(FooTable.Paging)
  195. return ft_paging.totalRows;
  196. })
  197. }
  198. }
  199. });
  200. }
  201. function draw_domain_admins() {
  202. ft_domainadmins = FooTable.init('#domainadminstable', {
  203. "columns": [
  204. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  205. {"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
  206. {"name":"selected_domains","title":lang.admin_domains,"breakpoints":"xs sm"},
  207. {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"}},
  208. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  209. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  210. ],
  211. "rows": $.ajax({
  212. dataType: 'json',
  213. url: '/api/v1/get/domain-admin/all',
  214. jsonp: false,
  215. error: function () {
  216. console.log('Cannot draw domain admin table');
  217. },
  218. success: function (data) {
  219. return process_table_data(data, 'domainadminstable');
  220. }
  221. }),
  222. "empty": lang.empty,
  223. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  224. "filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table
  225. },
  226. "sorting": {"enabled": true}
  227. });
  228. }
  229. function draw_fwd_hosts() {
  230. ft_forwardinghoststable = FooTable.init('#forwardinghoststable', {
  231. "columns": [
  232. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  233. {"name":"host","type":"text","title":lang.host,"style":{"width":"250px"}},
  234. {"name":"source","title":lang.source,"breakpoints":"xs sm"},
  235. {"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"}},
  236. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  237. ],
  238. "rows": $.ajax({
  239. dataType: 'json',
  240. url: '/api/v1/get/fwdhost/all',
  241. jsonp: false,
  242. error: function () {
  243. console.log('Cannot draw forwarding hosts table');
  244. },
  245. success: function (data) {
  246. return process_table_data(data, 'forwardinghoststable');
  247. }
  248. }),
  249. "empty": lang.empty,
  250. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  251. "sorting": {"enabled": true}
  252. });
  253. }
  254. function draw_relayhosts() {
  255. ft_relayhoststable = FooTable.init('#relayhoststable', {
  256. "columns": [
  257. {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
  258. {"name":"id","type":"text","title":"ID","style":{"width":"50px"}},
  259. {"name":"hostname","type":"text","title":lang.host,"style":{"width":"250px"}},
  260. {"name":"username","title":lang.username,"breakpoints":"xs sm"},
  261. {"name":"used_by_domains","title":lang.in_use_by, "type": "text","breakpoints":"xs sm"},
  262. {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
  263. {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"280px","width":"280px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
  264. ],
  265. "rows": $.ajax({
  266. dataType: 'json',
  267. url: '/api/v1/get/relayhost/all',
  268. jsonp: false,
  269. error: function () {
  270. console.log('Cannot draw forwarding hosts table');
  271. },
  272. success: function (data) {
  273. return process_table_data(data, 'relayhoststable');
  274. }
  275. }),
  276. "empty": lang.empty,
  277. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  278. "sorting": {"enabled": true}
  279. });
  280. }
  281. function draw_rspamd_history() {
  282. ft_rspamd_history = FooTable.init('#rspamd_history', {
  283. "columns": [
  284. {"name":"unix_time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
  285. {"name": "ip","title": "IP address","breakpoints": "all","style": {"minWidth": 88}},
  286. {"name": "sender_mime","title": "From","breakpoints": "xs sm md","style": {"minWidth": 100}},
  287. {"name": "rcpt_mime","title": "To","breakpoints": "xs sm md","style": {"minWidth": 100}},
  288. {"name": "subject","title": "Subject","breakpoints": "all","style": {"word-break": "break-all","minWidth": 150}},
  289. {"name": "action","title": "Action","style": {"minwidth": 82}},
  290. {"name": "score","title": "Score","style": {"maxWidth": 110},},
  291. {"name": "symbols","title": "Symbols","breakpoints": "all",},
  292. {"name": "size","title": "Msg size","breakpoints": "all","style": {"minwidth": 50},"formatter": function(value){return humanFileSize(value);}},
  293. {"name": "scan_time","title": "Scan time","breakpoints": "all","style": {"maxWidth": 72},},
  294. {"name": "message-id","title": "ID","breakpoints": "all","style": {"minWidth": 130,"overflow": "hidden","textOverflow": "ellipsis","wordBreak": "break-all","whiteSpace": "normal"}},
  295. {"name": "user","title": "Authenticated user","breakpoints": "xs sm md","style": {"minWidth": 100}}
  296. ],
  297. "rows": $.ajax({
  298. dataType: 'json',
  299. url: '/api/v1/get/logs/rspamd-history',
  300. jsonp: false,
  301. error: function () {
  302. console.log('Cannot draw rspamd history table');
  303. },
  304. success: function (data) {
  305. return process_table_data(data, 'rspamd_history');
  306. }
  307. }),
  308. "empty": lang.empty,
  309. "paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
  310. "filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
  311. "sorting": {"enabled": true},
  312. "on": {
  313. "ready.ft.table": function(e, ft){
  314. heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  315. $(heading).children('.log-lines').text(function(){
  316. var ft_paging = ft.use(FooTable.Paging)
  317. return ft_paging.totalRows;
  318. })
  319. }
  320. }
  321. });
  322. }
  323. function process_table_data(data, table) {
  324. if (table == 'rspamd_history') {
  325. $.each(data, function (i, item) {
  326. item.rcpt_mime = item.rcpt_mime.join(",&#8203;");
  327. Object.keys(item.symbols).map(function(key) {
  328. var sym = item.symbols[key];
  329. if (sym.score <= 0) {
  330. sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)'
  331. }
  332. else {
  333. sym.score_formatted = '(<span class="text-danger"><b>' + sym.score + '</b></span>)'
  334. }
  335. var str = '<strong>' + key + '</strong> ' + sym.score_formatted;
  336. if (sym.options) {
  337. str += ' [' + sym.options.join(",") + "]";
  338. }
  339. item.symbols[key].str = str;
  340. });
  341. item.symbols = Object.keys(item.symbols).
  342. map(function(key) {
  343. return item.symbols[key];
  344. }).sort(function(e1, e2) {
  345. return Math.abs(e1.score) < Math.abs(e2.score);
  346. }).map(function(e) {
  347. return e.str;
  348. }).join("<br>\n");
  349. var scan_time = item.time_real.toFixed(3) + ' / ' + item.time_virtual.toFixed(3);
  350. item.scan_time = {
  351. "options": {
  352. "sortValue": item.time_real
  353. },
  354. "value": scan_time
  355. };
  356. if (item.action === 'clean' || item.action === 'no action') {
  357. item.action = "<div class='label label-success'>" + item.action + "</div>";
  358. } else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') {
  359. item.action = "<div class='label label-warning'>" + item.action + "</div>";
  360. } else if (item.action === 'spam' || item.action === 'reject') {
  361. item.action = "<div class='label label-danger'>" + item.action + "</div>";
  362. } else {
  363. item.action = "<div class='label label-info'>" + item.action + "</div>";
  364. }
  365. var score_content;
  366. if (item.score < item.required_score) {
  367. score_content = "[ <span class='text-success'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
  368. } else {
  369. score_content = "[ <span class='text-danger'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
  370. }
  371. item.score = {
  372. "options": {
  373. "sortValue": item.score
  374. },
  375. "value": score_content
  376. };
  377. if (item.user == null) {
  378. item.user = "none";
  379. }
  380. });
  381. } else if (table == 'relayhoststable') {
  382. $.each(data, function (i, item) {
  383. item.action = '<div class="btn-group">' +
  384. '<a href="#" data-toggle="modal" id="miau" data-target="#testRelayhostModal" data-relayhost-id="' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-stats"></span> Test</a>' +
  385. '<a href="/edit.php?relayhost=' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  386. '<a href="#" id="delete_selected" data-id="single-rlshost" data-api-url="delete/relayhost" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  387. '</div>';
  388. item.chkbox = '<input type="checkbox" data-id="rlyhosts" name="multi_select" value="' + item.id + '" />';
  389. });
  390. } else if (table == 'forwardinghoststable') {
  391. $.each(data, function (i, item) {
  392. item.action = '<div class="btn-group">' +
  393. '<a href="#" id="delete_selected" data-id="single-fwdhost" data-api-url="delete/fwdhost" data-item="' + encodeURI(item.host) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  394. '</div>';
  395. if (item.keep_spam == "yes") {
  396. item.keep_spam = lang.no;
  397. }
  398. else {
  399. item.keep_spam = lang.yes;
  400. }
  401. item.chkbox = '<input type="checkbox" data-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
  402. });
  403. } else if (table == 'domainadminstable') {
  404. $.each(data, function (i, item) {
  405. item.chkbox = '<input type="checkbox" data-id="domain_admins" name="multi_select" value="' + item.username + '" />';
  406. item.action = '<div class="btn-group">' +
  407. '<a href="/edit.php?domainadmin=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
  408. '<a href="#" id="delete_selected" data-id="single-domain-admin" data-api-url="delete/domain-admin" data-item="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
  409. '</div>';
  410. });
  411. } else if (table == 'autodiscover_log') {
  412. $.each(data, function (i, item) {
  413. item.ua = '<span style="font-size:small">' + item.ua + '</span>';
  414. if (item.service == "activesync") {
  415. item.service = '<span class="label label-info">ActiveSync</span>';
  416. }
  417. else if (item.service == "imap") {
  418. item.service = '<span class="label label-success">IMAP, SMTP, Cal-/CardDAV</span>';
  419. }
  420. else {
  421. item.service = '<span class="label label-danger">' + item.service + '</span>';
  422. }
  423. });
  424. } else if (table == 'general_syslog') {
  425. $.each(data, function (i, item) {
  426. item.message = escapeHtml(item.message);
  427. var danger_class = ["emerg", "alert", "crit", "err"];
  428. var warning_class = ["warning", "warn"];
  429. var info_class = ["notice", "info", "debug"];
  430. if (jQuery.inArray(item.priority, danger_class) !== -1) {
  431. item.priority = '<span class="label label-danger">' + item.priority + '</span>';
  432. }
  433. else if (jQuery.inArray(item.priority, warning_class) !== -1) {
  434. item.priority = '<span class="label label-warning">' + item.priority + '</span>';
  435. }
  436. else if (jQuery.inArray(item.priority, info_class) !== -1) {
  437. item.priority = '<span class="label label-info">' + item.priority + '</span>';
  438. }
  439. });
  440. }
  441. return data
  442. };
  443. // Initial table drawings
  444. draw_postfix_logs();
  445. draw_autodiscover_logs();
  446. draw_dovecot_logs();
  447. draw_sogo_logs();
  448. draw_fail2ban_logs();
  449. draw_domain_admins();
  450. draw_fwd_hosts();
  451. draw_relayhosts();
  452. draw_rspamd_history();
  453. // Relayhost
  454. $('#testRelayhostModal').on('show.bs.modal', function (e) {
  455. $('#test_relayhost_result').text("-");
  456. button = $(e.relatedTarget)
  457. if (button != null) {
  458. $('#relayhost_id').val(button.data('relayhost-id'));
  459. }
  460. })
  461. $('#test_relayhost').on('click', function (e) {
  462. e.preventDefault();
  463. prev = $('#test_relayhost').text();
  464. $(this).prop("disabled",true);
  465. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  466. $.ajax({
  467. type: 'GET',
  468. url: 'inc/relay_check.php',
  469. dataType: 'text',
  470. data: $('#test_relayhost_form').serialize(),
  471. complete: function (data) {
  472. $('#test_relayhost_result').html(data.responseText);
  473. $('#test_relayhost').prop("disabled",false);
  474. $('#test_relayhost').text(prev);
  475. }
  476. });
  477. })
  478. // DKIM private key modal
  479. $('#showDKIMprivKey').on('show.bs.modal', function (e) {
  480. $('#priv_key_pre').text("-");
  481. p_related = $(e.relatedTarget)
  482. if (p_related != null) {
  483. var decoded_key = Base64.decode((p_related.data('priv-key')));
  484. $('#priv_key_pre').text(decoded_key);
  485. }
  486. })
  487. $('.add_log_lines').on('click', function (e) {
  488. e.preventDefault();
  489. var log_table= $(this).data("table")
  490. var new_nrows = ($(this).data("nrows") - 1)
  491. var post_process = $(this).data("post-process")
  492. var log_url = $(this).data("log-url")
  493. if (log_table === undefined || new_nrows === undefined || post_process === undefined || log_url === undefined) {
  494. console.log("no data-table or data-nrows or log_url or data-post-process attr found");
  495. return;
  496. }
  497. if (ft = FooTable.get($('#' + log_table))) {
  498. var heading = ft.$el.parents('.tab-pane').find('.panel-heading')
  499. var ft_paging = ft.use(FooTable.Paging)
  500. var load_rows = ft_paging.totalRows + '-' + (ft_paging.totalRows + new_nrows)
  501. $.get('/api/v1/get/logs/' + log_url + '/' + load_rows).then(function(data){
  502. if (data.length === undefined) { mailcow_alert_box(lang.no_new_rows, "info"); return; }
  503. var rows = process_table_data(data, post_process);
  504. var rows_now = (ft_paging.totalRows + data.length);
  505. $(heading).children('.log-lines').text(rows_now)
  506. mailcow_alert_box(data.length + lang.additional_rows, "success");
  507. ft.rows.load(rows, true);
  508. });
  509. }
  510. })
  511. // App links
  512. function add_table_row(table_id) {
  513. var row = $('<tr />');
  514. cols = '<td><input class="input-sm form-control" data-id="app_links" type="text" name="app" required></td>';
  515. cols += '<td><input class="input-sm form-control" data-id="app_links" type="text" name="href" required></td>';
  516. cols += '<td><a href="#" role="button" class="btn btn-xs btn-default" type="button">Remove row</a></td>';
  517. row.append(cols);
  518. table_id.append(row);
  519. }
  520. $('#app_link_table').on('click', 'tr a', function (e) {
  521. e.preventDefault();
  522. $(this).parents('tr').remove();
  523. });
  524. $('#add_app_link_row').click(function() {
  525. add_table_row($('#app_link_table'));
  526. });
  527. });
  528. $(window).load(function(){
  529. initial_width = $("#sidebar-admin").width();
  530. $("#scrollbox").css("width", initial_width);
  531. $(window).bind('scroll', function() {
  532. if ($(window).scrollTop() > 70) {
  533. $('#scrollbox').addClass('scrollboxFixed');
  534. } else {
  535. $('#scrollbox').removeClass('scrollboxFixed');
  536. }
  537. });
  538. });
  539. function resizeScrollbox() {
  540. on_resize_width = $("#sidebar-admin").width();
  541. $("#scrollbox").removeAttr("style");
  542. $("#scrollbox").css("width", on_resize_width);
  543. }
  544. $(window).on('resize', resizeScrollbox);
  545. $('a[data-toggle="tab"]').on('shown.bs.tab', resizeScrollbox);