49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
import argparse
|
|
from dnsocial.creds import GoDaddyCreds
|
|
from dnsocial.dns import find_last_int
|
|
|
|
from godaddypy import Client, Account
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(
|
|
prog='post', description="Post to DNSocial",
|
|
)
|
|
parser.add_argument('-c', '--creds', required=False, help="Location of creds.json file (default is working directory)")
|
|
parser.add_argument('-d', '--domain', required=True, help="Domain to post to")
|
|
parser.add_argument('-p', '--post', required=True, help="Your post!")
|
|
|
|
args = parser.parse_args()
|
|
return args
|
|
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
if args.creds is not None:
|
|
creds = GoDaddyCreds.from_json(args.creds)
|
|
else:
|
|
creds = GoDaddyCreds.from_json()
|
|
|
|
account = Account(api_key=creds.key, api_secret=creds.secret)
|
|
client = Client(account)
|
|
|
|
# find the last integer to post from
|
|
post_int = find_last_int(args.domain)
|
|
|
|
# check if we are posting to a subdomain
|
|
domain_parts = args.domain.split('.')
|
|
if len(domain_parts)>2:
|
|
subdomain = domain_parts[:-2]
|
|
subdomain.insert(0, str(post_int))
|
|
dns_name = '.'.join(subdomain)
|
|
else:
|
|
dns_name = str(post_int)
|
|
|
|
client.add_record(args.domain, {
|
|
'data': args.post,
|
|
'name': dns_name,
|
|
'ttl': 3600,
|
|
'type': 'TXT'
|
|
})
|
|
print(f'Posted to {post_int}.{args.domain}')
|
|
|