diff --git a/composer.json b/composer.json index daec86e71a3c565f18c1c5d9620a1a5bca5b623c..ed103c4c3630cb4532b4e55cf2eb70aacd9633cf 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "leafs/leaf": "^2.4", "ramsey/uuid": "^4.1", "abhilashpujari/php-restservice": "dev-master", - "guzzlehttp/guzzle": "^7.0" + "guzzlehttp/guzzle": "^7.0", + "pear/net_dns2": "^1.5" } } diff --git a/composer.lock b/composer.lock index 50d75767fc2c9b2146b66e8e44ea76cc8d20efae..14e9633a5f49d526ad32ad86919114c982f7a9a8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7a250215a88065189d17512fceab45dd", + "content-hash": "dc9ea773c012d95dc4d3a74b07416eee", "packages": [ { "name": "abhilashpujari/php-restservice", @@ -1124,6 +1124,53 @@ ], "time": "2021-01-26T20:46:41+00:00" }, + { + "name": "pear/net_dns2", + "version": "v1.5.2", + "source": { + "type": "git", + "url": "https://github.com/mikepultz/netdns2.git", + "reference": "d5dbae0b0c0567923d25b3ae5e2bf1e9cbcedf76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mikepultz/netdns2/zipball/d5dbae0b0c0567923d25b3ae5e2bf1e9cbcedf76", + "reference": "d5dbae0b0c0567923d25b3ae5e2bf1e9cbcedf76", + "shasum": "" + }, + "require": { + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "^9" + }, + "type": "library", + "autoload": { + "psr-0": { + "Net_DNS2": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Mike Pultz", + "email": "mike@mikepultz.com", + "homepage": "https://mikepultz.com/", + "role": "lead" + } + ], + "description": "Native PHP DNS Resolver and Updater Library", + "homepage": "https://netdns2.com/", + "keywords": [ + "PEAR", + "dns", + "network" + ], + "time": "2020-10-11T17:33:54+00:00" + }, { "name": "phpmailer/phpmailer", "version": "v6.2.0", diff --git a/quovadis/config_sample.php b/quovadis/config_sample.php index 3542d789ba3dda033b5463727c05d68e5494ab7f..de605c96a57eb060414b848108660b6b590cea40 100644 --- a/quovadis/config_sample.php +++ b/quovadis/config_sample.php @@ -9,6 +9,13 @@ function get_config() { # API key for dynu.com 'QV_DYNU_API' => "ABCD1234", + # RFC2136 host + 'QV_RFC2136_HOST' => "1.2.3.4", + + # RFC2136 key + 'QV_RFC2136_KEYNAME' => "mykey", + 'QV_RFC2136_KEY' => "secret", + # Domain at desec.io 'QV_DOMAIN' => "quovadis-challenges.ucc.asn.au", diff --git a/quovadis/quovadis.php b/quovadis/quovadis.php index da9e454abb79abc9b82226b0cfba0a1510097f48..b92edfe3d29b4399a40ca170c1a25e83cc3f1176 100644 --- a/quovadis/quovadis.php +++ b/quovadis/quovadis.php @@ -35,7 +35,39 @@ function stripQuotes($text) { } function get_txt($config, $name) { - return get_desec_txt($config, $name); + return get_rfc2136_txt($config, $name); +} + +function get_rfc2136_txt($config, $name) { + + // + // create new resolver object, passing in an array of name + // servers to use for lookups + // + $r = new Net_DNS2_Resolver(array('nameservers' => array($config['QV_RFC2136_HOST']))); + + // + // execute the query request for the name TXT + // + try { + $result = $r->query($name . "." . $config['QV_DOMAIN'], 'TXT'); + + } catch(Net_DNS2_Exception $e) { + + echo "::query() failed: ", $e->getMessage(), "\n"; + return ""; + } + + // + // loop through the answer, printing out the TXT results returned. + // + foreach($result->answer as $txtrr) + { + return $txtrr; + } + // + + return ""; } function get_dynu_domainid($config, $name) { @@ -176,7 +208,72 @@ function check_challenge($challenge) { // function update_txt($config, $name, $txt) { - return update_desec_txt($config, $name, $txt); + return update_rfc2136_txt($config, $name, $txt); +} + +function delete_rfc2136_txt($config, $name) { + // create a new Updater object + // + $u = new Net_DNS2_Updater($config['QV_DOMAIN'], array('nameservers' => array($config['QV_RFC2136_HOST']))); + + try { + $u->deleteAny($name . "." . $config['QV_DOMAIN'], 'TXT'); + + // add a TSIG to authenticate the request + // + $u->signTSIG($config['QV_RFC2136_KEYNAME'], $config['QV_RFC2136_KEY']); + + // + // execute the request + // + $u->update(); + + return "$name deleted"; + + } catch(Net_DNS2_Exception $e) { + + echo "::update() for deleteAny failed: ", $e->getMessage(), "\n"; + } + + return ""; +} + +function update_rfc2136_txt($config, $name, $txt) { + + delete_rfc2136_txt($config, $name); + + // create a new Updater object + // + $u = new Net_DNS2_Updater($config['QV_DOMAIN'], array('nameservers' => array($config['QV_RFC2136_HOST']))); + + try { + // + // create a new MX RR object to add to the example.com zone + // + $txtrr = Net_DNS2_RR::fromString($name . "." . $config['QV_DOMAIN'] . ' TXT "'. $txt . '"'); + + // + // add the record + // + $u->add($txtrr); + + // add a TSIG to authenticate the request + // + $u->signTSIG($config['QV_RFC2136_KEYNAME'], $config['QV_RFC2136_KEY']); + + // + // execute the request + // + $u->update(); + + return $txt; + + } catch(Net_DNS2_Exception $e) { + + echo "::update() failed: ", $e->getMessage(), "\n"; + } + + return ""; } function update_dynu_txt($config, $name, $txt) {