Revert gpsd to 2.19 (#756)
[openwrt/svn-archive/archive.git] / net / updatedd / patches / 100-zoneedit-support.patch
1 ---
2 src/plugins/Makefile.in | 3
3 src/plugins/zoneedit.c | 280 ++++++++++++++++++++++++++++++++++++++++++++++++
4 src/plugins/zoneedit.h | 82 ++++++++++++++
5 3 files changed, 364 insertions(+), 1 deletion(-)
6
7 Index: updatedd-2.5/src/plugins/zoneedit.c
8 ===================================================================
9 --- /dev/null
10 +++ updatedd-2.5/src/plugins/zoneedit.c
11 @@ -0,0 +1,280 @@
12 +/* -- updatedd: zoneedit.c --
13 + *
14 + * Copyright (C) 2002, 2003, 2004, 2005 Philipp Benner
15 + *
16 + * This file is part of UpdateDD - http://updatedd.philipp-benner.de.
17 + *
18 + * UpdateDD is free software; you can redistribute it and/or modify
19 + * it under the terms of the GNU General Public License as published by
20 + * the Free Software Foundation; either version 2 of the License, or
21 + * any later version.
22 + *
23 + * UpdateDD is distributed in the hope that it will be useful,
24 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 + * GNU General Public License for more details.
27 + *
28 + * You should have received a copy of the GNU General Public License
29 + * along with UpdateDD; if not, write to the Free Software
30 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 + */
32 +
33 +#include <config.h>
34 +#include <stdio.h>
35 +#include <stdlib.h>
36 +#include <string.h>
37 +#include <stdarg.h>
38 +#include <ctype.h>
39 +#include <unistd.h>
40 +#include <getopt.h>
41 +
42 +#include <base64encode.h>
43 +#include <get_connection.h>
44 +#include <unistd.h>
45 +#include <libexception_handle.h>
46 +#include <ret_codes.h>
47 +#include <version.h>
48 +
49 +#include "zoneedit.h"
50 +
51 +static void
52 +print_usage(char *pname, FILE *fp)
53 +{
54 + (void)fprintf(fp,
55 + "\nUsage: %s [...] %s -- [OPTION]... [USERNAME:PASSWORD] HOSTNAME\n\n",
56 + pname, COLORED("zoneedit"));
57 + (void)fprintf(fp,
58 + "For security reasons use the environment variable LOGIN instead of\n"
59 + "passing the login information directly.\n\n"
60 + "Options:\n"
61 + " -4 --ipv4 <address> ip address version 4\n"
62 + " -o --offline host is currently offline\n"
63 + " --help print help and exit\n"
64 + " --version display version information and exit\n\n"
65 +
66 + "Report bugs to <"EMAIL">.\n\n");
67 +
68 + return;
69 +}
70 +
71 +static void
72 +print_version(FILE *fp)
73 +{
74 +
75 + (void)fprintf(fp,
76 + "\n" PNAME " plugin for zoneedit.com version " VERSION ",\n"
77 + "Copyright (C) 2005 Philipp Benner.\n"
78 + HOMEPAGE "\n\n"
79 +
80 + "This is free software, and you are welcome to redistribute it\n"
81 + "under certain conditions; see the source for copying conditions.\n"
82 + "There is NO warranty; not even for MERCHANTABILITY or FITNESS\n"
83 + "FOR A PARTICULAR PURPOSE.\n\n");
84 +
85 + return;
86 +
87 +}
88 +
89 +static void
90 +ret_msg(int mode, const char *fmt, ...)
91 +{
92 +
93 + va_list az;
94 +
95 + va_start(az, fmt);
96 + (void)vs_warn(ret_msg_buf, BUFSIZE, mode, fmt, az);
97 + va_end(az);
98 +
99 + return;
100 +
101 +}
102 +
103 +int
104 +dyndns(int argc, char *argv[])
105 +{
106 +
107 + struct arguments args;
108 + int s, ret;
109 + const char *ptr;
110 +
111 + (void)memset(&args, 0, sizeof(struct arguments));
112 +
113 + if(get_flags(&args, argc, argv) != RET_OK) {
114 + return RET_WRONG_USAGE;
115 + }
116 +
117 + s = get_connection(DYNDNSHOST, PORT, &ptr);
118 + if(s == -1) {
119 + ret_msg(HERR, "%s: %s", ptr, DYNDNSHOST);
120 + ret = RET_WARNING;
121 + } else {
122 + ret = update_dyndns(s, &args);
123 + if(ret == RET_OK) {
124 + ret = check_server_msg(s, args.hostname);
125 + }
126 + (void)close(s);
127 + }
128 +
129 + return ret;
130 +
131 +}
132 +
133 +static int
134 +get_flags(struct arguments *args, int argc, char *argv[])
135 +{
136 +
137 + int c;
138 +
139 + for(;;) {
140 +
141 + int option_index = 0;
142 + static struct option long_options[] = {
143 + { "ipv4", 1, 0, '4' },
144 + { "help", 0, 0, 'h' },
145 + { "offline", 0, 0, 'o' },
146 + { "version", 0, 0, 'v' },
147 + { NULL, 0, 0, 0 }
148 + };
149 +
150 + c = getopt_long(argc, argv, "4:o",
151 + long_options, &option_index);
152 +
153 + if(c == -1) break;
154 +
155 + switch(c) {
156 + case '4':
157 + args->ipv4 = optarg;
158 + break;
159 + case 'o':
160 + args->offline = 1;
161 + break;
162 + case 'h':
163 + print_usage(argv[ARGV_PNAME], stdout);
164 + exit(EXIT_SUCCESS);
165 + case 'v':
166 + print_version(stdout);
167 + exit(EXIT_SUCCESS);
168 + }
169 + }
170 +
171 + switch(argc-optind) {
172 + default:
173 + ret_msg(NONE, "wrong usage");
174 + return RET_WRONG_USAGE;
175 +
176 + case 2:
177 + args->login = getenv("LOGIN");
178 + if(args->login == NULL) {
179 + ret_msg(NONE,
180 + "environment variable LOGIN is empty");
181 + return RET_WRONG_USAGE;
182 + }
183 + break;
184 + case 3:
185 + args->login = argv[ARGV_LOGIN];
186 + }
187 + args->hostname = argv[ARGV_HOSTNAME];
188 +
189 + return RET_OK;
190 +
191 +}
192 +
193 +#define BUFLEN 4096
194 +#define BUFFREE(name) BUFLEN - strlen(name)
195 +
196 +static int
197 +update_dyndns(const int s, struct arguments *args)
198 +{
199 +
200 + char *b64user;
201 + char message[BUFLEN];
202 +
203 + if(strlen(args->login) > 128) {
204 + ret_msg(NONE, "username is too long");
205 + return RET_ERROR;
206 + }
207 + b64user = (char *)malloc((2 * strlen(args->login) + 1));
208 + if(b64user == NULL) {
209 + ret_msg(PERR, "malloc() failed");
210 + return RET_WARNING;
211 + }
212 + (void)memset(b64user, 0, 2 * strlen(args->login) + 1);
213 +
214 + base64encode(args->login, b64user);
215 + (void)snprintf(message, BUFLEN,
216 + "GET https://%s/auth/dynamic.html?host=%s",
217 + DYNDNSHOST, args->hostname);
218 +
219 + if(args->offline) {
220 + (void)strncat(message, "&dnsto=0.0.0.0", BUFFREE(message));
221 + }
222 + else if(args->ipv4) {
223 + (void)strncat(message, "&dnsto=", BUFFREE(message));
224 + (void)strncat(message, args->ipv4, BUFFREE(message));
225 + }
226 +
227 + {
228 + char buffer[1024];
229 +
230 + (void)snprintf(buffer, 1024,
231 + " HTTP/1.1\r\n"
232 + "Host: %s\r\n"
233 + "Authorization: Basic %s\r\n"
234 + "User-Agent: %s %s - %s\r\n"
235 + "Connection: close\r\n"
236 + "Pragma: no-cache\r\n\r\n",
237 + DYNDNSHOST, b64user, PNAME, VERSION, HOMEPAGE);
238 + (void)strncat(message, buffer, BUFLEN - 1 - strlen(message));
239 + }
240 + print_debug("\n\nMessage:"
241 + "\n--------------------------------------\n"
242 + "%s--------------------------------------\n\n",
243 + message);
244 +
245 + if(write(s, message, strlen(message)) == -1) {
246 + ret_msg(PERR, "write() failed");
247 + return RET_WARNING;
248 + }
249 +
250 + free(b64user);
251 + return RET_OK;
252 +
253 +}
254 +
255 +static int
256 +check_server_msg(int s, const char *hostname)
257 +{
258 +
259 + char server_msg[BUFSIZE];
260 +
261 + /* get server_msg */
262 + (void)memset(server_msg, 0, sizeof(server_msg));
263 + if(read(s, server_msg, sizeof(server_msg) - 1) < 0) {
264 + ret_msg(PERR, "read() failed");
265 + return RET_WARNING;
266 + }
267 +
268 + print_debug("\n\nServer message:"
269 + "\n--------------------------------------\n"
270 + "%s--------------------------------------\n\n",
271 + server_msg);
272 +
273 + if(strstr(server_msg, "HTTP/1.1 200 OK") ||
274 + strstr(server_msg, "HTTP/1.0 200 OK")) {
275 + if(strstr(server_msg, "SUCCESS CODE=")) {
276 + ret_msg(NONE, "%s: Successful Update!", hostname);
277 + return RET_OK;
278 + } else if(strstr(server_msg, "ERROR CODE=")) {
279 + ret_msg(NONE, "%s: Error! - %s", hostname, server_msg);
280 + return RET_OK;
281 + } else {
282 + ret_msg(NONE, "%s: Unknown fault - %s", hostname, server_msg);
283 + }
284 + } else if(strstr(server_msg, "401 Authorization Required")) {
285 + ret_msg(NONE, "zoneedit.com: wrong username or password");
286 + } else {
287 + ret_msg(NONE, "zoneedit.com: Internal Server Error - %s", server_msg);
288 + }
289 +
290 + return RET_ERROR;
291 +}
292 Index: updatedd-2.5/src/plugins/Makefile.in
293 ===================================================================
294 --- updatedd-2.5.orig/src/plugins/Makefile.in
295 +++ updatedd-2.5/src/plugins/Makefile.in
296 @@ -35,7 +35,7 @@
297 CFLAGS = -I$(top_builddir) -I$(top_srcdir)/include @CFLAGS@ -fPIC
298 LIBERROR = $(top_builddir)/libexception_handle/libexception_handle.a
299
300 -OBJECTS := changeip.o dyndns.o eurodyndns.o hn.o noip.o ods.o ovh.o regfish.o tzo.o
301 +OBJECTS := changeip.o dyndns.o eurodyndns.o hn.o noip.o ods.o ovh.o regfish.o tzo.o zoneedit.o
302 PLUGINS_ROOT := $(OBJECTS:.o= )
303
304 UNAME:=$(shell uname -s)
305 @@ -78,5 +78,6 @@
306 ovh.o: ovh.h
307 regfish.o: regfish.h
308 tzo.o: tzo.h
309 +zoneedit.o: zoneedit.h
310
311 .PHONY: all plugins install uninstall clean distclean
312 Index: updatedd-2.5/src/plugins/zoneedit.h
313 ===================================================================
314 --- /dev/null
315 +++ updatedd-2.5/src/plugins/zoneedit.h
316 @@ -0,0 +1,82 @@
317 +/* -- updatedd: zoneedit.h --
318 + *
319 + * Copyright (C) 2002, 2003, 2004, 2005 Philipp Benner
320 + *
321 + * This file is part of UpdateDD - http://updatedd.philipp-benner.de.
322 + *
323 + * UpdateDD is free software; you can redistribute it and/or modify
324 + * it under the terms of the GNU General Public License as published by
325 + * the Free Software Foundation; either version 2 of the License, or
326 + * any later version.
327 + *
328 + * UpdateDD is distributed in the hope that it will be useful,
329 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
330 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
331 + * GNU General Public License for more details.
332 + *
333 + * You should have received a copy of the GNU General Public License
334 + * along with UpdateDD; if not, write to the Free Software
335 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
336 + */
337 +
338 +#include <ret_codes.h>
339 +
340 +#define DYNDNSHOST "www.zoneedit.com"
341 +#define PORT 80
342 +
343 +#define BUFSIZE 4096
344 +
345 +#define ARGV_PNAME 0
346 +#define ARGV_LOGIN argc-2
347 +#define ARGV_HOSTNAME argc-1
348 +
349 +#define COLORED(x) "\033[0;39;1m"x"\033[0m"
350 +
351 +static char ret_msg_buf[BUFSIZE];
352 +
353 +struct arguments {
354 + const char *hostname;
355 + char *ipv4;
356 + char *login;
357 + int offline;
358 +};
359 +
360 +/* static struct dyndns_return_codes { */
361 +/* const char *code; */
362 +/* const char *message; */
363 +/* const int error; */
364 +/* } return_codes[] = { */
365 +/* { "badauth", "Bad authorization (username or password).", 1 }, */
366 +/* { "badsys", "The system parameter given was not valid.", 1 }, */
367 +/* { "badagent", "The useragent your client sent has been blocked " */
368 +/* "at the access level.", 1 */
369 +/* }, */
370 +/* { "good", "Update good and successful, IP updated.", 0 }, */
371 +/* { "nochg", "No changes, update considered abusive.", 0 }, */
372 +/* { "notfqdn", "A Fully-Qualified Domain Name was not provided.", 1 }, */
373 +/* { "nohost", "The hostname specified does not exist.", 1 }, */
374 +/* { "!donator", "The offline setting was set, when the user is " */
375 +/* "not a donator.", 1 */
376 +/* }, */
377 +/* { "!yours", "The hostname specified exists, but not under " */
378 +/* "the username currently being used.", 1 */
379 +/* }, */
380 +/* { "!active", "The hostname specified is in a Custom DNS " */
381 +/* "domain which has not yet been activated.", 1 */
382 +/* }, */
383 +/* { "abuse", "The hostname specified is blocked for abuse", 1 }, */
384 +/* { "notfqdn", "No hosts are given.", 1 }, */
385 +/* { "numhost", "Too many or too few hosts found.", 1 }, */
386 +/* { "dnserr", "DNS error encountered.", 1 }, */
387 +/* { NULL, NULL, 0 } */
388 +/* }; */
389 +
390 +static int get_flags(struct arguments *args, int argc, char *argv[]);
391 +static int update_dyndns(const int s, struct arguments *args);
392 +static int check_server_msg(const int s, const char *hostnames);
393 +
394 +char *
395 +get_retmsg(void)
396 +{
397 + return ret_msg_buf;
398 +}