]> git.proxmox.com Git - pmg-gui.git/blob - js/Utils.js
add virusfilter
[pmg-gui.git] / js / Utils.js
1 /*global Proxmox */
2 Ext.ns('PMG');
3
4 console.log("Starting PMG Manager");
5
6
7 Ext.define('PMG.Utils', {
8 singleton: true,
9
10 // this singleton contains miscellaneous utilities
11
12 senderText: gettext('Sender'),
13 receiverText: gettext('Receiver'),
14 scoreText: gettext('Score'),
15
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
27 oclass_text: {
28 who: gettext('Who Objects'),
29 what: gettext('What Objects'),
30 when: gettext('When Objects'),
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> ',
42 to: '<span class="fa fa-fw fa-user-circle"></span> '
43 },
44
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
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
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;
97 },
98
99 rule_direction_text: {
100 0: gettext('In'),
101 1: gettext('Out'),
102 2: gettext('In & Out')
103 },
104
105 rule_direction_icon: {
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> '
109 },
110
111 format_rule_direction: function(dir) {
112 var icon = PMG.Utils.rule_direction_icon[dir] || '';
113 var text = PMG.Utils.rule_direction_text[dir] || dir;
114 return icon + text;
115 },
116
117 format_otype: function(otype) {
118 var editor = PMG.Utils.object_editors[otype];
119 if (editor) {
120 return editor.subject;
121 }
122 return 'unknown';
123 },
124
125 format_ldap_protocol: function(p) {
126 if (p === undefined) { return 'LDAP'; }
127 if (p === 'ldap') { return 'LDAP'; }
128 if (p === 'ldaps') { return 'LDAPS'; }
129 return 'unknown';
130 },
131
132 convert_field_to_per_min: function(value, record) {
133 return (value/(record.data.timespan/60));
134 },
135
136 object_editors: {
137 1000: {
138 xtype: 'proxmoxWindowEdit',
139 subdir: 'regex',
140 subject: gettext("Regular Expression"),
141 width: 400,
142 items: [
143 {
144 xtype: 'textfield',
145 name: 'regex',
146 labelWidth: 150,
147 fieldLabel: gettext("Regular Expression")
148 }
149 ]
150 },
151 1005: {
152 xtype: 'pmgLDAPGroupEditor',
153 subdir: 'ldap',
154 subject: gettext("LDAP Group")
155 },
156 1006: {
157 xtype: 'pmgLDAPUserEditor',
158 subdir: 'ldapuser',
159 subject: gettext("LDAP User")
160 },
161 1009: {
162 xtype: 'proxmoxWindowEdit',
163 subdir: 'receiver_regex',
164 subject: gettext("Regular Expression"),
165 receivertest: true,
166 width: 400,
167 items: [
168 {
169 xtype: 'textfield',
170 name: 'regex',
171 labelWidth: 150,
172 fieldLabel: gettext("Regular Expression")
173 }
174 ]
175 },
176 1001: {
177 xtype: 'proxmoxWindowEdit',
178 subdir: 'email',
179 subject: gettext("Email"),
180 width: 400,
181 items: [
182 {
183 xtype: 'textfield',
184 name: 'email',
185 fieldLabel: gettext("Email")
186 }
187 ]
188 },
189 1007: {
190 xtype: 'proxmoxWindowEdit',
191 subdir: 'receiver',
192 subject: gettext("Email"),
193 receivertest: true,
194 width: 400,
195 items: [
196 {
197 xtype: 'textfield',
198 name: 'email',
199 fieldLabel: gettext("Email")
200 }
201 ]
202 },
203 1002: {
204 xtype: 'proxmoxWindowEdit',
205 subdir: 'domain',
206 subject: gettext("Domain"),
207 width: 400,
208 items: [
209 {
210 xtype: 'textfield',
211 name: 'domain',
212 fieldLabel: gettext("Domain")
213 }
214 ]
215 },
216 1008: {
217 xtype: 'proxmoxWindowEdit',
218 subdir: 'receiver_domain',
219 subject: gettext("Domain"),
220 receivertest: true,
221 width: 400,
222 items: [
223 {
224 xtype: 'textfield',
225 name: 'domain',
226 fieldLabel: gettext("Domain")
227 }
228 ]
229 },
230 1003: {
231 xtype: 'proxmoxWindowEdit',
232 subdir: 'ip',
233 subject: gettext("IP Address"),
234 width: 400,
235 items: [
236 {
237 xtype: 'textfield',
238 name: 'ip',
239 fieldLabel: gettext("IP Address")
240 }
241 ]
242 },
243 1004: {
244 xtype: 'proxmoxWindowEdit',
245 subdir: 'network',
246 subject: gettext("IP Network"),
247 width: 400,
248 items: [
249 {
250 xtype: 'textfield',
251 name: 'cidr',
252 fieldLabel: gettext("IP Network")
253 }
254 ]
255 },
256 2000: {
257 xtype: 'proxmoxWindowEdit',
258 subdir: 'timeframe',
259 subject: gettext("TimeFrame"),
260 items: [
261 {
262 xtype: 'timefield',
263 name: 'start',
264 format: 'H:i',
265 fieldLabel: gettext("Start Time")
266 },
267 {
268 xtype: 'timefield',
269 name: 'end',
270 format: 'H:i',
271 fieldLabel: gettext("End Time")
272 }
273 ]
274 },
275 3000: {
276 xtype: 'proxmoxWindowEdit',
277 subdir: 'spamfilter',
278 subject: gettext('Spam Filter'),
279 items: [
280 {
281 xtype: 'proxmoxintegerfield',
282 name: 'spamlevel',
283 allowBlank: false,
284 minValue: 0,
285 fieldLabel: gettext('Level')
286 }
287 ]
288 },
289 3001: {
290 xtype: 'proxmoxWindowEdit',
291 subdir: 'virusfilter',
292 subject: gettext('Virus Filter'),
293 uneditable: true,
294 // there are no parameters to give, so we simply submit it
295 listeners: {
296 show: function(win) {
297 win.submit();
298 }
299 }
300 },
301 3002: {
302 xtype: 'proxmoxWindowEdit',
303 subdir: 'matchfield',
304 subject: gettext('Match Field'),
305 width: 400,
306 items: [
307 {
308 xtype: 'textfield',
309 name: 'field',
310 labelWidth: 150,
311 allowBlank: false,
312 fieldLabel: gettext('Field')
313 },
314 {
315 xtype: 'textfield',
316 reference: 'value',
317 name: 'value',
318 labelWidth: 150,
319 allowBlank: false,
320 fieldLabel: gettext('Value')
321 },
322 {
323 labelWidth: 150,
324 fieldLabel: gettext('Test String'),
325 xtype: 'pmgRegexTester',
326 regexFieldReference: 'value'
327 }
328 ]
329 },
330 3003: {
331 xtype: 'proxmoxWindowEdit',
332 subdir: 'contenttype',
333 width: 400,
334 subject: gettext('Content Type Filter'),
335 items: [
336 {
337 xtype: 'combobox',
338 displayField: 'text',
339 labelWidth: 150,
340 valueField: 'mimetype',
341 name: 'contenttype',
342 editable: true,
343 queryMode: 'local',
344 store: {
345 autoLoad: true,
346 proxy: {
347 type: 'proxmox',
348 url: '/api2/json/config/mimetypes'
349 }
350 },
351 fieldLabel: gettext('Content Type'),
352 anyMatch: true,
353 matchFieldWidth: false,
354 listeners: {
355 change: function(cb, value) {
356 var me = this;
357 me.up().down('displayfield').setValue(value);
358 }
359 }
360 },
361 {
362 xtype: 'displayfield',
363 fieldLabel: gettext('Value'),
364 labelWidth: 150,
365 allowBlank: false,
366 reset: Ext.emptyFn
367 }
368 ]
369 },
370 3004: {
371 xtype: 'proxmoxWindowEdit',
372 subdir: 'filenamefilter',
373 width: 400,
374 subject: gettext('Match Filename'),
375 items: [
376 {
377 xtype: 'textfield',
378 name: 'filename',
379 reference: 'filename',
380 fieldLabel: gettext('Filename'),
381 labelWidth: 150,
382 allowBlank: false
383 },
384 {
385 labelWidth: 150,
386 fieldLabel: gettext('Test String'),
387 wholeMatch: true,
388 xtype: 'pmgRegexTester',
389 regexFieldReference: 'filename'
390 }
391 ]
392 },
393 3005: {
394 xtype: 'proxmoxWindowEdit',
395 subdir: 'archivefilter',
396 width: 400,
397 subject: gettext('Archive Filter'),
398 items: [
399 {
400 xtype: 'combobox',
401 displayField: 'text',
402 labelWidth: 150,
403 valueField: 'mimetype',
404 name: 'contenttype',
405 editable: true,
406 queryMode: 'local',
407 store: {
408 autoLoad: true,
409 proxy: {
410 type: 'proxmox',
411 url: '/api2/json/config/mimetypes'
412 }
413 },
414 fieldLabel: gettext('Content Type'),
415 anyMatch: true,
416 matchFieldWidth: false,
417 listeners: {
418 change: function(cb, value) {
419 var me = this;
420 me.up().down('displayfield').setValue(value);
421 }
422 }
423 },
424 {
425 xtype: 'displayfield',
426 fieldLabel: gettext('Value'),
427 labelWidth: 150,
428 allowBlank: false,
429 reset: Ext.emptyFn
430 }
431 ]
432 },
433 4005: {
434 xtype: 'proxmoxWindowEdit',
435 subdir: 'bcc',
436 subject: gettext('BCC'),
437 width: 400,
438 items: [
439 {
440 xtype: 'textfield',
441 name: 'name',
442 allowBlank: false,
443 fieldLabel: gettext('Name')
444 },
445 {
446 xtype: 'textareafield',
447 name: 'info',
448 fieldLabel: gettext("Description")
449 },
450 {
451 xtype: 'textfield',
452 name: 'target',
453 allowBlank: false,
454 fieldLabel: gettext("Target")
455 },
456 {
457 xtype: 'proxmoxcheckbox',
458 checked: true,
459 name: 'original',
460 fieldLabel: gettext("send orig. Mail")
461 }
462 ]
463
464 }
465 },
466
467 openVNCViewer: function(consoletype, nodename) {
468 var url = Ext.urlEncode({
469 console: consoletype, // upgrade or shell
470 novnc: 1,
471 node: nodename
472 });
473 var nw = window.open("?" + url, '_blank',
474 "innerWidth=745,innerheight=427");
475 nw.focus();
476 },
477
478 updateLoginData: function(data) {
479 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
480 Proxmox.UserName = data.username;
481 Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true );
482 },
483
484 quarantineActionExtracted: false,
485
486 extractQuarantineAction: function() {
487
488 if (PMG.Utils.quarantineActionExtracted) { return; }
489
490 PMG.Utils.quarantineActionExtracted = true;
491
492 var qs = Ext.Object.fromQueryString(location.search);
493
494 var cselect = qs.cselect;
495 var action = qs.action;
496 var ticket = qs.ticket;
497
498 delete qs.cselect;
499 delete qs.action;
500 delete qs.ticket;
501
502 var newsearch = Ext.Object.toQueryString(qs);
503
504 var newurl = location.protocol + "//" + location.host + location.pathname;
505 if (newsearch) { newurl += '?' + newsearch; }
506 newurl += location.hash;
507
508 if (window.history) {
509 window.history.pushState({ path:newurl }, '', newurl);
510 }
511
512 if (action || cselect) {
513 return { action: action, cselect: cselect };
514 }
515 },
516
517 doQuarantineAction: function(action, id, callback) {
518 Proxmox.Utils.API2Request({
519 url: '/quarantine/content/',
520 params: {
521 action: action,
522 id: id
523 },
524 method: 'POST',
525 failure: function(response, opts) {
526 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
527 },
528 success: function(response, opts) {
529 var win = Ext.create('Ext.window.MessageBox',{
530 closeAction: 'destroy'
531 }).show({
532 title: gettext('Info'),
533 message: "Action '" + action + ' ' +
534 id + "' successful",
535 buttons: Ext.Msg.OK,
536 icon: Ext.MessageBox.INFO
537 });
538
539 if (Ext.isFunction(callback)) {
540 callback();
541 }
542 }
543 });
544 },
545
546 sender_renderer: function(value, metaData, rec) {
547 var subject = Ext.htmlEncode(value);
548 var from = Ext.htmlEncode(rec.data.from);
549 var sender = Ext.htmlEncode(rec.data.sender);
550 if (sender) {
551 from = Ext.String.format(gettext("{0} on behalf of {1}"),
552 sender, from);
553 }
554 return '<small>' + from + '</small><br>' + subject;
555 },
556
557 constructor: function() {
558 var me = this;
559
560 // do whatever you want here
561 }
562 });