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