2019-06-06 14:19:43 +00:00
|
|
|
import urllib.request
|
2019-05-12 08:27:07 +00:00
|
|
|
import argparse
|
2019-06-06 14:19:43 +00:00
|
|
|
import json
|
2019-06-12 00:57:55 +00:00
|
|
|
from pyotp import TOTP
|
2019-05-12 08:27:07 +00:00
|
|
|
|
|
|
|
class ungleichDNS(object):
|
|
|
|
def __init__(self, parser, parents):
|
|
|
|
self.parser = parser
|
|
|
|
|
|
|
|
self.parser['dns'] = self.parser['sub'].add_parser(
|
2019-05-12 10:42:28 +00:00
|
|
|
'dns',
|
|
|
|
help="Manage DNS entries @ ungleich",
|
|
|
|
parents=[parents])
|
2019-05-12 08:27:07 +00:00
|
|
|
|
2019-05-18 16:39:28 +00:00
|
|
|
self.parser['dns'].add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', required=True)
|
2019-06-12 00:57:55 +00:00
|
|
|
self.parser['dns'].add_argument('--user', help='Your stored user ID', required=True)
|
2019-05-18 16:39:28 +00:00
|
|
|
self.parser['dns'].add_argument('--name', help='Hostname', required=True)
|
|
|
|
self.parser['dns'].add_argument('--email', help='registered email', required=True)
|
2019-05-15 22:49:00 +00:00
|
|
|
self.parser['dns'].set_defaults(func=self._handle_dns)
|
2019-05-12 08:27:07 +00:00
|
|
|
|
2019-05-15 22:49:00 +00:00
|
|
|
def _handle_dns(self, args):
|
2019-05-30 09:24:09 +00:00
|
|
|
"""Reverse dns endpoint."""
|
2019-06-12 00:57:55 +00:00
|
|
|
f = open('users.json', 'r')
|
|
|
|
data = json.loads(f.read())[args.user]
|
|
|
|
|
2019-06-06 14:19:43 +00:00
|
|
|
url = 'https://dns.service.ungleich.ch'
|
|
|
|
req = urllib.request.Request(
|
|
|
|
url=url,
|
|
|
|
method='POST',
|
|
|
|
headers={
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
data=json.dumps({
|
2019-06-12 00:57:55 +00:00
|
|
|
'username': data['name'],
|
|
|
|
'token': TOTP(data['seed']).now(),
|
2019-05-15 22:49:00 +00:00
|
|
|
'ipaddress': args.set_reverse,
|
|
|
|
'name': args.name,
|
|
|
|
'email': args.email,
|
2019-06-12 00:57:55 +00:00
|
|
|
'realm': data['realm']
|
2019-06-06 14:19:43 +00:00
|
|
|
}).encode('utf-8')
|
|
|
|
)
|
2019-06-12 00:57:55 +00:00
|
|
|
try:
|
|
|
|
response = urllib.request.urlopen(req).read()
|
2019-06-13 01:02:04 +00:00
|
|
|
print(response)
|
2019-06-12 00:57:55 +00:00
|
|
|
except urllib.error.HTTPError as e:
|
|
|
|
error_message = e.read()
|
|
|
|
print(json.loads(error_message))
|