Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions dns/ddclient/src/opnsense/scripts/ddclient/lib/account/hetzner.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,34 +144,26 @@ def _get_record(self, headers, zone_id, record_name, record_type):
return None

def _update_record(self, headers, zone_id, record_name, record_type, address):
"""Update existing record with new address"""
url = f"{self._api_base}/zones/{zone_id}/rrsets/{record_name}/{record_type}"

data = {
'records': [{'value': str(address)}],
'ttl': int(self.settings.get('ttl', 300))
}
"""Update existing record with new address

response = requests.put(url, headers=headers, json=data)
NOTE: Hetzner Cloud API has a bug where PUT returns 200 but doesn't update.
Workaround: DELETE old record, then POST new record.
"""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating records cannot be done with PUT /.../rrsets/..., you must use one of the following endpoint:

Also note, that those endpoint return "Actions", which describe async tasks that should be waited upon.

# DELETE old record first
delete_url = f"{self._api_base}/zones/{zone_id}/rrsets/{record_name}/{record_type}"
delete_response = requests.delete(delete_url, headers=headers)

if response.status_code != 200:
if delete_response.status_code not in [200, 201, 204]:
syslog.syslog(
syslog.LOG_ERR,
"Account %s error updating record: HTTP %d - %s" % (
self.description, response.status_code, response.text
"Account %s error deleting record for update: HTTP %d - %s" % (
self.description, delete_response.status_code, delete_response.text
)
)
return False

if self.is_verbose:
syslog.syslog(
syslog.LOG_NOTICE,
"Account %s updated %s %s to %s" % (
self.description, record_name, record_type, address
)
)

return True
# CREATE new record
return self._create_record(headers, zone_id, record_name, record_type, address)

def _create_record(self, headers, zone_id, record_name, record_type, address):
"""Create new record"""
Expand Down
8 changes: 8 additions & 0 deletions net/hclouddns/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PLUGIN_NAME= hclouddns
PLUGIN_VERSION= 2.0.0
PLUGIN_COMMENT= Hetzner Cloud DNS Management with Multi-Zone and Failover
PLUGIN_MAINTAINER= info@arcan-it.de
PLUGIN_WWW= https://github.com/ArcanConsulting/os-hclouddns
PLUGIN_DEPENDS= python311

.include "../../Mk/plugins.mk"
16 changes: 16 additions & 0 deletions net/hclouddns/pkg-descr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Hetzner Cloud DNS Management Plugin for OPNsense

Features:
- Multi-account support (multiple Hetzner API tokens)
- Multi-zone DNS management
- Dynamic DNS with automatic failover between WAN interfaces
- IPv4 and IPv6 (Dual-Stack) support
- DNS record templates for quick setup
- Direct DNS management (view/edit/delete records)
- Change history with undo functionality
- Notifications (Email, Webhook, Ntfy)
- Configuration backup/restore

Supports both Hetzner Cloud API and legacy DNS Console API.

WWW: https://github.com/ArcanConsulting/os-hclouddns
51 changes: 51 additions & 0 deletions net/hclouddns/pkg-plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
etc/inc/plugins.inc.d/hclouddns.inc
etc/rc.syshook.d/monitor/50-hclouddns
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/Api/AccountsController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/Api/EntriesController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/Api/GatewaysController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/Api/HetznerController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/Api/HistoryController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/Api/ServiceController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/Api/SettingsController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/DnsController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/forms/dialogAccount.xml
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/forms/dialogEntry.xml
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/forms/dialogGateway.xml
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/forms/dialogScheduled.xml
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/forms/failover.xml
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/forms/general.xml
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/IndexController.php
opnsense/mvc/app/controllers/OPNsense/HCloudDNS/SettingsController.php
opnsense/mvc/app/models/OPNsense/HCloudDNS/ACL/ACL.xml
opnsense/mvc/app/models/OPNsense/HCloudDNS/HCloudDNS.php
opnsense/mvc/app/models/OPNsense/HCloudDNS/HCloudDNS.xml
opnsense/mvc/app/models/OPNsense/HCloudDNS/Menu/Menu.xml
opnsense/mvc/app/views/OPNsense/HCloudDNS/accounts.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/dns.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/entries.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/gateways.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/general.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/index.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/settings.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/status.volt
opnsense/mvc/app/views/OPNsense/HCloudDNS/zones.volt
opnsense/scripts/ddclient/lib/account/hetzner_cloud.py
opnsense/scripts/ddclient/lib/account/hetzner_legacy.py
opnsense/scripts/HCloudDNS/create_record.py
opnsense/scripts/HCloudDNS/delete_record.py
opnsense/scripts/HCloudDNS/gateway_health.py
opnsense/scripts/HCloudDNS/get_hetzner_ip.py
opnsense/scripts/HCloudDNS/hcloud_api.py
opnsense/scripts/HCloudDNS/lib/__init__.py
opnsense/scripts/HCloudDNS/lib/hetzner_api.py
opnsense/scripts/HCloudDNS/list_records.py
opnsense/scripts/HCloudDNS/list_zones.py
opnsense/scripts/HCloudDNS/refresh_status.py
opnsense/scripts/HCloudDNS/simulate_failover.py
opnsense/scripts/HCloudDNS/status.py
opnsense/scripts/HCloudDNS/test_notify.py
opnsense/scripts/HCloudDNS/update_record.py
opnsense/scripts/HCloudDNS/update_records.py
opnsense/scripts/HCloudDNS/update_records_v2.py
opnsense/scripts/HCloudDNS/validate_token.py
opnsense/service/conf/actions.d/actions_hclouddns.conf
135 changes: 135 additions & 0 deletions net/hclouddns/src/etc/inc/plugins.inc.d/hclouddns.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

/**
* Copyright (c) 2025 Arcan Consulting (www.arcan-it.de)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* Register HCloudDNS services
* @return array
*/
function hclouddns_services()
{
$services = array();

$mdl = new \OPNsense\HCloudDNS\HCloudDNS();
if ((string)$mdl->general->enabled == '1') {
$services[] = array(
'description' => gettext('Hetzner Cloud Dynamic DNS'),
'configd' => array(
'restart' => array('hclouddns update'),
),
'name' => 'hclouddns',
);
}

return $services;
}

/**
* Register cron jobs for HCloudDNS
* Only active when explicitly enabled - automatic triggers (gateway syshook, newwanip)
* handle most use cases without needing scheduled updates.
* @return array
*/
function hclouddns_cron()
{
$jobs = [];

$mdl = new \OPNsense\HCloudDNS\HCloudDNS();
// Cron is only registered when both service AND cron are enabled
if ((string)$mdl->general->enabled == '1' && (string)$mdl->general->cronEnabled == '1') {
// Use cronInterval setting (in minutes) - cast to string first as model fields are objects
$minutes = intval((string)$mdl->general->cronInterval);
if (empty($minutes) || $minutes < 1) {
$minutes = 5; // Default 5 minutes
}
if ($minutes > 60) {
$minutes = 60;
}

// autocron format: [command, minute, hour, monthday, month, weekday]
$jobs[]['autocron'] = [
'/usr/local/sbin/configctl hclouddns update',
"*/{$minutes}"
];
}

return $jobs;
}

/**
* Register plugin hooks - triggers on interface IP changes
* @return array
*/
function hclouddns_configure()
{
return [
'newwanip' => ['hclouddns_configure_do:2'],
];
}

/**
* Called when WAN IP changes - trigger DNS update
* @param bool $verbose
*/
function hclouddns_configure_do($verbose = false)
{
$mdl = new \OPNsense\HCloudDNS\HCloudDNS();
if ((string)$mdl->general->enabled != '1') {
return;
}

service_log('Hetzner Cloud DDNS: Interface IP changed, updating DNS...', $verbose);

// Trigger update via configd
configd_run('hclouddns update');

service_log("done.\n", $verbose);
}

/**
* Register syslog facility
* @return array
*/
function hclouddns_syslog()
{
$logfacilities = [];
$logfacilities['hclouddns'] = ['facility' => ['hclouddns']];
return $logfacilities;
}

/**
* XML-RPC sync handler
* @return array
*/
function hclouddns_xmlrpc_sync()
{
$result = array();
$result['id'] = 'hclouddns';
$result['section'] = 'OPNsense.HCloudDNS';
$result['description'] = gettext('Hetzner Cloud Dynamic DNS');
return array($result);
}
42 changes: 42 additions & 0 deletions net/hclouddns/src/etc/rc.syshook.d/monitor/50-hclouddns
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

#
# Copyright (c) 2025 Arcan Consulting (www.arcan-it.de)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

# HCloudDNS Gateway Monitor Syshook
# Called by rc.routing_configure when gateway status changes
# Arguments: $1 = comma-separated list of gateway names that triggered the alarm

GATEWAYS="${1}"

# Log the gateway alarm
logger -t hclouddns "Gateway alarm triggered for: ${GATEWAYS}"

# Trigger async DNS update via configd (non-blocking)
# The -d flag runs the command detached so we don't block the routing reconfigure
/usr/local/sbin/configctl -d hclouddns update

exit 0
Loading