]> git.proxmox.com Git - pve-manager.git/blob - www/manager/dc/AuthEdit.js
disable animation of charts on load
[pve-manager.git] / www / manager / dc / AuthEdit.js
1 Ext.define('PVE.dc.AuthEdit', {
2 extend: 'PVE.window.Edit',
3 alias: ['widget.pveDcAuthEdit'],
4
5 isAdd: true,
6
7 initComponent : function() {
8 var me = this;
9
10 me.create = !me.realm;
11
12 var url;
13 var method;
14 var serverlist;
15
16 if (me.create) {
17 url = '/api2/extjs/access/domains';
18 method = 'POST';
19 } else {
20 url = '/api2/extjs/access/domains/' + me.realm;
21 method = 'PUT';
22 }
23
24 var column1 = [
25 {
26 xtype: me.create ? 'textfield' : 'displayfield',
27 height: 22, // hack: set same height as text fields
28 name: 'realm',
29 fieldLabel: gettext('Realm'),
30 value: me.realm,
31 allowBlank: false
32 }
33 ];
34
35 if (me.authType === 'ad') {
36
37 me.subject = gettext('Active Directory Server');
38
39 column1.push({
40 xtype: 'textfield',
41 name: 'domain',
42 fieldLabel: gettext('Domain'),
43 emptyText: 'company.net',
44 allowBlank: false
45 });
46
47 } else if (me.authType === 'ldap') {
48
49 me.subject = gettext('LDAP Server');
50
51 column1.push({
52 xtype: 'textfield',
53 name: 'base_dn',
54 fieldLabel: gettext('Base Domain Name'),
55 emptyText: 'CN=Users,DC=Company,DC=net',
56 allowBlank: false
57 });
58
59 column1.push({
60 xtype: 'textfield',
61 name: 'user_attr',
62 emptyText: 'uid / sAMAccountName',
63 fieldLabel: gettext('User Attribute Name'),
64 allowBlank: false
65 });
66 } else if (me.authType === 'pve') {
67
68 if (me.create) throw 'unknown auth type';
69
70 me.subject = 'Proxmox VE authentication server';
71
72 } else if (me.authType === 'pam') {
73
74 if (me.create) throw 'unknown auth type';
75
76 me.subject = 'linux PAM';
77
78 } else {
79 throw 'unknown auth type ';
80 }
81
82 column1.push({
83 xtype: 'pvecheckbox',
84 fieldLabel: gettext('Default'),
85 name: 'default',
86 uncheckedValue: 0
87 });
88
89 var column2 = [];
90
91 if (me.authType === 'ldap' || me.authType === 'ad') {
92 column2.push([
93 {
94 xtype: 'textfield',
95 fieldLabel: gettext('Server'),
96 name: 'server1',
97 allowBlank: false
98 },
99 {
100 xtype: 'pvetextfield',
101 fieldLabel: gettext('Fallback Server'),
102 deleteEmpty: !me.create,
103 name: 'server2'
104 },
105 {
106 xtype: 'numberfield',
107 name: 'port',
108 fieldLabel: gettext('Port'),
109 minValue: 1,
110 maxValue: 65535,
111 emptyText: gettext('Default'),
112 submitEmptyText: false
113 },
114 {
115 xtype: 'pvecheckbox',
116 fieldLabel: 'SSL',
117 name: 'secure',
118 uncheckedValue: 0
119 }
120 ]);
121 }
122
123 // Two Factor Auth settings
124
125 column2.push({
126 xtype: 'pveKVComboBox',
127 name: 'tfa',
128 deleteEmpty: !me.create,
129 value: '',
130 fieldLabel: gettext('TFA'),
131 data: [ ['', PVE.Utils.noneText], ['oath', 'OATH'], ['yubico', 'Yubico']],
132 listeners: {
133 change: function(f, value) {
134 if (!me.rendered) {
135 return;
136 }
137 me.down('field[name=oath_step]').setVisible(value === 'oath');
138 me.down('field[name=oath_digits]').setVisible(value === 'oath');
139 me.down('field[name=yubico_api_id]').setVisible(value === 'yubico');
140 me.down('field[name=yubico_api_key]').setVisible(value === 'yubico');
141 me.down('field[name=yubico_url]').setVisible(value === 'yubico');
142 }
143 }
144 });
145
146 column2.push({
147 xtype: 'numberfield',
148 name: 'oath_step',
149 value: '',
150 minValue: 10,
151 step: 1,
152 allowDecimals: false,
153 allowBlank: true,
154 emptyText: PVE.Utils.defaultText + ' (30)',
155 submitEmptyText: false,
156 hidden: true,
157 fieldLabel: 'OATH time step'
158 });
159
160 column2.push({
161 xtype: 'numberfield',
162 name: 'oath_digits',
163 value: '',
164 minValue: 6,
165 maxValue: 8,
166 step: 1,
167 allowDecimals: false,
168 allowBlank: true,
169 emptyText: PVE.Utils.defaultText + ' (6)',
170 submitEmptyText: false,
171 hidden: true,
172 fieldLabel: 'OATH password length'
173 });
174
175 column2.push({
176 xtype: 'textfield',
177 name: 'yubico_api_id',
178 hidden: true,
179 fieldLabel: 'Yubico API Id'
180 });
181
182 column2.push({
183 xtype: 'textfield',
184 name: 'yubico_api_key',
185 hidden: true,
186 fieldLabel: 'Yubico API Key'
187 });
188
189 column2.push({
190 xtype: 'textfield',
191 name: 'yubico_url',
192 hidden: true,
193 fieldLabel: 'Yubico URL'
194 });
195
196 var ipanel = Ext.create('PVE.panel.InputPanel', {
197 column1: column1,
198 column2: column2,
199 columnB: [{
200 xtype: 'textfield',
201 name: 'comment',
202 fieldLabel: gettext('Comment')
203 }],
204 onGetValues: function(values) {
205 if (!values.port) {
206 if (!me.create) {
207 PVE.Utils.assemble_field_data(values, { 'delete': 'port' });
208 }
209 delete values.port;
210 }
211
212 if (me.create) {
213 values.type = me.authType;
214 }
215
216 if (values.tfa === 'oath') {
217 values.tfa = "type=oath";
218 if (values.oath_step) {
219 values.tfa += ",step=" + values.oath_step;
220 }
221 if (values.oath_digits) {
222 values.tfa += ",digits=" + values.oath_digits;
223 }
224 } else if (values.tfa === 'yubico') {
225 values.tfa = "type=yubico";
226 values.tfa += ",id=" + values.yubico_api_id;
227 values.tfa += ",key=" + values.yubico_api_key;
228 if (values.yubico_url) {
229 values.tfa += ",url=" + values.yubico_url;
230 }
231 } else {
232 delete values.tfa;
233 }
234
235 delete values.oath_step;
236 delete values.oath_digits;
237 delete values.yubico_api_id;
238 delete values.yubico_api_key;
239 delete values.yubico_url;
240
241 return values;
242 }
243 });
244
245 Ext.applyIf(me, {
246 url: url,
247 method: method,
248 fieldDefaults: {
249 labelWidth: 120
250 },
251 items: [ ipanel ]
252 });
253
254 me.callParent();
255
256 if (!me.create) {
257 me.load({
258 success: function(response, options) {
259 var data = response.result.data || {};
260 // just to be sure (should not happen)
261 if (data.type !== me.authType) {
262 me.close();
263 throw "got wrong auth type";
264 }
265
266 if (data.tfa) {
267 var tfacfg = PVE.Parser.parseTfaConfig(data.tfa);
268 data.tfa = tfacfg.type;
269 if (tfacfg.type === 'yubico') {
270 data.yubico_api_key = tfacfg.key;
271 data.yubico_api_id = tfacfg.id;
272 data.yubico_url = tfacfg.url;
273 } else if (tfacfg.type === 'oath') {
274 data.oath_step = tfacfg.step;
275 data.oath_digits = tfacfg.digits;
276 }
277 }
278
279 me.setValues(data);
280 }
281 });
282 }
283 }
284 });