]> git.proxmox.com Git - pmg-gui.git/blob - js/Utils.js
UserView.js: display role
[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 object_editors: {
133 1000: {
134 xtype: 'proxmoxWindowEdit',
135 subdir: 'regex',
136 subject: gettext("Regular Expression"),
137 width: 400,
138 items: [
139 {
140 xtype: 'textfield',
141 name: 'regex',
142 labelWidth: 150,
143 fieldLabel: gettext("Regular Expression")
144 }
145 ]
146 },
147 1005: {
148 xtype: 'pmgLDAPGroupEditor',
149 subdir: 'ldap',
150 subject: gettext("LDAP Group")
151 },
152 1006: {
153 xtype: 'pmgLDAPUserEditor',
154 subdir: 'ldapuser',
155 subject: gettext("LDAP User")
156 },
157 1009: {
158 xtype: 'proxmoxWindowEdit',
159 subdir: 'receiver_regex',
160 subject: gettext("Regular Expression"),
161 receivertest: true,
162 width: 400,
163 items: [
164 {
165 xtype: 'textfield',
166 name: 'regex',
167 labelWidth: 150,
168 fieldLabel: gettext("Regular Expression")
169 }
170 ]
171 },
172 1001: {
173 xtype: 'proxmoxWindowEdit',
174 subdir: 'email',
175 subject: gettext("Email"),
176 width: 400,
177 items: [
178 {
179 xtype: 'textfield',
180 name: 'email',
181 fieldLabel: gettext("Email")
182 }
183 ]
184 },
185 1007: {
186 xtype: 'proxmoxWindowEdit',
187 subdir: 'receiver',
188 subject: gettext("Email"),
189 receivertest: true,
190 width: 400,
191 items: [
192 {
193 xtype: 'textfield',
194 name: 'email',
195 fieldLabel: gettext("Email")
196 }
197 ]
198 },
199 1002: {
200 xtype: 'proxmoxWindowEdit',
201 subdir: 'domain',
202 subject: gettext("Domain"),
203 width: 400,
204 items: [
205 {
206 xtype: 'textfield',
207 name: 'domain',
208 fieldLabel: gettext("Domain")
209 }
210 ]
211 },
212 1008: {
213 xtype: 'proxmoxWindowEdit',
214 subdir: 'receiver_domain',
215 subject: gettext("Domain"),
216 receivertest: true,
217 width: 400,
218 items: [
219 {
220 xtype: 'textfield',
221 name: 'domain',
222 fieldLabel: gettext("Domain")
223 }
224 ]
225 },
226 1003: {
227 xtype: 'proxmoxWindowEdit',
228 subdir: 'ip',
229 subject: gettext("IP Address"),
230 width: 400,
231 items: [
232 {
233 xtype: 'textfield',
234 name: 'ip',
235 fieldLabel: gettext("IP Address")
236 }
237 ]
238 },
239 1004: {
240 xtype: 'proxmoxWindowEdit',
241 subdir: 'network',
242 subject: gettext("IP Network"),
243 width: 400,
244 items: [
245 {
246 xtype: 'textfield',
247 name: 'cidr',
248 fieldLabel: gettext("IP Network")
249 }
250 ]
251 },
252 2000: {
253 xtype: 'proxmoxWindowEdit',
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 ]
270 },
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')
282 }
283 ]
284 },
285 3002: {
286 xtype: 'proxmoxWindowEdit',
287 subdir: 'matchfield',
288 subject: gettext('Match Field'),
289 width: 400,
290 items: [
291 {
292 xtype: 'textfield',
293 name: 'field',
294 labelWidth: 150,
295 allowBlank: false,
296 fieldLabel: gettext('Field')
297 },
298 {
299 xtype: 'textfield',
300 reference: 'value',
301 name: 'value',
302 labelWidth: 150,
303 allowBlank: false,
304 fieldLabel: gettext('Value')
305 },
306 {
307 labelWidth: 150,
308 fieldLabel: gettext('Test String'),
309 xtype: 'pmgRegexTester',
310 regexFieldReference: 'value'
311 }
312 ]
313 },
314 3003: {
315 xtype: 'proxmoxWindowEdit',
316 subdir: 'contenttype',
317 width: 400,
318 subject: gettext('Content Type Filter'),
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'
333 }
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,
350 reset: Ext.emptyFn
351 }
352 ]
353 },
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 },
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'
396 }
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 },
417 4005: {
418 xtype: 'proxmoxWindowEdit',
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
448 }
449 },
450
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
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
468 quarantineActionExtracted: false,
469
470 extractQuarantineAction: function() {
471
472 if (PMG.Utils.quarantineActionExtracted) { return; }
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;
489 if (newsearch) { newurl += '?' + newsearch; }
490 newurl += location.hash;
491
492 if (window.history) {
493 window.history.pushState({ path:newurl }, '', newurl);
494 }
495
496 if (action || cselect) {
497 return { action: action, cselect: cselect };
498 }
499 },
500
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) {
513 var win = Ext.create('Ext.window.MessageBox',{
514 closeAction: 'destroy'
515 }).show({
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
541 constructor: function() {
542 var me = this;
543
544 // do whatever you want here
545 }
546 });