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