Skip to content

Commit 16d3def

Browse files
committed
Add explicit banning option to ipfilter window
1 parent 1e89454 commit 16d3def

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

core/src/com/biglybt/internat/MessagesBundle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -5367,6 +5367,7 @@ Peers.column.localintf.info=Local network interface
53675367
menu.config.is.default=Currently Set to Default Value
53685368
copy.config.param.name=Copy Option Name to Clipboard
53695369
ConfigView.section.ipfilter.unban=List of IP addresses to unban [, separated]
5370+
ConfigView.section.ipfilter.ban=List of IP addresses to ban [, separated]
53705371
Button.unban=Unban
53715372
Button.unban.all=Unban All
53725373
ConfigView.section.ipfilter.list.unbanned=has been unbanned

uis/src/com/biglybt/ui/swt/BlockedIpsWindow.java

+54-3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,39 @@ public void widgetDisposed(DisposeEvent event) {
128128
Label bannedInfo = new Label(window, SWT.NULL);
129129
Messages.setLanguageText(bannedInfo,"ConfigView.section.ipfilter.bannedinfo");
130130

131+
// manual ban
132+
133+
Label lblBan = new Label(window,SWT.NULL );
134+
Messages.setLanguageText(lblBan,"ConfigView.section.ipfilter.ban");
135+
136+
Text textBan = new Text(window,SWT.BORDER );
137+
138+
Button btnBan = new Button(window,SWT.PUSH);
139+
Messages.setLanguageText(btnBan,"label.ban");
140+
141+
btnBan.addListener(SWT.Selection, (ev)->{
142+
IpFilter filter = core.getIpFilterManager().getIPFilter();
143+
BadIps badIPs = core.getIpFilterManager().getBadIps();
144+
145+
String[] ips = textBan.getText().replace(';',',' ).split( "," );
146+
for ( String ip: ips ){
147+
ip = ip.trim();
148+
if ( !ip.isEmpty()){
149+
filter.ban(ip, MessageText.getString( "manual.mode"), true );
150+
textBanned.append( ip + " " + MessageText.getString( "ConfigView.section.ipfilter.list.banned" ) + "\n");
151+
}
152+
}
153+
textBanned.setSelection(textBanned.getText().length());
154+
});
155+
156+
textBan.addListener( SWT.Modify, (ev)->{
157+
btnBan.setEnabled( !textBan.getText().trim().isEmpty());
158+
});
159+
160+
btnBan.setEnabled( false );
161+
162+
// manual unban
163+
131164
Label lblUnban = new Label(window,SWT.NULL );
132165
Messages.setLanguageText(lblUnban,"ConfigView.section.ipfilter.unban");
133166

@@ -211,10 +244,28 @@ public void widgetDisposed(DisposeEvent event) {
211244
formData.left = new FormAttachment(0,0);
212245
formData.right = new FormAttachment(100,0);
213246
formData.top = new FormAttachment(btnClear);
214-
formData.bottom = new FormAttachment(btnUnban);
247+
formData.bottom = new FormAttachment(btnBan);
215248

216249
textBanned.setLayoutData(formData);
217250

251+
// ban line
252+
253+
formData = new FormData();
254+
formData.left = new FormAttachment(0,0);
255+
formData.top = new FormAttachment(btnBan,0,SWT.CENTER);
256+
lblBan.setLayoutData(formData);
257+
258+
formData = new FormData();
259+
formData.left = new FormAttachment(lblBan,100);
260+
formData.right = new FormAttachment(btnBan);
261+
formData.top = new FormAttachment(btnBan,0,SWT.CENTER);
262+
textBan.setLayoutData(formData);
263+
264+
formData = new FormData();
265+
formData.right = new FormAttachment(btnOk);
266+
formData.bottom = new FormAttachment(btnUnban);
267+
btnBan.setLayoutData(formData);
268+
218269
// unban line
219270

220271
formData = new FormData();
@@ -223,7 +274,7 @@ public void widgetDisposed(DisposeEvent event) {
223274
lblUnban.setLayoutData(formData);
224275

225276
formData = new FormData();
226-
formData.left = new FormAttachment(lblUnban);
277+
formData.left = new FormAttachment(textBan,0,SWT.LEFT);
227278
formData.right = new FormAttachment(btnUnban);
228279
formData.top = new FormAttachment(btnUnban,0,SWT.CENTER);
229280
textUnban.setLayoutData(formData);
@@ -264,7 +315,7 @@ public void widgetDisposed(DisposeEvent event) {
264315
textBlocked.setSelection(textBlocked.getText().length());
265316
textBanned.setSelection(textBanned.getText().length());
266317

267-
Utils.makeButtonsEqualWidth( btnUnban, btnClear, btnReset, btnOk );
318+
Utils.makeButtonsEqualWidth( btnBan, btnUnban, btnClear, btnReset, btnOk );
268319

269320
window.setDefaultButton( btnOk );
270321

0 commit comments

Comments
 (0)