Merge lp:~swt-techie/ubuntu/utopic/ddclient/bug-1068884 into lp:ubuntu/utopic/ddclient
- Utopic (14.10)
- bug-1068884
- Merge into utopic
Proposed by
Scott Talbert
Status: | Approved |
---|---|
Approved by: | Brian Murray |
Approved revision: | 39 |
Proposed branch: | lp:~swt-techie/ubuntu/utopic/ddclient/bug-1068884 |
Merge into: | lp:ubuntu/utopic/ddclient |
Diff against target: |
3799 lines (+3730/-5) 7 files modified
.pc/applied-patches (+1/-0) .pc/fix_digest_sha_freedns.diff/ddclient (+3683/-0) ddclient (+9/-4) debian/changelog (+7/-0) debian/control (+2/-1) debian/patches/fix_digest_sha_freedns.diff (+27/-0) debian/patches/series (+1/-0) |
To merge this branch: | bzr merge lp:~swt-techie/ubuntu/utopic/ddclient/bug-1068884 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Murray | Approve | ||
Review via email: mp+244253@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Unmerged revisions
- 39. By Scott Talbert
-
Add patch from upstream which enables ddclient to find Digest::SHA to
fix FreeDNS support (LP: #1068884)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.pc/applied-patches' | |||
2 | --- .pc/applied-patches 2012-09-18 13:30:33 +0000 | |||
3 | +++ .pc/applied-patches 2014-12-10 04:52:08 +0000 | |||
4 | @@ -2,3 +2,4 @@ | |||
5 | 2 | config_path.diff | 2 | config_path.diff |
6 | 3 | maxinterval.diff | 3 | maxinterval.diff |
7 | 4 | sample_ubuntu.diff | 4 | sample_ubuntu.diff |
8 | 5 | fix_digest_sha_freedns.diff | ||
9 | 5 | 6 | ||
10 | === added file '.pc/config_path.diff/.timestamp' | |||
11 | === added directory '.pc/fix_digest_sha_freedns.diff' | |||
12 | === added file '.pc/fix_digest_sha_freedns.diff/.timestamp' | |||
13 | === added file '.pc/fix_digest_sha_freedns.diff/ddclient' | |||
14 | --- .pc/fix_digest_sha_freedns.diff/ddclient 1970-01-01 00:00:00 +0000 | |||
15 | +++ .pc/fix_digest_sha_freedns.diff/ddclient 2014-12-10 04:52:08 +0000 | |||
16 | @@ -0,0 +1,3683 @@ | |||
17 | 1 | #!/usr/bin/perl -w | ||
18 | 2 | #!/usr/local/bin/perl -w | ||
19 | 3 | ###################################################################### | ||
20 | 4 | # $Id: ddclient 130 2011-07-11 21:02:07Z wimpunk $ | ||
21 | 5 | # | ||
22 | 6 | # DDCLIENT - a Perl client for updating DynDNS information | ||
23 | 7 | # | ||
24 | 8 | # Author: Paul Burry (paul+ddclient@burry.ca) | ||
25 | 9 | # ddclient-developers: see https://sourceforge.net/project/memberlist.php?group_id=116817 | ||
26 | 10 | # | ||
27 | 11 | # website: http://ddclient.sf.net | ||
28 | 12 | # | ||
29 | 13 | # Support for multiple IP numbers added by | ||
30 | 14 | # Astaro AG, Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> September 16, 2008 | ||
31 | 15 | # | ||
32 | 16 | ###################################################################### | ||
33 | 17 | require 5.004; | ||
34 | 18 | use strict; | ||
35 | 19 | use Getopt::Long; | ||
36 | 20 | use Sys::Hostname; | ||
37 | 21 | use IO::Socket; | ||
38 | 22 | |||
39 | 23 | my ($VERSION) = q$Revision: 130 $ =~ /(\d+)/; | ||
40 | 24 | |||
41 | 25 | my $version = "3.8.1"; | ||
42 | 26 | my $programd = $0; | ||
43 | 27 | $programd =~ s%^.*/%%; | ||
44 | 28 | my $program = $programd; | ||
45 | 29 | $program =~ s/d$//; | ||
46 | 30 | my $now = time; | ||
47 | 31 | my $hostname = hostname(); | ||
48 | 32 | my $etc = ($program =~ /test/i) ? './' : '/etc/'; | ||
49 | 33 | my $cachedir = ($program =~ /test/i) ? './' : '/var/cache/ddclient/'; | ||
50 | 34 | my $savedir = ($program =~ /test/i) ? 'URL/' : '/tmp/'; | ||
51 | 35 | my $msgs = ''; | ||
52 | 36 | my $last_msgs = ''; | ||
53 | 37 | |||
54 | 38 | use vars qw($file $lineno); | ||
55 | 39 | local $file = ''; | ||
56 | 40 | local $lineno = ''; | ||
57 | 41 | |||
58 | 42 | $ENV{'PATH'} = (exists($ENV{PATH}) ? "$ENV{PATH}:" : "") . "/sbin:/usr/sbin:/bin:/usr/bin:/etc:/usr/lib:"; | ||
59 | 43 | |||
60 | 44 | sub T_ANY {'any'}; | ||
61 | 45 | sub T_STRING {'string'}; | ||
62 | 46 | sub T_EMAIL {'e-mail address'}; | ||
63 | 47 | sub T_NUMBER {'number'}; | ||
64 | 48 | sub T_DELAY {'time delay (ie. 1d, 1hour, 1m)'}; | ||
65 | 49 | sub T_LOGIN {'login'}; | ||
66 | 50 | sub T_PASSWD {'password'}; | ||
67 | 51 | sub T_BOOL {'boolean value'}; | ||
68 | 52 | sub T_FQDN {'fully qualified host name'}; | ||
69 | 53 | sub T_OFQDN {'optional fully qualified host name'}; | ||
70 | 54 | sub T_FILE {'file name'}; | ||
71 | 55 | sub T_FQDNP {'fully qualified host name and optional port number'}; | ||
72 | 56 | sub T_PROTO {'protocol'} | ||
73 | 57 | sub T_USE {'ip strategy'} | ||
74 | 58 | sub T_IF {'interface'} | ||
75 | 59 | sub T_PROG {'program name'} | ||
76 | 60 | sub T_IP {'ip'} | ||
77 | 61 | sub T_POSTS {'postscript'}; | ||
78 | 62 | |||
79 | 63 | ## strategies for obtaining an ip address. | ||
80 | 64 | my %builtinweb = ( | ||
81 | 65 | 'dyndns' => { 'url' => 'http://checkip.dyndns.org/', 'skip' => | ||
82 | 66 | 'Current IP Address:', }, | ||
83 | 67 | 'dnspark' => { 'url' => 'http://ipdetect.dnspark.com/', 'skip' => 'Current Address:', }, | ||
84 | 68 | 'loopia' => { 'url' => 'http://dns.loopia.se/checkip/checkip.php', 'skip' => 'Current Address:', }, | ||
85 | 69 | ); | ||
86 | 70 | my %builtinfw = ( | ||
87 | 71 | 'watchguard-soho' => { | ||
88 | 72 | 'name' => 'Watchguard SOHO FW', | ||
89 | 73 | 'url' => '/pubnet.htm', | ||
90 | 74 | 'skip' => 'NAME=IPAddress VALUE=', | ||
91 | 75 | }, | ||
92 | 76 | 'netopia-r910' => { | ||
93 | 77 | 'name' => 'Netopia R910 FW', | ||
94 | 78 | 'url' => '/WanEvtLog', | ||
95 | 79 | 'skip' => 'local:', | ||
96 | 80 | }, | ||
97 | 81 | 'smc-barricade' => { | ||
98 | 82 | 'name' => 'SMC Barricade FW', | ||
99 | 83 | 'url' => '/status.htm', | ||
100 | 84 | 'skip' => 'IP Address', | ||
101 | 85 | }, | ||
102 | 86 | 'smc-barricade-alt' => { | ||
103 | 87 | 'name' => 'SMC Barricade FW (alternate config)', | ||
104 | 88 | 'url' => '/status.HTM', | ||
105 | 89 | 'skip' => 'WAN IP', | ||
106 | 90 | }, | ||
107 | 91 | 'smc-barricade-alt' => { | ||
108 | 92 | 'name' => 'SMC Barricade FW (alternate config)', | ||
109 | 93 | 'url' => '/status.HTM', | ||
110 | 94 | 'skip' => 'WAN IP', | ||
111 | 95 | }, | ||
112 | 96 | 'smc-barricade-7401bra' => { | ||
113 | 97 | 'name' => 'SMC Barricade 7401BRA FW', | ||
114 | 98 | 'url' => '/admin/wan1.htm', | ||
115 | 99 | 'skip' => 'IP Address', | ||
116 | 100 | }, | ||
117 | 101 | 'netgear-rt3xx' => { | ||
118 | 102 | 'name' => 'Netgear FW', | ||
119 | 103 | 'url' => '/mtenSysStatus.html', | ||
120 | 104 | 'skip' => 'IP Address', | ||
121 | 105 | }, | ||
122 | 106 | 'elsa-lancom-dsl10' => { | ||
123 | 107 | 'name' => 'ELSA LanCom DSL/10 DSL FW', | ||
124 | 108 | 'url' => '/config/1/6/8/3/', | ||
125 | 109 | 'skip' => 'IP.Address', | ||
126 | 110 | }, | ||
127 | 111 | 'elsa-lancom-dsl10-ch01' => { | ||
128 | 112 | 'name' => 'ELSA LanCom DSL/10 DSL FW (isdn ch01)', | ||
129 | 113 | 'url' => '/config/1/6/8/3/', | ||
130 | 114 | 'skip' => 'IP.Address.*?CH01', | ||
131 | 115 | }, | ||
132 | 116 | 'elsa-lancom-dsl10-ch02' => { | ||
133 | 117 | 'name' => 'ELSA LanCom DSL/10 DSL FW (isdn ch01)', | ||
134 | 118 | 'url' => '/config/1/6/8/3/', | ||
135 | 119 | 'skip' => 'IP.Address.*?CH02', | ||
136 | 120 | }, | ||
137 | 121 | 'linksys' => { | ||
138 | 122 | 'name' => 'Linksys FW', | ||
139 | 123 | 'url' => '/Status.htm', | ||
140 | 124 | 'skip' => 'WAN.*?Address', | ||
141 | 125 | }, | ||
142 | 126 | 'linksys-ver2' => { | ||
143 | 127 | 'name' => 'Linksys FW version 2', | ||
144 | 128 | 'url' => '/RouterStatus.htm', | ||
145 | 129 | 'skip' => 'WAN.*?Address', | ||
146 | 130 | }, | ||
147 | 131 | 'linksys-ver3' => { | ||
148 | 132 | 'name' => 'Linksys FW version 3', | ||
149 | 133 | 'url' => '/Status_Router.htm', | ||
150 | 134 | 'skip' => 'WAN.*?Address', | ||
151 | 135 | }, | ||
152 | 136 | 'linksys-wrt854g' => { | ||
153 | 137 | 'name' => 'Linksys WRT854G FW', | ||
154 | 138 | 'url' => '/Status_Router.asp', | ||
155 | 139 | 'skip' => 'IP Address:', | ||
156 | 140 | }, | ||
157 | 141 | 'maxgate-ugate3x00' => { | ||
158 | 142 | 'name' => 'MaxGate UGATE-3x00 FW', | ||
159 | 143 | 'url' => '/Status.htm', | ||
160 | 144 | 'skip' => 'WAN.*?IP Address', | ||
161 | 145 | }, | ||
162 | 146 | 'netcomm-nb3' => { | ||
163 | 147 | 'name' => 'NetComm NB3', | ||
164 | 148 | 'url' => '/MainPage?id=6', | ||
165 | 149 | 'skip' => 'ppp-0', | ||
166 | 150 | }, | ||
167 | 151 | '3com-3c886a' => { | ||
168 | 152 | 'name' => '3com 3c886a 56k Lan Modem', | ||
169 | 153 | 'url' => '/stat3.htm', | ||
170 | 154 | 'skip' => 'IP address in use', | ||
171 | 155 | }, | ||
172 | 156 | 'sohoware-nbg800' => { | ||
173 | 157 | 'name' => 'SOHOWare BroadGuard NBG800', | ||
174 | 158 | 'url' => '/status.htm', | ||
175 | 159 | 'skip' => 'Internet IP', | ||
176 | 160 | }, | ||
177 | 161 | 'xsense-aero' => { | ||
178 | 162 | 'name' => 'Xsense Aero', | ||
179 | 163 | 'url' => '/A_SysInfo.htm', | ||
180 | 164 | 'skip' => 'WAN.*?IP Address', | ||
181 | 165 | }, | ||
182 | 166 | 'alcatel-stp' => { | ||
183 | 167 | 'name' => 'Alcatel Speed Touch Pro', | ||
184 | 168 | 'url' => '/cgi/router/', | ||
185 | 169 | 'skip' => 'Brt', | ||
186 | 170 | }, | ||
187 | 171 | 'alcatel-510' => { | ||
188 | 172 | 'name' => 'Alcatel Speed Touch 510', | ||
189 | 173 | 'url' => '/cgi/ip/', | ||
190 | 174 | 'skip' => 'ppp', | ||
191 | 175 | }, | ||
192 | 176 | 'allnet-1298' => { | ||
193 | 177 | 'name' => 'Allnet 1298', | ||
194 | 178 | 'url' => '/cgi/router/', | ||
195 | 179 | 'skip' => 'WAN', | ||
196 | 180 | }, | ||
197 | 181 | '3com-oc-remote812' => { | ||
198 | 182 | 'name' => '3com OfficeConnect Remote 812', | ||
199 | 183 | 'url' => '/callEvent', | ||
200 | 184 | 'skip' => '.*LOCAL', | ||
201 | 185 | }, | ||
202 | 186 | 'e-tech' => { | ||
203 | 187 | 'name' => 'E-tech Router', | ||
204 | 188 | 'url' => '/Status.htm', | ||
205 | 189 | 'skip' => 'Public IP Address', | ||
206 | 190 | }, | ||
207 | 191 | 'cayman-3220h' => { | ||
208 | 192 | 'name' => 'Cayman 3220-H DSL', | ||
209 | 193 | 'url' => '/shell/show+ip+interfaces', | ||
210 | 194 | 'skip' => '.*inet', | ||
211 | 195 | }, | ||
212 | 196 | 'vigor-2200usb' => { | ||
213 | 197 | 'name' => 'Vigor 2200 USB', | ||
214 | 198 | 'url' => '/doc/online.sht', | ||
215 | 199 | 'skip' => 'PPPoA', | ||
216 | 200 | }, | ||
217 | 201 | 'dlink-614' => { | ||
218 | 202 | 'name' => 'D-Link DI-614+', | ||
219 | 203 | 'url' => '/st_devic.html', | ||
220 | 204 | 'skip' => 'WAN', | ||
221 | 205 | }, | ||
222 | 206 | 'dlink-604' => { | ||
223 | 207 | 'name' => 'D-Link DI-604', | ||
224 | 208 | 'url' => '/st_devic.html', | ||
225 | 209 | 'skip' => 'WAN.*?IP.*Address', | ||
226 | 210 | }, | ||
227 | 211 | 'olitec-SX200' => { | ||
228 | 212 | 'name' => 'olitec-SX200', | ||
229 | 213 | 'url' => '/doc/wan.htm', | ||
230 | 214 | 'skip' => 'st_wan_ip[0] = "', | ||
231 | 215 | }, | ||
232 | 216 | 'westell-6100' => { | ||
233 | 217 | 'name' => 'Westell C90-610015-06 DSL Router', | ||
234 | 218 | 'url' => '/advstat.htm', | ||
235 | 219 | 'skip' => 'IP.+?Address', | ||
236 | 220 | }, | ||
237 | 221 | '2wire' => { | ||
238 | 222 | 'name' => '2Wire 1701HG Gateway', | ||
239 | 223 | 'url' => '/xslt?PAGE=B01', | ||
240 | 224 | 'skip' => 'Internet Address:', | ||
241 | 225 | }, | ||
242 | 226 | 'linksys-rv042-wan1' => { | ||
243 | 227 | 'name' => 'Linksys RV042 Dual Homed Router WAN Port 2', | ||
244 | 228 | 'url' => '/home.htm', | ||
245 | 229 | 'skip' => 'WAN1 IP', | ||
246 | 230 | }, | ||
247 | 231 | 'linksys-rv042-wan2' => { | ||
248 | 232 | 'name' => 'Linksys RV042 Dual Homed Router WAN Port 2', | ||
249 | 233 | 'url' => '/home.htm', | ||
250 | 234 | 'skip' => 'WAN2 IP', | ||
251 | 235 | }, | ||
252 | 236 | 'netgear-rp614' => { | ||
253 | 237 | 'name' => 'Netgear RP614 FW', | ||
254 | 238 | 'url' => '/sysstatus.html', | ||
255 | 239 | 'skip' => 'IP Address', | ||
256 | 240 | }, | ||
257 | 241 | 'watchguard-edge-x' => { | ||
258 | 242 | 'name' => 'Watchguard Edge X FW', | ||
259 | 243 | 'url' => '/netstat.htm', | ||
260 | 244 | 'skip' => 'inet addr:', | ||
261 | 245 | }, | ||
262 | 246 | 'dlink-524' => { | ||
263 | 247 | 'name' => 'D-Link DI-524', | ||
264 | 248 | 'url' => '/st_device.html', | ||
265 | 249 | 'skip' => 'WAN.*?Addres', | ||
266 | 250 | }, | ||
267 | 251 | 'rtp300' => { | ||
268 | 252 | 'name' => 'Linksys RTP300', | ||
269 | 253 | 'url' => '/cgi-bin/webcm?getpage=%2Fusr%2Fwww_safe%2Fhtml%2Fstatus%2FRouter.html', | ||
270 | 254 | 'skip' => 'Internet.*?IP Address', | ||
271 | 255 | }, | ||
272 | 256 | 'netgear-wpn824' => { | ||
273 | 257 | 'name' => 'Netgear WPN824 FW', | ||
274 | 258 | 'url' => '/RST_status.htm', | ||
275 | 259 | 'skip' => 'IP Address', | ||
276 | 260 | }, | ||
277 | 261 | 'linksys-wcg200' => { | ||
278 | 262 | 'name' => 'Linksys WCG200 FW', | ||
279 | 263 | 'url' => '/RgStatus.asp', | ||
280 | 264 | 'skip' => 'WAN.IP.*?Address', | ||
281 | 265 | }, | ||
282 | 266 | 'netgear-dg834g' => { | ||
283 | 267 | 'name' => 'netgear-dg834g', | ||
284 | 268 | 'url' => '/setup.cgi?next_file=s_status.htm&todo=cfg_init', | ||
285 | 269 | 'skip' => '', | ||
286 | 270 | }, | ||
287 | 271 | 'netgear-wgt624' => { | ||
288 | 272 | 'name' => 'Netgear WGT624', | ||
289 | 273 | 'url' => '/RST_st_dhcp.htm', | ||
290 | 274 | 'skip' => 'IP Address</B></td><TD NOWRAP width="50%">', | ||
291 | 275 | }, | ||
292 | 276 | 'sveasoft' => { | ||
293 | 277 | 'name' => 'Sveasoft WRT54G/WRT54GS', | ||
294 | 278 | 'url' => '/Status_Router.asp', | ||
295 | 279 | 'skip' => 'var wan_ip', | ||
296 | 280 | }, | ||
297 | 281 | 'smc-barricade-7004vbr' => { | ||
298 | 282 | 'name' => 'SMC Barricade FW (7004VBR model config)', | ||
299 | 283 | 'url' => '/status_main.stm', | ||
300 | 284 | 'skip' => 'var wan_ip=', | ||
301 | 285 | }, | ||
302 | 286 | 'sitecom-dc202' => { | ||
303 | 287 | 'name' => 'Sitecom DC-202 FW', | ||
304 | 288 | 'url' => '/status.htm', | ||
305 | 289 | 'skip' => 'Internet IP Address', | ||
306 | 290 | }, | ||
307 | 291 | ); | ||
308 | 292 | my %ip_strategies = ( | ||
309 | 293 | 'ip' => ": obtain IP from -ip {address}", | ||
310 | 294 | 'web' => ": obtain IP from an IP discovery page on the web", | ||
311 | 295 | 'fw' => ": obtain IP from the firewall specified by -fw {type|address}", | ||
312 | 296 | 'if' => ": obtain IP from the -if {interface}", | ||
313 | 297 | 'cmd' => ": obtain IP from the -cmd {external-command}", | ||
314 | 298 | 'cisco' => ": obtain IP from Cisco FW at the -fw {address}", | ||
315 | 299 | 'cisco-asa' => ": obtain IP from Cisco ASA at the -fw {address}", | ||
316 | 300 | map { $_ => sprintf ": obtain IP from %s at the -fw {address}", $builtinfw{$_}->{'name'} } keys %builtinfw, | ||
317 | 301 | ); | ||
318 | 302 | sub ip_strategies_usage { | ||
319 | 303 | return map { sprintf(" -use=%-22s %s.", $_, $ip_strategies{$_}) } sort keys %ip_strategies; | ||
320 | 304 | } | ||
321 | 305 | |||
322 | 306 | my %web_strategies = ( | ||
323 | 307 | 'dyndns'=> 1, | ||
324 | 308 | 'dnspark'=> 1, | ||
325 | 309 | 'loopia'=> 1, | ||
326 | 310 | ); | ||
327 | 311 | |||
328 | 312 | sub setv { | ||
329 | 313 | return { | ||
330 | 314 | 'type' => shift, | ||
331 | 315 | 'required' => shift, | ||
332 | 316 | 'cache' => shift, | ||
333 | 317 | 'config' => shift, | ||
334 | 318 | 'default' => shift, | ||
335 | 319 | 'minimum' => shift, | ||
336 | 320 | }; | ||
337 | 321 | }; | ||
338 | 322 | my %variables = ( | ||
339 | 323 | 'global-defaults' => { | ||
340 | 324 | 'daemon' => setv(T_DELAY, 0, 0, 1, 0, interval('60s')), | ||
341 | 325 | 'foreground' => setv(T_BOOL, 0, 0, 1, 0, undef), | ||
342 | 326 | 'file' => setv(T_FILE, 0, 0, 1, "$etc$program.conf", undef), | ||
343 | 327 | 'cache' => setv(T_FILE, 0, 0, 1, "$cachedir$program.cache", undef), | ||
344 | 328 | 'pid' => setv(T_FILE, 0, 0, 1, "", undef), | ||
345 | 329 | 'proxy' => setv(T_FQDNP, 0, 0, 1, '', undef), | ||
346 | 330 | 'protocol' => setv(T_PROTO, 0, 0, 1, 'dyndns2', undef), | ||
347 | 331 | |||
348 | 332 | 'use' => setv(T_USE, 0, 0, 1, 'ip', undef), | ||
349 | 333 | 'ip' => setv(T_IP, 0, 0, 1, undef, undef), | ||
350 | 334 | 'if' => setv(T_IF, 0, 0, 1, 'ppp0', undef), | ||
351 | 335 | 'if-skip' => setv(T_STRING,1, 0, 1, '', undef), | ||
352 | 336 | 'web' => setv(T_STRING,0, 0, 1, 'dyndns', undef), | ||
353 | 337 | 'web-skip' => setv(T_STRING,1, 0, 1, '', undef), | ||
354 | 338 | 'fw' => setv(T_ANY, 0, 0, 1, '', undef), | ||
355 | 339 | 'fw-skip' => setv(T_STRING,1, 0, 1, '', undef), | ||
356 | 340 | 'fw-login' => setv(T_LOGIN, 1, 0, 1, '', undef), | ||
357 | 341 | 'fw-password' => setv(T_PASSWD,1, 0, 1, '', undef), | ||
358 | 342 | 'cmd' => setv(T_PROG, 0, 0, 1, '', undef), | ||
359 | 343 | 'cmd-skip' => setv(T_STRING,1, 0, 1, '', undef), | ||
360 | 344 | |||
361 | 345 | 'timeout' => setv(T_DELAY, 0, 0, 1, interval('120s'), interval('120s')), | ||
362 | 346 | 'retry' => setv(T_BOOL, 0, 0, 0, 0, undef), | ||
363 | 347 | 'force' => setv(T_BOOL, 0, 0, 0, 0, undef), | ||
364 | 348 | 'ssl' => setv(T_BOOL, 0, 0, 0, 0, undef), | ||
365 | 349 | |||
366 | 350 | 'syslog' => setv(T_BOOL, 0, 0, 1, 0, undef), | ||
367 | 351 | 'facility' => setv(T_STRING,0, 0, 1, 'daemon', undef), | ||
368 | 352 | 'priority' => setv(T_STRING,0, 0, 1, 'notice', undef), | ||
369 | 353 | 'mail' => setv(T_EMAIL, 0, 0, 1, '', undef), | ||
370 | 354 | 'mail-failure' => setv(T_EMAIL, 0, 0, 1, '', undef), | ||
371 | 355 | |||
372 | 356 | 'exec' => setv(T_BOOL, 0, 0, 1, 1, undef), | ||
373 | 357 | 'debug' => setv(T_BOOL, 0, 0, 1, 0, undef), | ||
374 | 358 | 'verbose' => setv(T_BOOL, 0, 0, 1, 0, undef), | ||
375 | 359 | 'quiet' => setv(T_BOOL, 0, 0, 1, 0, undef), | ||
376 | 360 | 'help' => setv(T_BOOL, 0, 0, 1, 0, undef), | ||
377 | 361 | 'test' => setv(T_BOOL, 0, 0, 1, 0, undef), | ||
378 | 362 | 'geturl' => setv(T_STRING,0, 0, 0, '', undef), | ||
379 | 363 | |||
380 | 364 | 'postscript' => setv(T_POSTS, 0, 0, 1, '', undef), | ||
381 | 365 | }, | ||
382 | 366 | 'service-common-defaults' => { | ||
383 | 367 | 'server' => setv(T_FQDNP, 1, 0, 1, 'members.dyndns.org', undef), | ||
384 | 368 | 'login' => setv(T_LOGIN, 1, 0, 1, '', undef), | ||
385 | 369 | 'password' => setv(T_PASSWD, 1, 0, 1, '', undef), | ||
386 | 370 | 'host' => setv(T_STRING, 1, 1, 1, '', undef), | ||
387 | 371 | |||
388 | 372 | 'use' => setv(T_USE, 0, 0, 1, 'ip', undef), | ||
389 | 373 | 'if' => setv(T_IF, 0, 0, 1, 'ppp0', undef), | ||
390 | 374 | 'if-skip' => setv(T_STRING,0, 0, 1, '', undef), | ||
391 | 375 | 'web' => setv(T_STRING,0, 0, 1, 'dyndns', undef), | ||
392 | 376 | 'web-skip' => setv(T_STRING,0, 0, 1, '', undef), | ||
393 | 377 | 'fw' => setv(T_ANY, 0, 0, 1, '', undef), | ||
394 | 378 | 'fw-skip' => setv(T_STRING,0, 0, 1, '', undef), | ||
395 | 379 | 'fw-login' => setv(T_LOGIN, 0, 0, 1, '', undef), | ||
396 | 380 | 'fw-password' => setv(T_PASSWD,0, 0, 1, '', undef), | ||
397 | 381 | 'cmd' => setv(T_PROG, 0, 0, 1, '', undef), | ||
398 | 382 | 'cmd-skip' => setv(T_STRING,0, 0, 1, '', undef), | ||
399 | 383 | |||
400 | 384 | 'ip' => setv(T_IP, 0, 1, 0, undef, undef), | ||
401 | 385 | 'wtime' => setv(T_DELAY, 0, 1, 1, 0, interval('30s')), | ||
402 | 386 | 'mtime' => setv(T_NUMBER, 0, 1, 0, 0, undef), | ||
403 | 387 | 'atime' => setv(T_NUMBER, 0, 1, 0, 0, undef), | ||
404 | 388 | 'status' => setv(T_ANY, 0, 1, 0, '', undef), | ||
405 | 389 | 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('30s'), 0), | ||
406 | 390 | 'max-interval' => setv(T_DELAY, 0, 0, 1, interval('30d'), 0), | ||
407 | 391 | 'min-error-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0), | ||
408 | 392 | |||
409 | 393 | 'warned-min-interval' => setv(T_ANY, 0, 1, 0, 0, undef), | ||
410 | 394 | 'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, 0, undef), | ||
411 | 395 | }, | ||
412 | 396 | 'dyndns-common-defaults' => { | ||
413 | 397 | 'static' => setv(T_BOOL, 0, 1, 1, 0, undef), | ||
414 | 398 | 'wildcard' => setv(T_BOOL, 0, 1, 1, 0, undef), | ||
415 | 399 | 'mx' => setv(T_OFQDN, 0, 1, 1, '', undef), | ||
416 | 400 | 'backupmx' => setv(T_BOOL, 0, 1, 1, 0, undef), | ||
417 | 401 | }, | ||
418 | 402 | 'easydns-common-defaults' => { | ||
419 | 403 | 'wildcard' => setv(T_BOOL, 0, 1, 1, 0, undef), | ||
420 | 404 | 'mx' => setv(T_OFQDN, 0, 1, 1, '', undef), | ||
421 | 405 | 'backupmx' => setv(T_BOOL, 0, 1, 1, 0, undef), | ||
422 | 406 | }, | ||
423 | 407 | 'dnspark-common-defaults' => { | ||
424 | 408 | 'mx' => setv(T_OFQDN, 0, 1, 1, '', undef), | ||
425 | 409 | 'mxpri' => setv(T_NUMBER, 0, 0, 1, 5, undef), | ||
426 | 410 | }, | ||
427 | 411 | 'noip-common-defaults' => { | ||
428 | 412 | 'static' => setv(T_BOOL, 0, 1, 1, 0, undef), | ||
429 | 413 | }, | ||
430 | 414 | 'noip-service-common-defaults' => { | ||
431 | 415 | 'server' => setv(T_FQDNP, 1, 0, 1, 'dynupdate.no-ip.com', undef), | ||
432 | 416 | 'login' => setv(T_LOGIN, 1, 0, 1, '', undef), | ||
433 | 417 | 'password' => setv(T_PASSWD, 1, 0, 1, '', undef), | ||
434 | 418 | 'host' => setv(T_STRING, 1, 1, 1, '', undef), | ||
435 | 419 | 'ip' => setv(T_IP, 0, 1, 0, undef, undef), | ||
436 | 420 | 'wtime' => setv(T_DELAY, 0, 1, 1, 0, interval('30s')), | ||
437 | 421 | 'mtime' => setv(T_NUMBER, 0, 1, 0, 0, undef), | ||
438 | 422 | 'atime' => setv(T_NUMBER, 0, 1, 0, 0, undef), | ||
439 | 423 | 'status' => setv(T_ANY, 0, 1, 0, '', undef), | ||
440 | 424 | 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('30s'), 0), | ||
441 | 425 | 'max-interval' => setv(T_DELAY, 0, 0, 1, interval('25d'), 0), | ||
442 | 426 | 'min-error-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0), | ||
443 | 427 | 'warned-min-interval' => setv(T_ANY, 0, 1, 0, 0, undef), | ||
444 | 428 | 'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, 0, undef), | ||
445 | 429 | }, | ||
446 | 430 | 'zoneedit-service-common-defaults' => { | ||
447 | 431 | 'zone' => setv(T_OFQDN, 0, 0, 1, undef, undef), | ||
448 | 432 | }, | ||
449 | 433 | 'dtdns-common-defaults' => { | ||
450 | 434 | 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), | ||
451 | 435 | 'client' => setv(T_STRING, 0, 1, 1, $program, undef), | ||
452 | 436 | }, | ||
453 | 437 | ); | ||
454 | 438 | my %services = ( | ||
455 | 439 | 'dyndns1' => { | ||
456 | 440 | 'updateable' => \&nic_dyndns2_updateable, | ||
457 | 441 | 'update' => \&nic_dyndns1_update, | ||
458 | 442 | 'examples' => \&nic_dyndns1_examples, | ||
459 | 443 | 'variables' => merge( | ||
460 | 444 | $variables{'dyndns-common-defaults'}, | ||
461 | 445 | $variables{'service-common-defaults'}, | ||
462 | 446 | ), | ||
463 | 447 | }, | ||
464 | 448 | 'dyndns2' => { | ||
465 | 449 | 'updateable' => \&nic_dyndns2_updateable, | ||
466 | 450 | 'update' => \&nic_dyndns2_update, | ||
467 | 451 | 'examples' => \&nic_dyndns2_examples, | ||
468 | 452 | 'variables' => merge( | ||
469 | 453 | { 'custom' => setv(T_BOOL, 0, 1, 1, 0, undef), }, | ||
470 | 454 | { 'script' => setv(T_STRING, 1, 1, 1, '/nic/update', undef), }, | ||
471 | 455 | # { 'offline' => setv(T_BOOL, 0, 1, 1, 0, undef), }, | ||
472 | 456 | $variables{'dyndns-common-defaults'}, | ||
473 | 457 | $variables{'service-common-defaults'}, | ||
474 | 458 | ), | ||
475 | 459 | }, | ||
476 | 460 | 'noip' => { | ||
477 | 461 | 'updateable' => undef, | ||
478 | 462 | 'update' => \&nic_noip_update, | ||
479 | 463 | 'examples' => \&nic_noip_examples, | ||
480 | 464 | 'variables' => merge( | ||
481 | 465 | { 'custom' => setv(T_BOOL, 0, 1, 1, 0, undef), }, | ||
482 | 466 | $variables{'noip-common-defaults'}, | ||
483 | 467 | $variables{'noip-service-common-defaults'}, | ||
484 | 468 | ), | ||
485 | 469 | }, | ||
486 | 470 | 'concont' => { | ||
487 | 471 | 'updateable' => undef, | ||
488 | 472 | 'update' => \&nic_concont_update, | ||
489 | 473 | 'examples' => \&nic_concont_examples, | ||
490 | 474 | 'variables' => merge( | ||
491 | 475 | $variables{'service-common-defaults'}, | ||
492 | 476 | { 'mx' => setv(T_OFQDN, 0, 1, 1, '', undef), }, | ||
493 | 477 | { 'wildcard' => setv(T_BOOL, 0, 1, 1, 0, undef), }, | ||
494 | 478 | ), | ||
495 | 479 | }, | ||
496 | 480 | 'dslreports1' => { | ||
497 | 481 | 'updateable' => undef, | ||
498 | 482 | 'update' => \&nic_dslreports1_update, | ||
499 | 483 | 'examples' => \&nic_dslreports1_examples, | ||
500 | 484 | 'variables' => merge( | ||
501 | 485 | { 'host' => setv(T_NUMBER, 1, 1, 1, 0, undef) }, | ||
502 | 486 | $variables{'service-common-defaults'}, | ||
503 | 487 | ), | ||
504 | 488 | }, | ||
505 | 489 | 'hammernode1' => { | ||
506 | 490 | 'updateable' => undef, | ||
507 | 491 | 'update' => \&nic_hammernode1_update, | ||
508 | 492 | 'examples' => \&nic_hammernode1_examples, | ||
509 | 493 | 'variables' => merge( | ||
510 | 494 | { 'server' => setv(T_FQDNP, 1, 0, 1, 'dup.hn.org', undef) }, | ||
511 | 495 | { 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0),}, | ||
512 | 496 | $variables{'service-common-defaults'}, | ||
513 | 497 | ), | ||
514 | 498 | }, | ||
515 | 499 | 'zoneedit1' => { | ||
516 | 500 | 'updateable' => undef, | ||
517 | 501 | 'update' => \&nic_zoneedit1_update, | ||
518 | 502 | 'examples' => \&nic_zoneedit1_examples, | ||
519 | 503 | 'variables' => merge( | ||
520 | 504 | { 'server' => setv(T_FQDNP, 1, 0, 1, 'dynamic.zoneedit.com', undef) }, | ||
521 | 505 | { 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0),}, | ||
522 | 506 | $variables{'service-common-defaults'}, | ||
523 | 507 | $variables{'zoneedit-service-common-defaults'}, | ||
524 | 508 | ), | ||
525 | 509 | }, | ||
526 | 510 | 'easydns' => { | ||
527 | 511 | 'updateable' => undef, | ||
528 | 512 | 'update' => \&nic_easydns_update, | ||
529 | 513 | 'examples' => \&nic_easydns_examples, | ||
530 | 514 | 'variables' => merge( | ||
531 | 515 | { 'server' => setv(T_FQDNP, 1, 0, 1, 'members.easydns.com', undef) }, | ||
532 | 516 | { 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0),}, | ||
533 | 517 | $variables{'easydns-common-defaults'}, | ||
534 | 518 | $variables{'service-common-defaults'}, | ||
535 | 519 | ), | ||
536 | 520 | }, | ||
537 | 521 | 'dnspark' => { | ||
538 | 522 | 'updateable' => undef, | ||
539 | 523 | 'update' => \&nic_dnspark_update, | ||
540 | 524 | 'examples' => \&nic_dnspark_examples, | ||
541 | 525 | 'variables' => merge( | ||
542 | 526 | { 'server' => setv(T_FQDNP, 1, 0, 1, 'www.dnspark.com', undef) }, | ||
543 | 527 | { 'min-interval' => setv(T_DELAY, 0, 0, 1, interval('5m'), 0),}, | ||
544 | 528 | $variables{'dnspark-common-defaults'}, | ||
545 | 529 | $variables{'service-common-defaults'}, | ||
546 | 530 | ), | ||
547 | 531 | }, | ||
548 | 532 | 'namecheap' => { | ||
549 | 533 | 'updateable' => undef, | ||
550 | 534 | 'update' => \&nic_namecheap_update, | ||
551 | 535 | 'examples' => \&nic_namecheap_examples, | ||
552 | 536 | 'variables' => merge( | ||
553 | 537 | { 'server' => setv(T_FQDNP, 1, 0, 1, 'dynamicdns.park-your-domain.com', undef) }, | ||
554 | 538 | { 'min-interval' => setv(T_DELAY, 0, 0, 1, 0, interval('5m')),}, | ||
555 | 539 | $variables{'service-common-defaults'}, | ||
556 | 540 | ), | ||
557 | 541 | }, | ||
558 | 542 | 'sitelutions' => { | ||
559 | 543 | 'updateable' => undef, | ||
560 | 544 | 'update' => \&nic_sitelutions_update, | ||
561 | 545 | 'examples' => \&nic_sitelutions_examples, | ||
562 | 546 | 'variables' => merge( | ||
563 | 547 | { 'server' => setv(T_FQDNP, 1, 0, 1, 'www.sitelutions.com', undef) }, | ||
564 | 548 | { 'min-interval' => setv(T_DELAY, 0, 0, 1, 0, interval('5m')),}, | ||
565 | 549 | $variables{'service-common-defaults'}, | ||
566 | 550 | ), | ||
567 | 551 | }, | ||
568 | 552 | 'freedns' => { | ||
569 | 553 | 'updateable' => undef, | ||
570 | 554 | 'update' => \&nic_freedns_update, | ||
571 | 555 | 'examples' => \&nic_freedns_examples, | ||
572 | 556 | 'variables' => merge( | ||
573 | 557 | { 'server' => setv(T_FQDNP, 1, 0, 1, 'freedns.afraid.org', undef) }, | ||
574 | 558 | { 'min-interval' => setv(T_DELAY, 0, 0, 1, 0, interval('5m')),}, | ||
575 | 559 | $variables{'service-common-defaults'}, | ||
576 | 560 | ), | ||
577 | 561 | }, | ||
578 | 562 | 'dtdns' => { | ||
579 | 563 | 'updateable' => undef, | ||
580 | 564 | 'update' => \&nic_dtdns_update, | ||
581 | 565 | 'examples' => \&nic_dtdns_examples, | ||
582 | 566 | 'variables' => merge( | ||
583 | 567 | $variables{'dtdns-common-defaults'}, | ||
584 | 568 | $variables{'service-common-defaults'}, | ||
585 | 569 | ), | ||
586 | 570 | }, | ||
587 | 571 | ); | ||
588 | 572 | $variables{'merged'} = merge($variables{'global-defaults'}, | ||
589 | 573 | $variables{'service-common-defaults'}, | ||
590 | 574 | $variables{'dyndns-common-defaults'}, | ||
591 | 575 | map { $services{$_}{'variables'} } keys %services, | ||
592 | 576 | ); | ||
593 | 577 | |||
594 | 578 | my @opt = ( | ||
595 | 579 | "usage: ${program} [options]", | ||
596 | 580 | "options are:", | ||
597 | 581 | [ "daemon", "=s", "-daemon delay : run as a daemon, specify delay as an interval." ], | ||
598 | 582 | + [ "foreground", "!", "-foreground : do not fork" ], | ||
599 | 583 | [ "proxy", "=s", "-proxy host : use 'host' as the HTTP proxy" ], | ||
600 | 584 | [ "server", "=s", "-server host : update DNS information on 'host'" ], | ||
601 | 585 | [ "protocol", "=s", "-protocol type : update protocol used" ], | ||
602 | 586 | [ "file", "=s", "-file path : load configuration information from 'path'" ], | ||
603 | 587 | [ "cache", "=s", "-cache path : record address used in 'path'" ], | ||
604 | 588 | [ "pid", "=s", "-pid path : record process id in 'path'" ], | ||
605 | 589 | "", | ||
606 | 590 | [ "use", "=s", "-use which : how the should IP address be obtained." ], | ||
607 | 591 | &ip_strategies_usage(), | ||
608 | 592 | "", | ||
609 | 593 | [ "ip", "=s", "-ip address : set the IP address to 'address'" ], | ||
610 | 594 | "", | ||
611 | 595 | [ "if", "=s", "-if interface : obtain IP address from 'interface'" ], | ||
612 | 596 | [ "if-skip", "=s", "-if-skip pattern : skip any IP addresses before 'pattern' in the output of ifconfig {if}" ], | ||
613 | 597 | "", | ||
614 | 598 | [ "web", "=s", "-web provider|url : obtain IP address from provider's IP checking page" ], | ||
615 | 599 | [ "web-skip", "=s", "-web-skip pattern : skip any IP addresses before 'pattern' on the web provider|url" ], | ||
616 | 600 | "", | ||
617 | 601 | [ "fw", "=s", "-fw address|url : obtain IP address from firewall at 'address'" ], | ||
618 | 602 | [ "fw-skip", "=s", "-fw-skip pattern : skip any IP addresses before 'pattern' on the firewall address|url" ], | ||
619 | 603 | [ "fw-login", "=s", "-fw-login login : use 'login' when getting IP from fw" ], | ||
620 | 604 | [ "fw-password", "=s", "-fw-password secret : use password 'secret' when getting IP from fw" ], | ||
621 | 605 | "", | ||
622 | 606 | [ "cmd", "=s", "-cmd program : obtain IP address from by calling {program}" ], | ||
623 | 607 | [ "cmd-skip", "=s", "-cmd-skip pattern : skip any IP addresses before 'pattern' in the output of {cmd}" ], | ||
624 | 608 | "", | ||
625 | 609 | [ "login", "=s", "-login user : login as 'user'" ], | ||
626 | 610 | [ "password", "=s", "-password secret : use password 'secret'" ], | ||
627 | 611 | [ "host", "=s", "-host host : update DNS information for 'host'" ], | ||
628 | 612 | "", | ||
629 | 613 | [ "options", "=s", "-options opt,opt : optional per-service arguments (see below)" ], | ||
630 | 614 | "", | ||
631 | 615 | [ "ssl", "!", "-{no}ssl : do updates over encrypted SSL connection" ], | ||
632 | 616 | [ "retry", "!", "-{no}retry : retry failed updates." ], | ||
633 | 617 | [ "force", "!", "-{no}force : force an update even if the update may be unnecessary" ], | ||
634 | 618 | [ "timeout", "=i", "-timeout max : wait at most 'max' seconds for the host to respond" ], | ||
635 | 619 | |||
636 | 620 | [ "syslog", "!", "-{no}syslog : log messages to syslog" ], | ||
637 | 621 | [ "facility", "=s", "-facility {type} : log messages to syslog to facility {type}" ], | ||
638 | 622 | [ "priority", "=s", "-priority {pri} : log messages to syslog with priority {pri}" ], | ||
639 | 623 | [ "mail", "=s", "-mail address : e-mail messages to {address}" ], | ||
640 | 624 | [ "mail-failure","=s", "-mail-failure address : e-mail messages for failed updates to {address}" ], | ||
641 | 625 | [ "exec", "!", "-{no}exec : do {not} execute; just show what would be done" ], | ||
642 | 626 | [ "debug", "!", "-{no}debug : print {no} debugging information" ], | ||
643 | 627 | [ "verbose", "!", "-{no}verbose : print {no} verbose information" ], | ||
644 | 628 | [ "quiet", "!", "-{no}quiet : print {no} messages for unnecessary updates" ], | ||
645 | 629 | [ "help", "", "-help : this message" ], | ||
646 | 630 | [ "postscript", "", "-postscript : script to run after updating ddclient, has new IP as param" ], | ||
647 | 631 | |||
648 | 632 | [ "query", "!", "-{no}query : print {no} ip addresses and exit" ], | ||
649 | 633 | [ "test", "!", "" ], ## hidden | ||
650 | 634 | [ "geturl", "=s", "" ], ## hidden | ||
651 | 635 | "", | ||
652 | 636 | nic_examples(), | ||
653 | 637 | "$program version $version, ", | ||
654 | 638 | " originally written by Paul Burry, paul+ddclient\@burry.ca", | ||
655 | 639 | " project now maintained on http://ddclient.sourceforge.net" | ||
656 | 640 | ); | ||
657 | 641 | |||
658 | 642 | ## process args | ||
659 | 643 | my ($opt_usage, %opt) = process_args(@opt); | ||
660 | 644 | my ($result, %config, %globals, %cache); | ||
661 | 645 | my $saved_cache = ''; | ||
662 | 646 | my %saved_opt = %opt; | ||
663 | 647 | $result = 'OK'; | ||
664 | 648 | |||
665 | 649 | test_geturl(opt('geturl')) if opt('geturl'); | ||
666 | 650 | |||
667 | 651 | ## process help option | ||
668 | 652 | if (opt('help')) { | ||
669 | 653 | *STDERR = *STDOUT; | ||
670 | 654 | usage(0); | ||
671 | 655 | } | ||
672 | 656 | |||
673 | 657 | ## read config file because 'daemon' mode may be defined there. | ||
674 | 658 | read_config(define($opt{'file'}, default('file')), \%config, \%globals); | ||
675 | 659 | init_config(); | ||
676 | 660 | test_possible_ip() if opt('query'); | ||
677 | 661 | |||
678 | 662 | if (!opt('daemon') && $programd =~ /d$/) { | ||
679 | 663 | $opt{'daemon'} = minimum('daemon'); | ||
680 | 664 | } | ||
681 | 665 | my $caught_hup = 0; | ||
682 | 666 | my $caught_term = 0; | ||
683 | 667 | my $caught_kill = 0; | ||
684 | 668 | $SIG{'HUP'} = sub { $caught_hup = 1; }; | ||
685 | 669 | $SIG{'TERM'} = sub { $caught_term = 1; }; | ||
686 | 670 | $SIG{'KILL'} = sub { $caught_kill = 1; }; | ||
687 | 671 | # don't fork() if foreground or force is on | ||
688 | 672 | if (opt('foreground') || opt('force')) { | ||
689 | 673 | ; | ||
690 | 674 | } elsif (opt('daemon')) { | ||
691 | 675 | $SIG{'CHLD'} = 'IGNORE'; | ||
692 | 676 | my $pid = fork; | ||
693 | 677 | if ($pid < 0) { | ||
694 | 678 | print STDERR "${program}: can not fork ($!)\n"; | ||
695 | 679 | exit -1; | ||
696 | 680 | } elsif ($pid) { | ||
697 | 681 | exit 0; | ||
698 | 682 | } | ||
699 | 683 | $SIG{'CHLD'} = 'DEFAULT'; | ||
700 | 684 | open(STDOUT, ">/dev/null"); | ||
701 | 685 | open(STDERR, ">/dev/null"); | ||
702 | 686 | open(STDIN, "</dev/null"); | ||
703 | 687 | } | ||
704 | 688 | |||
705 | 689 | # write out the pid file if we're daemon'ized | ||
706 | 690 | if(opt('daemon')) { | ||
707 | 691 | write_pid(); | ||
708 | 692 | $opt{'syslog'} = 1; | ||
709 | 693 | } | ||
710 | 694 | |||
711 | 695 | umask 077; | ||
712 | 696 | my $daemon; | ||
713 | 697 | do { | ||
714 | 698 | $now = time; | ||
715 | 699 | $result = 'OK'; | ||
716 | 700 | %opt = %saved_opt; | ||
717 | 701 | if (opt('help')) { | ||
718 | 702 | *STDERR = *STDOUT; | ||
719 | 703 | printf("Help found"); | ||
720 | 704 | # usage(); | ||
721 | 705 | } | ||
722 | 706 | |||
723 | 707 | read_config(define($opt{'file'}, default('file')), \%config, \%globals); | ||
724 | 708 | init_config(); | ||
725 | 709 | read_cache(opt('cache'), \%cache); | ||
726 | 710 | print_info() if opt('debug') && opt('verbose'); | ||
727 | 711 | |||
728 | 712 | # usage("invalid argument '-use %s'; possible values are:\n\t%s", $opt{'use'}, join("\n\t,",sort keys %ip_strategies)) | ||
729 | 713 | usage("invalid argument '-use %s'; possible values are:\n%s", $opt{'use'}, join("\n",ip_strategies_usage())) | ||
730 | 714 | unless exists $ip_strategies{lc opt('use')}; | ||
731 | 715 | |||
732 | 716 | $daemon = $opt{'daemon'}; | ||
733 | 717 | $daemon = 0 if opt('force'); | ||
734 | 718 | |||
735 | 719 | update_nics(); | ||
736 | 720 | |||
737 | 721 | if ($daemon) { | ||
738 | 722 | debug("sleep %s", $daemon); | ||
739 | 723 | sendmail(); | ||
740 | 724 | |||
741 | 725 | my $left = $daemon; | ||
742 | 726 | while (($left > 0) && !$caught_hup && !$caught_term && !$caught_kill) { | ||
743 | 727 | my $delay = $left > 10 ? 10 : $left; | ||
744 | 728 | |||
745 | 729 | $0 = sprintf("%s - sleeping for %s seconds", $program, $left); | ||
746 | 730 | $left -= sleep $delay; | ||
747 | 731 | } | ||
748 | 732 | $caught_hup = 0; | ||
749 | 733 | $result = 0; | ||
750 | 734 | |||
751 | 735 | } elsif (! scalar(%config)) { | ||
752 | 736 | warning("no hosts to update.") unless !opt('quiet') || opt('verbose') || !$daemon; | ||
753 | 737 | $result = 1; | ||
754 | 738 | |||
755 | 739 | } else { | ||
756 | 740 | $result = $result eq 'OK' ? 0 : 1; | ||
757 | 741 | } | ||
758 | 742 | } while ($daemon && !$result && !$caught_term && !$caught_kill); | ||
759 | 743 | |||
760 | 744 | warning("caught SIGKILL; exiting") if $caught_kill; | ||
761 | 745 | unlink_pid(); | ||
762 | 746 | sendmail(); | ||
763 | 747 | |||
764 | 748 | exit($result); | ||
765 | 749 | |||
766 | 750 | ###################################################################### | ||
767 | 751 | ## runpostscript | ||
768 | 752 | ###################################################################### | ||
769 | 753 | |||
770 | 754 | sub runpostscript { | ||
771 | 755 | my ($ip) = @_; | ||
772 | 756 | |||
773 | 757 | if ( defined $globals{postscript} ) { | ||
774 | 758 | if ( -x $globals{postscript}) { | ||
775 | 759 | system ("$globals{postscript} $ip &"); | ||
776 | 760 | } else { | ||
777 | 761 | warning ("Can not execute post script: %s", $globals{postscript}); | ||
778 | 762 | } | ||
779 | 763 | } | ||
780 | 764 | } | ||
781 | 765 | |||
782 | 766 | ###################################################################### | ||
783 | 767 | ## update_nics | ||
784 | 768 | ###################################################################### | ||
785 | 769 | sub update_nics { | ||
786 | 770 | my %examined = (); | ||
787 | 771 | my %iplist = (); | ||
788 | 772 | |||
789 | 773 | foreach my $s (sort keys %services) { | ||
790 | 774 | my (@hosts, %ips) = (); | ||
791 | 775 | my $updateable = $services{$s}{'updateable'}; | ||
792 | 776 | my $update = $services{$s}{'update'}; | ||
793 | 777 | |||
794 | 778 | foreach my $h (sort keys %config) { | ||
795 | 779 | next if $config{$h}{'protocol'} ne lc($s); | ||
796 | 780 | $examined{$h} = 1; | ||
797 | 781 | my $use = $config{$h}{'use'} || opt('use'); | ||
798 | 782 | local $opt{$use} = $config{$h}{$use} if $config{$h}{$use}; | ||
799 | 783 | # bug #13: we should only do this once | ||
800 | 784 | # use isn't enough, we have to save the origin to. | ||
801 | 785 | # this will break the multiple ip stuff if use has | ||
802 | 786 | # been used twice for the same device. | ||
803 | 787 | my $ip = ""; | ||
804 | 788 | if (defined $iplist{$use}) { | ||
805 | 789 | $ip = $iplist{$use}; | ||
806 | 790 | } else { | ||
807 | 791 | $ip = get_ip($use, $h); | ||
808 | 792 | if (!defined $ip || !$ip) { | ||
809 | 793 | warning("unable to determine IP address") | ||
810 | 794 | if !$daemon || opt('verbose'); | ||
811 | 795 | next; | ||
812 | 796 | } | ||
813 | 797 | if ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { | ||
814 | 798 | warning("malformed IP address (%s)", $ip); | ||
815 | 799 | next; | ||
816 | 800 | } | ||
817 | 801 | $iplist{$use} = $ip; | ||
818 | 802 | } | ||
819 | 803 | $config{$h}{'wantip'} = $ip; | ||
820 | 804 | next if !nic_updateable($h, $updateable); | ||
821 | 805 | push @hosts, $h; | ||
822 | 806 | $ips{$ip} = $h; | ||
823 | 807 | } | ||
824 | 808 | if (@hosts) { | ||
825 | 809 | $0 = sprintf("%s - updating %s", $program, join(',', @hosts)); | ||
826 | 810 | &$update(@hosts); | ||
827 | 811 | runpostscript(join ' ', keys %ips); | ||
828 | 812 | } | ||
829 | 813 | } | ||
830 | 814 | foreach my $h (sort keys %config) { | ||
831 | 815 | if (!exists $examined{$h}) { | ||
832 | 816 | failed("%s was not updated because protocol %s is not supported.", | ||
833 | 817 | $h, define($config{$h}{'protocol'}, '<undefined>') | ||
834 | 818 | ); | ||
835 | 819 | } | ||
836 | 820 | } | ||
837 | 821 | write_cache(opt('cache')); | ||
838 | 822 | } | ||
839 | 823 | ###################################################################### | ||
840 | 824 | ## unlink_pid() | ||
841 | 825 | ###################################################################### | ||
842 | 826 | sub unlink_pid { | ||
843 | 827 | if (opt('pid') && opt('daemon')) { | ||
844 | 828 | unlink opt('pid'); | ||
845 | 829 | } | ||
846 | 830 | } | ||
847 | 831 | |||
848 | 832 | ###################################################################### | ||
849 | 833 | ## write_pid() | ||
850 | 834 | ###################################################################### | ||
851 | 835 | sub write_pid { | ||
852 | 836 | my $file = opt('pid'); | ||
853 | 837 | |||
854 | 838 | if ($file && opt('daemon')) { | ||
855 | 839 | local *FD; | ||
856 | 840 | if (! open(FD, "> $file")) { | ||
857 | 841 | warning("Cannot create file '%s'. ($!)", $file); | ||
858 | 842 | |||
859 | 843 | } else { | ||
860 | 844 | printf FD "$$\n"; | ||
861 | 845 | close(FD); | ||
862 | 846 | } | ||
863 | 847 | } | ||
864 | 848 | } | ||
865 | 849 | |||
866 | 850 | ###################################################################### | ||
867 | 851 | ## write_cache($file) | ||
868 | 852 | ###################################################################### | ||
869 | 853 | sub write_cache { | ||
870 | 854 | my ($file) = @_; | ||
871 | 855 | |||
872 | 856 | ## merge the updated host entries into the cache. | ||
873 | 857 | foreach my $h (keys %config) { | ||
874 | 858 | if (! exists $cache{$h} || $config{$h}{'update'}) { | ||
875 | 859 | map {$cache{$h}{$_} = $config{$h}{$_} } @{$config{$h}{'cacheable'}}; | ||
876 | 860 | |||
877 | 861 | } else { | ||
878 | 862 | map {$cache{$h}{$_} = $config{$h}{$_} } qw(atime wtime status); | ||
879 | 863 | } | ||
880 | 864 | } | ||
881 | 865 | |||
882 | 866 | ## construct the cache file. | ||
883 | 867 | my $cache = ""; | ||
884 | 868 | foreach my $h (sort keys %cache) { | ||
885 | 869 | my $opt = join(',', map { "$_=".define($cache{$h}{$_},'') } sort keys %{$cache{$h}}); | ||
886 | 870 | |||
887 | 871 | $cache .= sprintf "%s%s%s\n", $opt, ($opt ? ' ' : ''), $h; | ||
888 | 872 | } | ||
889 | 873 | $file = '' if defined($saved_cache) && $cache eq $saved_cache; | ||
890 | 874 | |||
891 | 875 | ## write the updates and other entries to the cache file. | ||
892 | 876 | if ($file) { | ||
893 | 877 | $saved_cache = undef; | ||
894 | 878 | local *FD; | ||
895 | 879 | if (! open(FD, "> $file")) { | ||
896 | 880 | fatal("Cannot create file '%s'. ($!)", $file); | ||
897 | 881 | } | ||
898 | 882 | printf FD "## $program-$version\n"; | ||
899 | 883 | printf FD "## last updated at %s (%d)\n", prettytime($now), $now; | ||
900 | 884 | printf FD $cache; | ||
901 | 885 | |||
902 | 886 | close(FD); | ||
903 | 887 | } | ||
904 | 888 | } | ||
905 | 889 | ###################################################################### | ||
906 | 890 | ## read_cache($file) - called before reading the .conf | ||
907 | 891 | ###################################################################### | ||
908 | 892 | sub read_cache { | ||
909 | 893 | my $file = shift; | ||
910 | 894 | my $config = shift; | ||
911 | 895 | my $globals = {}; | ||
912 | 896 | |||
913 | 897 | %{$config} = (); | ||
914 | 898 | ## read the cache file ignoring anything on the command-line. | ||
915 | 899 | if (-e $file) { | ||
916 | 900 | my %saved = %opt; | ||
917 | 901 | %opt = (); | ||
918 | 902 | $saved_cache = _read_config($config, $globals, "##\\s*$program-$version\\s*", $file); | ||
919 | 903 | %opt = %saved; | ||
920 | 904 | |||
921 | 905 | foreach my $h (keys %cache) { | ||
922 | 906 | if (exists $config->{$h}) { | ||
923 | 907 | foreach (qw(atime mtime wtime ip status)) { | ||
924 | 908 | $config->{$h}{$_} = $cache{$h}{$_} if exists $cache{$h}{$_}; | ||
925 | 909 | } | ||
926 | 910 | } | ||
927 | 911 | } | ||
928 | 912 | } | ||
929 | 913 | } | ||
930 | 914 | ###################################################################### | ||
931 | 915 | ## parse_assignments(string) return (rest, %variables) | ||
932 | 916 | ## parse_assignment(string) return (name, value, rest) | ||
933 | 917 | ###################################################################### | ||
934 | 918 | sub parse_assignments { | ||
935 | 919 | my $rest = shift; | ||
936 | 920 | my @args = @_; | ||
937 | 921 | my %variables = (); | ||
938 | 922 | my ($name, $value); | ||
939 | 923 | |||
940 | 924 | while (1) { | ||
941 | 925 | $rest =~ s/^\s+//; | ||
942 | 926 | ($name, $value, $rest) = parse_assignment($rest, @args); | ||
943 | 927 | if (defined $name) { | ||
944 | 928 | $variables{$name} = $value; | ||
945 | 929 | } else { | ||
946 | 930 | last; | ||
947 | 931 | } | ||
948 | 932 | } | ||
949 | 933 | return ($rest, %variables); | ||
950 | 934 | } | ||
951 | 935 | sub parse_assignment { | ||
952 | 936 | my $rest = shift; | ||
953 | 937 | my $stop = @_ ? shift : '[\n\s,]'; | ||
954 | 938 | my ($c, $name, $value); | ||
955 | 939 | my ($escape, $quote) = (0, ''); | ||
956 | 940 | |||
957 | 941 | if ($rest =~ /^\s*([a-z][a-z_-]*)=(.*)/i) { | ||
958 | 942 | ($name, $rest, $value) = ($1, $2, ''); | ||
959 | 943 | |||
960 | 944 | while (length($c = substr($rest,0,1))) { | ||
961 | 945 | $rest = substr($rest,1); | ||
962 | 946 | if ($escape) { | ||
963 | 947 | $value .= $c; | ||
964 | 948 | $escape = 0; | ||
965 | 949 | } elsif ($c eq "\\") { | ||
966 | 950 | $escape = 1; | ||
967 | 951 | } elsif ($quote && $c eq $quote) { | ||
968 | 952 | $quote = '' | ||
969 | 953 | } elsif (!$quote && $c =~ /[\'\"]/) { | ||
970 | 954 | $quote = $c; | ||
971 | 955 | } elsif (!$quote && $c =~ /^${stop}/) { | ||
972 | 956 | last; | ||
973 | 957 | } else { | ||
974 | 958 | $value .= $c; | ||
975 | 959 | } | ||
976 | 960 | } | ||
977 | 961 | } | ||
978 | 962 | warning("assignment ended with an open quote") if $quote; | ||
979 | 963 | return ($name, $value, $rest); | ||
980 | 964 | } | ||
981 | 965 | ###################################################################### | ||
982 | 966 | ## read_config | ||
983 | 967 | ###################################################################### | ||
984 | 968 | sub read_config { | ||
985 | 969 | my $file = shift; | ||
986 | 970 | my $config = shift; | ||
987 | 971 | my $globals = shift; | ||
988 | 972 | my %globals = (); | ||
989 | 973 | |||
990 | 974 | _read_config($config, $globals, '', $file, %globals); | ||
991 | 975 | } | ||
992 | 976 | sub _read_config { | ||
993 | 977 | my $config = shift; | ||
994 | 978 | my $globals = shift; | ||
995 | 979 | my $stamp = shift; | ||
996 | 980 | local $file = shift; | ||
997 | 981 | my %globals = @_; | ||
998 | 982 | my %config = (); | ||
999 | 983 | my $content = ''; | ||
1000 | 984 | |||
1001 | 985 | local *FD; | ||
1002 | 986 | if (! open(FD, "< $file")) { | ||
1003 | 987 | # fatal("Cannot open file '%s'. ($!)", $file); | ||
1004 | 988 | warning("Cannot open file '%s'. ($!)", $file); | ||
1005 | 989 | } | ||
1006 | 990 | # Check for only owner has any access to config file | ||
1007 | 991 | my ($dev, $ino, $mode, @statrest) = stat(FD); | ||
1008 | 992 | if ($mode & 077) { | ||
1009 | 993 | if (-f FD && (chmod 0600, $file)) { | ||
1010 | 994 | warning("file $file must be accessible only by its owner (fixed)."); | ||
1011 | 995 | } else { | ||
1012 | 996 | # fatal("file $file must be accessible only by its owner."); | ||
1013 | 997 | warning("file $file must be accessible only by its owner."); | ||
1014 | 998 | } | ||
1015 | 999 | } | ||
1016 | 1000 | |||
1017 | 1001 | local $lineno = 0; | ||
1018 | 1002 | my $continuation = ''; | ||
1019 | 1003 | my %passwords = (); | ||
1020 | 1004 | while (<FD>) { | ||
1021 | 1005 | s/[\r\n]//g; | ||
1022 | 1006 | |||
1023 | 1007 | $lineno++; | ||
1024 | 1008 | |||
1025 | 1009 | ## check for the program version stamp | ||
1026 | 1010 | if (($. == 1) && $stamp && ($_ !~ /^$stamp$/i)) { | ||
1027 | 1011 | warning("program version mismatch; ignoring %s", $file); | ||
1028 | 1012 | last; | ||
1029 | 1013 | } | ||
1030 | 1014 | if (/\\\s+$/) { | ||
1031 | 1015 | warning("whitespace follows the \\ at the end-of-line.\nIf you meant to have a line continuation, remove the trailing whitespace."); | ||
1032 | 1016 | } | ||
1033 | 1017 | |||
1034 | 1018 | $content .= "$_\n" unless /^#/; | ||
1035 | 1019 | |||
1036 | 1020 | ## parsing passwords is special | ||
1037 | 1021 | if (/^([^#]*\s)?([^#]*?password\S*?)\s*=\s*('.*'|[^']\S*)(.*)/) { | ||
1038 | 1022 | my ($head, $key, $value, $tail) = ($1 || '', $2, $3, $4); | ||
1039 | 1023 | $value = $1 if $value =~ /^'(.*)'$/; | ||
1040 | 1024 | $passwords{$key} = $value; | ||
1041 | 1025 | $_ = "${head}${key}=dummy${tail}"; | ||
1042 | 1026 | } | ||
1043 | 1027 | |||
1044 | 1028 | ## remove comments | ||
1045 | 1029 | s/#.*//; | ||
1046 | 1030 | |||
1047 | 1031 | ## handle continuation lines | ||
1048 | 1032 | $_ = "$continuation$_"; | ||
1049 | 1033 | if (/\\$/) { | ||
1050 | 1034 | chop; | ||
1051 | 1035 | $continuation = $_; | ||
1052 | 1036 | next; | ||
1053 | 1037 | } | ||
1054 | 1038 | $continuation = ''; | ||
1055 | 1039 | |||
1056 | 1040 | s/^\s+//; # remove leading white space | ||
1057 | 1041 | s/\s+$//; # remove trailing white space | ||
1058 | 1042 | s/\s+/ /g; # canonify | ||
1059 | 1043 | next if /^$/; | ||
1060 | 1044 | |||
1061 | 1045 | ## expected configuration line is: | ||
1062 | 1046 | ## [opt=value,opt=..] [host [login [password]]] | ||
1063 | 1047 | my %locals; | ||
1064 | 1048 | ($_, %locals) = parse_assignments($_); | ||
1065 | 1049 | s/\s*,\s*/,/g; | ||
1066 | 1050 | my @args = split; | ||
1067 | 1051 | |||
1068 | 1052 | ## verify that keywords are valid...and check the value | ||
1069 | 1053 | foreach my $k (keys %locals) { | ||
1070 | 1054 | $locals{$k} = $passwords{$k} if defined $passwords{$k}; | ||
1071 | 1055 | if (!exists $variables{'merged'}{$k}) { | ||
1072 | 1056 | warning("unrecognized keyword '%s' (ignored)", $k); | ||
1073 | 1057 | delete $locals{$k}; | ||
1074 | 1058 | } else { | ||
1075 | 1059 | my $def = $variables{'merged'}{$k}; | ||
1076 | 1060 | my $value = check_value($locals{$k}, $def); | ||
1077 | 1061 | if (!defined($value)) { | ||
1078 | 1062 | warning("Invalid Value for keyword '%s' = '%s'", $k, $locals{$k}); | ||
1079 | 1063 | delete $locals{$k}; | ||
1080 | 1064 | } else { $locals{$k} = $value; } | ||
1081 | 1065 | } | ||
1082 | 1066 | } | ||
1083 | 1067 | if (exists($locals{'host'})) { | ||
1084 | 1068 | $args[0] = @args ? "$args[0],$locals{host}" : "$locals{host}"; | ||
1085 | 1069 | } | ||
1086 | 1070 | ## accumulate globals | ||
1087 | 1071 | if ($#args < 0) { | ||
1088 | 1072 | map { $globals{$_} = $locals{$_} } keys %locals; | ||
1089 | 1073 | } | ||
1090 | 1074 | |||
1091 | 1075 | ## process this host definition | ||
1092 | 1076 | if (@args) { | ||
1093 | 1077 | my ($host, $login, $password) = @args; | ||
1094 | 1078 | |||
1095 | 1079 | ## add in any globals.. | ||
1096 | 1080 | %locals = %{ merge(\%locals, \%globals) }; | ||
1097 | 1081 | |||
1098 | 1082 | ## override login and password if specified the old way. | ||
1099 | 1083 | $locals{'login'} = $login if defined $login; | ||
1100 | 1084 | $locals{'password'} = $password if defined $password; | ||
1101 | 1085 | |||
1102 | 1086 | ## allow {host} to be a comma separated list of hosts | ||
1103 | 1087 | foreach my $h (split_by_comma($host)) { | ||
1104 | 1088 | ## save a copy of the current globals | ||
1105 | 1089 | $config{$h} = { %locals }; | ||
1106 | 1090 | $config{$h}{'host'} = $h; | ||
1107 | 1091 | } | ||
1108 | 1092 | } | ||
1109 | 1093 | %passwords = (); | ||
1110 | 1094 | } | ||
1111 | 1095 | close(FD); | ||
1112 | 1096 | |||
1113 | 1097 | warning("file ends while expecting a continuation line.") | ||
1114 | 1098 | if $continuation; | ||
1115 | 1099 | |||
1116 | 1100 | %$globals = %globals; | ||
1117 | 1101 | %$config = %config; | ||
1118 | 1102 | |||
1119 | 1103 | return $content; | ||
1120 | 1104 | } | ||
1121 | 1105 | ###################################################################### | ||
1122 | 1106 | ## init_config - | ||
1123 | 1107 | ###################################################################### | ||
1124 | 1108 | sub init_config { | ||
1125 | 1109 | %opt = %saved_opt; | ||
1126 | 1110 | |||
1127 | 1111 | ## | ||
1128 | 1112 | $opt{'quiet'} = 0 if opt('verbose'); | ||
1129 | 1113 | |||
1130 | 1114 | ## infer the IP strategy if possible | ||
1131 | 1115 | $opt{'use'} = 'ip' if !define($opt{'use'}) && defined($opt{'ip'}); | ||
1132 | 1116 | $opt{'use'} = 'if' if !define($opt{'use'}) && defined($opt{'if'}); | ||
1133 | 1117 | $opt{'use'} = 'web' if !define($opt{'use'}) && defined($opt{'web'}); | ||
1134 | 1118 | |||
1135 | 1119 | ## sanity check | ||
1136 | 1120 | $opt{'max-interval'} = min(interval(opt('max-interval')), interval(default('max-interval'))); | ||
1137 | 1121 | $opt{'min-interval'} = max(interval(opt('min-interval')), interval(default('min-interval'))); | ||
1138 | 1122 | $opt{'min-error-interval'} = max(interval(opt('min-error-interval')), interval(default('min-error-interval'))); | ||
1139 | 1123 | |||
1140 | 1124 | $opt{'timeout'} = 0 if opt('timeout') < 0; | ||
1141 | 1125 | |||
1142 | 1126 | ## only set $opt{'daemon'} if it has been explicitly passed in | ||
1143 | 1127 | if (define($opt{'daemon'},$globals{'daemon'},0)) { | ||
1144 | 1128 | $opt{'daemon'} = interval(opt('daemon')); | ||
1145 | 1129 | $opt{'daemon'} = minimum('daemon') | ||
1146 | 1130 | if ($opt{'daemon'} < minimum('daemon')); | ||
1147 | 1131 | } | ||
1148 | 1132 | |||
1149 | 1133 | ## define or modify host options specified on the command-line | ||
1150 | 1134 | if (exists $opt{'options'} && defined $opt{'options'}) { | ||
1151 | 1135 | ## collect cmdline configuration options. | ||
1152 | 1136 | my %options = (); | ||
1153 | 1137 | foreach my $opt (split_by_comma($opt{'options'})) { | ||
1154 | 1138 | my ($name,$var) = split /\s*=\s*/, $opt; | ||
1155 | 1139 | $options{$name} = $var; | ||
1156 | 1140 | } | ||
1157 | 1141 | ## determine hosts specified with -host | ||
1158 | 1142 | my @hosts = (); | ||
1159 | 1143 | if (exists $opt{'host'}) { | ||
1160 | 1144 | foreach my $h (split_by_comma($opt{'host'})) { | ||
1161 | 1145 | push @hosts, $h; | ||
1162 | 1146 | } | ||
1163 | 1147 | } | ||
1164 | 1148 | ## and those in -options=... | ||
1165 | 1149 | if (exists $options{'host'}) { | ||
1166 | 1150 | foreach my $h (split_by_comma($options{'host'})) { | ||
1167 | 1151 | push @hosts, $h; | ||
1168 | 1152 | } | ||
1169 | 1153 | delete $options{'host'}; | ||
1170 | 1154 | } | ||
1171 | 1155 | ## merge options into host definitions or globals | ||
1172 | 1156 | if (@hosts) { | ||
1173 | 1157 | foreach my $h (@hosts) { | ||
1174 | 1158 | $config{$h} = merge(\%options, $config{$h}); | ||
1175 | 1159 | } | ||
1176 | 1160 | $opt{'host'} = join(',', @hosts); | ||
1177 | 1161 | } else { | ||
1178 | 1162 | %globals = %{ merge(\%options, \%globals) }; | ||
1179 | 1163 | } | ||
1180 | 1164 | } | ||
1181 | 1165 | |||
1182 | 1166 | ## override global options with those on the command-line. | ||
1183 | 1167 | foreach my $o (keys %opt) { | ||
1184 | 1168 | if (defined $opt{$o} && exists $variables{'global-defaults'}{$o}) { | ||
1185 | 1169 | $globals{$o} = $opt{$o}; | ||
1186 | 1170 | } | ||
1187 | 1171 | } | ||
1188 | 1172 | |||
1189 | 1173 | ## sanity check | ||
1190 | 1174 | if (defined $opt{'host'} && defined $opt{'retry'}) { | ||
1191 | 1175 | usage("options -retry and -host (or -option host=..) are mutually exclusive"); | ||
1192 | 1176 | } | ||
1193 | 1177 | |||
1194 | 1178 | ## determine hosts to update (those on the cmd-line, config-file, or failed cached) | ||
1195 | 1179 | my @hosts = keys %config; | ||
1196 | 1180 | if (opt('host')) { | ||
1197 | 1181 | @hosts = split_by_comma($opt{'host'}); | ||
1198 | 1182 | } | ||
1199 | 1183 | if (opt('retry')) { | ||
1200 | 1184 | @hosts = map { $_ if $cache{$_}{'status'} ne 'good' } keys %cache; | ||
1201 | 1185 | } | ||
1202 | 1186 | |||
1203 | 1187 | ## remove any other hosts | ||
1204 | 1188 | my %hosts; | ||
1205 | 1189 | map { $hosts{$_} = undef } @hosts; | ||
1206 | 1190 | map { delete $config{$_} unless exists $hosts{$_} } keys %config; | ||
1207 | 1191 | |||
1208 | 1192 | ## collect the cacheable variables. | ||
1209 | 1193 | foreach my $proto (keys %services) { | ||
1210 | 1194 | my @cacheable = (); | ||
1211 | 1195 | foreach my $k (keys %{$services{$proto}{'variables'}}) { | ||
1212 | 1196 | push @cacheable, $k if $services{$proto}{'variables'}{$k}{'cache'}; | ||
1213 | 1197 | } | ||
1214 | 1198 | $services{$proto}{'cacheable'} = [ @cacheable ]; | ||
1215 | 1199 | } | ||
1216 | 1200 | |||
1217 | 1201 | ## sanity check.. | ||
1218 | 1202 | ## make sure config entries have all defaults and they meet minimums | ||
1219 | 1203 | ## first the globals... | ||
1220 | 1204 | foreach my $k (keys %globals) { | ||
1221 | 1205 | my $def = $variables{'merged'}{$k}; | ||
1222 | 1206 | my $ovalue = define($globals{$k}, $def->{'default'}); | ||
1223 | 1207 | my $value = check_value($ovalue, $def); | ||
1224 | 1208 | if ($def->{'required'} && !defined $value) { | ||
1225 | 1209 | $value = default($k); | ||
1226 | 1210 | warning("'%s=%s' is an invalid %s. (using default of %s)", $k, $ovalue, $def->{'type'}, $value); | ||
1227 | 1211 | } | ||
1228 | 1212 | $globals{$k} = $value; | ||
1229 | 1213 | } | ||
1230 | 1214 | |||
1231 | 1215 | ## now the host definitions... | ||
1232 | 1216 | HOST: | ||
1233 | 1217 | foreach my $h (keys %config) { | ||
1234 | 1218 | my $proto; | ||
1235 | 1219 | $proto = $config{$h}{'protocol'}; | ||
1236 | 1220 | $proto = opt('protocol') if !defined($proto); | ||
1237 | 1221 | |||
1238 | 1222 | load_sha1_support() if ($proto eq "freedns"); | ||
1239 | 1223 | |||
1240 | 1224 | if (!exists($services{$proto})) { | ||
1241 | 1225 | warning("skipping host: %s: unrecognized protocol '%s'", $h, $proto); | ||
1242 | 1226 | delete $config{$h}; | ||
1243 | 1227 | |||
1244 | 1228 | } else { | ||
1245 | 1229 | my $svars = $services{$proto}{'variables'}; | ||
1246 | 1230 | my $conf = { 'protocol' => $proto }; | ||
1247 | 1231 | |||
1248 | 1232 | foreach my $k (keys %$svars) { | ||
1249 | 1233 | my $def = $svars->{$k}; | ||
1250 | 1234 | my $ovalue = define($config{$h}{$k}, $def->{'default'}); | ||
1251 | 1235 | my $value = check_value($ovalue, $def); | ||
1252 | 1236 | if ($def->{'required'} && !defined $value) { | ||
1253 | 1237 | warning("skipping host: %s: '%s=%s' is an invalid %s.", $h, $k, $ovalue, $def->{'type'}); | ||
1254 | 1238 | delete $config{$h}; | ||
1255 | 1239 | next HOST; | ||
1256 | 1240 | } | ||
1257 | 1241 | $conf->{$k} = $value; | ||
1258 | 1242 | |||
1259 | 1243 | } | ||
1260 | 1244 | $config{$h} = $conf; | ||
1261 | 1245 | $config{$h}{'cacheable'} = [ @{$services{$proto}{'cacheable'}} ]; | ||
1262 | 1246 | } | ||
1263 | 1247 | } | ||
1264 | 1248 | } | ||
1265 | 1249 | |||
1266 | 1250 | ###################################################################### | ||
1267 | 1251 | ## usage | ||
1268 | 1252 | ###################################################################### | ||
1269 | 1253 | sub usage { | ||
1270 | 1254 | my $exitcode = 1; | ||
1271 | 1255 | $exitcode = shift if @_ != 0; # use first arg if given | ||
1272 | 1256 | my $msg = ''; | ||
1273 | 1257 | if (@_) { | ||
1274 | 1258 | my $format = shift; | ||
1275 | 1259 | $msg .= sprintf $format, @_; | ||
1276 | 1260 | 1 while chomp($msg); | ||
1277 | 1261 | $msg .= "\n"; | ||
1278 | 1262 | } | ||
1279 | 1263 | printf STDERR "%s%s\n", $msg, $opt_usage; | ||
1280 | 1264 | sendmail(); | ||
1281 | 1265 | exit $exitcode; | ||
1282 | 1266 | } | ||
1283 | 1267 | |||
1284 | 1268 | ###################################################################### | ||
1285 | 1269 | ## process_args - | ||
1286 | 1270 | ###################################################################### | ||
1287 | 1271 | sub process_args { | ||
1288 | 1272 | my @spec = (); | ||
1289 | 1273 | my $usage = ""; | ||
1290 | 1274 | my %opts = (); | ||
1291 | 1275 | |||
1292 | 1276 | foreach (@_) { | ||
1293 | 1277 | if (ref $_) { | ||
1294 | 1278 | my ($key, $specifier, $arg_usage) = @$_; | ||
1295 | 1279 | my $value = default($key); | ||
1296 | 1280 | |||
1297 | 1281 | ## add a option specifier | ||
1298 | 1282 | push @spec, $key . $specifier; | ||
1299 | 1283 | |||
1300 | 1284 | ## define the default value which can be overwritten later | ||
1301 | 1285 | $opt{$key} = undef; | ||
1302 | 1286 | |||
1303 | 1287 | next unless $arg_usage; | ||
1304 | 1288 | |||
1305 | 1289 | ## add a line to the usage; | ||
1306 | 1290 | $usage .= " $arg_usage"; | ||
1307 | 1291 | if (defined($value) && $value ne '') { | ||
1308 | 1292 | $usage .= " (default: "; | ||
1309 | 1293 | if ($specifier eq '!') { | ||
1310 | 1294 | $usage .= "no" if ($specifier eq '!') && !$value; | ||
1311 | 1295 | $usage .= $key; | ||
1312 | 1296 | } else { | ||
1313 | 1297 | $usage .= $value; | ||
1314 | 1298 | } | ||
1315 | 1299 | $usage .= ")"; | ||
1316 | 1300 | } | ||
1317 | 1301 | $usage .= "."; | ||
1318 | 1302 | } else { | ||
1319 | 1303 | $usage .= $_; | ||
1320 | 1304 | } | ||
1321 | 1305 | $usage .= "\n"; | ||
1322 | 1306 | } | ||
1323 | 1307 | ## process the arguments | ||
1324 | 1308 | if (! GetOptions(\%opt, @spec)) { | ||
1325 | 1309 | $opt{"help"} = 1; | ||
1326 | 1310 | } | ||
1327 | 1311 | return ($usage, %opt); | ||
1328 | 1312 | } | ||
1329 | 1313 | ###################################################################### | ||
1330 | 1314 | ## test_possible_ip - print possible IPs | ||
1331 | 1315 | ###################################################################### | ||
1332 | 1316 | sub test_possible_ip { | ||
1333 | 1317 | local $opt{'debug'} = 0; | ||
1334 | 1318 | |||
1335 | 1319 | printf "use=ip, ip=%s address is %s\n", opt('ip'), define(get_ip('ip'), 'NOT FOUND') | ||
1336 | 1320 | if defined opt('ip'); | ||
1337 | 1321 | |||
1338 | 1322 | { | ||
1339 | 1323 | local $opt{'use'} = 'if'; | ||
1340 | 1324 | foreach my $if (grep {/^[a-zA-Z]/} `ifconfig -a`) { | ||
1341 | 1325 | $if =~ s/:?\s.*//is; | ||
1342 | 1326 | local $opt{'if'} = $if; | ||
1343 | 1327 | printf "use=if, if=%s address is %s\n", opt('if'), define(get_ip('if'), 'NOT FOUND'); | ||
1344 | 1328 | } | ||
1345 | 1329 | } | ||
1346 | 1330 | if (opt('fw')) { | ||
1347 | 1331 | if (opt('fw') !~ m%/%) { | ||
1348 | 1332 | foreach my $fw (sort keys %builtinfw) { | ||
1349 | 1333 | local $opt{'use'} = $fw; | ||
1350 | 1334 | printf "use=$fw address is %s\n", define(get_ip($fw), 'NOT FOUND'); | ||
1351 | 1335 | } | ||
1352 | 1336 | } | ||
1353 | 1337 | local $opt{'use'} = 'fw'; | ||
1354 | 1338 | printf "use=fw, fw=%s address is %s\n", opt('fw'), define(get_ip(opt('fw')), 'NOT FOUND') | ||
1355 | 1339 | if ! exists $builtinfw{opt('fw')}; | ||
1356 | 1340 | |||
1357 | 1341 | } | ||
1358 | 1342 | { | ||
1359 | 1343 | local $opt{'use'} = 'web'; | ||
1360 | 1344 | foreach my $web (sort keys %builtinweb) { | ||
1361 | 1345 | local $opt{'web'} = $web; | ||
1362 | 1346 | printf "use=web, web=$web address is %s\n", define(get_ip('web'), 'NOT FOUND'); | ||
1363 | 1347 | } | ||
1364 | 1348 | printf "use=web, web=%s address is %s\n", opt('web'), define(get_ip('web'), 'NOT FOUND') | ||
1365 | 1349 | if ! exists $builtinweb{opt('web')}; | ||
1366 | 1350 | } | ||
1367 | 1351 | if (opt('cmd')) { | ||
1368 | 1352 | local $opt{'use'} = 'cmd'; | ||
1369 | 1353 | printf "use=cmd, cmd=%s address is %s\n", opt('cmd'), define(get_ip('cmd'), 'NOT FOUND'); | ||
1370 | 1354 | } | ||
1371 | 1355 | exit 0 unless opt('debug'); | ||
1372 | 1356 | } | ||
1373 | 1357 | ###################################################################### | ||
1374 | 1358 | ## test_geturl - print (and save if -test) result of fetching a URL | ||
1375 | 1359 | ###################################################################### | ||
1376 | 1360 | sub test_geturl { | ||
1377 | 1361 | my $url = shift; | ||
1378 | 1362 | |||
1379 | 1363 | my $reply = geturl(opt('proxy'), $url, opt('login'), opt('password')); | ||
1380 | 1364 | print "URL $url\n";; | ||
1381 | 1365 | print defined($reply) ? $reply : "<undefined>\n"; | ||
1382 | 1366 | exit; | ||
1383 | 1367 | } | ||
1384 | 1368 | ###################################################################### | ||
1385 | 1369 | ## load_file | ||
1386 | 1370 | ###################################################################### | ||
1387 | 1371 | sub load_file { | ||
1388 | 1372 | my $file = shift; | ||
1389 | 1373 | my $buffer = ''; | ||
1390 | 1374 | |||
1391 | 1375 | if (exists($ENV{'TEST_CASE'})) { | ||
1392 | 1376 | my $try = "$file-$ENV{'TEST_CASE'}"; | ||
1393 | 1377 | $file = $try if -f $try; | ||
1394 | 1378 | } | ||
1395 | 1379 | |||
1396 | 1380 | local *FD; | ||
1397 | 1381 | if (open(FD, "< $file")) { | ||
1398 | 1382 | read(FD, $buffer, -s FD); | ||
1399 | 1383 | close(FD); | ||
1400 | 1384 | debug("Loaded %d bytes from %s", length($buffer), $file); | ||
1401 | 1385 | } else { | ||
1402 | 1386 | debug("Load failed from %s ($!)", $file); | ||
1403 | 1387 | } | ||
1404 | 1388 | return $buffer | ||
1405 | 1389 | } | ||
1406 | 1390 | ###################################################################### | ||
1407 | 1391 | ## save_file | ||
1408 | 1392 | ###################################################################### | ||
1409 | 1393 | sub save_file { | ||
1410 | 1394 | my ($file, $buffer, $opt) = @_; | ||
1411 | 1395 | |||
1412 | 1396 | $file .= "-$ENV{'TEST_CASE'}" if exists $ENV{'TEST_CASE'}; | ||
1413 | 1397 | if (defined $opt) { | ||
1414 | 1398 | my $i = 0; | ||
1415 | 1399 | while (-f "$file-$i") { | ||
1416 | 1400 | if ('unique' =~ /^$opt/i) { | ||
1417 | 1401 | my $a = join('\n', grep {!/^Date:/} split /\n/, $buffer); | ||
1418 | 1402 | my $b = join('\n', grep {!/^Date:/} split /\n/, load_file("$file-$i")); | ||
1419 | 1403 | last if $a eq $b; | ||
1420 | 1404 | } | ||
1421 | 1405 | $i++; | ||
1422 | 1406 | } | ||
1423 | 1407 | $file = "$file-$i"; | ||
1424 | 1408 | } | ||
1425 | 1409 | debug("Saving to %s", $file); | ||
1426 | 1410 | local *FD; | ||
1427 | 1411 | open(FD, "> $file") or return; | ||
1428 | 1412 | print FD $buffer; | ||
1429 | 1413 | close(FD); | ||
1430 | 1414 | return $buffer; | ||
1431 | 1415 | } | ||
1432 | 1416 | ###################################################################### | ||
1433 | 1417 | ## print_opt | ||
1434 | 1418 | ## print_globals | ||
1435 | 1419 | ## print_config | ||
1436 | 1420 | ## print_cache | ||
1437 | 1421 | ## print_info | ||
1438 | 1422 | ###################################################################### | ||
1439 | 1423 | sub _print_hash { | ||
1440 | 1424 | my ($string, $ptr) = @_; | ||
1441 | 1425 | my $value = $ptr; | ||
1442 | 1426 | |||
1443 | 1427 | if (! defined($ptr)) { | ||
1444 | 1428 | $value = "<undefined>"; | ||
1445 | 1429 | } elsif (ref $ptr eq 'HASH') { | ||
1446 | 1430 | foreach my $key (sort keys %$ptr) { | ||
1447 | 1431 | _print_hash("${string}\{$key\}", $ptr->{$key}); | ||
1448 | 1432 | } | ||
1449 | 1433 | return; | ||
1450 | 1434 | } | ||
1451 | 1435 | printf "%-36s : %s\n", $string, $value; | ||
1452 | 1436 | } | ||
1453 | 1437 | sub print_hash { | ||
1454 | 1438 | my ($string, $hash) = @_; | ||
1455 | 1439 | printf "=== %s ====\n", $string; | ||
1456 | 1440 | _print_hash($string, $hash); | ||
1457 | 1441 | } | ||
1458 | 1442 | sub print_opt { print_hash("opt", \%opt); } | ||
1459 | 1443 | sub print_globals { print_hash("globals", \%globals); } | ||
1460 | 1444 | sub print_config { print_hash("config", \%config); } | ||
1461 | 1445 | sub print_cache { print_hash("cache", \%cache); } | ||
1462 | 1446 | sub print_info { | ||
1463 | 1447 | print_opt(); | ||
1464 | 1448 | print_globals(); | ||
1465 | 1449 | print_config(); | ||
1466 | 1450 | print_cache(); | ||
1467 | 1451 | } | ||
1468 | 1452 | ###################################################################### | ||
1469 | 1453 | ## pipecmd - run an external command | ||
1470 | 1454 | ## logger | ||
1471 | 1455 | ## sendmail | ||
1472 | 1456 | ###################################################################### | ||
1473 | 1457 | sub pipecmd { | ||
1474 | 1458 | my $cmd = shift; | ||
1475 | 1459 | my $stdin = join("\n", @_); | ||
1476 | 1460 | my $ok = 0; | ||
1477 | 1461 | |||
1478 | 1462 | ## remove trailing newlines | ||
1479 | 1463 | 1 while chomp($stdin); | ||
1480 | 1464 | |||
1481 | 1465 | ## override when debugging. | ||
1482 | 1466 | $cmd = opt('exec') ? "| $cmd" : "> /dev/null"; | ||
1483 | 1467 | |||
1484 | 1468 | ## execute the command. | ||
1485 | 1469 | local *FD; | ||
1486 | 1470 | if (! open(FD, $cmd)) { | ||
1487 | 1471 | printf STDERR "$program: cannot execute command %s.\n", $cmd; | ||
1488 | 1472 | |||
1489 | 1473 | } elsif ($stdin && (! print FD "$stdin\n")) { | ||
1490 | 1474 | printf STDERR "$program: failed writting to %s.\n", $cmd; | ||
1491 | 1475 | close(FD); | ||
1492 | 1476 | |||
1493 | 1477 | } elsif (! close(FD)) { | ||
1494 | 1478 | printf STDERR "$program: failed closing %s.($@)\n", $cmd; | ||
1495 | 1479 | |||
1496 | 1480 | } elsif (opt('exec') && $?) { | ||
1497 | 1481 | printf STDERR "$program: failed %s. ($@)\n", $cmd; | ||
1498 | 1482 | |||
1499 | 1483 | } else { | ||
1500 | 1484 | $ok = 1; | ||
1501 | 1485 | } | ||
1502 | 1486 | return $ok; | ||
1503 | 1487 | } | ||
1504 | 1488 | sub logger { | ||
1505 | 1489 | if (opt('syslog') && opt('facility') && opt('priority')) { | ||
1506 | 1490 | my $facility = opt('facility'); | ||
1507 | 1491 | my $priority = opt('priority'); | ||
1508 | 1492 | return pipecmd("logger -p$facility.$priority -t${program}\[$$\]", @_); | ||
1509 | 1493 | } | ||
1510 | 1494 | return 1; | ||
1511 | 1495 | } | ||
1512 | 1496 | sub sendmail { | ||
1513 | 1497 | my $recipients = opt('mail'); | ||
1514 | 1498 | |||
1515 | 1499 | if (opt('mail-failure') && ($result ne 'OK' && $result ne '0')) { | ||
1516 | 1500 | $recipients = opt('mail-failure'); | ||
1517 | 1501 | } | ||
1518 | 1502 | if ($msgs && $recipients && $msgs ne $last_msgs) { | ||
1519 | 1503 | pipecmd("sendmail -oi $recipients", | ||
1520 | 1504 | "To: $recipients", | ||
1521 | 1505 | "Subject: status report from $program\@$hostname", | ||
1522 | 1506 | "\r\n", | ||
1523 | 1507 | $msgs, | ||
1524 | 1508 | "", | ||
1525 | 1509 | "regards,", | ||
1526 | 1510 | " $program\@$hostname (version $version)" | ||
1527 | 1511 | ); | ||
1528 | 1512 | } | ||
1529 | 1513 | $last_msgs = $msgs; | ||
1530 | 1514 | $msgs = ''; | ||
1531 | 1515 | } | ||
1532 | 1516 | ###################################################################### | ||
1533 | 1517 | ## split_by_comma | ||
1534 | 1518 | ## merge | ||
1535 | 1519 | ## default | ||
1536 | 1520 | ## minimum | ||
1537 | 1521 | ## opt | ||
1538 | 1522 | ###################################################################### | ||
1539 | 1523 | sub split_by_comma { | ||
1540 | 1524 | my $string = shift; | ||
1541 | 1525 | |||
1542 | 1526 | return split /\s*[, ]\s*/, $string if defined $string; | ||
1543 | 1527 | return (); | ||
1544 | 1528 | } | ||
1545 | 1529 | sub merge { | ||
1546 | 1530 | my %merged = (); | ||
1547 | 1531 | foreach my $h (@_) { | ||
1548 | 1532 | foreach my $k (keys %$h) { | ||
1549 | 1533 | $merged{$k} = $h->{$k} unless exists $merged{$k}; | ||
1550 | 1534 | } | ||
1551 | 1535 | } | ||
1552 | 1536 | return \%merged; | ||
1553 | 1537 | } | ||
1554 | 1538 | sub default { | ||
1555 | 1539 | my $v = shift; | ||
1556 | 1540 | return $variables{'merged'}{$v}{'default'}; | ||
1557 | 1541 | } | ||
1558 | 1542 | sub minimum { | ||
1559 | 1543 | my $v = shift; | ||
1560 | 1544 | return $variables{'merged'}{$v}{'minimum'}; | ||
1561 | 1545 | } | ||
1562 | 1546 | sub opt { | ||
1563 | 1547 | my $v = shift; | ||
1564 | 1548 | my $h = shift; | ||
1565 | 1549 | return $config{$h}{$v} if defined($h && $config{$h}{$v}); | ||
1566 | 1550 | return $opt{$v} if defined $opt{$v}; | ||
1567 | 1551 | return $globals{$v} if defined $globals{$v}; | ||
1568 | 1552 | return default($v) if defined default($v); | ||
1569 | 1553 | return undef; | ||
1570 | 1554 | } | ||
1571 | 1555 | sub min { | ||
1572 | 1556 | my $min = shift; | ||
1573 | 1557 | foreach my $arg (@_) { | ||
1574 | 1558 | $min = $arg if $arg < $min; | ||
1575 | 1559 | } | ||
1576 | 1560 | return $min; | ||
1577 | 1561 | } | ||
1578 | 1562 | sub max { | ||
1579 | 1563 | my $max = shift; | ||
1580 | 1564 | foreach my $arg (@_) { | ||
1581 | 1565 | $max = $arg if $arg > $max; | ||
1582 | 1566 | } | ||
1583 | 1567 | return $max; | ||
1584 | 1568 | } | ||
1585 | 1569 | ###################################################################### | ||
1586 | 1570 | ## define | ||
1587 | 1571 | ###################################################################### | ||
1588 | 1572 | sub define { | ||
1589 | 1573 | foreach (@_) { | ||
1590 | 1574 | return $_ if defined $_; | ||
1591 | 1575 | } | ||
1592 | 1576 | return undef; | ||
1593 | 1577 | } | ||
1594 | 1578 | ###################################################################### | ||
1595 | 1579 | ## ynu | ||
1596 | 1580 | ###################################################################### | ||
1597 | 1581 | sub ynu { | ||
1598 | 1582 | my ($value, $yes, $no, $undef) = @_; | ||
1599 | 1583 | |||
1600 | 1584 | return $no if !defined($value) || !$value; | ||
1601 | 1585 | return $yes if $value eq '1'; | ||
1602 | 1586 | foreach (qw(yes true)) { | ||
1603 | 1587 | return $yes if $_ =~ /^$value/i; | ||
1604 | 1588 | } | ||
1605 | 1589 | foreach (qw(no false)) { | ||
1606 | 1590 | return $no if $_ =~ /^$value/i; | ||
1607 | 1591 | } | ||
1608 | 1592 | return $undef; | ||
1609 | 1593 | } | ||
1610 | 1594 | ###################################################################### | ||
1611 | 1595 | ## msg | ||
1612 | 1596 | ## debug | ||
1613 | 1597 | ## warning | ||
1614 | 1598 | ## fatal | ||
1615 | 1599 | ###################################################################### | ||
1616 | 1600 | sub _msg { | ||
1617 | 1601 | my $log = shift; | ||
1618 | 1602 | my $prefix = shift; | ||
1619 | 1603 | my $format = shift; | ||
1620 | 1604 | my $buffer = sprintf $format, @_; | ||
1621 | 1605 | chomp($buffer); | ||
1622 | 1606 | |||
1623 | 1607 | $prefix = sprintf "%-9s ", $prefix if $prefix; | ||
1624 | 1608 | if ($file) { | ||
1625 | 1609 | $prefix .= "file $file"; | ||
1626 | 1610 | $prefix .= ", line $lineno" if $lineno; | ||
1627 | 1611 | $prefix .= ": "; | ||
1628 | 1612 | } | ||
1629 | 1613 | if ($prefix) { | ||
1630 | 1614 | $buffer = "$prefix$buffer"; | ||
1631 | 1615 | $buffer =~ s/\n/\n$prefix /g; | ||
1632 | 1616 | } | ||
1633 | 1617 | $buffer .= "\n"; | ||
1634 | 1618 | print $buffer; | ||
1635 | 1619 | |||
1636 | 1620 | $msgs .= $buffer if $log; | ||
1637 | 1621 | logger($buffer) if $log; | ||
1638 | 1622 | |||
1639 | 1623 | } | ||
1640 | 1624 | sub msg { _msg(0, '', @_); } | ||
1641 | 1625 | sub verbose { _msg(1, @_) if opt('verbose'); } | ||
1642 | 1626 | sub info { _msg(1, 'INFO:', @_) if opt('verbose'); } | ||
1643 | 1627 | sub debug { _msg(0, 'DEBUG:', @_) if opt('debug'); } | ||
1644 | 1628 | sub debug2 { _msg(0, 'DEBUG:', @_) if opt('debug') && opt('verbose');} | ||
1645 | 1629 | sub warning { _msg(1, 'WARNING:', @_); } | ||
1646 | 1630 | sub fatal { _msg(1, 'FATAL:', @_); sendmail(); exit(1); } | ||
1647 | 1631 | sub success { _msg(1, 'SUCCESS:', @_); } | ||
1648 | 1632 | sub failed { _msg(1, 'FAILED:', @_); $result = 'FAILED'; } | ||
1649 | 1633 | sub prettytime { return scalar(localtime(shift)); } | ||
1650 | 1634 | |||
1651 | 1635 | sub prettyinterval { | ||
1652 | 1636 | my $interval = shift; | ||
1653 | 1637 | use integer; | ||
1654 | 1638 | my $s = $interval % 60; $interval /= 60; | ||
1655 | 1639 | my $m = $interval % 60; $interval /= 60; | ||
1656 | 1640 | my $h = $interval % 24; $interval /= 24; | ||
1657 | 1641 | my $d = $interval; | ||
1658 | 1642 | |||
1659 | 1643 | my $string = ""; | ||
1660 | 1644 | $string .= "$d day" if $d; | ||
1661 | 1645 | $string .= "s" if $d > 1; | ||
1662 | 1646 | $string .= ", " if $string && $h; | ||
1663 | 1647 | $string .= "$h hour" if $h; | ||
1664 | 1648 | $string .= "s" if $h > 1; | ||
1665 | 1649 | $string .= ", " if $string && $m; | ||
1666 | 1650 | $string .= "$m minute" if $m; | ||
1667 | 1651 | $string .= "s" if $m > 1; | ||
1668 | 1652 | $string .= ", " if $string && $s; | ||
1669 | 1653 | $string .= "$s second" if $s; | ||
1670 | 1654 | $string .= "s" if $s > 1; | ||
1671 | 1655 | return $string; | ||
1672 | 1656 | } | ||
1673 | 1657 | sub interval { | ||
1674 | 1658 | my $value = shift; | ||
1675 | 1659 | if ($value =~ /^(\d+)(seconds|s)/i) { | ||
1676 | 1660 | $value = $1; | ||
1677 | 1661 | } elsif ($value =~ /^(\d+)(minutes|m)/i) { | ||
1678 | 1662 | $value = $1 * 60; | ||
1679 | 1663 | } elsif ($value =~ /^(\d+)(hours|h)/i) { | ||
1680 | 1664 | $value = $1 * 60*60; | ||
1681 | 1665 | } elsif ($value =~ /^(\d+)(days|d)/i) { | ||
1682 | 1666 | $value = $1 * 60*60*24; | ||
1683 | 1667 | } elsif ($value !~ /^\d+$/) { | ||
1684 | 1668 | $value = undef; | ||
1685 | 1669 | } | ||
1686 | 1670 | return $value; | ||
1687 | 1671 | } | ||
1688 | 1672 | sub interval_expired { | ||
1689 | 1673 | my ($host, $time, $interval) = @_; | ||
1690 | 1674 | |||
1691 | 1675 | return 1 if !exists $cache{$host}; | ||
1692 | 1676 | return 1 if !exists $cache{$host}{$time} || !$cache{$host}{$time}; | ||
1693 | 1677 | return 1 if !exists $config{$host}{$interval} || !$config{$host}{$interval}; | ||
1694 | 1678 | |||
1695 | 1679 | return $now > ($cache{$host}{$time} + $config{$host}{$interval}); | ||
1696 | 1680 | } | ||
1697 | 1681 | |||
1698 | 1682 | |||
1699 | 1683 | |||
1700 | 1684 | ###################################################################### | ||
1701 | 1685 | ## check_value | ||
1702 | 1686 | ###################################################################### | ||
1703 | 1687 | sub check_value { | ||
1704 | 1688 | my ($value, $def) = @_; | ||
1705 | 1689 | my $type = $def->{'type'}; | ||
1706 | 1690 | my $min = $def->{'minimum'}; | ||
1707 | 1691 | my $required = $def->{'required'}; | ||
1708 | 1692 | |||
1709 | 1693 | if (!defined $value && !$required) { | ||
1710 | 1694 | ; | ||
1711 | 1695 | |||
1712 | 1696 | } elsif ($type eq T_DELAY) { | ||
1713 | 1697 | $value = interval($value); | ||
1714 | 1698 | $value = $min if defined($value) && defined($min) && $value < $min; | ||
1715 | 1699 | |||
1716 | 1700 | } elsif ($type eq T_NUMBER) { | ||
1717 | 1701 | return undef if $value !~ /^\d+$/; | ||
1718 | 1702 | $value = $min if defined($min) && $value < $min; | ||
1719 | 1703 | |||
1720 | 1704 | } elsif ($type eq T_BOOL) { | ||
1721 | 1705 | if ($value =~ /^y(es)?$|^t(true)?$|^1$/i) { | ||
1722 | 1706 | $value = 1; | ||
1723 | 1707 | } elsif ($value =~ /^n(o)?$|^f(alse)?$|^0$/i) { | ||
1724 | 1708 | $value = 0; | ||
1725 | 1709 | } else { | ||
1726 | 1710 | return undef; | ||
1727 | 1711 | } | ||
1728 | 1712 | } elsif ($type eq T_FQDN || $type eq T_OFQDN && $value ne '') { | ||
1729 | 1713 | $value = lc $value; | ||
1730 | 1714 | return undef if $value !~ /[^.]\.[^.]/; | ||
1731 | 1715 | |||
1732 | 1716 | } elsif ($type eq T_FQDNP) { | ||
1733 | 1717 | $value = lc $value; | ||
1734 | 1718 | return undef if $value !~ /[^.]\.[^.].*(:\d+)?$/; | ||
1735 | 1719 | |||
1736 | 1720 | } elsif ($type eq T_PROTO) { | ||
1737 | 1721 | $value = lc $value; | ||
1738 | 1722 | return undef if ! exists $services{$value}; | ||
1739 | 1723 | |||
1740 | 1724 | } elsif ($type eq T_USE) { | ||
1741 | 1725 | $value = lc $value; | ||
1742 | 1726 | return undef if ! exists $ip_strategies{$value}; | ||
1743 | 1727 | |||
1744 | 1728 | } elsif ($type eq T_FILE) { | ||
1745 | 1729 | return undef if $value eq ""; | ||
1746 | 1730 | |||
1747 | 1731 | } elsif ($type eq T_IF) { | ||
1748 | 1732 | return undef if $value !~ /^[a-z0-9:._-]+$/; | ||
1749 | 1733 | |||
1750 | 1734 | } elsif ($type eq T_PROG) { | ||
1751 | 1735 | return undef if $value eq ""; | ||
1752 | 1736 | |||
1753 | 1737 | } elsif ($type eq T_LOGIN) { | ||
1754 | 1738 | return undef if $value eq ""; | ||
1755 | 1739 | |||
1756 | 1740 | # } elsif ($type eq T_PASSWD) { | ||
1757 | 1741 | # return undef if $value =~ /:/; | ||
1758 | 1742 | |||
1759 | 1743 | } elsif ($type eq T_IP) { | ||
1760 | 1744 | return undef if $value !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; | ||
1761 | 1745 | } | ||
1762 | 1746 | return $value; | ||
1763 | 1747 | } | ||
1764 | 1748 | ###################################################################### | ||
1765 | 1749 | ## encode_base64 - from MIME::Base64 | ||
1766 | 1750 | ###################################################################### | ||
1767 | 1751 | sub encode_base64 ($;$) { | ||
1768 | 1752 | my $res = ''; | ||
1769 | 1753 | my $eol = $_[1]; | ||
1770 | 1754 | $eol = "\n" unless defined $eol; | ||
1771 | 1755 | pos($_[0]) = 0; # ensure start at the beginning | ||
1772 | 1756 | while ($_[0] =~ /(.{1,45})/gs) { | ||
1773 | 1757 | $res .= substr(pack('u', $1), 1); | ||
1774 | 1758 | chop($res); | ||
1775 | 1759 | } | ||
1776 | 1760 | $res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs | ||
1777 | 1761 | |||
1778 | 1762 | # fix padding at the end | ||
1779 | 1763 | my $padding = (3 - length($_[0]) % 3) % 3; | ||
1780 | 1764 | $res =~ s/.{$padding}$/'=' x $padding/e if $padding; | ||
1781 | 1765 | $res; | ||
1782 | 1766 | } | ||
1783 | 1767 | ###################################################################### | ||
1784 | 1768 | ## load_ssl_support | ||
1785 | 1769 | ###################################################################### | ||
1786 | 1770 | sub load_ssl_support { | ||
1787 | 1771 | my $ssl_loaded = eval {require IO::Socket::SSL}; | ||
1788 | 1772 | unless ($ssl_loaded) { | ||
1789 | 1773 | fatal(<<"EOM"); | ||
1790 | 1774 | Error loading the Perl module IO::Socket::SSL needed for SSL connect. | ||
1791 | 1775 | On Debian, the package libio-socket-ssl-perl must be installed. | ||
1792 | 1776 | On Red Hat, the package perl-IO-Socket-SSL must be installed. | ||
1793 | 1777 | EOM | ||
1794 | 1778 | } | ||
1795 | 1779 | import IO::Socket::SSL; | ||
1796 | 1780 | { no warnings; $IO::Socket::SSL::DEBUG = 0; } | ||
1797 | 1781 | } | ||
1798 | 1782 | ###################################################################### | ||
1799 | 1783 | ## load_sha1_support | ||
1800 | 1784 | ###################################################################### | ||
1801 | 1785 | sub load_sha1_support { | ||
1802 | 1786 | my $sha1_loaded = eval {require Digest::SHA1}; | ||
1803 | 1787 | unless ($sha1_loaded) { | ||
1804 | 1788 | fatal(<<"EOM"); | ||
1805 | 1789 | Error loading the Perl module Digest::SHA1 needed for freedns update. | ||
1806 | 1790 | On Debian, the package libdigest-sha1-perl must be installed. | ||
1807 | 1791 | EOM | ||
1808 | 1792 | } | ||
1809 | 1793 | import Digest::SHA1 (qw/sha1_hex/); | ||
1810 | 1794 | } | ||
1811 | 1795 | ###################################################################### | ||
1812 | 1796 | ## geturl | ||
1813 | 1797 | ###################################################################### | ||
1814 | 1798 | sub geturl { | ||
1815 | 1799 | my $proxy = shift || ''; | ||
1816 | 1800 | my $url = shift || ''; | ||
1817 | 1801 | my $login = shift || ''; | ||
1818 | 1802 | my $password = shift || ''; | ||
1819 | 1803 | my ($peer, $server, $port, $default_port, $use_ssl); | ||
1820 | 1804 | my ($sd, $rq, $request, $reply); | ||
1821 | 1805 | |||
1822 | 1806 | debug("proxy = $proxy"); | ||
1823 | 1807 | debug("url = %s", $url); | ||
1824 | 1808 | ## canonify proxy and url | ||
1825 | 1809 | my $force_ssl; | ||
1826 | 1810 | $force_ssl = 1 if ($url =~ /^https:/); | ||
1827 | 1811 | $proxy =~ s%^https?://%%i; | ||
1828 | 1812 | $url =~ s%^https?://%%i; | ||
1829 | 1813 | $server = $url; | ||
1830 | 1814 | $server =~ s%/.*%%; | ||
1831 | 1815 | $url = "/" unless $url =~ m%/%; | ||
1832 | 1816 | $url =~ s%^[^/]*/%%; | ||
1833 | 1817 | |||
1834 | 1818 | debug("server = $server"); | ||
1835 | 1819 | opt('fw') && debug("opt(fw = ",opt('fw'),")"); | ||
1836 | 1820 | $globals{'fw'} && debug("glo fw = $globals{'fw'}"); | ||
1837 | 1821 | #if ( $globals{'ssl'} and $server ne $globals{'fw'} ) { | ||
1838 | 1822 | ## always omit SSL for connections to local router | ||
1839 | 1823 | if ( $force_ssl || ($globals{'ssl'} and (caller(1))[3] ne 'main::get_ip') ) { | ||
1840 | 1824 | $use_ssl = 1; | ||
1841 | 1825 | $default_port = 443; | ||
1842 | 1826 | load_ssl_support; | ||
1843 | 1827 | } else { | ||
1844 | 1828 | $use_ssl = 0; | ||
1845 | 1829 | $default_port = 80; | ||
1846 | 1830 | } | ||
1847 | 1831 | |||
1848 | 1832 | ## determine peer and port to use. | ||
1849 | 1833 | $peer = $proxy || $server; | ||
1850 | 1834 | $peer =~ s%/.*%%; | ||
1851 | 1835 | $port = $peer; | ||
1852 | 1836 | $port =~ s%^.*:%%; | ||
1853 | 1837 | $port = $default_port unless $port =~ /^\d+$/; | ||
1854 | 1838 | $peer =~ s%:.*$%%; | ||
1855 | 1839 | |||
1856 | 1840 | my $to = sprintf "%s%s", $server, $proxy ? " via proxy $peer:$port" : ""; | ||
1857 | 1841 | verbose("CONNECT:", "%s", $to); | ||
1858 | 1842 | |||
1859 | 1843 | $request = "GET "; | ||
1860 | 1844 | $request .= "http://$server" if $proxy; | ||
1861 | 1845 | $request .= "/$url HTTP/1.0\n"; | ||
1862 | 1846 | $request .= "Host: $server\n"; | ||
1863 | 1847 | |||
1864 | 1848 | my $auth = encode_base64("${login}:${password}"); | ||
1865 | 1849 | $request .= "Authorization: Basic $auth\n" if $login || $password; | ||
1866 | 1850 | $request .= "User-Agent: ${program}/${version}\n"; | ||
1867 | 1851 | $request .= "Connection: close\n"; | ||
1868 | 1852 | $request .= "\n"; | ||
1869 | 1853 | |||
1870 | 1854 | ## make sure newlines are <cr><lf> for some pedantic proxy servers | ||
1871 | 1855 | ($rq = $request) =~ s/\n/\r\n/g; | ||
1872 | 1856 | |||
1873 | 1857 | # local $^W = 0; | ||
1874 | 1858 | $0 = sprintf("%s - connecting to %s port %s", $program, $peer, $port); | ||
1875 | 1859 | if (! opt('exec')) { | ||
1876 | 1860 | debug("skipped network connection"); | ||
1877 | 1861 | verbose("SENDING:", "%s", $request); | ||
1878 | 1862 | } elsif ($use_ssl) { | ||
1879 | 1863 | $sd = IO::Socket::SSL->new( | ||
1880 | 1864 | PeerAddr => $peer, | ||
1881 | 1865 | PeerPort => $port, | ||
1882 | 1866 | Proto => 'tcp', | ||
1883 | 1867 | MultiHomed => 1, | ||
1884 | 1868 | Timeout => opt('timeout'), | ||
1885 | 1869 | ); | ||
1886 | 1870 | defined $sd or warning("cannot connect to $peer:$port socket: $@ " . IO::Socket::SSL::errstr()); | ||
1887 | 1871 | } else { | ||
1888 | 1872 | $sd = IO::Socket::INET->new( | ||
1889 | 1873 | PeerAddr => $peer, | ||
1890 | 1874 | PeerPort => $port, | ||
1891 | 1875 | Proto => 'tcp', | ||
1892 | 1876 | MultiHomed => 1, | ||
1893 | 1877 | Timeout => opt('timeout'), | ||
1894 | 1878 | ); | ||
1895 | 1879 | defined $sd or warning("cannot connect to $peer:$port socket: $@"); | ||
1896 | 1880 | } | ||
1897 | 1881 | |||
1898 | 1882 | if (defined $sd) { | ||
1899 | 1883 | ## send the request to the http server | ||
1900 | 1884 | verbose("CONNECTED: ", $use_ssl ? 'using SSL' : 'using HTTP'); | ||
1901 | 1885 | verbose("SENDING:", "%s", $request); | ||
1902 | 1886 | |||
1903 | 1887 | $0 = sprintf("%s - sending to %s port %s", $program, $peer, $port); | ||
1904 | 1888 | my $result = syswrite $sd, $rq; | ||
1905 | 1889 | if ($result != length($rq)) { | ||
1906 | 1890 | warning("cannot send to $peer:$port ($!)."); | ||
1907 | 1891 | } else { | ||
1908 | 1892 | $0 = sprintf("%s - reading from %s port %s", $program, $peer, $port); | ||
1909 | 1893 | eval { | ||
1910 | 1894 | local $SIG{'ALRM'} = sub { die "timeout";}; | ||
1911 | 1895 | alarm(opt('timeout')) if opt('timeout') > 0; | ||
1912 | 1896 | while ($_ = <$sd>) { | ||
1913 | 1897 | $0 = sprintf("%s - read from %s port %s", $program, $peer, $port); | ||
1914 | 1898 | verbose("RECEIVE:", "%s", define($_, "<undefined>")); | ||
1915 | 1899 | $reply .= $_ if defined $_; | ||
1916 | 1900 | } | ||
1917 | 1901 | if (opt('timeout') > 0) { | ||
1918 | 1902 | alarm(0); | ||
1919 | 1903 | } | ||
1920 | 1904 | }; | ||
1921 | 1905 | close($sd); | ||
1922 | 1906 | |||
1923 | 1907 | if ($@ and $@ =~ /timeout/) { | ||
1924 | 1908 | warning("TIMEOUT: %s after %s seconds", $to, opt('timeout')); | ||
1925 | 1909 | $reply = ''; | ||
1926 | 1910 | } | ||
1927 | 1911 | $reply = '' if !defined $reply; | ||
1928 | 1912 | } | ||
1929 | 1913 | } | ||
1930 | 1914 | $0 = sprintf("%s - closed %s port %s", $program, $peer, $port); | ||
1931 | 1915 | |||
1932 | 1916 | ## during testing simulate reading the URL | ||
1933 | 1917 | if (opt('test')) { | ||
1934 | 1918 | my $filename = "$server/$url"; | ||
1935 | 1919 | $filename =~ s|/|%2F|g; | ||
1936 | 1920 | if (opt('exec')) { | ||
1937 | 1921 | $reply = save_file("${savedir}$filename", $reply, 'unique'); | ||
1938 | 1922 | } else { | ||
1939 | 1923 | $reply = load_file("${savedir}$filename"); | ||
1940 | 1924 | } | ||
1941 | 1925 | } | ||
1942 | 1926 | |||
1943 | 1927 | $reply =~ s/\r//g if defined $reply; | ||
1944 | 1928 | return $reply; | ||
1945 | 1929 | } | ||
1946 | 1930 | ###################################################################### | ||
1947 | 1931 | ## get_ip | ||
1948 | 1932 | ###################################################################### | ||
1949 | 1933 | sub get_ip { | ||
1950 | 1934 | my $use = lc shift; | ||
1951 | 1935 | my $h = shift; | ||
1952 | 1936 | my ($ip, $arg, $reply, $url, $skip) = (undef, opt($use), ''); | ||
1953 | 1937 | $arg = '' unless $arg; | ||
1954 | 1938 | |||
1955 | 1939 | if ($use eq 'ip') { | ||
1956 | 1940 | $ip = opt('ip', $h); | ||
1957 | 1941 | $arg = 'ip'; | ||
1958 | 1942 | |||
1959 | 1943 | } elsif ($use eq 'if') { | ||
1960 | 1944 | $skip = opt('if-skip', $h) || ''; | ||
1961 | 1945 | $reply = `ifconfig $arg 2> /dev/null`; | ||
1962 | 1946 | $reply = '' if $?; | ||
1963 | 1947 | |||
1964 | 1948 | } elsif ($use eq 'cmd') { | ||
1965 | 1949 | if ($arg) { | ||
1966 | 1950 | $skip = opt('cmd-skip', $h) || ''; | ||
1967 | 1951 | $reply = `$arg`; | ||
1968 | 1952 | $reply = '' if $?; | ||
1969 | 1953 | } | ||
1970 | 1954 | |||
1971 | 1955 | } elsif ($use eq 'web') { | ||
1972 | 1956 | $url = opt('web', $h) || ''; | ||
1973 | 1957 | $skip = opt('web-skip', $h) || ''; | ||
1974 | 1958 | |||
1975 | 1959 | if (exists $builtinweb{$url}) { | ||
1976 | 1960 | $skip = $builtinweb{$url}->{'skip'} unless $skip; | ||
1977 | 1961 | $url = $builtinweb{$url}->{'url'}; | ||
1978 | 1962 | } | ||
1979 | 1963 | $arg = $url; | ||
1980 | 1964 | |||
1981 | 1965 | if ($url) { | ||
1982 | 1966 | $reply = geturl(opt('proxy', $h), $url) || ''; | ||
1983 | 1967 | } | ||
1984 | 1968 | |||
1985 | 1969 | } elsif (($use eq 'cisco')) { | ||
1986 | 1970 | # Stuff added to support Cisco router ip http daemon | ||
1987 | 1971 | # User fw-login should only have level 1 access to prevent | ||
1988 | 1972 | # password theft. This is pretty harmless. | ||
1989 | 1973 | my $queryif = opt('if', $h); | ||
1990 | 1974 | $skip = opt('fw-skip', $h) || ''; | ||
1991 | 1975 | |||
1992 | 1976 | # Convert slashes to protected value "\/" | ||
1993 | 1977 | $queryif =~ s%\/%\\\/%g; | ||
1994 | 1978 | |||
1995 | 1979 | # Protect special HTML characters (like '?') | ||
1996 | 1980 | $queryif =~ s/([\?&= ])/sprintf("%%%02x",ord($1))/ge; | ||
1997 | 1981 | |||
1998 | 1982 | $url = "http://".opt('fw', $h)."/level/1/exec/show/ip/interface/brief/${queryif}/CR"; | ||
1999 | 1983 | $reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || ''; | ||
2000 | 1984 | $arg = $url; | ||
2001 | 1985 | |||
2002 | 1986 | } elsif (($use eq 'cisco-asa')) { | ||
2003 | 1987 | # Stuff added to support Cisco ASA ip https daemon | ||
2004 | 1988 | # User fw-login should only have level 1 access to prevent | ||
2005 | 1989 | # password theft. This is pretty harmless. | ||
2006 | 1990 | my $queryif = opt('if', $h); | ||
2007 | 1991 | $skip = opt('fw-skip', $h) || ''; | ||
2008 | 1992 | |||
2009 | 1993 | # Convert slashes to protected value "\/" | ||
2010 | 1994 | $queryif =~ s%\/%\\\/%g; | ||
2011 | 1995 | |||
2012 | 1996 | # Protect special HTML characters (like '?') | ||
2013 | 1997 | $queryif =~ s/([\?&= ])/sprintf("%%%02x",ord($1))/ge; | ||
2014 | 1998 | |||
2015 | 1999 | $url = "https://".opt('fw', $h)."/exec/show%20interface%20${queryif}"; | ||
2016 | 2000 | $reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || ''; | ||
2017 | 2001 | $arg = $url; | ||
2018 | 2002 | |||
2019 | 2003 | } else { | ||
2020 | 2004 | $url = opt('fw', $h) || ''; | ||
2021 | 2005 | $skip = opt('fw-skip', $h) || ''; | ||
2022 | 2006 | |||
2023 | 2007 | if (exists $builtinfw{$use}) { | ||
2024 | 2008 | $skip = $builtinfw{$use}->{'skip'} unless $skip; | ||
2025 | 2009 | $url = "http://${url}" . $builtinfw{$use}->{'url'} unless $url =~ /\//; | ||
2026 | 2010 | } | ||
2027 | 2011 | $arg = $url; | ||
2028 | 2012 | |||
2029 | 2013 | if ($url) { | ||
2030 | 2014 | $reply = geturl('', $url, opt('fw-login', $h), opt('fw-password', $h)) || ''; | ||
2031 | 2015 | } | ||
2032 | 2016 | } | ||
2033 | 2017 | if (!defined $reply) { | ||
2034 | 2018 | $reply = ''; | ||
2035 | 2019 | } | ||
2036 | 2020 | if ($skip) { | ||
2037 | 2021 | $skip =~ s/ /\\s/is; | ||
2038 | 2022 | $reply =~ s/^.*?${skip}//is; | ||
2039 | 2023 | } | ||
2040 | 2024 | if ($reply =~ /^.*?\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b.*/is) { | ||
2041 | 2025 | $ip = $1; | ||
2042 | 2026 | } | ||
2043 | 2027 | if (($use ne 'ip') && (define($ip,'') eq '0.0.0.0')) { | ||
2044 | 2028 | $ip = undef; | ||
2045 | 2029 | } | ||
2046 | 2030 | |||
2047 | 2031 | debug("get_ip: using %s, %s reports %s", $use, $arg, define($ip, "<undefined>")); | ||
2048 | 2032 | return $ip; | ||
2049 | 2033 | } | ||
2050 | 2034 | |||
2051 | 2035 | ###################################################################### | ||
2052 | 2036 | ## group_hosts_by | ||
2053 | 2037 | ###################################################################### | ||
2054 | 2038 | sub group_hosts_by { | ||
2055 | 2039 | my ($hosts, $attributes) = @_; | ||
2056 | 2040 | |||
2057 | 2041 | my %groups = (); | ||
2058 | 2042 | foreach my $h (@$hosts) { | ||
2059 | 2043 | my @keys = (@$attributes, 'wantip'); | ||
2060 | 2044 | map { $config{$h}{$_} = '' unless exists $config{$h}{$_} } @keys; | ||
2061 | 2045 | my $sig = join(',', map { "$_=$config{$h}{$_}" } @keys); | ||
2062 | 2046 | |||
2063 | 2047 | push @{$groups{$sig}}, $h; | ||
2064 | 2048 | } | ||
2065 | 2049 | return %groups; | ||
2066 | 2050 | } | ||
2067 | 2051 | ###################################################################### | ||
2068 | 2052 | ## nic_examples | ||
2069 | 2053 | ###################################################################### | ||
2070 | 2054 | sub nic_examples { | ||
2071 | 2055 | my $examples = ""; | ||
2072 | 2056 | my $separator = ""; | ||
2073 | 2057 | foreach my $s (sort keys %services) { | ||
2074 | 2058 | my $subr = $services{$s}{'examples'}; | ||
2075 | 2059 | my $example; | ||
2076 | 2060 | |||
2077 | 2061 | if (defined($subr) && ($example = &$subr())) { | ||
2078 | 2062 | chomp($example); | ||
2079 | 2063 | $examples .= $example; | ||
2080 | 2064 | $examples .= "\n\n$separator"; | ||
2081 | 2065 | $separator = "\n"; | ||
2082 | 2066 | } | ||
2083 | 2067 | } | ||
2084 | 2068 | my $intro = <<EoEXAMPLE; | ||
2085 | 2069 | == CONFIGURING ${program} | ||
2086 | 2070 | |||
2087 | 2071 | The configuration file, ${program}.conf, can be used to define the | ||
2088 | 2072 | default behaviour and operation of ${program}. The file consists of | ||
2089 | 2073 | sequences of global variable definitions and host definitions. | ||
2090 | 2074 | |||
2091 | 2075 | Global definitions look like: | ||
2092 | 2076 | name=value [,name=value]* | ||
2093 | 2077 | |||
2094 | 2078 | For example: | ||
2095 | 2079 | daemon=5m | ||
2096 | 2080 | use=if, if=eth0 | ||
2097 | 2081 | proxy=proxy.myisp.com | ||
2098 | 2082 | protocol=dyndns2 | ||
2099 | 2083 | |||
2100 | 2084 | specifies that ${program} should operate as a daemon, checking the | ||
2101 | 2085 | eth0 interface for an IP address change every 5 minutes and use the | ||
2102 | 2086 | 'dyndns2' protocol by default. The daemon interval can be specified | ||
2103 | 2087 | as seconds (600s), minutes (5m), hours (1h) or days (1d). | ||
2104 | 2088 | |||
2105 | 2089 | Host definitions look like: | ||
2106 | 2090 | [name=value [,name=value]*]* a.host.domain [,b.host.domain] [login] [password] | ||
2107 | 2091 | |||
2108 | 2092 | For example: | ||
2109 | 2093 | protocol=hammernode1, \\ | ||
2110 | 2094 | login=my-hn-login, password=my-hn-password myhost.hn.org | ||
2111 | 2095 | login=my-login, password=my-password myhost.dyndns.org,my2nd.dyndns.org | ||
2112 | 2096 | |||
2113 | 2097 | specifies two host definitions. | ||
2114 | 2098 | |||
2115 | 2099 | The first definition will use the hammernode1 protocol, | ||
2116 | 2100 | my-hn-login and my-hn-password to update the ip-address of | ||
2117 | 2101 | myhost.hn.org and my2ndhost.hn.org. | ||
2118 | 2102 | |||
2119 | 2103 | The second host definition will use the current default protocol | ||
2120 | 2104 | ('dyndns2'), my-login and my-password to update the ip-address of | ||
2121 | 2105 | myhost.dyndns.org and my2ndhost.dyndns.org. | ||
2122 | 2106 | |||
2123 | 2107 | The order of this sequence is significant because the values of any | ||
2124 | 2108 | global variable definitions are bound to a host definition when the | ||
2125 | 2109 | host definition is encountered. | ||
2126 | 2110 | |||
2127 | 2111 | See the sample-${program}.conf file for further examples. | ||
2128 | 2112 | EoEXAMPLE | ||
2129 | 2113 | $intro .= "\n== NIC specific variables and examples:\n$examples" if $examples; | ||
2130 | 2114 | return $intro; | ||
2131 | 2115 | } | ||
2132 | 2116 | ###################################################################### | ||
2133 | 2117 | ## nic_updateable | ||
2134 | 2118 | ###################################################################### | ||
2135 | 2119 | sub nic_updateable { | ||
2136 | 2120 | my $host = shift; | ||
2137 | 2121 | my $sub = shift; | ||
2138 | 2122 | my $update = 0; | ||
2139 | 2123 | my $ip = $config{$host}{'wantip'}; | ||
2140 | 2124 | |||
2141 | 2125 | if ($config{$host}{'login'} eq '') { | ||
2142 | 2126 | warning("null login name specified for host %s.", $host); | ||
2143 | 2127 | |||
2144 | 2128 | } elsif ($config{$host}{'password'} eq '') { | ||
2145 | 2129 | warning("null password specified for host %s.", $host); | ||
2146 | 2130 | |||
2147 | 2131 | } elsif ($opt{'force'}) { | ||
2148 | 2132 | info("forcing update of %s.", $host); | ||
2149 | 2133 | $update = 1; | ||
2150 | 2134 | |||
2151 | 2135 | } elsif (!exists($cache{$host})) { | ||
2152 | 2136 | info("forcing updating %s because no cached entry exists.", $host); | ||
2153 | 2137 | $update = 1; | ||
2154 | 2138 | |||
2155 | 2139 | } elsif ($cache{$host}{'wtime'} && $cache{$host}{'wtime'} > $now) { | ||
2156 | 2140 | warning("cannot update %s from %s to %s until after %s.", | ||
2157 | 2141 | $host, | ||
2158 | 2142 | ($cache{$host}{'ip'} ? $cache{$host}{'ip'} : '<nothing>'), $ip, | ||
2159 | 2143 | prettytime($cache{$host}{'wtime'}) | ||
2160 | 2144 | ); | ||
2161 | 2145 | |||
2162 | 2146 | } elsif ($cache{$host}{'mtime'} && interval_expired($host, 'mtime', 'max-interval')) { | ||
2163 | 2147 | warning("forcing update of %s from %s to %s; %s since last update on %s.", | ||
2164 | 2148 | $host, | ||
2165 | 2149 | ($cache{$host}{'ip'} ? $cache{$host}{'ip'} : '<nothing>'), $ip, | ||
2166 | 2150 | prettyinterval($config{$host}{'max-interval'}), | ||
2167 | 2151 | prettytime($cache{$host}{'mtime'}) | ||
2168 | 2152 | ); | ||
2169 | 2153 | $update = 1; | ||
2170 | 2154 | |||
2171 | 2155 | } elsif ((!exists($cache{$host}{'ip'})) || | ||
2172 | 2156 | ("$cache{$host}{'ip'}" ne "$ip")) { | ||
2173 | 2157 | if (($cache{$host}{'status'} eq 'good') && | ||
2174 | 2158 | !interval_expired($host, 'mtime', 'min-interval')) { | ||
2175 | 2159 | |||
2176 | 2160 | warning("skipping update of %s from %s to %s.\nlast updated %s.\nWait at least %s between update attempts.", | ||
2177 | 2161 | $host, | ||
2178 | 2162 | ($cache{$host}{'ip'} ? $cache{$host}{'ip'} : '<nothing>'), | ||
2179 | 2163 | $ip, | ||
2180 | 2164 | ($cache{$host}{'mtime'} ? prettytime($cache{$host}{'mtime'}) : '<never>'), | ||
2181 | 2165 | prettyinterval($config{$host}{'min-interval'}) | ||
2182 | 2166 | ) | ||
2183 | 2167 | if opt('verbose') || !define($cache{$host}{'warned-min-interval'}, 0); | ||
2184 | 2168 | |||
2185 | 2169 | $cache{$host}{'warned-min-interval'} = $now; | ||
2186 | 2170 | |||
2187 | 2171 | } elsif (($cache{$host}{'status'} ne 'good') && !interval_expired($host, 'atime', 'min-error-interval')) { | ||
2188 | 2172 | |||
2189 | 2173 | warning("skipping update of %s from %s to %s.\nlast updated %s but last attempt on %s failed.\nWait at least %s between update attempts.", | ||
2190 | 2174 | $host, | ||
2191 | 2175 | ($cache{$host}{'ip'} ? $cache{$host}{'ip'} : '<nothing>'), | ||
2192 | 2176 | $ip, | ||
2193 | 2177 | ($cache{$host}{'mtime'} ? prettytime($cache{$host}{'mtime'}) : '<never>'), | ||
2194 | 2178 | ($cache{$host}{'atime'} ? prettytime($cache{$host}{'atime'}) : '<never>'), | ||
2195 | 2179 | prettyinterval($config{$host}{'min-error-interval'}) | ||
2196 | 2180 | ) | ||
2197 | 2181 | if opt('verbose') || !define($cache{$host}{'warned-min-error-interval'}, 0); | ||
2198 | 2182 | |||
2199 | 2183 | $cache{$host}{'warned-min-error-interval'} = $now; | ||
2200 | 2184 | |||
2201 | 2185 | } else { | ||
2202 | 2186 | $update = 1; | ||
2203 | 2187 | } | ||
2204 | 2188 | |||
2205 | 2189 | } elsif (defined($sub) && &$sub($host)) { | ||
2206 | 2190 | $update = 1; | ||
2207 | 2191 | } elsif ((defined($cache{$host}{'static'}) && defined($config{$host}{'static'}) && | ||
2208 | 2192 | ($cache{$host}{'static'} ne $config{$host}{'static'})) || | ||
2209 | 2193 | (defined($cache{$host}{'wildcard'}) && defined($config{$host}{'wildcard'}) && | ||
2210 | 2194 | ($cache{$host}{'wildcard'} ne $config{$host}{'wildcard'})) || | ||
2211 | 2195 | (defined($cache{$host}{'mx'}) && defined($config{$host}{'mx'}) && | ||
2212 | 2196 | ($cache{$host}{'mx'} ne $config{$host}{'mx'})) || | ||
2213 | 2197 | (defined($cache{$host}{'backupmx'}) && defined($config{$host}{'backupmx'}) && | ||
2214 | 2198 | ($cache{$host}{'backupmx'} ne $config{$host}{'backupmx'})) ) { | ||
2215 | 2199 | info("updating %s because host settings have been changed.", $host); | ||
2216 | 2200 | $update = 1; | ||
2217 | 2201 | |||
2218 | 2202 | } else { | ||
2219 | 2203 | success("%s: skipped: IP address was already set to %s.", $host, $ip) | ||
2220 | 2204 | if opt('verbose'); | ||
2221 | 2205 | } | ||
2222 | 2206 | $config{$host}{'status'} = define($cache{$host}{'status'},''); | ||
2223 | 2207 | $config{$host}{'update'} = $update; | ||
2224 | 2208 | if ($update) { | ||
2225 | 2209 | $config{$host}{'status'} = 'noconnect'; | ||
2226 | 2210 | $config{$host}{'atime'} = $now; | ||
2227 | 2211 | $config{$host}{'wtime'} = 0; | ||
2228 | 2212 | $config{$host}{'warned-min-interval'} = 0; | ||
2229 | 2213 | $config{$host}{'warned-min-error-interval'} = 0; | ||
2230 | 2214 | |||
2231 | 2215 | delete $cache{$host}{'warned-min-interval'}; | ||
2232 | 2216 | delete $cache{$host}{'warned-min-error-interval'}; | ||
2233 | 2217 | } | ||
2234 | 2218 | |||
2235 | 2219 | return $update; | ||
2236 | 2220 | } | ||
2237 | 2221 | ###################################################################### | ||
2238 | 2222 | ## header_ok | ||
2239 | 2223 | ###################################################################### | ||
2240 | 2224 | sub header_ok { | ||
2241 | 2225 | my ($host, $line) = @_; | ||
2242 | 2226 | my $ok = 0; | ||
2243 | 2227 | |||
2244 | 2228 | if ($line =~ m%^s*HTTP/1.*\s+(\d+)%i) { | ||
2245 | 2229 | my $result = $1; | ||
2246 | 2230 | |||
2247 | 2231 | if ($result eq '200') { | ||
2248 | 2232 | $ok = 1; | ||
2249 | 2233 | |||
2250 | 2234 | } elsif ($result eq '401') { | ||
2251 | 2235 | failed("updating %s: authorization failed (%s)", $host, $line); | ||
2252 | 2236 | } | ||
2253 | 2237 | |||
2254 | 2238 | } else { | ||
2255 | 2239 | failed("updating %s: unexpected line (%s)", $host, $line); | ||
2256 | 2240 | } | ||
2257 | 2241 | return $ok; | ||
2258 | 2242 | } | ||
2259 | 2243 | ###################################################################### | ||
2260 | 2244 | ## nic_dyndns1_examples | ||
2261 | 2245 | ###################################################################### | ||
2262 | 2246 | sub nic_dyndns1_examples { | ||
2263 | 2247 | return <<EoEXAMPLE; | ||
2264 | 2248 | o 'dyndns1' | ||
2265 | 2249 | |||
2266 | 2250 | The 'dyndns1' protocol is a deprecated protocol used by the free dynamic | ||
2267 | 2251 | DNS service offered by www.dyndns.org. The 'dyndns2' should be used to | ||
2268 | 2252 | update the www.dyndns.org service. However, other services are also | ||
2269 | 2253 | using this protocol so support is still provided by ${program}. | ||
2270 | 2254 | |||
2271 | 2255 | Configuration variables applicable to the 'dyndns1' protocol are: | ||
2272 | 2256 | protocol=dyndns1 ## | ||
2273 | 2257 | server=fqdn.of.service ## defaults to members.dyndns.org | ||
2274 | 2258 | backupmx=no|yes ## indicates that this host is the primary MX for the domain. | ||
2275 | 2259 | mx=any.host.domain ## a host MX'ing for this host definition. | ||
2276 | 2260 | wildcard=no|yes ## add a DNS wildcard CNAME record that points to {host} | ||
2277 | 2261 | login=service-login ## login name and password registered with the service | ||
2278 | 2262 | password=service-password ## | ||
2279 | 2263 | fully.qualified.host ## the host registered with the service. | ||
2280 | 2264 | |||
2281 | 2265 | Example ${program}.conf file entries: | ||
2282 | 2266 | ## single host update | ||
2283 | 2267 | protocol=dyndns1, \\ | ||
2284 | 2268 | login=my-dyndns.org-login, \\ | ||
2285 | 2269 | password=my-dyndns.org-password \\ | ||
2286 | 2270 | myhost.dyndns.org | ||
2287 | 2271 | |||
2288 | 2272 | ## multiple host update with wildcard'ing mx, and backupmx | ||
2289 | 2273 | protocol=dyndns1, \\ | ||
2290 | 2274 | login=my-dyndns.org-login, \\ | ||
2291 | 2275 | password=my-dyndns.org-password, \\ | ||
2292 | 2276 | mx=a.host.willing.to.mx.for.me,backupmx=yes,wildcard=yes \\ | ||
2293 | 2277 | myhost.dyndns.org,my2ndhost.dyndns.org | ||
2294 | 2278 | EoEXAMPLE | ||
2295 | 2279 | } | ||
2296 | 2280 | ###################################################################### | ||
2297 | 2281 | ## nic_dyndns1_update | ||
2298 | 2282 | ###################################################################### | ||
2299 | 2283 | sub nic_dyndns1_update { | ||
2300 | 2284 | debug("\nnic_dyndns1_update -------------------"); | ||
2301 | 2285 | ## update each configured host | ||
2302 | 2286 | foreach my $h (@_) { | ||
2303 | 2287 | my $ip = delete $config{$h}{'wantip'}; | ||
2304 | 2288 | info("setting IP address to %s for %s", $ip, $h); | ||
2305 | 2289 | verbose("UPDATE:","updating %s", $h); | ||
2306 | 2290 | |||
2307 | 2291 | my $url; | ||
2308 | 2292 | $url = "http://$config{$h}{'server'}/nic/"; | ||
2309 | 2293 | $url .= ynu($config{$h}{'static'}, 'statdns', 'dyndns', 'dyndns'); | ||
2310 | 2294 | $url .= "?action=edit&started=1&hostname=YES&host_id=$h"; | ||
2311 | 2295 | $url .= "&myip="; | ||
2312 | 2296 | $url .= $ip if $ip; | ||
2313 | 2297 | $url .= "&wildcard=ON" if ynu($config{$h}{'wildcard'}, 1, 0, 0); | ||
2314 | 2298 | if ($config{$h}{'mx'}) { | ||
2315 | 2299 | $url .= "&mx=$config{$h}{'mx'}"; | ||
2316 | 2300 | $url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO'); | ||
2317 | 2301 | } | ||
2318 | 2302 | |||
2319 | 2303 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
2320 | 2304 | if (!defined($reply) || !$reply) { | ||
2321 | 2305 | failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); | ||
2322 | 2306 | next; | ||
2323 | 2307 | } | ||
2324 | 2308 | last if !header_ok($h, $reply); | ||
2325 | 2309 | |||
2326 | 2310 | my @reply = split /\n/, $reply; | ||
2327 | 2311 | my ($title, $return_code, $error_code) = ('','',''); | ||
2328 | 2312 | foreach my $line (@reply) { | ||
2329 | 2313 | $title = $1 if $line =~ m%<TITLE>\s*(.*)\s*</TITLE>%i; | ||
2330 | 2314 | $return_code = $1 if $line =~ m%^return\s+code\s*:\s*(.*)\s*$%i; | ||
2331 | 2315 | $error_code = $1 if $line =~ m%^error\s+code\s*:\s*(.*)\s*$%i; | ||
2332 | 2316 | } | ||
2333 | 2317 | |||
2334 | 2318 | if ($return_code ne 'NOERROR' || $error_code ne 'NOERROR' || !$title) { | ||
2335 | 2319 | $config{$h}{'status'} = 'failed'; | ||
2336 | 2320 | $title = "incomplete response from $config{$h}{server}" unless $title; | ||
2337 | 2321 | warning("SENT: %s", $url) unless opt('verbose'); | ||
2338 | 2322 | warning("REPLIED: %s", $reply); | ||
2339 | 2323 | failed("updating %s: %s", $h, $title); | ||
2340 | 2324 | |||
2341 | 2325 | } else { | ||
2342 | 2326 | $config{$h}{'ip'} = $ip; | ||
2343 | 2327 | $config{$h}{'mtime'} = $now; | ||
2344 | 2328 | $config{$h}{'status'} = 'good'; | ||
2345 | 2329 | success("updating %s: %s: IP address set to %s (%s)", $h, $return_code, $ip, $title); | ||
2346 | 2330 | } | ||
2347 | 2331 | } | ||
2348 | 2332 | } | ||
2349 | 2333 | ###################################################################### | ||
2350 | 2334 | ## nic_dyndns2_updateable | ||
2351 | 2335 | ###################################################################### | ||
2352 | 2336 | sub nic_dyndns2_updateable { | ||
2353 | 2337 | my $host = shift; | ||
2354 | 2338 | my $update = 0; | ||
2355 | 2339 | |||
2356 | 2340 | if ($config{$host}{'mx'} ne $cache{$host}{'mx'}) { | ||
2357 | 2341 | info("forcing updating %s because 'mx' has changed to %s.", $host, $config{$host}{'mx'}); | ||
2358 | 2342 | $update = 1; | ||
2359 | 2343 | |||
2360 | 2344 | } elsif ($config{$host}{'mx'} && (ynu($config{$host}{'backupmx'},1,2,3) ne ynu($config{$host}{'backupmx'},1,2,3))) { | ||
2361 | 2345 | info("forcing updating %s because 'backupmx' has changed to %s.", $host, ynu($config{$host}{'backupmx'},"YES","NO","NO")); | ||
2362 | 2346 | $update = 1; | ||
2363 | 2347 | |||
2364 | 2348 | } elsif ($config{$host}{'static'} ne $cache{$host}{'static'}) { | ||
2365 | 2349 | |||
2366 | 2350 | info("forcing updating %s because 'static' has changed to %s.", $host, ynu($config{$host}{'static'},"YES","NO","NO")); | ||
2367 | 2351 | $update = 1; | ||
2368 | 2352 | |||
2369 | 2353 | } | ||
2370 | 2354 | return $update; | ||
2371 | 2355 | } | ||
2372 | 2356 | ###################################################################### | ||
2373 | 2357 | ## nic_dyndns2_examples | ||
2374 | 2358 | ###################################################################### | ||
2375 | 2359 | sub nic_dyndns2_examples { | ||
2376 | 2360 | return <<EoEXAMPLE; | ||
2377 | 2361 | o 'dyndns2' | ||
2378 | 2362 | |||
2379 | 2363 | The 'dyndns2' protocol is a newer low-bandwidth protocol used by a | ||
2380 | 2364 | free dynamic DNS service offered by www.dyndns.org. It supports | ||
2381 | 2365 | features of the older 'dyndns1' in addition to others. [These will be | ||
2382 | 2366 | supported in a future version of ${program}.] | ||
2383 | 2367 | |||
2384 | 2368 | Configuration variables applicable to the 'dyndns2' protocol are: | ||
2385 | 2369 | protocol=dyndns2 ## | ||
2386 | 2370 | server=fqdn.of.service ## defaults to members.dyndns.org | ||
2387 | 2371 | script=/path/to/script ## defaults to /nic/update | ||
2388 | 2372 | backupmx=no|yes ## indicates that this host is the primary MX for the domain. | ||
2389 | 2373 | static=no|yes ## indicates that this host has a static IP address. | ||
2390 | 2374 | custom=no|yes ## indicates that this host is a 'custom' top-level domain name. | ||
2391 | 2375 | mx=any.host.domain ## a host MX'ing for this host definition. | ||
2392 | 2376 | wildcard=no|yes ## add a DNS wildcard CNAME record that points to {host} | ||
2393 | 2377 | login=service-login ## login name and password registered with the service | ||
2394 | 2378 | password=service-password ## | ||
2395 | 2379 | fully.qualified.host ## the host registered with the service. | ||
2396 | 2380 | |||
2397 | 2381 | Example ${program}.conf file entries: | ||
2398 | 2382 | ## single host update | ||
2399 | 2383 | protocol=dyndns2, \\ | ||
2400 | 2384 | login=my-dyndns.org-login, \\ | ||
2401 | 2385 | password=my-dyndns.org-password \\ | ||
2402 | 2386 | myhost.dyndns.org | ||
2403 | 2387 | |||
2404 | 2388 | ## multiple host update with wildcard'ing mx, and backupmx | ||
2405 | 2389 | protocol=dyndns2, \\ | ||
2406 | 2390 | login=my-dyndns.org-login, \\ | ||
2407 | 2391 | password=my-dyndns.org-password, \\ | ||
2408 | 2392 | mx=a.host.willing.to.mx.for.me,backupmx=yes,wildcard=yes \\ | ||
2409 | 2393 | myhost.dyndns.org,my2ndhost.dyndns.org | ||
2410 | 2394 | |||
2411 | 2395 | ## multiple host update to the custom DNS service | ||
2412 | 2396 | protocol=dyndns2, \\ | ||
2413 | 2397 | login=my-dyndns.org-login, \\ | ||
2414 | 2398 | password=my-dyndns.org-password \\ | ||
2415 | 2399 | my-toplevel-domain.com,my-other-domain.com | ||
2416 | 2400 | EoEXAMPLE | ||
2417 | 2401 | } | ||
2418 | 2402 | ###################################################################### | ||
2419 | 2403 | ## nic_dyndns2_update | ||
2420 | 2404 | ###################################################################### | ||
2421 | 2405 | sub nic_dyndns2_update { | ||
2422 | 2406 | debug("\nnic_dyndns2_update -------------------"); | ||
2423 | 2407 | |||
2424 | 2408 | ## group hosts with identical attributes together | ||
2425 | 2409 | my %groups = group_hosts_by([ @_ ], [ qw(login password server static custom wildcard mx backupmx) ]); | ||
2426 | 2410 | |||
2427 | 2411 | my %errors = ( | ||
2428 | 2412 | 'badauth' => 'Bad authorization (username or password)', | ||
2429 | 2413 | 'badsys' => 'The system parameter given was not valid', | ||
2430 | 2414 | |||
2431 | 2415 | 'notfqdn' => 'A Fully-Qualified Domain Name was not provided', | ||
2432 | 2416 | 'nohost' => 'The hostname specified does not exist in the database', | ||
2433 | 2417 | '!yours' => 'The hostname specified exists, but not under the username currently being used', | ||
2434 | 2418 | '!donator' => 'The offline setting was set, when the user is not a donator', | ||
2435 | 2419 | '!active' => 'The hostname specified is in a Custom DNS domain which has not yet been activated.', | ||
2436 | 2420 | 'abuse', => 'The hostname specified is blocked for abuse; you should receive an email notification ' . | ||
2437 | 2421 | 'which provides an unblock request link. More info can be found on ' . | ||
2438 | 2422 | 'https://www.dyndns.com/support/abuse.html', | ||
2439 | 2423 | |||
2440 | 2424 | 'numhost' => 'System error: Too many or too few hosts found. Contact support@dyndns.org', | ||
2441 | 2425 | 'dnserr' => 'System error: DNS error encountered. Contact support@dyndns.org', | ||
2442 | 2426 | |||
2443 | 2427 | 'nochg' => 'No update required; unnecessary attempts to change to the current address are considered abusive', | ||
2444 | 2428 | ); | ||
2445 | 2429 | |||
2446 | 2430 | ## update each set of hosts that had similar configurations | ||
2447 | 2431 | foreach my $sig (keys %groups) { | ||
2448 | 2432 | my @hosts = @{$groups{$sig}}; | ||
2449 | 2433 | my $hosts = join(',', @hosts); | ||
2450 | 2434 | my $h = $hosts[0]; | ||
2451 | 2435 | my $ip = $config{$h}{'wantip'}; | ||
2452 | 2436 | delete $config{$_}{'wantip'} foreach @hosts; | ||
2453 | 2437 | |||
2454 | 2438 | info("setting IP address to %s for %s", $ip, $hosts); | ||
2455 | 2439 | verbose("UPDATE:","updating %s", $hosts); | ||
2456 | 2440 | |||
2457 | 2441 | ## Select the DynDNS system to update | ||
2458 | 2442 | my $url = "http://$config{$h}{'server'}$config{$h}{'script'}?system="; | ||
2459 | 2443 | if ($config{$h}{'custom'}) { | ||
2460 | 2444 | warning("updating %s: 'custom' and 'static' may not be used together. ('static' ignored)", $hosts) | ||
2461 | 2445 | if $config{$h}{'static'}; | ||
2462 | 2446 | # warning("updating %s: 'custom' and 'offline' may not be used together. ('offline' ignored)", $hosts) | ||
2463 | 2447 | # if $config{$h}{'offline'}; | ||
2464 | 2448 | $url .= 'custom'; | ||
2465 | 2449 | |||
2466 | 2450 | } elsif ($config{$h}{'static'}) { | ||
2467 | 2451 | # warning("updating %s: 'static' and 'offline' may not be used together. ('offline' ignored)", $hosts) | ||
2468 | 2452 | # if $config{$h}{'offline'}; | ||
2469 | 2453 | $url .= 'statdns'; | ||
2470 | 2454 | |||
2471 | 2455 | } else { | ||
2472 | 2456 | $url .= 'dyndns'; | ||
2473 | 2457 | } | ||
2474 | 2458 | |||
2475 | 2459 | $url .= "&hostname=$hosts"; | ||
2476 | 2460 | $url .= "&myip="; | ||
2477 | 2461 | $url .= $ip if $ip; | ||
2478 | 2462 | |||
2479 | 2463 | ## some args are not valid for a custom domain. | ||
2480 | 2464 | $url .= "&wildcard=ON" if ynu($config{$h}{'wildcard'}, 1, 0, 0); | ||
2481 | 2465 | if ($config{$h}{'mx'}) { | ||
2482 | 2466 | $url .= "&mx=$config{$h}{'mx'}"; | ||
2483 | 2467 | $url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO'); | ||
2484 | 2468 | } | ||
2485 | 2469 | |||
2486 | 2470 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
2487 | 2471 | if (!defined($reply) || !$reply) { | ||
2488 | 2472 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); | ||
2489 | 2473 | last; | ||
2490 | 2474 | } | ||
2491 | 2475 | last if !header_ok($hosts, $reply); | ||
2492 | 2476 | |||
2493 | 2477 | my @reply = split /\n/, $reply; | ||
2494 | 2478 | my $state = 'header'; | ||
2495 | 2479 | my $returnedip = $ip; | ||
2496 | 2480 | |||
2497 | 2481 | foreach my $line (@reply) { | ||
2498 | 2482 | if ($state eq 'header') { | ||
2499 | 2483 | $state = 'body'; | ||
2500 | 2484 | |||
2501 | 2485 | } elsif ($state eq 'body') { | ||
2502 | 2486 | $state = 'results' if $line eq ''; | ||
2503 | 2487 | |||
2504 | 2488 | } elsif ($state =~ /^results/) { | ||
2505 | 2489 | $state = 'results2'; | ||
2506 | 2490 | |||
2507 | 2491 | # bug #10: some dyndns providers does not return the IP so | ||
2508 | 2492 | # we can't use the returned IP | ||
2509 | 2493 | my ($status, $returnedip) = split / /, lc $line; | ||
2510 | 2494 | $ip = $returnedip if (not $ip); | ||
2511 | 2495 | my $h = shift @hosts; | ||
2512 | 2496 | |||
2513 | 2497 | $config{$h}{'status'} = $status; | ||
2514 | 2498 | if ($status eq 'good') { | ||
2515 | 2499 | $config{$h}{'ip'} = $ip; | ||
2516 | 2500 | $config{$h}{'mtime'} = $now; | ||
2517 | 2501 | success("updating %s: %s: IP address set to %s", $h, $status, $ip); | ||
2518 | 2502 | |||
2519 | 2503 | } elsif (exists $errors{$status}) { | ||
2520 | 2504 | if ($status eq 'nochg') { | ||
2521 | 2505 | warning("updating %s: %s: %s", $h, $status, $errors{$status}); | ||
2522 | 2506 | $config{$h}{'ip'} = $ip; | ||
2523 | 2507 | $config{$h}{'mtime'} = $now; | ||
2524 | 2508 | $config{$h}{'status'} = 'good'; | ||
2525 | 2509 | |||
2526 | 2510 | } else { | ||
2527 | 2511 | failed("updating %s: %s: %s", $h, $status, $errors{$status}); | ||
2528 | 2512 | } | ||
2529 | 2513 | |||
2530 | 2514 | } elsif ($status =~ /w(\d+)(.)/) { | ||
2531 | 2515 | my ($wait, $units) = ($1, lc $2); | ||
2532 | 2516 | my ($sec, $scale) = ($wait, 1); | ||
2533 | 2517 | |||
2534 | 2518 | ($scale, $units) = (1, 'seconds') if $units eq 's'; | ||
2535 | 2519 | ($scale, $units) = (60, 'minutes') if $units eq 'm'; | ||
2536 | 2520 | ($scale, $units) = (60*60, 'hours') if $units eq 'h'; | ||
2537 | 2521 | |||
2538 | 2522 | $sec = $wait * $scale; | ||
2539 | 2523 | $config{$h}{'wtime'} = $now + $sec; | ||
2540 | 2524 | warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip); | ||
2541 | 2525 | |||
2542 | 2526 | } else { | ||
2543 | 2527 | failed("updating %s: %s: unexpected status (%s)", $h, $line); | ||
2544 | 2528 | } | ||
2545 | 2529 | } | ||
2546 | 2530 | } | ||
2547 | 2531 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}) | ||
2548 | 2532 | if $state ne 'results2'; | ||
2549 | 2533 | } | ||
2550 | 2534 | } | ||
2551 | 2535 | |||
2552 | 2536 | |||
2553 | 2537 | ###################################################################### | ||
2554 | 2538 | ## nic_noip_update | ||
2555 | 2539 | ## Note: uses same features as nic_dyndns2_update, less return codes | ||
2556 | 2540 | ###################################################################### | ||
2557 | 2541 | sub nic_noip_update { | ||
2558 | 2542 | debug("\nnic_noip_update -------------------"); | ||
2559 | 2543 | |||
2560 | 2544 | ## group hosts with identical attributes together | ||
2561 | 2545 | my %groups = group_hosts_by([ @_ ], [ qw(login password server static custom wildcard mx backupmx) ]); | ||
2562 | 2546 | |||
2563 | 2547 | my %errors = ( | ||
2564 | 2548 | 'badauth' => 'Invalid username or password', | ||
2565 | 2549 | 'badagent' => 'Invalid user agent', | ||
2566 | 2550 | 'nohost' => 'The hostname specified does not exist in the database', | ||
2567 | 2551 | '!donator' => 'The offline setting was set, when the user is not a donator', | ||
2568 | 2552 | 'abuse', => 'The hostname specified is blocked for abuse; open a trouble ticket at http://www.no-ip.com', | ||
2569 | 2553 | 'numhost' => 'System error: Too many or too few hosts found. open a trouble ticket at http://www.no-ip.com', | ||
2570 | 2554 | 'dnserr' => 'System error: DNS error encountered. Contact support@dyndns.org', | ||
2571 | 2555 | 'nochg' => 'No update required; unnecessary attempts to change to the current address are considered abusive', | ||
2572 | 2556 | ); | ||
2573 | 2557 | |||
2574 | 2558 | ## update each set of hosts that had similar configurations | ||
2575 | 2559 | foreach my $sig (keys %groups) { | ||
2576 | 2560 | my @hosts = @{$groups{$sig}}; | ||
2577 | 2561 | my $hosts = join(',', @hosts); | ||
2578 | 2562 | my $h = $hosts[0]; | ||
2579 | 2563 | my $ip = $config{$h}{'wantip'}; | ||
2580 | 2564 | delete $config{$_}{'wantip'} foreach @hosts; | ||
2581 | 2565 | |||
2582 | 2566 | info("setting IP address to %s for %s", $ip, $hosts); | ||
2583 | 2567 | verbose("UPDATE:","updating %s", $hosts); | ||
2584 | 2568 | |||
2585 | 2569 | my $url = "http://$config{$h}{'server'}/nic/update?system="; | ||
2586 | 2570 | $url .= 'noip'; | ||
2587 | 2571 | $url .= "&hostname=$hosts"; | ||
2588 | 2572 | $url .= "&myip="; | ||
2589 | 2573 | $url .= $ip if $ip; | ||
2590 | 2574 | |||
2591 | 2575 | |||
2592 | 2576 | print "here..." . $config{$h}{'login'} . " --> " . $config{$h}{'password'} . "\n"; | ||
2593 | 2577 | |||
2594 | 2578 | |||
2595 | 2579 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
2596 | 2580 | if (!defined($reply) || !$reply) { | ||
2597 | 2581 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); | ||
2598 | 2582 | last; | ||
2599 | 2583 | } | ||
2600 | 2584 | last if !header_ok($hosts, $reply); | ||
2601 | 2585 | |||
2602 | 2586 | my @reply = split /\n/, $reply; | ||
2603 | 2587 | my $state = 'header'; | ||
2604 | 2588 | foreach my $line (@reply) { | ||
2605 | 2589 | if ($state eq 'header') { | ||
2606 | 2590 | $state = 'body'; | ||
2607 | 2591 | |||
2608 | 2592 | } elsif ($state eq 'body') { | ||
2609 | 2593 | $state = 'results' if $line eq ''; | ||
2610 | 2594 | |||
2611 | 2595 | } elsif ($state =~ /^results/) { | ||
2612 | 2596 | $state = 'results2'; | ||
2613 | 2597 | |||
2614 | 2598 | my ($status, $ip) = split / /, lc $line; | ||
2615 | 2599 | my $h = shift @hosts; | ||
2616 | 2600 | |||
2617 | 2601 | $config{$h}{'status'} = $status; | ||
2618 | 2602 | if ($status eq 'good') { | ||
2619 | 2603 | $config{$h}{'ip'} = $ip; | ||
2620 | 2604 | $config{$h}{'mtime'} = $now; | ||
2621 | 2605 | success("updating %s: %s: IP address set to %s", $h, $status, $ip); | ||
2622 | 2606 | |||
2623 | 2607 | } elsif (exists $errors{$status}) { | ||
2624 | 2608 | if ($status eq 'nochg') { | ||
2625 | 2609 | warning("updating %s: %s: %s", $h, $status, $errors{$status}); | ||
2626 | 2610 | $config{$h}{'ip'} = $ip; | ||
2627 | 2611 | $config{$h}{'mtime'} = $now; | ||
2628 | 2612 | $config{$h}{'status'} = 'good'; | ||
2629 | 2613 | |||
2630 | 2614 | } else { | ||
2631 | 2615 | failed("updating %s: %s: %s", $h, $status, $errors{$status}); | ||
2632 | 2616 | } | ||
2633 | 2617 | |||
2634 | 2618 | } elsif ($status =~ /w(\d+)(.)/) { | ||
2635 | 2619 | my ($wait, $units) = ($1, lc $2); | ||
2636 | 2620 | my ($sec, $scale) = ($wait, 1); | ||
2637 | 2621 | |||
2638 | 2622 | ($scale, $units) = (1, 'seconds') if $units eq 's'; | ||
2639 | 2623 | ($scale, $units) = (60, 'minutes') if $units eq 'm'; | ||
2640 | 2624 | ($scale, $units) = (60*60, 'hours') if $units eq 'h'; | ||
2641 | 2625 | |||
2642 | 2626 | $sec = $wait * $scale; | ||
2643 | 2627 | $config{$h}{'wtime'} = $now + $sec; | ||
2644 | 2628 | warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip); | ||
2645 | 2629 | |||
2646 | 2630 | } else { | ||
2647 | 2631 | failed("updating %s: %s: unexpected status (%s)", $h, $line); | ||
2648 | 2632 | } | ||
2649 | 2633 | } | ||
2650 | 2634 | } | ||
2651 | 2635 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}) | ||
2652 | 2636 | if $state ne 'results2'; | ||
2653 | 2637 | } | ||
2654 | 2638 | } | ||
2655 | 2639 | ###################################################################### | ||
2656 | 2640 | ## nic_noip_examples | ||
2657 | 2641 | ###################################################################### | ||
2658 | 2642 | sub nic_noip_examples { | ||
2659 | 2643 | return <<EoEXAMPLE; | ||
2660 | 2644 | o 'noip' | ||
2661 | 2645 | |||
2662 | 2646 | The 'No-IP Compatible' protocol is used to make dynamic dns updates | ||
2663 | 2647 | over an http request. Details of the protocol are outlined at: | ||
2664 | 2648 | http://www.no-ip.com/integrate/ | ||
2665 | 2649 | |||
2666 | 2650 | Configuration variables applicable to the 'noip' protocol are: | ||
2667 | 2651 | protocol=noip ## | ||
2668 | 2652 | server=fqdn.of.service ## defaults to dynupdate.no-ip.com | ||
2669 | 2653 | login=service-login ## login name and password registered with the service | ||
2670 | 2654 | password=service-password ## | ||
2671 | 2655 | fully.qualified.host ## the host registered with the service. | ||
2672 | 2656 | |||
2673 | 2657 | Example ${program}.conf file entries: | ||
2674 | 2658 | ## single host update | ||
2675 | 2659 | protocol=noip, \\ | ||
2676 | 2660 | login=userlogin\@domain.com, \\ | ||
2677 | 2661 | password=noip-password \\ | ||
2678 | 2662 | myhost.no-ip.biz | ||
2679 | 2663 | |||
2680 | 2664 | |||
2681 | 2665 | EoEXAMPLE | ||
2682 | 2666 | } | ||
2683 | 2667 | |||
2684 | 2668 | ###################################################################### | ||
2685 | 2669 | ## nic_concont_examples | ||
2686 | 2670 | ###################################################################### | ||
2687 | 2671 | sub nic_concont_examples { | ||
2688 | 2672 | return <<EoEXAMPLE; | ||
2689 | 2673 | o 'concont' | ||
2690 | 2674 | |||
2691 | 2675 | The 'concont' protocol is the protocol used by the content management | ||
2692 | 2676 | system ConCont's dydns module. This is currently used by the free | ||
2693 | 2677 | dynamic DNS service offered by Tyrmida at www.dydns.za.net | ||
2694 | 2678 | |||
2695 | 2679 | Configuration variables applicable to the 'concont' protocol are: | ||
2696 | 2680 | protocol=concont ## | ||
2697 | 2681 | server=www.fqdn.of.service ## for example www.dydns.za.net (for most add a www) | ||
2698 | 2682 | login=service-login ## login registered with the service | ||
2699 | 2683 | password=service-password ## password registered with the service | ||
2700 | 2684 | mx=mail.server.fqdn ## fqdn of the server handling domain\'s mail (leave out for none) | ||
2701 | 2685 | wildcard=yes|no ## set yes for wild (*.host.domain) support | ||
2702 | 2686 | fully.qualified.host ## the host registered with the service. | ||
2703 | 2687 | |||
2704 | 2688 | Example ${program}.conf file entries: | ||
2705 | 2689 | ## single host update | ||
2706 | 2690 | protocol=concont, \\ | ||
2707 | 2691 | login=dydns.za.net, \\ | ||
2708 | 2692 | password=my-dydns.za.net-password, \\ | ||
2709 | 2693 | mx=mailserver.fqdn, \\ | ||
2710 | 2694 | wildcard=yes \\ | ||
2711 | 2695 | myhost.hn.org | ||
2712 | 2696 | |||
2713 | 2697 | EoEXAMPLE | ||
2714 | 2698 | } | ||
2715 | 2699 | ###################################################################### | ||
2716 | 2700 | ## nic_concont_update | ||
2717 | 2701 | ###################################################################### | ||
2718 | 2702 | sub nic_concont_update { | ||
2719 | 2703 | debug("\nnic_concont_update -------------------"); | ||
2720 | 2704 | |||
2721 | 2705 | ## update each configured host | ||
2722 | 2706 | foreach my $h (@_) { | ||
2723 | 2707 | my $ip = delete $config{$h}{'wantip'}; | ||
2724 | 2708 | info("setting IP address to %s for %s", $ip, $h); | ||
2725 | 2709 | verbose("UPDATE:","updating %s", $h); | ||
2726 | 2710 | |||
2727 | 2711 | # Set the URL that we're going to to update | ||
2728 | 2712 | my $url; | ||
2729 | 2713 | $url = "http://$config{$h}{'server'}/modules/dydns/update.php"; | ||
2730 | 2714 | $url .= "?username="; | ||
2731 | 2715 | $url .= $config{$h}{'login'}; | ||
2732 | 2716 | $url .= "&password="; | ||
2733 | 2717 | $url .= $config{$h}{'password'}; | ||
2734 | 2718 | $url .= "&wildcard="; | ||
2735 | 2719 | $url .= $config{$h}{'wildcard'}; | ||
2736 | 2720 | $url .= "&mx="; | ||
2737 | 2721 | $url .= $config{$h}{'mx'}; | ||
2738 | 2722 | $url .= "&host="; | ||
2739 | 2723 | $url .= $h; | ||
2740 | 2724 | $url .= "&ip="; | ||
2741 | 2725 | $url .= $ip; | ||
2742 | 2726 | |||
2743 | 2727 | # Try to get URL | ||
2744 | 2728 | my $reply = geturl(opt('proxy'), $url); | ||
2745 | 2729 | |||
2746 | 2730 | # No response, declare as failed | ||
2747 | 2731 | if (!defined($reply) || !$reply) { | ||
2748 | 2732 | failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); | ||
2749 | 2733 | last; | ||
2750 | 2734 | } | ||
2751 | 2735 | last if !header_ok($h, $reply); | ||
2752 | 2736 | |||
2753 | 2737 | # Response found, just declare as success (this is ugly, we need more error checking) | ||
2754 | 2738 | if ($reply =~ /SUCCESS/) | ||
2755 | 2739 | { | ||
2756 | 2740 | $config{$h}{'ip'} = $ip; | ||
2757 | 2741 | $config{$h}{'mtime'} = $now; | ||
2758 | 2742 | $config{$h}{'status'} = 'good'; | ||
2759 | 2743 | success("updating %s: good: IP address set to %s", $h, $ip); | ||
2760 | 2744 | } | ||
2761 | 2745 | else | ||
2762 | 2746 | { | ||
2763 | 2747 | my @reply = split /\n/, $reply; | ||
2764 | 2748 | my $returned = pop(@reply); | ||
2765 | 2749 | $config{$h}{'status'} = 'failed'; | ||
2766 | 2750 | failed("updating %s: Server said: '$returned'", $h); | ||
2767 | 2751 | } | ||
2768 | 2752 | } | ||
2769 | 2753 | } | ||
2770 | 2754 | ###################################################################### | ||
2771 | 2755 | ## nic_dslreports1_examples | ||
2772 | 2756 | ###################################################################### | ||
2773 | 2757 | sub nic_dslreports1_examples { | ||
2774 | 2758 | return <<EoEXAMPLE; | ||
2775 | 2759 | o 'dslreports1' | ||
2776 | 2760 | |||
2777 | 2761 | The 'dslreports1' protocol is used by a free DSL monitoring service | ||
2778 | 2762 | offered by www.dslreports.com. | ||
2779 | 2763 | |||
2780 | 2764 | Configuration variables applicable to the 'dslreports1' protocol are: | ||
2781 | 2765 | protocol=dslreports1 ## | ||
2782 | 2766 | server=fqdn.of.service ## defaults to www.dslreports.com | ||
2783 | 2767 | login=service-login ## login name and password registered with the service | ||
2784 | 2768 | password=service-password ## | ||
2785 | 2769 | unique-number ## the host registered with the service. | ||
2786 | 2770 | |||
2787 | 2771 | Example ${program}.conf file entries: | ||
2788 | 2772 | ## single host update | ||
2789 | 2773 | protocol=dslreports1, \\ | ||
2790 | 2774 | server=www.dslreports.com, \\ | ||
2791 | 2775 | login=my-dslreports-login, \\ | ||
2792 | 2776 | password=my-dslreports-password \\ | ||
2793 | 2777 | 123456 | ||
2794 | 2778 | |||
2795 | 2779 | Note: DSL Reports uses a unique number as the host name. This number | ||
2796 | 2780 | can be found on the Monitor Control web page. | ||
2797 | 2781 | EoEXAMPLE | ||
2798 | 2782 | } | ||
2799 | 2783 | ###################################################################### | ||
2800 | 2784 | ## nic_dslreports1_update | ||
2801 | 2785 | ###################################################################### | ||
2802 | 2786 | sub nic_dslreports1_update { | ||
2803 | 2787 | debug("\nnic_dslreports1_update -------------------"); | ||
2804 | 2788 | ## update each configured host | ||
2805 | 2789 | foreach my $h (@_) { | ||
2806 | 2790 | my $ip = delete $config{$h}{'wantip'}; | ||
2807 | 2791 | info("setting IP address to %s for %s", $ip, $h); | ||
2808 | 2792 | verbose("UPDATE:","updating %s", $h); | ||
2809 | 2793 | |||
2810 | 2794 | my $url; | ||
2811 | 2795 | $url = "http://$config{$h}{'server'}/nic/"; | ||
2812 | 2796 | $url .= ynu($config{$h}{'static'}, 'statdns', 'dyndns', 'dyndns'); | ||
2813 | 2797 | $url .= "?action=edit&started=1&hostname=YES&host_id=$h"; | ||
2814 | 2798 | $url .= "&myip="; | ||
2815 | 2799 | $url .= $ip if $ip; | ||
2816 | 2800 | |||
2817 | 2801 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
2818 | 2802 | if (!defined($reply) || !$reply) { | ||
2819 | 2803 | failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); | ||
2820 | 2804 | next; | ||
2821 | 2805 | } | ||
2822 | 2806 | |||
2823 | 2807 | my @reply = split /\n/, $reply; | ||
2824 | 2808 | my $return_code = ''; | ||
2825 | 2809 | foreach my $line (@reply) { | ||
2826 | 2810 | $return_code = $1 if $line =~ m%^return\s+code\s*:\s*(.*)\s*$%i; | ||
2827 | 2811 | } | ||
2828 | 2812 | |||
2829 | 2813 | if ($return_code !~ /NOERROR/) { | ||
2830 | 2814 | $config{$h}{'status'} = 'failed'; | ||
2831 | 2815 | warning("SENT: %s", $url) unless opt('verbose'); | ||
2832 | 2816 | warning("REPLIED: %s", $reply); | ||
2833 | 2817 | failed("updating %s", $h); | ||
2834 | 2818 | |||
2835 | 2819 | } else { | ||
2836 | 2820 | $config{$h}{'ip'} = $ip; | ||
2837 | 2821 | $config{$h}{'mtime'} = $now; | ||
2838 | 2822 | $config{$h}{'status'} = 'good'; | ||
2839 | 2823 | success("updating %s: %s: IP address set to %s", $h, $return_code, $ip); | ||
2840 | 2824 | } | ||
2841 | 2825 | } | ||
2842 | 2826 | } | ||
2843 | 2827 | ###################################################################### | ||
2844 | 2828 | ## nic_hammernode1_examples | ||
2845 | 2829 | ###################################################################### | ||
2846 | 2830 | sub nic_hammernode1_examples { | ||
2847 | 2831 | return <<EoEXAMPLE; | ||
2848 | 2832 | o 'hammernode1' | ||
2849 | 2833 | |||
2850 | 2834 | The 'hammernode1' protocol is the protocol used by the free dynamic | ||
2851 | 2835 | DNS service offered by Hammernode at www.hn.org | ||
2852 | 2836 | |||
2853 | 2837 | Configuration variables applicable to the 'hammernode1' protocol are: | ||
2854 | 2838 | protocol=hammernode1 ## | ||
2855 | 2839 | server=fqdn.of.service ## defaults to members.dyndns.org | ||
2856 | 2840 | login=service-login ## login name and password registered with the service | ||
2857 | 2841 | password=service-password ## | ||
2858 | 2842 | fully.qualified.host ## the host registered with the service. | ||
2859 | 2843 | |||
2860 | 2844 | Example ${program}.conf file entries: | ||
2861 | 2845 | ## single host update | ||
2862 | 2846 | protocol=hammernode1, \\ | ||
2863 | 2847 | login=my-hn.org-login, \\ | ||
2864 | 2848 | password=my-hn.org-password \\ | ||
2865 | 2849 | myhost.hn.org | ||
2866 | 2850 | |||
2867 | 2851 | ## multiple host update | ||
2868 | 2852 | protocol=hammernode1, \\ | ||
2869 | 2853 | login=my-hn.org-login, \\ | ||
2870 | 2854 | password=my-hn.org-password, \\ | ||
2871 | 2855 | myhost.hn.org,my2ndhost.hn.org | ||
2872 | 2856 | EoEXAMPLE | ||
2873 | 2857 | } | ||
2874 | 2858 | ###################################################################### | ||
2875 | 2859 | ## nic_hammernode1_update | ||
2876 | 2860 | ###################################################################### | ||
2877 | 2861 | sub nic_hammernode1_update { | ||
2878 | 2862 | debug("\nnic_hammernode1_update -------------------"); | ||
2879 | 2863 | |||
2880 | 2864 | ## update each configured host | ||
2881 | 2865 | foreach my $h (@_) { | ||
2882 | 2866 | my $ip = delete $config{$h}{'wantip'}; | ||
2883 | 2867 | info("setting IP address to %s for %s", $ip, $h); | ||
2884 | 2868 | verbose("UPDATE:","updating %s", $h); | ||
2885 | 2869 | |||
2886 | 2870 | my $url; | ||
2887 | 2871 | $url = "http://$config{$h}{'server'}/vanity/update"; | ||
2888 | 2872 | $url .= "?ver=1"; | ||
2889 | 2873 | $url .= "&ip="; | ||
2890 | 2874 | $url .= $ip if $ip; | ||
2891 | 2875 | |||
2892 | 2876 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
2893 | 2877 | if (!defined($reply) || !$reply) { | ||
2894 | 2878 | failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); | ||
2895 | 2879 | last; | ||
2896 | 2880 | } | ||
2897 | 2881 | last if !header_ok($h, $reply); | ||
2898 | 2882 | |||
2899 | 2883 | my @reply = split /\n/, $reply; | ||
2900 | 2884 | if (grep /<!--\s+DDNS_Response_Code=101\s+-->/i, @reply) { | ||
2901 | 2885 | $config{$h}{'ip'} = $ip; | ||
2902 | 2886 | $config{$h}{'mtime'} = $now; | ||
2903 | 2887 | $config{$h}{'status'} = 'good'; | ||
2904 | 2888 | success("updating %s: good: IP address set to %s", $h, $ip); | ||
2905 | 2889 | } else { | ||
2906 | 2890 | $config{$h}{'status'} = 'failed'; | ||
2907 | 2891 | warning("SENT: %s", $url) unless opt('verbose'); | ||
2908 | 2892 | warning("REPLIED: %s", $reply); | ||
2909 | 2893 | failed("updating %s: Invalid reply.", $h); | ||
2910 | 2894 | } | ||
2911 | 2895 | } | ||
2912 | 2896 | } | ||
2913 | 2897 | ###################################################################### | ||
2914 | 2898 | ## nic_zoneedit1_examples | ||
2915 | 2899 | ###################################################################### | ||
2916 | 2900 | sub nic_zoneedit1_examples { | ||
2917 | 2901 | return <<EoEXAMPLE; | ||
2918 | 2902 | o 'zoneedit1' | ||
2919 | 2903 | |||
2920 | 2904 | The 'zoneedit1' protocol is used by a DNS service offered by | ||
2921 | 2905 | www.zoneedit.com. | ||
2922 | 2906 | |||
2923 | 2907 | Configuration variables applicable to the 'zoneedit1' protocol are: | ||
2924 | 2908 | protocol=zoneedit1 ## | ||
2925 | 2909 | server=fqdn.of.service ## defaults to www.zoneedit.com | ||
2926 | 2910 | zone=zone-where-domains-are ## only needed if 1 or more subdomains are deeper | ||
2927 | 2911 | ## than 1 level in relation to the zone where it | ||
2928 | 2912 | ## is defined. For example, b.foo.com in a zone | ||
2929 | 2913 | ## foo.com doesn't need this, but a.b.foo.com in | ||
2930 | 2914 | ## the same zone needs zone=foo.com | ||
2931 | 2915 | login=service-login ## login name and password registered with the service | ||
2932 | 2916 | password=service-password ## | ||
2933 | 2917 | your.domain.name ## the host registered with the service. | ||
2934 | 2918 | |||
2935 | 2919 | Example ${program}.conf file entries: | ||
2936 | 2920 | ## single host update | ||
2937 | 2921 | protocol=zoneedit1, \\ | ||
2938 | 2922 | server=dynamic.zoneedit.com, \\ | ||
2939 | 2923 | zone=zone-where-domains-are, \\ | ||
2940 | 2924 | login=my-zoneedit-login, \\ | ||
2941 | 2925 | password=my-zoneedit-password \\ | ||
2942 | 2926 | my.domain.name | ||
2943 | 2927 | EoEXAMPLE | ||
2944 | 2928 | } | ||
2945 | 2929 | |||
2946 | 2930 | ###################################################################### | ||
2947 | 2931 | ## nic_zoneedit1_updateable | ||
2948 | 2932 | ###################################################################### | ||
2949 | 2933 | sub nic_zoneedit1_updateable { | ||
2950 | 2934 | return 0; | ||
2951 | 2935 | } | ||
2952 | 2936 | |||
2953 | 2937 | ###################################################################### | ||
2954 | 2938 | ## nic_zoneedit1_update | ||
2955 | 2939 | # <SUCCESS CODE="200" TEXT="Update succeeded." ZONE="trialdomain.com" IP="127.0.0.12"> | ||
2956 | 2940 | # <SUCCESS CODE="201" TEXT="No records need updating." ZONE="bannedware.com"> | ||
2957 | 2941 | # <ERROR CODE="701" TEXT="Zone is not set up in this account." ZONE="bad.com"> | ||
2958 | 2942 | ###################################################################### | ||
2959 | 2943 | sub nic_zoneedit1_update { | ||
2960 | 2944 | debug("\nnic_zoneedit1_update -------------------"); | ||
2961 | 2945 | |||
2962 | 2946 | ## group hosts with identical attributes together | ||
2963 | 2947 | my %groups = group_hosts_by([ @_ ], [ qw(login password server zone) ]); | ||
2964 | 2948 | |||
2965 | 2949 | ## update each set of hosts that had similar configurations | ||
2966 | 2950 | foreach my $sig (keys %groups) { | ||
2967 | 2951 | my @hosts = @{$groups{$sig}}; | ||
2968 | 2952 | my $hosts = join(',', @hosts); | ||
2969 | 2953 | my $h = $hosts[0]; | ||
2970 | 2954 | my $ip = $config{$h}{'wantip'}; | ||
2971 | 2955 | delete $config{$_}{'wantip'} foreach @hosts; | ||
2972 | 2956 | |||
2973 | 2957 | info("setting IP address to %s for %s", $ip, $hosts); | ||
2974 | 2958 | verbose("UPDATE:","updating %s", $hosts); | ||
2975 | 2959 | |||
2976 | 2960 | my $url = ''; | ||
2977 | 2961 | $url .= "http://$config{$h}{'server'}/auth/dynamic.html"; | ||
2978 | 2962 | $url .= "?host=$hosts"; | ||
2979 | 2963 | $url .= "&dnsto=$ip" if $ip; | ||
2980 | 2964 | $url .= "&zone=$config{$h}{'zone'}" if defined $config{$h}{'zone'}; | ||
2981 | 2965 | |||
2982 | 2966 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
2983 | 2967 | if (!defined($reply) || !$reply) { | ||
2984 | 2968 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); | ||
2985 | 2969 | last; | ||
2986 | 2970 | } | ||
2987 | 2971 | last if !header_ok($hosts, $reply); | ||
2988 | 2972 | |||
2989 | 2973 | my @reply = split /\n/, $reply; | ||
2990 | 2974 | foreach my $line (@reply) { | ||
2991 | 2975 | if ($line =~ /^[^<]*<(SUCCESS|ERROR)\s+([^>]+)>(.*)/) { | ||
2992 | 2976 | my ($status, $assignments, $rest) = ($1, $2, $3); | ||
2993 | 2977 | my ($left, %var) = parse_assignments($assignments); | ||
2994 | 2978 | |||
2995 | 2979 | if (keys %var) { | ||
2996 | 2980 | my ($status_code, $status_text, $status_ip) = ('999', '', $ip); | ||
2997 | 2981 | $status_code = $var{'CODE'} if exists $var{'CODE'}; | ||
2998 | 2982 | $status_text = $var{'TEXT'} if exists $var{'TEXT'}; | ||
2999 | 2983 | $status_ip = $var{'IP'} if exists $var{'IP'}; | ||
3000 | 2984 | |||
3001 | 2985 | if ($status eq 'SUCCESS' || ($status eq 'ERROR' && $var{'CODE'} eq '707')) { | ||
3002 | 2986 | $config{$h}{'ip'} = $status_ip; | ||
3003 | 2987 | $config{$h}{'mtime'} = $now; | ||
3004 | 2988 | $config{$h}{'status'} = 'good'; | ||
3005 | 2989 | |||
3006 | 2990 | success("updating %s: IP address set to %s (%s: %s)", $h, $ip, $status_code, $status_text); | ||
3007 | 2991 | |||
3008 | 2992 | } else { | ||
3009 | 2993 | $config{$h}{'status'} = 'failed'; | ||
3010 | 2994 | failed("updating %s: %s: %s", $h, $status_code, $status_text); | ||
3011 | 2995 | } | ||
3012 | 2996 | shift @hosts; | ||
3013 | 2997 | $h = $hosts[0]; | ||
3014 | 2998 | $hosts = join(',', @hosts); | ||
3015 | 2999 | } | ||
3016 | 3000 | $line = $rest; | ||
3017 | 3001 | redo if $line; | ||
3018 | 3002 | } | ||
3019 | 3003 | } | ||
3020 | 3004 | failed("updating %s: no response from %s", $hosts, $config{$h}{'server'}) | ||
3021 | 3005 | if @hosts; | ||
3022 | 3006 | } | ||
3023 | 3007 | } | ||
3024 | 3008 | ###################################################################### | ||
3025 | 3009 | ## nic_easydns_updateable | ||
3026 | 3010 | ###################################################################### | ||
3027 | 3011 | sub nic_easydns_updateable { | ||
3028 | 3012 | my $host = shift; | ||
3029 | 3013 | my $update = 0; | ||
3030 | 3014 | |||
3031 | 3015 | if ($config{$host}{'mx'} ne $cache{$host}{'mx'}) { | ||
3032 | 3016 | info("forcing updating %s because 'mx' has changed to %s.", $host, $config{$host}{'mx'}); | ||
3033 | 3017 | $update = 1; | ||
3034 | 3018 | |||
3035 | 3019 | } elsif ($config{$host}{'mx'} && (ynu($config{$host}{'backupmx'},1,2,3) ne ynu($config{$host}{'backupmx'},1,2,3))) { | ||
3036 | 3020 | info("forcing updating %s because 'backupmx' has changed to %s.", $host, ynu($config{$host}{'backupmx'},"YES","NO","NO")); | ||
3037 | 3021 | $update = 1; | ||
3038 | 3022 | |||
3039 | 3023 | } elsif ($config{$host}{'static'} ne $cache{$host}{'static'}) { | ||
3040 | 3024 | |||
3041 | 3025 | info("forcing updating %s because 'static' has changed to %s.", $host, ynu($config{$host}{'static'},"YES","NO","NO")); | ||
3042 | 3026 | $update = 1; | ||
3043 | 3027 | |||
3044 | 3028 | } | ||
3045 | 3029 | return $update; | ||
3046 | 3030 | } | ||
3047 | 3031 | ###################################################################### | ||
3048 | 3032 | ## nic_easydns_examples | ||
3049 | 3033 | ###################################################################### | ||
3050 | 3034 | sub nic_easydns_examples { | ||
3051 | 3035 | return <<EoEXAMPLE; | ||
3052 | 3036 | o 'easydns' | ||
3053 | 3037 | |||
3054 | 3038 | The 'easydns' protocol is used by the for fee DNS service offered | ||
3055 | 3039 | by www.easydns.com. | ||
3056 | 3040 | |||
3057 | 3041 | Configuration variables applicable to the 'easydns' protocol are: | ||
3058 | 3042 | protocol=easydns ## | ||
3059 | 3043 | server=fqdn.of.service ## defaults to members.easydns.com | ||
3060 | 3044 | backupmx=no|yes ## indicates that EasyDNS should be the secondary MX | ||
3061 | 3045 | ## for this domain or host. | ||
3062 | 3046 | mx=any.host.domain ## a host MX'ing for this host or domain. | ||
3063 | 3047 | wildcard=no|yes ## add a DNS wildcard CNAME record that points to {host} | ||
3064 | 3048 | login=service-login ## login name and password registered with the service | ||
3065 | 3049 | password=service-password ## | ||
3066 | 3050 | fully.qualified.host ## the host registered with the service. | ||
3067 | 3051 | |||
3068 | 3052 | Example ${program}.conf file entries: | ||
3069 | 3053 | ## single host update | ||
3070 | 3054 | protocol=easydns, \\ | ||
3071 | 3055 | login=my-easydns.com-login, \\ | ||
3072 | 3056 | password=my-easydns.com-password \\ | ||
3073 | 3057 | myhost.easydns.com | ||
3074 | 3058 | |||
3075 | 3059 | ## multiple host update with wildcard'ing mx, and backupmx | ||
3076 | 3060 | protocol=easydns, \\ | ||
3077 | 3061 | login=my-easydns.com-login, \\ | ||
3078 | 3062 | password=my-easydns.com-password, \\ | ||
3079 | 3063 | mx=a.host.willing.to.mx.for.me, \\ | ||
3080 | 3064 | backupmx=yes, \\ | ||
3081 | 3065 | wildcard=yes \\ | ||
3082 | 3066 | my-toplevel-domain.com,my-other-domain.com | ||
3083 | 3067 | |||
3084 | 3068 | ## multiple host update to the custom DNS service | ||
3085 | 3069 | protocol=easydns, \\ | ||
3086 | 3070 | login=my-easydns.com-login, \\ | ||
3087 | 3071 | password=my-easydns.com-password \\ | ||
3088 | 3072 | my-toplevel-domain.com,my-other-domain.com | ||
3089 | 3073 | EoEXAMPLE | ||
3090 | 3074 | } | ||
3091 | 3075 | ###################################################################### | ||
3092 | 3076 | ## nic_easydns_update | ||
3093 | 3077 | ###################################################################### | ||
3094 | 3078 | sub nic_easydns_update { | ||
3095 | 3079 | debug("\nnic_easydns_update -------------------"); | ||
3096 | 3080 | |||
3097 | 3081 | ## group hosts with identical attributes together | ||
3098 | 3082 | ## my %groups = group_hosts_by([ @_ ], [ qw(login password server wildcard mx backupmx) ]); | ||
3099 | 3083 | |||
3100 | 3084 | ## each host is in a group by itself | ||
3101 | 3085 | my %groups = map { $_ => [ $_ ] } @_; | ||
3102 | 3086 | |||
3103 | 3087 | my %errors = ( | ||
3104 | 3088 | 'NOACCESS' => 'Authentication failed. This happens if the username/password OR host or domain are wrong.', | ||
3105 | 3089 | 'NOSERVICE'=> 'Dynamic DNS is not turned on for this domain.', | ||
3106 | 3090 | 'ILLEGAL' => 'Client sent data that is not allowed in a dynamic DNS update.', | ||
3107 | 3091 | 'TOOSOON' => 'Update frequency is too short.', | ||
3108 | 3092 | ); | ||
3109 | 3093 | |||
3110 | 3094 | ## update each set of hosts that had similar configurations | ||
3111 | 3095 | foreach my $sig (keys %groups) { | ||
3112 | 3096 | my @hosts = @{$groups{$sig}}; | ||
3113 | 3097 | my $hosts = join(',', @hosts); | ||
3114 | 3098 | my $h = $hosts[0]; | ||
3115 | 3099 | my $ip = $config{$h}{'wantip'}; | ||
3116 | 3100 | delete $config{$_}{'wantip'} foreach @hosts; | ||
3117 | 3101 | |||
3118 | 3102 | info("setting IP address to %s for %s", $ip, $hosts); | ||
3119 | 3103 | verbose("UPDATE:","updating %s", $hosts); | ||
3120 | 3104 | |||
3121 | 3105 | #'http://members.easydns.com/dyn/dyndns.php?hostname=test.burry.ca&myip=10.20.30.40&wildcard=ON' | ||
3122 | 3106 | |||
3123 | 3107 | my $url; | ||
3124 | 3108 | $url = "http://$config{$h}{'server'}/dyn/dyndns.php?"; | ||
3125 | 3109 | $url .= "hostname=$hosts"; | ||
3126 | 3110 | $url .= "&myip="; | ||
3127 | 3111 | $url .= $ip if $ip; | ||
3128 | 3112 | $url .= "&wildcard=" . ynu($config{$h}{'wildcard'}, 'ON', 'OFF', 'OFF') if defined $config{$h}{'wildcard'}; | ||
3129 | 3113 | |||
3130 | 3114 | if ($config{$h}{'mx'}) { | ||
3131 | 3115 | $url .= "&mx=$config{$h}{'mx'}"; | ||
3132 | 3116 | $url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO'); | ||
3133 | 3117 | } | ||
3134 | 3118 | |||
3135 | 3119 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
3136 | 3120 | if (!defined($reply) || !$reply) { | ||
3137 | 3121 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); | ||
3138 | 3122 | last; | ||
3139 | 3123 | } | ||
3140 | 3124 | last if !header_ok($hosts, $reply); | ||
3141 | 3125 | |||
3142 | 3126 | my @reply = split /\n/, $reply; | ||
3143 | 3127 | my $state = 'header'; | ||
3144 | 3128 | foreach my $line (@reply) { | ||
3145 | 3129 | if ($state eq 'header') { | ||
3146 | 3130 | $state = 'body'; | ||
3147 | 3131 | |||
3148 | 3132 | } elsif ($state eq 'body') { | ||
3149 | 3133 | $state = 'results' if $line eq ''; | ||
3150 | 3134 | |||
3151 | 3135 | } elsif ($state =~ /^results/) { | ||
3152 | 3136 | $state = 'results2'; | ||
3153 | 3137 | |||
3154 | 3138 | my ($status) = $line =~ /^(\S*)\b.*/; | ||
3155 | 3139 | my $h = shift @hosts; | ||
3156 | 3140 | |||
3157 | 3141 | $config{$h}{'status'} = $status; | ||
3158 | 3142 | if ($status eq 'NOERROR') { | ||
3159 | 3143 | $config{$h}{'ip'} = $ip; | ||
3160 | 3144 | $config{$h}{'mtime'} = $now; | ||
3161 | 3145 | success("updating %s: %s: IP address set to %s", $h, $status, $ip); | ||
3162 | 3146 | |||
3163 | 3147 | } elsif ($status =~ /TOOSOON/) { | ||
3164 | 3148 | ## make sure we wait at least a little | ||
3165 | 3149 | my ($wait, $units) = (5, 'm'); | ||
3166 | 3150 | my ($sec, $scale) = ($wait, 1); | ||
3167 | 3151 | |||
3168 | 3152 | ($scale, $units) = (1, 'seconds') if $units eq 's'; | ||
3169 | 3153 | ($scale, $units) = (60, 'minutes') if $units eq 'm'; | ||
3170 | 3154 | ($scale, $units) = (60*60, 'hours') if $units eq 'h'; | ||
3171 | 3155 | $config{$h}{'wtime'} = $now + $sec; | ||
3172 | 3156 | warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip); | ||
3173 | 3157 | |||
3174 | 3158 | } elsif (exists $errors{$status}) { | ||
3175 | 3159 | failed("updating %s: %s: %s", $h, $line, $errors{$status}); | ||
3176 | 3160 | |||
3177 | 3161 | } else { | ||
3178 | 3162 | failed("updating %s: %s: unexpected status (%s)", $h, $line); | ||
3179 | 3163 | } | ||
3180 | 3164 | last; | ||
3181 | 3165 | } | ||
3182 | 3166 | } | ||
3183 | 3167 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}) | ||
3184 | 3168 | if $state ne 'results2'; | ||
3185 | 3169 | } | ||
3186 | 3170 | } | ||
3187 | 3171 | ###################################################################### | ||
3188 | 3172 | |||
3189 | 3173 | ###################################################################### | ||
3190 | 3174 | ## nic_dnspark_updateable | ||
3191 | 3175 | ###################################################################### | ||
3192 | 3176 | sub nic_dnspark_updateable { | ||
3193 | 3177 | my $host = shift; | ||
3194 | 3178 | my $update = 0; | ||
3195 | 3179 | |||
3196 | 3180 | if ($config{$host}{'mx'} ne $cache{$host}{'mx'}) { | ||
3197 | 3181 | info("forcing updating %s because 'mx' has changed to %s.", $host, $config{$host}{'mx'}); | ||
3198 | 3182 | $update = 1; | ||
3199 | 3183 | |||
3200 | 3184 | } elsif ($config{$host}{'mx'} && ($config{$host}{'mxpri'} ne $cache{$host}{'mxpri'})) { | ||
3201 | 3185 | info("forcing updating %s because 'mxpri' has changed to %s.", $host, $config{$host}{'mxpri'}); | ||
3202 | 3186 | $update = 1; | ||
3203 | 3187 | } | ||
3204 | 3188 | return $update; | ||
3205 | 3189 | } | ||
3206 | 3190 | ###################################################################### | ||
3207 | 3191 | ## nic_dnspark_examples | ||
3208 | 3192 | ###################################################################### | ||
3209 | 3193 | sub nic_dnspark_examples { | ||
3210 | 3194 | return <<EoEXAMPLE; | ||
3211 | 3195 | o 'dnspark' | ||
3212 | 3196 | |||
3213 | 3197 | The 'dnspark' protocol is used by DNS service offered by www.dnspark.com. | ||
3214 | 3198 | |||
3215 | 3199 | Configuration variables applicable to the 'dnspark' protocol are: | ||
3216 | 3200 | protocol=dnspark ## | ||
3217 | 3201 | server=fqdn.of.service ## defaults to www.dnspark.com | ||
3218 | 3202 | backupmx=no|yes ## indicates that DNSPark should be the secondary MX | ||
3219 | 3203 | ## for this domain or host. | ||
3220 | 3204 | mx=any.host.domain ## a host MX'ing for this host or domain. | ||
3221 | 3205 | mxpri=priority ## MX priority. | ||
3222 | 3206 | login=service-login ## login name and password registered with the service | ||
3223 | 3207 | password=service-password ## | ||
3224 | 3208 | fully.qualified.host ## the host registered with the service. | ||
3225 | 3209 | |||
3226 | 3210 | Example ${program}.conf file entries: | ||
3227 | 3211 | ## single host update | ||
3228 | 3212 | protocol=dnspark, \\ | ||
3229 | 3213 | login=my-dnspark.com-login, \\ | ||
3230 | 3214 | password=my-dnspark.com-password \\ | ||
3231 | 3215 | myhost.dnspark.com | ||
3232 | 3216 | |||
3233 | 3217 | ## multiple host update with wildcard'ing mx, and backupmx | ||
3234 | 3218 | protocol=dnspark, \\ | ||
3235 | 3219 | login=my-dnspark.com-login, \\ | ||
3236 | 3220 | password=my-dnspark.com-password, \\ | ||
3237 | 3221 | mx=a.host.willing.to.mx.for.me, \\ | ||
3238 | 3222 | mxpri=10, \\ | ||
3239 | 3223 | my-toplevel-domain.com,my-other-domain.com | ||
3240 | 3224 | |||
3241 | 3225 | ## multiple host update to the custom DNS service | ||
3242 | 3226 | protocol=dnspark, \\ | ||
3243 | 3227 | login=my-dnspark.com-login, \\ | ||
3244 | 3228 | password=my-dnspark.com-password \\ | ||
3245 | 3229 | my-toplevel-domain.com,my-other-domain.com | ||
3246 | 3230 | EoEXAMPLE | ||
3247 | 3231 | } | ||
3248 | 3232 | ###################################################################### | ||
3249 | 3233 | ## nic_dnspark_update | ||
3250 | 3234 | ###################################################################### | ||
3251 | 3235 | sub nic_dnspark_update { | ||
3252 | 3236 | debug("\nnic_dnspark_update -------------------"); | ||
3253 | 3237 | |||
3254 | 3238 | ## group hosts with identical attributes together | ||
3255 | 3239 | ## my %groups = group_hosts_by([ @_ ], [ qw(login password server wildcard mx backupmx) ]); | ||
3256 | 3240 | |||
3257 | 3241 | ## each host is in a group by itself | ||
3258 | 3242 | my %groups = map { $_ => [ $_ ] } @_; | ||
3259 | 3243 | |||
3260 | 3244 | my %errors = ( | ||
3261 | 3245 | 'nochange' => 'No changes made to the hostname(s). Continual updates with no changes lead to blocked clients.', | ||
3262 | 3246 | 'nofqdn' => 'No valid FQDN (fully qualified domain name) was specified', | ||
3263 | 3247 | 'nohost'=> 'An invalid hostname was specified. This due to the fact the hostname has not been created in the system. Creating new host names via clients is not supported.', | ||
3264 | 3248 | 'abuse' => 'The hostname specified has been blocked for abuse.', | ||
3265 | 3249 | 'unauth' => 'The username specified is not authorized to update this hostname and domain.', | ||
3266 | 3250 | 'blocked' => 'The dynamic update client (specified by the user-agent) has been blocked from the system.', | ||
3267 | 3251 | 'notdyn' => 'The hostname specified has not been marked as a dynamic host. Hosts must be marked as dynamic in the system in order to be updated via clients. This prevents unwanted or accidental updates.', | ||
3268 | 3252 | ); | ||
3269 | 3253 | |||
3270 | 3254 | ## update each set of hosts that had similar configurations | ||
3271 | 3255 | foreach my $sig (keys %groups) { | ||
3272 | 3256 | my @hosts = @{$groups{$sig}}; | ||
3273 | 3257 | my $hosts = join(',', @hosts); | ||
3274 | 3258 | my $h = $hosts[0]; | ||
3275 | 3259 | my $ip = $config{$h}{'wantip'}; | ||
3276 | 3260 | delete $config{$_}{'wantip'} foreach @hosts; | ||
3277 | 3261 | |||
3278 | 3262 | info("setting IP address to %s for %s", $ip, $hosts); | ||
3279 | 3263 | verbose("UPDATE:","updating %s", $hosts); | ||
3280 | 3264 | |||
3281 | 3265 | #'http://www.dnspark.com:80/visitors/update.html?myip=10.20.30.40&hostname=test.burry.ca' | ||
3282 | 3266 | |||
3283 | 3267 | my $url; | ||
3284 | 3268 | $url = "http://$config{$h}{'server'}/visitors/update.html"; | ||
3285 | 3269 | $url .= "?hostname=$hosts"; | ||
3286 | 3270 | $url .= "&myip="; | ||
3287 | 3271 | $url .= $ip if $ip; | ||
3288 | 3272 | |||
3289 | 3273 | if ($config{$h}{'mx'}) { | ||
3290 | 3274 | $url .= "&mx=$config{$h}{'mx'}"; | ||
3291 | 3275 | $url .= "&mxpri=" . $config{$h}{'mxpri'}; | ||
3292 | 3276 | } | ||
3293 | 3277 | |||
3294 | 3278 | my $reply = geturl(opt('proxy'), $url, $config{$h}{'login'}, $config{$h}{'password'}); | ||
3295 | 3279 | if (!defined($reply) || !$reply) { | ||
3296 | 3280 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}); | ||
3297 | 3281 | last; | ||
3298 | 3282 | } | ||
3299 | 3283 | last if !header_ok($hosts, $reply); | ||
3300 | 3284 | |||
3301 | 3285 | my @reply = split /\n/, $reply; | ||
3302 | 3286 | my $state = 'header'; | ||
3303 | 3287 | foreach my $line (@reply) { | ||
3304 | 3288 | if ($state eq 'header') { | ||
3305 | 3289 | $state = 'body'; | ||
3306 | 3290 | |||
3307 | 3291 | } elsif ($state eq 'body') { | ||
3308 | 3292 | $state = 'results' if $line eq ''; | ||
3309 | 3293 | |||
3310 | 3294 | } elsif ($state =~ /^results/) { | ||
3311 | 3295 | $state = 'results2'; | ||
3312 | 3296 | |||
3313 | 3297 | my ($status) = $line =~ /^(\S*)\b.*/; | ||
3314 | 3298 | my $h = pop @hosts; | ||
3315 | 3299 | |||
3316 | 3300 | $config{$h}{'status'} = $status; | ||
3317 | 3301 | if ($status eq 'ok') { | ||
3318 | 3302 | $config{$h}{'ip'} = $ip; | ||
3319 | 3303 | $config{$h}{'mtime'} = $now; | ||
3320 | 3304 | success("updating %s: %s: IP address set to %s", $h, $status, $ip); | ||
3321 | 3305 | |||
3322 | 3306 | } elsif ($status =~ /TOOSOON/) { | ||
3323 | 3307 | ## make sure we wait at least a little | ||
3324 | 3308 | my ($wait, $units) = (5, 'm'); | ||
3325 | 3309 | my ($sec, $scale) = ($wait, 1); | ||
3326 | 3310 | |||
3327 | 3311 | ($scale, $units) = (1, 'seconds') if $units eq 's'; | ||
3328 | 3312 | ($scale, $units) = (60, 'minutes') if $units eq 'm'; | ||
3329 | 3313 | ($scale, $units) = (60*60, 'hours') if $units eq 'h'; | ||
3330 | 3314 | $config{$h}{'wtime'} = $now + $sec; | ||
3331 | 3315 | warning("updating %s: %s: wait $wait $units before further updates", $h, $status, $ip); | ||
3332 | 3316 | |||
3333 | 3317 | } elsif (exists $errors{$status}) { | ||
3334 | 3318 | failed("updating %s: %s: %s", $h, $line, $errors{$status}); | ||
3335 | 3319 | |||
3336 | 3320 | } else { | ||
3337 | 3321 | failed("updating %s: %s: unexpected status (%s)", $h, $line); | ||
3338 | 3322 | } | ||
3339 | 3323 | last; | ||
3340 | 3324 | } | ||
3341 | 3325 | } | ||
3342 | 3326 | failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'}) | ||
3343 | 3327 | if $state ne 'results2'; | ||
3344 | 3328 | } | ||
3345 | 3329 | } | ||
3346 | 3330 | |||
3347 | 3331 | ###################################################################### | ||
3348 | 3332 | |||
3349 | 3333 | ###################################################################### | ||
3350 | 3334 | ## nic_namecheap_examples | ||
3351 | 3335 | ###################################################################### | ||
3352 | 3336 | sub nic_namecheap_examples { | ||
3353 | 3337 | return <<EoEXAMPLE; | ||
3354 | 3338 | |||
3355 | 3339 | o 'namecheap' | ||
3356 | 3340 | |||
3357 | 3341 | The 'namecheap' protocol is used by DNS service offered by www.namecheap.com. | ||
3358 | 3342 | |||
3359 | 3343 | Configuration variables applicable to the 'namecheap' protocol are: | ||
3360 | 3344 | protocol=namecheap ## | ||
3361 | 3345 | server=fqdn.of.service ## defaults to dynamicdns.park-your-domain.com | ||
3362 | 3346 | login=service-login ## login name and password registered with the service | ||
3363 | 3347 | password=service-password ## | ||
3364 | 3348 | fully.qualified.host ## the host registered with the service. | ||
3365 | 3349 | |||
3366 | 3350 | Example ${program}.conf file entries: | ||
3367 | 3351 | ## single host update | ||
3368 | 3352 | protocol=namecheap, \\ | ||
3369 | 3353 | login=my-namecheap.com-login, \\ | ||
3370 | 3354 | password=my-namecheap.com-password \\ | ||
3371 | 3355 | myhost.namecheap.com | ||
3372 | 3356 | |||
3373 | 3357 | EoEXAMPLE | ||
3374 | 3358 | } | ||
3375 | 3359 | ###################################################################### | ||
3376 | 3360 | ## nic_namecheap_update | ||
3377 | 3361 | ## | ||
3378 | 3362 | ## written by Dan Boardman | ||
3379 | 3363 | ## | ||
3380 | 3364 | ## based on http://www.namecheap.com/resources/help/index.asp?t=dynamicdns | ||
3381 | 3365 | ## needs this url to update: | ||
3382 | 3366 | ## http://dynamicdns.park-your-domain.com/update?host=host_name& | ||
3383 | 3367 | ## domain=domain.com&password=domain_password[&ip=your_ip] | ||
3384 | 3368 | ## | ||
3385 | 3369 | ###################################################################### | ||
3386 | 3370 | sub nic_namecheap_update { | ||
3387 | 3371 | |||
3388 | 3372 | |||
3389 | 3373 | debug("\nnic_namecheap1_update -------------------"); | ||
3390 | 3374 | |||
3391 | 3375 | ## update each configured host | ||
3392 | 3376 | foreach my $h (@_) { | ||
3393 | 3377 | my $ip = delete $config{$h}{'wantip'}; | ||
3394 | 3378 | info("setting IP address to %s for %s", $ip, $h); | ||
3395 | 3379 | verbose("UPDATE:","updating %s", $h); | ||
3396 | 3380 | |||
3397 | 3381 | my $url; | ||
3398 | 3382 | $url = "http://$config{$h}{'server'}/update"; | ||
3399 | 3383 | $url .= "?host=$h"; | ||
3400 | 3384 | $url .= "&domain=$config{$h}{'login'}"; | ||
3401 | 3385 | $url .= "&password=$config{$h}{'password'}"; | ||
3402 | 3386 | $url .= "&ip="; | ||
3403 | 3387 | $url .= $ip if $ip; | ||
3404 | 3388 | |||
3405 | 3389 | my $reply = geturl(opt('proxy'), $url); | ||
3406 | 3390 | if (!defined($reply) || !$reply) { | ||
3407 | 3391 | failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); | ||
3408 | 3392 | last; | ||
3409 | 3393 | } | ||
3410 | 3394 | last if !header_ok($h, $reply); | ||
3411 | 3395 | |||
3412 | 3396 | my @reply = split /\n/, $reply; | ||
3413 | 3397 | if (grep /<ErrCount>0/i, @reply) { | ||
3414 | 3398 | $config{$h}{'ip'} = $ip; | ||
3415 | 3399 | $config{$h}{'mtime'} = $now; | ||
3416 | 3400 | $config{$h}{'status'} = 'good'; | ||
3417 | 3401 | success("updating %s: good: IP address set to %s", $h, $ip); | ||
3418 | 3402 | } else { | ||
3419 | 3403 | $config{$h}{'status'} = 'failed'; | ||
3420 | 3404 | warning("SENT: %s", $url) unless opt('verbose'); | ||
3421 | 3405 | warning("REPLIED: %s", $reply); | ||
3422 | 3406 | failed("updating %s: Invalid reply.", $h); | ||
3423 | 3407 | } | ||
3424 | 3408 | } | ||
3425 | 3409 | } | ||
3426 | 3410 | |||
3427 | 3411 | ###################################################################### | ||
3428 | 3412 | |||
3429 | 3413 | |||
3430 | 3414 | ###################################################################### | ||
3431 | 3415 | |||
3432 | 3416 | ###################################################################### | ||
3433 | 3417 | ## nic_sitelutions_examples | ||
3434 | 3418 | ###################################################################### | ||
3435 | 3419 | sub nic_sitelutions_examples { | ||
3436 | 3420 | return <<EoEXAMPLE; | ||
3437 | 3421 | |||
3438 | 3422 | o 'sitelutions' | ||
3439 | 3423 | |||
3440 | 3424 | The 'sitelutions' protocol is used by DNS services offered by www.sitelutions.com. | ||
3441 | 3425 | |||
3442 | 3426 | Configuration variables applicable to the 'sitelutions' protocol are: | ||
3443 | 3427 | protocol=sitelutions ## | ||
3444 | 3428 | server=fqdn.of.service ## defaults to sitelutions.com | ||
3445 | 3429 | login=service-login ## login name and password registered with the service | ||
3446 | 3430 | password=service-password ## | ||
3447 | 3431 | A_record_id ## Id of the A record for the host registered with the service. | ||
3448 | 3432 | |||
3449 | 3433 | Example ${program}.conf file entries: | ||
3450 | 3434 | ## single host update | ||
3451 | 3435 | protocol=sitelutions, \\ | ||
3452 | 3436 | login=my-sitelutions.com-login, \\ | ||
3453 | 3437 | password=my-sitelutions.com-password \\ | ||
3454 | 3438 | my-sitelutions.com-id_of_A_record | ||
3455 | 3439 | |||
3456 | 3440 | EoEXAMPLE | ||
3457 | 3441 | } | ||
3458 | 3442 | ###################################################################### | ||
3459 | 3443 | ## nic_sitelutions_update | ||
3460 | 3444 | ## | ||
3461 | 3445 | ## written by Mike W. Smith | ||
3462 | 3446 | ## | ||
3463 | 3447 | ## based on http://www.sitelutions.com/help/dynamic_dns_clients#updatespec | ||
3464 | 3448 | ## needs this url to update: | ||
3465 | 3449 | ## https://www.sitelutions.com/dnsup?id=990331&user=myemail@mydomain.com&pass=SecretPass&ip=192.168.10.4 | ||
3466 | 3450 | ## domain=domain.com&password=domain_password&ip=your_ip | ||
3467 | 3451 | ## | ||
3468 | 3452 | ###################################################################### | ||
3469 | 3453 | sub nic_sitelutions_update { | ||
3470 | 3454 | |||
3471 | 3455 | |||
3472 | 3456 | debug("\nnic_sitelutions_update -------------------"); | ||
3473 | 3457 | |||
3474 | 3458 | ## update each configured host | ||
3475 | 3459 | foreach my $h (@_) { | ||
3476 | 3460 | my $ip = delete $config{$h}{'wantip'}; | ||
3477 | 3461 | info("setting IP address to %s for %s", $ip, $h); | ||
3478 | 3462 | verbose("UPDATE:","updating %s", $h); | ||
3479 | 3463 | |||
3480 | 3464 | my $url; | ||
3481 | 3465 | $url = "http://$config{$h}{'server'}/dnsup"; | ||
3482 | 3466 | $url .= "?id=$h"; | ||
3483 | 3467 | $url .= "&user=$config{$h}{'login'}"; | ||
3484 | 3468 | $url .= "&pass=$config{$h}{'password'}"; | ||
3485 | 3469 | $url .= "&ip="; | ||
3486 | 3470 | $url .= $ip if $ip; | ||
3487 | 3471 | |||
3488 | 3472 | my $reply = geturl(opt('proxy'), $url); | ||
3489 | 3473 | if (!defined($reply) || !$reply) { | ||
3490 | 3474 | failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); | ||
3491 | 3475 | last; | ||
3492 | 3476 | } | ||
3493 | 3477 | last if !header_ok($h, $reply); | ||
3494 | 3478 | |||
3495 | 3479 | my @reply = split /\n/, $reply; | ||
3496 | 3480 | if (grep /success/i, @reply) { | ||
3497 | 3481 | $config{$h}{'ip'} = $ip; | ||
3498 | 3482 | $config{$h}{'mtime'} = $now; | ||
3499 | 3483 | $config{$h}{'status'} = 'good'; | ||
3500 | 3484 | success("updating %s: good: IP address set to %s", $h, $ip); | ||
3501 | 3485 | } else { | ||
3502 | 3486 | $config{$h}{'status'} = 'failed'; | ||
3503 | 3487 | warning("SENT: %s", $url) unless opt('verbose'); | ||
3504 | 3488 | warning("REPLIED: %s", $reply); | ||
3505 | 3489 | failed("updating %s: Invalid reply.", $h); | ||
3506 | 3490 | } | ||
3507 | 3491 | } | ||
3508 | 3492 | } | ||
3509 | 3493 | |||
3510 | 3494 | ###################################################################### | ||
3511 | 3495 | |||
3512 | 3496 | ###################################################################### | ||
3513 | 3497 | ## nic_freedns_examples | ||
3514 | 3498 | ###################################################################### | ||
3515 | 3499 | sub nic_freedns_examples { | ||
3516 | 3500 | return <<EoEXAMPLE; | ||
3517 | 3501 | |||
3518 | 3502 | o 'freedns' | ||
3519 | 3503 | |||
3520 | 3504 | The 'freedns' protocol is used by DNS services offered by freedns.afraid.org. | ||
3521 | 3505 | |||
3522 | 3506 | Configuration variables applicable to the 'freedns' protocol are: | ||
3523 | 3507 | protocol=freedns ## | ||
3524 | 3508 | server=fqdn.of.service ## defaults to freedns.afraid.org | ||
3525 | 3509 | login=service-login ## login name and password registered with the service | ||
3526 | 3510 | password=service-password ## | ||
3527 | 3511 | fully.qualified.host ## the host registered with the service. | ||
3528 | 3512 | |||
3529 | 3513 | Example ${program}.conf file entries: | ||
3530 | 3514 | ## single host update | ||
3531 | 3515 | protocol=freedns, \\ | ||
3532 | 3516 | login=my-freedns.afraid.org-login, \\ | ||
3533 | 3517 | password=my-freedns.afraid.org-password \\ | ||
3534 | 3518 | myhost.afraid.com | ||
3535 | 3519 | |||
3536 | 3520 | EoEXAMPLE | ||
3537 | 3521 | } | ||
3538 | 3522 | ###################################################################### | ||
3539 | 3523 | ## nic_freedns_update | ||
3540 | 3524 | ## | ||
3541 | 3525 | ## written by John Haney | ||
3542 | 3526 | ## | ||
3543 | 3527 | ## based on http://freedns.afraid.org/api/ | ||
3544 | 3528 | ## needs this url to update: | ||
3545 | 3529 | ## http://freedns.afraid.org/api/?action=getdyndns&sha=<sha1sum of login|password> | ||
3546 | 3530 | ## This returns a list of host|currentIP|updateURL lines. | ||
3547 | 3531 | ## Pick the line that matches myhost, and fetch the URL. | ||
3548 | 3532 | ## word 'Updated' for success, 'fail' for failure. | ||
3549 | 3533 | ## | ||
3550 | 3534 | ###################################################################### | ||
3551 | 3535 | sub nic_freedns_update { | ||
3552 | 3536 | |||
3553 | 3537 | |||
3554 | 3538 | debug("\nnic_freedns_update -------------------"); | ||
3555 | 3539 | |||
3556 | 3540 | ## First get the list of updatable hosts | ||
3557 | 3541 | my $url; | ||
3558 | 3542 | $url = "http://$config{$_[0]}{'server'}/api/?action=getdyndns&sha=".&sha1_hex("$config{$_[0]}{'login'}|$config{$_[0]}{'password'}"); | ||
3559 | 3543 | my $reply = geturl(opt('proxy'), $url); | ||
3560 | 3544 | if (!defined($reply) || !$reply || !header_ok($_[0], $reply)) { | ||
3561 | 3545 | failed("updating %s: Could not connect to %s for site list.", $_[0], $url); | ||
3562 | 3546 | return; | ||
3563 | 3547 | } | ||
3564 | 3548 | my @lines = split("\n", $reply); | ||
3565 | 3549 | my %freedns_hosts; | ||
3566 | 3550 | grep { | ||
3567 | 3551 | my @rec = split(/\|/, $_); | ||
3568 | 3552 | $freedns_hosts{$rec[0]} = \@rec if ($#rec > 0); | ||
3569 | 3553 | } @lines; | ||
3570 | 3554 | if (!keys %freedns_hosts) { | ||
3571 | 3555 | failed("Could not get freedns update URLs from %s", $config{$_[0]}{'server'}); | ||
3572 | 3556 | return; | ||
3573 | 3557 | } | ||
3574 | 3558 | ## update each configured host | ||
3575 | 3559 | foreach my $h (@_) { | ||
3576 | 3560 | if(!$h){ next }; | ||
3577 | 3561 | my $ip = delete $config{$h}{'wantip'}; | ||
3578 | 3562 | info("setting IP address to %s for %s", $ip, $h); | ||
3579 | 3563 | verbose("UPDATE:","updating %s", $h); | ||
3580 | 3564 | |||
3581 | 3565 | if($ip eq $freedns_hosts{$h}->[1]) { | ||
3582 | 3566 | $config{$h}{'ip'} = $ip; | ||
3583 | 3567 | $config{$h}{'mtime'} = $now; | ||
3584 | 3568 | $config{$h}{'status'} = 'good'; | ||
3585 | 3569 | success("update not necessary %s: good: IP address already set to %s", $h, $ip); | ||
3586 | 3570 | } else { | ||
3587 | 3571 | my $reply = geturl(opt('proxy'), $freedns_hosts{$h}->[2]); | ||
3588 | 3572 | if (!defined($reply) || !$reply) { | ||
3589 | 3573 | failed("updating %s: Could not connect to %s.", $h, $freedns_hosts{$h}->[2]); | ||
3590 | 3574 | last; | ||
3591 | 3575 | } | ||
3592 | 3576 | if(!header_ok($h, $reply)) { | ||
3593 | 3577 | $config{$h}{'status'} = 'failed'; | ||
3594 | 3578 | last; | ||
3595 | 3579 | } | ||
3596 | 3580 | |||
3597 | 3581 | if($reply =~ /Updated.*$h.*to.*$ip/) { | ||
3598 | 3582 | $config{$h}{'ip'} = $ip; | ||
3599 | 3583 | $config{$h}{'mtime'} = $now; | ||
3600 | 3584 | $config{$h}{'status'} = 'good'; | ||
3601 | 3585 | success("updating %s: good: IP address set to %s", $h, $ip); | ||
3602 | 3586 | } else { | ||
3603 | 3587 | $config{$h}{'status'} = 'failed'; | ||
3604 | 3588 | warning("SENT: %s", $freedns_hosts{$h}->[2]) unless opt('verbose'); | ||
3605 | 3589 | warning("REPLIED: %s", $reply); | ||
3606 | 3590 | failed("updating %s: Invalid reply.", $h); | ||
3607 | 3591 | } | ||
3608 | 3592 | } | ||
3609 | 3593 | } | ||
3610 | 3594 | } | ||
3611 | 3595 | |||
3612 | 3596 | ###################################################################### | ||
3613 | 3597 | |||
3614 | 3598 | ###################################################################### | ||
3615 | 3599 | ## nic_dtdns_examples | ||
3616 | 3600 | ###################################################################### | ||
3617 | 3601 | sub nic_dtdns_examples { | ||
3618 | 3602 | return <<EoEXAMPLE; | ||
3619 | 3603 | o 'dtdns' | ||
3620 | 3604 | |||
3621 | 3605 | The 'dtdns' protocol is the protocol used by the dynamic hostname services | ||
3622 | 3606 | of the 'DtDNS' dns services. This is currently used by the free | ||
3623 | 3607 | dynamic DNS service offered by www.dtdns.com. | ||
3624 | 3608 | |||
3625 | 3609 | Configuration variables applicable to the 'dtdns' protocol are: | ||
3626 | 3610 | protocol=dtdns ## | ||
3627 | 3611 | server=www.fqdn.of.service ## defaults to www.dtdns.com | ||
3628 | 3612 | password=service-password ## password registered with the service | ||
3629 | 3613 | client=name_of_updater ## defaults to $program (10 chars max, no spaces) | ||
3630 | 3614 | fully.qualified.host ## the host registered with the service. | ||
3631 | 3615 | |||
3632 | 3616 | Example ${program}.conf file entries: | ||
3633 | 3617 | ## single host update | ||
3634 | 3618 | protocol=dtdns, \\ | ||
3635 | 3619 | password=my-dydns.za.net-password, \\ | ||
3636 | 3620 | client=ddclient \\ | ||
3637 | 3621 | myhost.dtdns.net | ||
3638 | 3622 | |||
3639 | 3623 | EoEXAMPLE | ||
3640 | 3624 | } | ||
3641 | 3625 | |||
3642 | 3626 | ###################################################################### | ||
3643 | 3627 | ## nic_dtdns_update | ||
3644 | 3628 | ## by Achim Franke | ||
3645 | 3629 | ###################################################################### | ||
3646 | 3630 | sub nic_dtdns_update { | ||
3647 | 3631 | debug("\nnic_dtdns_update -------------------"); | ||
3648 | 3632 | |||
3649 | 3633 | ## update each configured host | ||
3650 | 3634 | foreach my $h (@_) { | ||
3651 | 3635 | my $ip = delete $config{$h}{'wantip'}; | ||
3652 | 3636 | info("setting IP address to %s for %s", $ip, $h); | ||
3653 | 3637 | verbose("UPDATE:","updating %s", $h); | ||
3654 | 3638 | |||
3655 | 3639 | # Set the URL that we're going to to update | ||
3656 | 3640 | my $url; | ||
3657 | 3641 | $url = "http://$config{$h}{'server'}/api/autodns.cfm"; | ||
3658 | 3642 | $url .= "?id="; | ||
3659 | 3643 | $url .= $h; | ||
3660 | 3644 | $url .= "&pw="; | ||
3661 | 3645 | $url .= $config{$h}{'password'}; | ||
3662 | 3646 | $url .= "&ip="; | ||
3663 | 3647 | $url .= $ip; | ||
3664 | 3648 | $url .= "&client="; | ||
3665 | 3649 | $url .= $config{$h}{'client'}; | ||
3666 | 3650 | |||
3667 | 3651 | # Try to get URL | ||
3668 | 3652 | my $reply = geturl(opt('proxy'), $url); | ||
3669 | 3653 | |||
3670 | 3654 | # No response, declare as failed | ||
3671 | 3655 | if (!defined($reply) || !$reply) { | ||
3672 | 3656 | failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'}); | ||
3673 | 3657 | last; | ||
3674 | 3658 | } | ||
3675 | 3659 | last if !header_ok($h, $reply); | ||
3676 | 3660 | |||
3677 | 3661 | # Response found, just declare as success (this is ugly, we need more error checking) | ||
3678 | 3662 | if ($reply =~ /now\spoints\sto/) | ||
3679 | 3663 | { | ||
3680 | 3664 | $config{$h}{'ip'} = $ip; | ||
3681 | 3665 | $config{$h}{'mtime'} = $now; | ||
3682 | 3666 | $config{$h}{'status'} = 'good'; | ||
3683 | 3667 | success("updating %s: good: IP address set to %s", $h, $ip); | ||
3684 | 3668 | } | ||
3685 | 3669 | else | ||
3686 | 3670 | { | ||
3687 | 3671 | my @reply = split /\n/, $reply; | ||
3688 | 3672 | my $returned = pop(@reply); | ||
3689 | 3673 | $config{$h}{'status'} = 'failed'; | ||
3690 | 3674 | failed("updating %s: Server said: '$returned'", $h); | ||
3691 | 3675 | } | ||
3692 | 3676 | } | ||
3693 | 3677 | } | ||
3694 | 3678 | |||
3695 | 3679 | ###################################################################### | ||
3696 | 3680 | # vim: ai ts=4 sw=4 tw=78 : | ||
3697 | 3681 | |||
3698 | 3682 | |||
3699 | 3683 | __END__ | ||
3700 | 0 | 3684 | ||
3701 | === added file '.pc/maxinterval.diff/.timestamp' | |||
3702 | === added file '.pc/sample_ubuntu.diff/.timestamp' | |||
3703 | === added file '.pc/smc-barricade-fw-alt.diff/.timestamp' | |||
3704 | === modified file 'ddclient' | |||
3705 | --- ddclient 2012-09-18 13:30:33 +0000 | |||
3706 | +++ ddclient 2014-12-10 04:52:08 +0000 | |||
3707 | @@ -1784,13 +1784,18 @@ | |||
3708 | 1784 | ###################################################################### | 1784 | ###################################################################### |
3709 | 1785 | sub load_sha1_support { | 1785 | sub load_sha1_support { |
3710 | 1786 | my $sha1_loaded = eval {require Digest::SHA1}; | 1786 | my $sha1_loaded = eval {require Digest::SHA1}; |
3712 | 1787 | unless ($sha1_loaded) { | 1787 | my $sha_loaded = eval {require Digest::SHA}; |
3713 | 1788 | unless ($sha1_loaded || $sha_loaded) { | ||
3714 | 1788 | fatal(<<"EOM"); | 1789 | fatal(<<"EOM"); |
3717 | 1789 | Error loading the Perl module Digest::SHA1 needed for freedns update. | 1790 | Error loading the Perl module Digest::SHA1 or Digest::SHA needed for freedns update. |
3718 | 1790 | On Debian, the package libdigest-sha1-perl must be installed. | 1791 | On Debian, the package libdigest-sha1-perl or libdigest-sha-perl must be installed. |
3719 | 1791 | EOM | 1792 | EOM |
3720 | 1792 | } | 1793 | } |
3722 | 1793 | import Digest::SHA1 (qw/sha1_hex/); | 1794 | if($sha1_loaded) { |
3723 | 1795 | import Digest::SHA1 (qw/sha1_hex/); | ||
3724 | 1796 | } elsif($sha_loaded) { | ||
3725 | 1797 | import Digest::SHA (qw/sha1_hex/); | ||
3726 | 1798 | } | ||
3727 | 1794 | } | 1799 | } |
3728 | 1795 | ###################################################################### | 1800 | ###################################################################### |
3729 | 1796 | ## geturl | 1801 | ## geturl |
3730 | 1797 | 1802 | ||
3731 | === modified file 'debian/changelog' | |||
3732 | --- debian/changelog 2013-07-29 14:49:34 +0000 | |||
3733 | +++ debian/changelog 2014-12-10 04:52:08 +0000 | |||
3734 | @@ -1,3 +1,10 @@ | |||
3735 | 1 | ddclient (3.8.1-1ubuntu3) vivid; urgency=low | ||
3736 | 2 | |||
3737 | 3 | * Add patch from upstream which enables ddclient to find Digest::SHA to | ||
3738 | 4 | fix FreeDNS support (LP: #1068884) | ||
3739 | 5 | |||
3740 | 6 | -- Scott Talbert <swt@techie.net> Sat, 06 Dec 2014 22:49:13 -0500 | ||
3741 | 7 | |||
3742 | 1 | ddclient (3.8.1-1ubuntu2) saucy; urgency=low | 8 | ddclient (3.8.1-1ubuntu2) saucy; urgency=low |
3743 | 2 | 9 | ||
3744 | 3 | * debian/ddclient.NetworkManager | 10 | * debian/ddclient.NetworkManager |
3745 | 4 | 11 | ||
3746 | === modified file 'debian/control' | |||
3747 | --- debian/control 2012-09-18 13:30:33 +0000 | |||
3748 | +++ debian/control 2014-12-10 04:52:08 +0000 | |||
3749 | @@ -1,7 +1,8 @@ | |||
3750 | 1 | Source: ddclient | 1 | Source: ddclient |
3751 | 2 | Section: net | 2 | Section: net |
3752 | 3 | Priority: extra | 3 | Priority: extra |
3754 | 4 | Maintainer: Torsten Landschoff <torsten@debian.org> | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
3755 | 5 | XSBC-Original-Maintainer: Torsten Landschoff <torsten@debian.org> | ||
3756 | 5 | Uploaders: Marco Rodrigues <gothicx@sapo.pt> | 6 | Uploaders: Marco Rodrigues <gothicx@sapo.pt> |
3757 | 6 | Build-Depends: debhelper (>= 5), po-debconf, xmlto, quilt | 7 | Build-Depends: debhelper (>= 5), po-debconf, xmlto, quilt |
3758 | 7 | Standards-Version: 3.8.4 | 8 | Standards-Version: 3.8.4 |
3759 | 8 | 9 | ||
3760 | === added file 'debian/patches/fix_digest_sha_freedns.diff' | |||
3761 | --- debian/patches/fix_digest_sha_freedns.diff 1970-01-01 00:00:00 +0000 | |||
3762 | +++ debian/patches/fix_digest_sha_freedns.diff 2014-12-10 04:52:08 +0000 | |||
3763 | @@ -0,0 +1,27 @@ | |||
3764 | 1 | Index: ddclient/ddclient | ||
3765 | 2 | =================================================================== | ||
3766 | 3 | --- ddclient.orig/ddclient 2014-12-06 21:59:46.763693000 -0500 | ||
3767 | 4 | +++ ddclient/ddclient 2014-12-06 22:32:58.422405251 -0500 | ||
3768 | 5 | @@ -1784,13 +1784,18 @@ | ||
3769 | 6 | ###################################################################### | ||
3770 | 7 | sub load_sha1_support { | ||
3771 | 8 | my $sha1_loaded = eval {require Digest::SHA1}; | ||
3772 | 9 | - unless ($sha1_loaded) { | ||
3773 | 10 | + my $sha_loaded = eval {require Digest::SHA}; | ||
3774 | 11 | + unless ($sha1_loaded || $sha_loaded) { | ||
3775 | 12 | fatal(<<"EOM"); | ||
3776 | 13 | -Error loading the Perl module Digest::SHA1 needed for freedns update. | ||
3777 | 14 | -On Debian, the package libdigest-sha1-perl must be installed. | ||
3778 | 15 | +Error loading the Perl module Digest::SHA1 or Digest::SHA needed for freedns update. | ||
3779 | 16 | +On Debian, the package libdigest-sha1-perl or libdigest-sha-perl must be installed. | ||
3780 | 17 | EOM | ||
3781 | 18 | } | ||
3782 | 19 | - import Digest::SHA1 (qw/sha1_hex/); | ||
3783 | 20 | + if($sha1_loaded) { | ||
3784 | 21 | + import Digest::SHA1 (qw/sha1_hex/); | ||
3785 | 22 | + } elsif($sha_loaded) { | ||
3786 | 23 | + import Digest::SHA (qw/sha1_hex/); | ||
3787 | 24 | + } | ||
3788 | 25 | } | ||
3789 | 26 | ###################################################################### | ||
3790 | 27 | ## geturl | ||
3791 | 0 | 28 | ||
3792 | === modified file 'debian/patches/series' | |||
3793 | --- debian/patches/series 2012-09-18 13:30:33 +0000 | |||
3794 | +++ debian/patches/series 2014-12-10 04:52:08 +0000 | |||
3795 | @@ -2,3 +2,4 @@ | |||
3796 | 2 | config_path.diff | 2 | config_path.diff |
3797 | 3 | maxinterval.diff | 3 | maxinterval.diff |
3798 | 4 | sample_ubuntu.diff | 4 | sample_ubuntu.diff |
3799 | 5 | fix_digest_sha_freedns.diff |
This looks okay, but you neglected to change the release and package version number for utopic. I've changed it to the following:
ddclient (3.8.1- 1ubuntu2. 14.10.1) utopic; urgency=low
You can find guidelines for package versioning here:
https:/ /wiki.ubuntu. com/SecurityTea m/UpdatePrepara tion#Update_ the_packaging