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'): for tun_xml in tunnels_xml.findall('tunnel'):
tun_id = int(tun_xml.attrib['id'].strip()) tun_id = int(tun_xml.attrib['id'].strip())
tun_creds_id = tun_xml.attrib['creds'] 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 self.tunnels[tun_id] = tun
return(None) return(None)


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




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

View File

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

View File

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




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


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


def _assignments(self): def _assignments(self):

View File

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




class TunnelBroker(object): class TunnelBroker(object):
@ -40,14 +41,16 @@ class TunnelBroker(object):
if os.path.isfile(self.ip_cache): if os.path.isfile(self.ip_cache):
with open(self.ip_cache, 'r') as fh: with open(self.ip_cache, 'r') as fh:
self.cached_ips = [(datetime.datetime.fromtimestamp(i[0]), 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: if self.wan:
logger.debug('WAN IP tunneling enabled; fetching WAN IP.') logger.debug('WAN IP tunneling enabled; fetching WAN IP.')
req = requests.get(self.url_ip, params = self.params_ip) req = requests.get(self.url_ip, params = self.params_ip)
if not req.ok: if not req.ok:
logger.error('Could not fetch self IP. Request returned {0}.'.format(req.status_code)) logger.error('Could not fetch self IP. Request returned {0}.'.format(req.status_code))
raise RuntimeError('Could not fetch self IP') 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)) logger.debug('Set my_ip to {0}.'.format(self.my_ip.str))
else: else:
logger.debug('WAN IP tunneling disabled; fetching LAN IP.') 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. 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?') logger.error('Could not determine default route. Does this machine have a single default route?')
raise RuntimeError('Could not determine default IPv4 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() ipr.close()
logger.debug('Set my_ip to {0}.'.format(self.my_ip.str)) logger.debug('Set my_ip to {0}.'.format(self.my_ip.str))
chk_tuple = (datetime.datetime.utcnow(), self.my_ip) chk_tuple = (datetime.datetime.utcnow(), self.my_ip)
@ -204,7 +207,7 @@ class TunnelBroker(object):
def update(self): def update(self):
if not self.my_ip: if not self.my_ip:
self._get_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('Set auth handler.')
logger.debug('Requesting IP update at provider.') logger.debug('Requesting IP update at provider.')
req = requests.get(self.url_api, req = requests.get(self.url_api,