forked from ddclient/ddclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddclient.in
executable file
·7447 lines (6788 loc) · 299 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
#
# Original Author: Paul Burry ([email protected])
# Current maintainers:
# Reuben Thomas <[email protected]>
# Lenard Heß <[email protected]>
#
# website: https://github.com/ddclient/ddclient
#
######################################################################
package ddclient;
require v5.10.1;
use strict;
use warnings;
use Data::Dumper;
use File::Basename;
use File::Path qw(make_path);
use File::Temp;
use Getopt::Long;
use Sys::Hostname;
# Declare the ddclient version number.
#
# Perl's version strings do not support pre-release versions (alpha/development, beta, or release
# candidate) very well. The best it does is an optional underscore between arbitrary digits in the
# final component (e.g., "v1.2.3_4"). The underscore doesn't behave as most developers expect; it
# is treated as if it never existed (e.g., "v1.2.3_4" becomes "v1.2.34") except:
#
# * $v->is_alpha() will return true
# * $v->is_strict() will return false
# * $v->stringify() preserves the underscore (in its original position)
#
# Note that version::normal and version::numify lose information because the underscore is
# effectively removed.
#
# To work around Perl's limitations, human-readable versions are translated to/from Perl versions
# as follows:
#
# Human-readable Perl version Notes
# -------------------------------------------------------------------------------------------
# 1.2.3~alpha v1.2.3.0_0 compares equal to Perl version v1.2.3 (unfortunately)
# 1.2.3~betaN v1.2.3.0_N 1 <= N < 900; compares equal to Perl v1.2.3.N
# 1.2.3~rcN v1.2.3.0_M 1 <= N < 99; M = N + 900; compares equal to Perl v1.2.3.M
# 1.2.3 v1.2.3.999 for releases; no underscore in Perl version string
# 1.2.3rN v1.2.3.999.N 1 <= N < 1000; for re-releases, if necessary (rare)
#
# A tilde is used to separate "alpha", "beta", and "rc" from the version numbers because it has
# special meaning for the version comparison algorithms in RPM and Debian:
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Versioning/#_handling_non_sorting_versions_with_tilde_dot_and_caret
# https://manpages.debian.org/bookworm/dpkg-dev/deb-version.7.en.html
#
# No period separator is required between "beta", "rc", or "r" and its adjacent number(s); both RPM
# and Debian will compare the adjacent number numerically, not lexicographically ("~beta2" sorts
# before "~beta10" as expected).
#
# The Perl version is declared first then converted to a human-readable form. It would be nicer to
# declare a human-readable version string and convert that to a Perl version string, but various
# tools in the Perl ecosystem require the line of source code that defines the VERSION variable to
# be self-contained (because they grep the source code and evaluate only that one line).
#
# For consistency and to match user expectations, the release part of the version is always three
# components: MAJOR.MINOR.PATCH.
use version 0.77; our $VERSION = version->declare('v4.0.0.0_0');
sub parse_version {
my ($v) = @_;
# Matches a non-negative integer with 1-3 decimal digits (zero padding disallowed).
my $n = qr/0|[1-9]\d{0,2}/;
my $vre = qr/
^
v # required "v" prefix
((?:$n\.)*?$n) # release version (e.g., 1.2, 1.2.3, or 1.2.3.4)
\.(?: # release or pre-release suffix
0_(?!999)($n)| # pre-release (alpha, beta, rc) revision
999(?:\.($n))? # release with optional re-release revision
)
$
/x;
return $v =~ $vre;
}
sub humanize_version {
my ($v) = @_;
my ($r, $pr, $rr) = parse_version($v);
return $v if !defined($r);
$v = $r;
if (!defined($pr)) {
$v .= "r$rr" if defined($rr);
} elsif ($pr eq '0') {
$v .= '~alpha';
} elsif ($pr < 900) {
$v .= "~beta$pr";
} elsif ($pr < 999) {
$v .= '~rc' . ($pr - 900);
}
return $v;
}
our $version = humanize_version($VERSION);
my $programd = $0;
$programd =~ s%^.*/%%;
my $program = $programd;
$program =~ s/d$//;
our $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';
our @curl = (subst_var('@CURL@', 'curl'));
our $emailbody = '';
my $last_emailbody = '';
## 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') : undef;
# Current Logger instance. To push a context prefix onto the context stack:
# local _l = pushlogctx('additional context goes here');
our $_l = ddclient::Logger->new();
our @_test_headers;
$ENV{'PATH'} = (exists($ENV{PATH}) ? "$ENV{PATH}:" : "") . "/sbin:/usr/sbin:/bin:/usr/bin:/etc:/usr/lib:";
our %globals;
our %config;
# %recap holds details about recent updates (and attempts) that are needed to implement various
# service-specific and protocol-independent mechanisms such as `min-interval`. This data is
# persisted in the cache file (`--cache`) so that it survives ddclient restarts. This hash maps a
# hostname to a hashref containing those protocol variables that have their `recap` property set to
# true.
#
# A note about terminology: This was previously named `%cache`, but "cache" implies that the
# purpose is to reduce the cost or latency of data retrieval or computation, and that deletion only
# affects performance. That is not the case here, so the variable was renamed. "Recap" is meant
# to evoke the "previously on" clips that play before TV episodes, which are designed to give you
# just enough context to recall the state. The recap is written to the cache file, so-named for
# historical reasons. (Renaming "cache file" to "recap file" is more difficult due to
# compatibility concerns with the public `--cache` option.)
our %recap;
my $result;
my $saved_recap;
my %saved_opt;
my $daemon;
# Control how many times warning message logged for invalid IP addresses
my (%warned_ip, %warned_ipv4, %warned_ipv6);
sub repr {
my $vals = @_ % 2 ? [shift] : [];
my %opts = @_;
my $d = Data::Dumper->new($vals)->Sortkeys(1)->Terse(!exists($opts{Names}))->Useqq(1);
$d->$_($opts{$_}) for keys(%opts);
return $d->Dump();
}
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.
our %builtinweb = (
'dyndns' => {'url' => 'http://checkip.dyndns.org/', 'skip' => 'Current IP Address:'},
'freedns' => {'url' => 'https://freedns.afraid.org/dynamic/check.php'},
'he' => {
url => 'https://checkip.dns.he.net/',
deprecated => "Use 'he.net' instead.",
},
'he.net' => {'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'},
);
sub query_cisco {
my ($h, $asa, $v4) = @_;
warning("'--if' is deprecated; use '--ifv4' instead")
if ($v4 && !defined(opt('ifv4', $h)) && defined(opt('if', $h)));
my $if = ($v4 ? opt('ifv4', $h) : undef) // opt('if', $h);
my $fw = ($v4 ? opt('fwv4', $h) : undef) // opt('fw', $h);
# Convert slashes to protected value "\/"
$if =~ s%\/%\\\/%g;
# Protect special HTML characters (like '?')
$if =~ s/([\?&= ])/sprintf("%%%02x", ord($1))/ge;
my $reply = geturl(
url => ($asa)
? "https://$fw/exec/show%20interface%20$if"
: "http://$fw/level/1/exec/show/ip/interface/brief/$if/CR",
login => opt('fw-login', $h),
password => opt('fw-password', $h),
ignore_ssl_option => 1,
ssl_validate => opt('fw-ssl-validate', $h),
);
return undef if !header_ok($reply, \&warning);
$reply =~ s/^.*?\n\n//s;
return $reply;
}
our %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',
},
'cisco' => {
'name' => 'Cisco FW',
'query' => sub { return query_cisco($_[0], 0, 0); },
'queryv4' => sub { return query_cisco($_[0], 0, 1); },
'help' => sub { return " at the host given by --fw$_[0]=<host> and interface given by --if$_[0]=<interface>"; },
},
'cisco-asa' => {
'name' => 'Cisco ASA',
'query' => sub { return query_cisco($_[0], 1, 0); },
'queryv4' => sub { return query_cisco($_[0], 1, 1); },
'help' => sub { return " at the host given by --fw$_[0]=<host> and interface given by --if$_[0]=<interface>"; },
},
'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 = (
'disabled' => ": do not use a deprecated method to obtain an IP address for this host",
'no' => ": deprecated, see '--use=disabled'",
'ip' => ": deprecated, see '--usev4=ipv4' and '--usev6=ipv6'",
'web' => ": deprecated, see '--usev4=webv4' and '--usev6=webv6'",
'fw' => ": deprecated, see '--usev4=fwv4' and '--usev6=fwv6'",
'if' => ": deprecated, see '--usev4=ifv4' and '--usev6=ifv6'",
'cmd' => ": deprecated, see '--usev4=cmdv4' and '--usev6=cmdv6'",
map({
my $fw = $builtinfw{$_};
$_ => ": deprecated, see '--usev4=$_'" .
(defined($fw->{queryv6}) ? " and '--usev6=$_'" : '');
} keys(%builtinfw)),
);
sub ip_strategies_usage {
return map({ sprintf(" --use=%-22s %s.", $_, $ip_strategies{$_}) }
'disabled', 'no', 'ip', 'web', 'if', 'cmd', 'fw', sort(keys(%builtinfw)));
}
my %ipv4_strategies = (
'disabled' => ": do not obtain an IPv4 address for this host (except possibly via the deprecated '--use' option, if it is enabled)",
'ipv4' => ": obtain IPv4 from the address given by --ipv4=<address>",
'webv4' => ": obtain IPv4 from an IP discovery page on the web",
'ifv4' => ": obtain IPv4 from the interface given by --ifv4=<interface>",
'cmdv4' => ": obtain IPv4 from the command given by --cmdv4=<command>",
'fwv4' => ": obtain IPv4 from the URL given by --fwv4=<URL>",
map({
my $fw = $builtinfw{$_};
$_ => defined($fw->{queryv4})
? ": obtain IPv4 from $fw->{name}@{[($fw->{help} // sub {})->('v4') // '']}"
: ": obtain IPv4 from $fw->{name} at the host or URL given by --fwv4=<host|URL>";
} keys(%builtinfw)),
);
sub ipv4_strategies_usage {
return map({ sprintf(" --usev4=%-22s %s.", $_, $ipv4_strategies{$_}) }
'disabled', 'ipv4', 'webv4', 'ifv4', 'cmdv4', 'fwv4', sort(keys(%builtinfw)));
}
my %ipv6_strategies = (
'disabled' => ": do not obtain an IPv6 address for this host (except possibly via the deprecated '--use' option, if it is enabled)",
'no' => ": deprecated, use '--usev6=disabled'",
'ipv6' => ": obtain IPv6 from the address given by --ipv6=<address>",
'ip' => ": deprecated, use '--usev6=ipv6'",
'webv6' => ": obtain IPv6 from an IP discovery page on the web",
'web' => ": deprecated, use '--usev6=webv6'",
'ifv6' => ": obtain IPv6 from the interface given by --ifv6=<interface>",
'if' => ": deprecated, use '--usev6=ifv6'",
'cmdv6' => ": obtain IPv6 from the command given by --cmdv6=<command>",
'cmd' => ": deprecated, use '--usev6=cmdv6'",
'fwv6' => ": obtain IPv6 from the URL given by --fwv6=<URL>",
map({
my $fw = $builtinfw{$_};
defined($fw->{queryv6})
? ($_ => ": obtain IPv6 from $fw->{name}@{[($fw->{help} // sub {})->('v6') // '']}")
: ();
} keys(%builtinfw)),
);
sub ipv6_strategies_usage {
return map({ sprintf(" --usev6=%-22s %s.", $_, $ipv6_strategies{$_}) }
'disabled', 'no', 'ipv6', 'ip', 'webv6', 'web', 'ifv6', 'if', 'cmdv6', 'cmd',
'fwv6', sort(map({exists($ipv6_strategies{$_}) ? ($_) : ()} keys(%builtinfw))));
}
sub setv {
return {
'type' => shift,
'required' => shift,
'recap' => shift,
'default' => shift,
'minimum' => shift,
};
}
our %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, 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,0, 0, undef, undef),
'webv4' => setv(T_STRING,0, 0, 'ipify-ipv4', undef),
'webv4-skip' => setv(T_STRING,0, 0, undef, undef),
'webv6' => setv(T_STRING,0, 0, 'ipify-ipv6', undef),
'webv6-skip' => setv(T_STRING,0, 0, undef, undef),
'fw' => setv(T_ANY, 0, 0, undef, undef),
'fw-skip' => setv(T_STRING,0, 0, undef, undef),
'fwv4' => setv(T_ANY, 0, 0, undef, undef),
'fwv4-skip' => setv(T_STRING,0, 0, undef, undef),
'fwv6' => setv(T_ANY, 0, 0, undef, undef),
'fwv6-skip' => setv(T_STRING,0, 0, undef, undef),
'fw-login' => setv(T_LOGIN, 0, 0, undef, undef),
'fw-password' => setv(T_PASSWD,0, 0, undef, undef),
'cmd' => setv(T_PROG, 0, 0, undef, undef),
'cmd-skip' => setv(T_STRING,0, 0, undef, undef),
'cmdv4' => setv(T_PROG, 0, 0, undef, undef),
'cmdv6' => setv(T_PROG, 0, 0, undef, 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, 1, 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, undef),
'mail-failure' => setv(T_EMAIL, 0, 0, undef, 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),
'postscript' => setv(T_POSTS, 0, 0, undef, undef),
'ssl_ca_dir' => setv(T_FILE, 0, 0, undef, undef),
'ssl_ca_file' => setv(T_FILE, 0, 0, undef, undef),
'redirect' => setv(T_NUMBER,0, 0, 0, undef)
},
'protocol-common-defaults' => {
'server' => setv(T_FQDNP, 0, 0, 'members.dyndns.org', undef),
'login' => setv(T_LOGIN, 1, 0, undef, undef),
'password' => setv(T_PASSWD,1, 0, undef, undef),
'host' => setv(T_STRING,1, 1, undef, 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, undef),
'web-ssl-validate' => setv(T_BOOL, 0, 0, 1, undef),
'webv4' => setv(T_STRING,0, 0, 'ipify-ipv4', undef),
'webv4-skip' => setv(T_STRING,0, 0, undef, undef),
'webv6' => setv(T_STRING,0, 0, 'ipify-ipv6', undef),
'webv6-skip' => setv(T_STRING,0, 0, undef, undef),
'fw' => setv(T_ANY, 0, 0, undef, undef),
'fw-skip' => setv(T_STRING,0, 0, undef, undef),
'fw-login' => setv(T_LOGIN, 0, 0, undef, undef),
'fw-password' => setv(T_PASSWD,0, 0, undef, undef),
'fw-ssl-validate' => setv(T_BOOL, 0, 0, 1, undef),
'fwv4' => setv(T_ANY, 0, 0, undef, undef),
'fwv4-skip' => setv(T_STRING,0, 0, undef, undef),
'fwv6' => setv(T_ANY, 0, 0, undef, undef),
'fwv6-skip' => setv(T_STRING,0, 0, undef, undef),
'cmd' => setv(T_PROG, 0, 0, undef, undef),
'cmd-skip' => setv(T_STRING,0, 0, undef, undef),
'cmdv4' => setv(T_PROG, 0, 0, undef, undef),
'cmdv6' => setv(T_PROG, 0, 0, undef, 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),
# As a recap value, this is the IP address (IPv4 or IPv6, but almost always IPv4) most
# recently saved at the DDNS service. As a setting, this is the desired IP address that
# should be saved at the DDNS service. Unfortunately, these two meanings are conflated,
# causing the bug "skipped: IP address was already set to a.b.c.d" when the IP was never
# set to a.b.c.d.
# TODO: Move the recap value elsewhere to fix the bug.
'ip' => setv(T_IP, 0, 1, undef, undef),
# As `ip`, but only IPv4 addresses.
'ipv4' => setv(T_IPV4, 0, 1, undef, undef),
# As `ip`, but only IPv6 addresses.
'ipv6' => setv(T_IPV6, 0, 1, undef, undef),
# Timestamp (seconds since epoch) indicating the earliest time the next update is
# permitted.
# TODO: Create a timestamp type and change this to that type.
'wtime' => setv(T_NUMBER,0, 1, undef, undef),
# Timestamp (seconds since epoch) indicating when an IP address was last sent to the DDNS
# service, even if the IP address was not different from what was already stored.
# TODO: Create a timestamp type and change this to that type.
'mtime' => setv(T_NUMBER,0, 1, 0, undef),
# Timestamp (seconds since epoch) of the most recent attempt to update the DDNS service
# (including attempts to update with the same IP address). This equals mtime if the most
# recent attempt was successful, otherwise it will be more recent than mtime.
# TODO: Create a timestamp type and change this to that type.
'atime' => setv(T_NUMBER,0, 1, 0, undef),
# Disposition of the most recent (or currently in progress) attempt to update the DDNS
# service with the IP address in `wantip`. Anything other than `good`, including undef, is
# treated as a failure.
'status' => setv(T_ANY, 0, 1, undef, undef),
# As `status`, but with `wantipv4`.
'status-ipv4' => setv(T_ANY, 0, 1, undef, undef),
# As `status`, but with `wantipv6`.
'status-ipv6' => setv(T_ANY, 0, 1, undef, undef),
# Timestamp (seconds since epoch) of the most recent attempt that would have been made had
# `min-interval` not inhibited the attempt. This is reset to 0 once an attempt is actually
# made. This is used as a boolean to suppress repeated warnings to the user that indicate
# that `min-interval` has inhibited an update attempt.
# TODO: Change to a boolean and rename to improve readability.
'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef),
# Timestamp (seconds since epoch) of the most recent attempt that would have been made had
# `min-error-interval` not inhibited the attempt. This is reset to 0 once an attempt is
# actually made. This is used as a boolean to suppress repeated warnings to the user that
# indicate that `min-error-interval` has inhibited an update attempt.
# TODO: Change to a boolean and rename to improve readability.
'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, undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
},
);
our %protocols = (
'1984' => {
'update' => \&nic_1984_update,
'examples' => \&nic_1984_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'server' => setv(T_FQDNP, 0, 0, 'api.1984.is', undef),
},
},
'changeip' => {
'update' => \&nic_changeip_update,
'examples' => \&nic_changeip_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'server' => setv(T_FQDNP, 0, 0, 'nic.changeip.com', undef),
},
},
'cloudflare' => {
'update' => \&nic_cloudflare_update,
'examples' => \&nic_cloudflare_examples,
'variables' => {
%{$variables{'protocol-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, undef),
'server' => setv(T_FQDNP, 0, 0, 'api.cloudflare.com/client/v4', undef),
'static' => setv(T_BOOL, 0, 1, 0, undef),
'ttl' => setv(T_NUMBER, 0, 0, 1, undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
},
},
'cloudns' => {
'update' => \&nic_cloudns_update,
'examples' => \&nic_cloudns_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'password' => undef,
'dynurl' => setv(T_STRING, 1, 0, undef, undef),
},
},
'ddns.fm' => {
'update' => \&nic_ddnsfm_update,
'examples' => \&nic_ddnsfm_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'server' => setv(T_FQDNP, 0, 0, 'https://api.ddns.fm', undef),
},
},
'digitalocean' => {
'update' => \&nic_digitalocean_update,
'examples' => \&nic_digitalocean_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'server' => setv(T_FQDNP, 0, 0, 'api.digitalocean.com', undef),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
},
},
'dinahosting' => {
'update' => \&nic_dinahosting_update,
'examples' => \&nic_dinahosting_examples,
'variables' => {
%{$variables{'protocol-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, 0, 0, 'dinahosting.com', undef),
},
},
'dnsmadeeasy' => {
'update' => \&nic_dnsmadeeasy_update,
'examples' => \&nic_dnsmadeeasy_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'script' => setv(T_STRING, 0, 1, '/servlet/updateip', undef),
'server' => setv(T_FQDNP, 0, 0, 'cp.dnsmadeeasy.com', undef),
},
},
'dondominio' => {
'update' => \&nic_dondominio_update,
'examples' => \&nic_dondominio_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'server' => setv(T_FQDNP, 0, 0, 'dondns.dondominio.com', undef),
},
},
'dslreports1' => {
'update' => \&nic_dslreports1_update,
'examples' => \&nic_dslreports1_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'server' => setv(T_FQDNP, 0, 0, 'www.dslreports.com', undef),
},
},
'domeneshop' => {
'update' => \&nic_domeneshop_update,
'examples' => \&nic_domeneshop_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'server' => setv(T_FQDNP, 0, 0, 'api.domeneshop.no', undef),
},
},
'duckdns' => {
'update' => \&nic_duckdns_update,
'examples' => \&nic_duckdns_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'server' => setv(T_FQDNP, 0, 0, 'www.duckdns.org', undef),
},
},
'dyndns1' => {
'update' => \&nic_dyndns1_update,
'examples' => \&nic_dyndns1_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
%{$variables{'dyndns-common-defaults'}},
'static' => setv(T_BOOL, 0, 1, 0, undef),
},
},
'dyndns2' => {
'update' => \&nic_dyndns2_update,
'examples' => \&nic_dyndns2_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
%{$variables{'dyndns-common-defaults'}},
'script' => setv(T_STRING, 0, 1, '/nic/update', undef),
},
},
'easydns' => {
'update' => \&nic_easydns_update,
'examples' => \&nic_easydns_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'backupmx' => setv(T_BOOL, 0, 1, 0, undef),
# From <https://kb.easydns.com/knowledge/dynamic-dns/>: "You need to wait at least 10
# minutes between updates."
'min-interval' => setv(T_DELAY, 0, 0, interval('10m'), 0),
'mx' => setv(T_OFQDN, 0, 1, undef, undef),
'server' => setv(T_FQDNP, 0, 0, 'api.cp.easydns.com', undef),
'script' => setv(T_STRING, 0, 1, '/dyn/generic.php', undef),
'wildcard' => setv(T_BOOL, 0, 1, 0, undef),
},
},
'freedns' => {
'update' => \&nic_freedns_update,
'examples' => \&nic_freedns_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), interval('5m')),
'server' => setv(T_FQDNP, 0, 0, 'freedns.afraid.org', undef),
},
},
'freemyip' => {
'update' => \&nic_freemyip_update,
'examples' => \&nic_freemyip_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'server' => setv(T_FQDNP, 0, 0, 'freemyip.com', undef),
},
},
'gandi' => {
'update' => \&nic_gandi_update,
'examples' => \&nic_gandi_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), interval('5m')),
'server' => setv(T_FQDNP, 0, 0, 'api.gandi.net', undef),
'script' => setv(T_STRING, 0, 1, '/v5', undef),
'use-personal-access-token' => setv(T_BOOL, 0, 0, 0, undef),
'ttl' => setv(T_DELAY, 0, 0, undef, interval('5m')),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
}
},
'godaddy' => {
'update' => \&nic_godaddy_update,
'examples' => \&nic_godaddy_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 0, 0, 'api.godaddy.com/v1/domains', undef),
'ttl' => setv(T_NUMBER, 0, 0, 600, undef),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
},
},
'he.net' => {
'update' => \&nic_henet_update,
'examples' => \&nic_henet_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 0, 0, 'dyn.dns.he.net', undef),
},
},
'hetzner' => {
'update' => \&nic_hetzner_update,
'examples' => \&nic_hetzner_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'min-interval' => setv(T_DELAY, 0, 0, interval('1m'), 0),
'server' => setv(T_FQDNP, 0, 0, 'dns.hetzner.com/api/v1', undef),
'ttl' => setv(T_NUMBER, 0, 0, 60, 60),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
},
},
'inwx' => {
'update' => \&nic_inwx_update,
'examples' => \&nic_inwx_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'server' => setv(T_FQDNP, 0, 0, 'dyndns.inwx.com', undef),
'script' => setv(T_STRING, 0, 0, '/nic/update', undef),
},
},
'mythicdyn' => {
'update' => \&nic_mythicdyn_update,
'examples' => \&nic_mythicdyn_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0),
'server' => setv(T_FQDNP, 0, 0, 'api.mythic-beasts.com', undef),
},
},
'namecheap' => {
'update' => \&nic_namecheap_update,
'examples' => \&nic_namecheap_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), interval('5m')),
'server' => setv(T_FQDNP, 0, 0, 'dynamicdns.park-your-domain.com', undef),
},
},
'nfsn' => {
'update' => \&nic_nfsn_update,
'examples' => \&nic_nfsn_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'min-interval' => setv(T_DELAY, 0, 0, interval('5m'), interval('5m')),
'server' => setv(T_FQDNP, 0, 0, 'api.nearlyfreespeech.net', undef),
'ttl' => setv(T_NUMBER, 0, 0, 300, undef),
'zone' => setv(T_FQDN, 1, 0, undef, undef),
},
},
'njalla' => {
'update' => \&nic_njalla_update,
'examples' => \&nic_njalla_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => undef,
'server' => setv(T_FQDNP, 0, 0, 'njal.la', undef),
'quietreply' => setv(T_BOOL, 0, 1, 0, undef),
},
},
'noip' => {
'update' => \&nic_noip_update,
'examples' => \&nic_noip_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'server' => setv(T_FQDNP, 0, 0, 'dynupdate.no-ip.com', undef),
},
},
'nsupdate' => {
'update' => \&nic_nsupdate_update,
'examples' => \&nic_nsupdate_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'login' => setv(T_LOGIN, 0, 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, undef),
},
},
'ovh' => {
'update' => \&nic_ovh_update,
'examples' => \&nic_ovh_examples,
'variables' => {
%{$variables{'protocol-common-defaults'}},
'script' => setv(T_STRING, 0, 1, '/nic/update', undef),
'server' => setv(T_FQDNP, 0, 0, 'www.ovh.com', undef),
},
},
'porkbun' => {