This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
/
freenom.sh
executable file
·1794 lines (1696 loc) · 69.3 KB
/
freenom.sh
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
#!/bin/bash
###############################################################################
# Domain Renewal and Dynamic DNS shell script for freenom.com #
###############################################################################
# #
# Updates IP address and/or auto renews domain(s) so they do not expire #
# See README.md for more information #
# #
# freenom-script Copyright (C) 2019 M. Korthof #
# This program comes with ABSOLUTELY NO WARRANTY #
# This is free software, and you are welcome to redistribute it #
# under certain conditions. #
# See LICENSE file for more information #
# gpl-3.0-only v2023-08-03 #
###############################################################################
# shellcheck disable=SC2317
########
# Main #
########
set -eo pipefail
# check some requirements
for i in curl grep date basename dirname sed; do
if ! command -v $i >/dev/null 2>&1; then
echo "Error: could not find \"$i\", exiting..."
exit 1
fi
done
if [ -z "$BASH" ]; then
echo "Warning: bash not detected"
fi
if [ "$(readlink /proc/$$/exe 2>&1)" = "/bin/busybox" ]; then
echo "Warning: looks like we're running under BusyBox"
fi
scriptName="$(basename "$0")"
infoCount="0"
warnCount="0"
errCount="0"
oldCurl="0"
if curl --version | grep -Eiq "^curl (7\.[0-5]|[0-6]\.)"; then
oldCurl=1
fi
if [[ -n "$freenom_oldcurl_force" && "${freenom_oldcurl_force:-0}" -eq 1 ]]; then
oldCurl=1
else
oldCurl=0
fi
########
# Conf #
########
# configuration file from argument '-c'
SAVE_IFS="$IFS"
IFS='|'
c=0
for i in "$@"; do
if printf -- "%s" "$i" | grep -Eq -- "(^|[^a-z])-c"; then
c=1
continue
else
if [ "${c:-0}" -eq 1 ]; then
if printf -- "%s" "$i" | grep -Eq -- "^-"; then
echo "Error: config file not specfied, try \"$scriptName -h\""
exit 1
fi
scriptConf="$i"
if [ ! -s "$scriptConf" ]; then
echo "Error: invalid config file \"$scriptConf\" specified"
exit 1
fi
break
fi
fi
done
IFS="$SAVE_IFS"
# if scriptConf is empty, check for {/usr/local,}/etc/freenom.conf and in same dir as script
if [ -z "$scriptConf" ]; then
sc1="$(dirname "$0")/$(basename -s '.sh' "$0").conf"
sc2="${BASH_SOURCE[0]/%.sh/}.conf"
for i in "/usr/local/etc/freenom.conf" "/etc/freenom.conf" "$sc1" "$sc2"; do
if [ -e "$i" ]; then
scriptConf="$i"
break
fi
done
fi
unset -v i
# make sure we dont source ourselves
if [ "$scriptConf" = "$0" ] || [ "$scriptConf" = "${BASH_SOURCE[0]}" ]; then
echo "Error: invalid config file \"$scriptConf\" specified"
exit 1
fi
# source scriptConf if its non empty, else exit
if [ -n "$scriptConf" ] && [ -s "$scriptConf" ]; then
# shellcheck source=/usr/local/etc/freenom.conf
source "$scriptConf" || {
echo "Error: could not load $scriptConf"
exit 1
}
fi
# make sure debug is always set
if [ -z "$debug" ]; then
debug=0
fi
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $pad8 $pad8 debug=$debug curlExtraOpts=$curlExtraOpts"
echo "DEBUG: $pad8 conf $pad8 scriptConf=$scriptConf"
fi
# check args for help
help=0
if printf -- "%s" "$*" | grep -Eqi '(^|[^a-z])-h'; then
help=1
fi
# config checks: we need these settings, so if they do not exist 'exit'
if [ -z "$freenom_email" ]; then
echo "Error: setting \"freenom_email\" is missing in config"
if [ "${help:-0}" -eq 0 ]; then
exit 1
fi
fi
if [ -z "$freenom_passwd" ]; then
echo "Error: setting \"freenom_passwd\" is missing in config"
if [ "${help:-0}" -eq 0 ]; then
exit 1
fi
fi
# if needed create freenom_out_dir. if out_path is not set or invalid, set default
if [ -d "$(dirname "$freenom_out_dir")" ]; then
if [ ! -d "$freenom_out_dir}" ]; then
mkdir "${freenom_out_dir}" >/dev/null 2>&1 || true
fi
fi
out_path="${freenom_out_dir}/${freenom_out_mask}"
if [[ -z "$freenom_out_dir" || -z "$freenom_out_mask" || ! -d "$freenom_out_dir" ]]; then
out_path="/var/log/$(basename -s '.sh' "$0")"
echo "Warning: no valid \"freenom_out_dir\" or \"mask\" setting found, using default path: $out_path"
fi
if [ ! -e "${out_path}.log" ]; then
touch "${out_path}.log" >/dev/null 2>&1 || true
fi
if [ ! -w "${out_path}.log" ]; then
if [ "${help:-0}" -eq 0 ]; then
echo "Info: logfile \"${out_path}.log\" not writable, using \"/tmp/$(basename -s '.sh' "$0").log\""
fi
out_path="/tmp/$(basename -s '.sh' "$0")"
fi
# shellcheck disable=SC2128
if [ -z "$uaString" ]; then
echo "Error: setting \"uaString\" is missing in config"
if [ "${help:-0}" -eq 0 ]; then
exit 1
fi
fi
# shellcheck disable=SC2128
if [ -z "$ipCmd" ]; then
echo "Error: setting \"ipCmd\" is missing in config"
if [ "${help:-0}" -eq 0 ]; then
exit 1
fi
fi
if [ -z "$RCPTTO" ]; then
RCPTTO="$freenom_email"
fi
if [ ! -x "$MTA" ]; then
if [ -x "/usr/sbin/sendmail" ]; then
MTA="/usr/sbin/sendmail"
else
MTA=""
echo "Warning: No MTA found, cant send email"
fi
fi
# set a few general variables
c_opts="--connect-timeout 30 --compressed -L -s"
# generate "random" useragent string, used for curl and below in func_randIp
agent="${uaString[$((RANDOM % ${#uaString[@]}))]}"
# add http code to curl output
http_code="<!--http_code=%{http_code}-->"
ipRE='((((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])))|(((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?))'
pad4="$(printf "%*s" 4 " ")"
pad8="$(printf "%*s" 8 " ")"
# DEBUG: add proxy to curlExtraOpts
debug_proxy=0
if [ "${debug_proxy:-0}" -eq 1 ]; then
curlExtraOpts+=" --proxy http://localhost:3128"
fi
# Make sure 'my.freenom.com' resolves correctly
if [ "${freenom_http_resolve:-0}" -eq 1 ]; then
if curl --max-time 10 --dns-servers "$curlDns" my.freenom.com >/dev/null 2>&1; then
curlExtraOpts+=" --dns-servers $curlDns"
else
for ((i = 0; i < ${#resolveCmd[@]}; i++)); do
_myfn_ip=$(${resolveCmd[$i]} 2>/dev/null | awk '/^(.*[aA]ddress:? )?[0-9.]+$/{ print $NF; exit }')
if [[ "$_myfn_ip" =~ ^$ipRE$ ]]; then
curlExtraOpts+=" --resolve my.freenom.com:443:$_myfn_ip"
break
fi
done
fi
fi
# AWS WAF CAPTCHA token. To manually get it from browser:
# goto my.freenom.com, solve captcha puzzle and copy cookie 'aws-waf-token' (valid ~3 mins)
if [ -n "$AWS_WAF_TOKEN" ]; then
TOKEN="${AWS_WAF_TOKEN#aws-waf-token=}"
if echo "$TOKEN" | grep -Eq '[0-9a-f-]{36}:[A-Za-z0-9+/]{16}:[A-Za-z0-9+/=]{64,}'; then
curlExtraOpts+=" -b aws-waf-token=${TOKEN} "
else
echo "Error: Incorrect AWS WAF CAPTCHA token"
exit 1
fi
else
_wmsg="Warning: Missing AWS WAF CAPTCHA token"
echo "$_wmsg (\$AWS_WAF_TOKEN not set)"
echo -e "[$(date)] [$$] $_wmsg" >>"${out_path}.log"
fi
#############
# Functions #
#############
# Function cleanup: remove cookie file using trap
func_cleanup() {
if [[ -n "$cookie_file" && -f "$cookie_file" ]]; then
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $(date '+%H:%M:%S') func_cleanup cookie_file=$cookie_file"
fi
rm "$cookie_file"
fi
}
trap "func_cleanup" EXIT HUP INT TERM
# Function help: displays options etc
func_help() {
cat <<-_EOF_
freenom.com Domain Renewal and DynDNS
-------------------------------------
Usage: $scriptName -l [-d]
$scriptName -r <domain OR -a> [-s <subdomain>]
$scriptName -u <domain> [-s <subdomain>] [-m <ip>] [-f]
$scriptName -z <domain>
Options: -l List all domains and id's in account
add [-d] to show renewal Details
-r Renew <domain> or use '-r -a' to update All
add [-s] to renew <Subdomain>
-u Update <domain> A record with current ip
add [-s] to update <Subdomain> record
add [-m <ip>] to Manually update static <ip>
add [-f] to Force update on unchanged ip
-z Zone for <domain>, shows dns records
-4 Use ipv4 and modify A record on "-u" (default)
-6 Use ipv6 and modify AAAA record on "-u"
-c Config <file> to use, instead of freenom.conf
-i Ip commands list, used to get current ip
-o Output renewals, shows html file(s)
Examples ./$scriptName -r example.com
./$scriptName -c /etc/mycustom.conf -r -a
./$scriptName -u example.com -s mail
* When "-u" or "-r" is used with argument <domain>
any settings in script or config file are overridden
_EOF_
# TEST: use [-a] with -u to update All domains and records
# ./$scriptName -u -a
exit 0
}
# Function getDomainArgs: use regexps to get domain name, id etc
func_getDomainArgs() {
local _d_args
local _arg_domain_name
local _arg_domain_id
local _arg_subdomain_name
local _subdom_set
# check for subdomain arg '-s'
_subdom_set=0
if printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-s'; then
_subdom_set=1
fi
# first remove debug arg...
_d_args="$(echo "$*" | sed -E 's/ ?-debug ([0-9])//')"
# ...then remove '-c' arg and save other options to $_d_args
# XXX: (#12) this regex has issues with bash 5.0.3/sed 4.7 but works on bash 4.4.12/sed 4.4
# sed -E 's| ?-c [][a-zA-Z0-9 !"#$%&'\''()*+,-.:;<=>?@^_`{}~/]+ ?||g'
_d_args="$(echo "$_d_args" | sed -E 's| ?(-c ([^ ]+\|['\''"].+['\''"])) ?||g')"
# now get domain_name by removing:
# - options "-m <ip>" and "-s"
# - 'digits' which match domain id
# - any other args e.g. "-[a-z]"
if [[ -n "$freenom_update_all" && "${freenom_update_all:-0}" -eq 0 ]]; then
_arg_domain_name="$(
echo "$_d_args" |
sed -E -e 's/-m '"$ipRE"'//' \
-e 's/( ?-s [^ ]+|( -[[:alnum:]]+|-[[:alnum:]]+ )| [0-9]+|[0-9]+ | )|^-[[:alnum:]]+$/ /g' |
awk '{ print $1 }'
)"
fi
_arg_domain_id="$(echo "$_d_args" | sed -n -E 's/.*([0-9]{10}+).*/\1/p')"
_arg_subdomain_name="$(echo "$_d_args" | sed -n -E 's/.*-s ([^ ]+).*/\1/p')"
# if domain arg is not empty, use that instead of setting from conf
if [[ -n "$freenom_update_all" && "${freenom_update_all:-0}" -eq 0 ]]; then
if [ -n "$_arg_domain_name" ]; then
freenom_domain_name="$_arg_domain_name"
if [ "$((0 + $(echo "$freenom_domain_name" | tr '.' '\n' | wc -l)))" -ge 3 ]; then
local _wmsg="Warning: \"$freenom_domain_name\" looks like a subdomain (use '-s' ?)"
echo "$_wmsg"
echo -e "[$(date)] [$$] $_wmsg" >>"${out_path}.log"
fi
fi
fi
if [ -n "$_arg_subdomain_name" ]; then
freenom_subdomain_name="$_arg_subdomain_name"
fi
if [ -n "$_arg_domain_id" ]; then
freenom_domain_id="$_arg_domain_id"
fi
debugDomainArgs=0
if [ "${debug:-0}" -ge 1 ]; then
debugDomainArgs=1
fi
# if we didnt get any args and theres no conf settings, display error message
if [[ -n "$freenom_update_all" && "${freenom_update_all:-0}" -eq 0 ]]; then
if [ "$freenom_domain_name" == "" ]; then
echo "Error: domain name missing"
echo " Try: $scriptName [-u|-r|-z] [domain]"
exit 1
fi
# handle invalid domain setting
if [[ ! "$freenom_domain_name" =~ ^[^.-][a-zA-Z0-9.-]+$ ]] ||
[[ "$freenom_domain_name" == "$freenom_domain_id" ]]; then
echo "Error: invalid domain name \"$freenom_domain_name\""
exit 1
fi
if [ "$_subdom_set" -ge 1 ] && [[ ! "$freenom_subdomain_name" =~ ^[^.-][a-zA-Z0-9.-]+$ ]]; then
echo "Error: invalid or missing subdomain"
exit 1
fi
fi
if [[ ! "$freenom_domain_id" =~ ^[0-9]{10}+$ ]]; then
freenom_domain_id=""
fi
if [[ -n "$debugDomainArgs" && "${debugDomainArgs:-0}" -eq 1 ]]; then
echo "DEBUG: $pad8 getdomargs d_args=$_d_args _subdom_set=$_subdom_set"
echo "DEBUG: $pad8 getdomargs arg_domain_name=$_arg_domain_name arg_subdomain_name=$_arg_subdomain_name arg_domain_id=$_arg_domain_id"
fi
}
# Function showResult: format html and output as text
func_showResult() {
printf "\n[ %s ]\n\n" "$1"
local i=""
for i in lynx links links2 wb3m elinks curl cat; do
if command -v $i >/dev/null 2>&1; then
break
fi
done
case "$i" in
lynx | links | links2 | w3m | elinks)
[ $i = "lynx" ] && s_args="-nolist"
[ $i = "elinks" ] && s_args="-no-numbering -no-references"
# shellcheck disable=SC2086
"$i" -dump $s_args "$1" | sed '/ \([*+□•] \?.\+\|\[.*\]\)/d'
;;
curl | cat)
[ $i = "curl" ] && s_args="-s file:///"
# shellcheck disable=SC2086
"$i" ${s_args}"${1}" |
sed -e '/<a href.*>/d' -e '/<style type="text\/css">/,/</d' -e '/class="lang-/d' \
-e 's/<[^>]\+>//g' -e '/[;}{):,>]$/d' -e '/\r/d' -e 's/\t//g' -e '/^ \{2,\}$/d' -e '/^$/d'
;;
*)
echo "Error: cannot display \"$1\""
exit 1
;;
esac
}
# Function randIp: run random dig or curl ipCmd, replace %agent% with random useragent string
# regex: https://www.regexpal.com/?fam=104038
# returns: ipv4/6 address
func_randIp() {
[ "${debug:-0}" -ge 3 ] && set -x
${ipCmdSorted[$((RANDOM % ${#ipCmdSorted[@]}))]/\%agent\%/$agent} 2>/dev/null |
grep -Pow "${ipRE}" | head -1
[ "${debug:-0}" -ge 3 ] && set +x
}
# Function sortIpCimd: trim ipCmd array from conf for update_ipv=4|6 and whether we want dig or not
# replaces %ipv% with $freenom_update_ipv
# creates new array: $ipCmdSorted
func_sortIpCmd() {
local i
ipCmdSorted=()
for ((i = 0; i < ${#ipCmd[@]}; i++)); do
local skip=0
# if update_ipv is set to '6', skip ipCmd's that do not not contain '-6'
if [[ -n "$freenom_update_ipv" && "$freenom_update_ipv" -eq 6 ]]; then
if [[ "${ipCmd[$i]}" =~ '-4' ]]; then
skip=1
fi
if [ "${debug:-0}" -ge 2 ]; then
echo "DEBUG: $(date '+%H:%M:%S') sortIpCmd skip=$skip i=$i ipCmd=${ipCmd[$i]}"
fi
fi
# if update_dig is disabled, skip if ipCmd is 'dig'
if [[ -n "$freenom_update_dig" && "${freenom_update_dig:-0}" -eq 0 ]]; then
if [[ "${ipCmd[$i]}" =~ ^dig ]]; then skip=1; fi
fi
if [ "${skip:-0}" -eq 0 ]; then
ipCmdSorted+=("${ipCmd[$i]//\%ipv\%/$freenom_update_ipv}")
else
i=$((i + 1))
fi
done
if [ "${debug:-0}" -ge 2 ]; then
for ((i = 0; i < ${#ipCmdSorted[@]}; i++)); do echo "DEBUG: $(date '+%H:%M:%S') sortIpCmd i=$i ipCmdSorted: ${ipCmdSorted[$i]}"; done
fi
if [ ! "${#ipCmdSorted[@]}" -gt 0 ]; then
echo "Error: no \"get ip\" command found"
exit 1
fi
}
# Function ipCheck: compare current ip to file 'freedom_example.cf.ip4'
# parameters : $1 = updateDomain
# returns : 0 (ok), 1 (skip)
func_ipCheck() {
if [ "${freenom_update_force:-0}" -eq 0 ]; then
if [ "$(cat "${out_path}_${1}.ip${freenom_update_ipv}" 2>&1)" == "$currentIp" ]; then
return 1
fi
return 0
fi
}
# Function httpOut: set curl result and httpcode
func_httpOut() {
local _hc_re='<!--http_code=([1-5][0-9][0-9])-->'
httpCode=""
httpOut=""
httpCode="$(echo "$1" | sed -En 's/.*'"$_hc_re"'/\1/p')"
httpOut="$(echo "$1" | sed -E 's/'"$_hc_re"'//')"
}
# Function httpError: show msg with http error code and retries
# $1 = url, $2= title
func_httpError() {
local showRetry=$retry
if [ "$retry" -ge "$freenom_http_retry" ]; then
showRetry=$((retry - 1))
fi
local _c403="403 Forbidden"
local _c500="500 Internal Service Error"
local _c503="503 Service Temporarily Unavailable"
local _msg="$2 - httpcode "
if [ "${httpCode:-"000"}" -eq "403" ] || echo "$1" | grep -q "$_c403"; then
agent="${uaString[$((RANDOM % ${#uaString[@]}))]}"
_msg+="$_c403"
elif [ "${httpCode:-"000"}" -eq "500" ] || echo "$1" | grep -q "$_c500"; then
_msg+="$_c500"
elif [ "${httpCode:-"000"}" -eq "503" ] || echo "$1" | grep -q "$_c503"; then
_msg+="$_c503"
else
_msg+="${httpCode:-"000"}"
fi
printf "Error: %s (try %s/%s)\\n" "$_msg" "$showRetry" "$freenom_http_retry"
}
# Function lc/uc: convert $1 beween lower and UPPERCASE
func_lc() {
echo "$@" | tr '[:upper:]' '[:lower:]'
}
func_uc() {
echo "$@" | tr '[:lower:]' '[:upper:]'
}
# Function sleep: sleep between 'random' min and max seconds
func_sleep() {
if [[ -n "$freenom_http_sleep" && "$freenom_http_sleep" =~ ^[1-9]+\ [1-9]+$ ]]; then
min="$(echo "$freenom_http_sleep" | cut -d" " -f1)"
max="$(echo "$freenom_http_sleep" | cut -d" " -f2)"
rnd="$(((RANDOM % max) + min))"
if [ "${debug:-0}" -ge 1 ]; then
printf "DEBUG: %-*s sleep %s (min=%s max=%s)\n" "21" " " "$rnd" "$min" "$((min + max))"
fi
sleep $rnd
fi
}
# Function mailEvent: send mail
# parameters: $1: $event 2: $messages
mailEvent() {
if [ "$MTA" != "" ] && [ "$RCPTTO" != "" ]; then
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $(date '+%H:%M:%S') email $pad4 HOSTNAME=$HOSTNAME MTA=$MTA RCPTTO=$RCPTTO 1=$1 2=$2"
fi
[ "${debug:-0}" -ge 3 ] && set -x
HEADER="To: <$RCPTTO>\n"
if [ "$MAILFROM" ]; then
HEADER+="From: $MAILFROM\n"
fi
echo -e "${HEADER}Subject: freenom.sh: \"$1\" on \"$HOSTNAME\"\n\nDate: $(date +%F\ %T)\n\n$2" | "$MTA" "$RCPTTO"
EXITCODE="$?"
if [ "$EXITCODE" -ne 0 ]; then
echo "Error: exit code \"$EXITCODE\" while running $MTA"
fi
[ "${debug:-0}" -ge 3 ] && set +x
fi
}
# Function appriseEvent: send Apprise notification
# parameters: $1: $event 2: $messages
appriseEvent() {
if [ -s "$APPRISE" ] && [ "${#APPRISE_SERVER_URLS[@]}" -gt 0 ]; then
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $(date '+%H:%M:%S') apprise $pad4 HOSTNAME=$HOSTNAME APPRISE=$APPRISE APPRISE_SERVER_URLS=(${APPRISE_SERVER_URLS[*]}) 1=$1 2=$2"
fi
if [ "${debug:-0}" -ge 3 ]; then
set -x
fi
"$APPRISE" --title "freenom.sh: \"$1\" on \"$HOSTNAME\"" --body "$2" "${APPRISE_SERVER_URLS[@]}"
EXITCODE="$?"
if [ "$EXITCODE" -ne 0 ]; then
echo "Error: exit code \"$EXITCODE\" while running $APPRISE"
fi
if [ "${debug:-0}" -ge 3 ]; then
set +x
fi
fi
}
# Function setUpdateDomVars: make sure correct domain, record and id are set
func_updateDomVars() {
local _domain _record
domId="1234567890"
[ -n "$freenom_domain_name" ] && _domain="$freenom_domain_name" || _domain="${domainName[$d]}"
[ -n "$freenom_subdomain_name" ] && _record="$freenom_subdomain_name" || _record="${recName[$r]}"
[ -n "$freenom_domain_id" ] && domId="$freenom_domain_id" || domId="${domainId[$d]}"
if [[ -z "${_record}" && -n "${_domain}" ]]; then
updateDomain="$(func_lc "${_domain}")"
else
updateDomain="$(func_lc "${_record:+${_record}.}${_domain}")"
fi
}
# debug functions
# Function debugHttp: show curl error
func_debugHttp() {
local showRetry=$retry
if [ "$retry" -ge "$freenom_http_retry" ]; then
showRetry=$((retry - 1))
fi
printf "DEBUG: %s %-12s curl %s (retry=%s/%s http_code=%s errCount=%s)\n" \
"$(date '+%H:%M:%S')" "$1" "$2" "$showRetry" "$freenom_http_retry" "$httpCode" "$errCount"
}
# Function debugVars: debug output args, actions etc
func_debugVars() {
echo "DEBUG: $pad8 args $pad4 debug=$debug curlExtraOpts=$curlExtraOpts"
echo "DEBUG: $pad8 args $pad4 1=$1 2=$2 3=$3 4=$4 5=$5 6=$6 7=$7 8=$8 9=$9"
echo "DEBUG: $pad8 opts/conf freenom_out_dir=$freenom_out_dir freenom_out_mask=$freenom_out_mask out_path=$out_path"
echo "DEBUG: $pad8 opts/conf freenom_domain_name=$freenom_domain_name freenom_domain_id=$freenom_domain_id freenom_subdomain_name=$freenom_subdomain_name"
echo "DEBUG: $pad8 opts/conf freenom_static_ip=$freenom_static_ip"
echo "DEBUG: $pad8 action $pad4 freenom_update_ip=$freenom_update_ip freenom_update_force=$freenom_update_force freenom_update_manual=$freenom_update_manual freenom_update_all=$freenom_update_all"
echo "DEBUG: $pad8 action $pad4 freenom_list_records=$freenom_list_records freenom_list=$freenom_list freenom_list_renewals=$freenom_list_renewals"
echo "DEBUG: $pad8 action $pad4 freenom_renew_domain=$freenom_renew_domain freenom_renew_all=$freenom_renew_all"
}
# Function debugArrays: show domain Id, Name, Expiry
# shellcheck disable=2317
func_debugArrays() {
echo "DEBUG: $pad8 arrays domainId domainName domainExpiryDate:"
echo "${domainId[@]}"
echo "${domainName[@]}"
echo "${domainExpiryDate[@]}"
}
# Function debugMyDomainsResult
# shellcheck disable=2317
func_debugMyDomainsResult() {
if [ "${debug:-0}" -ge 1 ]; then
IFS_SAVE=$IFS
IFS=$'\n'
local i=""
# shellcheck disable=SC2116
for i in $(echo "$myDomainsResult"); do
if [ "${debug:-0}" -ge 2 ]; then
echo "DEBUG: $pad8 myDomainsResult i=$i"
fi
domainResult="$(echo "$i" | cut -d " " -f2)"
domainIdResult="$(echo "$i" | cut -d " " -f4)"
done
echo "DEBUG: $pad8 myDomainsResult domainResult: $domainResult domainIdResult: $domainIdResult"
IFS=$IFS_SAVE
fi
}
###############################################################################
# Note that there are 6 more inline Functions placed down below
# Dns:
# - Function getDnsPage: get DNS Management Page
# - Function getRec: get domain records from dnsManagementPage
# - Function setRec: add/modify domain records
# Renew:
# - Function renewDate: check date to make sure we can renew
# - Function renewDomain: if date is ok; submit actual renewal, get result
###############################################################################
###########
# Options #
###########
unset -v a
# handle debug
if printf -- "%s" "$*" | grep -Eiq '(^|[^a-z])-debug'; then
debug="$(echo "$*" | sed -E 's/.*-debug ([0-9]) ?.*/\1/')"
if [[ ! "$debug" =~ ^[0-9]$ ]]; then
debug=0
fi
fi
# show help
#if printf -- "%s" "$*" | grep -Eqi '(^|[^a-z])-h'; then
# shellcheck disable=2317
if [ "${help:-0}" -eq 1 ]; then
func_help
exit 0
fi
# handle all other arguments
if ! printf -- "%s" "$*" | grep -Eqi -- '-[46lruziceo]'; then
echo "Error: invalid or unknown argument(s), try \"$scriptName -h\""
exit 1
fi
# ipv4/6
if printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-4'; then
freenom_update_ipv=4
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $pad8 ipv freenom_update_ipv=$freenom_update_ipv"
fi
elif printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-6'; then
freenom_update_ipv=6
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $pad8 ipv freenom_update_ipv=$freenom_update_ipv"
fi
fi
# list domains and id's and exit, unless list_records is set
if printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-l'; then
freenom_list="1"
lMsg=""
# list domains with details
a="$(echo "$*" | sed -E 's/ ?-debug ([0-9])//')"
if printf -- "%s" "$a" | grep -Eqi -- '(^|[^a-z])-[dn]'; then
freenom_list_renewals="1"
lMsg=" with renewal details, this might take a while"
fi
printf "\nListing Domains and ID's%s...\n" "$lMsg"
echo
# list dns records
elif printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-z'; then
printf "\nListing Domain Record(s)%s...\n" "$lMsg"
echo
func_getDomainArgs "$@"
freenom_list_records="1"
# output ipcmd list
elif printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-i'; then
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $pad8 ipv freenom_update_ipv=$freenom_update_ipv"
fi
printf "\nListing all \"get ip\" commands..."
echo
for ((i = 0; i < ${#ipCmd[@]}; i++)); do
printf "%2s: %s\n" "$i" "${ipCmd[$i]}"
done
printf "\nNOTES:\n"
printf " %%ipv%% gets replaced by \$freenom_update_ipv ('4' or '6')\n"
printf " %%agent%% gets replaced with useragent string from conf\n\n"
exit 0
# update ip
elif printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-u'; then
freenom_update_ip="1"
a="$*"
if printf -- "%s" "$a" | grep -Eiq -- '(^|[^a-z])-f'; then
freenom_update_force="1"
a="$(echo "$a" | sed -E 's/ ?-f//')"
fi
if printf -- "%s" "$a" | grep -Eiq -- '(^|[^a-z])-m'; then
freenom_update_manual="1"
arg_static_ip="$(echo "$a" | sed -n -E 's/.*-m ('"$ipRE"')([^0-9].*)?/\1/p')"
if [ -n "$arg_static_ip" ]; then
freenom_static_ip="$arg_static_ip"
fi
if [[ ! "$freenom_static_ip" =~ ^$ipRE$ ]]; then
freenom_static_ip=""
fi
fi
# TEST: update all records
if printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-a'; then
freenom_update_all="1"
fi
func_getDomainArgs "$@"
# renew domains
elif printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-r'; then
freenom_renew_domain="1"
if printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-a'; then
freenom_renew_all="1"
else
func_getDomainArgs "$@"
fi
# show update and renewal result file(s)
elif printf -- "%s" "$*" | grep -Eiq -- '(^|[^a-z])-[eo]'; then
# use regex if file is specfied
fget="$(printf -- "%s\n" "$*" | sed -En 's/.* ?-[eo] ?([][a-zA-Z0-9 !"#$%&'\''()*+,-.:;<=>?@^_`{}~.]+)[ -]?.*/\1/gp')"
if [ -z "$fget" ]; then
for f in "${out_path}"_renewalResult-*.html; do
if [ -e "$f" ]; then fget+="$f "; fi
done
count="$(echo "$fget" | wc -w)"
if [ "${count:-0}" -eq 0 ]; then
echo "No result file(s) found"
exit 0
elif [ "${count-0}" -gt 1 ]; then
printf "\nMultiple results found, listing %d html files:\n" "$count"
for rf in $fget; do
find "$rf" -printf ' [%TF %TH:%TM] %f\n'
done
printf "\nTo show a file use: \"%s -o <file.html>\"\n\n" "$scriptName"
exit 0
fi
fi
fdir="$(dirname "$out_path")"
if ! echo "$fget" | grep -q "$fdir"; then
ffile="$(dirname "$out_path")/$fget"
else
ffile="$fget"
fi
if [ -s "$ffile" ]; then
func_showResult "$ffile"
else
echo "Result file not found"
fi
exit 0
else
func_help
fi
# more config checks: if these vars are missing, set defaults
if [ -z "$freenom_http_retry" ]; then freenom_http_retry=1; fi
if [ -z "$freenom_list" ]; then freenom_list=0; fi
if [ -z "$freenom_list_records" ]; then freenom_list_records=0; fi
if [ -z "$freenom_list_renewals" ]; then freenom_list_renewals=0; fi
if [ -z "$freenom_renew_all" ]; then freenom_renew_all=0; fi
if [ -z "$freenom_update_force" ]; then freenom_update_force=0; fi
if [ -z "$freenom_update_ip" ]; then freenom_update_ip=0; fi
if [ -z "$freenom_update_ipv" ]; then freenom_update_ipv=4; fi
if [ -z "$freenom_update_ttl" ]; then freenom_update_ttl="3600"; fi
if [ -z "$freenom_update_ip_retry" ]; then freenom_update_ip_retry=3; fi
if [ "${debug:-0}" -ge 1 ]; then
func_debugVars "$@"
fi
# log start msg
if [ "${freenom_update_ip:-0}" -eq 1 ]; then
func_updateDomVars
if [[ -n "$freenom_update_ip_log" && "${freenom_update_ip_log:-0}" -eq 1 ]]; then
echo -e "[$(date)] [$$] Start: Update ip of \"${updateDomain}\"" >>"${out_path}.log"
else
printf "[%s] Start: Update ip of \"%s\" $(date)" "${updateDomain}"
fi
elif [[ "${freenom_renew_domain:-0}" -eq 1 || "${freenom_renew_all:-0}" -eq 1 ]]; then
if [[ -n "${freenom_renew_log:-0}" && "${freenom_renew_log:-0}" -eq 1 ]]; then
echo -e "[$(date)] [$$] Start: Domain renewal" >>"${out_path}.log"
else
printf "[%s] Start: Domain renewal" "$(date)"
fi
fi
##########
# Get IP #
##########
if [ "${freenom_update_ip:-0}" -eq 1 ]; then
if [[ -n "$freenom_update_manual" && "${freenom_update_manual:-0}" -eq 0 ]]; then
func_sortIpCmd
i=0
# try getting ip by running random ipCmd(s), stop after max retries
while [[ "$currentIp" == "" && "$i" -lt "$freenom_update_ip_retry" ]]; do
currentIp="$(func_randIp || true)"
i=$((i + 1))
done
if [ "$currentIp" == "" ]; then
eMsg="Could not get current local ip address"
fi
else
if [ "$freenom_static_ip" != "" ]; then
currentIp="$freenom_static_ip"
else
eMsg="Valid static ip address missing for manual update"
uMsg="\n%7sUse \"-m <ip>\" or remove static option for auto detect\n"
fi
fi
# shellcheck disable=SC2059
if [ "$currentIp" == "" ]; then
printf "Error: ${eMsg}${uMsg}\n"
echo "[$(date)] [$$] Error: $eMsg" >>"${out_path}.log"
exit 1
fi
# ipcheck single domain
if [[ -n "$freenom_update_all" && "${freenom_update_all:-0}" -eq 0 ]]; then
func_updateDomVars
if ! func_ipCheck "$updateDomain"; then
if [[ -n "$freenom_update_ip_log" && "${freenom_update_ip_log:-0}" -eq 1 ]]; then
uMsg="Update: Skipping \"${updateDomain}\" - found same ip \"$currentIp\""
echo "$uMsg"
echo "[$(date)] [$$] $uMsg" >>"${out_path}.log"
echo "[$(date)] [$$] Done" >>"${out_path}.log"
fi
exit 0
fi
fi
fi
#########
# Login #
#########
retry=1
while [ "$retry" -le "$freenom_http_retry" ]; do
cookie_file="$(mktemp)"
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $pad8 logintoken cookie_file=$cookie_file"
fi
# DEBUG: comment 'loginPage' line below for debugging
# shellcheck disable=SC2086
loginPage="$(curl $c_opts $curlExtraOpts -A "$agent" -c "$cookie_file" -w "$http_code" \
"https://my.freenom.com/clientarea.php" 2>&1)" || { \
eMsg="Error: Login token - failure (curl error code: $?)"
echo "$eMsg"
echo "[$(date)] [$$] $eMsg" >>"${out_path}.log"
exit 1
}
func_httpOut "$loginPage"
loginPage="$httpOut"
if [ "${httpCode:-"000"}" -eq "200" ]; then
if echo "$loginPage" | grep -q "token.*value="; then
# token length is 40 chars, numbers and lowercase letters a-f
token="$(echo "$loginPage" | grep -E -m 1 -o '[0-9a-f]{40}')"
break
else
printf "Error: Login token - value not found (try %s/%s)\\n" "$retry" "$freenom_http_retry"
retry="$((retry + 1))"
fi
else
# handle http status other than '200'
func_httpError "$loginPage" "Login token"
retry="$((retry + 1))"
fi
done
if [ "${debug:-0}" -ge 1 ]; then
func_debugHttp "logintoken" "clientarea token=$token"
fi
if [ -z "$token" ]; then
eMsg="Error: Login token - value empty after $freenom_http_retry max tries, exiting..."
echo "$eMsg"
echo "[$(date)] [$$] $eMsg" >>"${out_path}.log"
exit 1
fi
retry=1
clientareaURL="https://my.freenom.com/clientarea.php"
dologinURL="https://my.freenom.com/dologin.php"
while [ "$retry" -le "$freenom_http_retry" ]; do
# DEBUG: comment loginResult for debugging
if [ "${oldCurl:-0} " -eq 1 ]; then
# shellcheck disable=SC2086
loginResult="$(curl $c_opts $curlExtraOpts -A "$agent" -e "$clientareaURL" -c "$cookie_file" -w "$http_code" \
-F "username=$freenom_email" -F "password=$freenom_passwd" -F "token=$token" "$dologinURL")"
else
# shellcheck disable=SC2086
loginResult="$(curl $c_opts $curlExtraOpts -A "$agent" -e "$clientareaURL" -c "$cookie_file" -w "$http_code" \
-F "username=$freenom_email" -F "password=\"$freenom_passwd\"" -F "token=$token" "$dologinURL")"
fi
func_httpOut "$loginResult"
loginResult="$httpOut"
incorrectPat="Location: /clientarea.php\?incorrect=true|Login Details Incorrect"
if [ "$(echo -e "$loginResult" | grep -E "$incorrectPat")" != "" ]; then
eMsg="Error: Login failed, incorrect details"
echo "$eMsg"
echo "[$(date)] [$$] $eMsg" >>"${out_path}.log"
exit 1
fi
if [ "${httpCode:-"000"}" -eq "200" ]; then
break
else
func_httpError "$loginResult" "Login"
retry="$((retry + 1))"
fi
done
if [ "${debug:-0}" -ge 1 ]; then
func_debugHttp "login" "dologin.php username=$freenom_email"
fi
if [ "$retry" -gt "$freenom_http_retry" ]; then
eMsg="Error: Login - max retries $freenom_http_retry was reached, exiting..."
echo "$eMsg"
echo "[$(date)] [$$] $eMsg" >>"${out_path}.log"
exit 1
fi
###################
# Get Domain info #
###################
# Retrieve client area page, get domain detail urls and loop over them to get all data
# arrays: domainId, domainName, domainRegDate, domainExpiryDate
# shellcheck disable=SC2004
if [ "$freenom_domain_id" == "" ]; then
myDomainsURL="https://my.freenom.com/clientarea.php?action=domains&itemlimit=all&token=$token"
# DEBUG: for debugging use local file instead:
# DEBUG: myDomainsURL="file:///home/user/src/freenom/myDomainsPage"
retry=1
# first get mydomains page
while [ "$retry" -le "$freenom_http_retry" ]; do
if [ "${debug:-0}" -ge 1 ]; then
func_debugHttp "domains" "myDomainsPage"
fi
# shellcheck disable=SC2086
myDomainsPage="$(curl $c_opts $curlExtraOpts -A "$agent" -b "$cookie_file" -w "$http_code" "$myDomainsURL")"
func_httpOut "$myDomainsPage"
myDomainsPage="$httpOut"
if [ "${httpCode:-"000"}" -eq "200" ]; then
break
else
func_httpError "$myDomainsPage" "My domains page"
retry="$((retry + 1))"
fi
done
if [ "$retry" -gt "$freenom_http_retry" ]; then
eMsg="Error: My domains page - $freenom_http_retry max retries was reached, exiting..."
echo "$eMsg"
echo "[$(date)] [$$] $eMsg" >>"${out_path}.log"
exit 1
fi
# if we have mydomains page, get domaindetails url(s) from result
if [ -n "$myDomainsPage" ]; then
# old: myDomainsResult="$( echo -e "$myDomainsPage" | sed -n '/href.*external-link/,/action=domaindetails/p' | sed -n 's/.*id=\([0-9]\+\).*/\1/p;g' )"
myDomainsResult="$(echo -e "$myDomainsPage" | sed -n 's/.*"\(clientarea.php?action=domaindetails&id=[0-9]\+\)".*/\1/p;g')"
if [[ "${freenom_update_ip:-0}" -eq 1 || "${freenom_list_records:-0}" -eq 1 ]]; then
# on ip update or list_records reverse sort newest first to possibly get a quicker match below
myDomainsResult=$(echo "$myDomainsResult" | tr ' ' '\n' | sort -r)
fi
i=0
# iterate over domaindetails url(s)
for url in $myDomainsResult; do
retry=1
while [ "$retry" -le "$freenom_http_retry" ]; do
if [ "${debug:-0}" -ge 1 ]; then
func_debugHttp "domains" "domainDetails"
fi
# DEBUG: for debugging use local file instead:
# domainDetails=$( curl $c_opts $curlExtraOpts -A "$agent" -b "$cookie_file" -w "$http_code" "file:///home/user/src/freenom/domainDetails_$i.bak" )
# shellcheck disable=SC2086
domainDetails="$(curl $c_opts $curlExtraOpts -A "$agent" -b "$cookie_file" -w "$http_code" "https://my.freenom.com/$url")"
func_httpOut "$domainDetails"
domainDetails="$httpOut"
if [ "${httpCode:-"000"}" -eq "200" ]; then
domainId[$i]="$(echo "$url" | sed -n 's/.*id=\([0-9]\+\).*/\1/p;g')"
domainName[$i]="$(echo -e "$domainDetails" | sed -n 's/.*Domain:\(.*\)<[a-z].*/\1/p' | sed -e 's/<[^>]\+>//g' -e 's/ *//g')"
if [ "${debug:-0}" -ge 1 ]; then
echo "DEBUG: $(date '+%H:%M:%S') domains $pad4 domainId=${domainId[$i]} domainName=${domainName[$i]} (${#domainId[@]}/$(echo "$myDomainsResult" | wc -w))"