i...think it's ready to test.

This commit is contained in:
brent s. 2020-05-14 23:46:03 -04:00
parent efb53be81b
commit 742a0b55d5
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
4 changed files with 18 additions and 11 deletions

View File

@ -175,7 +175,10 @@ class Config(BaseConfig):
for tun_xml in tunnels_xml.findall('tunnel'):
tun_id = int(tun_xml.attrib['id'].strip())
tun_creds_id = tun_xml.attrib['creds']
tun = tunnel.Tunnel(tun_xml, self.creds[tun_creds_id])
creds = self.creds[tun_creds_id]
update_key = tun_xml.find('updateKey').text.strip()
he_conf = HETunnelConfig(tun_id, creds, update_key)
tun = tunnel.Tunnel(tun_xml, he_conf, self.creds[tun_creds_id])
self.tunnels[tun_id] = tun
return(None)

@ -223,7 +226,7 @@ class HEBaseConfig(BaseConfig):
return(raw_xml)


# This isn't really used anymore.
# This isn't really used.
class HEConfig(HEBaseConfig):
default_xsd = 'http://schema.xml.r00t2.io/projects/tunnelbroker.tun.xsd'
nsmap = {None: 'https://tunelbroker.net/tunnelInfo.php?tid',

View File

@ -8,6 +8,7 @@
https://www.tunnelbroker.net/tunnel_detail.php?tid=584532
I highly recommend their (free) certification as well if you're brand-new to IPv6:
https://ipv6.he.net/certification/
**It is VERY highly encouraged to only use one tunnel at a time on a machine.**
-->
<creds>
<!--

View File

@ -104,23 +104,23 @@ class Allocation(object):


class Tunnel(object):
def __init__(self, tun_xml, he_tunnels):
def __init__(self, tun_xml, he_tunnel, creds):
self.xml = tun_xml
self.creds = creds
self.he = he_tunnel
self.update_key = self.he.creds.password
self.id = None
self.client = None
self.server = None
self.creds = None
self.creds_id = None
self.radvd = None
self.enable_radvd = None
self.radvd_dns = None
self.allocations = {} # This is a dict of {}[alloc.id] = Allocation obj
self.assignments = [] # This is a list of Assignment objs
self.heconf = he_tunnels
self.parse()

def _allocations(self):
self.allocations = self.heconf[self.id].allocations
self.allocations = self.he.allocations
return(None)

def _assignments(self):

View File

@ -10,6 +10,7 @@ import requests.auth
from pyroute2 import IPRoute
##
from . import config
from . import tunnel


class TunnelBroker(object):
@ -40,14 +41,16 @@ class TunnelBroker(object):
if os.path.isfile(self.ip_cache):
with open(self.ip_cache, 'r') as fh:
self.cached_ips = [(datetime.datetime.fromtimestamp(i[0]),
config.IP4(i[1], 32)) for i in json.loads(fh.read())]
tunnel.IP4(i[1], 32)) for i in json.loads(fh.read())]
else:
os.makedirs(os.path.dirname(self.ip_cache), exist_ok = True, mode = 0o0700)
if self.wan:
logger.debug('WAN IP tunneling enabled; fetching WAN IP.')
req = requests.get(self.url_ip, params = self.params_ip)
if not req.ok:
logger.error('Could not fetch self IP. Request returned {0}.'.format(req.status_code))
raise RuntimeError('Could not fetch self IP')
self.my_ip = config.IP4(req.json()['ip'], 32)
self.my_ip = tunnel.IP4(req.json()['ip'], 32)
logger.debug('Set my_ip to {0}.'.format(self.my_ip.str))
else:
logger.debug('WAN IP tunneling disabled; fetching LAN IP.')
@ -56,7 +59,7 @@ class TunnelBroker(object):
if len(_defrt) != 1: # This (probably) WILL fail on multipath systems.
logger.error('Could not determine default route. Does this machine have a single default route?')
raise RuntimeError('Could not determine default IPv4 route')
self.my_ip = config.IP4(_defrt[0]['attrs']['RTA_PREFSRC'], 32)
self.my_ip = tunnel.IP4(_defrt[0]['attrs']['RTA_PREFSRC'], 32)
ipr.close()
logger.debug('Set my_ip to {0}.'.format(self.my_ip.str))
chk_tuple = (datetime.datetime.utcnow(), self.my_ip)
@ -204,7 +207,7 @@ class TunnelBroker(object):
def update(self):
if not self.my_ip:
self._get_my_ip()
auth_handler = requests.auth.HTTPBasicAuth(self.tun.creds.user, self.tun.creds.key)
auth_handler = requests.auth.HTTPBasicAuth(self.tun.creds.user, self.tun.creds.update_key)
logger.debug('Set auth handler.')
logger.debug('Requesting IP update at provider.')
req = requests.get(self.url_api,