Add dnsexit support from #1798
[openwrt/svn-archive/archive.git] / net / ez-ipupdate / patches / 003-dnsexit.patch
1 diff -Naur ez-ipupdate-3.0.11b8-patched/example-dnsexit.conf ez-ipupdate-3.0.11b8-dnsexit/example-dnsexit.conf
2 --- ez-ipupdate-3.0.11b8-patched/example-dnsexit.conf 1970-01-01 01:00:00.000000000 +0100
3 +++ ez-ipupdate-3.0.11b8-dnsexit/example-dnsexit.conf 2005-12-23 01:34:51.000000000 +0000
4 @@ -0,0 +1,20 @@
5 +#!/usr/sbin/ez-ipupdate -c
6 +#
7 +# example config file for ez-ipupdate
8 +#
9 +# this file is actually executable!
10 +#
11 +
12 +service-type=dnsexit
13 +user=loginname:password
14 +host=www.yourdomain.com
15 +interface=eth0
16 +
17 +# please ensure the user has permission to write this file
18 +cache-file=/tmp/ez-ipupdate.cache
19 +
20 +run-as-user=ez-ipupd
21 +# uncomment this once you have everything working how you want and you are
22 +# ready to have ez-ipupdate running in the background all the time. to stop it
23 +# you can use "killall -QUIT ez-ipupdate" under linux.
24 +#daemon
25 diff -Naur ez-ipupdate-3.0.11b8-patched/ez-ipupdate.c ez-ipupdate-3.0.11b8-dnsexit/ez-ipupdate.c
26 --- ez-ipupdate-3.0.11b8-patched/ez-ipupdate.c 2005-12-23 01:33:54.000000000 +0000
27 +++ ez-ipupdate-3.0.11b8-dnsexit/ez-ipupdate.c 2005-12-23 02:51:19.000000000 +0000
28 @@ -103,6 +103,10 @@
29 #define HEIPV6TB_DEFAULT_PORT "80"
30 #define HEIPV6TB_REQUEST "/index.cgi"
31
32 +#define DNSEXIT_DEFAULT_SERVER "www.dnsexit.com"
33 +#define DNSEXIT_DEFAULT_PORT "80"
34 +#define DNSEXIT_REQUEST "/RemoteUpdate.sv"
35 +
36 #define DEFAULT_TIMEOUT 120
37 #define DEFAULT_UPDATE_PERIOD 120
38 #define DEFAULT_RESOLV_PERIOD 30
39 @@ -344,6 +348,11 @@
40 int HEIPV6TB_check_info(void);
41 static char *HEIPV6TB_fields_used[] = { "server", "user", NULL };
42
43 +int DNSEXIT_update_entry(void);
44 +int DNSEXIT_check_info(void);
45 +static char *DNSEXIT_fields_used[] = { "server", "user", "address", "wildcard", "mx", "host", NULL };
46 +
47 +
48 struct service_t services[] = {
49 { "NULL",
50 { "null", "NULL", 0, },
51 @@ -517,6 +526,16 @@
52 HEIPV6TB_DEFAULT_PORT,
53 HEIPV6TB_REQUEST
54 },
55 + { "dnsexit",
56 + { "dnsexit", 0, 0, },
57 + NULL,
58 + DNSEXIT_update_entry,
59 + DNSEXIT_check_info,
60 + DNSEXIT_fields_used,
61 + DNSEXIT_DEFAULT_SERVER,
62 + DNSEXIT_DEFAULT_PORT,
63 + DNSEXIT_REQUEST
64 + },
65 };
66
67 static struct service_t *service = NULL;
68 @@ -4251,6 +4270,195 @@
69 return(UPDATERES_OK);
70 }
71
72 +int DNSEXIT_check_info(void)
73 +{
74 + char buf[BUFSIZ+1];
75 +
76 + if((host == NULL) || (*host == '\0'))
77 + {
78 + if(options & OPT_DAEMON)
79 + {
80 + return(-1);
81 + }
82 + if(host) { free(host); }
83 + printf("host: ");
84 + *buf = '\0';
85 + fgets(buf, BUFSIZ, stdin);
86 + host = strdup(buf);
87 + chomp(host);
88 + }
89 +
90 + if(interface == NULL && address == NULL)
91 + {
92 + if(options & OPT_DAEMON)
93 + {
94 + fprintf(stderr, "you must provide either an interface or an address\n");
95 + return(-1);
96 + }
97 + if(interface) { free(interface); }
98 + printf("interface: ");
99 + *buf = '\0';
100 + fgets(buf, BUFSIZ, stdin);
101 + chomp(buf);
102 + option_handler(CMD_interface, buf);
103 + }
104 +
105 + warn_fields(service->fields_used);
106 +
107 + return 0;
108 +}
109 +
110 +int DNSEXIT_update_entry(void)
111 +{
112 + char buf[BUFFER_SIZE+1];
113 + char *bp = buf;
114 + int bytes;
115 + int btot;
116 + int ret;
117 +
118 + buf[BUFFER_SIZE] = '\0';
119 +
120 + if(do_connect((int*)&client_sockfd, server, port) != 0)
121 + {
122 + if(!(options & OPT_QUIET))
123 + {
124 + show_message("error connecting to %s:%s\n", server, port);
125 + }
126 + return(UPDATERES_ERROR);
127 + }
128 +
129 + snprintf(buf, BUFFER_SIZE, "GET %s?action=edit&", request);
130 + output(buf);
131 + if(address != NULL && *address != '\0')
132 + {
133 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "myip", address);
134 + output(buf);
135 + }
136 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "wildcard", wildcard ? "ON" : "OFF");
137 + output(buf);
138 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "mx", mx);
139 + output(buf);
140 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "backmx", *mx == '\0' ? "NO" : "YES");
141 + output(buf);
142 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "host", host);
143 + output(buf);
144 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "login", user_name);
145 + output(buf);
146 + snprintf(buf, BUFFER_SIZE, "%s=%s&", "password", password);
147 + output(buf);
148 + snprintf(buf, BUFFER_SIZE, " HTTP/1.0\015\012");
149 + output(buf);
150 + snprintf(buf, BUFFER_SIZE, "Authorization: Basic %s\015\012", auth);
151 + output(buf);
152 + snprintf(buf, BUFFER_SIZE, "User-Agent: %s-%s %s [%s] (%s)\015\012",
153 + "ez-update", VERSION, OS, (options & OPT_DAEMON) ? "daemon" : "", "by Angus Mackay");
154 + output(buf);
155 + snprintf(buf, BUFFER_SIZE, "Host: %s\015\012", server);
156 + output(buf);
157 + snprintf(buf, BUFFER_SIZE, "\015\012");
158 + output(buf);
159 +
160 + bp = buf;
161 + bytes = 0;
162 + btot = 0;
163 + while((bytes=read_input(bp, BUFFER_SIZE-btot)) > 0)
164 + {
165 + bp += bytes;
166 + btot += bytes;
167 + dprintf((stderr, "btot: %d\n", btot));
168 + }
169 + close(client_sockfd);
170 + buf[btot] = '\0';
171 +
172 + dprintf((stderr, "server output: %s\n", buf));
173 +
174 + if(sscanf(buf, " HTTP/1.%*c %3d", &ret) != 1)
175 + {
176 + ret = -1;
177 + }
178 +
179 + switch(ret)
180 + {
181 + case -1:
182 + if(!(options & OPT_QUIET))
183 + {
184 + show_message("strange server response, are you connecting to the right server?\n");
185 + }
186 + return(UPDATERES_ERROR);
187 + break;
188 +
189 + case 200:
190 +
191 + if(strstr(buf, "0=Success") != NULL)
192 + {
193 + if(!(options & OPT_QUIET))
194 + {
195 + printf("Request successful\n");
196 + }
197 + }
198 + else if(strstr(buf, "1=IP is the same as the IP on the system") != NULL)
199 + {
200 + if(!(options & OPT_QUIET))
201 + {
202 + printf("Request successful but the IP is the same as previous update\n");
203 + }
204 + }
205 + else if(strstr(buf, "2=Invalid passwords") != NULL)
206 + {
207 + if(!(options & OPT_QUIET))
208 + {
209 + printf("Invalid Password\n");
210 + }
211 + }
212 + else if(strstr(buf, "3=User not found") != NULL)
213 + {
214 + if(!(options & OPT_QUIET))
215 + {
216 + printf("Username not found\n");
217 + }
218 + }
219 + else if(strstr(buf, "4=Update too often") != NULL)
220 + {
221 + if(!(options & OPT_QUIET))
222 + {
223 + printf("Updatting too often\n");
224 + }
225 + }
226 + else
227 + {
228 + show_message("Errors return from server\n");
229 + if(!(options & OPT_QUIET))
230 + {
231 + fprintf(stderr, "server output: %s\n", buf);
232 + }
233 + return(UPDATERES_ERROR);
234 + }
235 + break;
236 +
237 + case 401:
238 + if(!(options & OPT_QUIET))
239 + {
240 + show_message("authentication failure\n");
241 + }
242 + return(UPDATERES_SHUTDOWN);
243 + break;
244 +
245 + default:
246 + if(!(options & OPT_QUIET))
247 + {
248 + // reuse the auth buffer
249 + *auth = '\0';
250 + sscanf(buf, " HTTP/1.%*c %*3d %255[^\r\n]", auth);
251 + show_message("unknown return code: %d\n", ret);
252 + show_message("server response: %s\n", auth);
253 + }
254 + return(UPDATERES_ERROR);
255 + break;
256 + }
257 +
258 + return(UPDATERES_OK);
259 +}
260 +
261 static int is_in_list(char *needle, char **haystack)
262 {
263 char **p;