]>
Commit | Line | Data |
---|---|---|
aa5cbdbb LW |
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 | ||
2ee8cbda LW |
32 | onlineHelp: 'user-realms-ldap', |
33 | ||
aa5cbdbb LW |
34 | onGetValues: function(values) { |
35 | if (this.isCreate) { | |
36 | values.type = this.type; | |
37 | } | |
38 | ||
39 | if (values.anonymous_search) { | |
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) { | |
4d3a18df | 60 | let me = this; |
aa5cbdbb | 61 | values.anonymous_search = values["bind-dn"] ? 0 : 1; |
4d3a18df | 62 | me.getViewModel().set('anonymous_search', values.anonymous_search); |
aa5cbdbb LW |
63 | |
64 | return values; | |
65 | }, | |
66 | ||
67 | ||
68 | column1: [ | |
69 | { | |
70 | xtype: 'pmxDisplayEditField', | |
71 | name: 'realm', | |
72 | cbind: { | |
73 | value: '{realm}', | |
74 | editable: '{isCreate}', | |
75 | }, | |
76 | fieldLabel: gettext('Realm'), | |
77 | allowBlank: false, | |
78 | }, | |
79 | { | |
80 | xtype: 'proxmoxtextfield', | |
81 | fieldLabel: gettext('Base Domain Name'), | |
82 | name: 'base-dn', | |
83 | allowBlank: false, | |
84 | emptyText: 'cn=Users,dc=company,dc=net', | |
85 | }, | |
86 | { | |
87 | xtype: 'proxmoxtextfield', | |
88 | fieldLabel: gettext('User Attribute Name'), | |
89 | name: 'user-attr', | |
90 | allowBlank: false, | |
91 | emptyText: 'uid / sAMAccountName', | |
92 | }, | |
93 | { | |
94 | xtype: 'proxmoxcheckbox', | |
95 | fieldLabel: gettext('Anonymous Search'), | |
96 | name: 'anonymous_search', | |
58bff886 TL |
97 | bind: { |
98 | value: '{anonymous_search}', | |
99 | }, | |
aa5cbdbb LW |
100 | }, |
101 | { | |
102 | xtype: 'proxmoxtextfield', | |
103 | fieldLabel: gettext('Bind Domain Name'), | |
104 | name: 'bind-dn', | |
105 | allowBlank: false, | |
106 | emptyText: 'cn=user,dc=company,dc=net', | |
107 | bind: { | |
108 | disabled: "{anonymous_search}", | |
109 | }, | |
110 | }, | |
111 | { | |
112 | xtype: 'proxmoxtextfield', | |
113 | inputType: 'password', | |
114 | fieldLabel: gettext('Bind Password'), | |
115 | name: 'password', | |
116 | allowBlank: true, | |
117 | cbind: { | |
118 | emptyText: get => !get('isCreate') ? gettext('Unchanged') : '', | |
119 | }, | |
120 | bind: { | |
121 | disabled: "{anonymous_search}", | |
122 | }, | |
123 | }, | |
124 | ], | |
125 | ||
126 | column2: [ | |
127 | { | |
128 | xtype: 'proxmoxtextfield', | |
129 | name: 'server1', | |
130 | fieldLabel: gettext('Server'), | |
131 | allowBlank: false, | |
132 | }, | |
133 | { | |
134 | xtype: 'proxmoxtextfield', | |
135 | name: 'server2', | |
136 | fieldLabel: gettext('Fallback Server'), | |
137 | submitEmpty: false, | |
138 | cbind: { | |
139 | deleteEmpty: '{!isCreate}', | |
140 | }, | |
141 | }, | |
142 | { | |
143 | xtype: 'proxmoxintegerfield', | |
144 | name: 'port', | |
145 | fieldLabel: gettext('Port'), | |
146 | minValue: 1, | |
147 | maxValue: 65535, | |
148 | emptyText: gettext('Default'), | |
149 | submitEmptyText: false, | |
150 | deleteEmpty: true, | |
151 | }, | |
152 | { | |
153 | xtype: 'proxmoxKVComboBox', | |
154 | name: 'mode', | |
155 | fieldLabel: gettext('Mode'), | |
156 | editable: false, | |
157 | comboItems: [ | |
158 | ['ldap', 'LDAP'], | |
159 | ['ldap+starttls', 'STARTTLS'], | |
160 | ['ldaps', 'LDAPS'], | |
161 | ], | |
162 | bind: "{mode}", | |
163 | cbind: { | |
164 | deleteEmpty: '{!isCreate}', | |
165 | value: get => get('isCreate') ? 'ldap' : 'LDAP', | |
166 | }, | |
167 | }, | |
168 | { | |
169 | xtype: 'proxmoxcheckbox', | |
170 | fieldLabel: gettext('Verify Certificate'), | |
171 | name: 'verify', | |
172 | value: 0, | |
173 | cbind: { | |
174 | deleteEmpty: '{!isCreate}', | |
175 | }, | |
176 | ||
177 | bind: { | |
178 | disabled: '{!tls_enabled}', | |
179 | }, | |
180 | autoEl: { | |
181 | tag: 'div', | |
182 | 'data-qtip': gettext('Verify TLS certificate of the server'), | |
183 | }, | |
184 | ||
185 | }, | |
186 | ], | |
187 | ||
188 | columnB: [ | |
189 | { | |
190 | xtype: 'textfield', | |
191 | name: 'comment', | |
192 | fieldLabel: gettext('Comment'), | |
193 | cbind: { | |
194 | deleteEmpty: '{!isCreate}', | |
195 | }, | |
196 | }, | |
197 | ], | |
198 | ||
199 | }); | |
200 | ||
d6b65a89 LW |
201 | |
202 | Ext.define('Proxmox.panel.LDAPSyncInputPanel', { | |
203 | extend: 'Proxmox.panel.InputPanel', | |
204 | xtype: 'pmxAuthLDAPSyncPanel', | |
205 | mixins: ['Proxmox.Mixin.CBind'], | |
206 | ||
78970361 | 207 | editableAttributes: ['firstname', 'lastname', 'email'], |
d6b65a89 LW |
208 | editableDefaults: ['scope', 'enable-new'], |
209 | default_opts: {}, | |
210 | sync_attributes: {}, | |
211 | ||
212 | type: 'ldap', | |
213 | ||
214 | // (de)construct the sync-attributes from the list above, | |
215 | // not touching all others | |
216 | onGetValues: function(values) { | |
217 | let me = this; | |
218 | ||
219 | me.editableDefaults.forEach((attr) => { | |
220 | if (values[attr]) { | |
221 | me.default_opts[attr] = values[attr]; | |
222 | delete values[attr]; | |
223 | } else { | |
224 | delete me.default_opts[attr]; | |
225 | } | |
226 | }); | |
227 | let vanished_opts = []; | |
228 | ['acl', 'entry', 'properties'].forEach((prop) => { | |
229 | if (values[`remove-vanished-${prop}`]) { | |
230 | vanished_opts.push(prop); | |
231 | } | |
232 | delete values[`remove-vanished-${prop}`]; | |
233 | }); | |
234 | me.default_opts['remove-vanished'] = vanished_opts.join(';'); | |
235 | ||
236 | values['sync-defaults-options'] = Proxmox.Utils.printPropertyString(me.default_opts); | |
237 | me.editableAttributes.forEach((attr) => { | |
238 | if (values[attr]) { | |
239 | me.sync_attributes[attr] = values[attr]; | |
240 | delete values[attr]; | |
241 | } else { | |
242 | delete me.sync_attributes[attr]; | |
243 | } | |
244 | }); | |
245 | values['sync-attributes'] = Proxmox.Utils.printPropertyString(me.sync_attributes); | |
246 | ||
247 | Proxmox.Utils.delete_if_default(values, 'sync-defaults-options'); | |
248 | Proxmox.Utils.delete_if_default(values, 'sync-attributes'); | |
249 | ||
bfb750a5 LW |
250 | // Force values.delete to be an array |
251 | if (typeof values.delete === 'string') { | |
252 | values.delete = values.delete.split(','); | |
253 | } | |
254 | ||
d6b65a89 LW |
255 | if (me.isCreate) { |
256 | delete values.delete; // on create we cannot delete values | |
257 | } | |
258 | ||
259 | return values; | |
260 | }, | |
261 | ||
262 | setValues: function(values) { | |
263 | let me = this; | |
264 | ||
265 | if (values['sync-attributes']) { | |
266 | me.sync_attributes = Proxmox.Utils.parsePropertyString(values['sync-attributes']); | |
267 | delete values['sync-attributes']; | |
268 | me.editableAttributes.forEach((attr) => { | |
269 | if (me.sync_attributes[attr]) { | |
270 | values[attr] = me.sync_attributes[attr]; | |
271 | } | |
272 | }); | |
273 | } | |
274 | if (values['sync-defaults-options']) { | |
275 | me.default_opts = Proxmox.Utils.parsePropertyString(values['sync-defaults-options']); | |
276 | delete values.default_opts; | |
277 | me.editableDefaults.forEach((attr) => { | |
278 | if (me.default_opts[attr]) { | |
279 | values[attr] = me.default_opts[attr]; | |
280 | } | |
281 | }); | |
282 | ||
283 | if (me.default_opts['remove-vanished']) { | |
284 | let opts = me.default_opts['remove-vanished'].split(';'); | |
285 | for (const opt of opts) { | |
286 | values[`remove-vanished-${opt}`] = 1; | |
287 | } | |
288 | } | |
289 | } | |
290 | return me.callParent([values]); | |
291 | }, | |
292 | ||
293 | column1: [ | |
78970361 LW |
294 | { |
295 | xtype: 'proxmoxtextfield', | |
296 | name: 'firstname', | |
297 | fieldLabel: gettext('First Name attribute'), | |
298 | }, | |
299 | { | |
300 | xtype: 'proxmoxtextfield', | |
301 | name: 'lastname', | |
302 | fieldLabel: gettext('Last Name attribute'), | |
303 | }, | |
d6b65a89 LW |
304 | { |
305 | xtype: 'proxmoxtextfield', | |
306 | name: 'email', | |
307 | fieldLabel: gettext('E-Mail attribute'), | |
308 | }, | |
309 | { | |
310 | xtype: 'displayfield', | |
311 | value: gettext('Default Sync Options'), | |
312 | }, | |
313 | { | |
314 | xtype: 'proxmoxKVComboBox', | |
315 | value: '__default__', | |
316 | deleteEmpty: false, | |
317 | comboItems: [ | |
318 | [ | |
319 | '__default__', | |
320 | Ext.String.format( | |
321 | gettext("{0} ({1})"), | |
322 | Proxmox.Utils.yesText, | |
323 | Proxmox.Utils.defaultText, | |
324 | ), | |
325 | ], | |
326 | ['true', Proxmox.Utils.yesText], | |
327 | ['false', Proxmox.Utils.noText], | |
328 | ], | |
329 | name: 'enable-new', | |
330 | fieldLabel: gettext('Enable new users'), | |
331 | }, | |
332 | ], | |
333 | ||
334 | column2: [ | |
335 | { | |
336 | xtype: 'proxmoxtextfield', | |
337 | name: 'user-classes', | |
338 | fieldLabel: gettext('User classes'), | |
339 | deleteEmpty: true, | |
340 | emptyText: 'inetorgperson, posixaccount, person, user', | |
341 | autoEl: { | |
342 | tag: 'div', | |
343 | 'data-qtip': gettext('Default user classes: inetorgperson, posixaccount, person, user'), | |
344 | }, | |
345 | }, | |
346 | { | |
347 | xtype: 'proxmoxtextfield', | |
348 | name: 'filter', | |
349 | fieldLabel: gettext('User Filter'), | |
350 | deleteEmpty: true, | |
351 | }, | |
352 | ], | |
353 | ||
354 | columnB: [ | |
355 | { | |
356 | xtype: 'fieldset', | |
357 | title: gettext('Remove Vanished Options'), | |
358 | items: [ | |
359 | { | |
360 | xtype: 'proxmoxcheckbox', | |
361 | fieldLabel: gettext('ACL'), | |
362 | name: 'remove-vanished-acl', | |
363 | boxLabel: gettext('Remove ACLs of vanished users'), | |
364 | }, | |
365 | { | |
366 | xtype: 'proxmoxcheckbox', | |
367 | fieldLabel: gettext('Entry'), | |
368 | name: 'remove-vanished-entry', | |
369 | boxLabel: gettext('Remove vanished user'), | |
370 | }, | |
371 | { | |
372 | xtype: 'proxmoxcheckbox', | |
373 | fieldLabel: gettext('Properties'), | |
374 | name: 'remove-vanished-properties', | |
375 | boxLabel: gettext('Remove vanished properties from synced users.'), | |
376 | }, | |
377 | ], | |
378 | }, | |
379 | ], | |
380 | }); |