moving code from command server into cli

This commit is contained in:
midefos committed 2024-05-28 16:03:32 +02:00
1 parent 8a6021aa83
commit d53ca8a33a
8 files changed
+323 -146

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
pub fn ban_port(port: u16) {
let iptables = iptables::new(false).unwrap();
let _ = iptables.append_unique(
"filter",
"INPUT",
&format!("-p tcp --dport {} -j DROP", port),
);
println!("banned port {}", port);
}
pub fn unban_port(port: u16) {
let iptables = iptables::new(false).unwrap();
let _ = iptables.delete(
"filter",
"INPUT",
&format!("-p tcp --dport {} -j DROP", port),
);
println!("unbanned port {}", port);
}
pub fn allow_ip_port(ip: &str, port: u16) {
let iptables = iptables::new(false).unwrap();
let _ = iptables.append_unique(
"filter",
"INPUT",
&format!("-p tcp --dport {} -s {} -j ACCEPT", port, ip),
);
println!("allowed {} to access {}", ip, port);
}
pub fn remove_ip_port(ip: &str, port: u16) {
let iptables = iptables::new(false).unwrap();
let _ = iptables.delete(
"filter",
"INPUT",
&format!("-p tcp --dport {} -s {} -j ACCEPT", port, ip),
);
println!("removed access {} to {}", ip, port);
}