[FIX] Some fixes about encoding

This commit is contained in:
root
2026-03-06 22:11:43 +01:00
parent a8615a2f70
commit 4c23e0abe9
+9 -7
View File
@@ -247,6 +247,7 @@ ipv4 2 udp 17 178 src=192.168.149.184 dst=80.13.55.10 sport=1194 dport=1194 src=
10: ppp3g: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 3 10: ppp3g: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 3
6: br1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT 6: br1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
""" """
LINK = re.compile(r':\s+<(?P<link_states>.+)>.* state (?P<link_status>.+?)\s') LINK = re.compile(r':\s+<(?P<link_states>.+)>.* state (?P<link_status>.+?)\s')
link = LINK.search(output.decode('utf-8')) link = LINK.search(output.decode('utf-8'))
if link: if link:
@@ -331,7 +332,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss
else: else:
self._available = True self._available = True
else: else:
self.status = 'Device {} is down or link state is unknown'.format(self.device.decode('utf-8')) self.status = 'Device {} is down or link state is unknown'.format(str(self.device))
self._available = False self._available = False
self.update_leds() self.update_leds()
@@ -347,7 +348,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss
self.last_ip = ipaddr.groupdict()['ipv4'] self.last_ip = ipaddr.groupdict()['ipv4']
else: else:
self.last_ip = None self.last_ip = None
macaddr = MACADDR.search(output.decode('utf-8')) macaddr = MACADDR.search(str(output))
if macaddr: if macaddr:
self.device_mac = macaddr.groupdict()['mac'] self.device_mac = macaddr.groupdict()['mac']
self.device_type = macaddr.groupdict()['type'] self.device_type = macaddr.groupdict()['type']
@@ -372,7 +373,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss
88.163.76.254 scope link src 88.163.76.120 88.163.76.254 scope link src 88.163.76.120
""" """
GW = re.compile(r'default via (?P<gateway>\d+.\d+.\d+.\d+)\s+') GW = re.compile(r'default via (?P<gateway>\d+.\d+.\d+.\d+)\s+')
gw = GW.search(output.decode('utf-8')) gw = GW.search(str(output))
if gw: if gw:
logger.debug('Gateway : {}'.format(gw.groupdict()['gateway'])) logger.debug('Gateway : {}'.format(gw.groupdict()['gateway']))
return gw.groupdict()['gateway'] return gw.groupdict()['gateway']
@@ -389,7 +390,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss
try: try:
(retcode,routes) = run('ip route list table {}'.format(self.provider_name)) (retcode,routes) = run('ip route list table {}'.format(self.provider_name))
if retcode == 0: if retcode == 0:
routes = routes.decode('utf-8').splitlines() routes = str(routes).splitlines()
self.last_enabled = len(routes)>0 self.last_enabled = len(routes)>0
else: else:
self.last_enabled = False self.last_enabled = False
@@ -482,7 +483,7 @@ available == True if actual rtt and loss are below the max_rtt and max_loss
"""Remove default route which could have been added in main routing table and will prevent fallback interface from taking over""" """Remove default route which could have been added in main routing table and will prevent fallback interface from taking over"""
(retcode,routes) = run('ip route list table main dev {}'.format(self.device)) (retcode,routes) = run('ip route list table main dev {}'.format(self.device))
if retcode == 0: if retcode == 0:
if 'default ' in routes.decode('utf-8'): if 'default ' in str(routes):
print(run('ip route del default table main dev {}'.format(self.device),dry_run=self.dry_run)) print(run('ip route del default table main dev {}'.format(self.device),dry_run=self.dry_run))
def __str__(self): def __str__(self):
@@ -692,7 +693,7 @@ if __name__ == '__main__':
if not provider.enabled: if not provider.enabled:
logger.warning("Enabling the available provider {}".format(provider.provider_name)) logger.warning("Enabling the available provider {}".format(provider.provider_name))
provider.enable() provider.enable()
run('conntrack -F') run('/usr/sbin/conntrack -F')
if provider.openvpn_master: if provider.openvpn_master:
restart_openvpn() restart_openvpn()
@@ -707,7 +708,7 @@ if __name__ == '__main__':
nexthop via 185.16.51.9 realm 3 dev eth1 weight 1 nexthop via 185.16.51.9 realm 3 dev eth1 weight 1
nexthop dev tun2 weight 1 nexthop dev tun2 weight 1
""" """
balance = output.decode('utf-8').splitlines() balance = str(output).splitlines()
in_balance = False in_balance = False
for l in balance: for l in balance:
if provider.gateway in l.split(' ') or provider.device in l.split(' '): if provider.gateway in l.split(' ') or provider.device in l.split(' '):
@@ -716,6 +717,7 @@ if __name__ == '__main__':
if not in_balance: if not in_balance:
shorewall_restart_needed = True shorewall_restart_needed = True
logger.critical("Shorewall restart needed because provider {} is not in default balance route ".format(provider.provider_name)) logger.critical("Shorewall restart needed because provider {} is not in default balance route ".format(provider.provider_name))
run('/usr/sbin/shorewall restart && /usr/sbin/conntrack -F')
else: else: