forked from NeySlim/xtreamui_mirror
-
Notifications
You must be signed in to change notification settings - Fork 2
/
balancer3.py
135 lines (123 loc) · 9.11 KB
/
balancer3.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
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import subprocess, os, random, string, sys, shutil, socket, zipfile, urllib.request, urllib.error, urllib.parse, json, base64
from itertools import cycle
from zipfile import ZipFile
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
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("apt-get remove --auto-remove libcurl4 -y > /dev/null")
# for rPackage in rPackages: os.system("apt-get install %s -y > /dev/null" % rPackage)
os.system("wget -qO- https://raw.githubusercontent.com/amidevous/xtream-ui-ubuntu20.04/master/ubuntu/depbuild.sh | bash -s > /dev/null")
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')
lestring=''.join(chr(ord(c)^ord(k)) for c,k in zip('{\"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')))
rf.write(base64.b64encode(bytes(lestring, 'ascii')))
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, /usr/bin/chattr" >> /etc/sudoers')
os.system('systemctl disable xtreamcodes > /dev/null')
try: os.remove("/etc/init.d/xtreamcodes")
except: pass
if not os.path.exists("/etc/systemd/system/xtreamcodes.service"):
rStart = open("/etc/systemd/system/xtreamcodes.service", "w")
# rStart.write("#!/bin/bash\n### BEGIN INIT INFO\n# Provides: xtreamcodes\n# Required-Start: $all\n# Required-Stop:\n# Default-Start: 2 3 4 5\n# Default-Stop:\n# Short-Description: Run /etc/init.d/xtreamcodes if it exist\n### END INIT INFO\nsleep 1\n/home/xtreamcodes/iptv_xtream_codes/start_services.sh > /dev/null")
rStart.write("[Unit]\nDescription=xtreamcodes systemd service\nAfter=network-online.target\n\n[Service]\nType=oneshot\nRemainAfterExit=yes\nExecStart=/home/xtreamcodes/iptv_xtream_codes/start_services.sh\n\n[Install]\nWantedBy=multi-user.target")
rStart.close()
os.system("chmod +x /etc/systemd/system/xtreamcodes.service")
os.system("ln -s /etc/systemd/system/xtreamcodes.service /etc/systemd/system/multi-user.target.wants/xtreamcodes.service")
os.system("systemctl daemon-reload")
os.system("systemctl enable xtreamcodes")
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')
os.system("wget -qO- https://raw.githubusercontent.com/amidevous/xtream-ui-ubuntu20.04/master/ubuntu/posinstall.sh | bash -s > /dev/null")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/youtube-dl")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/youtube")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/bin/youtube-dl")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/bin/youtube")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/bin/yt-dlp")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /home/xtreamcodes/iptv_xtream_codes/bin/youtube-dl")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /home/xtreamcodes/iptv_xtream_codes/bin/youtube")
os.system("sudo wget -q https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /home/xtreamcodes/iptv_xtream_codes/bin/yt-dlp")
os.system("sudo chmod a+rx /usr/local/bin/youtube-dl")
os.system("sudo chmod a+rx /usr/local/bin/youtube")
os.system("sudo chmod a+rx /usr/local/bin/yt-dlp")
os.system("sudo chmod a+rx /usr/bin/youtube-dl")
os.system("sudo chmod a+rx /usr/bin/youtube")
os.system("sudo chmod a+rx /usr/bin/yt-dlp")
os.system("sudo chmod a+rx /home/xtreamcodes/iptv_xtream_codes/bin/youtube-dl")
os.system("sudo chmod a+rx /home/xtreamcodes/iptv_xtream_codes/bin/youtube")
os.system("sudo chmod a+rx /home/xtreamcodes/iptv_xtream_codes/bin/yt-dlp")
os.system("wget -qO- https://raw.githubusercontent.com/amidevous/xtream-ui-ubuntu20.04/master/phpbuild.sh | bash -s > /dev/null")
def start(first=True):
if first: printc("Starting Xtream Codes")
else: printc("Restarting Xtream Codes")
os.system("chattr +i /home/xtreamcodes/iptv_xtream_codes/GeoLite2.mmdb")
os.system("/home/xtreamcodes/iptv_xtream_codes/start_services.sh 2>/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()