1 /* Common plugin methods, built around DynDNS standard HTTP API
2 *
3 * Copyright (C) 2003-2004 Narcis Ilisei <inarcis2002@hotpop.com>
4 * Copyright (C) 2006 Steve Horbachuk
5 * Copyright (C) 2010-2021 Joachim Wiberg <troglobit@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, visit the Free Software Foundation
19 * website at http://www.gnu.org/licenses/gpl-2.0.html or write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24 #include "plugin.h"
25
26 /*
27 * dyndns.org specific update address format
28 *
29 * Also applies to other dyndns2 api compatible services, like:
30 * DNS-O-Matic, no-ip, 3322, HE and nsupdate.info.
31 */
32 #define DYNDNS_UPDATE_IP_HTTP_REQUEST \
33 "GET %s?" \
34 "hostname=%s&" \
35 "myip=%s" \
36 "%s " \
37 "HTTP/1.0\r\n" \
38 "Host: %s\r\n" \
39 "Authorization: Basic %s\r\n" \
40 "User-Agent: %s\r\n\r\n"
41
42 /*
43 * DynDNS request composer -- common to many other DDNS providers as well
44 */
common_request(ddns_t * ctx,ddns_info_t * info,ddns_alias_t * alias)45 int common_request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
46 {
47 char wildcard[20] = "";
48
49 if (info->wildcard)
50 strlcpy(wildcard, "&wildcard=ON", sizeof(wildcard));
51
52 return snprintf(ctx->request_buf, ctx->request_buflen,
53 DYNDNS_UPDATE_IP_HTTP_REQUEST,
54 info->server_url,
55 alias->name,
56 alias->address,
57 wildcard,
58 info->server_name.name,
59 info->creds.encoded_password,
60 info->user_agent);
61 }
62
63 /*
64 * DynDNS response validator -- common to many other DDNS providers as well
65 * 'good' or 'nochg' are the good answers,
66 */
common_response(http_trans_t * trans,ddns_info_t * info,ddns_alias_t * alias)67 int common_response(http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias)
68 {
69 char *body = trans->rsp_body;
70
71 (void)info;
72 (void)alias;
73
74 DO(http_status_valid(trans->status));
75
76 if (strstr(body, "good") || strstr(body, "nochg"))
77 return 0;
78
79 if (strstr(body, "dnserr") || strstr(body, "911"))
80 return RC_DDNS_RSP_RETRY_LATER;
81
82 if (strstr(body, "badauth"))
83 return RC_DDNS_RSP_AUTH_FAIL;
84
85 /* Loopia responds "[200 OK] nohost" when no DNS record exists */
86 if (strstr(body, "nohost"))
87 return RC_DDNS_RSP_NOHOST;
88
89 return RC_DDNS_RSP_NOTOK;
90 }
91
92 /**
93 * Local Variables:
94 * indent-tabs-mode: t
95 * c-file-style: "linux"
96 * End:
97 */
98