forked from midefos/martillo-maldito
altering also docker chain
This commit is contained in:
1 parent
d53ca8a33a
commit
9cffe40520
3 files changed
+30
-12
No files matched your search
+17
-8
@@ -1,41 +1,50 @@
|
||||
pub fn ban_port(port: u16) {
|
||||
pub fn ban_port(port: u16, docker: bool) {
|
||||
let iptables = iptables::new(false).unwrap();
|
||||
|
||||
let _ = iptables.append_unique(
|
||||
"filter",
|
||||
"INPUT",
|
||||
&get_chain(docker),
|
||||
&format!("-p tcp --dport {} -j DROP", port),
|
||||
);
|
||||
|
||||
println!("banned port {}", port);
|
||||
}
|
||||
|
||||
pub fn unban_port(port: u16) {
|
||||
pub fn unban_port(port: u16, docker: bool) {
|
||||
let iptables = iptables::new(false).unwrap();
|
||||
let _ = iptables.delete(
|
||||
"filter",
|
||||
"INPUT",
|
||||
&get_chain(docker),
|
||||
&format!("-p tcp --dport {} -j DROP", port),
|
||||
);
|
||||
|
||||
println!("unbanned port {}", port);
|
||||
}
|
||||
|
||||
pub fn allow_ip_port(ip: &str, port: u16) {
|
||||
pub fn allow_ip_port(ip: &str, port: u16, docker: bool) {
|
||||
let iptables = iptables::new(false).unwrap();
|
||||
let _ = iptables.append_unique(
|
||||
"filter",
|
||||
"INPUT",
|
||||
&get_chain(docker),
|
||||
&format!("-p tcp --dport {} -s {} -j ACCEPT", port, ip),
|
||||
);
|
||||
println!("allowed {} to access {}", ip, port);
|
||||
}
|
||||
|
||||
pub fn remove_ip_port(ip: &str, port: u16) {
|
||||
pub fn remove_ip_port(ip: &str, port: u16, docker: bool) {
|
||||
let iptables = iptables::new(false).unwrap();
|
||||
let _ = iptables.delete(
|
||||
"filter",
|
||||
"INPUT",
|
||||
&get_chain(docker),
|
||||
&format!("-p tcp --dport {} -s {} -j ACCEPT", port, ip),
|
||||
);
|
||||
println!("removed access {} to {}", ip, port);
|
||||
}
|
||||
|
||||
fn get_chain(docker: bool) -> String {
|
||||
if docker {
|
||||
"DOCKER-USER".to_string()
|
||||
} else {
|
||||
"INPUT".to_string()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user