Compare commits
4 Commits
62586de020
...
f77ade44d5
| Author | SHA1 | Date | |
|---|---|---|---|
| f77ade44d5 | |||
| c5d6916fa6 | |||
| 1b2bb83eeb | |||
| 2884cd91a8 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
.env
|
||||
**/__pycache__
|
||||
**/*.pem
|
||||
|
||||
14
README.md
14
README.md
@@ -28,3 +28,17 @@ Copy the `app.py` file to your desired location, and run it using Python:
|
||||
```bash
|
||||
flask run app.py
|
||||
```
|
||||
|
||||
## Self-Signed SSL Certificate (Optional)
|
||||
|
||||
To run the Flask app with HTTPS, you can create a self-signed SSL certificate:
|
||||
|
||||
```bash
|
||||
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost"
|
||||
```
|
||||
|
||||
Then run the Flask app with SSL context:
|
||||
|
||||
```bash
|
||||
flask run --cert=cert.pem --key=key.pem
|
||||
```
|
||||
|
||||
@@ -7,14 +7,14 @@ def list_records(record_type: str = None):
|
||||
f"https://{MIAB_HOST}/admin/dns/custom",
|
||||
headers={"Authorization": MIAB_AUTH_HEADER}
|
||||
)
|
||||
|
||||
|
||||
if response.status_code == 200:
|
||||
records = response.json()
|
||||
if record_type:
|
||||
jmespath_expr = f"[?rtype=='{record_type.upper()}']"
|
||||
else:
|
||||
jmespath_expr = "[]"
|
||||
|
||||
|
||||
return jmespath.search(jmespath_expr + ".{name: qname, type: rtype, value: value}", records)
|
||||
else:
|
||||
raise Exception(f"Failed to retrieve DNS records: {response.status_code} {response.text}")
|
||||
@@ -45,4 +45,4 @@ def delete_record(name: str, type: str):
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
else:
|
||||
raise Exception(f"Failed to delete DNS record: {response.status_code} {response.text}")
|
||||
raise Exception(f"Failed to delete DNS record: {response.status_code} {response.text}")
|
||||
|
||||
@@ -8,9 +8,9 @@ if __name__ == "__main__":
|
||||
parser.add_argument("name", type=str, help="The name of the DNS record to set")
|
||||
parser.add_argument("value", type=str, help="The value of the DNS record to set")
|
||||
parser.add_argument("--type", type=str, default="A", help="The type of the DNS record (default: A)")
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
miab = miab_dns.MailInABox()
|
||||
response = miab.set_record(name=args.name, value=args.value, type=args.type)
|
||||
if response == "OK":
|
||||
|
||||
Reference in New Issue
Block a user