]>
Commit | Line | Data |
---|---|---|
fe81f069 DM |
1 | /* |
2 | * Workspace base class | |
3 | * | |
4 | * popup login window when auth fails (call onLogin handler) | |
5 | * update (re-login) ticket every 15 minutes | |
6 | * | |
7 | */ | |
8 | ||
9 | Ext.define('PMG.Workspace', { | |
10 | extend: 'Ext.container.Viewport', | |
11 | ||
12 | title: 'Proxmox Mail Gateway', | |
13 | ||
14 | loginData: null, // Data from last login call | |
15 | ||
16 | onLogin: function(loginData) {}, | |
17 | ||
18 | // private | |
19 | updateLoginData: function(loginData) { | |
20 | var me = this; | |
21 | ||
fe81f069 DM |
22 | me.loginData = loginData; |
23 | PMG.CSRFPreventionToken = loginData.CSRFPreventionToken; | |
24 | PMG.UserName = loginData.username; | |
25 | ||
3fd52fba | 26 | // creates a session cookie (expire = null) |
fe81f069 DM |
27 | // that way the cookie gets deleted after browser window close |
28 | Ext.util.Cookies.set('PMGAuthCookie', loginData.ticket, null, '/', null, true); | |
29 | me.onLogin(loginData); | |
30 | }, | |
31 | ||
32 | // private | |
33 | showLogin: function() { | |
34 | var me = this; | |
35 | ||
36 | PMG.Utils.authClear(); | |
37 | PMG.UserName = null; | |
38 | me.loginData = null; | |
39 | ||
40 | if (!me.login) { | |
41 | me.login = Ext.create('PMG.window.LoginWindow', { | |
42 | handler: function(data) { | |
43 | me.login = null; | |
44 | me.updateLoginData(data); | |
45 | } | |
46 | }); | |
47 | } | |
48 | me.onLogin(null); | |
49 | me.login.show(); | |
50 | }, | |
51 | ||
52 | initComponent : function() { | |
53 | var me = this; | |
54 | ||
55 | Ext.tip.QuickTipManager.init(); | |
56 | ||
57 | // fixme: what about other errors | |
58 | Ext.Ajax.on('requestexception', function(conn, response, options) { | |
59 | if (response.status == 401) { // auth failure | |
60 | me.showLogin(); | |
61 | } | |
62 | }); | |
63 | ||
64 | me.callParent(); | |
65 | ||
66 | if (!PMG.Utils.authOK()) { | |
67 | me.showLogin(); | |
3fd52fba | 68 | } else { |
fe81f069 DM |
69 | if (me.loginData) { |
70 | me.onLogin(me.loginData); | |
71 | } | |
72 | } | |
73 | ||
74 | Ext.TaskManager.start({ | |
75 | run: function() { | |
76 | var ticket = PMG.Utils.authOK(); | |
77 | if (!ticket || !PMG.UserName) { | |
78 | return; | |
79 | } | |
80 | ||
81 | Ext.Ajax.request({ | |
3fd52fba | 82 | params: { |
fe81f069 DM |
83 | username: PMG.UserName, |
84 | password: ticket | |
85 | }, | |
86 | url: '/api2/json/access/ticket', | |
87 | method: 'POST', | |
a3588c0c DM |
88 | failure: function() { |
89 | me.showLogin(); | |
90 | }, | |
fe81f069 DM |
91 | success: function(response, opts) { |
92 | var obj = Ext.decode(response.responseText); | |
93 | me.updateLoginData(obj.data); | |
94 | } | |
95 | }); | |
96 | }, | |
97 | interval: 15*60*1000 | |
98 | }); | |
99 | } | |
100 | }); | |
101 | ||
102 | Ext.define('PMG.StdWorkspace', { | |
103 | extend: 'PMG.Workspace', | |
104 | ||
105 | alias: ['widget.pmgStdWorkspace'], | |
106 | ||
fe81f069 DM |
107 | onLogin: function(loginData) { |
108 | var me = this; | |
109 | ||
110 | me.updateUserInfo(); | |
111 | ||
112 | if (loginData) { | |
113 | PMG.Utils.API2Request({ | |
114 | url: '/version', | |
115 | method: 'GET', | |
116 | success: function(response) { | |
117 | PMG.VersionInfo = response.result.data; | |
118 | me.updateVersionInfo(); | |
119 | } | |
120 | }); | |
121 | } | |
122 | }, | |
123 | ||
124 | updateUserInfo: function() { | |
125 | var me = this; | |
126 | ||
127 | var ui = me.query('#userinfo')[0]; | |
128 | ||
129 | if (PMG.UserName) { | |
130 | var msg = Ext.String.format(gettext("You are logged in as {0}"), "'" + PMG.UserName + "'"); | |
131 | ui.update('<div class="x-unselectable" style="white-space:nowrap;">' + msg + '</div>'); | |
132 | } else { | |
133 | ui.update(''); | |
134 | } | |
135 | ui.updateLayout(); | |
136 | }, | |
137 | ||
138 | updateVersionInfo: function() { | |
139 | var me = this; | |
140 | ||
141 | var ui = me.query('#versioninfo')[0]; | |
142 | ||
143 | if (PMG.VersionInfo) { | |
144 | var version = PMG.VersionInfo.version + '-' + PMG.VersionInfo.release + '/' + | |
145 | PMG.VersionInfo.repoid; | |
146 | ui.update('Mail Gateway ' + version); | |
147 | } else { | |
148 | ui.update('Mail Gateway'); | |
149 | } | |
150 | ui.updateLayout(); | |
151 | }, | |
152 | ||
153 | initComponent : function() { | |
154 | var me = this; | |
155 | ||
156 | Ext.History.init(); | |
157 | ||
158 | // var sprovider = Ext.create('PVE.StateProvider'); | |
159 | // Ext.state.Manager.setProvider(sprovider); | |
160 | ||
161 | Ext.apply(me, { | |
162 | layout: { type: 'border' }, | |
163 | border: false, | |
164 | items: [ | |
165 | { | |
166 | region: 'north', | |
3fd52fba | 167 | layout: { |
fe81f069 DM |
168 | type: 'hbox', |
169 | align: 'middle' | |
170 | }, | |
3fd52fba | 171 | baseCls: 'x-plain', |
fe81f069 | 172 | defaults: { |
3fd52fba | 173 | baseCls: 'x-plain' |
fe81f069 DM |
174 | }, |
175 | border: false, | |
176 | margin: '2 0 2 5', | |
177 | items: [ | |
178 | { | |
179 | html: '<a class="x-unselectable" target=_blank href="http://www.proxmox.com">' + | |
180 | '<img style="padding-top:4px;padding-right:5px" src="/pve2/images/proxmox_logo.png"/></a>' | |
181 | }, | |
182 | { | |
183 | minWidth: 200, | |
184 | id: 'versioninfo', | |
185 | html: 'Mail Gateway' | |
186 | }, | |
187 | { | |
188 | flex: 1 | |
189 | }, | |
190 | { | |
191 | pack: 'end', | |
192 | id: 'userinfo', | |
193 | stateful: false | |
194 | }, | |
195 | { | |
196 | pack: 'end', | |
197 | margin: '0 5 0 10', | |
198 | xtype: 'button', | |
199 | baseCls: 'x-btn', | |
200 | iconCls: 'fa fa-sign-out', | |
201 | text: gettext("Logout"), | |
3fd52fba DM |
202 | handler: function() { |
203 | me.showLogin(); | |
204 | // fixme: me.setContent(null); | |
fe81f069 DM |
205 | } |
206 | } | |
207 | ] | |
208 | }, | |
209 | { | |
210 | region: 'center', | |
211 | stateful: true, | |
212 | stateId: 'pvecenter', | |
213 | minWidth: 100, | |
214 | minHeight: 100, | |
215 | id: 'content', | |
3fd52fba DM |
216 | xtype: 'pmgPanelConfig', |
217 | items: [ | |
218 | { | |
219 | xtype: 'panel', | |
220 | title: 'Mail Filter', | |
221 | itemId: 'filter', | |
222 | expandedOnInit: true, | |
f1e32362 | 223 | items: [{ xtype: 'pmgRuleConfiguration' }] |
3fd52fba DM |
224 | }, |
225 | { | |
226 | xtype: 'panel', | |
227 | groups: ['filter'], | |
228 | title: 'Actions', | |
229 | itemId: 'filter-actions', | |
230 | html: "Actions" | |
231 | }, | |
232 | { | |
233 | xtype: 'panel', | |
234 | groups: ['filter'], | |
235 | title: 'Who', | |
236 | itemId: 'filter-who', | |
237 | html: "Who" | |
238 | }, | |
239 | { | |
240 | xtype: 'panel', | |
241 | groups: ['filter'], | |
242 | title: 'What', | |
243 | itemId: 'filter-what', | |
244 | html: "What" | |
245 | }, | |
246 | { | |
247 | xtype: 'panel', | |
248 | groups: ['filter'], | |
249 | title: 'When', | |
250 | itemId: 'filter-when', | |
251 | html: "When" | |
252 | }, | |
253 | ||
254 | { | |
255 | xtype: 'panel', | |
256 | title: 'Configuration', | |
257 | itemId: 'configuration', | |
258 | expandedOnInit: true, | |
e119071c | 259 | items: [{ xtype: 'pmgSystemConfiguration' }] |
3fd52fba DM |
260 | }, |
261 | { | |
262 | xtype: 'panel', | |
263 | groups: ['configuration'], | |
264 | title: 'Mail Proxy', | |
265 | itemId: 'config-mail-proxy', | |
266 | html: "Mail Proxy" | |
267 | }, | |
268 | { | |
269 | xtype: 'panel', | |
270 | groups: ['configuration'], | |
271 | title: 'Spam Detector', | |
272 | itemId: 'config-spam', | |
273 | html: "Spam Detector" | |
274 | }, | |
275 | { | |
276 | xtype: 'panel', | |
277 | groups: ['configuration'], | |
278 | title: 'Virus Detector', | |
279 | itemId: 'config-virus', | |
280 | html: "Virus Detector" | |
281 | }, | |
282 | { | |
283 | xtype: 'panel', | |
284 | groups: ['configuration'], | |
285 | title: 'User Management', | |
286 | itemId: 'config-users', | |
287 | html: "User Management" | |
288 | }, | |
289 | { | |
290 | xtype: 'panel', | |
291 | groups: ['configuration'], | |
292 | title: 'Cluster', | |
293 | itemId: 'config-cluster', | |
294 | html: "Cluster" | |
295 | }, | |
296 | { | |
297 | xtype: 'panel', | |
298 | groups: ['configuration'], | |
299 | title: 'License', | |
300 | itemId: 'config-license', | |
301 | html: "License" | |
302 | }, | |
303 | ||
304 | { | |
305 | xtype: 'panel', | |
306 | title: 'Administration', | |
307 | itemId: 'admin', | |
308 | expandedOnInit: true, | |
f1e32362 | 309 | items: [{ xtype: 'pmgServerAdministration' }] |
3fd52fba DM |
310 | }, |
311 | { | |
312 | xtype: 'panel', | |
313 | groups: ['admin'], | |
314 | title: 'Statistics', | |
315 | itemId: 'statistics', | |
316 | html: "Statistics" | |
317 | }, | |
318 | { | |
319 | xtype: 'panel', | |
320 | groups: ['admin'], | |
321 | title: 'Quarantine', | |
322 | itemId: 'quarantine', | |
323 | html: "Quarantine" | |
324 | }, | |
325 | { | |
326 | xtype: 'panel', | |
327 | groups: ['admin'], | |
328 | title: 'Tracking Center', | |
329 | itemId: 'tracking', | |
330 | html: "Tracking Center" | |
331 | }, | |
332 | { | |
333 | xtype: 'panel', | |
334 | groups: ['admin'], | |
335 | title: 'Queues', | |
336 | itemId: 'queues', | |
337 | html: "Queues" | |
fe81f069 | 338 | } |
3fd52fba | 339 | ] |
fe81f069 DM |
340 | } |
341 | ] | |
342 | }); | |
343 | ||
344 | me.callParent(); | |
345 | ||
346 | me.updateUserInfo(); | |
347 | ||
348 | // on resize, center all modal windows | |
349 | Ext.on('resize', function(){ | |
350 | var wins = Ext.ComponentQuery.query('window[modal]'); | |
351 | if (wins.length > 0) { | |
352 | wins.forEach(function(win){ | |
353 | win.alignTo(me, 'c-c'); | |
354 | }); | |
355 | } | |
356 | }); | |
357 | } | |
358 | }); |