]> git.proxmox.com Git - pmg-gui.git/blob - js/Utils.js
improve rule_direction formatter
[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
14 oclass_text: {
15 who: gettext('Who Objects'),
16 what: gettext('What Objects'),
17 when: gettext('When Objects'),
18 action: gettext('Action Objects'),
19 from: gettext('From'),
20 to: gettext('To')
21 },
22
23 oclass_icon: {
24 who: '<span class="fa fa-fw fa-user-circle"></span> ',
25 what: '<span class="fa fa-fw fa-cube"></span> ',
26 when: '<span class="fa fa-fw fa-clock-o"></span> ',
27 action: '<span class="fa fa-fw fa-flag"></span> ',
28 from: '<span class="fa fa-fw fa-user-circle"></span> ',
29 to: '<span class="fa fa-fw fa-user-circle"></span> ',
30 },
31
32 format_oclass: function(oclass) {
33 var icon = PMG.Utils.oclass_icon[oclass] || '';
34 var text = PMG.Utils.oclass_text[oclass] || oclass;
35 return icon + text;
36 },
37
38 rule_direction_text: {
39 0: gettext('In'),
40 1: gettext('Out'),
41 2: gettext('In & Out')
42 },
43
44 rule_direction_icon: {
45 0: '<span class="x-fa fa-fw fa-long-arrow-left"></span> ',
46 1: '<span class="x-fa fa-fw fa-long-arrow-right"></span> ',
47 2: '<span class="x-fa fa-fw fa-exchange"></span> '
48 },
49
50 format_rule_direction: function(dir) {
51 var icon = PMG.Utils.rule_direction_icon[dir] || '';
52 var text = PMG.Utils.rule_direction_text[dir] || dir;
53 return icon + text;
54 },
55
56 format_otype: function(otype) {
57 var editor = PMG.Utils.object_editors[otype];
58 if (editor) {
59 return editor.subject;
60 }
61 return 'unknown';
62 },
63
64 format_ldap_protocol: function(p) {
65 if (p === undefined) return 'LDAP';
66 if (p === 'ldap') return 'LDAP';
67 if (p === 'ldaps') return 'LDAPS';
68 return 'unknown';
69 },
70
71 object_editors: {
72 1000: {
73 xtype: 'proxmoxWindowEdit',
74 subdir: 'regex',
75 subject: gettext("Regular Expression"),
76 width: 400,
77 items: [
78 {
79 xtype: 'textfield',
80 name: 'regex',
81 labelWidth: 150,
82 fieldLabel: gettext("Regular Expression")
83 }
84 ]
85 },
86 1005: {
87 xtype: 'pmgLDAPGroupEditor',
88 subdir: 'ldap',
89 subject: gettext("LDAP Group")
90 },
91 1006: {
92 xtype: 'pmgLDAPUserEditor',
93 subdir: 'ldapuser',
94 subject: gettext("LDAP User")
95 },
96 1009: {
97 xtype: 'proxmoxWindowEdit',
98 subdir: 'receiver_regex',
99 subject: gettext("Regular Expression"),
100 receivertest: true,
101 width: 400,
102 items: [
103 {
104 xtype: 'textfield',
105 name: 'regex',
106 labelWidth: 150,
107 fieldLabel: gettext("Regular Expression")
108 }
109 ]
110 },
111 1001: {
112 xtype: 'proxmoxWindowEdit',
113 subdir: 'email',
114 subject: gettext("Email"),
115 width: 400,
116 items: [
117 {
118 xtype: 'textfield',
119 name: 'email',
120 fieldLabel: gettext("Email")
121 }
122 ]
123 },
124 1007: {
125 xtype: 'proxmoxWindowEdit',
126 subdir: 'receiver',
127 subject: gettext("Email"),
128 receivertest: true,
129 width: 400,
130 items: [
131 {
132 xtype: 'textfield',
133 name: 'email',
134 fieldLabel: gettext("Email")
135 }
136 ]
137 },
138 1002: {
139 xtype: 'proxmoxWindowEdit',
140 subdir: 'domain',
141 subject: gettext("Domain"),
142 width: 400,
143 items: [
144 {
145 xtype: 'textfield',
146 name: 'domain',
147 fieldLabel: gettext("Domain")
148 }
149 ]
150 },
151 1008: {
152 xtype: 'proxmoxWindowEdit',
153 subdir: 'receiver_domain',
154 subject: gettext("Domain"),
155 receivertest: true,
156 width: 400,
157 items: [
158 {
159 xtype: 'textfield',
160 name: 'domain',
161 fieldLabel: gettext("Domain")
162 }
163 ]
164 },
165 1003: {
166 xtype: 'proxmoxWindowEdit',
167 subdir: 'ip',
168 subject: gettext("IP Address"),
169 width: 400,
170 items: [
171 {
172 xtype: 'textfield',
173 name: 'ip',
174 fieldLabel: gettext("IP Address")
175 }
176 ]
177 },
178 1004: {
179 xtype: 'proxmoxWindowEdit',
180 subdir: 'network',
181 subject: gettext("IP Network"),
182 width: 400,
183 items: [
184 {
185 xtype: 'textfield',
186 name: 'cidr',
187 fieldLabel: gettext("IP Network")
188 }
189 ]
190 },
191 2000: {
192 xtype: 'proxmoxWindowEdit',
193 subdir: 'timeframe',
194 subject: gettext("TimeFrame"),
195 items: [
196 {
197 xtype: 'timefield',
198 name: 'start',
199 format: 'H:i',
200 fieldLabel: gettext("Start Time")
201 },
202 {
203 xtype: 'timefield',
204 name: 'end',
205 format: 'H:i',
206 fieldLabel: gettext("End Time")
207 }
208 ]
209 },
210 4005: {
211 xtype: 'proxmoxWindowEdit',
212 subdir: 'bcc',
213 subject: gettext('BCC'),
214 width: 400,
215 items: [
216 {
217 xtype: 'textfield',
218 name: 'name',
219 allowBlank: false,
220 fieldLabel: gettext('Name')
221 },
222 {
223 xtype: 'textareafield',
224 name: 'info',
225 fieldLabel: gettext("Description")
226 },
227 {
228 xtype: 'textfield',
229 name: 'target',
230 allowBlank: false,
231 fieldLabel: gettext("Target")
232 },
233 {
234 xtype: 'proxmoxcheckbox',
235 checked: true,
236 name: 'original',
237 fieldLabel: gettext("send orig. Mail")
238 }
239 ]
240
241 }
242 },
243
244 openVNCViewer: function(consoletype, nodename) {
245 var url = Ext.urlEncode({
246 console: consoletype, // upgrade or shell
247 novnc: 1,
248 node: nodename
249 });
250 var nw = window.open("?" + url, '_blank',
251 "innerWidth=745,innerheight=427");
252 nw.focus();
253 },
254
255 updateLoginData: function(data) {
256 Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
257 Proxmox.UserName = data.username;
258 Ext.util.Cookies.set('PMGAuthCookie', data.ticket, null, '/', null, true );
259 },
260
261 constructor: function() {
262 var me = this;
263
264 // do whatever you want here
265 }
266 });