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