Fix duplication security and add a bit of verbose on router insertion

This commit is contained in:
Ethanell 2020-03-01 15:04:37 +01:00
parent 648a3fcc07
commit b463117300
3 changed files with 17 additions and 14 deletions

View file

@ -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))

View file

@ -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")

View file

@ -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()