fix: portstring & newline

This commit is contained in:
2022-12-21 21:44:53 +01:00
parent ef3729f529
commit 8501f494c6

7
vm.py
View File

@@ -52,9 +52,8 @@ class VM:
entries = [] entries = []
BASE = "iptables -t mangle -{option} " BASE = "iptables -t mangle -{option} "
RULE = "PREROUTING -p {proto} -s {ip} {port} -j MARK --set-xmark 0x1/0xffffffff" RULE = "PREROUTING -p {proto} -s {ip} {port} -j MARK --set-xmark 0x1/0xffffffff\n"
PORT_SIMPLE = "--sport {port}" PORT_SIMPLE = "--sport {port}"
PORT_MULTI = "--match multiport --sports {port}"
option = "A" option = "A"
if remove: if remove:
@@ -66,8 +65,8 @@ class VM:
port = portStruct.get("port") port = portStruct.get("port")
partport = PORT_SIMPLE.format(port=port) partport = PORT_SIMPLE.format(port=port)
if type(port) == str and "-" in port: if type(port) == str and "-" in port:
port = port.replace("-", "") port = port.replace("-", ":").replace(" ","")
part_port = PORT_MULTI.format(port=port) partport = PORT_SIMPLE.format(port=port)
entry = BASE.format(option=option) entry = BASE.format(option=option)
entry += RULE.format(ip=self.ip, port=partport, proto=portStruct.get("proto", "tcp")) entry += RULE.format(ip=self.ip, port=partport, proto=portStruct.get("proto", "tcp"))