From 2b261313ed79bb49f0074e8ea8c78b53254bf756 Mon Sep 17 00:00:00 2001 From: Kenan Amundsen Elkoca Date: Sat, 24 Aug 2024 17:10:48 +0200 Subject: [PATCH 1/4] Added domeneshop support --- examples/domeneshop.conf | 10 ++++ plugins/Makefile.am | 2 +- plugins/domeneshop.c | 114 +++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 3 +- 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 examples/domeneshop.conf create mode 100644 plugins/domeneshop.c diff --git a/examples/domeneshop.conf b/examples/domeneshop.conf new file mode 100644 index 00000000..dc5addb5 --- /dev/null +++ b/examples/domeneshop.conf @@ -0,0 +1,10 @@ +# Inadyn v2.0 configuration file format +period = 300 +allow-ipv6 = true +#verify-address = false + +provider default@domene.shop { + username = user + password = secret + hostname = example.domene.shop +} diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 0a6e0d51..406faa38 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -10,4 +10,4 @@ inadyn_SOURCES += common.c changeip.c cloudflare.c porkbun.c \ core-networks.c dnsever.c dnshome.c \ dnsmadeeasy.c dnsmax.c mydns.c \ myonlineportal.c namecheap.c regfish.c \ - twodns.c ipv64.c + twodns.c ipv64.c domeneshop.c diff --git a/plugins/domeneshop.c b/plugins/domeneshop.c new file mode 100644 index 00000000..8882ab4a --- /dev/null +++ b/plugins/domeneshop.c @@ -0,0 +1,114 @@ +/* Plugin for domene.shop +* + * Copyright (C) 2024 Kenan Amundsen Elkoca + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, visit the Free Software Foundation + * website at http://www.gnu.org/licenses/gpl-2.0.html or write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "plugin.h" + +/* + * https://api.domeneshop.no/docs/#tag/ddns/paths/~1dyndns~1update/get + */ +#define API_HOST "api.domeneshop.no" +#define API_URL "/v0/dyndns/update" + +// TODO Check this +#define DOMENESHOP_UPDATE_IP_REQUEST \ + "GET %s?" \ + "hostname=%s&" \ + "myip=%s " \ + "HTTP/1.1\r\n" \ + "Host: %s\r\n" \ + "Authorization: Basic %s\r\n" \ + "User-Agent: %s\r\n\r\n" + +static int request (ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias); +static int response (http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias); + +static ddns_system_t domeneshop = { + .name = "default@domene.shop", + + .request = (req_fn_t)request, + .response = (rsp_fn_t)response, + + .checkip_name = DYNDNS_MY_IP_SERVER, + .checkip_url = DYNDNS_MY_CHECKIP_URL, + .checkip_ssl = DYNDNS_MY_IP_SSL, + + .server_name = API_HOST, + .server_url = API_URL +}; + +// TODO See if this works +static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) +{ + return common_request(ctx, info, alias); +} + +// static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) +// { +// return snprintf(ctx->request_buf, ctx->request_buflen, +// info->system->server_req, +// info->server_url, +// alias->name, +// alias->address, +// wildcard, +// info->server_name.name, +// info->creds.encoded_password, +// info->user_agent); +// } + +static int response(http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias) +{ + char *body = trans->rsp_body; + + (void)info; + (void)alias; + + DO(check_response_code(trans->status)); + + if (strstr(body, "")) + return 0; + + return RC_DDNS_RSP_NOTOK; +} + +static int check_response_code(int status){ + if (status == 204){ + return RC_OK; + + DO(http_status_valid(trans->status)); +} + +PLUGIN_INIT(plugin_init) +{ + plugin_register(&plugin, DHIS_UPDATE_IP_REQUEST); + plugin_register(&plugin_ipv6, DHIS_UPDATE_IP_REQUEST); +} + +PLUGIN_EXIT(plugin_exit) +{ + plugin_unregister(&plugin); +} + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ diff --git a/src/Makefile.am b/src/Makefile.am index dbea64f9..0ab76134 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,4 +49,5 @@ inadyn_SOURCES += ../plugins/common.c ../plugins/changeip.c \ ../plugins/dnsmax.c ../plugins/mydns.c \ ../plugins/myonlineportal.c ../plugins/namecheap.c \ ../plugins/regfish.c ../plugins/twodns.c \ - ../plugins/ipv64.c ../plugins/porkbun.c + ../plugins/ipv64.c ../plugins/porkbun.c \ + ../plugins/domeneshop.c From 55cbdae711602ef72024141266b2bb0616c2a712 Mon Sep 17 00:00:00 2001 From: Kenan Amundsen Elkoca Date: Sat, 24 Aug 2024 19:16:00 +0200 Subject: [PATCH 2/4] Fixed domeneshop plugin --- examples/domeneshop.conf | 6 ++--- plugins/domeneshop.c | 58 +++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/examples/domeneshop.conf b/examples/domeneshop.conf index dc5addb5..75018668 100644 --- a/examples/domeneshop.conf +++ b/examples/domeneshop.conf @@ -3,8 +3,8 @@ period = 300 allow-ipv6 = true #verify-address = false -provider default@domene.shop { - username = user +provider domene.shop { + username = token password = secret - hostname = example.domene.shop + hostname = { "subdomain.domene.shop", "*.domene.shop" } } diff --git a/plugins/domeneshop.c b/plugins/domeneshop.c index 8882ab4a..71f5147e 100644 --- a/plugins/domeneshop.c +++ b/plugins/domeneshop.c @@ -24,10 +24,7 @@ /* * https://api.domeneshop.no/docs/#tag/ddns/paths/~1dyndns~1update/get */ -#define API_HOST "api.domeneshop.no" -#define API_URL "/v0/dyndns/update" -// TODO Check this #define DOMENESHOP_UPDATE_IP_REQUEST \ "GET %s?" \ "hostname=%s&" \ @@ -39,6 +36,7 @@ static int request (ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias); static int response (http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias); +static int check_response_code (int status); static ddns_system_t domeneshop = { .name = "default@domene.shop", @@ -50,60 +48,54 @@ static ddns_system_t domeneshop = { .checkip_url = DYNDNS_MY_CHECKIP_URL, .checkip_ssl = DYNDNS_MY_IP_SSL, - .server_name = API_HOST, - .server_url = API_URL + .server_name = "api.domeneshop.no", + .server_url = "/v0/dyndns/update" }; -// TODO See if this works static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) { - return common_request(ctx, info, alias); + return snprintf(ctx->request_buf, ctx->request_buflen, + info->system->server_req, + info->server_url, + alias->name, + alias->address, + info->server_name.name, + info->creds.encoded_password, + info->user_agent); } -// static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) -// { -// return snprintf(ctx->request_buf, ctx->request_buflen, -// info->system->server_req, -// info->server_url, -// alias->name, -// alias->address, -// wildcard, -// info->server_name.name, -// info->creds.encoded_password, -// info->user_agent); -// } +static int check_response_code(int status) +{ + if (status == 204) + return RC_OK; + + return http_status_valid(status); +} static int response(http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias) { + int rc; char *body = trans->rsp_body; (void)info; (void)alias; - DO(check_response_code(trans->status)); + rc = check_response_code(trans->status); - if (strstr(body, "")) - return 0; + if (rc == RC_OK && !strstr(body, "")) + rc = RC_DDNS_RSP_NOTOK; - return RC_DDNS_RSP_NOTOK; -} - -static int check_response_code(int status){ - if (status == 204){ - return RC_OK; - - DO(http_status_valid(trans->status)); + return rc; } PLUGIN_INIT(plugin_init) { - plugin_register(&plugin, DHIS_UPDATE_IP_REQUEST); - plugin_register(&plugin_ipv6, DHIS_UPDATE_IP_REQUEST); + plugin_register(&domeneshop, DOMENESHOP_UPDATE_IP_REQUEST); } PLUGIN_EXIT(plugin_exit) { - plugin_unregister(&plugin); + plugin_unregister(&domeneshop); } /** From 358a6a91ce929e9eeb4c1e8178f72d2b64d0515d Mon Sep 17 00:00:00 2001 From: Kenan Amundsen Elkoca Date: Sat, 24 Aug 2024 20:44:44 +0200 Subject: [PATCH 3/4] Added domeneshop references --- README.md | 1 + examples/domeneshop.conf | 2 ++ plugins/domeneshop.c | 5 +---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5116a0bb..6b76e7ad 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ providers, ordered by the plugin that support them: * * * + * For the complete list, see `inadyn -L`, for machine friendly JSON output, use `inadyn -L -j`. diff --git a/examples/domeneshop.conf b/examples/domeneshop.conf index 75018668..b58e9ea0 100644 --- a/examples/domeneshop.conf +++ b/examples/domeneshop.conf @@ -3,6 +3,8 @@ period = 300 allow-ipv6 = true #verify-address = false +# To generate credentials, visit this page: +# https://domene.shop/admin?view=api provider domene.shop { username = token password = secret diff --git a/plugins/domeneshop.c b/plugins/domeneshop.c index 71f5147e..29b3a47b 100644 --- a/plugins/domeneshop.c +++ b/plugins/domeneshop.c @@ -21,10 +21,7 @@ #include "plugin.h" -/* - * https://api.domeneshop.no/docs/#tag/ddns/paths/~1dyndns~1update/get - */ - +/* https://api.domeneshop.no/docs/#tag/ddns/paths/~1dyndns~1update/get */ #define DOMENESHOP_UPDATE_IP_REQUEST \ "GET %s?" \ "hostname=%s&" \ From db1cd99c5f89bd3c56c1f353760aaaf8c977eeb9 Mon Sep 17 00:00:00 2001 From: Kenan Amundsen Elkoca Date: Sat, 24 Aug 2024 20:58:49 +0200 Subject: [PATCH 4/4] Fixed some spacing --- plugins/Makefile.am | 26 +++++++++++++------------- plugins/domeneshop.c | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 406faa38..e671c4a5 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,13 +1,13 @@ -inadyn_SOURCES += common.c changeip.c cloudflare.c porkbun.c \ - cloudxns.c ddnss.c dhis.c \ - dnsexit.c dnspod.c duckdns.c \ - duiadns.c dyndns.c dynv6.c \ - easydns.c freedns.c freemyip.c \ - generic.c giradns.c \ - sitelutions.c tunnelbroker.c \ - yandex.c zoneedit.c goip.c \ - desec.c domaindiscount24.c all-inkl.c \ - core-networks.c dnsever.c dnshome.c \ - dnsmadeeasy.c dnsmax.c mydns.c \ - myonlineportal.c namecheap.c regfish.c \ - twodns.c ipv64.c domeneshop.c +inadyn_SOURCES += common.c changeip.c cloudflare.c porkbun.c \ + cloudxns.c ddnss.c dhis.c \ + dnsexit.c dnspod.c duckdns.c \ + duiadns.c dyndns.c dynv6.c \ + easydns.c freedns.c freemyip.c \ + generic.c giradns.c \ + sitelutions.c tunnelbroker.c \ + yandex.c zoneedit.c goip.c \ + desec.c domaindiscount24.c all-inkl.c \ + core-networks.c dnsever.c dnshome.c \ + dnsmadeeasy.c dnsmax.c mydns.c \ + myonlineportal.c namecheap.c regfish.c \ + twodns.c ipv64.c domeneshop.c diff --git a/plugins/domeneshop.c b/plugins/domeneshop.c index 29b3a47b..4251e96f 100644 --- a/plugins/domeneshop.c +++ b/plugins/domeneshop.c @@ -1,5 +1,5 @@ /* Plugin for domene.shop -* + * * Copyright (C) 2024 Kenan Amundsen Elkoca * * This program is free software; you can redistribute it and/or