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