better commands
This commit is contained in:
parent
1919ec183e
commit
f7c2f313f7
@ -19,9 +19,7 @@ pub fn start_tcp_command_server() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_client(mut stream: &TcpStream) {
|
fn handle_client(mut stream: &TcpStream) {
|
||||||
let reader = BufReader::new(stream);
|
for line in BufReader::new(stream).lines() {
|
||||||
|
|
||||||
for line in reader.lines() {
|
|
||||||
let buffer = match line {
|
let buffer = match line {
|
||||||
Ok(data) => data,
|
Ok(data) => data,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
@ -44,7 +42,35 @@ fn handle_client(mut stream: &TcpStream) {
|
|||||||
|
|
||||||
fn handle_command(command: &str, arguments: Vec<&str>) -> String {
|
fn handle_command(command: &str, arguments: Vec<&str>) -> String {
|
||||||
match command {
|
match command {
|
||||||
"ban" => {
|
"banport" => {
|
||||||
|
if let Some(port) = arguments.get(0) {
|
||||||
|
let iptables = iptables::new(false).unwrap();
|
||||||
|
let _ = iptables.append_unique(
|
||||||
|
"filter",
|
||||||
|
"INPUT",
|
||||||
|
&format!("-p tcp --dport {} -j DROP", port),
|
||||||
|
);
|
||||||
|
|
||||||
|
format!("banned port {} for all ips", port)
|
||||||
|
} else {
|
||||||
|
"missing args for banport: port".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"unbanport" => {
|
||||||
|
if let Some(port) = arguments.get(0) {
|
||||||
|
let iptables = iptables::new(false).unwrap();
|
||||||
|
let _ = iptables.delete(
|
||||||
|
"filter",
|
||||||
|
"INPUT",
|
||||||
|
&format!("-p tcp --dport {} -j DROP", port),
|
||||||
|
);
|
||||||
|
|
||||||
|
format!("unbanned port {}", port)
|
||||||
|
} else {
|
||||||
|
"missing args for unbanport: port".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"allowipport" => {
|
||||||
if let (Some(ip), Some(port)) = (arguments.get(0), arguments.get(1)) {
|
if let (Some(ip), Some(port)) = (arguments.get(0), arguments.get(1)) {
|
||||||
let iptables = iptables::new(false).unwrap();
|
let iptables = iptables::new(false).unwrap();
|
||||||
let _ = iptables.append_unique(
|
let _ = iptables.append_unique(
|
||||||
@ -52,19 +78,12 @@ fn handle_command(command: &str, arguments: Vec<&str>) -> String {
|
|||||||
"INPUT",
|
"INPUT",
|
||||||
&format!("-s {} -p tcp --dport {} -j ACCEPT", ip, port),
|
&format!("-s {} -p tcp --dport {} -j ACCEPT", ip, port),
|
||||||
);
|
);
|
||||||
|
format!("allowed {} to access {}", ip, port)
|
||||||
let _ = iptables.append_unique(
|
|
||||||
"filter",
|
|
||||||
"INPUT",
|
|
||||||
&format!("-p tcp --dport {} -j DROP", port),
|
|
||||||
);
|
|
||||||
|
|
||||||
format!("banned port {}, only {} allowed", port, ip)
|
|
||||||
} else {
|
} else {
|
||||||
"missing args for ban: ip and port".to_string()
|
"missing args for allowipport: ip and port".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"unban" => {
|
"removeipport" => {
|
||||||
if let (Some(ip), Some(port)) = (arguments.get(0), arguments.get(1)) {
|
if let (Some(ip), Some(port)) = (arguments.get(0), arguments.get(1)) {
|
||||||
let iptables = iptables::new(false).unwrap();
|
let iptables = iptables::new(false).unwrap();
|
||||||
let _ = iptables.delete(
|
let _ = iptables.delete(
|
||||||
@ -72,16 +91,9 @@ fn handle_command(command: &str, arguments: Vec<&str>) -> String {
|
|||||||
"INPUT",
|
"INPUT",
|
||||||
&format!("-s {} -p tcp --dport {} -j ACCEPT", ip, port),
|
&format!("-s {} -p tcp --dport {} -j ACCEPT", ip, port),
|
||||||
);
|
);
|
||||||
|
format!("rm {} access to {}", ip, port)
|
||||||
let _ = iptables.delete(
|
|
||||||
"filter",
|
|
||||||
"INPUT",
|
|
||||||
&format!("-p tcp --dport {} -j DROP", port),
|
|
||||||
);
|
|
||||||
|
|
||||||
format!("unbanned port {}, used for {}", port, ip)
|
|
||||||
} else {
|
} else {
|
||||||
"missing args for unban: ip and port".to_string()
|
"missing args for rmipport: ip and port".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user