forked from ddclient/ddclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddclient.in
executable file
·7484 lines (6646 loc) · 296 KB
/
ddclient.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
######################################################################
#
# DDCLIENT - a Perl client for updating DynDNS information
#
# Author: Paul Burry (paul+ddclient@burry.ca)
# ddclient developers: see https://github.com/orgs/ddclient/people
#
# website: https://ddclient.net
#
# Support for multiple IP numbers added by
# Astaro AG, Ingo Schwarze <ischwarze-OOs/4mkCeqbQT0dZR+AlfA@public.gmane.org> September 16, 2008
#
# Support for multiple domain support for Namecheap by Robert Ian Hawdon 2010-09-03: https://robertianhawdon.me.uk/
#
# Initial Cloudflare support by Ian Pye, updated by Robert Ian Hawdon 2012-07-16
# Further updates by Peter Roberts to support the new API 2013-09-26, 2014-06-22: http://blog.peter-r.co.uk/
#
#
######################################################################
package ddclient;
require v5.10.1;
use strict;
use warnings;
use File::Basename;
use File::Path qw(make_path);
use File::Temp;
use Getopt::Long;
use IO::Socket::INET;
use Socket qw(AF_INET AF_INET6 PF_INET PF_INET6);
use Sys::Hostname;
use version 0.77; our $VERSION = version->declare('@PACKAGE_VERSION@');
my $version = $VERSION->stringify();
my $programd = $0;
$programd =~ s%^.*/%%;
my $program = $programd;
$program =~ s/d$//;
my $now = time;
my $hostname = hostname();
# subst_var(subst, default) returns subst unless it looks like @foo@ in which case it returns
# default. The @foo@ strings are expected to be replaced by make; this function makes it possible
# to run this file as a Perl script before those substitutions are made.
sub subst_var {
my ($subst, $default) = @_;
return $default if $subst =~ qr'^@\w+@$';
return $subst;
}
my $etc = subst_var('@sysconfdir@', '/etc/ddclient');
my $cachedir = subst_var('@localstatedir@', '/var') . '/cache/ddclient';
my $savedir = '/tmp';
if ($program =~ /test/i) {
$etc = '.';
$cachedir = '.';
$savedir = 'URL';
}
my $msgs = '';
my $last_msgs = '';
## If run as *d (e.g., ddclientd) then daemonize by default (but allow
## flags and options to override).
my $daemon_default = ($programd =~ /d$/) ? interval('5m') : 0;
use vars qw($file $lineno);
local $file = '';
local $lineno = '';
$ENV{'PATH'} = (exists($ENV{PATH}) ? "$ENV{PATH}:" : "") . "/sbin:/usr/sbin:/bin:/usr/bin:/etc:/usr/lib:";
our %globals;
my ($result, %config, %cache);
my $saved_cache;
my %saved_opt;
my $daemon;
# Control how many times warning message logged for invalid IP addresses
my (%warned_ip, %warned_ipv4, %warned_ipv6);
my $inv_ip_warn_count = opt('max-warn') // 1;
sub T_ANY { 'any' }
sub T_STRING { 'string' }
sub T_EMAIL { 'e-mail address' }
sub T_NUMBER { 'number' }
sub T_DELAY { 'time delay (ie. 1d, 1hour, 1m)' }
sub T_LOGIN { 'login' }
sub T_PASSWD { 'password' }
sub T_BOOL { 'boolean value' }
sub T_FQDN { 'fully qualified host name' }
sub T_OFQDN { 'optional fully qualified host name' }
sub T_FILE { 'file name' }
sub T_FQDNP { 'fully qualified host name and optional port number' }
sub T_PROTO { 'protocol' }
sub T_USE { 'ip strategy' }
sub T_USEV4 { 'ipv4 strategy' }
sub T_USEV6 { 'ipv6 strategy' }
sub T_IF { 'interface' }
sub T_PROG { 'program name' }
sub T_IP { 'ip' }
sub T_IPV4 { 'ipv4' }
sub T_IPV6 { 'ipv6' }
sub T_POSTS { 'postscript' }
## strategies for obtaining an ip address.
my %builtinweb = (
'dyndns' => {'url' => 'http://checkip.dyndns.org/', 'skip' => 'Current IP Address:'},
'freedns' => {'url' => 'https://freedns.afraid.org/dynamic/check.php'},
'googledomains' => {'url' => 'https://domains.google.com/checkip'},
'he' => {'url' => 'https://checkip.dns.he.net/'},
'ip4only.me' => {'url' => 'https://ip4only.me/api/'},
'ip6only.me' => {'url' => 'https://ip6only.me/api/'},
'ipify-ipv4' => {'url' => 'https://api.ipify.org/'},
'ipify-ipv6' => {'url' => 'https://api6.ipify.org/'},
'loopia' => {'url' => 'https://dns.loopia.se/checkip/checkip.php', 'skip' => 'Current IP Address:'},
'myonlineportal' => {'url' => 'https://myonlineportal.net/checkip'},
'noip-ipv4' => {'url' => 'http://ip1.dynupdate.no-ip.com/'},
'noip-ipv6' => {'url' => 'http://ip1.dynupdate6.no-ip.com/'},
'nsupdate.info-ipv4' => {'url' => 'https://ipv4.nsupdate.info/myip'},
'nsupdate.info-ipv6' => {'url' => 'https://ipv6.nsupdate.info/myip'},
'zoneedit' => {'url' => 'https://dynamic.zoneedit.com/checkip.html'},
);
my %builtinfw = (
'2wire' => {
'name' => '2Wire 1701HG Gateway',
'url' => '/xslt?PAGE=B01',
'skip' => 'Internet Address:',
},
'3com-3c886a' => {
'name' => '3com 3c886a 56k Lan Modem',
'url' => '/stat3.htm',
'skip' => 'IP address in use',
},
'3com-oc-remote812' => {
'name' => '3com OfficeConnect Remote 812',
'url' => '/callEvent',
'skip' => '.*LOCAL',
},
'alcatel-510' => {
'name' => 'Alcatel Speed Touch 510',
'url' => '/cgi/ip/',
'skip' => 'ppp',
},
'alcatel-530' => {
'name' => 'Alcatel/Thomson SpeedTouch 530',
'url' => '/cgi/status/',
'skip' => 'IP Address',
},
'alcatel-stp' => {
'name' => 'Alcatel Speed Touch Pro',
'url' => '/cgi/router/',
'skip' => 'Brt',
},
'allnet-1298' => {
'name' => 'Allnet 1298',
'url' => '/cgi/router/',
'skip' => 'WAN',
},
'cayman-3220h' => {
'name' => 'Cayman 3220-H DSL',
'url' => '/shell/show+ip+interfaces',
'skip' => '.*inet',
},
'dlink-524' => {
'name' => 'D-Link DI-524',
'url' => '/st_device.html',
'skip' => 'WAN.*?Addres',
},
'dlink-604' => {
'name' => 'D-Link DI-604',
'url' => '/st_devic.html',
'skip' => 'WAN.*?IP.*Address',
},
'dlink-614' => {
'name' => 'D-Link DI-614+',
'url' => '/st_devic.html',
'skip' => 'WAN',
},
'e-tech' => {
'name' => 'E-tech Router',
'url' => '/Status.htm',
'skip' => 'Public IP Address',
},
'elsa-lancom-dsl10' => {
'name' => 'ELSA LanCom DSL/10 DSL FW',
'url' => '/config/1/6/8/3/',
'skip' => 'IP.Address',
},
'elsa-lancom-dsl10-ch01' => {
'name' => 'ELSA LanCom DSL/10 DSL FW (isdn ch01)',
'url' => '/config/1/6/8/3/',
'skip' => 'IP.Address.*?CH01',
},
'elsa-lancom-dsl10-ch02' => {
'name' => 'ELSA LanCom DSL/10 DSL FW (isdn ch01)',
'url' => '/config/1/6/8/3/',
'skip' => 'IP.Address.*?CH02',
},
'linksys' => {
'name' => 'Linksys FW',
'url' => '/Status.htm',
'skip' => 'WAN.*?Address',
},
'linksys-rv042-wan1' => {
'name' => 'Linksys RV042 Dual Homed Router WAN Port 2',
'url' => '/home.htm',
'skip' => 'WAN1 IP',
},
'linksys-rv042-wan2' => {
'name' => 'Linksys RV042 Dual Homed Router WAN Port 2',
'url' => '/home.htm',
'skip' => 'WAN2 IP',
},
'linksys-ver2' => {
'name' => 'Linksys FW version 2',
'url' => '/RouterStatus.htm',
'skip' => 'WAN.*?Address',
},
'linksys-ver3' => {
'name' => 'Linksys FW version 3',
'url' => '/Status_Router.htm',
'skip' => 'WAN.*?Address',
},
'linksys-wcg200' => {
'name' => 'Linksys WCG200 FW',
'url' => '/RgStatus.asp',
'skip' => 'WAN.IP.*?Address',
},
'linksys-wrt854g' => {
'name' => 'Linksys WRT854G FW',
'url' => '/Status_Router.asp',
'skip' => 'IP Address:',
},
'maxgate-ugate3x00' => {
'name' => 'MaxGate UGATE-3x00 FW',
'url' => '/Status.htm',
'skip' => 'WAN.*?IP Address',
},
'netcomm-nb3' => {
'name' => 'NetComm NB3',
'url' => '/MainPage?id=6',
'skip' => 'ppp-0',
},
'netgear-dg834g' => {
'name' => 'netgear-dg834g',
'url' => '/setup.cgi?next_file=s_status.htm&todo=cfg_init',
'skip' => '',
},
'netgear-rp614' => {
'name' => 'Netgear RP614 FW',
'url' => '/sysstatus.html',
'skip' => 'IP Address',
},
'netgear-rt3xx' => {
'name' => 'Netgear FW',
'url' => '/mtenSysStatus.html',
'skip' => 'IP Address',
},
'netgear-wgt624' => {
'name' => 'Netgear WGT624',
'url' => '/RST_st_dhcp.htm',
'skip' => 'IP Address</B></td><TD NOWRAP width="50%">',
},
'netgear-wpn824' => {
'name' => 'Netgear WPN824 FW',
'url' => '/RST_status.htm',
'skip' => 'IP Address',
},
'netopia-r910' => {
'name' => 'Netopia R910 FW',
'url' => '/WanEvtLog',
'skip' => 'local:',
},
'olitec-SX200' => {
'name' => 'olitec-SX200',
'url' => '/doc/wan.htm',
'skip' => 'st_wan_ip[0] = "',
},
'rtp300' => {
'name' => 'Linksys RTP300',
'url' => '/cgi-bin/webcm?getpage=%2Fusr%2Fwww_safe%2Fhtml%2Fstatus%2FRouter.html',
'skip' => 'Internet.*?IP Address',
},
'siemens-ss4200' => {
'name' => 'Siemens SpeedStream 4200',
'url' => '/summary.htm',
'skip' => '',
},
'sitecom-dc202' => {
'name' => 'Sitecom DC-202 FW',
'url' => '/status.htm',
'skip' => 'Internet IP Address',
},
'smc-barricade' => {
'name' => 'SMC Barricade FW',
'url' => '/status.htm',
'skip' => 'IP Address',
},
'smc-barricade-7004vbr' => {
'name' => 'SMC Barricade FW (7004VBR model config)',
'url' => '/status_main.stm',
'skip' => 'var wan_ip=',
},
'smc-barricade-7401bra' => {
'name' => 'SMC Barricade 7401BRA FW',
'url' => '/admin/wan1.htm',
'skip' => 'IP Address',
},
'smc-barricade-alt' => {
'name' => 'SMC Barricade FW (alternate config)',
'url' => '/status.HTM',
'skip' => 'WAN IP',
},
'sohoware-nbg800' => {
'name' => 'SOHOWare BroadGuard NBG800',
'url' => '/status.htm',
'skip' => 'Internet IP',
},
'sveasoft' => {
'name' => 'Sveasoft WRT54G/WRT54GS',
'url' => '/Status_Router.asp',
'skip' => 'var wan_ip',
},
'thomson-st536v6' => {
'name' => 'Thomson SpeedTouch 536v6',
'url' => '/cgi/b/is/',
'skip' => 'IP Address',
},
'thomson-tg782' => {
'name' => 'Thomson/Technicolor TG782',
'url' => '/cgi/b/is/',
'skip' => 'IP Address',
},
'vigor-2200usb' => {
'name' => 'Vigor 2200 USB',
'url' => '/doc/online.sht',
'skip' => 'PPPoA',
},
'watchguard-edge-x' => {
'name' => 'Watchguard Edge X FW',
'url' => '/netstat.htm',
'skip' => 'inet addr:',
},
'watchguard-soho' => {
'name' => 'Watchguard SOHO FW',
'url' => '/pubnet.htm',
'skip' => 'NAME=IPAddress VALUE=',
},
'westell-6100' => {
'name' => 'Westell C90-610015-06 DSL Router',
'url' => '/advstat.htm',
'skip' => 'IP.+?Address',
},
'xsense-aero' => {
'name' => 'Xsense Aero',
'url' => '/A_SysInfo.htm',
'skip' => 'WAN.*?IP Address',
},
);
my %ip_strategies = (
'no' => ": deprecated, see 'usev4' and 'usev6'",
'ip' => ": deprecated, see 'usev4' and 'usev6'",
'web' => ": deprecated, see 'usev4' and 'usev6'",
'fw' => ": deprecated, see 'usev4' and 'usev6'",
'if' => ": deprecated, see 'usev4' and 'usev6'",
'cmd' => ": deprecated, see 'usev4' and 'usev6'",
'cisco' => ": deprecated, see 'usev4' and 'usev6'",
'cisco-asa' => ": deprecated, see 'usev4' and 'usev6'",
map({ $_ => sprintf(": Built-in firewall %s deprecated, see 'usev4' and 'usev6'",
$builtinfw{$_}->{'name'}) }
keys(%builtinfw)),
);
sub ip_strategies_usage {
return map({ sprintf(" -use=%-22s %s.", $_, $ip_strategies{$_}) }
('ip', 'web', 'if', 'cmd', 'fw', sort('cisco', 'cisco-asa', keys(%builtinfw))));
}
my %ipv4_strategies = (
'disabled' => ": do not obtain an IPv4 address for this host",
'ipv4' => ": obtain IPv4 from -ipv4 {address}",
'webv4' => ": obtain IPv4 from an IP discovery page on the web",
'ifv4' => ": obtain IPv4 from the -ifv4 {interface}",
'cmdv4' => ": obtain IPv4 from the -cmdv4 {external-command}",
'fwv4' => ": obtain IPv4 from the firewall specified by -fwv4 {type|address}",
'ciscov4' => ": obtain IPv4 from Cisco FW at the -fwv4 {address}",
'cisco-asav4' => ": obtain IPv4 from Cisco ASA at the -fwv4 {address}",
map { $_ => sprintf ": obtain IPv4 from %s at the -fwv4 {address}", $builtinfw{$_}->{'name'} } keys %builtinfw,
);
sub ipv4_strategies_usage {
return map { sprintf(" -usev4=%-22s %s.", $_, $ipv4_strategies{$_}) } sort keys %ipv4_strategies;
}
my %ipv6_strategies = (
'no' => ": deprecated, use 'disabled'",
'disabled' => ": do not obtain an IPv6 address for this host",
'ip' => ": deprecated, use 'ipv6'",
'ipv6' => ": obtain IPv6 from -ipv6 {address}",
'web' => ": deprecated, use 'webv6'",
'webv6' => ": obtain IPv6 from an IP discovery page on the web",
'if' => ": deprecated, use 'ifv6'",
'ifv6' => ": obtain IPv6 from the -if {interface}",
'cmd' => ": deprecated, use 'cmdv6'",
'cmdv6' => ": obtain IPv6 from the -cmdv6 {external-command}",
'fwv6' => ": obtain IPv6 from the firewall specified by -fwv6 {type|address}",
'ciscov6' => ": obtain IPv6 from Cisco FW at the -fwv6 {address}",
'cisco-asav6' => ": obtain IPv6 from Cisco ASA at the -fwv6 {address}",
map { $_ => sprintf ": obtain IPv6 from %s at the -fwv6 {address}", $builtinfw{$_}->{'name'} } keys %builtinfw,
);
sub ipv6_strategies_usage {
return map { sprintf(" -usev6=%-22s %s.", $_, $ipv6_strategies{$_}) } sort keys %ipv6_strategies;
}
sub setv {
return {
'type' => shift,
'required' => shift,
'cache' => shift,
'default' => shift,
'minimum' => shift,
};
}
my %variables = (
'global-defaults' => {
'daemon' => setv(T_DELAY, 0, 0, $daemon_default, interval('60s')),
'foreground' => setv(T_BOOL, 0, 0, 0, undef),
'file' => setv(T_FILE, 0, 0, "$etc/$program.conf", undef),
'cache' => setv(T_FILE, 0, 0, "$cachedir/$program.cache", undef),
'pid' => setv(T_FILE, 0, 0, "", undef),
'proxy' => setv(T_FQDNP, 0, 0, undef, undef),
'protocol' => setv(T_PROTO, 0, 0, 'dyndns2', undef),
'use' => setv(T_USE, 0, 0, 'ip', undef),
'usev4' => setv(T_USEV4, 0, 0, 'disabled', undef),
'usev6' => setv(T_USEV6, 0, 0, 'disabled', undef),
'ip' => setv(T_IP, 0, 0, undef, undef),
'ipv4' => setv(T_IPV4, 0, 0, undef, undef),
'ipv6' => setv(T_IPV6, 0, 0, undef, undef),
'if' => setv(T_IF, 0, 0, 'ppp0', undef),
'ifv4' => setv(T_IF, 0, 0, 'default', undef),
'ifv6' => setv(T_IF, 0, 0, 'default', undef),
'web' => setv(T_STRING,0, 0, 'dyndns', undef),
'web-skip' => setv(T_STRING,1, 0, '', undef),
'webv4' => setv(T_STRING,0, 0, 'googledomains', undef),
'webv4-skip' => setv(T_STRING,1, 0, '', undef),
'webv6' => setv(T_STRING,0, 0, 'googledomains', undef),
'webv6-skip' => setv(T_STRING,1, 0, '', undef),
'fw' => setv(T_ANY, 0, 0, '', undef),
'fw-skip' => setv(T_STRING,1, 0, '', undef),
'fwv4' => setv(T_ANY, 0, 0, '', undef),
'fwv4-skip' => setv(T_STRING,1, 0, '', undef),
'fwv6' => setv(T_ANY, 0, 0, '', undef),
'fwv6-skip' => setv(T_STRING,1, 0, '', undef),
'fw-login' => setv(T_LOGIN, 1, 0, '', undef),
'fw-password' => setv(T_PASSWD,1, 0, '', undef),
'cmd' => setv(T_PROG, 0, 0, '', undef),
'cmd-skip' => setv(T_STRING,1, 0, '', undef),
'cmdv4' => setv(T_PROG, 0, 0, '', undef),
'cmdv6' => setv(T_PROG, 0, 0, '', undef),
'timeout' => setv(T_DELAY, 0, 0, interval('120s'), interval('120s')),
'retry' => setv(T_BOOL, 0, 0, 0, undef),
'force' => setv(T_BOOL, 0, 0, 0, undef),
'ssl' => setv(T_BOOL, 0, 0, 0, undef),
'curl' => setv(T_BOOL, 0, 0, 0, undef),
'syslog' => setv(T_BOOL, 0, 0, 0, undef),
'facility' => setv(T_STRING,0, 0, 'daemon', undef),
'priority' => setv(T_STRING,0, 0, 'notice', undef),
'mail' => setv(T_EMAIL, 0, 0, '', undef),
'mail-failure' => setv(T_EMAIL, 0, 0, '', undef),
'max-warn' => setv(T_NUMBER,0, 0, 1, undef),
'exec' => setv(T_BOOL, 0, 0, 1, undef),
'debug' => setv(T_BOOL, 0, 0, 0, undef),
'verbose' => setv(T_BOOL, 0, 0, 0, undef),
'quiet' => setv(T_BOOL, 0, 0, 0, undef),
'help' => setv(T_BOOL, 0, 0, 0, undef),
'test' => setv(T_BOOL, 0, 0, 0, undef),
'geturl' => setv(T_STRING,0, 0, '', undef),
'postscript' => setv(T_POSTS, 0, 0, '', undef),
'ssl_ca_dir' => setv(T_FILE, 0, 0, undef, undef),
'ssl_ca_file' => setv(T_FILE, 0, 0, undef, undef),
},
'service-common-defaults' => {
'server' => setv(T_FQDNP, 1, 0, 'members.dyndns.org', undef),
'login' => setv(T_LOGIN, 1, 0, '', undef),
'password' => setv(T_PASSWD,1, 0, '', undef),
'host' => setv(T_STRING,1, 1, '', undef),
'use' => setv(T_USE, 0, 0, 'ip', undef),
'usev4' => setv(T_USEV4, 0, 0, 'disabled', undef),
'usev6' => setv(T_USEV6, 0, 0, 'disabled', undef),
'if' => setv(T_IF, 0, 0, 'ppp0', undef),
'ifv4' => setv(T_IF, 0, 0, 'default', undef),
'ifv6' => setv(T_IF, 0, 0, 'default', undef),
'web' => setv(T_STRING,0, 0, 'dyndns', undef),
'web-skip' => setv(T_STRING,0, 0, '', undef),
'web-ssl-validate' => setv(T_BOOL, 0, 0, 1, undef),
'webv4' => setv(T_STRING,0, 0, 'googledomains', undef),
'webv4-skip' => setv(T_STRING,1, 0, '', undef),
'webv6' => setv(T_STRING,0, 0, 'googledomains', undef),
'webv6-skip' => setv(T_STRING,1, 0, '', undef),
'fw' => setv(T_ANY, 0, 0, '', undef),
'fw-skip' => setv(T_STRING,0, 0, '', undef),
'fw-login' => setv(T_LOGIN, 0, 0, '', undef),
'fw-password' => setv(T_PASSWD,0, 0, '', undef),
'fw-ssl-validate' => setv(T_BOOL, 0, 0, 1, undef),
'fwv4' => setv(T_ANY, 0, 0, '', undef),
'fwv4-skip' => setv(T_STRING,1, 0, '', undef),
'fwv6' => setv(T_ANY, 0, 0, '', undef),
'fwv6-skip' => setv(T_STRING,1, 0, '', undef),
'cmd' => setv(T_PROG, 0, 0, '', undef),
'cmd-skip' => setv(T_STRING,0, 0, '', undef),
'cmdv4' => setv(T_PROG, 0, 0, '', undef),
'cmdv6' => setv(T_PROG, 0, 0, '', undef),
'ip' => setv(T_IP, 0, 1, undef, undef), #TODO remove from cache?
'ipv4' => setv(T_IPV4, 0, 1, undef, undef),
'ipv6' => setv(T_IPV6, 0, 1, undef, undef),
'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')),
'mtime' => setv(T_NUMBER,0, 1, 0, undef),
'atime' => setv(T_NUMBER,0, 1, 0, undef),
'status' => setv(T_ANY, 0, 1, '', undef), #TODO remove from cache?
'status-ipv4' => setv(T_ANY, 0, 1, '', undef),
'status-ipv6' => setv(T_ANY, 0, 1, '', undef),
'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0),
'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0),
'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef),
'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, undef),
},
'dyndns-common-defaults' => {
'backupmx' => setv(T_BOOL, 0, 1, 0, undef),
'mx' => setv(T_OFQDN, 0, 1, '', undef),
'static' => setv(T_BOOL, 0, 1, 0, undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
},
'keysystems-common-defaults' => {
'server' => setv(T_FQDNP, 1, 0, 1, 'dynamicdns.key-systems.net', undef),
'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef),
},
'dnsexit-common-defaults' => {
'ssl' => setv(T_BOOL, 0, 0, 1, undef),
'server' => setv(T_FQDNP, 1, 0, 'update.dnsexit.com', undef),
'script' => setv(T_STRING, 0, 1, '/RemoteUpdate.sv', undef),
'min-error-interval' => setv(T_DELAY, 0, 0, interval('8m'), 0),
},
'regfishde-common-defaults' => {
'server' => setv(T_FQDNP, 1, 0, 'dyndns.regfish.de', undef),
'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef),
},
);
my %services = (
'1984' => {
'updateable' => undef,
'update' => \&nic_1984_update,
'examples' => \&nic_1984_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 0, 0, 'unused', undef),
'server' => setv(T_FQDNP, 1, 0, 'api.1984.is', undef),
},
},
'changeip' => {
'updateable' => undef,
'update' => \&nic_changeip_update,
'examples' => \&nic_changeip_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')),
'server' => setv(T_FQDNP, 1, 0, 'nic.changeip.com', undef),
},
},
'cloudflare' => {
'updateable' => undef,
'update' => \&nic_cloudflare_update,
'examples' => \&nic_cloudflare_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'backupmx' => setv(T_BOOL, 0, 1, 0, undef),
'login' => setv(T_LOGIN, 0, 0, 'token', undef),
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'mx' => setv(T_OFQDN, 0, 1, '', undef),
'server' => setv(T_FQDNP, 1, 0, 'api.cloudflare.com/client/v4', undef),
'static' => setv(T_BOOL, 0, 1, 0, undef),
'ttl' => setv(T_NUMBER, 1, 0, 1, undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
'zone' => setv(T_FQDN, 1, 0, '', undef),
},
},
'cloudns' => {
'updateable' => undef,
'update' => \&nic_cloudns_update,
'examples' => \&nic_cloudns_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'dynurl' => setv(T_STRING, 1, 0, undef, undef),
# nic_updateable() assumes that every service uses a username and password but that is
# not true for CloudNS. Silence warnings by redefining the username and password
# variables as non-required with a non-empty default.
'login' => setv(T_STRING, 0, 0, 'unused', undef),
'password' => setv(T_STRING, 0, 0, 'unused', undef),
},
},
'dinahosting' => {
'updateable' => undef,
'update' => \&nic_dinahosting_update,
'examples' => \&nic_dinahosting_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-error-interval' => setv(T_DELAY, 0, 0, interval('8m'), 0),
'script' => setv(T_STRING, 0, 1, '/special/api.php', undef),
'server' => setv(T_FQDNP, 1, 0, 'dinahosting.com', undef),
},
},
'dnsmadeeasy' => {
'updateable' => undef,
'update' => \&nic_dnsmadeeasy_update,
'examples' => \&nic_dnsmadeeasy_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'script' => setv(T_STRING, 1, 1, '/servlet/updateip', undef),
'server' => setv(T_FQDNP, 1, 0, 'cp.dnsmadeeasy.com', undef),
},
},
'dondominio' => {
'updateable' => undef,
'update' => \&nic_dondominio_update,
'examples' => \&nic_dondominio_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'server' => setv(T_FQDNP, 1, 0, 'dondns.dondominio.com', undef),
},
},
'dslreports1' => {
'updateable' => undef,
'update' => \&nic_dslreports1_update,
'examples' => \&nic_dslreports1_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'server' => setv(T_FQDNP, 1, 0, 'www.dslreports.com', undef),
'host' => setv(T_NUMBER, 1, 1, 0, undef),
},
},
'domeneshop' => {
'updateable' => undef,
'update' => \&nic_domeneshop_update,
'examples' => \&nic_domeneshop_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'server' => setv(T_FQDNP, 1, 0, 'api.domeneshop.no', undef),
},
},
'duckdns' => {
'updateable' => undef,
'update' => \&nic_duckdns_update,
'examples' => \&nic_duckdns_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 0, 0, 'unused', undef),
'server' => setv(T_FQDNP, 1, 0, 'www.duckdns.org', undef),
},
},
'dyndns1' => {
'updateable' => \&nic_dyndns2_updateable,
'update' => \&nic_dyndns1_update,
'examples' => \&nic_dyndns1_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
%{$variables{'dyndns-common-defaults'}},
},
},
'dyndns2' => {
'updateable' => \&nic_dyndns2_updateable,
'update' => \&nic_dyndns2_update,
'examples' => \&nic_dyndns2_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
%{$variables{'dyndns-common-defaults'}},
'custom' => setv(T_BOOL, 0, 1, 0, undef),
'script' => setv(T_STRING, 1, 1, '/nic/update', undef),
},
},
'easydns' => {
'updateable' => undef,
'update' => \&nic_easydns_update,
'examples' => \&nic_easydns_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'backupmx' => setv(T_BOOL, 0, 1, 0, undef),
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'mx' => setv(T_OFQDN, 0, 1, '', undef),
'server' => setv(T_FQDNP, 1, 0, 'api.cp.easydns.com', undef),
'script' => setv(T_STRING, 1, 1, '/dyn/generic.php', undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
},
},
'freedns' => {
'updateable' => undef,
'update' => \&nic_freedns_update,
'examples' => \&nic_freedns_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')),
'server' => setv(T_FQDNP, 1, 0, 'freedns.afraid.org', undef),
},
},
'freemyip' => {
'updateable' => undef,
'update' => \&nic_freemyip_update,
'examples' => \&nic_freemyip_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 0, 0, 'unused', undef),
'server' => setv(T_FQDNP, 1, 0, 'freemyip.com', undef),
},
},
'gandi' => {
'updateable' => undef,
'update' => \&nic_gandi_update,
'examples' => \&nic_gandi_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')),
'server' => setv(T_FQDNP, 1, 0, 'api.gandi.net', undef),
'script' => setv(T_STRING, 1, 1, '/v5', undef),
'ttl' => setv(T_DELAY, 0, 0, undef, interval('5m')),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
# Unused variables.
'login' => setv(T_STRING, 0, 0, 'unused', undef),
}
},
'godaddy' => {
'updateable' => undef,
'update' => \&nic_godaddy_update,
'examples' => \&nic_godaddy_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 1, 0, 'api.godaddy.com/v1/domains', undef),
'ttl' => setv(T_NUMBER, 1, 0, 600, undef),
'zone' => setv(T_FQDN, 1, 0, '', undef),
},
},
'googledomains' => {
'updateable' => undef,
'update' => \&nic_googledomains_update,
'examples' => \&nic_googledomains_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 1, 0, 'domains.google.com', undef),
},
},
'hetzner' => {
'updateable' => undef,
'update' => \&nic_hetzner_update,
'examples' => \&nic_hetzner_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 0, 0, 'token', undef),
'min-interval' => setv(T_DELAY, 0, 0, interval('1m'), 0),
'server' => setv(T_FQDNP, 1, 0, 'dns.hetzner.com/api/v1', undef),
'ttl' => setv(T_NUMBER, 0, 0, 60, 60),
'zone' => setv(T_FQDN, 1, 0, '', undef),
},
},
'mythicdyn' => {
'updateable' => undef,
'update' => \&nic_mythicdyn_update,
'examples' => \&nic_mythicdyn_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 1, 0, 'api.mythic-beasts.com', undef),
},
},
'namecheap' => {
'updateable' => undef,
'update' => \&nic_namecheap_update,
'examples' => \&nic_namecheap_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')),
'server' => setv(T_FQDNP, 1, 0, 'dynamicdns.park-your-domain.com', undef),
},
},
'nfsn' => {
'updateable' => undef,
'update' => \&nic_nfsn_update,
'examples' => \&nic_nfsn_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min_interval' => setv(T_FQDNP, 0, 0, 0, interval('5m')),
'server' => setv(T_FQDNP, 1, 0, 'api.nearlyfreespeech.net', undef),
'ttl' => setv(T_NUMBER, 1, 0, 300, undef),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
},
},
'njalla' => {
'updateable' => undef,
'update' => \&nic_njalla_update,
'examples' => \&nic_njalla_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'login' => setv(T_STRING, 0, 0, 'unused', undef),
'server' => setv(T_FQDNP, 1, 0, 'njal.la', undef),
'quietreply' => setv(T_BOOL, 0, 1, 0, undef)
},
},
'noip' => {
'updateable' => undef,
'update' => \&nic_noip_update,
'examples' => \&nic_noip_examples,
'variables' => {
'atime' => setv(T_NUMBER, 0, 1, 0, undef),
'custom' => setv(T_BOOL, 0, 1, 0, undef),
'host' => setv(T_STRING, 1, 1, '', undef),
'ip' => setv(T_IP, 0, 1, undef, undef),
'login' => setv(T_LOGIN, 1, 0, '', undef),
'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0),
'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0),
'mtime' => setv(T_NUMBER, 0, 1, 0, undef),
'password' => setv(T_PASSWD, 1, 0, '', undef),
'server' => setv(T_FQDNP, 1, 0, 'dynupdate.no-ip.com', undef),
'static' => setv(T_BOOL, 0, 1, 0, undef),
'status' => setv(T_ANY, 0, 1, '', undef),
'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, undef),
'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef),
'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')),
},
},
'nsupdate' => {
'updateable' => undef,
'update' => \&nic_nsupdate_update,
'examples' => \&nic_nsupdate_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 1, 0, '/usr/bin/nsupdate', undef),
'tcp' => setv(T_BOOL, 0, 1, 0, undef),
'ttl' => setv(T_NUMBER, 0, 1, 600, undef),
'zone' => setv(T_STRING, 1, 1, '', undef),
},
},
'ovh' => {
'updateable' => undef,
'update' => \&nic_ovh_update,
'examples' => \&nic_ovh_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'login' => setv(T_LOGIN, 1, 0, '', undef),
'password' => setv(T_PASSWD, 1, 0, '', undef),
'script' => setv(T_STRING, 1, 1, '/nic/update', undef),
'server' => setv(T_FQDNP, 1, 0, 'www.ovh.com', undef),
},
},
'sitelutions' => {
'updateable' => undef,
'update' => \&nic_sitelutions_update,
'examples' => \&nic_sitelutions_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'server' => setv(T_FQDNP, 1, 0, 'www.sitelutions.com', undef),
'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')),
},
},
'woima' => {
'updateable' => undef,
'update' => \&nic_woima_update,
'examples' => \&nic_woima_examples,
'variables' => {
'atime' => setv(T_NUMBER, 0, 1, 0, undef),
'backupmx' => setv(T_BOOL, 0, 1, 0, undef),
'custom' => setv(T_BOOL, 0, 1, 0, undef),
'ip' => setv(T_IP, 0, 1, undef, undef),
'login' => setv(T_LOGIN, 1, 0, '', undef),
'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0),
'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0),
'mtime' => setv(T_NUMBER, 0, 1, 0, undef),
'mx' => setv(T_OFQDN, 0, 1, '', undef),
'password' => setv(T_PASSWD, 1, 0, '', undef),
'script' => setv(T_STRING, 1, 1, '/nic/update', undef),
'server' => setv(T_FQDNP, 1, 0, 'dyn.woima.fi', undef),
'static' => setv(T_BOOL, 0, 1, 0, undef),
'status' => setv(T_ANY, 0, 1, '', undef),
'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, undef),
'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')),
},
},
'yandex' => {
'updateable' => undef,
'update' => \&nic_yandex_update,
'examples' => \&nic_yandex_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 1, 0, 'pddimp.yandex.ru', undef),
},
},
'zoneedit1' => {
'updateable' => undef,
'update' => \&nic_zoneedit1_update,
'examples' => \&nic_zoneedit1_examples,
'variables' => {
%{$variables{'service-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 1, 0, 'dynamic.zoneedit.com', undef),
'zone' => setv(T_OFQDN, 0, 0, undef, undef),
},
},
'keysystems' => {
'updateable' => undef,
'update' => \&nic_keysystems_update,
'examples' => \&nic_keysystems_examples,
'variables' => merge(
$variables{'keysystems-common-defaults'},
$variables{'service-common-defaults'},
),
},
'dnsexit' => {
'updateable' => undef,
'update' => \&nic_dnsexit_update,
'examples' => \&nic_dnsexit_examples,
'variables' => merge(
$variables{'dnsexit-common-defaults'},
$variables{'service-common-defaults'},
),
},
'regfishde' => {
'updateable' => undef,
'update' => \&nic_regfishde_update,
'examples' => \&nic_regfishde_examples,
'variables' => merge(
$variables{'regfishde-common-defaults'},
$variables{'service-common-defaults'},
),
},
);
$variables{'merged'} = {
map({ %{$services{$_}{'variables'}} } keys(%services)),
%{$variables{'dyndns-common-defaults'}},
%{$variables{'service-common-defaults'}},
%{$variables{'global-defaults'}},
};
# This will hold the processed args.
my %opt = ();
my $deprecated_handler = sub { warning("'-$_[0]' is deprecated and does nothing"); };
$opt{'fw-banlocal'} = $deprecated_handler;
$opt{'if-skip'} = $deprecated_handler;
$opt{'list-devices'} = sub {
printf("%s %s\n", $_, $builtinfw{$_}{name}) for sort(keys(%builtinfw));
exit(0);
};
$opt{'list-protocols'} = sub {
printf("%s\n", $_) for sort(keys(%services));
exit(0);
};
$opt{'list-web-services'} = sub {
printf("%s %s\n", $_, $builtinweb{$_}{url}) for sort(keys(%builtinweb));
exit(0);
};
my @opt = (
"usage: ${program} [options]",
"options are:",
["daemon", "=s", "-daemon <delay> : run as a daemon, specify <delay> as an interval"],
["foreground", "!", "-foreground : do not fork"],
["proxy", "=s", "-proxy <host> : use <host> as the HTTP proxy"],
["server", "=s", "-server <host> : update DNS information on <host>"],
["protocol", "=s", "-protocol <type> : update protocol used"],
["list-protocols", "", "-list-protocols : print a machine-readable list of supported update protocols and exit. Format: one per line"],
["file", "=s", "-file <path> : load configuration information from <path>"],
["cache", "=s", "-cache <path> : record address used in <path>"],
["pid", "=s", "-pid <path> : record process id in <path> if daemonized"],
"",
["use", "=s", "-use <which> : deprecated, see 'usev4' and 'usev6'"],
&ip_strategies_usage(),
[ "usev4", "=s", "-usev4 <which> : how the should IPv4 address be obtained."],
&ipv4_strategies_usage(),
[ "usev6", "=s", "-usev6 <which> : how the should IPv6 address be obtained."],
&ipv6_strategies_usage(),
"",
" Options that apply to 'use=ip':",
["ip", "=s", "-ip <address> : deprecated, use 'ipv4' or 'ipv6'"],
["ipv4", "=s", "-ipv4 <address> : set the IPv4 address to <address>"],
["ipv6", "=s", "-ipv6 <address> : set the IPv6 address to <address>"],
"",
" Options that apply to 'use=if':",
["if", "=s", "-if <interface> : deprecated, use 'ifv4' or 'ifv6'"],
["ifv4", "=s", "-ifv4 <interface> : obtain IPv4 address from <interface>"],
["ifv6", "=s", "-ifv6 <interface> : obtain IPv6 address from <interface>"],
"",