-
Notifications
You must be signed in to change notification settings - Fork 0
/
raida_tester.sh
executable file
·3652 lines (3170 loc) · 104 KB
/
raida_tester.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
#!/usr/bin/env bash
#
# Created: 2017-3-20, A-Lang ([email protected])
#
# Change Logs:
# 17/10/14 - Added test for multi_detect
# 17/10/15 - Added detection for version
# 18/04/10 - JSON validation for ECHO
# 19/05/25 - Added datetime for Advanced ECHO
# 19/06/09 - Added multi_fix
# 19/06/27 - Update _all_echo
# More logs are at Github website.
#
#
#set -x
#set -e
# Variables
VERSION="210523"
TESTCOINFILE1="testcoin.stack"
TESTCOINFILE2="testcoin_multi.stack"
TESTCOINFILE3="testcoin_multi2.stack"
TESTCOINFILE4="testcoin_id1_x1.stack"
TESTCOINFILE5="testcoin_id2_x1.stack"
TESTCOINFILE6="testcoin_bank_x3.stack"
# for Debgugging only
DEBUG=0 # True:1 , False:0
LOG_FILE="debug.log"
# Extra Custom Environment Variables
# e.g:
# Case #1, for self-signed certificates:
# export TESTER_CURL_EXTRA_OPT="-k"
# Case #2, for non-https:
# export TESTER_HTTP_PROTO="http"
CURL_EXTRA_OPT=$TESTER_CURL_EXTRA_OPT
HTTP_PROTO=${TESTER_HTTP_PROTO:-https}
#
RAIDA_NUMS=25
MAX_LATENCY=15
MAX_POST_NOTES=400
WARN_MS=10000 # millisecond
_REST_='\033[0m'
_GREEN_='\033[32m'
_RED_='\033[31m'
_BOLD_='\033[1m'
CURL_CMD="curl"
CURL_OPT="$CURL_EXTRA_OPT -qSfs -m 30"
CURL_OPT_multi="$CURL_EXTRA_OPT -qSfs -m 30 -X POST"
JQ_CMD="jq"
GETIP_CMD="dig"
PYTHON_CMD="python"
NOTIFY_CMD="notify-send"
HTML_DIR="html"
# Don't change the following lines
WORKDIR="$(cd $(dirname "$0") && pwd)"
RUNNINGOS=$($(echo uname) | tr '[a-z]' '[A-Z]')
RUNNINGARCH=$($(echo uname -m) | tr '[a-z]' '[A-Z]')
# Strings
STRING_01="Could not Check hints because get_ticket service failed to get a ticket. Fix get_ticket first."
STRING_02=""
STRING_03="Checking ticket..."
STRING_04=""
STRING_05="HTTPS Access No Response"
STRING_06="Would you like to generate a html report for test results (y/N)?"
ERROR_01="Error: Coin Files Not Found!"
ERROR_02="Error: Invalid Command"
ERROR_03="Error:"
ERROR_04="Error:"
ERROR_05="Error: Test failed, run the echo to see more details."
ERROR_06="Error: Test failed, run the detect to see more details."
ERROR_07="Error: Test failed, run the get_ticket to see more details."
#########################################
# Functions
Show_logo() {
printf '
MMMMMMMMMMMMMMMMMMMMNmmmmNNmNMMMMMMMMNNmmmNmmmNMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMNddmNMMmhs+/-.```````..-:/oydmNNmdNMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMNmmNMMdo:` +ssso `:ohNNmmNMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMNNmNMMh/` -ohh oMMMMo +ds+- -odNmmmNMMMMMMMMMMMMMMMMM
MMMMMMMMNddMMNo. `/hNMMMM/ `mMMMN. `mMMMNh+. `+dNmmNMMMMMMMMMMMMMMM
MMMMMMNmmMMN+` -yNMMMMMMMm` :++//. -MMMMMMMmo- .oNmNMMMMMMMMMMMMMM
MMMMMNmNMMs` -hMMMMMMMMMMh. -/ymMMMMMMd/``+mNNMMMMMMMMMMMM
MMMMmmMMN: `sMMMMMMMMMm+` .odMMMMMN+` +NNdNMMMMMMMMM
MMMmmMMm. .dMMMMMMMMm/ ./osyyyys+:. .sNMMMMN+ `sMmdMMMMMMMM
MMmdMMm. .mMMMMMMMMs` :yNMMMMMMMMMMMMNh+. `+NMMMMd- -mNdNMMMMMM
MNhMMN- `mMMMMMMMMo /mMMMMMMMMMMMMMMMMMMMd/ `yMMMMMo `yMdNMMMMM
MhNMMo yMMMMMMMMs yMMMMMMMMMMMMMMMMMMMMMMMm+.-://hMMMMMy` sMdNMMMM
NdMMN` -MMMMMMMMm` yMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh` oMdmMMM
dNMMs sMMMMMMMMo :MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh sMdNMM
dMMM/ hMMMMMMMM: oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMo dMhNM
yMMM: dMMMMMMMM: oMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMN- -NNhM
dMMM: hMMMMMMMM+ :MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy sMmN
NMMM: sMMMMMMMMh dMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNdhysoNMMMMN` .MNd
dMMMo :MMMMMMMMM- .mMMMMMMMMMMMMMMMMMMMMMMMMMMMMm` dMMMMM: dMd
hMMMd dMMMMMMMMd` .mMMMMMMMMMMMMMMMMMMMMMMMMMMMo mMMMMM+ yMN
mmMMM: :MMMMMMMMMh` `sMMMMMMMMMMMMMMMMMMMMMMMMMh .NMMMMM+ oMh
NdMMMd` sMMMMMMMMMh` -yMMMMMMMMMMMMMMMMMMMMMMs sMMMMMM: sMd
MmmMMMo `hMMMMMMMMMm- .+dMMMMMMMMMMMMMMMMNy. :MMMMMMN` hMm
MMhNMMM/ `hMMMMMMMMMMs` `/shmMMMMMMMNds/` :NMMMMMMs `NMm
MMNdNMMM/ sMMMMMMMMMMNo` `.....` +NMMMMMMm` /MMd
MMMmhMMMM+ /NMMMMMMMMMMNs- `dMMMMMMMN- `mMmm
MMMMMmNMMMs` .yMMMMMMMMMMMMmo- yMMMMMMN: yMMhN
MMMMMMdNMMMd- :dMMMMMMMMMMMMMNho:. `.:` `NMMMMm- oMMdmM
MMMMMMMmmMMMMs` :hMMMMMMMMMMMMMMMMN+ :hmNMMo /MMNo` oMMmmMM
MMMMMMMMNdNMMMN+` .sNMMMMMMMMMMMMMMm` `mMMMMN. yy. `yMMddMMM
MMMMMMMMMMmdMMMMNo` :smMMMMMMMMMMMM+ +MMMMMy /mMMdmMMMM
MMMMMMMMMMMMdmMMMMNy- .+ymMMMMMMMMm `mMMMMM- :dMMNmMMMMMM
MMMMMMMMMMMMMNmdNMMMMmo- `:+shmNMM/ /mhs/- `/dMMMmdMMMMMMM
MMMMMMMMMMMMMMMMNmmNMMMMmy/` ``` `/yNMMMmdMMMMMMMMM
MMMMMMMMMMMMMMMMMMMNmNNMMMMMmy+:` ./sdMMMMMNNmMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMNmdmNMMMMMMNdys+/:--...--:/+sydNMMMMMNNmNMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMNNmmmmNMMMMMMMMMMMMMMMMMMMMMMNNdmmNMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNmmmmNdNNmmmmmmMMNdNmmmNNMMMMMMMMMMMMMMMMMMMM
'
read -n 1 -p "Press any key to continue or Ctrl+C to exit..."
}
Show_logo2() {
printf '
________ ________ _
/ ____/ /___ __ ______/ / ____/___ (_)___
/ / / / __ \/ / / / __ / / / __ \/ / __ \
/ /___/ / /_/ / /_/ / /_/ / /___/ /_/ / / / / /
\____/_/\____/\__,_/\__,_/\____/\____/_/_/ /_/
'
}
Show_head() {
clear
#Show_logo
cat <<EOF
$(Show_logo2)
#############################################################################
# Welcome to RAIDA Tester. A CloudCoin Consortium Opensource. #
# The Software is provided as is, with all faults, defects and errors, and #
# without warranty of any kind. #
# #
# You have to have several authentic CloudCoin .stack files called #
# 'testcoin*.stack' in the same folder as this program to run tests. #
#############################################################################
[Version: ${VERSION}]$(Check_Update)|[Debug: $([ $DEBUG -eq 1 ] && echo "ON" || echo "OFF")]|[Protocol: $(ToUpper $HTTP_PROTO)]|[CCE: \$$(Get_Price)]
EOF
}
Show_menu() {
cat <<EOF
===================================
RAIDA Tester Commands Available:
[-] echo (e)
[-] version (v)
[-] CORS (c)
[-] detect (d)
[-] get_ticket (g)
[-] hints (h)
[-] multi_detect (md)
[-] multi_detect+ (md2)
[-] multi_get_ticket (mg)
[-] multi_hints (mh)
[-] multi_fix (mf)
[+] skywallet (sw) *New*
[+] advanced (a)
[+] misc (m)
[-] help (?)
[-] quit (q)
EOF
}
Show_help_head() {
local width
width=62
printf "%-${width}.${width}s\n" "#####################################################################"
printf "%-3s %-54.54s %3s\n" "###" " " "###"
printf "%-20s %-37s %3s\n" "###" "RAIDA Tester Help" "###"
printf "%-20s %-37s %3s\n" "###" "Version: ${VERSION}" "###"
printf "%-20s %-37s %3s\n" "###" "<Enter q to exit>" "###"
printf "%-${width}.${width}s\n" "#####################################################################"
}
Show_help() {
less <<EOF
$(Show_help_head)
:Introduction
This program is designed to test if the RAIDA node works with
all functions such as echo, detect etc.
:Dependencies
The following packages must be already installed on the system.
* Curl
* Jq (see more details on https://stedolan.github.io/jq/)
* dig
* python
* bc
Recommend: To install these packages, you can run the commands:
* For RedHat/CentOS
$> yum install curl jq bind-utils python bc
* For Debian/Ubuntu
$> sudo apt-get update; sudo apt-get install curl jq dnsutils python bc
* For macOS
$> brew install curl jqc
:Install and Upgrade
$> git clone https://github.com/a-lang/RAIDA_Tester.git
How to Upgrade existing code to up-to-date
$> cd RAIDA_Tester/
$> git pull
:The coins files
Each test requires different coins files, each stack file has
a fixed filename with one coin or multiple coins as following
list.
File Function Notes
Name Keys (Coins)
===============================================
testcoin.stack d/g/h 1
testcoin_multi.stack md/mg/mh/mf 3-200
testcoin_multi2.stack md2 800+
testcoin_id1_x1.stack sw 1
testcoin_id2_x1.stack sw 1
testcoin_bank_x3.stack sw 3-200
NOTE: Please don't copy the coin files to each other otherwise
they can be counterfeited.
:How to Enable the Debug mode
Find the line below, change it to 1
DEBUG=0
The debug info will be stored in the file <debug.log>.
:End of Line (Enter q to exit)
EOF
}
Error() {
message="$1"
message_color="$_RED_$message$_REST_"
echo -e "$message_color\n"
}
Show_requirement() {
cat <<EOF
NOTE: The following packages must be already installed on the system.
* Curl
* Jq (see more details on https://stedolan.github.io/jq/)
* dig
* python
* bc
Recommend: To install these packages, you can run the commands:
* For RedHat/CentOS
$> yum install curl jq bind-utils python bc
* For Debian/Ubuntu
$> sudo apt-get update; sudo apt-get install curl jq dnsutils python bc
* For macOS
$> brew install curl jq
EOF
}
Main() {
local opt
opt=""
while [ "$input" != "quit" ]; do
Show_menu
echo -n "RAIDA Tester> " && read opt
case $opt in
e | echo)
Process_request _echo
;;
v | version)
Process_request _version
;;
c | cors)
Process_request _cors
;;
d | detect)
Process_request _detect
;;
g | get_ticket)
Process_request _get_ticket
;;
h | hints)
Process_request _hints
;;
#f | fix)
# isFix4Mode="true"
# Process_request _fix
# ;;
md | multi_detect)
Process_request _multi_detect
;;
md2 | multi_detect+)
Process_request _multi_detect2
;;
mg | multi_get_ticket)
Process_request _multi_get_ticket
;;
mh | multi_hints)
Process_request _multi_hints
;;
mf | multi_fix)
isFix4Mode="true"
Process_request _multi_fix
;;
sw | skywallet)
Ask_raida_node "_SkyWallet" "SKYWALLET(sw)"
;;
a | advanced)
Advanced
;;
m | misc)
Misc
;;
\? | help)
Show_help
;;
q | quit)
break
;;
*)
Error "$ERROR_02"
;;
esac
done
}
Check_CMD() {
local cmd
cmd=$1
[ $(which $cmd) ] || {
#Show_requirement
#exit 1
return 1
}
return 0
}
Timer() {
if [ "$RUNNINGOS" == "LINUX" ]; then
seconds=$(date +%s%N)
else
seconds=$(ruby -e 'puts "%.9f" % Time.now' | tr -d '.')
fi
echo $seconds
}
Get_denom() {
sn=$1
denom=0
if [ $sn -gt 0 -a $sn -lt 2097153 ]; then
denom=1
elif [ $sn -lt 4194305 ]; then
denom=5
elif [ $sn -lt 6291457 ]; then
denom=25
elif [ $sn -lt 14680065 ]; then
denom=100
elif [ $sn -lt 16777217 ]; then
denom=250
fi
echo $denom
}
Advanced() {
local prompt input
input=""
prompt="ADVANCED(a)"
while true; do
echo "Test All RAIDA Nodes [1-8]: 1.Echo 2.Echo2 3.Detect 4.Ticket 5.Hints q.Exit"
echo " 6.Multi_Detect 7.Multi_Ticket 8.Version 9.CORS"
echo "NOTE: This process may take a few mins to check all nodes please be patient until all checks done."
echo -n "$prompt> " && read input
if [ $input -ge 1 -a $input -le 9 ] 2>/dev/null; then
case "$input" in
1)
_all_echo
;;
2)
_all_echo2
;;
3)
_all_detect
;;
4)
_all_ticket
;;
5)
_all_hints
;;
#6)
# _all_fix
# ;;
6)
_all_multi_detect
;;
7)
_all_multi_get_ticket
;;
8)
_all_version
;;
9)
_all_cors
;;
esac
elif [ "$input" == "q" ] 2>/dev/null; then
break
else
Error "$ERROR_02"
fi
done
}
Misc() {
local prompt input
input=""
prompt="MISC(m)"
while true; do
echo "Select the function [1-5]: 1.Fix-Fracked 2.IP->SN 3.SN->IP 4.Weather 5.SpeedTest q.Exit"
echo " "
echo -n "$prompt> " && read input
if [ $input -ge 1 -a $input -le 5 ] 2>/dev/null; then
case "$input" in
1)
_fix_fracked_coins $prompt
;;
2)
_IP2SN $prompt
;;
3)
_SN2IP $prompt
;;
4)
_Weather $prompt
;;
5)
_SpeedTest $prompt
;;
esac
elif [ "$input" == "q" ] 2>/dev/null; then
break
else
Error "$ERROR_02"
fi
done
}
Ask_raida_node() { # Ask_raida "Call-to-Function" "Prompt-String"
local func prompt input
func="$1"
prompt="$2"
input=""
while [ "$input" != "$RAIDA_NUMS" ]; do
echo
echo "What RAIDA# do you want to test $prompt? (Enter q to end)"
echo -n "$prompt[0-$((RAIDA_NUMS - 1))]> " && read input
if [ $input -ge 0 -a $input -lt $RAIDA_NUMS ] 2>/dev/null; then
$func $input
elif [ "$input" == "q" ] 2>/dev/null; then
return
else
Error "$ERROR_02"
fi
done
}
Ask_coin_file() {
local prompt input
local n coins_list
prompt="$1"
input=""
coins_list=($(Get_coin_files))
coins_count=${#coins_list[@]}
# for debug only
#echo "coins_list-> ${coins_list[@]}"
#echo "coins_count-> $coins_count"
if [ $coins_count -eq 0 ]; then
Error "$ERROR_01"
return 1
fi
for ((n = 0; n < $coins_count; n++)); do
echo "[$((n + 1))] ${coins_list[$n]}"
done
GET_COINFILE=""
while [ "$input" != "q" ]; do
echo "NOTE: The filename is not supposed to contain any space characters."
echo
echo "Please select the coin file. (Enter q to end)"
echo -n "$prompt[1-$coins_count]> " && read input
if [ $input -ge 1 -a $input -le $coins_count ] 2>/dev/null; then
GET_COINFILE="${coins_list[$((input - 1))]}"
return 0
elif [ "$input" != "q" ]; then
Error "$ERROR_02"
fi
done
return 1
}
_fix_fracked_coins() {
local coinfile input1 input2 func node_num
local prompt1 prompt2 prompt3 prompt4
local sn sns_list
coinfile=""
prompt1="$1>FIX_COINS"
Ask_coin_file "$prompt1"
if [ $? -eq 0 ]; then
coinfile="$GET_COINFILE"
prompt2="$prompt1>$coinfile"
else
return 1
fi
# Check if the coin file with over 200 notes
sn=$($JQ_CMD -r '.cloudcoin[].sn' $coinfile)
sns_list=($sn)
if [ ${#sns_list[@]} -gt 200 ]; then
Error "Error: The tester program is unable to handle more than 200 notes in the $coinfile!"
return 1
fi
input1=""
while [ "$input1" != "q" ]; do
echo "[1] multi detect"
echo "[2] multi fix"
echo
echo "Please select the function. (Enter q to end)"
echo -n "$prompt2[1-2]> " && read input1
if [ $input1 -ge 1 -a $input1 -le 2 ] 2>/dev/null; then
case "$input1" in
1)
prompt3="$prompt2>_multi_detect"
func="_multi_detect"
;;
2)
prompt3="$prompt2>_multi_fix"
isFix4Mode="true"
func="_multi_fix"
;;
esac
input2=""
while [ "$input2" != "q" ]; do
echo
echo "Please select the RAIDA node. (Enter q to go back)"
echo -n "$prompt3[0-$((RAIDA_NUMS - 1))]> " && read input2
if [ $input2 -ge 0 -a $input2 -le $((RAIDA_NUMS - 1)) ] 2>/dev/null; then
node_num=$input2
#echo "Debug: $func $node_num $coinfile"
$func "$node_num" "$coinfile"
elif [ "$input2" != "q" ]; then
Error "$ERROR_02"
fi
done
elif [ "$input1" != "q" ]; then
Error "$ERROR_02"
fi
done
}
_IP2SN() {
local input addr ip
local prompt
prompt="$1>IP-SN"
if ! Check_CMD $GETIP_CMD; then
Show_requirement
exit
fi
while [ "$input" != "q" ]; do
echo
echo "Please input the address to the SkyWallet. (Enter q to go back)"
echo -n "$prompt[*.skywallet.cc]> " && read input
if [ -n "$input" -a "$input" != "q" ] 2>/dev/null; then
addr=$(addr_validation "$input")
if [ -z "$addr" ]; then
Error "$ERROR_02"
continue
fi
if ! Check_Internet; then
echo
Error " Internet is not connected!"
continue
fi
addr=$(echo $addr | cut -d: -f2)
type=$(echo $addr | cut -d: -f1)
if [ "$type" == "IP" ]; then
ip=$addr
else
ip=$(get_ip "$addr")
fi
if [ -z "$ip" ]; then
echo
Error " The SkyWallet ($addr) is unavailable!"
continue
fi
sn=$(ip2dec "0.${ip#*.}")
echo
echo -e "$_GREEN_ The SN of the SkyWallet ($addr) is: $_BOLD_$sn$_REST_"
fi
done
}
_SN2IP() {
local sn ip input
prompt="$1>SN-IP"
while [ "$input" != "q" ]; do
echo
echo "Please input the SN that is converted. (Enter q to go back)"
echo -n "$prompt[1-16777215]> " && read input
if [ $input -ge 1 -a $input -le 16777215 ] 2>/dev/null; then
ip=$(dec2ip $input)
ip="1.${ip#*.}"
echo
echo -e "$_GREEN_ The IP for the SN ($input) is: $_BOLD_$ip$_REST_"
elif [ "$input" != "q" ]; then
Error "$ERROR_02"
fi
done
}
_Weather() {
local prompt url input
local city
prompt="$1>WEATHER"
if ! Check_Internet; then
echo
Error " Internet is not connected!"
continue
fi
while [ "$input" != "q" ]; do
echo
echo "Please input your city. (Enter q to go back)"
echo -n "$prompt[Taipei]> " && read input
if [ -n "$input" -a "$input" != "q" ] 2>/dev/null; then
city=$(ToLower $input)
url="http://wttr.in/$city"
$CURL_CMD $url
echo
break
fi
done
}
_SpeedTest() {
if ! Check_CMD $PYTHON_CMD; then
Show_requirement
exit
fi
$CURL_CMD -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | $PYTHON_CMD -
echo
}
_SkyWallet() {
local raida prompt node_num
local input
node_num="$1"
raida="raida$node_num"
prompt="RAIDA($node_num)-SW"
while true; do
echo "Test functions : 1.Multi_Detect 2.Show_ID1 3.Show_ID2 4.Send_ID1 5.Send_ID2 q.Exit"
echo "[1-11] 6.Receive_ID1 7.Receive_ID2 8.Transfer_ID1 9.Transfer_ID2 10.Rename_Tag_ID1"
echo " 11.Rename_Tag_ID2"
echo -n "$prompt> " && read input
if [ $input -ge 1 -a $input -le 11 ] 2>/dev/null; then
case "$input" in
1)
_multi_detect "$node_num" "$TESTCOINFILE6"
;;
2)
_SW_Show "$node_num" "$TESTCOINFILE4"
;;
3)
_SW_Show "$node_num" "$TESTCOINFILE5"
;;
4)
_SW_Send "$node_num" "$TESTCOINFILE4" "$TESTCOINFILE6"
;;
5)
_SW_Send "$node_num" "$TESTCOINFILE5" "$TESTCOINFILE6"
;;
6)
_SW_Receive "$node_num" "$TESTCOINFILE4" "$TESTCOINFILE6"
;;
7)
_SW_Receive "$node_num" "$TESTCOINFILE5" "$TESTCOINFILE6"
;;
8)
_SW_Transfer "$node_num" "$TESTCOINFILE4" "$TESTCOINFILE5" "$TESTCOINFILE6"
;;
9)
_SW_Transfer "$node_num" "$TESTCOINFILE5" "$TESTCOINFILE4" "$TESTCOINFILE6"
;;
10)
_SW_RenameTag "$node_num" "$TESTCOINFILE4"
;;
11)
_SW_RenameTag "$node_num" "$TESTCOINFILE5"
;;
#12)
# isFix4Mode="true"
# _multi_fix "$node_num" "$TESTCOINFILE6"
# ;;
esac
elif [ "$input" == "q" ] 2>/dev/null; then
break
else
Error "$ERROR_02"
fi
done
}
Process_request() {
local prompt input option
input=""
option="$1"
case "$option" in
_echo)
prompt="ECHO(e)"
;;
_version)
prompt="VERSION(v)"
;;
_cors)
prompt="CORS(c)"
;;
_detect)
prompt="DETECT(d)"
;;
_get_ticket)
prompt="GET_TICKET(g)"
;;
_hints)
prompt="HINTS(h)"
;;
_fix)
prompt="FIX(f)"
if [ "$isFix4Mode" = "true" ]; then
prompt="FIX4(f)"
else
prompt="FIX3(f)"
fi
;;
_multi_detect)
prompt="MULTI_DETECT(md)"
;;
_multi_detect2)
prompt="MULTI_DETECT+(md2)"
;;
_multi_get_ticket)
prompt="MULTI_GET_TICKET(mg)"
;;
_multi_hints)
prompt="MULTI_HINTS(mh)"
;;
_multi_fix)
if [ "$isFix4Mode" = "true" ]; then
prompt="MULTI_FIX4(mf)"
else
prompt="MULTI_FIX3(mf)"
fi
;;
esac
Ask_raida_node "$option" "$prompt"
}
_all_echo() {
local n
local version
#ask_html "ECHO"
#retval=$?
#[ $retval -eq 1 ] && return 1 # html template file not found
echo "ECHO Results: "
for ((n = 0; n < $RAIDA_NUMS; n++)); do
_echo $n >/dev/null 2>&1
run_echo=$?
if [ $run_echo -eq 0 ]; then
result="PASS"
else
result="${_RED_}FAIL${_REST_}"
fi
version=$(Get_version $n)
#Output $n "v$version|time:$echo_datetime|$result" $echo_elapsed
Output $n "v$version|time:$echo_datetime|status:$result|$(printf '%-6s' $echo_msg)"
if [ "$result" != "PASS" ]; then
Output2 "$echo_response"
fi
##if [ "$save_to_html" == "YES" ];then
# html_report="echotest.html"
# raida_node=$n
# get_status="$status"
# get_request="$raida_url"
# get_response="$http_response"
# get_ms="$elapsed"
# get_ver="$version"
# Basic_htmlreport "$html_report" "$raida_node" "$get_status" "$get_request" "$get_response" "$get_ms" "$get_ver"
#fi
done
echo
echo
}
_all_echo2() {
local url latency seconds
if ! Check_CMD "bc"; then
Show_requirement
exit
fi
warn=3
echo "ECHO: Latency) "
for ((n = 0; n < $RAIDA_NUMS; n++)); do
_echo $n >/dev/null 2>&1
run_echo=$?
if [ $run_echo -eq 0 ]; then
url="$(ToLower ${HTTP_PROTO})://raida$n.cloudcoin.global/service/echo"
seconds=$(Node_Latency "$url")
if [ $(echo "$seconds > $warn" | bc) -eq 1 ]; then
latency="${_RED_}$seconds${_REST_}"
else
latency=$seconds
fi
else
latency="${_RED_}----${_REST_}"
fi
if [ $(((($n + 1)) % 3)) -ne 0 ]; then
printf " %.10s %.20bs " "RAIDA($n): " $latency
else
printf " %.10s %.20bs \n" "RAIDA($n): " $latency
fi
done
echo
echo
}
_echo() {
echo_response=""
echo_elapsed=0
echo_datetime=""
echo_msg=""
echo_retval=0
input="$1"
raida="raida$input"
raida_url="$(ToLower ${HTTP_PROTO})://$raida.cloudcoin.global/service/echo"
start_s=$(Timer)
http_response=$($CURL_CMD $CURL_OPT $raida_url 2>&1)
http_retval=$?
end_s=$(Timer)
elapsed=$(((end_s - start_s) / 1000000))
if [ $http_retval -eq 0 ]; then
datetime=$(echo $http_response | $JQ_CMD -r '.time' 2>/dev/null)
status=$(echo $http_response | $JQ_CMD -r '.status' 2>/dev/null)
msg=$(echo $http_response | $JQ_CMD -r '.message' 2>/dev/null)
[ -z $status ] && status="invalid json data"
else
status="error"
echo_retval=1
fi
if [ "$status" == "ready" -o "$status" == "notready" ]; then
status_color="$_GREEN_$status$_REST_"
response_color="$_GREEN_$http_response$_REST_"
else
status_color="$_RED_$status$_REST_"
response_color="$_RED_$http_response$_REST_"
echo_retval=1
fi
echo
echo -e "Status: $_BOLD_$status_color"
echo "Milliseconds: $elapsed"
echo "Request: $raida_url"
echo -e "Response: $response_color"
echo
echo_response=$http_response
echo_elapsed=$elapsed
echo_datetime=$datetime
echo_msg=$msg
return $echo_retval
}
_version() {
version_response=""
version_elapsed=0
version_datetime=""
version_ver=""
version_eng=""
version_retval=0
input="$1"
raida="raida$input"
raida_url="$(ToLower ${HTTP_PROTO})://$raida.cloudcoin.global/service/version"
start_s=$(Timer)
http_response=$($CURL_CMD $CURL_OPT $raida_url 2>&1)
http_retval=$?
end_s=$(Timer)
elapsed=$(((end_s - start_s) / 1000000))
if [ $http_retval -eq 0 ]; then
datetime=$(echo $http_response | $JQ_CMD -r '.time' 2>/dev/null)
status=$(echo $http_response | $JQ_CMD -r '.status' 2>/dev/null)
ver=$(echo $http_response | $JQ_CMD -r '.version' 2>/dev/null)
eng=$(echo $http_response | $JQ_CMD -r '.engine' 2>/dev/null)
[ -z $status ] && status="invalid json data"
else
status="error"
version_retval=1
fi
if [ "$status" = "pass" ]; then
status_color="$_GREEN_$status$_REST_"
response_color="$_GREEN_$http_response$_REST_"
else
status_color="$_RED_$status$_REST_"
response_color="$_RED_$http_response$_REST_"
version_retval=1
fi
echo
echo -e "Status: $_BOLD_$status_color"
echo "Milliseconds: $elapsed"
echo "Request: $raida_url"
echo -e "Response: $response_color"
echo
version_response=$http_response
version_elapsed=$elapsed
version_datetime=$datetime
version_ver=$ver
version_eng=$eng
return $version_retval
}
_all_version() {
local n
local version
#ask_html "ECHO"
#retval=$?
#[ $retval -eq 1 ] && return 1 # html template file not found
echo "VERSION Results: "