]>
Commit | Line | Data |
---|---|---|
161f4504 DM |
1 | Ext.define('pmg-address-list', { |
2 | extend: 'Ext.data.Model', | |
c87d46fb TL |
3 | fields: ['address'], |
4 | idProperty: 'address', | |
161f4504 DM |
5 | }); |
6 | ||
7 | // base class - do not use directly | |
8 | Ext.define('PMG.UserBlackWhiteList', { | |
9 | extend: 'Ext.grid.GridPanel', | |
10 | ||
50531ef9 | 11 | border: false, |
161f4504 DM |
12 | listname: undefined, // 'blacklist' or 'whitelist', |
13 | ||
c41c3600 DC |
14 | selModel: 'checkboxmodel', |
15 | ||
64fb657f | 16 | emptyText: gettext('No data in database'), |
5810fc6b | 17 | |
161f4504 DM |
18 | controller: { |
19 | ||
20 | xclass: 'Ext.app.ViewController', | |
21 | ||
22 | onAddAddress: function() { | |
28eb60c0 TL |
23 | let view = this.getView(); |
24 | let params = view.getStore().getProxy().getExtraParams() || {}; | |
161f4504 | 25 | |
28eb60c0 | 26 | let url = '/quarantine/' + view.listname; |
161f4504 | 27 | |
28eb60c0 | 28 | let items = [{ |
7d51f9ff DC |
29 | xtype: 'proxmoxtextfield', |
30 | name: 'address', | |
c41c3600 | 31 | minLength: 3, |
28eb60c0 | 32 | regex: /^[^,;\s]*$/, // no whitespace no , and no ; |
c87d46fb | 33 | fieldLabel: gettext("Address"), |
7d51f9ff DC |
34 | }]; |
35 | ||
36 | Ext.Object.each(params, function(key, value) { | |
37 | items.push({ | |
38 | xtype: 'hidden', | |
39 | name: key, | |
c87d46fb | 40 | value: value, |
7d51f9ff DC |
41 | }); |
42 | }); | |
43 | ||
28eb60c0 | 44 | let config = { |
161f4504 DM |
45 | method: 'POST', |
46 | url: url, | |
573a6e8b | 47 | onlineHelp: 'pmg_userblackwhitelist', |
18b5b6ad | 48 | isCreate: true, |
161f4504 | 49 | isAdd: true, |
c87d46fb | 50 | items: items, |
161f4504 DM |
51 | }; |
52 | ||
28eb60c0 | 53 | if (view.listname === 'blacklist') { |
161f4504 | 54 | config.subject = gettext("Blacklist"); |
28eb60c0 | 55 | } else if (view.listname === 'whitelist') { |
161f4504 DM |
56 | config.subject = gettext("Whitelist"); |
57 | } else { | |
58 | throw "unknown list - internal error"; | |
59 | } | |
60 | ||
28eb60c0 TL |
61 | let win = Ext.createWidget('proxmoxWindowEdit', config); |
62 | win.on('destroy', function() { view.store.load(); }); | |
161f4504 DM |
63 | win.show(); |
64 | }, | |
65 | ||
66 | onRemoveAddress: function() { | |
28eb60c0 TL |
67 | let view = this.getView(); |
68 | let records = view.selModel.getSelection(); | |
c41c3600 | 69 | if (records.length < 1) { |
c17f9fe4 DC |
70 | return; |
71 | } | |
161f4504 | 72 | |
28eb60c0 | 73 | let url = '/quarantine/' + view.listname + '/'; |
c41c3600 | 74 | |
a144e534 DC |
75 | let params = { |
76 | address: records.map((rec) => rec.getId()).join(','), | |
77 | }; | |
28eb60c0 | 78 | Ext.applyIf(params, view.getStore().getProxy().getExtraParams()); |
161f4504 DM |
79 | |
80 | Proxmox.Utils.API2Request({ | |
7d51f9ff | 81 | url: url + '?' + Ext.Object.toQueryString(params), |
161f4504 | 82 | method: 'DELETE', |
28eb60c0 | 83 | waitMsgTarget: view, |
161f4504 | 84 | callback: function(options, success, response) { |
28eb60c0 | 85 | view.store.load(); |
161f4504 | 86 | }, |
c87d46fb | 87 | failure: function(response, opts) { |
161f4504 | 88 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); |
c87d46fb | 89 | }, |
161f4504 | 90 | }); |
7d51f9ff DC |
91 | }, |
92 | ||
93 | changeEmail: function(combobox, value) { | |
28eb60c0 | 94 | let view = this.getView(); |
a32f9554 DC |
95 | if (value && combobox.isValid()) { |
96 | view.getStore().getProxy().setExtraParams({ | |
c87d46fb | 97 | pmail: value, |
a32f9554 DC |
98 | }); |
99 | view.getStore().load(); | |
100 | } | |
7d51f9ff DC |
101 | }, |
102 | ||
2f8fe1a3 | 103 | init: function(view) { |
28eb60c0 | 104 | let emailcb = this.lookupReference('email'); |
99bba12c | 105 | if (PMG.view === 'quarantineview') { |
c1f045cd | 106 | emailcb.setVisible(false); |
e8dbe195 | 107 | view.getStore().load(); |
c1f045cd DC |
108 | } else { |
109 | emailcb.getStore().getProxy().setExtraParams({ | |
c87d46fb | 110 | list: view.listname === 'blacklist' ? 'BL' : 'WL', |
c1f045cd | 111 | }); |
7d51f9ff | 112 | } |
2f8fe1a3 | 113 | Proxmox.Utils.monStoreErrors(view.getView(), view.getStore(), true); |
7d51f9ff DC |
114 | }, |
115 | ||
116 | control: { | |
c87d46fb | 117 | 'combobox': { |
7d51f9ff DC |
118 | change: { |
119 | fn: 'changeEmail', | |
c87d46fb TL |
120 | buffer: 500, |
121 | }, | |
122 | }, | |
123 | }, | |
161f4504 DM |
124 | }, |
125 | ||
126 | tbar: [ | |
7d51f9ff DC |
127 | { |
128 | xtype: 'combobox', | |
129 | displayField: 'mail', | |
2797743e | 130 | vtype: 'PMGMail', |
a32f9554 | 131 | allowBlank: false, |
7d51f9ff DC |
132 | valueField: 'mail', |
133 | store: { | |
134 | proxy: { | |
135 | type: 'proxmox', | |
c87d46fb | 136 | url: '/api2/json/quarantine/quarusers', |
96fba078 DC |
137 | }, |
138 | fields: [ | |
139 | { | |
140 | name: 'mail', | |
c87d46fb TL |
141 | renderer: Ext.htmlEncode, |
142 | }, | |
143 | ], | |
7d51f9ff DC |
144 | }, |
145 | queryParam: false, | |
146 | queryCaching: false, | |
147 | editable: true, | |
148 | reference: 'email', | |
149 | name: 'email', | |
d387246f DC |
150 | listConfig: { |
151 | emptyText: | |
152 | '<div class="x-grid-empty">' + | |
153 | gettext('No data in database') + | |
c87d46fb | 154 | '</div>', |
d387246f | 155 | }, |
d2d9df1a | 156 | fieldLabel: gettext('E-Mail'), |
7d51f9ff | 157 | }, |
161f4504 DM |
158 | { |
159 | text: gettext('Add'), | |
c87d46fb | 160 | handler: 'onAddAddress', |
161f4504 DM |
161 | }, |
162 | { | |
163 | xtype: 'proxmoxButton', | |
164 | text: gettext('Remove'), | |
165 | disabled: true, | |
166 | handler: 'onRemoveAddress', | |
c41c3600 | 167 | confirmMsg: function() { |
28eb60c0 | 168 | let view = this.up('gridpanel'); |
c41c3600 | 169 | |
28eb60c0 TL |
170 | let selection = view.selModel.getSelection(); |
171 | let text, param; | |
c41c3600 DC |
172 | if (selection.length > 1) { |
173 | text = gettext('Are you sure you want to remove {0} entries'); | |
174 | param = selection.length.toString(); | |
175 | } else if (selection.length > 0) { | |
28eb60c0 TL |
176 | let rec = selection[0]; |
177 | let name = rec.getId(); | |
c41c3600 DC |
178 | text = gettext('Are you sure you want to remove entry {0}'); |
179 | param = "'" + Ext.String.htmlEncode(name) + "'"; | |
180 | } | |
161f4504 | 181 | |
c41c3600 DC |
182 | if (text && param) { |
183 | return Ext.String.format(text, param); | |
184 | } | |
28eb60c0 | 185 | return false; |
c87d46fb TL |
186 | }, |
187 | }, | |
161f4504 DM |
188 | ], |
189 | ||
190 | columns: [ | |
191 | { | |
192 | header: gettext('Address'), | |
193 | dataIndex: 'address', | |
194 | renderer: Ext.String.htmlEncode, | |
c87d46fb TL |
195 | flex: 1, |
196 | }, | |
197 | ], | |
161f4504 DM |
198 | }); |
199 | ||
0277bfeb | 200 | Ext.define('PMG.UserBlacklist', { |
161f4504 DM |
201 | extend: 'PMG.UserBlackWhiteList', |
202 | xtype: 'pmgUserBlacklist', | |
0277bfeb DM |
203 | |
204 | title: gettext('Blacklist'), | |
161f4504 DM |
205 | |
206 | listname: 'blacklist', | |
207 | ||
208 | store: { | |
209 | model: 'pmg-address-list', | |
e8dbe195 | 210 | autoDestroy: true, |
161f4504 DM |
211 | proxy: { |
212 | type: 'proxmox', | |
c87d46fb | 213 | url: "/api2/json/quarantine/blacklist", |
c41c3600 DC |
214 | }, |
215 | sorters: { | |
c87d46fb TL |
216 | property: 'address', |
217 | }, | |
161f4504 DM |
218 | }, |
219 | ||
220 | dockedItems: [ | |
221 | { | |
222 | dock: 'top', | |
50531ef9 DC |
223 | bodyStyle: { |
224 | padding: '10px', | |
225 | 'border-left': '0px', | |
c87d46fb | 226 | 'border-right': '0px', |
50531ef9 | 227 | }, |
28eb60c0 TL |
228 | html: gettext('With this feature, you can manually mark E-mails from certain domains or addresses as spam.') + `<br><br> |
229 | <b>*.com</b> (all mails from <b>.com</b> domains)<br> | |
230 | <b>*@example.com</b> (all mails from domain <b>example.com</b>)<br> | |
231 | <b>john@example.com</b> (all mails from <b>john@example.com</b>)`, | |
c87d46fb TL |
232 | }, |
233 | ], | |
0277bfeb DM |
234 | }); |
235 | ||
236 | Ext.define('PMG.UserWhitelist', { | |
161f4504 | 237 | extend: 'PMG.UserBlackWhiteList', |
0277bfeb DM |
238 | xtype: 'pmgUserWhitelist', |
239 | ||
240 | title: gettext('Whitelist'), | |
0277bfeb | 241 | |
161f4504 | 242 | listname: 'whitelist', |
0277bfeb | 243 | |
161f4504 DM |
244 | store: { |
245 | model: 'pmg-address-list', | |
e8dbe195 | 246 | autoDestroy: true, |
161f4504 DM |
247 | proxy: { |
248 | type: 'proxmox', | |
c87d46fb | 249 | url: "/api2/json/quarantine/whitelist", |
c41c3600 DC |
250 | }, |
251 | sorters: { | |
c87d46fb TL |
252 | property: 'address', |
253 | }, | |
161f4504 | 254 | }, |
0277bfeb | 255 | |
161f4504 DM |
256 | dockedItems: [ |
257 | { | |
258 | dock: 'top', | |
50531ef9 DC |
259 | bodyStyle: { |
260 | padding: '10px', | |
261 | 'border-left': '0px', | |
c87d46fb | 262 | 'border-right': '0px', |
50531ef9 | 263 | }, |
28eb60c0 TL |
264 | html: gettext('With this feature, you can manually bypass spam checking for certain domains or E-mail addresses.') + `<br><br> |
265 | <b>*.com</b> (all mails from <b>.com</b> domains)<br> | |
266 | <b>*@example.com</b> (all mails from domain <b>example.com</b>)<br> | |
267 | <b>john@example.com</b> (all mails from <b>john@example.com</b>)`, | |
c87d46fb TL |
268 | }, |
269 | ], | |
161f4504 | 270 | }); |