42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
|
|
import urllib.request
|
|
import argparse
|
|
import json
|
|
|
|
class ungleichDNS(object):
|
|
def __init__(self, parser, parents):
|
|
self.parser = parser
|
|
|
|
self.parser['dns'] = self.parser['sub'].add_parser(
|
|
'dns',
|
|
help="Manage DNS entries @ ungleich",
|
|
parents=[parents])
|
|
|
|
self.parser['dns'].add_argument('--set-reverse', help='REQUIRED: IPv6 Address of your VM', required=True)
|
|
self.parser['dns'].add_argument('--user', help='Your ungleich username', required=True)
|
|
self.parser['dns'].add_argument('--token', help='Your ungleich 6 digit OTP generated token', type=int, required=True)
|
|
self.parser['dns'].add_argument('--name', help='Hostname', required=True)
|
|
self.parser['dns'].add_argument('--email', help='registered email', required=True)
|
|
self.parser['dns'].add_argument('--realm', help='Otp realm', required=True)
|
|
self.parser['dns'].set_defaults(func=self._handle_dns)
|
|
|
|
def _handle_dns(self, args):
|
|
"""Reverse dns endpoint."""
|
|
url = 'https://dns.service.ungleich.ch'
|
|
req = urllib.request.Request(
|
|
url=url,
|
|
method='POST',
|
|
headers={
|
|
"Content-Type": "application/json"
|
|
},
|
|
data=json.dumps({
|
|
'username': args.user,
|
|
'token': args.token,
|
|
'ipaddress': args.set_reverse,
|
|
'name': args.name,
|
|
'email': args.email,
|
|
'realm': args.realm
|
|
}).encode('utf-8')
|
|
)
|
|
response = urllib.request.urlopen(req).read()
|
|
print(json.loads(response))
|