]> git.proxmox.com Git - pmg-gui.git/blob - js/Utils.js
change Content Type text and use emptyFn for reset for displayfield
[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 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;
37 },
38
39 rule_direction_text: {
40 0: gettext('In'),
41 1: gettext('Out'),
42 2: gettext('In & Out')
43 },
44
45 rule_direction_icon: {
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> '
49 },
50
51 format_rule_direction: function(dir) {
52 var icon = PMG.Utils.rule_direction_icon[dir] || '';
53 var text = PMG.Utils.rule_direction_text[dir] || dir;
54 return icon + text;
55 },
56
57 format_otype: function(otype) {
58 var editor = PMG.Utils.object_editors[otype];
59 if (editor) {
60 return editor.subject;
61 }
62 return 'unknown';
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';
70 },
71
72 object_editors: {
73 1000: {
74 xtype: 'proxmoxWindowEdit',
75 subdir: 'regex',
76 subject: gettext("Regular Expression"),
77 width: 400,
78 items: [
79 {
80 xtype: 'textfield',
81 name: 'regex',
82 labelWidth: 150,
83 fieldLabel: gettext("Regular Expression")
84 }
85 ]
86 },
87 1005: {
88 xtype: 'pmgLDAPGroupEditor',
89 subdir: 'ldap',
90 subject: gettext("LDAP Group")
91 },
92 1006: {
93 xtype: 'pmgLDAPUserEditor',
94 subdir: 'ldapuser',
95 subject: gettext("LDAP User")
96 },
97 1009: {
98 xtype: 'proxmoxWindowEdit',
99 subdir: 'receiver_regex',
100 subject: gettext("Regular Expression"),
101 receivertest: true,
102 width: 400,
103 items: [
104 {
105 xtype: 'textfield',
106 name: 'regex',
107 labelWidth: 150,
108 fieldLabel: gettext("Regular Expression")
109 }
110 ]
111 },
112 1001: {
113 xtype: 'proxmoxWindowEdit',
114 subdir: 'email',
115 subject: gettext("Email"),
116 width: 400,
117 items: [
118 {
119 xtype: 'textfield',
120 name: 'email',
121 fieldLabel: gettext("Email")
122 }
123 ]
124 },
125 1007: {
126 xtype: 'proxmoxWindowEdit',
127 subdir: 'receiver',
128 subject: gettext("Email"),
129 receivertest: true,
130 width: 400,
131 items: [
132 {
133 xtype: 'textfield',
134 name: 'email',
135 fieldLabel: gettext("Email")
136 }
137 ]
138 },
139 1002: {
140 xtype: 'proxmoxWindowEdit',
141 subdir: 'domain',
142 subject: gettext("Domain"),
143 width: 400,
144 items: [
145 {
146 xtype: 'textfield',
147 name: 'domain',
148 fieldLabel: gettext("Domain")
149 }
150 ]
151 },
152 1008: {
153 xtype: 'proxmoxWindowEdit',
154 subdir: 'receiver_domain',
155 subject: gettext("Domain"),
156 receivertest: true,
157 width: 400,
158 items: [
159 {
160 xtype: 'textfield',
161 name: 'domain',
162 fieldLabel: gettext("Domain")
163 }
164 ]
165 },
166 1003: {
167 xtype: 'proxmoxWindowEdit',
168 subdir: 'ip',
169 subject: gettext("IP Address"),
170 width: 400,
171 items: [
172 {
173 xtype: 'textfield',
174 name: 'ip',
175 fieldLabel: gettext("IP Address")
176 }
177 ]
178 },
179 1004: {
180 xtype: 'proxmoxWindowEdit',
181 subdir: 'network',
182 subject: gettext("IP Network"),
183 width: 400,
184 items: [
185 {
186 xtype: 'textfield',
187 name: 'cidr',
188 fieldLabel: gettext("IP Network")
189 }
190 ]
191 },
192 2000: {
193 xtype: 'proxmoxWindowEdit',
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 ]
210 },
211 3002: {
212 xtype: 'proxmoxWindowEdit',
213 subdir: 'matchfield',
214 subject: gettext('Match Field'),
215 width: 400,
216 items: [
217 {
218 xtype: 'textfield',
219 name: 'field',
220 labelWidth: 150,
221 allowBlank: false,
222 fieldLabel: gettext('Field')
223 },
224 {
225 xtype: 'textfield',
226 reference: 'value',
227 name: 'value',
228 labelWidth: 150,
229 allowBlank: false,
230 fieldLabel: gettext('Value')
231 },
232 {
233 labelWidth: 150,
234 fieldLabel: gettext('Test String'),
235 xtype: 'pmgRegexTester',
236 regexFieldReference: 'value',
237 }
238 ]
239 },
240 3003: {
241 xtype: 'proxmoxWindowEdit',
242 subdir: 'contenttype',
243 width: 400,
244 subject: gettext('Content Type Filter'),
245 items: [
246 {
247 xtype: 'combobox',
248 displayField: 'text',
249 labelWidth: 150,
250 valueField: 'mimetype',
251 name: 'contenttype',
252 editable: true,
253 queryMode: 'local',
254 store: {
255 autoLoad: true,
256 proxy: {
257 type: 'proxmox',
258 url: '/api2/json/config/mimetypes'
259 },
260 },
261 fieldLabel: gettext('Content Type'),
262 anyMatch: true,
263 matchFieldWidth: false,
264 listeners: {
265 change: function(cb, value) {
266 var me = this;
267 me.up().down('displayfield').setValue(value);
268 }
269 }
270 },
271 {
272 xtype: 'displayfield',
273 fieldLabel: gettext('Value'),
274 labelWidth: 150,
275 allowBlank: false,
276 reset: Ext.emptyFn
277 },
278 ]
279 },
280 4005: {
281 xtype: 'proxmoxWindowEdit',
282 subdir: 'bcc',
283 subject: gettext('BCC'),
284 width: 400,
285 items: [
286 {
287 xtype: 'textfield',
288 name: 'name',
289 allowBlank: false,
290 fieldLabel: gettext('Name')
291 },
292 {
293 xtype: 'textareafield',
294 name: 'info',
295 fieldLabel: gettext("Description")
296 },
297 {
298 xtype: 'textfield',
299 name: 'target',
300 allowBlank: false,
301 fieldLabel: gettext("Target")
302 },
303 {
304 xtype: 'proxmoxcheckbox',
305 checked: true,
306 name: 'original',
307 fieldLabel: gettext("send orig. Mail")
308 }
309 ]
310
311 }
312 },
313
314 openVNCViewer: function(consoletype, nodename) {
315 var url = Ext.urlEncode({
316 console: consoletype, // upgrade or shell
317 novnc: 1,
318 node: nodename
319 });
320 var nw = window.open("?" + url, '_blank',
321 "innerWidth=745,innerheight=427");
322 nw.focus();
323 },
324
325 updateLoginData: function(data) {
326 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
327 Proxmox.UserName = data.username;
328 Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true );
329 },
330
331 quarantineActionExtracted: false,
332
333 extractQuarantineAction: function() {
334
335 if (PMG.Utils.quarantineActionExtracted) return;
336
337 PMG.Utils.quarantineActionExtracted = true;
338
339 var qs = Ext.Object.fromQueryString(location.search);
340
341 var cselect = qs.cselect;
342 var action = qs.action;
343 var ticket = qs.ticket;
344
345 delete qs.cselect;
346 delete qs.action;
347 delete qs.ticket;
348
349 var newsearch = Ext.Object.toQueryString(qs);
350
351 var newurl = location.protocol + "//" + location.host + location.pathname;
352 if (newsearch) newurl += '?' + newsearch;
353 newurl += location.hash;
354
355 if (window.history) {
356 window.history.pushState({ path:newurl }, '', newurl);
357 }
358
359 if (action && cselect) {
360 return { action: action, cselect: cselect };
361 }
362 },
363
364 constructor: function() {
365 var me = this;
366
367 // do whatever you want here
368 }
369 });