-
Notifications
You must be signed in to change notification settings - Fork 17
/
best403unlocker-tui
186 lines (156 loc) · 5.68 KB
/
best403unlocker-tui
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
#!/usr/bin/env bash
CONFIG_FILE="/etc/best403unlocker.conf"
LOG_FILE="/var/log/best403unlocker-tui.log"
# Function to display the main menu
main_menu() {
password=
choice=$(whiptail --title "Best403Unlcoker TUI" --menu "Choose an option:" 15 60 4 \
"Run DNS analyzer" "find the most speedful dns" \
"Save file" "Download file with the best dns" \
"Advance setting" "change configuration" \
"Exit" "Exit the program" \
3>&1 1>&2 2>&3)
case "$choice" in
"Run DNS analyzer")
best_dns_finder
;;
"Save file")
download_file_with_best_dns
;;
"Advance setting")
change_settings
;;
"Exit")
exit
;;
*)
;;
esac
}
best_dns_finder() {
file_url=$(whiptail --title "add test file url" --inputbox "please type your url that you want to be checked" 15 60 "$file_url" 3>&1 1>&2 2>&3)
if [ $? -eq 1 ]; then
main
fi
# Replace the value of file_url with the value of the file_url environment variable
if grep -q "^file_url=" "$CONFIG_FILE" ; then
sed -i "s|^file_url=.*|file_url=$file_url|" $CONFIG_FILE
fi
choices=$(whiptail --title "choose engine otherwise it runs on system" --checklist "Choose options:" 15 60 1 \
"docker" "(suggested)" ON \
3>&1 1>&2 2>&3)
selected_options=($(echo $choices | tr -d '"'))
# Check if "docker" is in the selected options
if [[ " ${selected_options[@]} " =~ " docker " ]]; then
docker run --env-file $CONFIG_FILE armantaherighaletaki/best403unlocker 2>&1 | tee $LOG_FILE
status=$?
if [ $status -eq 0 ] && grep -q permission $LOG_FILE; then
password_checker
echo "$password" | sudo -S docker run --env-file $CONFIG_FILE armantaherighaletaki/best403unlocker | tee $LOG_FILE 2>&1
elif [ $status -nq 0 ]; then
whiptail --title "Error" --yesno "An error occurred. See $LOG_FILE for more info.\nDo you want to try again?" 15 60
status=$?
if [ $status -eq 0 ]; then
best_dns_finder
else
main
fi
fi
else
password_checker
best403unlocker | tee $LOG_FILE
fi
DNS=$(grep best $LOG_FILE| cut -d' ' -f5 )
whiptail --title "DNS analyzer" --msgbox "Best DNS:\n$DNS" 15 60
selected_options=($(echo $choices | tr -d '"'))
if whiptail --title "Confirmation" --yesno "set DNS to system" 10 60 ;then
password_checker
echo $password | sudo -S bash -c "echo 'nameserver $DNS' > /etc/resolv.conf"
fi
}
download_file_with_best_dns() {
file_url=$(whiptail --title "add file url" --inputbox "please type the url that you wnat to be downloaded" 15 60 "$file_url" 3>&1 1>&2 2>&3)
if [ $? -eq 1 ]; then
main
fi
# Replace the value of file_url with the value of the file_url environment variable
if grep -q "^file_url=" "$CONFIG_FILE" ; then
sed -i "s|^file_url=.*|file_url=$file_url|" $CONFIG_FILE
fi
save_filepath=$(echo "$file_url" | grep -o '[^/]*$')
save_filepath=$HOME/Downloads/$save_filepath
save_filepath=$(whiptail --title "save file as " --inputbox "choose the location to save the file" 15 60 "$save_filepath" 3>&1 1>&2 2>&3)
if [ $? -eq 1 ]; then
main
fi
choices=$(whiptail --title "choose engine otherwise it runs on system" --checklist "Choose options:" 15 60 1 \
"docker" "(suggested)" ON \
3>&1 1>&2 2>&3)
selected_options=($(echo $choices | tr -d '"'))
# Check if "docker" is in the selected options
if [[ " ${selected_options[@]} " =~ " docker " ]]; then
docker run --env-file $CONFIG_FILE armantaherighaletaki/best403unlocker 2>&1 | tee $LOG_FILE
status=$?
if [ $status -eq 0 ] && grep -q permission $LOG_FILE; then
password_checker
echo "$password" | sudo -S docker run --env-file $CONFIG_FILE armantaherighaletaki/best403unlocker | tee $LOG_FILE 2>&1
fi
else
password_checker
best403unlocker | tee $LOG_FILE
fi
DNS=$(grep best $LOG_FILE| cut -d' ' -f5 )
password_checker
echo "$password" | sudo -S bash -c "cp /etc/resolv.conf /etc/resolv.conf.bakup"
echo "$password" | sudo -S bash -c "echo 'nameserver $DNS' > /etc/resolv.conf"
wget --no-dns-cache $file_url -O $save_filepath 2>&1 | tee $LOG_FILE
if grep -q "No such file or directory" $LOG_FILE ; then
whiptail --title "Error" --msgbox "An error occurred. See $LOG_FILE for more info." 15 60
else
whiptail --title "Download Complete" --msgbox "The download has been completed successfully!" 15 60
fi
echo "$password" | sudo -S bash -c "mv /etc/resolv.conf.bakup /etc/resolv.conf"
}
change_settings() {
echo 'hello'
}
# Checks the password if a sudo command is executed
password_checker(){
password=
echo $password | sudo -S ls > /dev/null 2>&1
if [ $? -eq 1 ] && [[ -z $password ]]; then
while true; do
password=$(whiptail --title "Permission Denied" --passwordbox "Input your sudo password" 15 60 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
echo "$password" | sudo -S ls > /dev/null 2>&1
if [ $? -eq 0 ]; then
break
fi
else
main
fi
done
fi
}
check_and_source_env() {
if [ ! -f $CONFIG_FILE ]; then
wget -cq https://raw.githubusercontent.com/ArmanTaheriGhaleTaki/best403unlocker/main/.env -O $CONFIG_FILE
fi
source $CONFIG_FILE
}
check_run_with_root_accsses(){
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root (sudo)"
exit 1
fi
}
# Main function
main() {
check_run_with_root_accsses
check_and_source_env
while true; do
main_menu
done
}
# Main execution
main