]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/window/AuthEditLDAP.js
bump version to 4.2.3
[proxmox-widget-toolkit.git] / src / window / AuthEditLDAP.js
1
2 Ext.define('Proxmox.panel.LDAPInputPanelViewModel', {
3 extend: 'Ext.app.ViewModel',
4
5 alias: 'viewmodel.pmxAuthLDAPPanel',
6
7 data: {
8 mode: 'ldap',
9 anonymous_search: 1,
10 },
11
12 formulas: {
13 tls_enabled: function(get) {
14 return get('mode') !== 'ldap';
15 },
16 },
17
18 });
19
20
21 Ext.define('Proxmox.panel.LDAPInputPanel', {
22 extend: 'Proxmox.panel.InputPanel',
23 xtype: 'pmxAuthLDAPPanel',
24 mixins: ['Proxmox.Mixin.CBind'],
25
26 viewModel: {
27 type: 'pmxAuthLDAPPanel',
28 },
29
30 type: 'ldap',
31
32 onlineHelp: 'user-realms-ldap',
33
34 onGetValues: function(values) {
35 if (this.isCreate && !this.useTypeInUrl) {
36 values.type = this.type;
37 }
38
39 if (values.anonymous_search && !this.isCreate) {
40 if (!values.delete) {
41 values.delete = [];
42 }
43
44 if (!Array.isArray(values.delete)) {
45 let tmp = values.delete;
46 values.delete = [];
47 values.delete.push(tmp);
48 }
49
50 values.delete.push("bind-dn");
51 values.delete.push("password");
52 }
53
54 delete values.anonymous_search;
55
56 return values;
57 },
58
59 onSetValues: function(values) {
60 let me = this;
61 values.anonymous_search = values["bind-dn"] ? 0 : 1;
62 me.getViewModel().set('anonymous_search', values.anonymous_search);
63
64 return values;
65 },
66
67 cbindData: function(config) {
68 return {
69 isLdap: this.type === 'ldap',
70 isAd: this.type === 'ad',
71 };
72 },
73
74 column1: [
75 {
76 xtype: 'pmxDisplayEditField',
77 name: 'realm',
78 cbind: {
79 value: '{realm}',
80 editable: '{isCreate}',
81 },
82 fieldLabel: gettext('Realm'),
83 allowBlank: false,
84 },
85 {
86 xtype: 'proxmoxtextfield',
87 fieldLabel: gettext('Base Domain Name'),
88 name: 'base-dn',
89 emptyText: 'cn=Users,dc=company,dc=net',
90 cbind: {
91 hidden: '{!isLdap}',
92 allowBlank: '{!isLdap}',
93 },
94 },
95 {
96 xtype: 'proxmoxtextfield',
97 fieldLabel: gettext('User Attribute Name'),
98 name: 'user-attr',
99 emptyText: 'uid / sAMAccountName',
100 cbind: {
101 hidden: '{!isLdap}',
102 allowBlank: '{!isLdap}',
103 },
104 },
105 {
106 xtype: 'proxmoxcheckbox',
107 fieldLabel: gettext('Anonymous Search'),
108 name: 'anonymous_search',
109 bind: {
110 value: '{anonymous_search}',
111 },
112 },
113 {
114 xtype: 'proxmoxtextfield',
115 fieldLabel: gettext('Bind Domain Name'),
116 name: 'bind-dn',
117 allowBlank: false,
118 cbind: {
119 emptyText: get => get('isAd') ? 'user@company.net' : 'cn=user,dc=company,dc=net',
120 autoEl: get => get('isAd') ? {
121 tag: 'div',
122 'data-qtip':
123 gettext('LDAP DN syntax can be used as well, e.g. cn=user,dc=company,dc=net'),
124 } : {},
125 },
126 bind: {
127 disabled: "{anonymous_search}",
128 },
129 },
130 {
131 xtype: 'proxmoxtextfield',
132 inputType: 'password',
133 fieldLabel: gettext('Bind Password'),
134 name: 'password',
135 cbind: {
136 emptyText: get => !get('isCreate') ? gettext('Unchanged') : '',
137 allowBlank: '{!isCreate}',
138 },
139 bind: {
140 disabled: "{anonymous_search}",
141 },
142 },
143 ],
144
145 column2: [
146 {
147 xtype: 'proxmoxtextfield',
148 name: 'server1',
149 fieldLabel: gettext('Server'),
150 allowBlank: false,
151 },
152 {
153 xtype: 'proxmoxtextfield',
154 name: 'server2',
155 fieldLabel: gettext('Fallback Server'),
156 submitEmpty: false,
157 cbind: {
158 deleteEmpty: '{!isCreate}',
159 },
160 },
161 {
162 xtype: 'proxmoxintegerfield',
163 name: 'port',
164 fieldLabel: gettext('Port'),
165 minValue: 1,
166 maxValue: 65535,
167 emptyText: gettext('Default'),
168 submitEmptyText: false,
169 cbind: {
170 deleteEmpty: '{!isCreate}',
171 },
172 },
173 {
174 xtype: 'proxmoxKVComboBox',
175 name: 'mode',
176 fieldLabel: gettext('Mode'),
177 editable: false,
178 comboItems: [
179 ['ldap', 'LDAP'],
180 ['ldap+starttls', 'STARTTLS'],
181 ['ldaps', 'LDAPS'],
182 ],
183 bind: "{mode}",
184 cbind: {
185 deleteEmpty: '{!isCreate}',
186 value: get => get('isCreate') ? 'ldap' : 'LDAP',
187 },
188 },
189 {
190 xtype: 'proxmoxcheckbox',
191 fieldLabel: gettext('Verify Certificate'),
192 name: 'verify',
193 value: 0,
194 cbind: {
195 deleteEmpty: '{!isCreate}',
196 },
197
198 bind: {
199 disabled: '{!tls_enabled}',
200 },
201 autoEl: {
202 tag: 'div',
203 'data-qtip': gettext('Verify TLS certificate of the server'),
204 },
205
206 },
207 ],
208
209 columnB: [
210 {
211 xtype: 'proxmoxtextfield',
212 name: 'comment',
213 fieldLabel: gettext('Comment'),
214 cbind: {
215 deleteEmpty: '{!isCreate}',
216 },
217 },
218 ],
219
220 });
221
222
223 Ext.define('Proxmox.panel.LDAPSyncInputPanel', {
224 extend: 'Proxmox.panel.InputPanel',
225 xtype: 'pmxAuthLDAPSyncPanel',
226 mixins: ['Proxmox.Mixin.CBind'],
227
228 editableAttributes: ['firstname', 'lastname', 'email'],
229 editableDefaults: ['scope', 'enable-new'],
230 default_opts: {},
231 sync_attributes: {},
232
233 type: 'ldap',
234
235 // (de)construct the sync-attributes from the list above,
236 // not touching all others
237 onGetValues: function(values) {
238 let me = this;
239
240 me.editableDefaults.forEach((attr) => {
241 if (values[attr]) {
242 me.default_opts[attr] = values[attr];
243 delete values[attr];
244 } else {
245 delete me.default_opts[attr];
246 }
247 });
248 let vanished_opts = [];
249 ['acl', 'entry', 'properties'].forEach((prop) => {
250 if (values[`remove-vanished-${prop}`]) {
251 vanished_opts.push(prop);
252 }
253 delete values[`remove-vanished-${prop}`];
254 });
255 me.default_opts['remove-vanished'] = vanished_opts.join(';');
256
257 values['sync-defaults-options'] = Proxmox.Utils.printPropertyString(me.default_opts);
258 me.editableAttributes.forEach((attr) => {
259 if (values[attr]) {
260 me.sync_attributes[attr] = values[attr];
261 delete values[attr];
262 } else {
263 delete me.sync_attributes[attr];
264 }
265 });
266 values['sync-attributes'] = Proxmox.Utils.printPropertyString(me.sync_attributes);
267
268 Proxmox.Utils.delete_if_default(values, 'sync-defaults-options');
269 Proxmox.Utils.delete_if_default(values, 'sync-attributes');
270
271 // Force values.delete to be an array
272 if (typeof values.delete === 'string') {
273 values.delete = values.delete.split(',');
274 }
275
276 if (me.isCreate) {
277 delete values.delete; // on create we cannot delete values
278 }
279
280 return values;
281 },
282
283 setValues: function(values) {
284 let me = this;
285
286 if (values['sync-attributes']) {
287 me.sync_attributes = Proxmox.Utils.parsePropertyString(values['sync-attributes']);
288 delete values['sync-attributes'];
289 me.editableAttributes.forEach((attr) => {
290 if (me.sync_attributes[attr]) {
291 values[attr] = me.sync_attributes[attr];
292 }
293 });
294 }
295 if (values['sync-defaults-options']) {
296 me.default_opts = Proxmox.Utils.parsePropertyString(values['sync-defaults-options']);
297 delete values.default_opts;
298 me.editableDefaults.forEach((attr) => {
299 if (me.default_opts[attr]) {
300 values[attr] = me.default_opts[attr];
301 }
302 });
303
304 if (me.default_opts['remove-vanished']) {
305 let opts = me.default_opts['remove-vanished'].split(';');
306 for (const opt of opts) {
307 values[`remove-vanished-${opt}`] = 1;
308 }
309 }
310 }
311 return me.callParent([values]);
312 },
313
314 column1: [
315 {
316 xtype: 'proxmoxtextfield',
317 name: 'firstname',
318 fieldLabel: gettext('First Name attribute'),
319 autoEl: {
320 tag: 'div',
321 'data-qtip': Ext.String.format(gettext('Often called {0}'), '`givenName`'),
322 },
323 },
324 {
325 xtype: 'proxmoxtextfield',
326 name: 'lastname',
327 fieldLabel: gettext('Last Name attribute'),
328 autoEl: {
329 tag: 'div',
330 'data-qtip': Ext.String.format(gettext('Often called {0}'), '`sn`'),
331 },
332 },
333 {
334 xtype: 'proxmoxtextfield',
335 name: 'email',
336 fieldLabel: gettext('E-Mail attribute'),
337 autoEl: {
338 tag: 'div',
339 'data-qtip': get => get('isAd')
340 ? Ext.String.format(gettext('Often called {0} or {1}'), '`userPrincipalName`', '`mail`')
341 : Ext.String.format(gettext('Often called {0}'), '`mail`'),
342 },
343 },
344 {
345 xtype: 'displayfield',
346 value: gettext('Default Sync Options'),
347 },
348 {
349 xtype: 'proxmoxKVComboBox',
350 value: '__default__',
351 deleteEmpty: false,
352 comboItems: [
353 [
354 '__default__',
355 Ext.String.format(
356 gettext("{0} ({1})"),
357 Proxmox.Utils.yesText,
358 Proxmox.Utils.defaultText,
359 ),
360 ],
361 ['true', Proxmox.Utils.yesText],
362 ['false', Proxmox.Utils.noText],
363 ],
364 name: 'enable-new',
365 fieldLabel: gettext('Enable new users'),
366 },
367 ],
368
369 column2: [
370 {
371 xtype: 'proxmoxtextfield',
372 name: 'user-classes',
373 fieldLabel: gettext('User classes'),
374 cbind: {
375 deleteEmpty: '{!isCreate}',
376 },
377 emptyText: 'inetorgperson, posixaccount, person, user',
378 autoEl: {
379 tag: 'div',
380 'data-qtip': gettext('Default user classes: inetorgperson, posixaccount, person, user'),
381 },
382 },
383 {
384 xtype: 'proxmoxtextfield',
385 name: 'filter',
386 fieldLabel: gettext('User Filter'),
387 cbind: {
388 deleteEmpty: '{!isCreate}',
389 },
390 },
391 ],
392
393 columnB: [
394 {
395 xtype: 'fieldset',
396 title: gettext('Remove Vanished Options'),
397 items: [
398 {
399 xtype: 'proxmoxcheckbox',
400 fieldLabel: gettext('ACL'),
401 name: 'remove-vanished-acl',
402 boxLabel: gettext('Remove ACLs of vanished users'),
403 },
404 {
405 xtype: 'proxmoxcheckbox',
406 fieldLabel: gettext('Entry'),
407 name: 'remove-vanished-entry',
408 boxLabel: gettext('Remove vanished user'),
409 },
410 {
411 xtype: 'proxmoxcheckbox',
412 fieldLabel: gettext('Properties'),
413 name: 'remove-vanished-properties',
414 boxLabel: gettext('Remove vanished properties from synced users.'),
415 },
416 ],
417 },
418 ],
419 });