From b463117300fd2b034bd4d6290a6f1ee664a79f35 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sun, 1 Mar 2020 15:04:37 +0100 Subject: [PATCH] Fix duplication security and add a bit of verbose on router insertion --- ip/ipv4.py | 1 - router/insert_router.py | 15 +++++++++------ whmcs/insert_whmcs.py | 15 ++++++++------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/ip/ipv4.py b/ip/ipv4.py index 47e5944..333e8c3 100644 --- a/ip/ipv4.py +++ b/ip/ipv4.py @@ -35,7 +35,6 @@ def ipv4(prefix: str, ipl: [IPv4Address] = None, macl: [str] = None) -> [(IPv4Ad # For all ip in prefix for ip in ips.hosts(): mac = None - ip = str(ip) if ip not in ipl: ipl.append(ip) mac = str(RandMac("00:00:00:00:00:00", True)) diff --git a/router/insert_router.py b/router/insert_router.py index 41f1360..0f8e60f 100644 --- a/router/insert_router.py +++ b/router/insert_router.py @@ -26,10 +26,13 @@ def insert_router_ipv4(insert: [(IPv4Address, str, IPv4Address, int)], interface ipl = get_router_ipv4(host, port, user, key) + print("Start insert on router") for i in insert: - if ((i[0] not in ipl) or not (ipl[ipl.find(i[0]):5].replace(" ", ""))) and (i[1] not in ipl): - cmd = ["ssh", "-i", key, "-o", "StrictHostKeyChecking no", f"{user}@{host}", "-p", str(port), f"/ip arp add address={i[0]} mac-address={i[1]} interface={interface}".replace("'", "")] - if not debug: - run(cmd) - else: - print(cmd) + if i[1]: + if ((i[0] not in ipl) or not (ipl[ipl.find(i[0]):5].replace(" ", ""))) and (i[1] not in ipl): + cmd = ["ssh", "-i", key, "-o", "StrictHostKeyChecking no", f"{user}@{host}", "-p", str(port), f"/ip arp add address={i[0]} mac-address={i[1]} interface={interface}".replace("'", "")] + if not debug: + run(cmd) + else: + print(cmd) + print("Insert on router done") diff --git a/whmcs/insert_whmcs.py b/whmcs/insert_whmcs.py index 1cbca72..9da7c79 100644 --- a/whmcs/insert_whmcs.py +++ b/whmcs/insert_whmcs.py @@ -31,13 +31,14 @@ def insert_whmcs_ipv4(insert: [(IPv4Address, str, IPv4Address, int)], interface: # For every IP to insert for i in insert: - cmd = f"INSERT INTO mg_proxmox_addon_ip (ip, type, mac_address, subnet_mask, cidr, gateway, tag) " \ - f"VALUES ('{i[0]}', 'IPv4', {i[1]}, '{i[2]}', {i[3]}, '{gateway}', {vlan})" - try: - cursor.execute(cmd) - except Exception as e: - print(cmd, file=stderr) - raise e + if i[1]: + cmd = f"INSERT INTO mg_proxmox_addon_ip (ip, type, mac_address, subnet_mask, cidr, gateway, tag) " \ + f"VALUES ('{i[0]}', 'IPv4', {i[1]}, '{i[2]}', {i[3]}, '{gateway}', {vlan})" + try: + cursor.execute(cmd) + except Exception as e: + print(cmd, file=stderr) + raise e cursor.close()