diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000000000000000000000000000000000..333b42d6c1afbb776d915f23deb530eef9f5e054 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +MODOBOA_API_BASE= +PDNS_API_BASE= +MODOBOA_TOKEN= +PDNS_TOKEN= \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..0a4393b688d2a57007b4817800f2322c7d651b1b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.env +.vscode +.tmp +venv + diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..26d28f39829e433ded69ded608c9971e12ef76e2 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# DNS IP changer + +## Preparations + +Explain how to set + +``` +MODOBOA_API_BASE= +PDNS_API_BASE= +``` + +``` +MODOBOA_TOKEN= +PDNS_TOKEN= +``` + +in `.env` from copying `.env.example`, and why. + +Eventually create a venv, pyenv, pipenv, ... + +Install requirements + +``` +pip3 install -U pip +pip3 install -U requests python-dotenv +``` + +## Usage + +This tool helps to migrate DNS A records pointing at a certain IP to another one. + +``` +Usage: +./pdns-api.py from-ip to-ip +``` + +## Related + +This work lives on in [modoboa-pdns-bridge.py · ecobytes / lab / mx](https://lab.allmende.io/ecobytes/lab/mx/-/blob/master/modoboa-pdns-bridge.py) + +## Authors + +- Johannes Winter + +## License + +© Ecobytes e.V. diff --git a/pdns-api.py b/pdns-api.py old mode 100644 new mode 100755 index 5dd2001f423b1ecde1fa8c9e433b309b6b307645..3eed7508c0670f53febdf64843dada9faa1bbcf1 --- a/pdns-api.py +++ b/pdns-api.py @@ -1,11 +1,13 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 ## imports -import json import requests import os, sys +import pprint ## loaders +pp = pprint.PrettyPrinter(sort_dicts=True, indent=4) + from dotenv import load_dotenv env_path = os.path.abspath ( os.path.join ( os.curdir, os.path.relpath('.env') ) ) @@ -41,14 +43,11 @@ def set_record(zone, name, type, record): ] } print ('payload') - pprint(payload) + pp.pprint(payload) p = requests.patch(PDNS_API_BASE + 'zones/' + zone, headers={'X-API-KEY': PDNS_TOKEN}, json=payload) print (p.text) -def pprint(text): - print json.dumps(text, sort_keys=True, indent=4, separators=(',', ': ')) - def change_ip(record,ip): record['content']=ip set_record(record['zone'],record['name'],record['type'], record) @@ -60,7 +59,7 @@ def change_records(a, b): if len(sys.argv) > 1: - [pprint(result) for result in search_pdns(sys.argv[1])] + [pp.pprint(result) for result in search_pdns(sys.argv[1])] if len(sys.argv) > 2: change_records(sys.argv[1], sys.argv[2]) else: