#!/usr/bin/env python3 import subprocess from xmlrpc.client import ServerProxy import ssl import os dns = [] dns_section = False p = subprocess.Popen(['systemd-resolve','--status'],stdout=subprocess.PIPE) for x in [ z.decode('utf-8') for z in p.stdout.readlines()]: if "DNS Servers:" in x: dns_section = True elif ":" in x and dns_section: dns_section = False if dns_section: aux_dns = x.split(':')[-1].strip() if aux_dns.startswith('127'): continue dns.append(aux_dns) if len(dns) <= 0 : os.exit(0) with open('/var/lib/dnsmasq/config/extra-dns','w') as fd: for x in dns: fd.write("server=" + x + "\n") fd.write('\n') context = ssl.SSLContext() context.verify_mode = ssl.CERT_NONE c = ServerProxy('https://localhost:9779',context=context) key = None with open('/etc/n4d/key','r') as fd: key = fd.readline().strip() result = c.read_guardmode(key,'LliurexGuardManager') if result['status'] and result['data'] == 'WhiteMode': result = c.update_whitelist_dns(key,'LliurexGuardManager') if not result['status']: c.change_guardmode(key,'LliurexGuardManager','DisableMode') o = subprocess.Popen(['systemctl','restart','dnsmasq']).communicate()