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