add some error checkings for livebox req timeouts
This commit is contained in:
parent
f0033fb61a
commit
60b13d46f7
31
dyndomain
31
dyndomain
@ -74,9 +74,11 @@ def ping(hostname):
|
|||||||
|
|
||||||
|
|
||||||
def get_hosts():
|
def get_hosts():
|
||||||
r = sysbus.requete('Devices:get')
|
r = sysbus.requete('Devices:get', silent=True)
|
||||||
|
|
||||||
hosts = { 'A': {}, 'AAAA': {} }
|
hosts = { 'A': {}, 'AAAA': {} }
|
||||||
|
if not r:
|
||||||
|
return hosts
|
||||||
|
|
||||||
for h in r['status']:
|
for h in r['status']:
|
||||||
ns = {}
|
ns = {}
|
||||||
for n in h['Names']:
|
for n in h['Names']:
|
||||||
@ -102,8 +104,11 @@ def get_hosts():
|
|||||||
|
|
||||||
|
|
||||||
def get_wan_addr():
|
def get_wan_addr():
|
||||||
r = sysbus.requete('NMC:getWANStatus')
|
r = sysbus.requete('NMC:getWANStatus', silent=True)
|
||||||
wan = dict()
|
wan = dict()
|
||||||
|
if not r or not r.get('data') or not r['data'].get('IPAddress') or not r['data'].get('IPv6Address'):
|
||||||
|
log('get_wan_addr: {}'.format(r))
|
||||||
|
return None
|
||||||
wan['ipv4'] = r['data']['IPAddress']
|
wan['ipv4'] = r['data']['IPAddress']
|
||||||
wan['ipv6'] = r['data']['IPv6Address']
|
wan['ipv6'] = r['data']['IPv6Address']
|
||||||
if wan['ipv4'] == '0.0.0.0':
|
if wan['ipv4'] == '0.0.0.0':
|
||||||
@ -273,12 +278,12 @@ def livebox_rule_id(words):
|
|||||||
def livebox_delete_port_nat(port, addr):
|
def livebox_delete_port_nat(port, addr):
|
||||||
log('livebox: delete PortNat {} to {}'.format(port, addr))
|
log('livebox: delete PortNat {} to {}'.format(port, addr))
|
||||||
id = livebox_rule_id([port])
|
id = livebox_rule_id([port])
|
||||||
r = sysbus.requete('Firewall:deletePortForwarding', { 'id': id, 'origin': 'webui' })
|
r = sysbus.requete('Firewall:deletePortForwarding', { 'id': id, 'origin': 'webui' }, silent=True)
|
||||||
|
|
||||||
def livebox_delete_pinhole(port, addr):
|
def livebox_delete_pinhole(port, addr):
|
||||||
log('livebox: delete pinhole {} to {}'.format(port, addr))
|
log('livebox: delete pinhole {} to {}'.format(port, addr))
|
||||||
id = livebox_rule_id([port, addr])
|
id = livebox_rule_id([port, addr])
|
||||||
r = sysbus.requete('Firewall:deletePinhole', { 'id': id, 'origin': 'webui' })
|
r = sysbus.requete('Firewall:deletePinhole', { 'id': id, 'origin': 'webui' }, silent=True)
|
||||||
|
|
||||||
def livebox_add_port_nat(port, addr):
|
def livebox_add_port_nat(port, addr):
|
||||||
log('livebox: add PortNat {} to {}'.format(port, addr))
|
log('livebox: add PortNat {} to {}'.format(port, addr))
|
||||||
@ -292,7 +297,7 @@ def livebox_add_port_nat(port, addr):
|
|||||||
'internalPort': port,
|
'internalPort': port,
|
||||||
'enable': True,
|
'enable': True,
|
||||||
}
|
}
|
||||||
r = sysbus.requete('Firewall:setPortForwarding', a)
|
r = sysbus.requete('Firewall:setPortForwarding', a, silent=True)
|
||||||
|
|
||||||
def livebox_add_pinhole(port, addr):
|
def livebox_add_pinhole(port, addr):
|
||||||
log('livebox: add pinhole {} to {}'.format(port, addr))
|
log('livebox: add pinhole {} to {}'.format(port, addr))
|
||||||
@ -307,7 +312,7 @@ def livebox_add_pinhole(port, addr):
|
|||||||
'ipversion': '6',
|
'ipversion': '6',
|
||||||
'enable': True,
|
'enable': True,
|
||||||
}
|
}
|
||||||
r = sysbus.requete('Firewall:setPinhole', a)
|
r = sysbus.requete('Firewall:setPinhole', a, silent=True)
|
||||||
|
|
||||||
def livebox_update_fw(zone, update, sync_zone):
|
def livebox_update_fw(zone, update, sync_zone):
|
||||||
for prot, addr, port in update['delete']:
|
for prot, addr, port in update['delete']:
|
||||||
@ -372,13 +377,19 @@ if not ping(wan_hostname):
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
sysbus.load_conf()
|
sysbus.load_conf()
|
||||||
r = sysbus.auth(False)
|
try:
|
||||||
if not r:
|
r = sysbus.auth(False)
|
||||||
log('Error: cannot authenticate on livebox')
|
if not r:
|
||||||
|
log('Error: cannot authenticate on livebox')
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
log('Error: %s'.format(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
hosts = get_hosts()
|
hosts = get_hosts()
|
||||||
wan = get_wan_addr()
|
wan = get_wan_addr()
|
||||||
|
if not wan:
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
zone = read_zone_list(zone_filename)
|
zone = read_zone_list(zone_filename)
|
||||||
sync_zone = False
|
sync_zone = False
|
||||||
|
Loading…
Reference in New Issue
Block a user