forked from NeySlim/xtreamui_mirror
-
Notifications
You must be signed in to change notification settings - Fork 2
/
balancer.py
98 lines (88 loc) · 6.1 KB
/
balancer.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
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
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import subprocess, os, sys
from itertools import cycle, izip
rDownloadURL = "https://bitbucket.org/le_lio/assets/raw/master/sub_xui_neyslim.tar.gz"
rPackages = ["libcurl4", "libxslt1-dev", "libgeoip-dev", "e2fsprogs", "wget", "mcrypt", "nscd", "htop", "zip", "unzip", "mc", "libzip5"]
def getVersion():
try: return subprocess.check_output("lsb_release -d".split()).split(":")[-1].strip()
except: return ""
def prepare():
global rPackages
for rFile in ["/var/lib/dpkg/lock-frontend", "/var/cache/apt/archives/lock", "/var/lib/dpkg/lock"]:
try: os.remove(rFile)
except: pass
os.system("apt-get update > /dev/null")
os.system("chattr -i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null")
for rPackage in rPackages: os.system("apt-get install %s -y > /dev/null" % rPackage)
os.system("adduser --system --shell /bin/false --group --disabled-login xtreamcodes > /dev/null")
if not os.path.exists("/home/xtreamcodes"): os.mkdir("/home/xtreamcodes")
return True
def install():
global rInstall, rDownloadURL
rURL = rDownloadURL
os.system('wget -q -O "/tmp/xtreamcodes.tar.gz" "%s"' % rURL)
if os.path.exists("/tmp/xtreamcodes.tar.gz"):
os.system('tar -zxvf "/tmp/xtreamcodes.tar.gz" -C "/home/xtreamcodes/" > /dev/null')
try: os.remove("/tmp/xtreamcodes.tar.gz")
except: pass
return True
return False
def encrypt(rHost="127.0.0.1", rUsername="user_iptvpro", rPassword="", rDatabase="xtream_iptvpro", rServerID=1, rPort=7999):
try: os.remove("/home/xtreamcodes/iptv_xtream_codes/config")
except: pass
rf = open('/home/xtreamcodes/iptv_xtream_codes/config', 'wb')
rf.write(''.join(chr(ord(c)^ord(k)) for c,k in izip('{\"host\":\"%s\",\"db_user\":\"%s\",\"db_pass\":\"%s\",\"db_name\":\"%s\",\"server_id\":\"%d\", \"db_port\":\"%d\"}' % (rHost, rUsername, rPassword, rDatabase, rServerID, rPort), cycle('5709650b0d7806074842c6de575025b1'))).encode('base64').replace('\n', ''))
rf.close()
def configure():
if not "/home/xtreamcodes/iptv_xtream_codes/" in open("/etc/fstab").read():
rFile = open("/etc/fstab", "a")
rFile.write("tmpfs /home/xtreamcodes/iptv_xtream_codes/streams tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=90% 0 0\ntmpfs /home/xtreamcodes/iptv_xtream_codes/tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=2G 0 0")
rFile.close()
if not "xtreamcodes" in open("/etc/sudoers").read(): os.system('echo "xtreamcodes ALL = (root) NOPASSWD: /sbin/iptables" >> /etc/sudoers')
if not os.path.exists("/etc/init.d/xtreamcodes"):
rFile = open("/etc/init.d/xtreamcodes", "w")
rFile.write("#! /bin/bash\n/home/xtreamcodes/iptv_xtream_codes/start_services.sh")
rFile.close()
os.system("chmod +x /etc/init.d/xtreamcodes > /dev/null")
try: os.remove("/usr/bin/ffmpeg")
except: pass
if not os.path.exists("/home/xtreamcodes/iptv_xtream_codes/tv_archive"): os.mkdir("/home/xtreamcodes/iptv_xtream_codes/tv_archive/")
os.system("ln -s /home/xtreamcodes/iptv_xtream_codes/bin/ffmpeg /usr/bin/")
os.system("chattr -i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null")
os.system("wget -q https://bitbucket.org/le_lio/assets/raw/master/GeoLite2.mmdb -O /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb")
os.system("wget -q https://bitbucket.org/le_lio/assets/raw/master/pid_monitor.php -O /home/xtreamcodes/iptv_xtream_codes/crons/pid_monitor.php")
os.system("chown xtreamcodes:xtreamcodes -R /home/xtreamcodes > /dev/null")
os.system("chmod -R 0777 /home/xtreamcodes > /dev/null")
os.system("chattr +i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb > /dev/null")
os.system("sed -i 's|chown -R xtreamcodes:xtreamcodes /home/xtreamcodes|chown -R xtreamcodes:xtreamcodes /home/xtreamcodes 2>/dev/null|g' /home/xtreamcodes/iptv_xtream_codes/start_services.sh")
os.system("chmod +x /home/xtreamcodes/iptv_xtream_codes/start_services.sh > /dev/null")
os.system("mount -a")
os.system("chmod 0700 /home/xtreamcodes/iptv_xtream_codes/config > /dev/null")
os.system("sed -i 's|echo \"Xtream Codes Reborn\";|header(\"Location: https://www.google.com/\");|g' /home/xtreamcodes/iptv_xtream_codes/wwwdir/index.php")
if not "api.xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 api.xtream-codes.com" >> /etc/hosts')
if not "downloads.xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 downloads.xtream-codes.com" >> /etc/hosts')
if not "xtream-codes.com" in open("/etc/hosts").read(): os.system('echo "127.0.0.1 xtream-codes.com" >> /etc/hosts')
if not "@reboot root /home/xtreamcodes/iptv_xtream_codes/start_services.sh" in open("/etc/crontab").read(): os.system('echo "@reboot root /home/xtreamcodes/iptv_xtream_codes/start_services.sh" >> /etc/crontab')
def start(): os.system("/home/xtreamcodes/iptv_xtream_codes/start_services.sh > /dev/null")
def setPorts(rPorts):
os.system("sed -i 's/listen 25461;/listen %d;/g' /home/xtreamcodes/iptv_xtream_codes/nginx/conf/nginx.conf" % rPorts[0])
os.system("sed -i 's/:25461/:%d/g' /home/xtreamcodes/iptv_xtream_codes/nginx_rtmp/conf/nginx.conf" % rPorts[0])
os.system("sed -i 's/listen 25463 ssl;/listen %d ssl;/g' /home/xtreamcodes/iptv_xtream_codes/nginx/conf/nginx.conf" % rPorts[1])
os.system("sed -i 's/listen 25462;/listen %d;/g' /home/xtreamcodes/iptv_xtream_codes/nginx_rtmp/conf/nginx.conf" % rPorts[2])
if __name__ == "__main__":
rHost = sys.argv[1]
rPort = int(sys.argv[2])
rUsername = sys.argv[3]
rPassword = sys.argv[4]
rDatabase = sys.argv[5]
rServerID = int(sys.argv[6])
try: rPorts = [int(sys.argv[7]), int(sys.argv[8]), int(sys.argv[9])]
except: rPorts = None
rRet = prepare()
if not install(): sys.exit(1)
encrypt(rHost, rUsername, rPassword, rDatabase, rServerID, rPort)
configure()
if rPorts: setPorts(rPorts)
start()
#13.03.2020 minimum R22B version is required for lb installation with custom ports.