]>
Commit | Line | Data |
---|---|---|
2c1d504e | 1 | /*global Proxmox */ |
fe81f069 DM |
2 | Ext.ns('PMG'); |
3 | ||
fe81f069 DM |
4 | console.log("Starting PMG Manager"); |
5 | ||
fe81f069 | 6 | |
2c7b542d DM |
7 | Ext.define('PMG.Utils', { |
8 | singleton: true, | |
ad834b6f | 9 | |
fe81f069 DM |
10 | // this singleton contains miscellaneous utilities |
11 | ||
f9b851e8 DM |
12 | senderText: gettext('Sender'), |
13 | receiverText: gettext('Receiver'), | |
ad88af09 | 14 | scoreText: gettext('Score'), |
012f0f49 | 15 | |
c790d2ab DM |
16 | oclass_text: { |
17 | who: gettext('Who Objects'), | |
18 | what: gettext('What Objects'), | |
19 | when: gettext('When Objects'), | |
076d6a72 DC |
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> ', | |
cc6b80b6 | 31 | to: '<span class="fa fa-fw fa-user-circle"></span> ' |
076d6a72 DC |
32 | }, |
33 | ||
cf248533 DM |
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 | ||
c4ff49f7 DC |
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 | ||
076d6a72 DC |
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; | |
c790d2ab | 86 | }, |
ad834b6f DM |
87 | |
88 | rule_direction_text: { | |
89 | 0: gettext('In'), | |
90 | 1: gettext('Out'), | |
91 | 2: gettext('In & Out') | |
92 | }, | |
93 | ||
4b7e5c48 | 94 | rule_direction_icon: { |
2b97521b DC |
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> ' | |
4b7e5c48 DC |
98 | }, |
99 | ||
ad834b6f | 100 | format_rule_direction: function(dir) { |
4b7e5c48 DC |
101 | var icon = PMG.Utils.rule_direction_icon[dir] || ''; |
102 | var text = PMG.Utils.rule_direction_text[dir] || dir; | |
103 | return icon + text; | |
ad834b6f DM |
104 | }, |
105 | ||
012f0f49 DM |
106 | format_otype: function(otype) { |
107 | var editor = PMG.Utils.object_editors[otype]; | |
108 | if (editor) { | |
109 | return editor.subject; | |
110 | } | |
111 | return 'unknown'; | |
f6b1b3bf DM |
112 | }, |
113 | ||
114 | format_ldap_protocol: function(p) { | |
cc6b80b6 DM |
115 | if (p === undefined) { return 'LDAP'; } |
116 | if (p === 'ldap') { return 'LDAP'; } | |
117 | if (p === 'ldaps') { return 'LDAPS'; } | |
f6b1b3bf | 118 | return 'unknown'; |
012f0f49 DM |
119 | }, |
120 | ||
121 | object_editors: { | |
122 | 1000: { | |
5f3ec152 | 123 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
124 | subdir: 'regex', |
125 | subject: gettext("Regular Expression"), | |
f7be608f | 126 | width: 400, |
012f0f49 DM |
127 | items: [ |
128 | { | |
129 | xtype: 'textfield', | |
130 | name: 'regex', | |
f7be608f | 131 | labelWidth: 150, |
012f0f49 DM |
132 | fieldLabel: gettext("Regular Expression") |
133 | } | |
134 | ] | |
135 | }, | |
5f3ec152 DM |
136 | 1005: { |
137 | xtype: 'pmgLDAPGroupEditor', | |
138 | subdir: 'ldap', | |
139 | subject: gettext("LDAP Group") | |
140 | }, | |
6c137003 DM |
141 | 1006: { |
142 | xtype: 'pmgLDAPUserEditor', | |
143 | subdir: 'ldapuser', | |
144 | subject: gettext("LDAP User") | |
145 | }, | |
012f0f49 | 146 | 1009: { |
5f3ec152 | 147 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
148 | subdir: 'receiver_regex', |
149 | subject: gettext("Regular Expression"), | |
f7be608f DM |
150 | receivertest: true, |
151 | width: 400, | |
012f0f49 DM |
152 | items: [ |
153 | { | |
154 | xtype: 'textfield', | |
155 | name: 'regex', | |
f7be608f | 156 | labelWidth: 150, |
012f0f49 DM |
157 | fieldLabel: gettext("Regular Expression") |
158 | } | |
159 | ] | |
160 | }, | |
161 | 1001: { | |
5f3ec152 | 162 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
163 | subdir: 'email', |
164 | subject: gettext("Email"), | |
f7be608f | 165 | width: 400, |
012f0f49 DM |
166 | items: [ |
167 | { | |
168 | xtype: 'textfield', | |
169 | name: 'email', | |
170 | fieldLabel: gettext("Email") | |
171 | } | |
172 | ] | |
173 | }, | |
174 | 1007: { | |
5f3ec152 | 175 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
176 | subdir: 'receiver', |
177 | subject: gettext("Email"), | |
f7be608f DM |
178 | receivertest: true, |
179 | width: 400, | |
012f0f49 DM |
180 | items: [ |
181 | { | |
182 | xtype: 'textfield', | |
183 | name: 'email', | |
184 | fieldLabel: gettext("Email") | |
185 | } | |
186 | ] | |
187 | }, | |
188 | 1002: { | |
5f3ec152 | 189 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
190 | subdir: 'domain', |
191 | subject: gettext("Domain"), | |
f7be608f | 192 | width: 400, |
012f0f49 DM |
193 | items: [ |
194 | { | |
195 | xtype: 'textfield', | |
196 | name: 'domain', | |
197 | fieldLabel: gettext("Domain") | |
198 | } | |
199 | ] | |
200 | }, | |
201 | 1008: { | |
5f3ec152 | 202 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
203 | subdir: 'receiver_domain', |
204 | subject: gettext("Domain"), | |
f7be608f DM |
205 | receivertest: true, |
206 | width: 400, | |
012f0f49 DM |
207 | items: [ |
208 | { | |
209 | xtype: 'textfield', | |
210 | name: 'domain', | |
211 | fieldLabel: gettext("Domain") | |
212 | } | |
213 | ] | |
214 | }, | |
215 | 1003: { | |
5f3ec152 | 216 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
217 | subdir: 'ip', |
218 | subject: gettext("IP Address"), | |
f7be608f | 219 | width: 400, |
012f0f49 DM |
220 | items: [ |
221 | { | |
222 | xtype: 'textfield', | |
223 | name: 'ip', | |
224 | fieldLabel: gettext("IP Address") | |
225 | } | |
226 | ] | |
227 | }, | |
228 | 1004: { | |
5f3ec152 | 229 | xtype: 'proxmoxWindowEdit', |
012f0f49 DM |
230 | subdir: 'network', |
231 | subject: gettext("IP Network"), | |
f7be608f | 232 | width: 400, |
012f0f49 DM |
233 | items: [ |
234 | { | |
235 | xtype: 'textfield', | |
236 | name: 'cidr', | |
237 | fieldLabel: gettext("IP Network") | |
238 | } | |
239 | ] | |
b4eee4f7 DM |
240 | }, |
241 | 2000: { | |
5f3ec152 | 242 | xtype: 'proxmoxWindowEdit', |
b4eee4f7 DM |
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 | ] | |
f5de8682 | 259 | }, |
bed64e74 DC |
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') | |
cc6b80b6 | 271 | } |
bed64e74 DC |
272 | ] |
273 | }, | |
3a9b95a7 DC |
274 | 3002: { |
275 | xtype: 'proxmoxWindowEdit', | |
276 | subdir: 'matchfield', | |
277 | subject: gettext('Match Field'), | |
50fa6520 | 278 | width: 400, |
3a9b95a7 DC |
279 | items: [ |
280 | { | |
281 | xtype: 'textfield', | |
282 | name: 'field', | |
50fa6520 | 283 | labelWidth: 150, |
3a9b95a7 DC |
284 | allowBlank: false, |
285 | fieldLabel: gettext('Field') | |
286 | }, | |
287 | { | |
288 | xtype: 'textfield', | |
50fa6520 | 289 | reference: 'value', |
3a9b95a7 | 290 | name: 'value', |
50fa6520 | 291 | labelWidth: 150, |
3a9b95a7 DC |
292 | allowBlank: false, |
293 | fieldLabel: gettext('Value') | |
294 | }, | |
50fa6520 DC |
295 | { |
296 | labelWidth: 150, | |
297 | fieldLabel: gettext('Test String'), | |
298 | xtype: 'pmgRegexTester', | |
cc6b80b6 | 299 | regexFieldReference: 'value' |
50fa6520 | 300 | } |
3a9b95a7 DC |
301 | ] |
302 | }, | |
303 | 3003: { | |
304 | xtype: 'proxmoxWindowEdit', | |
305 | subdir: 'contenttype', | |
306 | width: 400, | |
3fb5067f | 307 | subject: gettext('Content Type Filter'), |
3a9b95a7 DC |
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' | |
cc6b80b6 | 322 | } |
3a9b95a7 DC |
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, | |
3fb5067f | 339 | reset: Ext.emptyFn |
cc6b80b6 | 340 | } |
3a9b95a7 DC |
341 | ] |
342 | }, | |
6af39772 DC |
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 | }, | |
e234e99d DC |
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' | |
cc6b80b6 | 385 | } |
e234e99d DC |
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 | }, | |
f5de8682 | 406 | 4005: { |
5f3ec152 | 407 | xtype: 'proxmoxWindowEdit', |
f5de8682 DM |
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 | ||
012f0f49 DM |
437 | } |
438 | }, | |
ad834b6f | 439 | |
e653eb82 DM |
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 | ||
f1ab2a14 DC |
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 | ||
258d48b5 DM |
457 | quarantineActionExtracted: false, |
458 | ||
459 | extractQuarantineAction: function() { | |
460 | ||
cc6b80b6 | 461 | if (PMG.Utils.quarantineActionExtracted) { return; } |
258d48b5 DM |
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; | |
cc6b80b6 | 478 | if (newsearch) { newurl += '?' + newsearch; } |
258d48b5 DM |
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 | ||
cf5268ca DC |
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 | ||
fe81f069 DM |
528 | constructor: function() { |
529 | var me = this; | |
fe81f069 | 530 | |
2c7b542d | 531 | // do whatever you want here |
fe81f069 DM |
532 | } |
533 | }); |