From f405dca771f7238f55d9122d4e252e1c7906f2f6 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sat, 14 Nov 2020 12:46:19 +0100 Subject: [PATCH] bundles/pppd: add dyndns capability --- bundles/pppd/files/dyndns | 24 ++++++++++++++++++++++++ bundles/pppd/items.py | 7 +++++++ bundles/pppd/metadata.py | 1 + nodes/home/router.py | 5 +++++ 4 files changed, 37 insertions(+) create mode 100644 bundles/pppd/files/dyndns diff --git a/bundles/pppd/files/dyndns b/bundles/pppd/files/dyndns new file mode 100644 index 0000000..543b848 --- /dev/null +++ b/bundles/pppd/files/dyndns @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import requests +from sys import argv + +INTERFACE = argv[1] +LOCAL_IP = argv[4] + +UPDATE_URL = '${url}' +USERNAME = '${username}' +PASSWORD = '${password}' + +r = requests.get( + UPDATE_URL.format( + ip=LOCAL_IP, + ), + auth=( + USERNAME, + PASSWORD, + ) +) + +with open('/var/tmp/dyndns.monitoring', 'w') as s: + s.write(str(r.status_code)) diff --git a/bundles/pppd/items.py b/bundles/pppd/items.py index 03b79e6..987d692 100644 --- a/bundles/pppd/items.py +++ b/bundles/pppd/items.py @@ -76,6 +76,13 @@ files = { }, } +if 'dyndns' in node.metadata['pppd']: + files['/etc/ppp/ip-up.d/dyndns'] = { + 'content_type': 'mako', + 'context': node.metadata['pppd']['dyndns'], + 'mode': '0755', + } + svc_systemd = { 'pppoe': { 'needs': { diff --git a/bundles/pppd/metadata.py b/bundles/pppd/metadata.py index 9213ab4..909dfe3 100644 --- a/bundles/pppd/metadata.py +++ b/bundles/pppd/metadata.py @@ -3,6 +3,7 @@ defaults = { 'packages': { 'ppp': {}, 'pppoe': {}, + 'python3-requests': {}, 'ndisc6': {}, }, }, diff --git a/nodes/home/router.py b/nodes/home/router.py index ba9bd6c..0b4eaed 100644 --- a/nodes/home/router.py +++ b/nodes/home/router.py @@ -67,6 +67,11 @@ nodes['home.router'] = { 'username': vault.decrypt('encrypt$gAAAAABfruZ5AZbgJ3mfMLWqIMx8o4bBRMJsDPD1jElh-vWN_gnhiuZVjrQ1-7Y6zDXNkxXiyhx8rxc2enmvo26axd7EBI8FqknCptXAPruVtDZrBCis4TE='), 'password': vault.decrypt('encrypt$gAAAAABfruaXEDkaFksFMU8g97ydWyJF8p2KcSDJJBlzaOLDsLL6oCDYjG1kMPVESOzqjn8ThtSht1uZDuMCstA-sATmLS-EWQ=='), 'interface': 'enp1s0.100', + 'dyndns': { + 'url': 'https://ns-1.kunbox.net/nic/update?hostname=franzi-home.kunbox.net&myip={ip}', + 'username': vault.decrypt('encrypt$gAAAAABfr8DLAJhmUIhdxLq83I8MnRRvkRgDZcO8Brvw1KpvplC3K8ZGj0jIIWD3Us33vIP6t0ybd_mgD8slpRUk78Kqd3BMoQ=='), + 'password': vault.decrypt('encrypt$gAAAAABfr8Cq5M1hweeJTQAl0dLhFntdlw-QnkIYUQpY-_ycODVWOpyeAwjwOgWLSdsdXIUvqcoiXPZPV-BE12p5C42NGnj9r7sKYpoGz8xfuGIk6haMa2g='), + }, }, 'dhcpd': { 'subnets': {