forked from erfjab/holderbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
holderbot.sh
240 lines (201 loc) · 8.27 KB
/
holderbot.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
#!/bin/bash
cd
clear && echo -e "\n\n\n Start installing the Holderbot! \n\n\n\n\n\n" && sleep 3
clear && echo -e "\n Checking update and upgrade packages....\n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo && sleep 1 && apt update && apt upgrade -y || { echo -e "\n\nFailed to update and upgrade packages. Exiting...\n\n"; exit 1; }
clear && echo -e "\n Checking required packages....\n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo && sleep 1 && apt install python3 python3-pip git python3-dev python3-venv build-essential libsqlite3-dev -y || { echo -e "\n\nFailed to install required packages. Exiting...\n\n"; exit 1; }
clear && echo -e "\n Checking directories... \n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo
directories=("/holderbot" "/holderbeta" "/holder" "~/holderbot")
for dir in "${directories[@]}"; do
if [ -d "$dir" ]; then
echo -e "Removing existing $dir directory...\n"
rm -rf "$dir"
else
echo "Directory $dir does not exist."
fi
done
clear && echo -e "\n Checking processes... \n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo
processes=("python3 holder.py" "python3 holderbeta.py" "python3 node_status_checker.py" "python3 monitoringbeta.py" "python3 monitoring.py" "python3 expired.py" "python3 limiteder.py")
for proc in "${processes[@]}"; do
if pgrep -f "$proc" &> /dev/null; then
proc_name=$(echo "$proc" | cut -d ' ' -f 2)
echo -e "Stopping existing $proc_name process...\n"
pkill -fx "$proc"
fi
done
clear && echo -e "\n Checking hold venv... \n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo
mkdir -p holderbot && cd holderbot && git clone -b main https://github.com/erfjab/holderbot.git .
python3 -m venv hold && source hold/bin/activate
clear && echo -e "\n Checking python library... \n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo
pip install -U pyrogram tgcrypto requests Pillow qrcode[pil] persiantools pytz python-dateutil pysqlite3 cdifflib reportlab && \
sudo apt-get install -y sqlite3
#defining variables
name=""
chatid=""
token=""
user=""
password=""
domain_simple=""
ssl_response=""
domain=""
function getinfo() {
clear && echo -e "\\n Complete the information. \\n\\n"
while [[ -z "$name" || ! "$name" =~ ^[a-zA-Z]+$ ]]; do
read -p "Please enter name (nickname) : " name
if [[ -z "$name" ]]; then
echo "Name cannot be empty. Please enter a valid name."
elif [[ ! "$name" =~ ^[a-zA-Z]+$ ]]; then
echo "Name must contain only English letters. Please enter a valid name."
fi
done
chatid=""
while [[ ! "$chatid" =~ ^[0-9]+$ ]]; do
read -p "Please enter telegram chatid : " chatid
if [[ ! "$chatid" =~ ^[0-9]+$ ]]; then
echo "Chat ID must be a number. Please enter a valid number."
fi
done
token=""
while [[ -z "$token" || ! "$token" =~ ^[0-9]+:.+$ ]]; do
read -p "Please enter telegram bot token: " token
if [[ ! "$token" =~ ^[0-9]+:.+$ ]]; then
echo "Invalid token format. Please enter a valid token."
else
response=$(curl -s "https://api.telegram.org/bot$token/getMe")
if [[ "$response" != *"ok\":true"* ]]; then
echo "Invalid token. Please enter a valid token."
token=""
fi
fi
done
user=""
while [[ -z "$user" ]]; do
read -p "Please enter panel sudo username : " user
if [[ -z "$user" ]]; then
echo "Username cannot be empty. Please enter a valid username."
fi
done
password=""
while [[ -z "$password" ]]; do
read -p "Please enter panel sudo password : " password
if [[ -z "$password" ]]; then
echo "Password cannot be empty. Please enter a valid password."
fi
done
domain_simple=""
while [[ ! "$domain_simple" =~ ^[a-zA-Z0-9.-]+\:[0-9]+$ ]]; do
read -p "Please enter panel domain (like: sub.domain.com:port) : " domain_simple
if [[ ! "$domain_simple" =~ ^[a-zA-Z0-9.-]+\:[0-9]+$ ]]; then
echo "Invalid domain format. Please enter a valid domain in the format sub.domain.com:port."
fi
done
ssl_response=""
while [[ ! "$ssl_response" =~ ^[ynYN]$ ]]; do
read -p "Do you have SSL? (y/n): " ssl_response
if [[ ! "$ssl_response" =~ ^[ynYN]$ ]]; then
echo "Please enter 'y' for Yes or 'n' for No."
fi
done
if [[ $ssl_response == "y" || $ssl_response == "Y" ]]; then
domain="https://$domain_simple"
else
domain="http://$domain_simple"
fi
}
function checkinfo() {
clear && echo -e "\\n Checking information... \\n\\n"
echo "Name: $name"
echo "Telegram Chat ID: $chatid"
echo "Telegram Bot Token: $token"
echo "Panel Sudo Username: $user"
echo "Panel Sudo Password: $password"
echo "Panel Domain: $domain"
read -p "Are these information correct? (y/n): " correct
if [[ $correct == "y" || $correct == "Y" ]]; then
clear && echo -e "\n Checking panel... \n\n" && printf "%0.s-" {1..50} && echo && sleep 1
response=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "username=$user&password=$password" "$domain/api/admin/token")
if [[ $response -eq 200 ]]; then
echo "Authentication successful."
else
echo "Authentication failed. either HAproxy or Wrong information"
echo "Run this script again if bot doesnt work"
fi
fi
}
while true; do
getinfo
checkinfo
read -p "do you want to continue with this info? (y/n): " response
if [[ $response == "y" || $response == "Y" ]]; then
break
fi
done
clear && echo -e "\n Creating database... \n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo
rm holder.db || true
while true; do
sqlite3 holder.db <<EOF
CREATE TABLE IF NOT EXISTS bot
(chatid INTEGER PRIMARY KEY,
token TEXT);
CREATE TABLE IF NOT EXISTS monitoring
(chatid INTEGER PRIMARY KEY,
status TEXT,
check_normal INTEGER,
check_error INTEGER);
CREATE TABLE IF NOT EXISTS templates
(name TEXT PRIMARY KEY,
data INTEGER,
date INTEGER,
proxies TEXT,
inbounds TEXT);
CREATE TABLE IF NOT EXISTS users
(chatid INTEGER PRIMARY KEY,
role TEXT,
name TEXT,
username TEXT,
password TEXT,
domain TEXT,
step TEXT);
CREATE TABLE IF NOT EXISTS messages
(chatid INTEGER PRIMARY KEY,
status TEXT);
INSERT INTO messages (chatid, status) VALUES ('$chatid', 'off');
INSERT INTO users (chatid, role, name, username, password, domain, step) VALUES ('$chatid', 'boss', '$name', '$user', '$password', '$domain', 'None');
INSERT INTO monitoring (chatid, status, check_normal, check_error) VALUES ('$chatid', 'on', '10', '100');
INSERT INTO bot (chatid, token) VALUES ('$chatid', '$token');
EOF
if [[ $? -eq 0 ]]; then
echo "Database setup successful."
break
else
echo "Error: Database setup failed. Retrying..."
fi
done
clear && echo -e "\n Running the bot... \n\n" && yes '-' | head -n 50 | tr -d '\n\n' && echo
count=0
while true; do
chmod +x monitoring.py holder.py expired.py limiteder.py restart.sh
nohup python3 monitoring.py & disown
nohup python3 holder.py & disown
nohup python3 expired.py & disown
nohup python3 limiteder.py & disown
sleep 1
echo -e "\n\nplease wait...\n\n"
sleep 7
if ! pgrep -x "monitoring.py" && ! pgrep -x "holder.py" && ! pgrep -x "expired.py" && ! pgrep -x "limiteder.py"; then
echo "Scripts are running successfully."
break
else
((count++))
if (( count > 3 )); then
echo "Error: Scripts could not be started after multiple attempts."
exit 1
fi
echo "Scripts are still running. Retrying..."
fi
done
crontab -l | grep -vF "/bin/bash ~/holderbot/restart.sh" | crontab -
cronjob="@reboot sleep 20 && /bin/bash ~/holderbot/restart.sh"
if ! crontab -l | grep -Fq "$cronjob" >/dev/null 2>&1; then
(crontab -l 2>/dev/null; echo "$cronjob") | crontab -
fi
clear && echo -e "\n Holderbot is run, Enjoy! \n You can find us in telegram with @ErfJabHolderbot" && yes '-' | head -n 50 | tr -d '\n\n' && echo && sleep 2