]> git.proxmox.com Git - pmg-gui.git/blame - js/Utils.js
add MailProcessing Component
[pmg-gui.git] / js / Utils.js
CommitLineData
2c1d504e 1/*global Proxmox */
fe81f069
DM
2Ext.ns('PMG');
3
fe81f069
DM
4console.log("Starting PMG Manager");
5
fe81f069 6
2c7b542d
DM
7Ext.define('PMG.Utils', {
8 singleton: true,
ad834b6f 9
fe81f069
DM
10 // this singleton contains miscellaneous utilities
11
f9b851e8
DM
12 senderText: gettext('Sender'),
13 receiverText: gettext('Receiver'),
ad88af09 14 scoreText: gettext('Score'),
012f0f49 15
7818f0a3
DM
16 user_role_text: {
17 root: gettext('Superuser'),
18 admin: gettext('Administrator'),
19 qmanager: gettext('Quarantine Manager'),
20 audit: gettext('Auditor'),
21 },
22
23 format_user_role: function(role) {
24 return PMG.Utils.user_role_text[role] || role;
25 },
26
c790d2ab
DM
27 oclass_text: {
28 who: gettext('Who Objects'),
29 what: gettext('What Objects'),
30 when: gettext('When Objects'),
076d6a72
DC
31 action: gettext('Action Objects'),
32 from: gettext('From'),
33 to: gettext('To')
34 },
35
36 oclass_icon: {
37 who: '<span class="fa fa-fw fa-user-circle"></span> ',
38 what: '<span class="fa fa-fw fa-cube"></span> ',
39 when: '<span class="fa fa-fw fa-clock-o"></span> ',
40 action: '<span class="fa fa-fw fa-flag"></span> ',
41 from: '<span class="fa fa-fw fa-user-circle"></span> ',
cc6b80b6 42 to: '<span class="fa fa-fw fa-user-circle"></span> '
076d6a72
DC
43 },
44
cf248533
DM
45 mail_status_map: {
46 2: 'delivered',
47 4: 'deferred',
48 5: 'bounced',
49 N: 'rejected',
50 G: 'greylisted',
51 A: 'accepted',
52 B: 'blocked',
53 Q: 'quarantine'
54 },
55
c4ff49f7
DC
56 icon_status_map: {
57 2: {
58 fa: 'check-circle',
59 color: 'green'
60 },
61 4: {
62 fa: 'clock-o',
63 },
64 5: {
65 fa: 'mail-reply',
66 color: 'gray'
67 },
68 N: {
69 fa: 'times-circle'
70 },
71 G: {
72 fa: 'list'
73 },
74 A: {
75 fa: 'check',
76 color: 'green'
77 },
78 B: {
79 fa: 'ban',
80 color: 'red'
81 },
82 Q: {
83 fa: 'cube'
84 }
85 },
86
87 format_status_icon: function(status) {
88 var icon = PMG.Utils.icon_status_map[status] || {};
89 return '<i class="fa fa-' + (icon.fa || 'question-circle') + ' ' +
90 (icon.color || '') + '"></i> ';
91 },
92
076d6a72
DC
93 format_oclass: function(oclass) {
94 var icon = PMG.Utils.oclass_icon[oclass] || '';
95 var text = PMG.Utils.oclass_text[oclass] || oclass;
96 return icon + text;
c790d2ab 97 },
ad834b6f
DM
98
99 rule_direction_text: {
100 0: gettext('In'),
101 1: gettext('Out'),
102 2: gettext('In & Out')
103 },
104
4b7e5c48 105 rule_direction_icon: {
2b97521b
DC
106 0: '<span class="fa fa-fw fa-long-arrow-left"></span> ',
107 1: '<span class="fa fa-fw fa-long-arrow-right"></span> ',
108 2: '<span class="fa fa-fw fa-exchange"></span> '
4b7e5c48
DC
109 },
110
ad834b6f 111 format_rule_direction: function(dir) {
4b7e5c48
DC
112 var icon = PMG.Utils.rule_direction_icon[dir] || '';
113 var text = PMG.Utils.rule_direction_text[dir] || dir;
114 return icon + text;
ad834b6f
DM
115 },
116
012f0f49
DM
117 format_otype: function(otype) {
118 var editor = PMG.Utils.object_editors[otype];
119 if (editor) {
120 return editor.subject;
121 }
122 return 'unknown';
f6b1b3bf
DM
123 },
124
125 format_ldap_protocol: function(p) {
cc6b80b6
DM
126 if (p === undefined) { return 'LDAP'; }
127 if (p === 'ldap') { return 'LDAP'; }
128 if (p === 'ldaps') { return 'LDAPS'; }
f6b1b3bf 129 return 'unknown';
012f0f49
DM
130 },
131
132 object_editors: {
133 1000: {
5f3ec152 134 xtype: 'proxmoxWindowEdit',
012f0f49
DM
135 subdir: 'regex',
136 subject: gettext("Regular Expression"),
f7be608f 137 width: 400,
012f0f49
DM
138 items: [
139 {
140 xtype: 'textfield',
141 name: 'regex',
f7be608f 142 labelWidth: 150,
012f0f49
DM
143 fieldLabel: gettext("Regular Expression")
144 }
145 ]
146 },
5f3ec152
DM
147 1005: {
148 xtype: 'pmgLDAPGroupEditor',
149 subdir: 'ldap',
150 subject: gettext("LDAP Group")
151 },
6c137003
DM
152 1006: {
153 xtype: 'pmgLDAPUserEditor',
154 subdir: 'ldapuser',
155 subject: gettext("LDAP User")
156 },
012f0f49 157 1009: {
5f3ec152 158 xtype: 'proxmoxWindowEdit',
012f0f49
DM
159 subdir: 'receiver_regex',
160 subject: gettext("Regular Expression"),
f7be608f
DM
161 receivertest: true,
162 width: 400,
012f0f49
DM
163 items: [
164 {
165 xtype: 'textfield',
166 name: 'regex',
f7be608f 167 labelWidth: 150,
012f0f49
DM
168 fieldLabel: gettext("Regular Expression")
169 }
170 ]
171 },
172 1001: {
5f3ec152 173 xtype: 'proxmoxWindowEdit',
012f0f49
DM
174 subdir: 'email',
175 subject: gettext("Email"),
f7be608f 176 width: 400,
012f0f49
DM
177 items: [
178 {
179 xtype: 'textfield',
180 name: 'email',
181 fieldLabel: gettext("Email")
182 }
183 ]
184 },
185 1007: {
5f3ec152 186 xtype: 'proxmoxWindowEdit',
012f0f49
DM
187 subdir: 'receiver',
188 subject: gettext("Email"),
f7be608f
DM
189 receivertest: true,
190 width: 400,
012f0f49
DM
191 items: [
192 {
193 xtype: 'textfield',
194 name: 'email',
195 fieldLabel: gettext("Email")
196 }
197 ]
198 },
199 1002: {
5f3ec152 200 xtype: 'proxmoxWindowEdit',
012f0f49
DM
201 subdir: 'domain',
202 subject: gettext("Domain"),
f7be608f 203 width: 400,
012f0f49
DM
204 items: [
205 {
206 xtype: 'textfield',
207 name: 'domain',
208 fieldLabel: gettext("Domain")
209 }
210 ]
211 },
212 1008: {
5f3ec152 213 xtype: 'proxmoxWindowEdit',
012f0f49
DM
214 subdir: 'receiver_domain',
215 subject: gettext("Domain"),
f7be608f
DM
216 receivertest: true,
217 width: 400,
012f0f49
DM
218 items: [
219 {
220 xtype: 'textfield',
221 name: 'domain',
222 fieldLabel: gettext("Domain")
223 }
224 ]
225 },
226 1003: {
5f3ec152 227 xtype: 'proxmoxWindowEdit',
012f0f49
DM
228 subdir: 'ip',
229 subject: gettext("IP Address"),
f7be608f 230 width: 400,
012f0f49
DM
231 items: [
232 {
233 xtype: 'textfield',
234 name: 'ip',
235 fieldLabel: gettext("IP Address")
236 }
237 ]
238 },
239 1004: {
5f3ec152 240 xtype: 'proxmoxWindowEdit',
012f0f49
DM
241 subdir: 'network',
242 subject: gettext("IP Network"),
f7be608f 243 width: 400,
012f0f49
DM
244 items: [
245 {
246 xtype: 'textfield',
247 name: 'cidr',
248 fieldLabel: gettext("IP Network")
249 }
250 ]
b4eee4f7
DM
251 },
252 2000: {
5f3ec152 253 xtype: 'proxmoxWindowEdit',
b4eee4f7
DM
254 subdir: 'timeframe',
255 subject: gettext("TimeFrame"),
256 items: [
257 {
258 xtype: 'timefield',
259 name: 'start',
260 format: 'H:i',
261 fieldLabel: gettext("Start Time")
262 },
263 {
264 xtype: 'timefield',
265 name: 'end',
266 format: 'H:i',
267 fieldLabel: gettext("End Time")
268 }
269 ]
f5de8682 270 },
bed64e74
DC
271 3000: {
272 xtype: 'proxmoxWindowEdit',
273 subdir: 'spamfilter',
274 subject: gettext('Spam Filter'),
275 items: [
276 {
277 xtype: 'proxmoxintegerfield',
278 name: 'spamlevel',
279 allowBlank: false,
280 minValue: 0,
281 fieldLabel: gettext('Level')
cc6b80b6 282 }
bed64e74
DC
283 ]
284 },
3a9b95a7
DC
285 3002: {
286 xtype: 'proxmoxWindowEdit',
287 subdir: 'matchfield',
288 subject: gettext('Match Field'),
50fa6520 289 width: 400,
3a9b95a7
DC
290 items: [
291 {
292 xtype: 'textfield',
293 name: 'field',
50fa6520 294 labelWidth: 150,
3a9b95a7
DC
295 allowBlank: false,
296 fieldLabel: gettext('Field')
297 },
298 {
299 xtype: 'textfield',
50fa6520 300 reference: 'value',
3a9b95a7 301 name: 'value',
50fa6520 302 labelWidth: 150,
3a9b95a7
DC
303 allowBlank: false,
304 fieldLabel: gettext('Value')
305 },
50fa6520
DC
306 {
307 labelWidth: 150,
308 fieldLabel: gettext('Test String'),
309 xtype: 'pmgRegexTester',
cc6b80b6 310 regexFieldReference: 'value'
50fa6520 311 }
3a9b95a7
DC
312 ]
313 },
314 3003: {
315 xtype: 'proxmoxWindowEdit',
316 subdir: 'contenttype',
317 width: 400,
3fb5067f 318 subject: gettext('Content Type Filter'),
3a9b95a7
DC
319 items: [
320 {
321 xtype: 'combobox',
322 displayField: 'text',
323 labelWidth: 150,
324 valueField: 'mimetype',
325 name: 'contenttype',
326 editable: true,
327 queryMode: 'local',
328 store: {
329 autoLoad: true,
330 proxy: {
331 type: 'proxmox',
332 url: '/api2/json/config/mimetypes'
cc6b80b6 333 }
3a9b95a7
DC
334 },
335 fieldLabel: gettext('Content Type'),
336 anyMatch: true,
337 matchFieldWidth: false,
338 listeners: {
339 change: function(cb, value) {
340 var me = this;
341 me.up().down('displayfield').setValue(value);
342 }
343 }
344 },
345 {
346 xtype: 'displayfield',
347 fieldLabel: gettext('Value'),
348 labelWidth: 150,
349 allowBlank: false,
3fb5067f 350 reset: Ext.emptyFn
cc6b80b6 351 }
3a9b95a7
DC
352 ]
353 },
6af39772
DC
354 3004: {
355 xtype: 'proxmoxWindowEdit',
356 subdir: 'filenamefilter',
357 width: 400,
358 subject: gettext('Match Filename'),
359 items: [
360 {
361 xtype: 'textfield',
362 name: 'filename',
363 reference: 'filename',
364 fieldLabel: gettext('Filename'),
365 labelWidth: 150,
366 allowBlank: false
367 },
368 {
369 labelWidth: 150,
370 fieldLabel: gettext('Test String'),
371 wholeMatch: true,
372 xtype: 'pmgRegexTester',
373 regexFieldReference: 'filename'
374 }
375 ]
376 },
e234e99d
DC
377 3005: {
378 xtype: 'proxmoxWindowEdit',
379 subdir: 'archivefilter',
380 width: 400,
381 subject: gettext('Archive Filter'),
382 items: [
383 {
384 xtype: 'combobox',
385 displayField: 'text',
386 labelWidth: 150,
387 valueField: 'mimetype',
388 name: 'contenttype',
389 editable: true,
390 queryMode: 'local',
391 store: {
392 autoLoad: true,
393 proxy: {
394 type: 'proxmox',
395 url: '/api2/json/config/mimetypes'
cc6b80b6 396 }
e234e99d
DC
397 },
398 fieldLabel: gettext('Content Type'),
399 anyMatch: true,
400 matchFieldWidth: false,
401 listeners: {
402 change: function(cb, value) {
403 var me = this;
404 me.up().down('displayfield').setValue(value);
405 }
406 }
407 },
408 {
409 xtype: 'displayfield',
410 fieldLabel: gettext('Value'),
411 labelWidth: 150,
412 allowBlank: false,
413 reset: Ext.emptyFn
414 }
415 ]
416 },
f5de8682 417 4005: {
5f3ec152 418 xtype: 'proxmoxWindowEdit',
f5de8682
DM
419 subdir: 'bcc',
420 subject: gettext('BCC'),
421 width: 400,
422 items: [
423 {
424 xtype: 'textfield',
425 name: 'name',
426 allowBlank: false,
427 fieldLabel: gettext('Name')
428 },
429 {
430 xtype: 'textareafield',
431 name: 'info',
432 fieldLabel: gettext("Description")
433 },
434 {
435 xtype: 'textfield',
436 name: 'target',
437 allowBlank: false,
438 fieldLabel: gettext("Target")
439 },
440 {
441 xtype: 'proxmoxcheckbox',
442 checked: true,
443 name: 'original',
444 fieldLabel: gettext("send orig. Mail")
445 }
446 ]
447
012f0f49
DM
448 }
449 },
ad834b6f 450
e653eb82
DM
451 openVNCViewer: function(consoletype, nodename) {
452 var url = Ext.urlEncode({
453 console: consoletype, // upgrade or shell
454 novnc: 1,
455 node: nodename
456 });
457 var nw = window.open("?" + url, '_blank',
458 "innerWidth=745,innerheight=427");
459 nw.focus();
460 },
461
f1ab2a14
DC
462 updateLoginData: function(data) {
463 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
464 Proxmox.UserName = data.username;
465 Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true );
466 },
467
258d48b5
DM
468 quarantineActionExtracted: false,
469
470 extractQuarantineAction: function() {
471
cc6b80b6 472 if (PMG.Utils.quarantineActionExtracted) { return; }
258d48b5
DM
473
474 PMG.Utils.quarantineActionExtracted = true;
475
476 var qs = Ext.Object.fromQueryString(location.search);
477
478 var cselect = qs.cselect;
479 var action = qs.action;
480 var ticket = qs.ticket;
481
482 delete qs.cselect;
483 delete qs.action;
484 delete qs.ticket;
485
486 var newsearch = Ext.Object.toQueryString(qs);
487
488 var newurl = location.protocol + "//" + location.host + location.pathname;
cc6b80b6 489 if (newsearch) { newurl += '?' + newsearch; }
258d48b5
DM
490 newurl += location.hash;
491
492 if (window.history) {
493 window.history.pushState({ path:newurl }, '', newurl);
494 }
495
207471c0 496 if (action || cselect) {
258d48b5
DM
497 return { action: action, cselect: cselect };
498 }
499 },
500
cf5268ca
DC
501 doQuarantineAction: function(action, id, callback) {
502 Proxmox.Utils.API2Request({
503 url: '/quarantine/content/',
504 params: {
505 action: action,
506 id: id
507 },
508 method: 'POST',
509 failure: function(response, opts) {
510 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
511 },
512 success: function(response, opts) {
2fa0b505
DC
513 var win = Ext.create('Ext.window.MessageBox',{
514 closeAction: 'destroy'
515 }).show({
cf5268ca
DC
516 title: gettext('Info'),
517 message: "Action '" + action + ' ' +
518 id + "' successful",
519 buttons: Ext.Msg.OK,
520 icon: Ext.MessageBox.INFO
521 });
522
523 if (Ext.isFunction(callback)) {
524 callback();
525 }
526 }
527 });
528 },
529
530 sender_renderer: function(value, metaData, rec) {
531 var subject = Ext.htmlEncode(value);
532 var from = Ext.htmlEncode(rec.data.from);
533 var sender = Ext.htmlEncode(rec.data.sender);
534 if (sender) {
535 from = Ext.String.format(gettext("{0} on behalf of {1}"),
536 sender, from);
537 }
538 return '<small>' + from + '</small><br>' + subject;
539 },
540
fe81f069
DM
541 constructor: function() {
542 var me = this;
fe81f069 543
2c7b542d 544 // do whatever you want here
fe81f069
DM
545 }
546});