-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsession-updater.py
67 lines (60 loc) · 2.73 KB
/
session-updater.py
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
import os
import sshx
import psutil
from pathlib import Path
from time import sleep
from datetime import datetime
from random import randint
if Path('logs.txt').is_file() is True:
os.remove('logs.txt')
def bot_checker():
for pid in psutil.pids():
try:
p = psutil.Process(pid)
if "python" in p.name():
if "bot.py" in p.cmdline():
return
except:
pass
os.system("nohup python3 -u bot.py &")
def main():
bot_checker()
with open('logs.txt', 'a+') as logs:
hosts, remarks = sshx.HOSTS()
for host in hosts:
port, username, password, panel, route_path, sshport, udgpw, remark = sshx.HOST_INFO(host)
if panel not in ['dragon']:
do = True
session = 'ssh/' + host + ".session"
if Path(session).is_file() is False:
if sshx.Login(username, password, host, port, panel) is False:
do = False
elif os.stat(session).st_size == 0:
os.remove(session)
if sshx.Login(username, password, host, port, panel) is False:
do = False
if (Path("protocol-cache.txt").is_file() is False) or (sshx.get_protocol_cache(host) is None):
protocol = sshx.check_panel_protocol(host)
sshx.add_protocol_cache(host, protocol)
if do is True:
for i in range(3):
try:
protocol_cache = sshx.get_protocol_cache(host)
protocol_check = sshx.check_panel_protocol(host)
if protocol_check != protocol_cache:
sshx.remove_protocol_cache(host)
sshx.add_protocol_cache(host, protocol_check)
url, r = sshx.open_session(host, port)
if sshx.Test(r, host, port, panel, 'updater') is False:
sshx.Login(username, password, host, port, panel)
logs.writelines("[+] Login: " + host + " " + panel + " " + str(datetime.now()) + "\n")
break
except Exception as e:
sleep(2)
if i == 2:
logs.writelines("[-] Session Error: " + str(e) + " " + str(datetime.now()) + "\n")
else:
logs.writelines("[-] Login Error: " + host + " " + str(datetime.now()) + "\n")
while True:
main()
sleep(randint(120, 360))